diff options
Diffstat (limited to 'c++/test/tlinks.cpp')
-rw-r--r-- | c++/test/tlinks.cpp | 416 |
1 files changed, 140 insertions, 276 deletions
diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp index 6e990c9..491cd6a 100644 --- a/c++/test/tlinks.cpp +++ b/c++/test/tlinks.cpp @@ -31,288 +31,27 @@ using namespace H5; #include "h5test.h" #include "h5cpputil.h" // C++ utilility header file -// A lot of the definition inherited from C test links.c is left here until -// the H5L API is implemented and tests are completed - BMR 10/19/2009 -/* - * This file needs to access private information from the H5G package. - * This file also needs to access the group testing code. - */ -//#define H5G_FRIEND -//#define H5G_TESTING - -//#include "h5test.h" -//#include "H5Gpkg.h" /* Groups */ -//#include "H5Iprivate.h" /* IDs */ -//#include "H5Lprivate.h" /* Links */ - -/* File for external link test. Created with gen_udlinks.c */ -#define LINKED_FILE "be_extlink2.h5" - -#if 0 -const char *FILENAME[] = { - "links0", - "links1", - "links2", - "links3", - "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: */ - "tmp/extlinks14", /* 35: */ - "tmp/extlinks15", /* 36: */ - "extlinks16A", /* 37: */ /* TESTS for H5P_set_elink_fapl */ - "extlinks16B", /* 38: */ - "extlinks17", /* 39: */ - "extlinks18A", /* 40: */ - "extlinks18B", /* 41: */ - "extlinks19A", /* 42: */ - "extlinks19B", /* 43: */ - "extlinks20", /* 44: */ - NULL -}; - -#endif // 0 - -#define TMPDIR "tmp" - -#define FAMILY_SIZE 1024 -#define CORE_INCREMENT 1024 -#define NUM400 400 - -/* 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) - -/* Link type IDs */ -#define UD_HARD_TYPE 201 -#define UD_CB_TYPE H5L_TYPE_MAX -#define UD_PLIST_TYPE 128 -#define UD_CBFAIL_TYPE UD_PLIST_TYPE -#define UD_ERROR_TYPE 189 -#define UD_BAD_TYPE1 H5L_TYPE_HARD -#define UD_BAD_TYPE2 (H5L_TYPE_UD_MIN - 5) -#define UD_BAD_VERS (H5L_LINK_CLASS_T_VERS + 1) - -#define DEST_PROP_NAME "destination_group" -#define REREG_TARGET_NAME "rereg_target" - -#define UD_CB_LINK_NAME "ud_callback_link" -#define NEW_UD_CB_LINK_NAME "ud_callback_link2" -#define UD_CB_TARGET "ud_target" -#define UD_CB_TARGET_LEN 10 - -#define LE_FILENAME "le_extlink1.h5" -#define BE_FILENAME "be_extlink1.h5" - -#define ELINK_CB_FAM_SIZE (hsize_t) 100 - #define H5L_DIM1 100 #define H5L_DIM2 100 -/* Creation order macros */ -#define CORDER_SOFT_GROUP_NAME "corder_soft_group" -#define CORDER_NLINKS 18 - -/* Timestamp macros */ -#define TIMESTAMP_GROUP_1 "timestamp1" -#define TIMESTAMP_GROUP_2 "timestamp2" - -/* Link iteration struct */ -typedef struct { - H5_iter_order_t order; /* Direction of iteration */ - unsigned ncalled; /* # of times callback is entered */ - unsigned nskipped; /* # of links skipped */ - int stop; /* # of iterations to stop after */ - int64_t curr; /* Current creation order value */ - size_t max_visit; /* Size of "visited link" flag array */ - hbool_t *visited; /* Pointer to array of "visited link" flags */ -} link_iter_info_t; - -#if 0 -/* Link visit structs */ -typedef struct { - const char *path; /* Path to link */ - H5L_type_t type; /* Type of link */ -} link_visit_t; -static const link_visit_t lvisit0[] = { - {"Dataset_zero", H5L_TYPE_HARD}, - {"Group1", H5L_TYPE_HARD}, - {"Group1/Dataset_one", H5L_TYPE_HARD}, - {"Group1/Group2", H5L_TYPE_HARD}, - {"Group1/Group2/Dataset_two", H5L_TYPE_HARD}, - {"Group1/Group2/Type_two", H5L_TYPE_HARD}, - {"Group1/Group2/hard_zero", H5L_TYPE_HARD}, - {"Group1/Type_one", H5L_TYPE_HARD}, - {"Group1/hard_one", H5L_TYPE_HARD}, - {"Type_zero", H5L_TYPE_HARD}, - {"ext_dangle", H5L_TYPE_EXTERNAL}, - {"ext_one", H5L_TYPE_EXTERNAL}, - {"hard_one", H5L_TYPE_HARD}, - {"hard_two", H5L_TYPE_HARD}, - {"hard_zero", H5L_TYPE_HARD}, - {"soft_dangle", H5L_TYPE_SOFT}, - {"soft_one", H5L_TYPE_SOFT}, - {"soft_two", H5L_TYPE_SOFT} -}; -static const link_visit_t lvisit1[] = { - {"Dataset_one", H5L_TYPE_HARD}, - {"Group2", H5L_TYPE_HARD}, - {"Group2/Dataset_two", H5L_TYPE_HARD}, - {"Group2/Type_two", H5L_TYPE_HARD}, - {"Group2/hard_zero", H5L_TYPE_HARD}, - {"Group2/hard_zero/Dataset_zero", H5L_TYPE_HARD}, - {"Group2/hard_zero/Group1", H5L_TYPE_HARD}, - {"Group2/hard_zero/Type_zero", H5L_TYPE_HARD}, - {"Group2/hard_zero/ext_dangle", H5L_TYPE_EXTERNAL}, - {"Group2/hard_zero/ext_one", H5L_TYPE_EXTERNAL}, - {"Group2/hard_zero/hard_one", H5L_TYPE_HARD}, - {"Group2/hard_zero/hard_two", H5L_TYPE_HARD}, - {"Group2/hard_zero/hard_zero", H5L_TYPE_HARD}, - {"Group2/hard_zero/soft_dangle", H5L_TYPE_SOFT}, - {"Group2/hard_zero/soft_one", H5L_TYPE_SOFT}, - {"Group2/hard_zero/soft_two", H5L_TYPE_SOFT}, - {"Type_one", H5L_TYPE_HARD}, - {"hard_one", H5L_TYPE_HARD} -}; -static const link_visit_t lvisit2[] = { - {"Dataset_two", H5L_TYPE_HARD}, - {"Type_two", H5L_TYPE_HARD}, - {"hard_zero", H5L_TYPE_HARD}, - {"hard_zero/Dataset_zero", H5L_TYPE_HARD}, - {"hard_zero/Group1", H5L_TYPE_HARD}, - {"hard_zero/Group1/Dataset_one", H5L_TYPE_HARD}, - {"hard_zero/Group1/Group2", H5L_TYPE_HARD}, - {"hard_zero/Group1/Type_one", H5L_TYPE_HARD}, - {"hard_zero/Group1/hard_one", H5L_TYPE_HARD}, - {"hard_zero/Type_zero", H5L_TYPE_HARD}, - {"hard_zero/ext_dangle", H5L_TYPE_EXTERNAL}, - {"hard_zero/ext_one", H5L_TYPE_EXTERNAL}, - {"hard_zero/hard_one", H5L_TYPE_HARD}, - {"hard_zero/hard_two", H5L_TYPE_HARD}, - {"hard_zero/hard_zero", H5L_TYPE_HARD}, - {"hard_zero/soft_dangle", H5L_TYPE_SOFT}, - {"hard_zero/soft_one", H5L_TYPE_SOFT}, - {"hard_zero/soft_two", H5L_TYPE_SOFT} -}; - -typedef struct { - unsigned idx; /* Index in link visit structure */ - const link_visit_t *info; /* Pointer to the link visit structure to use */ -} lvisit_ud_t; - - -/* Object visit structs */ +// Object visit structs typedef struct { const char *path; /* Path to object */ H5O_type_t type; /* Type of object */ } obj_visit_t; -static const obj_visit_t ovisit0_old[] = { - {".", H5O_TYPE_GROUP}, - {"Dataset_zero", H5O_TYPE_DATASET}, - {"Group1", H5O_TYPE_GROUP}, - {"Group1/Dataset_one", H5O_TYPE_DATASET}, - {"Group1/Group2", H5O_TYPE_GROUP}, - {"Group1/Group2/Dataset_two", H5O_TYPE_DATASET}, - {"Group1/Group2/Type_two", H5O_TYPE_NAMED_DATATYPE}, - {"Group1/Type_one", H5O_TYPE_NAMED_DATATYPE}, - {"Type_zero", H5O_TYPE_NAMED_DATATYPE} -}; -static const obj_visit_t ovisit0_new[] = { - {".", H5O_TYPE_GROUP}, - {"Dataset_zero", H5O_TYPE_DATASET}, - {"Group1", H5O_TYPE_GROUP}, - {"Group1/Dataset_one", H5O_TYPE_DATASET}, - {"Group1/Group2", H5O_TYPE_GROUP}, - {"Group1/Group2/Dataset_two", H5O_TYPE_DATASET}, - {"Group1/Group2/Type_two", H5O_TYPE_NAMED_DATATYPE}, - {"Group1/Type_one", H5O_TYPE_NAMED_DATATYPE}, - {"Type_zero", H5O_TYPE_NAMED_DATATYPE} -}; -static const obj_visit_t ovisit1_old[] = { - {".", H5O_TYPE_GROUP}, - {"Dataset_one", H5O_TYPE_DATASET}, - {"Group2", H5O_TYPE_GROUP}, - {"Group2/Dataset_two", H5O_TYPE_DATASET}, - {"Group2/Type_two", H5O_TYPE_NAMED_DATATYPE}, - {"Group2/hard_zero", H5O_TYPE_GROUP}, - {"Group2/hard_zero/Dataset_zero", H5O_TYPE_DATASET}, - {"Group2/hard_zero/Type_zero", H5O_TYPE_NAMED_DATATYPE}, - {"Type_one", H5O_TYPE_NAMED_DATATYPE} -}; -static const obj_visit_t ovisit1_new[] = { - {".", H5O_TYPE_GROUP}, - {"Dataset_one", H5O_TYPE_DATASET}, - {"Group2", H5O_TYPE_GROUP}, - {"Group2/Dataset_two", H5O_TYPE_DATASET}, - {"Group2/Type_two", H5O_TYPE_NAMED_DATATYPE}, - {"Group2/hard_zero", H5O_TYPE_GROUP}, - {"Group2/hard_zero/Dataset_zero", H5O_TYPE_DATASET}, - {"Group2/hard_zero/Type_zero", H5O_TYPE_NAMED_DATATYPE}, - {"Type_one", H5O_TYPE_NAMED_DATATYPE} -}; -static const obj_visit_t ovisit2_old[] = { - {".", H5O_TYPE_GROUP}, - {"Dataset_two", H5O_TYPE_DATASET}, - {"Type_two", H5O_TYPE_NAMED_DATATYPE}, - {"hard_zero", H5O_TYPE_GROUP}, - {"hard_zero/Dataset_zero", H5O_TYPE_DATASET}, - {"hard_zero/Group1", H5O_TYPE_GROUP}, - {"hard_zero/Group1/Dataset_one", H5O_TYPE_DATASET}, - {"hard_zero/Group1/Type_one", H5O_TYPE_NAMED_DATATYPE}, - {"hard_zero/Type_zero", H5O_TYPE_NAMED_DATATYPE} -}; -static const obj_visit_t ovisit2_new[] = { - {".", H5O_TYPE_GROUP}, - {"Dataset_two", H5O_TYPE_DATASET}, - {"Type_two", H5O_TYPE_NAMED_DATATYPE}, - {"hard_zero", H5O_TYPE_GROUP}, - {"hard_zero/Dataset_zero", H5O_TYPE_DATASET}, - {"hard_zero/Group1", H5O_TYPE_GROUP}, - {"hard_zero/Group1/Dataset_one", H5O_TYPE_DATASET}, - {"hard_zero/Group1/Type_one", H5O_TYPE_NAMED_DATATYPE}, - {"hard_zero/Type_zero", H5O_TYPE_NAMED_DATATYPE} -}; +// User data for callback function typedef struct { unsigned idx; /* Index in object visit structure */ const obj_visit_t *info; /* Pointer to the object visit structure to use */ } ovisit_ud_t; -#endif static const char *FILENAME[] = { "link0", "link1.h5", "link2.h5", + "visit", NULL }; @@ -842,6 +581,140 @@ static void test_num_links(hid_t fapl_id, hbool_t new_format) } // test_num_links +// Data for visit on the file +static const obj_visit_t file_visit[] = { + {".", H5O_TYPE_GROUP}, + {"Data", H5O_TYPE_GROUP}, + {"Data/Compressed_Data", H5O_TYPE_DATASET}, + {"Data/Float_Data", H5O_TYPE_DATASET}, +}; + +// Data for visit on the group +static const obj_visit_t group_visit[] = { + {".", H5O_TYPE_GROUP}, + {"Compressed_Data", H5O_TYPE_DATASET}, + {"Float_Data", H5O_TYPE_DATASET}, +}; + +const H5std_string FILE_NAME("tvisit.h5"); +const H5std_string GROUP_NAME("/Data"); +const H5std_string DSET1_NAME("/Data/Compressed_Data"); +const H5std_string DSET2_NAME("/Data/Float_Data"); +const int RANK = 2; +const int DIM1 = 2; + +// Operator function +static int visit_obj_cb(H5Object& obj, const H5std_string name, const H5O_info_t *oinfo, void *_op_data) +{ + ovisit_ud_t *op_data = static_cast <ovisit_ud_t *>(_op_data); + + // Check for correct object information + if(strcmp(op_data->info[op_data->idx].path, name.c_str())) return(H5_ITER_ERROR); + if(op_data->info[op_data->idx].type != oinfo->type) return(H5_ITER_ERROR); + + // Advance to next location + op_data->idx++; + + return(H5_ITER_CONT); +} + +/*------------------------------------------------------------------------- + * Function: test_visit + * + * Purpose Test H5Object::visit + * + * Return None + * + * February 8, 2019 + *------------------------------------------------------------------------- + */ +static void test_visit(hid_t fapl_id, hbool_t new_format) +{ + hsize_t dims[2]; + hsize_t cdims[2]; + char filename[NAME_BUF_SIZE]; + + if(new_format) + SUBTEST("H5Object::visit (w/new group format)") + else + SUBTEST("H5Object::visit") + + try + { + // Use the file access template id to create a file access prop. list + FileAccPropList fapl(fapl_id); + + // Build the hdf5 file name and create the file + h5_fixname(FILENAME[3], fapl_id, filename, sizeof filename); + H5File *file = new H5File(filename, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); + + // Create a group + Group* group = new Group(file->createGroup(GROUP_NAME)); + + // Create a chunked/compressed dataset within this group specified by path + dims[0] = 20; + dims[1] = 2; + cdims[0] = 2; + cdims[1] = 2; + DataSpace *dataspace = new DataSpace(RANK, dims); // create new dspace + DSetCreatPropList ds_creatplist; // create dataset creation prop list + ds_creatplist.setChunk(2, cdims); // then modify it for compression + ds_creatplist.setDeflate(6); + + DataSet* dataset = new DataSet(file->createDataSet(DSET1_NAME, + PredType::NATIVE_INT, *dataspace, ds_creatplist)); + + delete dataset; + delete dataspace; + + // Create another dataset + dims[0] = 5; + dims[1] = 2; + dataspace = new DataSpace(RANK, dims); // create second dspace + dataset = new DataSet(file->createDataSet(DSET2_NAME, + PredType::NATIVE_FLOAT, *dataspace)); + + // Close everything + delete dataset; + delete dataspace; + delete group; + delete file; + + // Reopen the file and group in the file. + file = new H5File(filename, H5F_ACC_RDWR); + group = new Group(file->openGroup("Data")); + + // Open the group + dataset = new DataSet(group->openDataSet(DSET2_NAME)); + delete dataset; + + // Visit objects in the file + ovisit_ud_t udata; /* User-data for visiting */ + udata.idx = 0; + udata.info = file_visit; + + file->visit(H5_INDEX_NAME, H5_ITER_INC, visit_obj_cb, &udata, H5O_INFO_BASIC); + + // Visit objects in the group + udata.idx = 0; + udata.info = group_visit; + + group->visit(H5_INDEX_NAME, H5_ITER_INC, visit_obj_cb, &udata, H5O_INFO_BASIC); + + // Close the group and file. + delete group; + delete file; + + PASSED(); + } // end of try block + catch (Exception& E) + { + cerr << "in catch" << endl; + issue_fail_msg("test_visit()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_visit() + + /*------------------------------------------------------------------------- * Function: test_links * @@ -858,7 +731,8 @@ void test_links() hid_t fapl_id, fapl2_id; /* File access property lists */ unsigned new_format; /* Whether to use the new format or not */ - fapl_id = h5_fileaccess(); + if((fapl_id = h5_fileaccess()) < 0) + throw Exception("test_links", "Unable to get file access property list"); // Output message about test being performed MESSAGE(5, ("Testing Various Links\n")); @@ -891,24 +765,18 @@ void test_links() test_move(my_fapl_id, new_format); test_copy(my_fapl_id, new_format); test_lcpl(my_fapl_id, new_format); + test_visit(my_fapl_id, new_format); } /* end for */ /* Close 2nd FAPL */ H5Pclose(fapl2_id); h5_clean_files(FILENAME, fapl_id); - - /* Test that external links can be used after a library reset. MUST be - * called last so the reset doesn't interfere with the property lists. This - * routine will delete its own file. */ - /* nerrors += external_reset_register() < 0 ? 1 : 0; - */ } catch (Exception& E) { issue_fail_msg("test_links()", __LINE__, __FILE__, E.getCDetailMsg()); } - } @@ -926,7 +794,3 @@ void cleanup_links() HDremove(FILENAME[0]); HDremove(FILENAME[1]); } - - - - |