static int test_create_close(hid_t fid) { herr_t err; hid_t table; hid_t part_t; TESTING("H5PTcreate_fl and H5PTclose"); /* Create a datatype for the particle struct */ part_t = make_particle_type(); HDassert(part_t != -1); /* Create the table */ table = H5PTcreate_fl(fid, PT_NAME, part_t, (hsize_t)100, -1); H5Tclose(part_t); if( H5PTis_valid(table) < 0) goto out; #ifdef VLPT_REMOVED if( H5PTis_varlen(table) != 0) goto out; #endif /* VLPT_REMOVED */ /* Close the table */ err = H5PTclose(table); if( err < 0) goto out; PASSED(); return 0; out: H5_FAILED(); return -1; }
static int test_create_close(hid_t fid) { herr_t err; hid_t table; hid_t part_t; TESTING("H5PTcreate_fl and H5PTclose"); /* Create a datatype for the particle struct */ part_t = make_particle_type(); HDassert(part_t != -1); /* Create the table */ table = H5PTcreate_fl(fid, PT_NAME, part_t, (hsize_t)100, -1); H5Tclose(part_t); if( H5PTis_valid(table) < 0) goto error; if( H5PTis_varlen(table) != 0) goto error; /* Close the table */ err = H5PTclose(table); if( err < 0) goto error; PASSED(); return SUCCEED; error: H5_FAILED(); return FAIL; }
/*------------------------------------------------------------------------- * test_compress * * Ensures that a FL packet table can be compressed. * This test creates a file named TEST_COMPRESS_FILE * *------------------------------------------------------------------------- */ static int test_compress(void) { hid_t fid1 = -1; herr_t err; hid_t table = -1; hid_t part_t = -1; hid_t dset_id = -1; hid_t plist_id = -1; size_t c; size_t num_elems = 1; unsigned filter_vals[1]; particle_t readPart[1]; hsize_t count; TESTING("packet table compression"); /* Create a file. */ if((fid1 = H5Fcreate(TEST_COMPRESS_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Create a datatype for the particle struct */ part_t = make_particle_type(); HDassert(part_t != -1); /* Create a new table with compression level 8 */ table = H5PTcreate_fl(fid1, "Compressed Test Dataset", part_t, (hsize_t)80, 8); if( H5PTis_valid(table) < 0) TEST_ERROR; /* We can now use this table exactly the same way we use a normal uncompressed * packet table, and it should pass the same tests. */ /* Add many particles */ for(c = 0; c < BIG_TABLE_SIZE ; c+=8) { /* Append eight particles at once*/ err = H5PTappend(table, (size_t)8, &(testPart[0])); if( err < 0) TEST_ERROR; } /* Count the number of packets in the table */ err = H5PTget_num_packets(table, &count); if( err < 0) TEST_ERROR; if( count != BIG_TABLE_SIZE ) TEST_ERROR; /* Read particles to ensure that all of them were written correctly */ HDmemset(readPart, 0, sizeof(readPart)); for(c = 0; c < BIG_TABLE_SIZE; c++) { err = H5PTget_next(table, 1, readPart); if(err < 0) TEST_ERROR; /* Ensure that particles were read correctly */ if( cmp_par(c % 8, 0, testPart, readPart) != 0) TEST_ERROR; } /* Close the table */ err = H5PTclose(table); if( err < 0) TEST_ERROR; /* Open the packet table as a regular dataset and make sure that the * compression filter is set. */ dset_id = H5Dopen2(fid1, "Compressed Test Dataset", H5P_DEFAULT); if( dset_id < 0) TEST_ERROR; plist_id = H5Dget_create_plist(dset_id); if( plist_id < 0) TEST_ERROR; err = H5Pget_filter_by_id2(plist_id, H5Z_FILTER_DEFLATE, NULL, &num_elems, filter_vals, 0, NULL, NULL); if( err < 0) TEST_ERROR; /* The compression level should be 8, the value we passed in */ if(filter_vals[0] != 8) TEST_ERROR; /* Clean up */ err = H5Pclose(plist_id); if( err < 0) TEST_ERROR; err = H5Dclose(dset_id); if( err < 0) TEST_ERROR; /* Create a new table without compression. */ table = H5PTcreate_fl(fid1, "Uncompressed Dataset", part_t, (hsize_t)80, -1); if(table < 0) TEST_ERROR; /* Close the packet table */ err = H5PTclose(table); if( err < 0) TEST_ERROR; /* Open the packet table as a regular dataset and make sure that the * compression filter is not set. */ dset_id = H5Dopen2(fid1, "Uncompressed Dataset", H5P_DEFAULT); if( dset_id < 0) TEST_ERROR; plist_id = H5Dget_create_plist(dset_id); if( plist_id < 0) TEST_ERROR; H5E_BEGIN_TRY { err = H5Pget_filter_by_id2(plist_id, H5Z_FILTER_DEFLATE, NULL, &num_elems, filter_vals, 0, NULL, NULL); if( err >= 0) TEST_ERROR; } H5E_END_TRY /* Clean up */ err = H5Pclose(plist_id); if( err < 0) TEST_ERROR; err = H5Dclose(dset_id); if( err < 0) TEST_ERROR; /* Close the datatype and the file */ err = H5Tclose(part_t); if( err < 0) TEST_ERROR; err = H5Fclose(fid1); if( err < 0) TEST_ERROR; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Pclose(plist_id); H5Dclose(dset_id); H5Tclose(part_t); H5PTclose(table); H5Fclose(fid1); } H5E_END_TRY H5_FAILED(); return -1; }
/*------------------------------------------------------------------------- * test_big_table * * Ensures that a FL packet table will not break when many (BIG_TABLE_SIZE) * packets are used. * *------------------------------------------------------------------------- */ static int test_big_table(hid_t fid) { herr_t err; hid_t table; hid_t part_t; size_t c; particle_t readPart; hsize_t count; TESTING("large packet table"); /* Create a datatype for the particle struct */ part_t = make_particle_type(); HDassert(part_t != -1); /* Create a new table */ table = H5PTcreate_fl(fid, "Packet Test Dataset2", part_t, (hsize_t)33, -1); H5Tclose(part_t); if( H5PTis_valid(table) < 0) goto out; /* Add many particles */ for(c = 0; c < BIG_TABLE_SIZE ; c+=8) { /* Append eight particles at once*/ err = H5PTappend(table, (size_t)8, &(testPart[0])); if( err < 0) goto out; } /* Count the number of packets in the table */ err = H5PTget_num_packets(table, &count); if( err < 0) goto out; if( count != BIG_TABLE_SIZE ) goto out; /* Read particles to ensure that all of them were written correctly */ /* Also, ensure that H5PTcreate_fl set the current packet to */ /* the first packet in the table */ for(c = 0; c < BIG_TABLE_SIZE; c++) { err = H5PTget_next(table, 1, &readPart); if(err < 0) goto out; /* Ensure that particles were read correctly */ if( cmp_par(c % 8, 0, testPart, &readPart) != 0) goto out; } /* Close the table */ err = H5PTclose(table); if( err < 0) goto out; PASSED(); return 0; out: H5_FAILED(); if( H5PTis_valid(table) < 0) H5PTclose(table); return -1; }