summaryrefslogtreecommitdiffstats
path: root/test/unlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/unlink.c')
-rw-r--r--test/unlink.c169
1 files changed, 59 insertions, 110 deletions
diff --git a/test/unlink.c b/test/unlink.c
index fcc9b2f..ca66c74 100644
--- a/test/unlink.c
+++ b/test/unlink.c
@@ -7,76 +7,17 @@
*
* Purpose: Test H5Gunlink().
*/
+#include <h5test.h>
-/* See H5private.h for how to include headers */
-#undef NDEBUG
-#include <hdf5.h>
+const char *FILENAME[] = {
+ "unlink",
+ NULL
+};
-#ifdef STDC_HEADERS
-# include <stdlib.h>
-#endif
-
-#ifndef HAVE_ATTRIBUTE
-# undef __attribute__
-# define __attribute__(X) /*void*/
-# define __unused__ /*void*/
-#else
-# define __unused__ __attribute__((unused))
-#endif
-
-#define FILE_NAME_1 "unlink.h5"
#define THE_OBJECT "/foo"
/*-------------------------------------------------------------------------
- * Function: cleanup
- *
- * Purpose: Removes test files
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Thursday, June 4, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-cleanup (void)
-{
- if (!getenv ("HDF5_NOCLEANUP")) {
- remove (FILE_NAME_1);
- }
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: display_error_cb
- *
- * Purpose: Displays the error stack after printing "*FAILED*".
- *
- * Return: Success: 0
- *
- * Failure: -1
- *
- * Programmer: Robb Matzke
- * Wednesday, March 4, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static herr_t
-display_error_cb (void __unused__ *client_data)
-{
- puts ("*FAILED*");
- H5Eprint (stdout);
- return 0;
-}
-
-
-/*-------------------------------------------------------------------------
* Function: test_one
*
* Purpose: Creates a group that has just one entry and then unlinks that
@@ -96,48 +37,49 @@ display_error_cb (void __unused__ *client_data)
static int
test_one(hid_t file)
{
- hid_t work, grp;
+ hid_t work=-1, grp=-1;
herr_t status;
/* Create a test group */
if ((work=H5Gcreate(file, "/test_one", 0))<0) goto error;
/* Delete by absolute name */
- printf("%-70s", "Testing unlink by absolute name");
- fflush(stdout);
+ TESTING("unlink by absolute name");
if ((grp=H5Gcreate(work, "foo", 0))<0) goto error;
if (H5Gclose(grp)<0) goto error;
if (H5Gunlink(file, "/test_one/foo")<0) goto error;
- puts(" PASSED");
+ PASSED();
/* Delete by local name */
- printf("%-70s", "Testing unlink by local name");
- fflush(stdout);
+ TESTING("unlink by local name");
if ((grp=H5Gcreate(work, "foo", 0))<0) goto error;
if (H5Gclose(grp)<0) goto error;
if (H5Gunlink(work, "foo")<0) goto error;
- puts(" PASSED");
+ PASSED();
/* Delete directly - should fail */
- printf("%-70s", "Testing unlink without a name");
- fflush(stdout);
+ TESTING("unlink without a name");
if ((grp=H5Gcreate(work, "foo", 0))<0) goto error;
H5E_BEGIN_TRY {
status = H5Gunlink(grp, ".");
} H5E_END_TRY;
if (status>=0) {
- puts("*FAILED*");
- puts(" Unlinking object w/o a name should have failed.");
+ FAILED();
+ puts(" Unlinking object w/o a name should have failed.");
goto error;
}
if (H5Gclose(grp)<0) goto error;
- puts(" PASSED");
+ PASSED();
/* Cleanup */
if (H5Gclose(work)<0) goto error;
return 0;
+
error:
- H5Gclose(work);
+ H5E_BEGIN_TRY {
+ H5Gclose(work);
+ H5Gclose(grp);
+ } H5E_END_TRY;
return 1;
}
@@ -161,7 +103,7 @@ test_one(hid_t file)
static int
test_many(hid_t file)
{
- hid_t work, grp;
+ hid_t work=-1, grp=-1;
int i;
const int how_many=500;
char name[32];
@@ -172,8 +114,7 @@ test_many(hid_t file)
if (H5Gclose(grp)<0) goto error;
/* Create a bunch of names and unlink them in order */
- printf("%-70s", "Testing forward unlink");
- fflush(stdout);
+ TESTING("forward unlink");
for (i=0; i<how_many; i++) {
sprintf(name, "obj_%05d", i);
if (H5Glink(work, H5G_LINK_HARD, "/test_many_foo", name)<0) goto error;
@@ -182,11 +123,10 @@ test_many(hid_t file)
sprintf(name, "obj_%05d", i);
if (H5Gunlink(work, name)<0) goto error;
}
- puts(" PASSED");
+ PASSED();
/* Create a bunch of names and unlink them in reverse order */
- printf("%-70s", "Testing backward unlink");
- fflush(stdout);
+ TESTING("backward unlink");
for (i=0; i<how_many; i++) {
sprintf(name, "obj_%05d", i);
if (H5Glink(work, H5G_LINK_HARD, "/test_many_foo", name)<0) goto error;
@@ -195,11 +135,10 @@ test_many(hid_t file)
sprintf(name, "obj_%05d", i);
if (H5Gunlink(work, name)<0) goto error;
}
- puts(" PASSED");
+ PASSED();
/* Create a bunch of names and unlink them from both directions */
- printf("%-70s", "Testing inward unlink");
- fflush(stdout);
+ TESTING("inward unlink");
for (i=0; i<how_many; i++) {
sprintf(name, "obj_%05d", i);
if (H5Glink(work, H5G_LINK_HARD, "/test_many_foo", name)<0) goto error;
@@ -212,11 +151,10 @@ test_many(hid_t file)
}
if (H5Gunlink(work, name)<0) goto error;
}
- puts(" PASSED");
+ PASSED();
/* Create a bunch of names and unlink them from the midle */
- printf("%-70s", "Testing outward unlink");
- fflush(stdout);
+ TESTING("outward unlink");
for (i=0; i<how_many; i++) {
sprintf(name, "obj_%05d", i);
if (H5Glink(work, H5G_LINK_HARD, "/test_many_foo", name)<0) goto error;
@@ -229,14 +167,18 @@ test_many(hid_t file)
}
if (H5Gunlink(work, name)<0) goto error;
}
- puts(" PASSED");
+ PASSED();
/* Cleanup */
if (H5Gclose(work)<0) goto error;
return 0;
+
error:
- H5Gclose(work);
+ H5E_BEGIN_TRY {
+ H5Gclose(work);
+ H5Gclose(grp);
+ } H5E_END_TRY;
return 1;
}
@@ -260,10 +202,9 @@ test_many(hid_t file)
static int
test_symlink(hid_t file)
{
- hid_t work;
+ hid_t work=-1;
- printf("%-70s", "Testing symlink removal");
- fflush(stdout);
+ TESTING("symlink removal");
/* Create a test group and symlink */
if ((work=H5Gcreate(file, "/test_symlink", 0))<0) goto error;
@@ -272,10 +213,13 @@ test_symlink(hid_t file)
/* Cleanup */
if (H5Gclose(work)<0) goto error;
- puts(" PASSED");
+ PASSED();
return 0;
+
error:
- H5Gclose(work);
+ H5E_BEGIN_TRY {
+ H5Gclose(work);
+ } H5E_END_TRY;
return 1;
}
@@ -299,12 +243,10 @@ test_symlink(hid_t file)
static int
test_rename(hid_t file)
{
- hid_t work, foo, inner;
+ hid_t work=-1, foo=-1, inner=-1;
-
/* Create a test group and rename something */
- printf("%-70s", "Testing object renaming");
- fflush(stdout);
+ TESTING("object renaming");
if ((work=H5Gcreate(file, "/test_rename", 0))<0) goto error;
if ((foo=H5Gcreate(work, "foo", 0))<0) goto error;
if (H5Gmove(work, "foo", "bar")<0) goto error;
@@ -313,20 +255,24 @@ test_rename(hid_t file)
if (H5Gclose(foo)<0) goto error;
if ((inner=H5Gopen(work, "bar/inner"))<0) goto error;
if (H5Gclose(inner)<0) goto error;
- puts(" PASSED");
+ PASSED();
/* Try renaming a symlink */
- printf("%-70s", "Testing symlink renaming");
- fflush(stdout);
+ TESTING("symlink renaming");
if (H5Glink(work, H5G_LINK_SOFT, "link_value", "link_one")<0) goto error;
if (H5Gmove(work, "link_one", "link_two")<0) goto error;
- puts(" PASSED");
+ PASSED();
/* Cleanup */
if (H5Gclose(work)<0) goto error;
return 0;
+
error:
- H5Gclose(work);
+ H5E_BEGIN_TRY {
+ H5Gclose(work);
+ H5Gclose(foo);
+ H5Gclose(inner);
+ } H5E_END_TRY;
return 1;
}
@@ -351,13 +297,16 @@ test_rename(hid_t file)
int
main(void)
{
- hid_t file;
+ hid_t fapl, file;
int nerrors = 0;
+ char filename[1024];
/* Open */
- H5Eset_auto(display_error_cb, NULL);
- if ((file=H5Fcreate(FILE_NAME_1, H5F_ACC_TRUNC,
- H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
+ h5_reset();
+ fapl = h5_fileaccess();
+ h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
+ if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
+ goto error;
/* Tests */
nerrors += test_one(file);
@@ -372,7 +321,7 @@ main(void)
exit(1);
}
puts("All unlink tests passed.");
- cleanup();
+ h5_cleanup(fapl);
return 0;
error:
return 1;