diff options
author | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2008-04-30 19:51:13 (GMT) |
---|---|---|
committer | Scot Breitenfeld <brtnfld@hdfgroup.org> | 2008-04-30 19:51:13 (GMT) |
commit | aec106e324ce20e5efb725c25a6a333c7970127b (patch) | |
tree | 234df369115a46b08037c5f385061cf58823e497 /test/links.c | |
parent | 5773fd34bc5adf59b4530d95ac9f0c0585902803 (diff) | |
download | hdf5-aec106e324ce20e5efb725c25a6a333c7970127b.zip hdf5-aec106e324ce20e5efb725c25a6a333c7970127b.tar.gz hdf5-aec106e324ce20e5efb725c25a6a333c7970127b.tar.bz2 |
[svn-r14903] Undoing change committed in r14902.
Diffstat (limited to 'test/links.c')
-rw-r--r-- | test/links.c | 1494 |
1 files changed, 1481 insertions, 13 deletions
diff --git a/test/links.c b/test/links.c index 1bff4c6..ed60748 100644 --- a/test/links.c +++ b/test/links.c @@ -20,10 +20,6 @@ * Purpose: Tests hard, soft (symbolic) & external links. */ -#include "h5test.h" - -#include "H5Lprivate.h" - /* * This file needs to access private information from the H5G package. * This file also needs to access the group testing code. @@ -32,6 +28,9 @@ #define H5G_TESTING #include "H5Gpkg.h" /* Groups */ +#include "h5test.h" +#include "H5Lprivate.h" + /* File for external link test. Created with gen_udlinks.c */ #define LINKED_FILE "be_extlink2.h5" @@ -40,15 +39,47 @@ const char *FILENAME[] = { "links1", "links2", "links3", - "links4a", - "links4b", - "links4c", - "links4d", - "links5", - "links6", + "links4a", /* 4 */ + "links4b", /* 5 */ + "links4c", /* 6 */ + "links4d", /* 7 */ + "links5", /* 8 */ + "links6", /* 9 */ + "links7", /* 10 */ + "links8", /* 11 */ + "extlinks0", /* 12: main files */ + "tmp/extlinks0", /* 13: */ + "extlinks1", /* 14: target files */ + "tmp/extlinks1", /* 15: */ + "extlinks2", /* 16: */ + "tmp/extlinks2", /* 17: */ + "extlinks3", /* 18: */ + "tmp/extlinks3", /* 19: */ + "extlinks4", /* 20: */ + "tmp/extlinks4", /* 21: */ + "extlinks5", /* 22: */ + "tmp/extlinks6", /* 23: */ + "extlinks7", /* 24: */ + "tmp/extlinks7", /* 25: */ + "tmp/extlinks8", /* 26: */ + "extlinks9", /* 27: */ + "tmp/extlinks9", /* 28: */ + "extlinks10", /* 29: */ /* TESTS for windows */ + "tmp/extlinks10", /* 30: */ + "tmp/extlinks11", /* 31: */ + "tmp/extlinks12", /* 32: */ + "extlinks13", /* 33: */ + "tmp/extlinks13", /* 34: */ + "extlinks14", /* 35: */ + "tmp/extlinks14", /* 36: */ + "tmp/extlinks15", /* 37: */ NULL }; +#define TMPDIR "tmp" +/* do not do check_all_closed() for "ext*" files and "tmp/ext*" */ +#define EXTSTOP 12 + #define LINK_BUF_SIZE 1024 #define NAME_BUF_SIZE 1024 #define MAX_NAME_LEN ((64*1024)+1024) @@ -2552,6 +2583,1418 @@ external_link_dangling(hid_t fapl, hbool_t new_format) return -1; } /* end external_link_dangling() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_env: test 1 + * + * Purpose: + * 1. target link: "extlinks1" + * 2. main file: "extlinks0" + * 3. target file: "tmp/extlinks1" + * 4. The environment variable "HDF5_EXT_PREFIX" should be set to ".:tmp" + * Should be able to access the target file in tmp directory through searching + * the pathnames set in HDF5_EXT_PREFIX. + * This test will be skipped if HDF5_EXT_PREFIX is not set as expected. + * + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb. 20, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_env(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + const char *envval = NULL; + + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via environment variable (w/new group format)") + else + TESTING("external links via environment variable") + + if ((envval = HDgetenv("HDF5_EXT_PREFIX")) == NULL) + envval = "nomatch"; + if (HDstrcmp(envval, ".:tmp")) { + SKIPPED(); + return(0); + } + + /* set up name for main file:"extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + /* set up name for external linked target file: "extlinks1" */ + h5_fixname(FILENAME[14], fapl, filename2, sizeof filename2); + + if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + + /* set up name for target file: "tmp/extlinks1" */ + h5_fixname(FILENAME[15], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file from pathnames set via environment variable */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp directory."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_env() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_prefix: test 2 + * + * Purpose: 1. target link: "extlinks2" + * 2. main file: "extlinks0" + * 3. target file: "tmp/extlinks2" + * 4. Set up external link prefix via H5Pset_elink_prefix() to be "tmp" + * Should be able to access the target file in tmp directory via the prefix set + * by H5Pset_elink_prefix() + * + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb 19, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_prefix(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + hid_t gapl_id = (-1); + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via H5Pset_elink_prefix()(w/new group format)") + else + TESTING("external links via H5Pset_elink_prefix()") + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + /* set up name for external linked target file: "extlinks2" */ + h5_fixname(FILENAME[16], fapl, filename2, sizeof filename2); + + /* create tmp directory and get current working directory path */ + if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + + /* set up name for target file: "tmp/extlinks2" */ + h5_fixname(FILENAME[17], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file (without the absolute path) */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* set up prefix for external link */ + if((gapl_id = H5Pcreate(H5P_GROUP_ACCESS)) < 0) TEST_ERROR + if(H5Pset_elink_prefix(gapl_id, TMPDIR) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", gapl_id); + } H5E_END_TRY; + + /* should be able to find the target file from pathnames set via H5Pset_elink_prefix() */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp directory."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_prefix() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_abs_mainpath: test 3 + * + * Purpose: 1. target link: "extlinks3" + * 2. main file: Linux:"/CWD/tmp/extlinks0"; Windows: "<cur drive>:/CWD/tmp/extlinks0" + * 3. target file: "tmp/extlinks3" + * Should be able to access the target file via the main file's absolute path + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb 19, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_abs_mainpath(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE], + cwdpath[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via main file's absolute path (w/new group format)") + else + TESTING("external links via main file's absolute path") + + /* set up name for external linked target file: "extlinks3" */ + h5_fixname(FILENAME[18], fapl, filename2, sizeof filename2); + /* set up name for target file: "tmp/extlinks3" */ + h5_fixname(FILENAME[19], fapl, filename3, sizeof filename3); + + /* create tmp directory and get current working directory path */ + if ((HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) || (HDgetcwd(cwdpath, NAME_BUF_SIZE)==NULL)) + TEST_ERROR + + /* + * set up name for main file: + * Linux: "/CWD/tmp/extlinks0" + * Window: "<cur drive>:/CWD/tmp/extlinks0" + */ + HDstrcpy(tmpname, cwdpath); + HDstrcat(tmpname, "/"); + HDstrcat(tmpname, FILENAME[13]); + h5_fixname(tmpname, fapl, filename1, sizeof filename1); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file from absolute path set for main file */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp directory."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_abs_mainpath() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_rel_mainpath: test 4 + * + * Purpose: 1. target link: "extlinks4" + * 2. main file: "tmp/extlinks0" + * 3. target file: "tmp/extlinks4" + * Should be able to access the target file via the main file's CWD+relative path + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb 19, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_rel_mainpath(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via main file's CWD + relative path(w/new group format)") + else + TESTING("external links via main file's CWD + relative path") + + /* set up name for external linked target file: "extlinks4" */ + h5_fixname(FILENAME[20], fapl, filename2, sizeof filename2); + + if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + + /* set up name for main file: "tmp/extlinks0" */ + h5_fixname(FILENAME[13], fapl, filename1, sizeof filename1); + /* set up name for target file: "tmp/extlinks4" */ + h5_fixname(FILENAME[21], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file from the main file's relative pathname */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in current working directory"); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_rel_mainpath() */ + +/*------------------------------------------------------------------------- + * Function: external_link_cwd: test 5 + * + * Purpose: 1. target link: "extlinks5" + * 2. main file: Linux:"/CWD/tmp/extlinks0"; Window: "<cur drive>:/CWD/tmp/extlinks0" + * 2. target file: "extlinks5" + * Should be able to access the target file in the current working directory + * + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb 19, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_cwd(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE], + cwdpath[NAME_BUF_SIZE]; + + + if(new_format) + TESTING("external links via current working directory(w/new group format)") + else + TESTING("external links via current working directory") + + /* set up name for external linked target file: "extlinks5" */ + /* set up name for target file: "extlinks5" */ + h5_fixname(FILENAME[22], fapl, filename2, sizeof filename2); + + if ((HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) || (HDgetcwd(cwdpath, NAME_BUF_SIZE)==NULL)) + TEST_ERROR + + /* + * set up name for main file: + * Linux: "/CWD/tmp/extlinks0" + * Windows: "<cur drive>:/CWD/tmp/extlinks0" + */ + HDstrcpy(tmpname, cwdpath); + HDstrcat(tmpname, "/"); + HDstrcat(tmpname, FILENAME[13]); + h5_fixname(tmpname, fapl, filename1, sizeof filename1); + + /* Create the target file */ + if((fid=H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file from the current working directory */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in current working directory"); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_cwd() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_abstar: test 6 + * + * Purpose: 1. target link: Linux:"/CWD/tmp/extlinks6"; Windows:"<cur drive>:/CWD/tmp/extlinks6" + * 2. main file: "extlinks0" + * 3. target file: "tmp/extlinks6" + * Should be able to access the target file's absolute path + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb. 20, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_abstar(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE], + cwdpath[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via target's absolute path (w/new group format)") + else + TESTING("external links via target's absolute path") + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + + /* create tmp directory and get current working directory path */ + if ((HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) || (HDgetcwd(cwdpath, NAME_BUF_SIZE)==NULL)) + TEST_ERROR + + /* + * set up name for external linked target file: + * Linux: "/CWD/tmp/extlinks6" + * Windows: "<cur drive>:/CWD/tmp/extlinks6" + */ + HDstrcpy(tmpname, cwdpath); + HDstrcat(tmpname, "/"); + HDstrcat(tmpname, FILENAME[23]); + h5_fixname(tmpname, fapl, filename2, sizeof filename2); + + /* set up name for target file: "tmp/extlinks6" */ + h5_fixname(FILENAME[23], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file with abolute path */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp directory."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_abstar() */ + +/*------------------------------------------------------------------------- + * Function: external_link_abstar_cur: test 7 + * + * Purpose: 1. target link: Linux: "/CWD/tmp/extlinks7"; Windows: "<cur drive>:/CWD/tmp/extlinks7" + * 2. main file: "extlinks0" + * 3. target file: "extlinks7" + * Should be able to access the target file via the main file's CWD. + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb. 20, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_abstar_cur(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE], + cwdpath[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via main file's CWD (w/new group format)") + else + TESTING("external links via main file's CWD") + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + + /* set up name for target file name: "extlinks7" */ + h5_fixname(FILENAME[24], fapl, filename3, sizeof filename3); + + /* create tmp directory and get current working directory path */ + if ((HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) || (HDgetcwd(cwdpath, NAME_BUF_SIZE)==NULL)) + TEST_ERROR + + /* + * set up name for external linked target file: + * Linux: "/CWD/tmp/extlinks7" + * Windows: "<cur drive>:/CWD/tmp/extlinks7" + */ + HDstrcpy(tmpname, cwdpath); + HDstrcat(tmpname, "/"); + HDstrcat(tmpname, FILENAME[25]); + h5_fixname(tmpname, fapl, filename2, sizeof filename2); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file from main file's current working directory */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in current working directory."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_abstar_cur() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_reltar: test 8 + * + * Purpose: 1. target link: Linux:"tmp/extlinks8" + * 2. main file: "extlinks0" + * 3. target file: "tmp/extlinks8" + * Should be able to access the target file via the main file's CWD+ target's relative path + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb. 20, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_reltar(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via main file's CWD + target's relative path(w/new group format)") + else + TESTING("external links via main file's CWD + target's relative path") + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + + /* create tmp directory */ + if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + + /* set up name for target file name: "tmp/extlinks8" */ + /* set up name for external linked target file: "tmp/extlinks8" */ + h5_fixname(FILENAME[26], fapl, filename2, sizeof filename2); + + /* Create the target file */ + if((fid=H5Fcreate(filename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* + * Should be able to find the target file from: + * main file's current working directory + pathname of external linked targetfile + */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp directory."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_reltar() */ + +/*------------------------------------------------------------------------- + * Function: external_link_chdir: test 9 + * + * Purpose: + * 1. target link: "extlinks9" + * 2. main file: "extlinks0" + * 3. target file" "tmp/extlinks9" + * 3. chdir "tmp" + * Should be able to access the target file in current working directory + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * Feb. 20, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_chdir(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via chdir and found in current working directory (w/new group format)") + else + TESTING("external links via chdir and found in current working directory") + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + /* set up name for external linked target file ("extlinks9") */ + h5_fixname(FILENAME[27], fapl, filename2, sizeof filename2); + + /* create tmp directory */ + if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + + /* set up name for target file name ("tmp/extlinks9") */ + h5_fixname(FILENAME[28], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + + if (HDchdir(TMPDIR) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + if (HDchdir("..") < 0) TEST_ERROR + + /* + * Should be able to find the target file from: + * main file's current working directory + pathname of external linked targetfile + */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp directory."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_chdir() */ + + + +#ifdef H5_HAVE_WINDOW_PATH + +/*------------------------------------------------------------------------- + * Function: external_link_win1 + * + * Purpose: + * 1. target link: "/CWD/tmp/extlinks10" + * 2. main file: "extlinks0" + * 3. target file: "extlinks10" + * Should be able to find the target file via main file's CWD + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * April 15, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_win1(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE], + cwdpath[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via main file's CWD (windows)(w/new group format)") + else + TESTING("external links via main file's CWD (windows)") + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + + if (HDgetcwd(cwdpath, NAME_BUF_SIZE)==NULL) + TEST_ERROR + + /* set up name for target link: "/CWD/tmp/extlinks10" */ + HDstrcpy(tmpname, &cwdpath[2]); /* stripped the drive letter to make it rel drive but absolute path */ + HDstrcat(tmpname, "/"); + HDstrcat(tmpname, FILENAME[30]); + h5_fixname(tmpname, fapl, filename2, sizeof filename2); + + /* set up name for target file: "extlinks10" */ + h5_fixname(FILENAME[29], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file via main file's CWD*/ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in CWD."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_win2() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_win2 + * + * Purpose: + * 1. target link: "/CWD/tmp/extlinks11" + * 2. main file: "extlinks0" + * 3. target file: "tmp/extlinks11" + * Should be able to access the target file directly + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * April 15, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_win2(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE], + cwdpath[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via target's rel drive/abs path (windows)(w/new group format)") + else + TESTING("external links via target's rel drive/abs path (windows)") + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + + /* create tmp directory and get current working directory path */ + if ((HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) || (HDgetcwd(cwdpath, NAME_BUF_SIZE)==NULL)) + TEST_ERROR + + /* set up name for target link: "/CWD/tmp/extlinks11" */ + HDstrcpy(tmpname, &cwdpath[2]); /* stripped the drive letter to make it relative drive but absolute path */ + HDstrcat(tmpname, "/"); + HDstrcat(tmpname, FILENAME[31]); + h5_fixname(tmpname, fapl, filename2, sizeof filename2); + + /* set up name for target file: "tmp/extlinks11" */ + h5_fixname(FILENAME[31], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file directly */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_win2() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_win3 + * + * Purpose: + * 1. target link: "<cur drive>:tmp/extlinks12" + * 2. main file: "extlinks0" + * 3. target file: "tmp/extlinks12" + * Should be able to access the target file directly + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * April i15 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_win3(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + int drive=0; + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via target's abs drive/rel path (windows)(w/new group format)") + else + TESTING("external links via target's abs drive/rel path (windows)") + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + + /* create tmp directory */ + if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + + /* set up name for target link: "<drive-letter>:tmp/extlinks12" */ + drive = HDgetdrive(); + sprintf(tmpname, "%c:%s", (drive+'A'-1), FILENAME[32]); + h5_fixname(tmpname, fapl, filename2, sizeof filename2); + + /* set up name for target file: "tmp/extlinks12" */ + h5_fixname(FILENAME[32], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file directly */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_win3() */ + +/*------------------------------------------------------------------------- + * Function: external_link_win4 + * + * Purpose: + * 1. target link: "<cur drive>:tmp/extlinks13" + * 2. main file: "<cur-drive>:extlinks0" + * 3. target file: extlinks13 + * Should be able to access the target file via main file's CWD + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * April 15, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_win4(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + int drive=0; + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via main file's abs drive/rel path (windows)(w/new group format)") + else + TESTING("external links via main file's abs drive/rel path (windows)") + + /* set up name for main file: "<drive-letter>:extlinks0" */ + drive = HDgetdrive(); + sprintf(tmpname, "%c:%s", (drive+'A'-1), FILENAME[12]); + h5_fixname(tmpname, fapl, filename1, sizeof filename1); + + /* set up name for target link: "<drive-letter>:tmp/extlinks13" */ + sprintf(tmpname, "%c:%s", (drive+'A'-1), FILENAME[34]); + h5_fixname(tmpname, fapl, filename2, sizeof filename2); + + /* set up name for target file: "extlinks13" */ + h5_fixname(FILENAME[33], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file via main file's absolute drive/relative path */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in CWD."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_win4() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_win5 + * + * Purpose: + * 1. target link: "<cur drive>:tmp/extlinks14" + * 2. main file: "/CWD/extlinks0" + * 3. target file: "extlinks14" + * Should be able to access the target file via main file's relative drive/absolute path + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * April 15, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_win5(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + int drive=0; + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE], + cwdpath[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via main file's rel drive/abs path (windows)(w/new group format)") + else + TESTING("external links via main file's rel drive/abs path (windows)") + + if (HDgetcwd(cwdpath, NAME_BUF_SIZE)==NULL) + TEST_ERROR + drive = HDgetdrive(); + + /* set up name for main file: "/CWD/extlinks0" */ + HDstrcpy(tmpname, &cwdpath[2]); /* stripped the drive letter to make it rel drive but absolute path */ + HDstrcat(tmpname, "/"); + HDstrcat(tmpname, FILENAME[12]); + h5_fixname(tmpname, fapl, filename1, sizeof filename1); + + /* set up name for target link: "<drive-letter>:tmp/extlinks14" */ + sprintf(tmpname, "%c:%s", (drive+'A'-1), FILENAME[36]); + h5_fixname(tmpname, fapl, filename2, sizeof filename2); + + /* set up name for target file: "extlinks14" */ + h5_fixname(FILENAME[35], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file via main file's rel drive/abs path */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in CWD."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_win5() */ + + +/*------------------------------------------------------------------------- + * Function: external_link_win6 + * + * Purpose: + * 1. target link: "<cur drive+1>:tmp/extlinks15" + * 2. main file: "extlinks0" + * 3. target file: "tmp/extlinks15" + * Should be able to access the target file via target's rel path in the current drive + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Vailin Choi + * April 15, 2008 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +external_link_win6(hid_t fapl, hbool_t new_format) +{ + hid_t fid = (-1); /* File ID */ + hid_t gid = (-1); /* Group IDs */ + int drive=0; + char filename1[NAME_BUF_SIZE], + filename2[NAME_BUF_SIZE], + filename3[NAME_BUF_SIZE], + tmpname[NAME_BUF_SIZE]; + + if(new_format) + TESTING("external links via target's rel path in current drive(windows)(w/new group format)") + else + TESTING("external links via target's rel path in current drive(windows)") + + /* create tmp directory */ + if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST) + TEST_ERROR + drive = HDgetdrive(); + + /* set up name for main file: "extlinks0" */ + h5_fixname(FILENAME[12], fapl, filename1, sizeof filename1); + + /* set up name for target link: "<drive-letter+1>:tmp/extlinks15" */ + sprintf(tmpname, "%c:%s", ((drive+1)+'A'-1), FILENAME[37]); + h5_fixname(tmpname, fapl, filename2, sizeof filename2); + + /* set up name for target file: "tmp/extlinks15" */ + h5_fixname(FILENAME[37], fapl, filename3, sizeof filename3); + + /* Create the target file */ + if((fid=H5Fcreate(filename3, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + if((gid=H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR + + /* closing for target file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + + /* Create the main file */ + if((fid=H5Fcreate(filename1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR + + /* Create external link to target file */ + if(H5Lcreate_external(filename2, "/A", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR + + /* Open object through external link */ + H5E_BEGIN_TRY { + gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT); + } H5E_END_TRY; + + /* should be able to find the target file via target file's rel path in current drive */ + if (gid < 0) { + H5_FAILED(); + puts(" Should have found the file in tmp."); + goto error; + } + + /* closing for main file */ + if(H5Gclose(gid) < 0) TEST_ERROR + if(H5Fclose(fid) < 0) TEST_ERROR + + PASSED(); + return 0; + + error: + H5E_BEGIN_TRY { + H5Gclose (gid); + H5Fclose (fid); + } H5E_END_TRY; + return -1; +} /* end external_link_win6() */ + +#endif /* H5_HAVE_WINDOW_PATH */ + /*------------------------------------------------------------------------- * Function: external_link_recursive @@ -5284,7 +6727,7 @@ linkinfo(hid_t fapl, hbool_t new_format) *------------------------------------------------------------------------- */ static int -check_all_closed(hid_t fapl, hbool_t new_format) +check_all_closed(hid_t fapl, hbool_t new_format, int stopat) { hid_t fid=-1; char filename[NAME_BUF_SIZE]; @@ -5300,7 +6743,7 @@ check_all_closed(hid_t fapl, hbool_t new_format) * To check this, try to create every file used in this test. If * a file is already open, creating it will fail. */ - for(x=0; FILENAME[x] != NULL; x++) + for(x=0; FILENAME[x] != NULL && x < stopat; x++) { h5_fixname(FILENAME[x], fapl, filename, sizeof filename); @@ -10225,6 +11668,8 @@ main(void) my_fapl = fapl; /* General tests... (on both old & new format groups */ + + nerrors += mklinks(my_fapl, new_format) < 0 ? 1 : 0; nerrors += cklinks(my_fapl, new_format) < 0 ? 1 : 0; nerrors += new_links(my_fapl, new_format) < 0 ? 1 : 0; @@ -10263,6 +11708,26 @@ main(void) nerrors += external_link_endian(my_fapl, new_format) < 0 ? 1 : 0; nerrors += external_link_strong(my_fapl, new_format) < 0 ? 1 : 0; + /* tests for external link */ + nerrors += external_link_env(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_prefix(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_abs_mainpath(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_rel_mainpath(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_cwd(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_abstar(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_abstar_cur(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_reltar(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_chdir(my_fapl, new_format) < 0 ? 1 : 0; + +#ifdef H5_HAVE_WINDOW_PATH + nerrors += external_link_win1(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_win2(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_win3(my_fapl, new_format) < 0 ? 1 : 0; + // nerrors += external_link_win4(my_fapl, new_format) < 0 ? 1 : 0; + // nerrors += external_link_win5(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += external_link_win6(my_fapl, new_format) < 0 ? 1 : 0; +#endif + /* These tests assume that external links are a form of UD links, * so assume that everything that passed for external links * above has already been tested for UD links. @@ -10284,7 +11749,8 @@ main(void) nerrors += obj_visit_by_name(my_fapl, new_format) < 0 ? 1 : 0; /* Keep this test last, it's testing files that are used above */ - nerrors += check_all_closed(my_fapl, new_format) < 0 ? 1 : 0; + /* do not do this for files used by external link tests */ + nerrors += check_all_closed(my_fapl, new_format, EXTSTOP) < 0 ? 1 : 0; } /* end for */ /* New group revision feature tests */ @@ -10324,6 +11790,8 @@ main(void) } printf("All link tests passed.\n"); h5_cleanup(FILENAME, fapl); + /* clean up tmp directory created by external link tests */ + HDrmdir(TMPDIR); } else puts("All link tests skipped - Incompatible with current Virtual File Driver"); |