hdf5/test/unlink.c

331 lines
7.6 KiB
C
Raw Normal View History

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().
*/
#include <h5test.h>
1998-10-06 21:16:04 +08:00
const char *FILENAME[] = {
"unlink",
NULL
};
[svn-r859] Changes since 19981030 ---------------------- ./MANIFEST Added new Pablo files HDF5record_RT.h and ProcIDs.h ./acconfig.h ./configure [REGENERATED] ./configure.in ./src/H5.c ./src/H5Vprivate.h ./src/H5config.h.in [REGENERATED] ./src/H5private.h ./src/H5public.h ./test/big.c Added more configuration stuff for the Win32 environment. Removed all the #ifdef WIN32 from the source and replaced them with OS-independent stuff. Specifics follow: Check for non-Posix.1 `st_blocks' field in `struct stat' which is used by the big file test to decide if the file system supports holes. If the st_blocks field isn't present then we just skip the test. Configure checks for <io.h> <sys/resource.h> <sys/time.h> and <winsock.h> and defines HAVE_IO_H, HAVE_SYS_RESOURCE_H, HAVE_SYS_TIME_H and HAVE_WINSOCK_H when they're found. Configure checks whether both <sys/time.h> and <time.h> can be included and defines SYS_TIME_WITH_TIME if so. Otherwise include only <sys/time.h> or <time.h> even if both exist. Configure checks sizeof(__int64) and defines SIZEOF___INT64 to the result or to zero if __int64 isn't defined. The source uses `long long' in preference to `__int64'. Removed null WIN32 definition for `inline' since such a definition already exists in H5config.h Protected gettimeofday() calls in debugging code with HAVE_GETTIMEOFDAY instead of WIN32. ./src/H5F.c ./src/H5Flow.c ./src/H5Fmpio.c ./src/H5Fsec2.c ./src/H5Fstdio.h ./src/H5P.c ./src/H5Tconv.c ./src/H5private.h Removed #include of system files from library source files and consolodated them into H5private.h where they're protected by various configuration macros (most of them were duplicated there already anyway). ./test/big.c ./test/chunk.c ./test/cmpd_dset.c ./test/dsets.c ./test/dtypes.c ./test/extend.c ./test/external.c ./test/fillval.c ./test/flush1.c ./test/flush2.c ./test/iopipe.c ./test/links.c ./test/mount.c ./test/mtime.c ./test/overhead.c ./test/ragged.c ./test/shtype.c ./test/unlink.c Protected system #include's with #ifdef's from H5config.h. Undefined NDEBUG since some of the tests rely on assert() to check return values. Removed WIN32 definitions for __unused__ since this can be controlled by the definition of HAVE_ATTRIBUTE in H5config.h ./test/testhdf5.h Removed the CLEAN_CMD definition because we no longer use it. Albert's cleanup() functions replaced it. ./test/fillval.c Initialized auto hid_t variables to fix warnings in error recovery code when data flow analysis is turned on in compilers. ./test/h5tools.c Initialized an auto variable to fix a compiler warning. ./test/chunk.c ./test/ragged.c The WIN32 had some unsigned variables changed to signed because the compiler generates warnings when coercing unsigned to double(?). I changed them back to unsigned because they really are unsigned quantities. If this the change was just to shut up extraneous warnings then perhaps a compiler flag can do the same; otherwise if the compiler generates bad code then we should supply a patch file instead messing up source code with bug work-arounds. ./src/H5detect.c Protected system #include's with #ifdef's from H5config.h thereby removing a WIN32. If getpwuid() doesn't exist (HAVE_GETPWUID) then we assume that `struct passwd' doesn't exist either (we don't really need it in that case). The H5T_NATIVE_LLONG and H5T_NATIVE_ULLONG are defined in terms of `long long' or else `__int64' or else `long' depending on what's available. ./src/H5Flow.c ./src/H5Ofill.c Added __unused__ to some function arguments that aren't used when assertions are turned off. ./src/H5V.c Changed an auto variable name in some hand-inlined code to get rid of a warning about the variable shadowing a previous auto.
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)
{
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 */
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;
PASSED();
1998-10-06 21:16:04 +08:00
/* Delete by local name */
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;
PASSED();
1998-10-06 21:16:04 +08:00
/* Delete directly - should fail */
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) {
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;
PASSED();
1998-10-06 21:16:04 +08:00
/* Cleanup */
if (H5Gclose(work)<0) goto error;
return 0;
1998-10-06 21:16:04 +08:00
error:
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)
{
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;
if (H5Gclose(grp)<0) goto error;
1998-10-06 21:16:04 +08:00
/* Create a bunch of names and unlink them in order */
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;
}
PASSED();
1998-10-06 21:16:04 +08:00
/* Create a bunch of names and unlink them in reverse order */
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;
}
PASSED();
1998-10-06 21:16:04 +08:00
/* Create a bunch of names and unlink them from both directions */
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;
}
PASSED();
1998-10-06 21:16:04 +08:00
/* Create a bunch of names and unlink them from the midle */
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;
}
PASSED();
1998-10-06 21:16:04 +08:00
/* Cleanup */
if (H5Gclose(work)<0) goto error;
return 0;
1998-10-06 21:16:04 +08:00
error:
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)
{
hid_t work=-1;
1998-10-06 21:16:04 +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;
PASSED();
1998-10-06 21:16:04 +08:00
return 0;
1998-10-06 21:16:04 +08:00
error:
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)
{
hid_t work=-1, foo=-1, inner=-1;
1998-10-06 21:16:04 +08:00
/* Create a test group and rename something */
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;
PASSED();
1998-10-06 21:16:04 +08:00
/* Try renaming a symlink */
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;
PASSED();
1998-10-06 21:16:04 +08:00
/* Cleanup */
if (H5Gclose(work)<0) goto error;
return 0;
1998-10-06 21:16:04 +08:00
error:
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)
{
hid_t fapl, file;
1998-10-06 21:16:04 +08:00
int nerrors = 0;
char filename[1024];
1998-10-06 21:16:04 +08:00
/* Open */
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.");
h5_cleanup(FILENAME, fapl);
1998-10-06 21:16:04 +08:00
return 0;
error:
return 1;
}