diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2015-10-06 04:31:58 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2015-10-06 04:31:58 (GMT) |
commit | f17eb1e6107fd7c86cbad2a16d66d0c18f4a6959 (patch) | |
tree | 57521002160558658dcf6d7596e5cc66b2f06aaf /c++/test | |
parent | 0fb60ee7aeb183adcc188302b76b660aeaf8d41e (diff) | |
download | hdf5-f17eb1e6107fd7c86cbad2a16d66d0c18f4a6959.zip hdf5-f17eb1e6107fd7c86cbad2a16d66d0c18f4a6959.tar.gz hdf5-f17eb1e6107fd7c86cbad2a16d66d0c18f4a6959.tar.bz2 |
[svn-r27961] Purpose: Partial fix of issues HDFFV-9169 and HDFFV-9167
Description:
Added wrappers for H5P[s/g]et_attr_phase_change and H5P[s/g]et_attr_creation_order
// Sets attribute storage phase change thresholds.
void setAttrPhaseChange(unsigned max_compact = 8, unsigned min_dense = 6)
// Gets attribute storage phase change thresholds.
void getAttrPhaseChange(unsigned& max_compact, unsigned& min_dense)
// Sets tracking and indexing of attribute creation order.
void setAttrCrtOrder(unsigned crt_order_flags)
// Gets tracking and indexing settings for attribute creation order.
unsigned getAttrCrtOrder()
Platforms tested:
Linux/32 2.6 (jam)
Linux/64 (platypus)
Darwin (osx1010test)
Diffstat (limited to 'c++/test')
-rw-r--r-- | c++/test/tattr.cpp | 285 |
1 files changed, 266 insertions, 19 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index c9422ce..5b32554 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -1569,6 +1569,198 @@ static void test_attr_exists() /**************************************************************** ** +** test_attr_dense_create(): Test phase change properties +** Tests "dense" attribute storage creation +** +****************************************************************/ +const H5std_string FILE_CRTPROPS("tattr_crt_properties.h5"); +const int NAME_BUF_SIZE = 1024; +const unsigned MAX_COMPACT_DEF = 8; +const unsigned MIN_DENSE_DEF = 6; + +static void test_attr_dense_create(FileCreatPropList& fcpl, + FileAccPropList& fapl) +{ + // Output message about test being performed + SUBTEST("Dense Attribute Storage Creation"); + + try { + // Create file + H5File fid1 (FILE_CRTPROPS, H5F_ACC_TRUNC, fcpl, fapl); + + // Close file + fid1.close(); + + // Get size of file + h5_stat_size_t empty_filesize; // Size of empty file + empty_filesize = h5_get_file_size(FILE_CRTPROPS.c_str(), fapl.getId()); + if (empty_filesize < 0) + TestErrPrintf("Line %d: file size wrong!\n", __LINE__); + + // Re-open file + fid1.openFile(FILE_CRTPROPS, H5F_ACC_RDWR, fapl); + + // Create dataspace for dataset + DataSpace ds_space(H5S_SCALAR); + + // Create dataset creation property list. + DSetCreatPropList dcpl; + + // Create a dataset + DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space, dcpl); + + unsigned max_compact = 0, min_dense = 0; + + // Retrieve limits for compact/dense attribute storage + dcpl.getAttrPhaseChange(max_compact, min_dense); + verify_val(max_compact, MAX_COMPACT_DEF, "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); + verify_val(min_dense, MIN_DENSE_DEF, "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); + + // Set new compact/dense attribute storage limits to some random numbers + dcpl.setAttrPhaseChange(7, 5); + + // Retrieve limits for compact/dense attribute storage and verify them + dcpl.getAttrPhaseChange(max_compact, min_dense); + verify_val(max_compact, 7, "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); + verify_val(min_dense, 5, "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); + + // Close property list + dcpl.close(); + + // H5O_is_attr_dense_test - un-usable + + // Add attributes, until just before converting to dense storage + char attr_name[NAME_BUF_SIZE]; + unsigned attr_num; + for (attr_num = 0; attr_num < max_compact; attr_num++) + { + // Create attribute + sprintf(attr_name, "attr %02u", attr_num); + Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); + + // Write data to the attribute + attr.write(PredType::NATIVE_UINT, &attr_num); + } // end for + + // H5O_is_attr_dense_test - un-usable + + { // Add one more attribute, to push into "dense" storage + + // Create another attribute + sprintf(attr_name, "attr %02u", attr_num); + Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); + + // Write data to the attribute + attr.write(PredType::NATIVE_UINT, &attr_num); + } + + // Attempt to add attribute again, which should fail + try + { + // Create another attribute + sprintf(attr_name, "attr %02u", attr_num); + Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); + + // continuation here, that means no exception has been thrown + throw InvalidActionException("DataSet::createAttribute", "Maximum number of attributes has been reached"); + } + catch (AttributeIException E) // catching invalid action + {} // do nothing, exception expected + + PASSED(); + } // end try block + + catch (Exception E) { + issue_fail_msg("test_attr_dense_create()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_attr_dense_create() + +/**************************************************************** +** +** test_attr_corder_create_basic(): Test creation order properties +** Tests creating an object w/attribute creation order info +** +****************************************************************/ +static void test_attr_corder_create_basic(FileCreatPropList& fcpl, + FileAccPropList& fapl) +{ + // Output message about test being performed + SUBTEST("Basic Code for Attributes with Creation Order Info"); + + try { + // Create file + H5File fid1 (FILE_CRTPROPS, H5F_ACC_TRUNC, fcpl, fapl); + + // Create dataset creation property list. + DSetCreatPropList dcpl; + + // Get creation order indexing on object + unsigned crt_order_flags = 0; + crt_order_flags = dcpl.getAttrCrtOrder(); + verify_val(crt_order_flags, 0, "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); + + // Setting invalid combination of a attribute order creation order + // indexing on should fail + try { + dcpl.setAttrCrtOrder(H5P_CRT_ORDER_INDEXED); + + // continuation here, that means no exception has been thrown + throw InvalidActionException("DSetCreatPropList::getAttrCrtOrder", "Indexing cannot be set alone, order tracking is required"); + } + catch (PropListIException E) // catching invalid action + {} // do nothing, exception expected + + // Set attribute creation order tracking & indexing for object then + // verify them + dcpl.setAttrCrtOrder(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED); + crt_order_flags = dcpl.getAttrCrtOrder(); + verify_val(crt_order_flags, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED), "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); + + // Create dataspace for dataset + DataSpace ds_space(H5S_SCALAR); + + // Create a dataset + DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space, dcpl); + + // Close dataspace + ds_space.close(); + + // Check on dataset's attribute storage status. + // NOTE: Wrappers not available yet (H5O_is_attr_empty_test + // and H5O_is_attr_dense_test) + + // Close dataset + dataset.close(); + + // Close property list + dcpl.close(); + + // Close file + fid1.close(); + + // Re-open file + fid1.openFile(FILE_CRTPROPS, H5F_ACC_RDWR, fapl); + + // Open dataset created previously + dataset = fid1.openDataSet(DSET1_NAME); + + // Retrieve dataset creation property list for the dataset + dcpl = dataset.getCreatePlist(); + + // Query the attribute creation properties + crt_order_flags = dcpl.getAttrCrtOrder(); + verify_val(crt_order_flags, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED), "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); + + PASSED(); + } // end try block + + catch (Exception E) { + issue_fail_msg("test_attr_corder_create_basic()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_attr_corder_create_basic() + +/**************************************************************** +** ** test_attr(): Main attribute testing routine. ** ****************************************************************/ @@ -1580,26 +1772,80 @@ void test_attr() // Output message about test being performed MESSAGE(5, ("Testing Attributes\n")); - test_attr_basic_write(); // Test basic H5A writing code - test_attr_getname(); // Test overloads of Attribute::getName - test_attr_rename(); // Test renaming attribute - test_attr_basic_read(); // Test basic H5A reading code - - test_attr_compound_write(); // Test complex datatype H5A writing code - test_attr_compound_read(); // Test complex datatype H5A reading code - - test_attr_scalar_write(); // Test scalar dataspace H5A writing code - test_attr_scalar_read(); // Test scalar dataspace H5A reading code - - test_attr_mult_write(); // Test writing multiple attributes - test_attr_mult_read(); // Test reading multiple attributes - test_attr_delete(); // Test deleting attributes - - test_attr_dtype_shared(); // Test using shared datatypes in attributes - - test_string_attr(); // Test read/write string attribute - test_attr_exists(); // Test H5Location::attrExists + try + { + // Create a default file access property list + FileAccPropList fapl; + + // Copy the file access property list for new format test + FileAccPropList fapl_new = fapl; + + // Set the "use the latest version of the format" bounds for creating + // objects in the file + fapl_new.setLibverBounds(H5F_LIBVER_LATEST, H5F_LIBVER_LATEST); + + // Create a default file creation property list + FileCreatPropList fcpl; + + // Copy the file creation property list for new format test + FileCreatPropList fcpl_new = fcpl; + + // Wrappers for ..._shared_mesg_nindexes are not available, skip + // use_shared test + + // Loop over using new group format + hbool_t new_format; + for (new_format = FALSE; new_format <= TRUE; new_format++) + { + FileAccPropList curr_fapl; + + // Set the file access proplist for the type of format + if (new_format) + { + MESSAGE(7, ("testing with new file format\n")); + curr_fapl = fapl_new; + } + else + { + MESSAGE(7, ("testing with old file format\n")); + curr_fapl = fapl; + } + + test_attr_basic_write(); // Test basic H5A writing code + test_attr_getname(); // Test overloads of Attribute::getName + test_attr_rename(); // Test renaming attribute + test_attr_basic_read(); // Test basic H5A reading code + + test_attr_compound_write(); // Test complex datatype H5A writing code + test_attr_compound_read(); // Test complex datatype H5A reading code + + test_attr_scalar_write(); // Test scalar dataspace H5A writing code + test_attr_scalar_read(); // Test scalar dataspace H5A reading code + + test_attr_mult_write(); // Test writing multiple attributes + test_attr_mult_read(); // Test reading multiple attributes + test_attr_delete(); // Test deleting attributes + + test_attr_dtype_shared(); // Test using shared datatypes in attributes + + test_string_attr(); // Test read/write string attribute + test_attr_exists(); // Test H5Location::attrExists + + // Test with new format + if (new_format) + { + // Test dense attribute storage creation + test_attr_dense_create(fcpl, curr_fapl); + + // Test create objects with attribute creation info + test_attr_corder_create_basic(fcpl, curr_fapl); + } + } // end for + } // end try block + catch (Exception E) { + issue_fail_msg("test_attr()", __LINE__, __FILE__, E.getCDetailMsg()); + } } // test_attr() /*------------------------------------------------------------------------- @@ -1626,5 +1872,6 @@ void cleanup_attr() HDremove(FILE_SCALAR.c_str()); HDremove(FILE_MULTI.c_str()); HDremove(FILE_DTYPE.c_str()); + HDremove(FILE_CRTPROPS.c_str()); } |