1998-10-06 21:16:04 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 1998 NCSA
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke <matzke@llnl.gov>
|
|
|
|
|
* Friday, September 25, 1998
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test H5Gunlink().
|
|
|
|
|
*/
|
1998-11-24 04:40:35 +08:00
|
|
|
|
#include <h5test.h>
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
1998-11-24 04:40:35 +08:00
|
|
|
|
const char *FILENAME[] = {
|
|
|
|
|
"unlink",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
1998-11-03 01:58:28 +08:00
|
|
|
|
|
1998-10-06 21:16:04 +08:00
|
|
|
|
#define THE_OBJECT "/foo"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_one
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Creates a group that has just one entry and then unlinks that
|
|
|
|
|
* entry.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: number of errors
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Friday, September 25, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
test_one(hid_t file)
|
|
|
|
|
{
|
1998-11-24 04:40:35 +08:00
|
|
|
|
hid_t work=-1, grp=-1;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
herr_t status;
|
|
|
|
|
|
|
|
|
|
/* Create a test group */
|
|
|
|
|
if ((work=H5Gcreate(file, "/test_one", 0))<0) goto error;
|
|
|
|
|
|
|
|
|
|
/* Delete by absolute name */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("unlink by absolute name");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
if ((grp=H5Gcreate(work, "foo", 0))<0) goto error;
|
|
|
|
|
if (H5Gclose(grp)<0) goto error;
|
|
|
|
|
if (H5Gunlink(file, "/test_one/foo")<0) goto error;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Delete by local name */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("unlink by local name");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
if ((grp=H5Gcreate(work, "foo", 0))<0) goto error;
|
|
|
|
|
if (H5Gclose(grp)<0) goto error;
|
|
|
|
|
if (H5Gunlink(work, "foo")<0) goto error;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Delete directly - should fail */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("unlink without a name");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
if ((grp=H5Gcreate(work, "foo", 0))<0) goto error;
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
status = H5Gunlink(grp, ".");
|
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
if (status>=0) {
|
1998-11-24 04:40:35 +08:00
|
|
|
|
FAILED();
|
|
|
|
|
puts(" Unlinking object w/o a name should have failed.");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (H5Gclose(grp)<0) goto error;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
|
if (H5Gclose(work)<0) goto error;
|
|
|
|
|
return 0;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
|
1998-10-06 21:16:04 +08:00
|
|
|
|
error:
|
1998-11-24 04:40:35 +08:00
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Gclose(work);
|
|
|
|
|
H5Gclose(grp);
|
|
|
|
|
} H5E_END_TRY;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_many
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests many unlinks in a single directory.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: number of errors
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Friday, September 25, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
test_many(hid_t file)
|
|
|
|
|
{
|
1998-11-24 04:40:35 +08:00
|
|
|
|
hid_t work=-1, grp=-1;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
int i;
|
|
|
|
|
const int how_many=500;
|
|
|
|
|
char name[32];
|
|
|
|
|
|
|
|
|
|
/* Create a test group */
|
|
|
|
|
if ((work=H5Gcreate(file, "/test_many", 0))<0) goto error;
|
|
|
|
|
if ((grp = H5Gcreate(work, "/test_many_foo", 0))<0) goto error;
|
1998-10-16 23:40:37 +08:00
|
|
|
|
if (H5Gclose(grp)<0) goto error;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Create a bunch of names and unlink them in order */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("forward unlink");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
for (i=0; i<how_many; i++) {
|
|
|
|
|
sprintf(name, "obj_%05d", i);
|
|
|
|
|
if (H5Gunlink(work, name)<0) goto error;
|
|
|
|
|
}
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Create a bunch of names and unlink them in reverse order */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("backward unlink");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
for (i=how_many-1; i>=0; --i) {
|
|
|
|
|
sprintf(name, "obj_%05d", i);
|
|
|
|
|
if (H5Gunlink(work, name)<0) goto error;
|
|
|
|
|
}
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Create a bunch of names and unlink them from both directions */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("inward unlink");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
for (i=0; i<how_many; i++) {
|
|
|
|
|
if (i%2) {
|
|
|
|
|
sprintf(name, "obj_%05d", how_many-(1+i/2));
|
|
|
|
|
} else {
|
|
|
|
|
sprintf(name, "obj_%05d", i/2);
|
|
|
|
|
}
|
|
|
|
|
if (H5Gunlink(work, name)<0) goto error;
|
|
|
|
|
}
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Create a bunch of names and unlink them from the midle */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("outward unlink");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
for (i=how_many-1; i>=0; --i) {
|
|
|
|
|
if (i%2) {
|
|
|
|
|
sprintf(name, "obj_%05d", how_many-(1+i/2));
|
|
|
|
|
} else {
|
|
|
|
|
sprintf(name, "obj_%05d", i/2);
|
|
|
|
|
}
|
|
|
|
|
if (H5Gunlink(work, name)<0) goto error;
|
|
|
|
|
}
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
|
if (H5Gclose(work)<0) goto error;
|
|
|
|
|
return 0;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
|
1998-10-06 21:16:04 +08:00
|
|
|
|
error:
|
1998-11-24 04:40:35 +08:00
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Gclose(work);
|
|
|
|
|
H5Gclose(grp);
|
|
|
|
|
} H5E_END_TRY;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_symlink
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests removal of symbolic links.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: number of errors
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Friday, September 25, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
test_symlink(hid_t file)
|
|
|
|
|
{
|
1998-11-24 04:40:35 +08:00
|
|
|
|
hid_t work=-1;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("symlink removal");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Create a test group and symlink */
|
|
|
|
|
if ((work=H5Gcreate(file, "/test_symlink", 0))<0) goto error;
|
|
|
|
|
if (H5Glink(work, H5G_LINK_SOFT, "link_value", "link")<0) goto error;
|
|
|
|
|
if (H5Gunlink(work, "link")<0) goto error;
|
|
|
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
|
if (H5Gclose(work)<0) goto error;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
return 0;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
|
1998-10-06 21:16:04 +08:00
|
|
|
|
error:
|
1998-11-24 04:40:35 +08:00
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Gclose(work);
|
|
|
|
|
} H5E_END_TRY;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_rename
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests H5Gmove()
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: 0
|
|
|
|
|
*
|
|
|
|
|
* Failure: number of errors
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Friday, September 25, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
test_rename(hid_t file)
|
|
|
|
|
{
|
1998-11-24 04:40:35 +08:00
|
|
|
|
hid_t work=-1, foo=-1, inner=-1;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Create a test group and rename something */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("object renaming");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
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;
|
|
|
|
|
if ((inner=H5Gcreate(foo, "inner", 0))<0) goto error;
|
|
|
|
|
if (H5Gclose(inner)<0) goto error;
|
|
|
|
|
if (H5Gclose(foo)<0) goto error;
|
|
|
|
|
if ((inner=H5Gopen(work, "bar/inner"))<0) goto error;
|
|
|
|
|
if (H5Gclose(inner)<0) goto error;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Try renaming a symlink */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
TESTING("symlink renaming");
|
1998-10-06 21:16:04 +08:00
|
|
|
|
if (H5Glink(work, H5G_LINK_SOFT, "link_value", "link_one")<0) goto error;
|
|
|
|
|
if (H5Gmove(work, "link_one", "link_two")<0) goto error;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
PASSED();
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
|
if (H5Gclose(work)<0) goto error;
|
|
|
|
|
return 0;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
|
1998-10-06 21:16:04 +08:00
|
|
|
|
error:
|
1998-11-24 04:40:35 +08:00
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Gclose(work);
|
|
|
|
|
H5Gclose(foo);
|
|
|
|
|
H5Gclose(inner);
|
|
|
|
|
} H5E_END_TRY;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: main
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Test H5Gunlink()
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: zero
|
|
|
|
|
*
|
|
|
|
|
* Failure: non-zero
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Robb Matzke
|
|
|
|
|
* Friday, September 25, 1998
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
main(void)
|
|
|
|
|
{
|
1998-11-24 04:40:35 +08:00
|
|
|
|
hid_t fapl, file;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
int nerrors = 0;
|
1998-11-24 04:40:35 +08:00
|
|
|
|
char filename[1024];
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Open */
|
1998-11-24 04:40:35 +08:00
|
|
|
|
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;
|
1998-10-06 21:16:04 +08:00
|
|
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
nerrors += test_one(file);
|
|
|
|
|
nerrors += test_many(file);
|
|
|
|
|
nerrors += test_symlink(file);
|
|
|
|
|
nerrors += test_rename(file);
|
|
|
|
|
|
|
|
|
|
/* Close */
|
|
|
|
|
if (H5Fclose(file)<0) goto error;
|
|
|
|
|
if (nerrors) {
|
|
|
|
|
printf("***** %d FAILURE%s! *****\n", nerrors, 1==nerrors?"":"S");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
puts("All unlink tests passed.");
|
2000-09-10 08:08:27 +08:00
|
|
|
|
h5_cleanup(FILENAME, fapl);
|
1998-10-06 21:16:04 +08:00
|
|
|
|
return 0;
|
|
|
|
|
error:
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|