2005-03-20 11:47:55 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2005-10-01 23:29:18 +08:00
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:36 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2005-10-01 23:29:18 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
FILE
|
|
|
|
tattr.cpp - HDF5 C++ testing the functionalities associated with the
|
|
|
|
C attribute interface (H5A)
|
|
|
|
|
|
|
|
***************************************************************************/
|
2021-06-01 21:49:39 +08:00
|
|
|
#include <cfloat>
|
|
|
|
#include <cmath>
|
2005-03-20 11:47:55 +08:00
|
|
|
#include <iostream>
|
2016-10-20 04:50:17 +08:00
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2016-10-20 04:50:17 +08:00
|
|
|
#include <string>
|
2020-09-30 22:27:10 +08:00
|
|
|
#include "H5Cpp.h" // C++ API header file
|
2016-10-20 04:50:17 +08:00
|
|
|
using namespace H5;
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2016-10-20 04:50:17 +08:00
|
|
|
#include "h5test.h"
|
2020-09-30 22:27:10 +08:00
|
|
|
#include "h5cpputil.h" // C++ utilility header file
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
const H5std_string FILE_BASIC("tattr_basic.h5");
|
|
|
|
const H5std_string FILE_COMPOUND("tattr_compound.h5");
|
|
|
|
const H5std_string FILE_SCALAR("tattr_scalar.h5");
|
|
|
|
const H5std_string FILE_MULTI("tattr_multi.h5");
|
|
|
|
const H5std_string FILE_DTYPE("tattr_dtype.h5");
|
|
|
|
const H5std_string ATTR_TMP_NAME("temp_attr_name");
|
|
|
|
const H5std_string FATTR_TMP_NAME("temp_fattr_name");
|
2020-09-30 22:27:10 +08:00
|
|
|
const size_t ATTR_MAX_DIMS = 7;
|
2005-03-20 11:47:55 +08:00
|
|
|
|
|
|
|
/* 3-D dataset with fixed dimensions */
|
2020-09-30 22:27:10 +08:00
|
|
|
const int SPACE1_RANK = 3;
|
2015-03-15 14:49:20 +08:00
|
|
|
const hsize_t SPACE1_DIM1 = 3;
|
|
|
|
const hsize_t SPACE1_DIM2 = 15;
|
|
|
|
const hsize_t SPACE1_DIM3 = 13;
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2007-03-18 00:26:53 +08:00
|
|
|
/* Object names */
|
2006-04-06 00:50:56 +08:00
|
|
|
const H5std_string DSET1_NAME("Dataset1");
|
|
|
|
const H5std_string GROUP1_NAME("/Group1");
|
|
|
|
const H5std_string TYPE1_NAME("/Type");
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2005-03-20 11:47:55 +08:00
|
|
|
/* Attribute Rank & Dimensions */
|
2006-04-06 00:50:56 +08:00
|
|
|
const H5std_string ATTR1_NAME("Attr1");
|
2020-09-30 22:27:10 +08:00
|
|
|
const int ATTR1_RANK = 1;
|
|
|
|
const hsize_t ATTR1_DIM1 = 3;
|
|
|
|
int attr_data1[ATTR1_DIM1] = {512, -234, 98123}; /* Test data for 1st attribute */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2012-09-28 07:26:16 +08:00
|
|
|
// File attribute, using the same rank and dimensions as ATTR1_NAME's
|
|
|
|
const H5std_string FATTR1_NAME("File Attr1");
|
|
|
|
const H5std_string FATTR2_NAME("File Attr2");
|
|
|
|
|
2006-04-06 00:50:56 +08:00
|
|
|
const H5std_string ATTR2_NAME("Attr2");
|
2020-09-30 22:27:10 +08:00
|
|
|
const int ATTR2_RANK = 2;
|
|
|
|
const hsize_t ATTR2_DIM1 = 2;
|
|
|
|
const hsize_t ATTR2_DIM2 = 2;
|
|
|
|
int attr_data2[ATTR2_DIM1][ATTR2_DIM2] = {{7614, -416}, {197814, -3}}; /* Test data for 2nd attribute */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2006-04-06 00:50:56 +08:00
|
|
|
const H5std_string ATTR3_NAME("Attr3");
|
2020-09-30 22:27:10 +08:00
|
|
|
const int ATTR3_RANK = 3;
|
|
|
|
const hsize_t ATTR3_DIM1 = 2;
|
|
|
|
const hsize_t ATTR3_DIM2 = 2;
|
|
|
|
const hsize_t ATTR3_DIM3 = 2;
|
|
|
|
double attr_data3[ATTR3_DIM1][ATTR3_DIM2][ATTR3_DIM3] = {
|
|
|
|
{{2.3, -26.1}, {0.123, -10.0}}, {{981724.2, -0.91827}, {2.0, 23.0}}}; /* Test data for 3rd attribute */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2006-04-06 00:50:56 +08:00
|
|
|
const H5std_string ATTR4_NAME("Attr4");
|
2020-09-30 22:27:10 +08:00
|
|
|
const int ATTR4_RANK = 2;
|
|
|
|
const hsize_t ATTR4_DIM1 = 2;
|
|
|
|
const hsize_t ATTR4_DIM2 = 2;
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2006-04-06 00:50:56 +08:00
|
|
|
const H5std_string ATTR4_FIELDNAME1("i");
|
|
|
|
const H5std_string ATTR4_FIELDNAME2("d");
|
|
|
|
const H5std_string ATTR4_FIELDNAME3("c");
|
2020-09-30 22:27:10 +08:00
|
|
|
size_t attr4_field1_off = 0;
|
|
|
|
size_t attr4_field2_off = 0;
|
|
|
|
size_t attr4_field3_off = 0;
|
2005-03-20 11:47:55 +08:00
|
|
|
struct attr4_struct {
|
2020-09-30 22:27:10 +08:00
|
|
|
int i;
|
2005-03-20 11:47:55 +08:00
|
|
|
double d;
|
2020-09-30 22:27:10 +08:00
|
|
|
char c;
|
|
|
|
} attr_data4[ATTR4_DIM1][ATTR4_DIM2] = {
|
|
|
|
{{3, -26.1, 'd'}, {-100000, 0.123, '3'}},
|
|
|
|
{{-23, 981724.2, 'Q'}, {0, 2.0, '\n'}}}; // Test data for 4th attribute
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2006-04-06 00:50:56 +08:00
|
|
|
const H5std_string ATTR5_NAME("Attr5");
|
2020-09-30 22:27:10 +08:00
|
|
|
const int ATTR5_RANK = 0;
|
2022-01-28 22:31:26 +08:00
|
|
|
float attr_data5 = -5.123F; // Test data for 5th attribute
|
2005-03-20 11:47:55 +08:00
|
|
|
|
|
|
|
/* Info for another attribute */
|
2006-04-06 00:50:56 +08:00
|
|
|
const H5std_string ATTR1A_NAME("Attr1_a");
|
2020-09-30 22:27:10 +08:00
|
|
|
int attr_data1a[ATTR1_DIM1] = {256, 11945, -22107};
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_basic_write
|
|
|
|
*
|
|
|
|
* Purpose Test basic write attribute on both datasets and groups.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_basic_write()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
|
|
|
|
hsize_t dims2[] = {ATTR1_DIM1};
|
|
|
|
hsize_t dims3[] = {ATTR2_DIM1, ATTR2_DIM2};
|
|
|
|
int read_data1[ATTR1_DIM1] = {0}; // Buffer for reading 1st attribute
|
2015-03-15 14:49:20 +08:00
|
|
|
hsize_t i;
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Basic Attribute Writing Functions");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create file
|
2020-09-30 22:27:10 +08:00
|
|
|
H5File fid1(FILE_BASIC, H5F_ACC_TRUNC);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
DataSpace ds_space(SPACE1_RANK, dims1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/*
|
|
|
|
* Test attribute with dataset
|
|
|
|
*/
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
|
|
|
DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
DataSpace att_space(ATTR1_RANK, dims2);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a file attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute file_attr2 = fid1.createAttribute(FATTR1_NAME, PredType::NATIVE_INT, att_space);
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a file attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute file_attr1 = fid1.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, att_space);
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create an attribute for the dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute ds_attr1 = dataset.createAttribute(ATTR1_NAME, PredType::NATIVE_INT, att_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Try creating an attribute that already exists. This should fail
|
|
|
|
// since two attributes cannot have the same name. If an exception
|
|
|
|
// is not thrown for this action by createAttribute, then throw an
|
|
|
|
// invalid action exception.
|
|
|
|
try {
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute invalid_attr = dataset.createAttribute(ATTR1_NAME, PredType::NATIVE_INT, att_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// continuation here, that means no exception has been thrown
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("H5File::createDataSet",
|
|
|
|
"Library allowed overwrite of existing dataset");
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (AttributeIException &E) // catching invalid creating attribute
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
ds_attr1.write(PredType::NATIVE_INT, attr_data1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information immediately, without closing attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
ds_attr1.read(PredType::NATIVE_INT, read_data1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR1_DIM1; i++)
|
|
|
|
if (attr_data1[i] != read_data1[i])
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data1[%" PRIuHSIZE
|
|
|
|
"]=%d,read_data1[%" PRIuHSIZE "]=%d\n",
|
2021-03-05 05:06:30 +08:00
|
|
|
__LINE__, i, attr_data1[i], i, read_data1[i]);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create two more attributes for this dataset, but only write to one.
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute ds_attr2 = dataset.createAttribute(ATTR2_NAME, PredType::NATIVE_INT, att_space);
|
|
|
|
Attribute ds_attr3 = dataset.createAttribute(ATTR3_NAME, PredType::NATIVE_INT, att_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
ds_attr2.write(PredType::NATIVE_INT, attr_data1a);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information immediately, without closing attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
ds_attr2.read(PredType::NATIVE_INT, read_data1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR1_DIM1; i++)
|
|
|
|
if (attr_data1a[i] != read_data1[i])
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data1a[%" PRIuHSIZE
|
|
|
|
"]=%d,read_data1[%" PRIuHSIZE "]=%d\n",
|
2020-09-30 22:27:10 +08:00
|
|
|
__LINE__, i, attr_data1a[i], i, read_data1[i]);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close both attributes
|
|
|
|
ds_attr1.close();
|
|
|
|
ds_attr2.close();
|
|
|
|
ds_attr3.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/*
|
|
|
|
* Test attribute with group
|
|
|
|
*/
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create group in file fid1
|
2020-09-30 22:27:10 +08:00
|
|
|
Group group = fid1.createGroup(GROUP1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for attribute
|
|
|
|
DataSpace sid3(ATTR2_RANK, dims3);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create an attribute for the group
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute gr_attr = group.createAttribute(ATTR2_NAME, PredType::NATIVE_INT, sid3);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check storage size for attribute
|
|
|
|
hsize_t attr_size = gr_attr.getStorageSize();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(attr_size), static_cast<long>(ATTR2_DIM1 * ATTR2_DIM2 * sizeof(int)),
|
2020-09-30 22:27:10 +08:00
|
|
|
"Attribute::getStorageSize", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Try to create the same attribute again (should fail)
|
|
|
|
try {
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute invalid_attr = group.createAttribute(ATTR2_NAME, PredType::NATIVE_INT, sid3);
|
2005-03-20 11:47:55 +08:00
|
|
|
// continuation here, that means no exception has been thrown
|
2005-08-14 04:53:35 +08:00
|
|
|
throw InvalidActionException("H5Group::createAttribute",
|
2020-09-30 22:27:10 +08:00
|
|
|
"Attempting to create an existing attribute");
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (AttributeIException &E) // catching invalid creating attribute
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
gr_attr.write(PredType::NATIVE_INT, attr_data2);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check storage size for attribute
|
|
|
|
attr_size = gr_attr.getStorageSize();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(attr_size), static_cast<long>(ATTR2_DIM1 * ATTR2_DIM2 * sizeof(int)),
|
2020-09-30 22:27:10 +08:00
|
|
|
"Attribute::getStorageSize", __LINE__, __FILE__);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_basic_write()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_basic_write()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_getname
|
|
|
|
*
|
|
|
|
* Purpose Test getting attribute name.
|
|
|
|
*
|
|
|
|
* Description
|
|
|
|
* Test these functions:
|
|
|
|
* A. ssize_t Attribute::getName(char* attr_name, size_t buf_size)
|
|
|
|
* 1. With arbitrary buf_size that is larger than the name size
|
|
|
|
* 2. With arbitrary buf_size that is smaller than the name's length.
|
|
|
|
* 3. With a buf_size that equals the name's length.
|
|
|
|
*
|
|
|
|
* B. ssize_t Attribute::getName(H5std_string& attr_name, size_t buf_size)
|
|
|
|
* 1. With buffer smaller than the actual name
|
|
|
|
* 2. Same test but with retiring overloaded function
|
|
|
|
* ssize_t Attribute::getName(size_t buf_size, H5std_string& attr_name)
|
|
|
|
*
|
|
|
|
* C. H5std_string Attribute::getName()
|
|
|
|
*
|
|
|
|
* D. H5std_string Attribute::getName(size_t len)
|
|
|
|
*
|
|
|
|
* E. ssize_t Attribute::getName(H5std_string& attr_name, size_t buf_size)
|
|
|
|
* With buffer size equals the name's length, i.e., buf_size=0
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_getname()
|
2014-04-01 13:59:37 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
|
|
|
SUBTEST("Testing all overloads of Attribute::getName");
|
|
|
|
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
//
|
|
|
|
// Open the file FILE_BASIC and test getName with its attribute
|
|
|
|
//
|
|
|
|
|
|
|
|
// Open file
|
|
|
|
H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
|
|
|
|
|
|
|
|
// Check for existence of attribute FATTR1_NAME
|
|
|
|
bool attr_exists = fid1.attrExists(FATTR1_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2017-03-03 22:45:57 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not");
|
|
|
|
|
2020-04-21 07:12:00 +08:00
|
|
|
// Open attribute
|
2017-03-03 22:45:57 +08:00
|
|
|
Attribute fattr1(fid1.openAttribute(FATTR1_NAME));
|
|
|
|
|
|
|
|
// A. Get attribute name with
|
|
|
|
// ssize_t Attribute::getName(char* attr_name, size_t buf_size)
|
|
|
|
// using different buffer sizes and verify against FATTR1_NAME (3 cases)
|
|
|
|
|
|
|
|
// 1. With arbitrary buf_size that is larger than the name size
|
2020-09-30 22:27:10 +08:00
|
|
|
size_t buf_size = FATTR1_NAME.length() + 10;
|
|
|
|
char * fattr1_name = new char[buf_size + 1];
|
|
|
|
HDmemset(fattr1_name, 0, buf_size + 1);
|
2017-03-03 22:45:57 +08:00
|
|
|
ssize_t name_size = 0; // actual length of attribute name
|
2020-09-30 22:27:10 +08:00
|
|
|
name_size = fattr1.getName(fattr1_name, buf_size + 1);
|
2017-03-03 22:45:57 +08:00
|
|
|
CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<size_t>(name_size), FATTR1_NAME.length(), "Attribute::getName", __LINE__,
|
|
|
|
__FILE__);
|
|
|
|
verify_val(const_cast<const char *>(fattr1_name), FATTR1_NAME, "Attribute::getName", __LINE__,
|
|
|
|
__FILE__);
|
2020-09-30 22:27:10 +08:00
|
|
|
delete[] fattr1_name;
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// 2. With arbitrary buf_size that is smaller than the name's length.
|
|
|
|
// Let's try 4 first characters in the name.
|
2020-09-30 22:27:10 +08:00
|
|
|
buf_size = 4;
|
2017-03-03 22:45:57 +08:00
|
|
|
char short_name[5] = "File"; // to verify the read name
|
2020-09-30 22:27:10 +08:00
|
|
|
fattr1_name = new char[buf_size + 1];
|
|
|
|
HDmemset(fattr1_name, 0, buf_size + 1);
|
|
|
|
name_size = fattr1.getName(fattr1_name, buf_size + 1);
|
2017-03-03 22:45:57 +08:00
|
|
|
CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<size_t>(name_size), FATTR1_NAME.size(), "Attribute::getName", __LINE__,
|
2020-09-30 22:27:10 +08:00
|
|
|
__FILE__);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(const_cast<const char *>(fattr1_name), const_cast<const char *>(short_name),
|
|
|
|
"Attribute::getName", __LINE__, __FILE__);
|
2020-09-30 22:27:10 +08:00
|
|
|
delete[] fattr1_name;
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// 3. With a buf_size that equals the name's length.
|
2020-09-30 22:27:10 +08:00
|
|
|
buf_size = FATTR1_NAME.length();
|
|
|
|
fattr1_name = new char[buf_size + 1];
|
|
|
|
HDmemset(fattr1_name, 0, buf_size + 1);
|
|
|
|
name_size = fattr1.getName(fattr1_name, buf_size + 1);
|
2017-03-03 22:45:57 +08:00
|
|
|
CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__);
|
|
|
|
verify_val(fattr1_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__);
|
2020-09-30 22:27:10 +08:00
|
|
|
delete[] fattr1_name;
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// B. Get attribute name with
|
|
|
|
// ssize_t Attribute::getName(H5std_string& attr_name, size_t buf_size)
|
|
|
|
// using buffer smaller than the actual name
|
|
|
|
buf_size = 4;
|
|
|
|
H5std_string fattr1_name2;
|
|
|
|
name_size = fattr1.getName(fattr1_name2, buf_size);
|
|
|
|
verify_val(fattr1_name2, "File", "Attribute::getName", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// Same test as above, but with deprecated overloaded function
|
|
|
|
// ssize_t Attribute::getName(size_t buf_size, H5std_string& attr_name)
|
|
|
|
// using buffer smaller than the actual name
|
|
|
|
H5std_string fattr1_name2a;
|
|
|
|
name_size = fattr1.getName(fattr1_name2a, buf_size);
|
|
|
|
verify_val(fattr1_name2a, "File", "Attribute::getName", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// C. Get file attribute's name with
|
|
|
|
// H5std_string Attribute::getName()
|
|
|
|
H5std_string fattr1_name3 = fattr1.getName();
|
|
|
|
verify_val(fattr1_name3, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
//
|
|
|
|
// D. Test getName getting part of an attribute's name using
|
|
|
|
// H5std_string Attribute::getName(len)
|
|
|
|
//
|
|
|
|
|
|
|
|
// Open dataset DSET1_NAME
|
|
|
|
DataSet dataset = fid1.openDataSet(DSET1_NAME);
|
|
|
|
|
|
|
|
// Check for existence of attribute
|
|
|
|
attr_exists = dataset.attrExists(ATTR1_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2017-03-03 22:45:57 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not");
|
|
|
|
|
|
|
|
// Open attribute
|
|
|
|
Attribute attr1(dataset.openAttribute(ATTR1_NAME));
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
size_t len = 4;
|
2017-03-03 22:45:57 +08:00
|
|
|
H5std_string dattr_name1 = attr1.getName(len);
|
|
|
|
verify_val(dattr_name1, "Attr", "Attribute::getName", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// E. Get dataset's attribute name with
|
|
|
|
// H5std_string Attribute::getName(H5std_string attr_name, buf_size=0)
|
|
|
|
H5std_string dattr_name2;
|
|
|
|
name_size = attr1.getName(dattr_name2);
|
|
|
|
verify_val(dattr_name2, ATTR1_NAME, "Attribute::getName", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
PASSED();
|
2014-04-01 13:59:37 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_getname()", __LINE__, __FILE__, E.getCDetailMsg());
|
2014-04-01 13:59:37 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_getname()
|
2014-04-01 13:59:37 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_rename
|
|
|
|
*
|
|
|
|
* Purpose Test renaming attribute function.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_rename()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int read_data1[ATTR1_DIM1] = {0}; // Buffer for reading the attribute
|
2015-03-15 14:49:20 +08:00
|
|
|
hsize_t i;
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2013-03-24 01:37:49 +08:00
|
|
|
// Output message about test being performed
|
|
|
|
SUBTEST("Checking for Existence and Renaming Attribute");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open file
|
|
|
|
H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check and rename attribute belonging to a file
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check for existence of attribute
|
|
|
|
bool attr_exists = fid1.attrExists(FATTR1_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2017-03-03 22:45:57 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not");
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Change attribute name
|
|
|
|
fid1.renameAttr(FATTR1_NAME, FATTR_TMP_NAME);
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open attribute again
|
|
|
|
Attribute fattr1(fid1.openAttribute(FATTR_TMP_NAME));
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify new attribute name
|
|
|
|
H5std_string fattr_name = fattr1.getName();
|
|
|
|
verify_val(fattr_name, FATTR_TMP_NAME, "Attribute::getName", __LINE__, __FILE__);
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
int num_attrs = fid1.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 2, "Attribute::getNumAttrs", __LINE__, __FILE__);
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Change first file attribute back to the original name
|
|
|
|
fid1.renameAttr(FATTR_TMP_NAME, FATTR1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the dataset
|
|
|
|
DataSet dataset = fid1.openDataSet(DSET1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check and rename attribute belonging to a dataset
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check for existence of attribute
|
|
|
|
attr_exists = dataset.attrExists(ATTR1_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2017-03-03 22:45:57 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Change attribute name
|
|
|
|
dataset.renameAttr(ATTR1_NAME, ATTR_TMP_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open attribute again
|
|
|
|
Attribute attr1(dataset.openAttribute(ATTR_TMP_NAME));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify new attribute name
|
|
|
|
H5std_string attr_name = attr1.getName();
|
|
|
|
verify_val(attr_name, ATTR_TMP_NAME, "Attribute::getName", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information immediately, without closing attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
attr1.read(PredType::NATIVE_INT, read_data1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR1_DIM1; i++)
|
|
|
|
if (attr_data1[i] != read_data1[i])
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data1[%" PRIuHSIZE
|
|
|
|
"]=%d,read_data1[%" PRIuHSIZE "]=%d\n",
|
2021-03-05 05:06:30 +08:00
|
|
|
__LINE__, i, attr_data1[i], i, read_data1[i]);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
attr1.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check for existence of second attribute
|
|
|
|
attr_exists = dataset.attrExists(ATTR2_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2017-03-03 22:45:57 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not");
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the second attribute
|
|
|
|
Attribute attr2(dataset.openAttribute(ATTR2_NAME));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify second attribute name
|
|
|
|
H5std_string attr2_name = attr2.getName();
|
|
|
|
verify_val(attr2_name, ATTR2_NAME, "Attribute::getName", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information immediately, without closing attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
attr2.read(PredType::NATIVE_INT, read_data1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR1_DIM1; i++)
|
|
|
|
if (attr_data1a[i] != read_data1[i])
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data1a[%" PRIuHSIZE
|
|
|
|
"]=%d,read_data1[%" PRIuHSIZE "]=%d\n",
|
2020-09-30 22:27:10 +08:00
|
|
|
__LINE__, i, attr_data1a[i], i, read_data1[i]);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close attribute
|
|
|
|
attr2.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Change first attribute back to the original name
|
|
|
|
dataset.renameAttr(ATTR_TMP_NAME, ATTR1_NAME);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check for existence of attribute after renaming
|
|
|
|
attr_exists = dataset.attrExists(ATTR1_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2017-03-03 22:45:57 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not");
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_rename()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_rename()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_basic_read
|
|
|
|
*
|
|
|
|
* Purpose Test basic read attribute.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_basic_read()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
2015-03-15 14:49:20 +08:00
|
|
|
hsize_t i, j;
|
2005-03-20 22:15:39 +08:00
|
|
|
|
2005-03-20 11:47:55 +08:00
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Basic Attribute Reading Functions");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open file
|
|
|
|
H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the dataset
|
|
|
|
DataSet dataset = fid1.openDataSet(DSET1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
int num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2018-07-17 14:09:45 +08:00
|
|
|
// Verify the correct number of attributes another way
|
2020-01-17 05:29:34 +08:00
|
|
|
H5O_info2_t oinfo;
|
2018-07-17 14:09:45 +08:00
|
|
|
HDmemset(&oinfo, 0, sizeof(oinfo));
|
2018-07-21 13:40:57 +08:00
|
|
|
dataset.getObjinfo(oinfo, H5O_INFO_NUM_ATTRS);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(oinfo.num_attrs), 3, "DataSet::getObjinfo", __LINE__, __FILE__);
|
2018-07-17 14:09:45 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open an attribute for the dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute ds_attr = dataset.openAttribute(ATTR1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
int read_data1[ATTR1_DIM1] = {0}; // Buffer for reading 1st attribute
|
2017-03-03 22:45:57 +08:00
|
|
|
ds_attr.read(PredType::NATIVE_INT, &read_data1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR1_DIM1; i++)
|
|
|
|
if (attr_data1[i] != read_data1[i])
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data1[%" PRIuHSIZE
|
|
|
|
"]=%d, read_data1[%" PRIuHSIZE "]=%d\n",
|
2020-09-30 22:27:10 +08:00
|
|
|
__LINE__, i, attr_data1[i], i, read_data1[i]);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/*
|
|
|
|
* Test attribute with group
|
|
|
|
*/
|
|
|
|
// Open the group
|
|
|
|
Group group = fid1.openGroup(GROUP1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
num_attrs = group.getNumAttrs();
|
2018-07-17 14:09:45 +08:00
|
|
|
verify_val(num_attrs, 1, "Group::getNumAttrs", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// Verify the correct number of attributes another way
|
|
|
|
HDmemset(&oinfo, 0, sizeof(oinfo));
|
2018-07-21 13:40:57 +08:00
|
|
|
group.getObjinfo(oinfo, H5O_INFO_NUM_ATTRS);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(oinfo.num_attrs), 1, "Group::getObjinfo", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open an attribute for the group
|
|
|
|
Attribute gr_attr = group.openAttribute(ATTR2_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Buffer for reading 2nd attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
int read_data2[ATTR2_DIM1][ATTR2_DIM2] = {{0}};
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information
|
|
|
|
gr_attr.read(PredType::NATIVE_INT, read_data2);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR2_DIM1; i++)
|
|
|
|
for (j = 0; j < ATTR2_DIM2; j++)
|
|
|
|
if (attr_data2[i][j] != read_data2[i][j]) {
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data2[%" PRIuHSIZE "][%" PRIuHSIZE
|
|
|
|
"]=%d, "
|
|
|
|
"read_data2[%" PRIuHSIZE "][%" PRIuHSIZE "]=%d\n",
|
2021-03-05 05:06:30 +08:00
|
|
|
__LINE__, i, j, attr_data2[i][j], i, j, read_data2[i][j]);
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_basic_read()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_basic_read()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_compound_write
|
|
|
|
*
|
|
|
|
* Purpose Test writing attributes with compound datatype.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_compound_write()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Multiple Attribute Functions");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create file
|
|
|
|
H5File fid1(FILE_COMPOUND.c_str(), H5F_ACC_TRUNC);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSpace sid1(SPACE1_RANK, dims1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, sid1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create the attribute datatype.
|
|
|
|
CompType comp_type(sizeof(struct attr4_struct));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
attr4_field1_off = HOFFSET(struct attr4_struct, i);
|
|
|
|
comp_type.insertMember(ATTR4_FIELDNAME1, attr4_field1_off, PredType::NATIVE_INT);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
attr4_field2_off = HOFFSET(struct attr4_struct, d);
|
|
|
|
comp_type.insertMember(ATTR4_FIELDNAME2, attr4_field2_off, PredType::NATIVE_DOUBLE);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
attr4_field3_off = HOFFSET(struct attr4_struct, c);
|
|
|
|
comp_type.insertMember(ATTR4_FIELDNAME3, attr4_field3_off, PredType::NATIVE_SCHAR);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for 1st attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims2[] = {ATTR4_DIM1, ATTR4_DIM2};
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSpace sid2(ATTR4_RANK, dims2);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create complex attribute for the dataset
|
|
|
|
Attribute attr = dataset.createAttribute(ATTR4_NAME, comp_type, sid2);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Try to create the same attribute again (should fail)
|
|
|
|
try {
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute invalid_attr = dataset.createAttribute(ATTR4_NAME, comp_type, sid2);
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (AttributeIException &E) // catching invalid creating attribute
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write complex attribute data
|
|
|
|
attr.write(comp_type, attr_data4);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_compound_write()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_compound_write()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_compound_read
|
|
|
|
*
|
|
|
|
* Purpose Test reading attributes with compound datatype.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_compound_read()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims[ATTR_MAX_DIMS]; // Attribute dimensions
|
|
|
|
size_t size; // Attribute datatype size as stored in file
|
|
|
|
size_t offset; // Attribute datatype field offset
|
2005-03-20 11:47:55 +08:00
|
|
|
struct attr4_struct read_data4[ATTR4_DIM1][ATTR4_DIM2]; // Buffer for reading 4th attribute
|
|
|
|
|
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Basic Attribute Functions");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open file
|
|
|
|
H5File fid1(FILE_COMPOUND, H5F_ACC_RDWR);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the dataset
|
|
|
|
DataSet dataset = fid1.openDataSet(DSET1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
int num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2018-07-17 14:09:45 +08:00
|
|
|
// Verify the correct number of attributes another way
|
2020-01-17 05:29:34 +08:00
|
|
|
H5O_info2_t oinfo;
|
2018-07-17 14:09:45 +08:00
|
|
|
HDmemset(&oinfo, 0, sizeof(oinfo));
|
2018-07-21 13:40:57 +08:00
|
|
|
dataset.getObjinfo(oinfo, H5O_INFO_NUM_ATTRS);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(oinfo.num_attrs), 1, "DataSet::getObjinfo", __LINE__, __FILE__);
|
2018-07-17 14:09:45 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open 1st attribute for the dataset
|
2021-06-01 21:49:39 +08:00
|
|
|
Attribute attr = dataset.openAttribute(static_cast<unsigned>(0));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Verify Dataspace */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dataspace of the attribute
|
|
|
|
DataSpace space = attr.getSpace();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the rank of the dataspace and verify it
|
|
|
|
int rank = space.getSimpleExtentNdims();
|
|
|
|
verify_val(rank, ATTR4_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dims of the dataspace and verify them
|
|
|
|
int ndims = space.getSimpleExtentDims(dims);
|
|
|
|
verify_val(ndims, ATTR4_RANK, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(dims[0]), static_cast<long>(ATTR4_DIM1),
|
|
|
|
"DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(dims[1]), static_cast<long>(ATTR4_DIM2),
|
|
|
|
"DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the class of the datatype that is used by attr
|
|
|
|
H5T_class_t type_class = attr.getTypeClass();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify that the type is of compound datatype
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(type_class), static_cast<long>(H5T_COMPOUND), "Attribute::getTypeClass",
|
|
|
|
__LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the compound datatype
|
|
|
|
CompType datatype = attr.getCompType();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the number of fields in the datatype, which must be 3
|
|
|
|
int fields = datatype.getNmembers();
|
|
|
|
verify_val(fields, 3, "CompType::getNmembers", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify that the fields have the same names as when the type
|
|
|
|
// was created
|
2022-07-11 23:59:51 +08:00
|
|
|
for (int j = 0; j < fields; j++) {
|
|
|
|
H5std_string fieldname = datatype.getMemberName(static_cast<unsigned>(j));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (!((fieldname == ATTR4_FIELDNAME1) || (fieldname == ATTR4_FIELDNAME2) ||
|
|
|
|
(fieldname == ATTR4_FIELDNAME3)))
|
|
|
|
TestErrPrintf("%d:invalid field name for field #%d: %s\n", __LINE__, j, fieldname.c_str());
|
2022-07-11 23:59:51 +08:00
|
|
|
}
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
offset = datatype.getMemberOffset(0);
|
|
|
|
verify_val(offset, attr4_field1_off, "DataType::getMemberOffset", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
offset = datatype.getMemberOffset(1);
|
|
|
|
verify_val(offset, attr4_field2_off, "DataType::getMemberOffset", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
offset = datatype.getMemberOffset(2);
|
|
|
|
verify_val(offset, attr4_field3_off, "DataType::getMemberOffset", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
/* Verify each field's type, class & size */
|
|
|
|
|
|
|
|
// Get and verify the type class of the first member
|
|
|
|
type_class = datatype.getMemberClass(0);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(type_class), static_cast<long>(H5T_INTEGER), "DataType::getMemberClass",
|
|
|
|
__LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify the order of this member's type
|
2020-09-30 22:27:10 +08:00
|
|
|
IntType i_type = datatype.getMemberIntType(0);
|
|
|
|
H5T_order_t order = i_type.getOrder();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(order), static_cast<long>(PredType::NATIVE_INT.getOrder()),
|
|
|
|
"DataType::getOrder", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Get and verify the size of this member's type
|
|
|
|
size = i_type.getSize();
|
|
|
|
verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// Get and verify class, order, and size of the second member's type
|
|
|
|
type_class = datatype.getMemberClass(1);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(type_class), static_cast<long>(H5T_FLOAT), "DataType::getMemberClass",
|
|
|
|
__LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
FloatType f_type = datatype.getMemberFloatType(1);
|
2020-09-30 22:27:10 +08:00
|
|
|
order = f_type.getOrder();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(order), static_cast<long>(PredType::NATIVE_DOUBLE.getOrder()),
|
|
|
|
"DataType::getOrder", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
size = f_type.getSize();
|
|
|
|
verify_val(size, PredType::NATIVE_DOUBLE.getSize(), "DataType::getSize", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// Get and verify class, order, and size of the third member's type
|
|
|
|
type_class = datatype.getMemberClass(2);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(type_class), static_cast<long>(H5T_INTEGER), "DataType::getMemberClass",
|
|
|
|
__LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
// Note: H5T_INTEGER is correct here!
|
|
|
|
|
|
|
|
StrType s_type = datatype.getMemberStrType(2);
|
2020-09-30 22:27:10 +08:00
|
|
|
order = s_type.getOrder();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(order), static_cast<long>(PredType::NATIVE_SCHAR.getOrder()),
|
|
|
|
"DataType::getOrder", __LINE__, __FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
size = s_type.getSize();
|
|
|
|
verify_val(size, PredType::NATIVE_SCHAR.getSize(), "DataType::getSize", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// Read attribute information
|
|
|
|
attr.read(datatype, read_data4);
|
|
|
|
|
|
|
|
// Verify values read in
|
|
|
|
hsize_t ii, jj;
|
2020-09-30 22:27:10 +08:00
|
|
|
for (ii = 0; ii < ATTR4_DIM1; ii++)
|
|
|
|
for (jj = 0; jj < ATTR4_DIM2; jj++)
|
2021-03-11 02:42:35 +08:00
|
|
|
if (HDmemcmp(&attr_data4[ii][jj], &read_data4[ii][jj], sizeof(struct attr4_struct)) != 0) {
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d:attribute data different: attr_data4[%" PRIuHSIZE "][%" PRIuHSIZE
|
|
|
|
"].i=%d, "
|
|
|
|
"read_data4[%" PRIuHSIZE "][%" PRIuHSIZE "].i=%d\n",
|
2021-03-05 05:06:30 +08:00
|
|
|
__LINE__, ii, jj, attr_data4[ii][jj].i, ii, jj, read_data4[ii][jj].i);
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d:attribute data different: attr_data4[%" PRIuHSIZE "][%" PRIuHSIZE
|
|
|
|
"].d=%f, "
|
|
|
|
"read_data4[%" PRIuHSIZE "][%" PRIuHSIZE "].d=%f\n",
|
2021-03-05 05:06:30 +08:00
|
|
|
__LINE__, ii, jj, attr_data4[ii][jj].d, ii, jj, read_data4[ii][jj].d);
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d:attribute data different: attr_data4[%" PRIuHSIZE "][%" PRIuHSIZE
|
|
|
|
"].c=%c, "
|
|
|
|
"read_data4[%" PRIuHSIZE "][%" PRIuHSIZE "].c=%c\n",
|
2021-03-05 05:06:30 +08:00
|
|
|
__LINE__, ii, jj, attr_data4[ii][jj].c, ii, jj, read_data4[ii][jj].c);
|
2020-09-30 22:27:10 +08:00
|
|
|
} /* end if */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify name
|
|
|
|
H5std_string attr_name = attr.getName();
|
|
|
|
verify_val(attr_name, ATTR4_NAME, "Attribute::getName", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
[svn-r26655] Purpose: Fixed HDFFV-7947
Description:
When copy constructor or constructor that takes an existing id is invoked,
the C ref counter stays the same but there is an extra C++ object which
later is destroyed and may cause the HDF5 id to be closed prematurely. The
C++ library needs to increment the ref counter in these situations, so that
the C library will not close the id when it is still being referenced.
However, the incrementing of ref count left some objects opened at the end
of the program, perhaps, due to compiler's optimization on cons/destructors. The constructor, that takes an existing id, needs to increment the counter
but it seems that the matching destructor wasn't invoked. The workaround
is to have a function for each class that has "id" that only sets the id
and not increment the ref count for the library to use in these situations.
These functions are "friend" and not public.
The friend functions are:
void f_Attribute_setId(Attribute *, hid_t)
void f_DataSet_setId(DataSet *, hid_t)
void f_DataSpace_setId(DataSpace *, hid_t)
void f_DataType_setId(DataType *, hid_t)
Platforms tested:
Linux/64 (platypus)
Linux/32 2.6 (jam gnu and Intel 15.0)
SunOS 5.11 (emu)
2015-03-31 01:58:44 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Now, try truncating the file to make sure reference counting is good.
|
|
|
|
// If any references to ids in the previous block are left unterminated,
|
|
|
|
// the truncating will fail, because the file will not be closed in
|
|
|
|
// the file.close() above.
|
|
|
|
H5File file1(FILE_COMPOUND, H5F_ACC_TRUNC);
|
[svn-r26655] Purpose: Fixed HDFFV-7947
Description:
When copy constructor or constructor that takes an existing id is invoked,
the C ref counter stays the same but there is an extra C++ object which
later is destroyed and may cause the HDF5 id to be closed prematurely. The
C++ library needs to increment the ref counter in these situations, so that
the C library will not close the id when it is still being referenced.
However, the incrementing of ref count left some objects opened at the end
of the program, perhaps, due to compiler's optimization on cons/destructors. The constructor, that takes an existing id, needs to increment the counter
but it seems that the matching destructor wasn't invoked. The workaround
is to have a function for each class that has "id" that only sets the id
and not increment the ref count for the library to use in these situations.
These functions are "friend" and not public.
The friend functions are:
void f_Attribute_setId(Attribute *, hid_t)
void f_DataSet_setId(DataSet *, hid_t)
void f_DataSpace_setId(DataSpace *, hid_t)
void f_DataType_setId(DataType *, hid_t)
Platforms tested:
Linux/64 (platypus)
Linux/32 2.6 (jam gnu and Intel 15.0)
SunOS 5.11 (emu)
2015-03-31 01:58:44 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
[svn-r26655] Purpose: Fixed HDFFV-7947
Description:
When copy constructor or constructor that takes an existing id is invoked,
the C ref counter stays the same but there is an extra C++ object which
later is destroyed and may cause the HDF5 id to be closed prematurely. The
C++ library needs to increment the ref counter in these situations, so that
the C library will not close the id when it is still being referenced.
However, the incrementing of ref count left some objects opened at the end
of the program, perhaps, due to compiler's optimization on cons/destructors. The constructor, that takes an existing id, needs to increment the counter
but it seems that the matching destructor wasn't invoked. The workaround
is to have a function for each class that has "id" that only sets the id
and not increment the ref count for the library to use in these situations.
These functions are "friend" and not public.
The friend functions are:
void f_Attribute_setId(Attribute *, hid_t)
void f_DataSet_setId(DataSet *, hid_t)
void f_DataSpace_setId(DataSpace *, hid_t)
void f_DataType_setId(DataType *, hid_t)
Platforms tested:
Linux/64 (platypus)
Linux/32 2.6 (jam gnu and Intel 15.0)
SunOS 5.11 (emu)
2015-03-31 01:58:44 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (FileIException &E) {
|
|
|
|
issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__,
|
|
|
|
"Unable to truncate file, possibly because some objects are left opened");
|
[svn-r26655] Purpose: Fixed HDFFV-7947
Description:
When copy constructor or constructor that takes an existing id is invoked,
the C ref counter stays the same but there is an extra C++ object which
later is destroyed and may cause the HDF5 id to be closed prematurely. The
C++ library needs to increment the ref counter in these situations, so that
the C library will not close the id when it is still being referenced.
However, the incrementing of ref count left some objects opened at the end
of the program, perhaps, due to compiler's optimization on cons/destructors. The constructor, that takes an existing id, needs to increment the counter
but it seems that the matching destructor wasn't invoked. The workaround
is to have a function for each class that has "id" that only sets the id
and not increment the ref count for the library to use in these situations.
These functions are "friend" and not public.
The friend functions are:
void f_Attribute_setId(Attribute *, hid_t)
void f_DataSet_setId(DataSet *, hid_t)
void f_DataSpace_setId(DataSpace *, hid_t)
void f_DataType_setId(DataType *, hid_t)
Platforms tested:
Linux/64 (platypus)
Linux/32 2.6 (jam gnu and Intel 15.0)
SunOS 5.11 (emu)
2015-03-31 01:58:44 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_compound_read()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_scalar_write
|
|
|
|
*
|
|
|
|
* Purpose Test scalar attribute writing functionality.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_scalar_write()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
2005-07-25 11:40:21 +08:00
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Basic Scalar Attribute Writing Functions");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create file
|
|
|
|
H5File fid1(FILE_SCALAR, H5F_ACC_TRUNC);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
|
2017-03-03 22:45:57 +08:00
|
|
|
DataSpace sid1(SPACE1_RANK, dims1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, sid1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close dataset's dataspace
|
|
|
|
sid1.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for attribute
|
|
|
|
DataSpace att_space(ATTR5_RANK, NULL);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create an attribute for the dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute ds_attr = dataset.createAttribute(ATTR5_NAME, PredType::NATIVE_FLOAT, att_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Try creating an attribute that already exists. This should fail
|
|
|
|
// since two attributes cannot have the same name. If an exception
|
|
|
|
// is not thrown for this action by createAttribute, then throw an
|
|
|
|
// invalid action exception.
|
|
|
|
try {
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute invalid_attr = dataset.createAttribute(ATTR5_NAME, PredType::NATIVE_FLOAT, att_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// continuation here, that means no exception has been thrown
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("H5File::createDataSet",
|
|
|
|
"Library allowed overwrite of existing dataset");
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (AttributeIException &E) // catching invalid creating attribute
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
ds_attr.write(PredType::NATIVE_FLOAT, &attr_data5);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_scalar_write()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_scalar_read
|
|
|
|
*
|
|
|
|
* Purpose Test scalar attribute reading functionality.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2016-09-02 11:14:22 +08:00
|
|
|
/* Epsilon for floating-point comparisons */
|
|
|
|
#define FP_EPSILON 0.000001F
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_scalar_read()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Basic Scalar Attribute Reading Functions");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open file
|
|
|
|
H5File fid1(FILE_SCALAR, H5F_ACC_RDWR);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the dataset
|
|
|
|
DataSet dataset = fid1.openDataSet(DSET1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
int num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open an attribute for the dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute ds_attr = dataset.openAttribute(ATTR5_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
float read_data2 = 0.0; // Buffer for reading 1st attribute
|
|
|
|
ds_attr.read(PredType::NATIVE_FLOAT, &read_data2);
|
2021-06-01 21:49:39 +08:00
|
|
|
if (abs(read_data2 - attr_data5) > FLT_EPSILON)
|
|
|
|
TestErrPrintf("%d: attribute data different: read_data2=%f, "
|
|
|
|
"attr_data5=%f\n",
|
|
|
|
__LINE__, static_cast<double>(read_data2), static_cast<double>(attr_data5));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dataspace of the attribute
|
|
|
|
DataSpace att_space = ds_attr.getSpace();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Make certain the dataspace is scalar
|
|
|
|
H5S_class_t space_type = att_space.getSimpleExtentType();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(space_type), static_cast<long>(H5S_SCALAR),
|
|
|
|
"DataSpace::getSimpleExtentType", __LINE__, __FILE__);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_scalar_read()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_mult_write
|
|
|
|
*
|
|
|
|
* Purpose Test writing multiple attributes.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_mult_write()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Multiple Attribute Writing Functions");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create file
|
2020-09-30 22:27:10 +08:00
|
|
|
H5File fid1(FILE_MULTI, H5F_ACC_TRUNC);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
|
|
|
|
DataSpace ds_space(SPACE1_RANK, dims1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
|
|
|
DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for 1st attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims2[] = {ATTR1_DIM1};
|
|
|
|
DataSpace att_space(ATTR1_RANK, dims2);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create 1st attribute for the dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute ds_attr = dataset.createAttribute(ATTR1_NAME, PredType::NATIVE_INT, att_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
ds_attr.write(PredType::NATIVE_INT, attr_data1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for 2nd attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims3[] = {ATTR2_DIM1, ATTR2_DIM2};
|
|
|
|
DataSpace att2_space(ATTR2_RANK, dims3);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create 2nd attribute for the dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute ds_attr2 = dataset.createAttribute(ATTR2_NAME, PredType::NATIVE_INT, att2_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write 2nd attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
ds_attr2.write(PredType::NATIVE_INT, attr_data2);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for 3rd attribute
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims4[] = {ATTR3_DIM1, ATTR3_DIM2, ATTR3_DIM3};
|
|
|
|
DataSpace att3_space(ATTR3_RANK, dims4);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create 3rd attribute for the dataset
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute ds_attr3 = dataset.createAttribute(ATTR3_NAME, PredType::NATIVE_DOUBLE, att3_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Try creating an attribute that already exists. This should fail
|
|
|
|
// since two attributes cannot have the same name. If an exception
|
|
|
|
// is not thrown for this action by createAttribute, then throw an
|
|
|
|
// invalid action exception.
|
|
|
|
try {
|
2020-09-30 22:27:10 +08:00
|
|
|
Attribute invalid_attr = dataset.createAttribute(ATTR3_NAME, PredType::NATIVE_DOUBLE, att3_space);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// continuation here, that means no exception has been thrown
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("DataSet::createAttribute",
|
|
|
|
"Attempting to create a duplicate attribute");
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (AttributeIException &E) // catching invalid creating attribute
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write 3rd attribute information
|
2020-09-30 22:27:10 +08:00
|
|
|
ds_attr3.write(PredType::NATIVE_DOUBLE, attr_data3);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_mult_write()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_mult_write()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_mult_read
|
|
|
|
*
|
|
|
|
* Purpose Test reading multiple attributes.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_mult_read()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int read_data1[ATTR1_DIM1] = {0}; // Buffer for reading 1st attribute
|
|
|
|
int read_data2[ATTR2_DIM1][ATTR2_DIM2] = {{0}}; // Buffer for reading 2nd attribute
|
|
|
|
double read_data3[ATTR3_DIM1][ATTR3_DIM2][ATTR3_DIM3] = {{{0}}}; // Buffer for reading 3rd attribute
|
|
|
|
hsize_t i, j, k;
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Multiple Attribute Reading Functions");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open file
|
|
|
|
H5File fid1(FILE_MULTI, H5F_ACC_RDWR);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the dataset
|
|
|
|
DataSet dataset = fid1.openDataSet(DSET1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
int num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open 1st attribute for the dataset
|
2021-06-01 21:49:39 +08:00
|
|
|
Attribute attr = dataset.openAttribute(static_cast<unsigned>(0));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Verify Dataspace */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dataspace of the attribute
|
|
|
|
DataSpace space = attr.getSpace();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the rank of the dataspace and verify it
|
|
|
|
int rank = space.getSimpleExtentNdims();
|
|
|
|
verify_val(rank, ATTR1_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dims of the dataspace and verify them
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t dims[ATTR_MAX_DIMS]; // Attribute dimensions
|
2021-06-01 21:49:39 +08:00
|
|
|
(void)space.getSimpleExtentDims(dims);
|
|
|
|
if (dims[0] != ATTR1_DIM1)
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d:attribute dimensions different: dims[0]=%d, should be %" PRIuHSIZE "\n",
|
|
|
|
__LINE__, static_cast<int>(dims[0]), ATTR1_DIM1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Verify Datatype */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
|
|
|
// Get the class of the datatype that is used by attr
|
|
|
|
H5T_class_t type_class = attr.getTypeClass();
|
|
|
|
|
|
|
|
// Verify that the type is of integer datatype
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(type_class), static_cast<long>(H5T_INTEGER), "Attribute::getTypeClass",
|
|
|
|
__LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Get the integer datatype
|
2005-03-20 11:47:55 +08:00
|
|
|
IntType i_type1 = attr.getIntType();
|
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify the order of this type
|
|
|
|
H5T_order_t order = i_type1.getOrder();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(order), static_cast<long>(PredType::NATIVE_INT.getOrder()),
|
|
|
|
"DataType::getOrder", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify the size of this type
|
|
|
|
size_t size = i_type1.getSize();
|
|
|
|
verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information
|
|
|
|
attr.read(PredType::NATIVE_INT, read_data1);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR1_DIM1; i++)
|
|
|
|
if (attr_data1[i] != read_data1[i])
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data1[%" PRIuHSIZE
|
|
|
|
"]=%d,read_data1[%" PRIuHSIZE "]=%d\n",
|
2021-03-05 05:06:30 +08:00
|
|
|
__LINE__, i, attr_data1[i], i, read_data1[i]);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify Name
|
|
|
|
H5std_string attr_name = attr.getName();
|
|
|
|
verify_val(attr_name, ATTR1_NAME, "DataType::getName", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
attr.close();
|
|
|
|
space.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open 2nd attribute for the dataset
|
2021-06-01 21:49:39 +08:00
|
|
|
attr = dataset.openAttribute(static_cast<unsigned>(1));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Verify Dataspace */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dataspace of the attribute
|
|
|
|
space = attr.getSpace();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the rank of the dataspace and verify it
|
|
|
|
rank = space.getSimpleExtentNdims();
|
|
|
|
verify_val(rank, ATTR2_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dims of the dataspace and verify them
|
2021-06-01 21:49:39 +08:00
|
|
|
(void)space.getSimpleExtentDims(dims);
|
2015-03-15 14:49:20 +08:00
|
|
|
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(dims[0]), static_cast<long>(ATTR2_DIM1),
|
|
|
|
"DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
|
|
|
|
verify_val(static_cast<long>(dims[1]), static_cast<long>(ATTR2_DIM2),
|
|
|
|
"DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Verify Datatype */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
|
|
|
// Get the class of the datatype that is used by attr
|
|
|
|
type_class = attr.getTypeClass();
|
|
|
|
|
|
|
|
// Verify that the type is of integer datatype
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(type_class), static_cast<long>(H5T_INTEGER), "Attribute::getTypeClass",
|
|
|
|
__LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Get the integer datatype
|
2005-03-20 11:47:55 +08:00
|
|
|
IntType i_type2 = attr.getIntType();
|
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify the order of this type
|
|
|
|
order = i_type2.getOrder();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(order), static_cast<long>(PredType::NATIVE_INT.getOrder()),
|
|
|
|
"DataType::getOrder", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify the size of this type
|
|
|
|
size = i_type2.getSize();
|
|
|
|
verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information
|
|
|
|
attr.read(PredType::NATIVE_INT, read_data2);
|
2020-09-30 22:27:10 +08:00
|
|
|
// attr.read(i_type, read_data2);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR2_DIM1; i++)
|
|
|
|
for (j = 0; j < ATTR2_DIM2; j++)
|
|
|
|
if (attr_data2[i][j] != read_data2[i][j])
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data2[%" PRIuHSIZE "][%" PRIuHSIZE
|
|
|
|
"]=%d, "
|
|
|
|
"read_data2[%" PRIuHSIZE "][%" PRIuHSIZE "]=%d\n",
|
2021-03-05 05:06:30 +08:00
|
|
|
__LINE__, i, j, attr_data2[i][j], i, j, read_data2[i][j]);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify Name
|
|
|
|
attr_name = attr.getName();
|
|
|
|
verify_val(attr_name, ATTR2_NAME, "DataType::getName", __LINE__, __FILE__);
|
|
|
|
attr.close();
|
|
|
|
space.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open 3rd attribute for the dataset
|
2021-06-01 21:49:39 +08:00
|
|
|
attr = dataset.openAttribute(static_cast<unsigned>(2));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Verify Dataspace */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dataspace of the attribute
|
|
|
|
space = attr.getSpace();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the rank of the dataspace and verify it
|
|
|
|
rank = space.getSimpleExtentNdims();
|
|
|
|
verify_val(rank, ATTR3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get the dims of the dataspace and verify them
|
2021-06-01 21:49:39 +08:00
|
|
|
(void)space.getSimpleExtentDims(dims);
|
|
|
|
verify_val(static_cast<long>(dims[0]), static_cast<long>(ATTR3_DIM1), "attribute dimensions",
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
verify_val(static_cast<long>(dims[1]), static_cast<long>(ATTR3_DIM2), "attribute dimensions",
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
verify_val(static_cast<long>(dims[2]), static_cast<long>(ATTR3_DIM3), "attribute dimensions",
|
|
|
|
__FILE__, __LINE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
/* Verify Datatype */
|
2005-03-20 11:47:55 +08:00
|
|
|
|
|
|
|
// Get the class of the datatype that is used by attr
|
|
|
|
type_class = attr.getTypeClass();
|
|
|
|
|
|
|
|
// Verify that the type is of compound datatype
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(type_class), static_cast<long>(H5T_FLOAT), "Attribute::getTypeClass",
|
|
|
|
__LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Get the double datatype
|
2005-03-20 11:47:55 +08:00
|
|
|
FloatType f_type = attr.getFloatType();
|
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify the order of this type
|
|
|
|
order = f_type.getOrder();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(order), static_cast<long>(PredType::NATIVE_DOUBLE.getOrder()),
|
|
|
|
"DataType::getOrder", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get and verify the size of this type
|
|
|
|
size = f_type.getSize();
|
|
|
|
verify_val(size, PredType::NATIVE_DOUBLE.getSize(), "DataType::getSize", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Read attribute information
|
|
|
|
attr.read(PredType::NATIVE_DOUBLE, read_data3);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify values read in
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < ATTR3_DIM1; i++)
|
|
|
|
for (j = 0; j < ATTR3_DIM2; j++)
|
|
|
|
for (k = 0; k < ATTR3_DIM3; k++)
|
2021-06-01 21:49:39 +08:00
|
|
|
if (abs(attr_data3[i][j][k] - read_data3[i][j][k]) > DBL_EPSILON)
|
2021-06-11 20:52:36 +08:00
|
|
|
TestErrPrintf("%d: attribute data different: attr_data3[%" PRIuHSIZE "][%" PRIuHSIZE
|
|
|
|
"][%" PRIuHSIZE "]=%f, "
|
|
|
|
"read_data3[%" PRIuHSIZE "][%" PRIuHSIZE "][%" PRIuHSIZE "]=%f\n",
|
2020-09-30 22:27:10 +08:00
|
|
|
__LINE__, i, j, k, attr_data3[i][j][k], i, j, k, read_data3[i][j][k]);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify Name
|
|
|
|
attr_name = attr.getName();
|
|
|
|
verify_val(attr_name, ATTR3_NAME, "DataType::getName", __LINE__, __FILE__);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_mult_read()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_mult_read()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_delete
|
|
|
|
*
|
|
|
|
* Purpose Test deleting attribute from different hdf5 objects.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_delete()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
H5std_string attr_name; // Buffer for attribute names
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2012-09-28 07:26:16 +08:00
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Removing Attribute Function");
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open file.
|
|
|
|
H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
|
|
|
|
|
|
|
|
// Get the number of file attributes
|
|
|
|
int num_attrs = fid1.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 2, "H5File::getNumAttrs", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// Delete the second file attribute
|
|
|
|
fid1.removeAttr(FATTR2_NAME);
|
|
|
|
|
|
|
|
// Get the number of file attributes
|
|
|
|
num_attrs = fid1.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 1, "H5File::getNumAttrs", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// Verify the name of the only file attribute left
|
2021-06-01 21:49:39 +08:00
|
|
|
Attribute fattr = fid1.openAttribute(static_cast<unsigned>(0));
|
2020-09-30 22:27:10 +08:00
|
|
|
attr_name = fattr.getName();
|
2017-03-03 22:45:57 +08:00
|
|
|
verify_val(attr_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__);
|
|
|
|
fattr.close();
|
2020-04-21 07:12:00 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Test deleting non-existing attribute
|
|
|
|
|
|
|
|
// Open the dataset
|
|
|
|
DataSet dataset = fid1.openDataSet(DSET1_NAME);
|
|
|
|
|
|
|
|
// Verify the correct number of attributes
|
|
|
|
num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
|
|
|
|
|
|
|
// Try to delete bogus attribute, should fail
|
|
|
|
try {
|
|
|
|
dataset.removeAttr("Bogus");
|
|
|
|
|
|
|
|
// continuation here, that means no exception has been thrown
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("DataSet::removeAttr",
|
|
|
|
"Attempting to remove non-existing attribute");
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (AttributeIException &E) // catching invalid removing attribute
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Test deleting dataset's attributes
|
2012-09-28 07:26:16 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Delete middle (2nd) attribute
|
|
|
|
dataset.removeAttr(ATTR2_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 2, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open 1st attribute for the dataset
|
2021-06-01 21:49:39 +08:00
|
|
|
Attribute attr = dataset.openAttribute(static_cast<unsigned>(0));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify Name
|
|
|
|
attr_name = attr.getName();
|
|
|
|
verify_val(attr_name, ATTR1_NAME, "Attribute::getName", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close attribute
|
|
|
|
attr.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open last (formally 3rd) attribute for the dataset
|
2021-06-01 21:49:39 +08:00
|
|
|
attr = dataset.openAttribute(static_cast<unsigned>(1));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify Name
|
|
|
|
attr_name = attr.getName();
|
|
|
|
verify_val(attr_name, ATTR3_NAME, "Attribute::getName", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
attr.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Delete first attribute
|
|
|
|
dataset.removeAttr(ATTR1_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the only attribute for the dataset (formally 3rd)
|
2021-06-01 21:49:39 +08:00
|
|
|
attr = dataset.openAttribute(static_cast<unsigned>(0));
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify Name
|
|
|
|
attr_name = attr.getName();
|
|
|
|
verify_val(attr_name, ATTR3_NAME, "Attribute::getName", __LINE__, __FILE__);
|
|
|
|
// Close attribute
|
|
|
|
attr.close();
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Delete first attribute
|
|
|
|
dataset.removeAttr(ATTR3_NAME);
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Verify the correct number of attributes
|
|
|
|
num_attrs = dataset.getNumAttrs();
|
|
|
|
verify_val(num_attrs, 0, "DataSet::getNumAttrs", __LINE__, __FILE__);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2005-03-20 11:47:55 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_delete()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_delete()
|
2005-03-20 11:47:55 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_dtype_shared
|
|
|
|
*
|
|
|
|
* Purpose Test accessing attributes using shared datatypes.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_dtype_shared()
|
2005-12-06 05:05:33 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int data = 8; // Data to write
|
|
|
|
int rdata = 0; // Data read in
|
2007-09-13 23:44:56 +08:00
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
2020-09-30 22:27:10 +08:00
|
|
|
H5G_stat_t statbuf; // Object's information
|
2017-12-05 02:21:12 +08:00
|
|
|
#endif
|
2020-09-30 22:27:10 +08:00
|
|
|
h5_stat_size_t filesize; // Size of file after modifications
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2006-04-26 02:02:28 +08:00
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("Shared Datatypes with Attributes");
|
2005-12-06 05:05:33 +08:00
|
|
|
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a file
|
|
|
|
H5File fid1(FILE_DTYPE, H5F_ACC_TRUNC);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close file
|
|
|
|
fid1.close();
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get size of file
|
2020-09-30 22:27:10 +08:00
|
|
|
h5_stat_size_t empty_filesize; // Size of empty file
|
2017-03-03 22:45:57 +08:00
|
|
|
empty_filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT);
|
|
|
|
if (empty_filesize < 0)
|
[svn-r15825] Description:
Fix various problems with a the core & sec2 VFDs.
Improve the h5_get_file_size() routine to handle files created with
VFDs that use multiple files.
Tested on:
Mac OS X/32 10.5.5 (amazon) in debug mode
Mac OS X/32 10.5.5 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
FreeBSD/32 6.3 (duty) in debug mode
FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/Intel compilers w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode
2008-10-09 11:44:22 +08:00
|
|
|
TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the file again
|
|
|
|
fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Enclosing to work around the issue of unused variables and/or
|
|
|
|
// objects created by copy constructors stay around until end of
|
|
|
|
// scope, causing incorrect number of ref counts.
|
|
|
|
{ // First enclosed block
|
2008-07-23 04:36:31 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Create a datatype to commit and use
|
|
|
|
IntType dtype(PredType::NATIVE_INT);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Commit datatype to file
|
|
|
|
dtype.commit(fid1, TYPE1_NAME);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2007-09-13 23:44:56 +08:00
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
2020-09-30 22:27:10 +08:00
|
|
|
// Check reference count on named datatype
|
|
|
|
fid1.getObjinfo(TYPE1_NAME, statbuf);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<int>(statbuf.nlink), 1, "DataType::getObjinfo", __LINE__, __FILE__);
|
2017-12-05 02:21:12 +08:00
|
|
|
#endif
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Create dataspace for dataset
|
|
|
|
DataSpace dspace;
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
DataSet dset = fid1.createDataSet(DSET1_NAME, dtype, dspace);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2007-09-13 23:44:56 +08:00
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
2020-09-30 22:27:10 +08:00
|
|
|
// Check reference count on named datatype
|
|
|
|
fid1.getObjinfo(TYPE1_NAME, statbuf);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<int>(statbuf.nlink), 2, "H5File::getObjinfo", __LINE__, __FILE__);
|
2017-12-05 02:21:12 +08:00
|
|
|
#endif
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Create attribute on dataset
|
|
|
|
Attribute attr = dset.createAttribute(ATTR1_NAME, dtype, dspace);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2007-09-13 23:44:56 +08:00
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
2020-09-30 22:27:10 +08:00
|
|
|
// Check reference count on named datatype
|
|
|
|
fid1.getObjinfo(TYPE1_NAME, statbuf);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<int>(statbuf.nlink), 3, "DataSet::getObjinfo", __LINE__, __FILE__);
|
2017-12-05 02:21:12 +08:00
|
|
|
#endif
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Close attribute
|
|
|
|
attr.close();
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Delete attribute
|
|
|
|
dset.removeAttr(ATTR1_NAME);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2007-09-13 23:44:56 +08:00
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
2020-09-30 22:27:10 +08:00
|
|
|
// Check reference count on named datatype
|
|
|
|
fid1.getObjinfo(TYPE1_NAME, statbuf);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<int>(statbuf.nlink), 2, "DataSet::getObjinfo after DataSet::removeAttr",
|
|
|
|
__LINE__, __FILE__);
|
2017-12-05 02:21:12 +08:00
|
|
|
#endif
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Create attribute on dataset
|
|
|
|
attr = dset.createAttribute(ATTR1_NAME, dtype, dspace);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2007-09-13 23:44:56 +08:00
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
2020-09-30 22:27:10 +08:00
|
|
|
// Check reference count on named datatype
|
|
|
|
fid1.getObjinfo(TYPE1_NAME, statbuf);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<int>(statbuf.nlink), 3, "DataSet::createAttribute", __LINE__, __FILE__);
|
2017-12-05 02:21:12 +08:00
|
|
|
#endif
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Write data into the attribute
|
|
|
|
attr.write(PredType::NATIVE_INT, &data);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Close attribute, dataset, dataspace, datatype, and file
|
|
|
|
attr.close();
|
|
|
|
dset.close();
|
|
|
|
dspace.close();
|
|
|
|
dtype.close();
|
2017-03-03 22:45:57 +08:00
|
|
|
} // end of first enclosing
|
2008-07-23 04:36:31 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
fid1.close();
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the file again
|
|
|
|
fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
{ // Second enclosed block...
|
2008-07-23 04:36:31 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Open dataset
|
|
|
|
DataSet *dset2 = new DataSet(fid1.openDataSet(DSET1_NAME));
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Open attribute
|
|
|
|
Attribute *attr2 = new Attribute(dset2->openAttribute(ATTR1_NAME));
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Read data from the attribute
|
|
|
|
attr2->read(PredType::NATIVE_INT, &rdata);
|
|
|
|
verify_val(data, rdata, "Attribute::read", __LINE__, __FILE__);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
// Close attribute and dataset
|
|
|
|
delete attr2;
|
|
|
|
delete dset2;
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2007-09-13 23:44:56 +08:00
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
2020-09-30 22:27:10 +08:00
|
|
|
// Check reference count on named datatype
|
|
|
|
fid1.getObjinfo(TYPE1_NAME, statbuf);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<int>(statbuf.nlink), 3, "DataSet::openAttribute", __LINE__, __FILE__);
|
2017-12-05 02:21:12 +08:00
|
|
|
#endif
|
2017-03-03 22:45:57 +08:00
|
|
|
} // end of second enclosing
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Unlink the dataset
|
|
|
|
fid1.unlink(DSET1_NAME);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2007-09-13 23:44:56 +08:00
|
|
|
#ifndef H5_NO_DEPRECATED_SYMBOLS
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check reference count on named datatype
|
|
|
|
fid1.getObjinfo(TYPE1_NAME, statbuf);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<int>(statbuf.nlink), 1, "H5File::unlink", __LINE__, __FILE__);
|
2017-12-05 02:21:12 +08:00
|
|
|
#endif
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Unlink the named datatype
|
|
|
|
fid1.unlink(TYPE1_NAME);
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close file
|
|
|
|
fid1.close();
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check size of file
|
|
|
|
filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT);
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(filesize), static_cast<long>(empty_filesize), "Checking file size",
|
|
|
|
__LINE__, __FILE__);
|
2007-03-18 00:26:53 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2020-09-30 22:27:10 +08:00
|
|
|
} // end try block
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_dtype_shared()", __LINE__, __FILE__, E.getCDetailMsg());
|
2005-12-06 05:05:33 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_dtype_shared()
|
2005-12-06 05:05:33 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_string_attr
|
|
|
|
*
|
|
|
|
* Purpose Test read/write string attribute.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2006-12-11 10:26:48 +08:00
|
|
|
/* Info for a string attribute */
|
2009-04-19 12:35:19 +08:00
|
|
|
const H5std_string ATTR1_FL_STR_NAME("String_attr 1");
|
|
|
|
const H5std_string ATTR2_FL_STR_NAME("String_attr 2");
|
|
|
|
const H5std_string ATTR_VL_STR_NAME("String_attr");
|
2006-12-11 10:26:48 +08:00
|
|
|
const H5std_string ATTRSTR_DATA("String Attribute");
|
2020-09-30 22:27:10 +08:00
|
|
|
const int ATTR_LEN = 17;
|
2006-12-11 10:26:48 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_string_attr()
|
2006-12-11 10:26:48 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
2010-02-27 00:55:49 +08:00
|
|
|
SUBTEST("I/O on FL and VL String Attributes");
|
2006-12-11 10:26:48 +08:00
|
|
|
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create file
|
|
|
|
H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fixed-lenth string attributes
|
|
|
|
//
|
|
|
|
// Create a fixed-length string datatype to refer to.
|
|
|
|
StrType fls_type(0, ATTR_LEN);
|
|
|
|
|
|
|
|
// Open the root group.
|
|
|
|
Group root = fid1.openGroup("/");
|
|
|
|
|
|
|
|
// Create dataspace for the attribute.
|
2020-09-30 22:27:10 +08:00
|
|
|
DataSpace att_space(H5S_SCALAR);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Test Attribute::write(...,const void *buf) with Fixed len string */
|
|
|
|
|
|
|
|
// Create an attribute for the root group.
|
|
|
|
Attribute gr_flattr1 = root.createAttribute(ATTR1_FL_STR_NAME, fls_type, att_space);
|
|
|
|
|
|
|
|
// Write data to the attribute.
|
|
|
|
gr_flattr1.write(fls_type, ATTRSTR_DATA.c_str());
|
|
|
|
|
|
|
|
/* Test Attribute::write(...,const H5std_string& strg) with FL string */
|
|
|
|
|
|
|
|
// Create an attribute for the root group.
|
|
|
|
Attribute gr_flattr2 = root.createAttribute(ATTR2_FL_STR_NAME, fls_type, att_space);
|
|
|
|
|
|
|
|
// Write data to the attribute.
|
|
|
|
gr_flattr2.write(fls_type, ATTRSTR_DATA);
|
|
|
|
|
|
|
|
/* Test Attribute::read(...,void *buf) with FL string */
|
|
|
|
|
|
|
|
// Read and verify the attribute string as a string of chars.
|
|
|
|
char flstring_att_check[ATTR_LEN];
|
|
|
|
gr_flattr1.read(fls_type, flstring_att_check);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str()) != 0)
|
|
|
|
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",
|
|
|
|
__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Read and verify the attribute string as a string of chars; buffer
|
|
|
|
// is dynamically allocated.
|
|
|
|
size_t attr_size = gr_flattr1.getInMemDataSize();
|
2020-09-30 22:27:10 +08:00
|
|
|
char * fl_dyn_string_att_check;
|
|
|
|
fl_dyn_string_att_check = new char[attr_size + 1];
|
2017-03-03 22:45:57 +08:00
|
|
|
gr_flattr1.read(fls_type, fl_dyn_string_att_check);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDstrcmp(fl_dyn_string_att_check, ATTRSTR_DATA.c_str()) != 0)
|
|
|
|
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",
|
|
|
|
__LINE__, ATTRSTR_DATA.c_str(), fl_dyn_string_att_check);
|
|
|
|
delete[] fl_dyn_string_att_check;
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Test Attribute::read(...,H5std_string& strg) with FL string */
|
|
|
|
|
|
|
|
// Read and verify the attribute string as an std::string.
|
|
|
|
H5std_string read_flstr1;
|
|
|
|
gr_flattr1.read(fls_type, read_flstr1);
|
|
|
|
if (read_flstr1 != ATTRSTR_DATA)
|
2020-09-30 22:27:10 +08:00
|
|
|
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_flstr1=%s\n", __LINE__,
|
|
|
|
ATTRSTR_DATA.c_str(), read_flstr1.c_str());
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Read and verify the attribute string as a string of chars.
|
|
|
|
HDstrcpy(flstring_att_check, "");
|
|
|
|
gr_flattr2.read(fls_type, flstring_att_check);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str()) != 0)
|
|
|
|
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",
|
|
|
|
__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
/* Test Attribute::read(...,H5std_string& strg) with FL string */
|
|
|
|
|
|
|
|
// Read and verify the attribute string as an std::string.
|
|
|
|
H5std_string read_flstr2;
|
|
|
|
gr_flattr2.read(fls_type, read_flstr2);
|
|
|
|
if (read_flstr2 != ATTRSTR_DATA)
|
2020-09-30 22:27:10 +08:00
|
|
|
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_flstr2=%s\n", __LINE__,
|
|
|
|
ATTRSTR_DATA.c_str(), read_flstr2.c_str());
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Variable-lenth string attributes
|
|
|
|
//
|
|
|
|
// Create a variable length string datatype to refer to.
|
|
|
|
StrType vls_type(0, H5T_VARIABLE);
|
|
|
|
|
|
|
|
// Create an attribute for the root group.
|
|
|
|
Attribute gr_vlattr = root.createAttribute(ATTR_VL_STR_NAME, vls_type, att_space);
|
|
|
|
|
|
|
|
// Write data to the attribute.
|
|
|
|
gr_vlattr.write(vls_type, ATTRSTR_DATA);
|
|
|
|
|
|
|
|
/* Test Attribute::read(...,void *buf) with Variable len string */
|
|
|
|
// Read and verify the attribute string as a string of chars.
|
|
|
|
char *string_att_check;
|
|
|
|
gr_vlattr.read(vls_type, &string_att_check);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (HDstrcmp(string_att_check, ATTRSTR_DATA.c_str()) != 0)
|
|
|
|
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",
|
|
|
|
__LINE__, ATTRSTR_DATA.c_str(), string_att_check);
|
2017-03-03 22:45:57 +08:00
|
|
|
HDfree(string_att_check);
|
|
|
|
|
|
|
|
/* Test Attribute::read(...,H5std_string& strg) with VL string */
|
|
|
|
// Read and verify the attribute string as an std::string.
|
|
|
|
H5std_string read_str;
|
|
|
|
gr_vlattr.read(vls_type, read_str);
|
|
|
|
if (read_str != ATTRSTR_DATA)
|
2020-09-30 22:27:10 +08:00
|
|
|
TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_str=%s\n", __LINE__,
|
|
|
|
ATTRSTR_DATA.c_str(), read_str.c_str());
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2006-12-11 10:26:48 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg());
|
2006-12-11 10:26:48 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_string_attr()
|
2006-12-11 10:26:48 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_exists
|
|
|
|
*
|
|
|
|
* Purpose Test checking for attribute existence.
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*
|
|
|
|
* Note
|
|
|
|
* Additional attrExists tests are in test_attr_rename().
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_exists()
|
2013-03-24 01:37:49 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
|
|
|
SUBTEST("Check Attribute Existence");
|
|
|
|
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open file.
|
|
|
|
H5File fid1(FILE_BASIC, H5F_ACC_RDWR);
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open the root group.
|
|
|
|
Group root = fid1.openGroup("/");
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check for existence of attribute
|
|
|
|
bool attr_exists = fid1.attrExists(ATTR1_FL_STR_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists",
|
|
|
|
"fid1, ATTR1_FL_STR_NAMEAttribute should exist but does not");
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check for existence of attribute
|
|
|
|
attr_exists = fid1.attrExists(FATTR1_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists",
|
|
|
|
"fid1,FATTR2_NAMEAttribute should exist but does not");
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open a group.
|
|
|
|
Group group = fid1.openGroup(GROUP1_NAME);
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check for existence of attribute
|
|
|
|
attr_exists = group.attrExists(ATTR2_NAME);
|
2021-08-24 05:14:53 +08:00
|
|
|
if (!attr_exists)
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("H5File::attrExists",
|
|
|
|
"group, ATTR2_NAMEAttribute should exist but does not");
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2013-03-24 01:37:49 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (InvalidActionException &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_exists()", __LINE__, __FILE__, E.getCDetailMsg());
|
2013-03-24 01:37:49 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_exists()", __LINE__, __FILE__, E.getCDetailMsg());
|
2013-03-24 01:37:49 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_exists()
|
2013-03-24 01:37:49 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_dense_create
|
|
|
|
*
|
|
|
|
* Purpose Test phase change properties
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2015-10-06 12:31:58 +08:00
|
|
|
const H5std_string FILE_CRTPROPS("tattr_crt_properties.h5");
|
2020-09-30 22:27:10 +08:00
|
|
|
const int NAME_BUF_SIZE = 1024;
|
|
|
|
const unsigned MAX_COMPACT_DEF = 8;
|
|
|
|
const unsigned MIN_DENSE_DEF = 6;
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_dense_create(FileCreatPropList &fcpl, FileAccPropList &fapl)
|
2015-10-06 12:31:58 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
|
|
|
SUBTEST("Dense Attribute Storage Creation");
|
|
|
|
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create file
|
2020-09-30 22:27:10 +08:00
|
|
|
H5File fid1(FILE_CRTPROPS, H5F_ACC_TRUNC, fcpl, fapl);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close file
|
|
|
|
fid1.close();
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Get size of file
|
2020-09-30 22:27:10 +08:00
|
|
|
h5_stat_size_t empty_filesize; // Size of empty file
|
2017-03-03 22:45:57 +08:00
|
|
|
empty_filesize = h5_get_file_size(FILE_CRTPROPS.c_str(), fapl.getId());
|
|
|
|
if (empty_filesize < 0)
|
2015-10-06 12:31:58 +08:00
|
|
|
TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
|
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Re-open file
|
|
|
|
fid1.openFile(FILE_CRTPROPS, H5F_ACC_RDWR, fapl);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for dataset
|
|
|
|
DataSpace ds_space(H5S_SCALAR);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataset creation property list.
|
|
|
|
DSetCreatPropList dcpl;
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
|
|
|
DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space, dcpl);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
unsigned max_compact = 0, min_dense = 0;
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Retrieve limits for compact/dense attribute storage
|
|
|
|
dcpl.getAttrPhaseChange(max_compact, min_dense);
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(max_compact, MAX_COMPACT_DEF, "DSetCreatPropList::getAttrPhaseChange", __LINE__, __FILE__);
|
|
|
|
verify_val(min_dense, MIN_DENSE_DEF, "DSetCreatPropList::getAttrPhaseChange", __LINE__, __FILE__);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Set new compact/dense attribute storage limits to some random numbers
|
|
|
|
dcpl.setAttrPhaseChange(7, 5);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Retrieve limits for compact/dense attribute storage and verify them
|
|
|
|
dcpl.getAttrPhaseChange(max_compact, min_dense);
|
2020-09-30 22:27:10 +08:00
|
|
|
verify_val(max_compact, static_cast<unsigned>(7), "DSetCreatPropList::getAttrPhaseChange", __LINE__,
|
|
|
|
__FILE__);
|
|
|
|
verify_val(min_dense, static_cast<unsigned>(5), "DSetCreatPropList::getAttrPhaseChange", __LINE__,
|
|
|
|
__FILE__);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close property list
|
|
|
|
dcpl.close();
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2018-09-19 13:57:37 +08:00
|
|
|
// H5O__is_attr_dense_test - un-usable
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Add attributes, until just before converting to dense storage
|
2020-09-30 22:27:10 +08:00
|
|
|
char attr_name[NAME_BUF_SIZE];
|
2017-03-03 22:45:57 +08:00
|
|
|
unsigned attr_num;
|
2020-09-30 22:27:10 +08:00
|
|
|
for (attr_num = 0; attr_num < max_compact; attr_num++) {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create attribute
|
2022-01-29 00:34:57 +08:00
|
|
|
snprintf(attr_name, sizeof(attr_name), "attr %02u", attr_num);
|
2017-03-03 22:45:57 +08:00
|
|
|
Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write data to the attribute
|
|
|
|
attr.write(PredType::NATIVE_UINT, &attr_num);
|
|
|
|
} // end for
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2018-09-19 13:57:37 +08:00
|
|
|
// H5O__is_attr_dense_test - un-usable
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
{ // Add one more attribute, to push into "dense" storage
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create another attribute
|
2022-01-29 00:34:57 +08:00
|
|
|
snprintf(attr_name, sizeof(attr_name), "attr %02u", attr_num);
|
2017-03-03 22:45:57 +08:00
|
|
|
Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Write data to the attribute
|
|
|
|
attr.write(PredType::NATIVE_UINT, &attr_num);
|
|
|
|
}
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Attempt to add attribute again, which should fail
|
2020-09-30 22:27:10 +08:00
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create another attribute
|
2022-01-29 00:34:57 +08:00
|
|
|
snprintf(attr_name, sizeof(attr_name), "attr %02u", attr_num);
|
2017-03-03 22:45:57 +08:00
|
|
|
Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// continuation here, that means no exception has been thrown
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("DataSet::createAttribute",
|
|
|
|
"Maximum number of attributes has been reached");
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (AttributeIException &E) // catching invalid action
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2015-10-06 12:31:58 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_dense_create()", __LINE__, __FILE__, E.getCDetailMsg());
|
2015-10-06 12:31:58 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_dense_create()
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr_corder_create_basic
|
|
|
|
*
|
|
|
|
* Purpose Test creation order properties
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
static void
|
|
|
|
test_attr_corder_create_basic(FileCreatPropList &fcpl, FileAccPropList &fapl)
|
2015-10-06 12:31:58 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
|
|
|
SUBTEST("Basic Code for Attributes with Creation Order Info");
|
|
|
|
|
|
|
|
try {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create file
|
2020-09-30 22:27:10 +08:00
|
|
|
H5File fid1(FILE_CRTPROPS, H5F_ACC_TRUNC, fcpl, fapl);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// Create dataset creation property list.
|
|
|
|
DSetCreatPropList dcpl;
|
|
|
|
|
|
|
|
// Get creation order indexing on object
|
|
|
|
unsigned crt_order_flags = 0;
|
2020-09-30 22:27:10 +08:00
|
|
|
crt_order_flags = dcpl.getAttrCrtOrder();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(static_cast<long>(crt_order_flags), 0, "DSetCreatPropList::getAttrCrtOrder", __LINE__,
|
|
|
|
__FILE__);
|
2017-03-03 22:45:57 +08:00
|
|
|
|
|
|
|
// 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
|
2020-09-30 22:27:10 +08:00
|
|
|
throw InvalidActionException("DSetCreatPropList::getAttrCrtOrder",
|
|
|
|
"Indexing cannot be set alone, order tracking is required");
|
2017-03-03 22:45:57 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (PropListIException &E) // catching invalid action
|
|
|
|
{
|
|
|
|
} // do nothing, exception expected
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// 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();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(crt_order_flags, static_cast<unsigned>(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED),
|
2020-09-30 22:27:10 +08:00
|
|
|
"DSetCreatPropList::getAttrCrtOrder", __LINE__, __FILE__);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create dataspace for dataset
|
|
|
|
DataSpace ds_space(H5S_SCALAR);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Create a dataset
|
|
|
|
DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space, dcpl);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close dataspace
|
|
|
|
ds_space.close();
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Check on dataset's attribute storage status.
|
2018-09-19 13:57:37 +08:00
|
|
|
// NOTE: Wrappers not available yet (H5O__is_attr_empty_test
|
|
|
|
// and H5O__is_attr_dense_test)
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close dataset
|
|
|
|
dataset.close();
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close property list
|
|
|
|
dcpl.close();
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Close file
|
|
|
|
fid1.close();
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Re-open file
|
|
|
|
fid1.openFile(FILE_CRTPROPS, H5F_ACC_RDWR, fapl);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Open dataset created previously
|
|
|
|
dataset = fid1.openDataSet(DSET1_NAME);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Retrieve dataset creation property list for the dataset
|
|
|
|
dcpl = dataset.getCreatePlist();
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Query the attribute creation properties
|
|
|
|
crt_order_flags = dcpl.getAttrCrtOrder();
|
2021-06-01 21:49:39 +08:00
|
|
|
verify_val(crt_order_flags, static_cast<unsigned>(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED),
|
2020-09-30 22:27:10 +08:00
|
|
|
"DSetCreatPropList::getAttrCrtOrder", __LINE__, __FILE__);
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
PASSED();
|
2015-10-06 12:31:58 +08:00
|
|
|
} // end try block
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr_corder_create_basic()", __LINE__, __FILE__, E.getCDetailMsg());
|
2015-10-06 12:31:58 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr_corder_create_basic()
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-12-05 02:21:12 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: test_attr
|
|
|
|
*
|
|
|
|
* Purpose Main attribute testing routine
|
|
|
|
*
|
|
|
|
* Return None
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
extern "C" void
|
|
|
|
test_attr()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
|
|
|
// Output message about test being performed
|
|
|
|
MESSAGE(5, ("Testing Attributes\n"));
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
try {
|
2015-10-06 12:31:58 +08:00
|
|
|
// 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
|
2015-10-20 14:28:17 +08:00
|
|
|
unsigned new_format;
|
2020-09-30 22:27:10 +08:00
|
|
|
for (new_format = FALSE; new_format <= TRUE; new_format++) {
|
2015-10-06 12:31:58 +08:00
|
|
|
FileAccPropList curr_fapl;
|
|
|
|
|
|
|
|
// Set the file access proplist for the type of format
|
2020-09-30 22:27:10 +08:00
|
|
|
if (new_format) {
|
2017-03-03 22:45:57 +08:00
|
|
|
MESSAGE(7, ("testing with new file format\n"));
|
|
|
|
curr_fapl = fapl_new;
|
2015-10-06 12:31:58 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
else {
|
2017-03-03 22:45:57 +08:00
|
|
|
MESSAGE(7, ("testing with old file format\n"));
|
|
|
|
curr_fapl = fapl;
|
2015-10-06 12:31:58 +08:00
|
|
|
}
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
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
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
test_attr_compound_write(); // Test complex datatype H5A writing code
|
|
|
|
test_attr_compound_read(); // Test complex datatype H5A reading code
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
test_attr_scalar_write(); // Test scalar dataspace H5A writing code
|
|
|
|
test_attr_scalar_read(); // Test scalar dataspace H5A reading code
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
test_attr_mult_write(); // Test writing multiple attributes
|
|
|
|
test_attr_mult_read(); // Test reading multiple attributes
|
|
|
|
test_attr_delete(); // Test deleting attributes
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
test_attr_dtype_shared(); // Test using shared datatypes in attributes
|
2015-10-06 12:31:58 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
test_string_attr(); // Test read/write string attribute
|
|
|
|
test_attr_exists(); // Test H5Location::attrExists
|
2015-10-06 12:31:58 +08:00
|
|
|
|
|
|
|
// Test with new format
|
2020-09-30 22:27:10 +08:00
|
|
|
if (new_format) {
|
2017-03-03 22:45:57 +08:00
|
|
|
// Test dense attribute storage creation
|
2015-10-06 12:31:58 +08:00
|
|
|
test_attr_dense_create(fcpl, curr_fapl);
|
|
|
|
|
2017-03-03 22:45:57 +08:00
|
|
|
// Test create objects with attribute creation info
|
2015-10-06 12:31:58 +08:00
|
|
|
test_attr_corder_create_basic(fcpl, curr_fapl);
|
|
|
|
}
|
|
|
|
} // end for
|
2020-09-30 22:27:10 +08:00
|
|
|
} // end try block
|
2006-12-11 10:26:48 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
catch (Exception &E) {
|
2017-03-03 22:45:57 +08:00
|
|
|
issue_fail_msg("test_attr()", __LINE__, __FILE__, E.getCDetailMsg());
|
2015-10-06 12:31:58 +08:00
|
|
|
}
|
2020-09-30 22:27:10 +08:00
|
|
|
} // test_attr()
|
2017-12-05 02:21:12 +08:00
|
|
|
|
2005-03-20 11:47:55 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2017-12-05 02:21:12 +08:00
|
|
|
* Function: cleanup_attr
|
2005-03-20 11:47:55 +08:00
|
|
|
*
|
2017-03-03 22:45:57 +08:00
|
|
|
* Purpose Cleanup temporary test files
|
2005-03-20 11:47:55 +08:00
|
|
|
*
|
2017-12-05 02:21:12 +08:00
|
|
|
* Return None
|
2005-03-20 11:47:55 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
extern "C" void
|
|
|
|
cleanup_attr()
|
2005-03-20 11:47:55 +08:00
|
|
|
{
|
2014-04-07 06:36:15 +08:00
|
|
|
HDremove(FILE_BASIC.c_str());
|
|
|
|
HDremove(FILE_COMPOUND.c_str());
|
|
|
|
HDremove(FILE_SCALAR.c_str());
|
|
|
|
HDremove(FILE_MULTI.c_str());
|
|
|
|
HDremove(FILE_DTYPE.c_str());
|
2015-10-06 12:31:58 +08:00
|
|
|
HDremove(FILE_CRTPROPS.c_str());
|
2005-03-20 11:47:55 +08:00
|
|
|
}
|