1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /***********************************************************
15 *
16 * Test program:     tattr
17 *
18 * Test the attribute functionality
19 *
20 *************************************************************/
21 
22 #include "testhdf5.h"
23 
24 /*
25  * This file needs to access private information from the H5O package.
26  * This file also needs to access the object header testing code.
27  */
28 #define H5O_FRIEND        /*suppress error about including H5Opkg      */
29 #define H5O_TESTING
30 #include "H5Opkg.h"        /* Object headers             */
31 
32 /*
33  * This file needs to access private information from the H5A package.
34  * This file also needs to access the attribute testing code.
35  */
36 #define H5A_FRIEND        /*suppress error about including H5Apkg      */
37 #define H5A_TESTING
38 #include "H5Apkg.h"        /* Attributes                 */
39 
40 /*
41  * This file needs to access private information from the H5F package.
42  * This file also needs to access the file testing code.
43  */
44 #define H5F_FRIEND        /*suppress error about including H5Fpkg      */
45 #define H5F_TESTING
46 #include "H5Fpkg.h"        /* File access                 */
47 
48 #define FILENAME   "tattr.h5"
49 #define NAME_BUF_SIZE   1024
50 #define ATTR_NAME_LEN   16
51 #define ATTR_MAX_DIMS   7
52 #define ATTR_TMP_NAME   "a really long temp_name"
53 #define CORDER_ITER_STOP            3
54 
55 /* 3-D dataset with fixed dimensions */
56 #define SPACE1_RANK    3
57 #define SPACE1_DIM1    3
58 #define SPACE1_DIM2    15
59 #define SPACE1_DIM3    13
60 
61 /* Dataset Information */
62 #define DSET1_NAME "Dataset1"
63 #define DSET2_NAME "Dataset2"
64 #define DSET3_NAME "Dataset3"
65 #define NUM_DSETS       3
66 
67 /* Group Information */
68 #define GROUP1_NAME "/Group1"
69 #define GROUP2_NAME "/Group2"
70 #define GROUP3_NAME "/Group3"
71 
72 /* Named Datatype Information */
73 #define TYPE1_NAME "/Type"
74 
75 /* Attribute Rank & Dimensions */
76 #define ATTR1_NAME  "Attr1"
77 #define ATTR1_RANK    1
78 #define ATTR1_DIM1    3
79 int attr_data1[ATTR1_DIM1]={512,-234,98123}; /* Test data for 1st attribute */
80 
81 /* rank & dimensions for another attribute */
82 #define ATTR1A_NAME  "Attr1_a"
83 int attr_data1a[ATTR1_DIM1]={256,11945,-22107};
84 
85 #define ATTR2_NAME  "Attr2"
86 #define ATTR2_RANK    2
87 #define ATTR2_DIM1    2
88 #define ATTR2_DIM2    2
89 int attr_data2[ATTR2_DIM1][ATTR2_DIM2]={{7614,-416},{197814,-3}}; /* Test data for 2nd attribute */
90 
91 #define ATTR3_NAME  "Attr3"
92 #define ATTR3_RANK    3
93 #define ATTR3_DIM1    2
94 #define ATTR3_DIM2    2
95 #define ATTR3_DIM3    2
96 double attr_data3[ATTR3_DIM1][ATTR3_DIM2][ATTR3_DIM3]={{{2.3F,-26.1F}, {0.123F,-10.0F}},{{973.23F,-0.91827F},{2.0F,23.0F}}}; /* Test data for 3rd attribute */
97 
98 #define ATTR4_NAME  "Attr4"
99 #define ATTR4_RANK    2
100 #define ATTR4_DIM1    2
101 #define ATTR4_DIM2    2
102 #define ATTR4_FIELDNAME1    "i"
103 #define ATTR4_FIELDNAME2    "d"
104 #define ATTR4_FIELDNAME3    "c"
105 size_t attr4_field1_off=0;
106 size_t attr4_field2_off=0;
107 size_t attr4_field3_off=0;
108 struct attr4_struct {
109     int i;
110     double d;
111     char c;
112  } attr_data4[ATTR4_DIM1][ATTR4_DIM2]={{{3,-26.1F,'d'},{-100000, 0.123F,'3'}},
113     {{-23,981724.2F,'Q'},{0,2.0F,'\n'}}}; /* Test data for 4th attribute */
114 
115 #define ATTR5_NAME  "Attr5"
116 #define ATTR5_RANK    0
117 float attr_data5=-5.123F;        /* Test data for 5th attribute */
118 
119 #define ATTR6_RANK    3
120 #define ATTR6_DIM1    100
121 #define ATTR6_DIM2    100
122 #define ATTR6_DIM3    100
123 
124 #define ATTR7_NAME      "attr 1 - 000000"
125 #define ATTR8_NAME      "attr 2"
126 
127 #define LINK1_NAME      "Link1"
128 
129 #define NATTR_MANY_OLD  350
130 #define NATTR_MANY_NEW  35000
131 
132 #define BUG2_NATTR  100
133 #define BUG2_NATTR2 16
134 
135 #define BUG3_DSET_NAME  "dset"
136 #define BUG3_DT_NAME    "dt"
137 #define BUG3_ATTR_NAME  "attr"
138 
139 /* Used by test_attr_delete_last_dense() */
140 #define GRPNAME "grp"
141 #define ATTRNAME "attr"
142 #define DIM0 100
143 #define DIM1 100
144 #define RANK 2
145 
146 /* Attribute iteration struct */
147 typedef struct {
148     H5_iter_order_t order;      /* Direction of iteration */
149     unsigned ncalled;           /* # of times callback is entered */
150     unsigned nskipped;          /* # of attributes skipped */
151     int stop;                   /* # of iterations to stop after */
152     hsize_t curr;               /* Current creation order value */
153     size_t max_visit;           /* Size of "visited attribute" flag array */
154     hbool_t *visited;           /* Pointer to array of "visited attribute" flags */
155 } attr_iter_info_t;
156 
157 static herr_t attr_op1(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
158     void *op_data);
159 
160 /* Global dcpl ID, can be re-set as a generated dcpl for various operations
161  * across multiple tests.
162  * e.g., minimized dataset object headers
163  */
164 static hid_t dcpl_g = H5P_DEFAULT;
165 
166 
167 
168 /****************************************************************
169 **
170 **  test_attr_basic_write(): Test basic H5A (attribute) code.
171 **      Tests integer attributes on both datasets and groups
172 **
173 ****************************************************************/
174 static void
test_attr_basic_write(hid_t fapl)175 test_attr_basic_write(hid_t fapl)
176 {
177     hid_t        fid1;        /* HDF5 File IDs */
178     hid_t        dataset;     /* Dataset ID */
179     hid_t        group;       /* Group ID */
180     hid_t        sid1,sid2;   /* Dataspace ID */
181     hid_t        attr, attr2; /* Attribute ID */
182     hsize_t      attr_size;   /* storage size for attribute */
183     ssize_t      attr_name_size;     /* size of attribute name */
184     char         *attr_name=NULL;    /* name of attribute */
185     hsize_t      dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
186     hsize_t      dims2[] = {ATTR1_DIM1};
187     hsize_t      dims3[] = {ATTR2_DIM1,ATTR2_DIM2};
188     int          read_data1[ATTR1_DIM1]={0}; /* Buffer for reading 1st attribute */
189     int          i;
190     hid_t        ret_id;        /* Generic hid_t return value */
191     herr_t       ret;           /* Generic return value */
192 
193     /* Output message about test being performed */
194     MESSAGE(5, ("Testing Basic Scalar Attribute Writing Functions\n"));
195 
196     /* Create file */
197     fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
198     CHECK(fid1, FAIL, "H5Fcreate");
199 
200     /* Create dataspace for dataset */
201     sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
202     CHECK(sid1, FAIL, "H5Screate_simple");
203 
204     /* Create a dataset */
205     dataset = H5Dcreate2(fid1, DSET1_NAME, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
206     CHECK(dataset, FAIL, "H5Dcreate2");
207 
208     /* Create dataspace for attribute */
209     sid2 = H5Screate_simple(ATTR1_RANK, dims2, NULL);
210     CHECK(sid2, FAIL, "H5Screate_simple");
211 
212     /* Try to create an attribute on the file (should create an attribute on root group) */
213     attr = H5Acreate2(fid1, ATTR1_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
214     CHECK(attr, FAIL, "H5Acreate2");
215 
216     /* Close attribute */
217     ret = H5Aclose(attr);
218     CHECK(ret, FAIL, "H5Aclose");
219 
220     /* Open the root group */
221     group = H5Gopen2(fid1, "/", H5P_DEFAULT);
222     CHECK(group, FAIL, "H5Gopen2");
223 
224     /* Open attribute again */
225     attr = H5Aopen(group, ATTR1_NAME, H5P_DEFAULT);
226     CHECK(attr, FAIL, "H5Aopen");
227 
228     /* Close attribute */
229     ret = H5Aclose(attr);
230     CHECK(ret, FAIL, "H5Aclose");
231 
232     /* Close root group */
233     ret = H5Gclose(group);
234     CHECK(ret, FAIL, "H5Gclose");
235 
236     /* Create an attribute for the dataset */
237     attr = H5Acreate2(dataset, ATTR1_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
238     CHECK(attr, FAIL, "H5Acreate2");
239 
240     /* Try to create the same attribute again (should fail) */
241     ret_id = H5Acreate2(dataset, ATTR1_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
242     VERIFY(ret_id, FAIL, "H5Acreate2");
243 
244     /* Write attribute information */
245     ret = H5Awrite(attr, H5T_NATIVE_INT, attr_data1);
246     CHECK(ret, FAIL, "H5Awrite");
247 
248     /* Create an another attribute for the dataset */
249     attr2 = H5Acreate2(dataset, ATTR1A_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
250     CHECK(attr, FAIL, "H5Acreate2");
251 
252     /* Write attribute information */
253     ret = H5Awrite(attr2, H5T_NATIVE_INT, attr_data1a);
254     CHECK(ret, FAIL, "H5Awrite");
255 
256     /* Check storage size for attribute */
257     attr_size = H5Aget_storage_size(attr);
258     VERIFY(attr_size, (ATTR1_DIM1 * sizeof(int)), "H5A_get_storage_size");
259 
260     /* Read attribute information immediately, without closing attribute */
261     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
262     CHECK(ret, FAIL, "H5Aread");
263 
264     /* Verify values read in */
265     for(i = 0; i < ATTR1_DIM1; i++)
266         if(attr_data1[i] != read_data1[i])
267             TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
268 
269     /* Close attribute */
270     ret = H5Aclose(attr);
271     CHECK(ret, FAIL, "H5Aclose");
272 
273     /* Close attribute */
274     ret = H5Aclose(attr2);
275     CHECK(ret, FAIL, "H5Aclose");
276 
277     /* change attribute name */
278     ret = H5Arename(dataset, ATTR1_NAME, ATTR_TMP_NAME);
279     CHECK(ret, FAIL, "H5Arename");
280 
281     /* Open attribute again */
282     attr = H5Aopen(dataset, ATTR_TMP_NAME, H5P_DEFAULT);
283     CHECK(attr, FAIL, "H5Aopen");
284 
285     /* Verify new attribute name */
286     attr_name_size = H5Aget_name(attr, (size_t)0, NULL);
287     CHECK(attr_name_size, FAIL, "H5Aget_name");
288 
289     if(attr_name_size > 0) {
290         attr_name = (char*)HDcalloc((size_t)(attr_name_size + 1), sizeof(char));
291         CHECK_PTR(attr_name, "HDcalloc");
292 
293         if(attr_name) {
294             ret = (herr_t)H5Aget_name(attr, (size_t)(attr_name_size + 1), attr_name);
295             CHECK(ret, FAIL, "H5Aget_name");
296             ret = HDstrcmp(attr_name, ATTR_TMP_NAME);
297             VERIFY(ret, 0, "HDstrcmp");
298 
299             HDfree(attr_name);
300             attr_name = NULL;
301         } /* end if */
302     } /* end if */
303 
304     /* Read attribute information immediately, without closing attribute */
305     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
306     CHECK(ret, FAIL, "H5Aread");
307 
308     /* Verify values read in */
309     for(i = 0; i < ATTR1_DIM1; i++)
310         if(attr_data1[i] != read_data1[i])
311             TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
312 
313     /* Close attribute */
314     ret = H5Aclose(attr);
315     CHECK(ret, FAIL, "H5Aclose");
316 
317     /* Open the second attribute again */
318     attr2 = H5Aopen(dataset, ATTR1A_NAME, H5P_DEFAULT);
319     CHECK(attr, FAIL, "H5Aopen");
320 
321     /* Verify new attribute name */
322     attr_name_size = H5Aget_name(attr2, (size_t)0, NULL);
323     CHECK(attr_name_size, FAIL, "H5Aget_name");
324 
325     if(attr_name_size > 0) {
326         attr_name = (char*)HDcalloc((size_t)(attr_name_size+1), sizeof(char));
327         CHECK_PTR(attr_name, "HDcalloc");
328 
329         if(attr_name) {
330             ret = (herr_t)H5Aget_name(attr2, (size_t)(attr_name_size + 1), attr_name);
331             CHECK(ret, FAIL, "H5Aget_name");
332             ret = HDstrcmp(attr_name, ATTR1A_NAME);
333             VERIFY(ret, 0, "HDstrcmp");
334 
335             HDfree(attr_name);
336             attr_name = NULL;
337         } /* end if */
338     } /* end if */
339 
340     /* Read attribute information immediately, without closing attribute */
341     ret = H5Aread(attr2, H5T_NATIVE_INT, read_data1);
342     CHECK(ret, FAIL, "H5Aread");
343 
344     /* Verify values read in */
345     for(i = 0; i < ATTR1_DIM1; i++)
346         if(attr_data1a[i] != read_data1[i])
347             TestErrPrintf("%d: attribute data different: attr_data1a[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1a[i], i, read_data1[i]);
348 
349     /* Close attribute */
350     ret = H5Aclose(attr2);
351     CHECK(ret, FAIL, "H5Aclose");
352 
353     ret = H5Sclose(sid1);
354     CHECK(ret, FAIL, "H5Sclose");
355     ret = H5Sclose(sid2);
356     CHECK(ret, FAIL, "H5Sclose");
357 
358     /* Close Dataset */
359     ret = H5Dclose(dataset);
360     CHECK(ret, FAIL, "H5Dclose");
361 
362     /* Create group */
363     group = H5Gcreate2(fid1, GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
364     CHECK(group, FAIL, "H5Gcreate2");
365 
366     /* Create dataspace for attribute */
367     sid2 = H5Screate_simple(ATTR2_RANK, dims3, NULL);
368     CHECK(sid2, FAIL, "H5Screate_simple");
369 
370     /* Create an attribute for the group */
371     attr = H5Acreate2(group, ATTR2_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
372     CHECK(attr, FAIL, "H5Acreate2");
373 
374     /* Check storage size for attribute */
375     attr_size = H5Aget_storage_size(attr);
376     VERIFY(attr_size, (ATTR2_DIM1 * ATTR2_DIM2 * sizeof(int)), "H5Aget_storage_size");
377 
378     /* Try to create the same attribute again (should fail) */
379     ret_id = H5Acreate2(group, ATTR2_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
380     VERIFY(ret_id, FAIL, "H5Acreate2");
381 
382     /* Write attribute information */
383     ret = H5Awrite(attr, H5T_NATIVE_INT, attr_data2);
384     CHECK(ret, FAIL, "H5Awrite");
385 
386     /* Check storage size for attribute */
387     attr_size = H5Aget_storage_size(attr);
388     VERIFY(attr_size, (ATTR2_DIM1 * ATTR2_DIM2 * sizeof(int)), "H5A_get_storage_size");
389 
390     /* Close attribute */
391     ret = H5Aclose(attr);
392     CHECK(ret, FAIL, "H5Aclose");
393 
394     /* Close Attribute dataspace */
395     ret = H5Sclose(sid2);
396     CHECK(ret, FAIL, "H5Sclose");
397 
398     /* Close Group */
399     ret = H5Gclose(group);
400     CHECK(ret, FAIL, "H5Gclose");
401 
402     /* Close file */
403     ret = H5Fclose(fid1);
404     CHECK(ret, FAIL, "H5Fclose");
405 }   /* test_attr_basic_write() */
406 
407 
408 /****************************************************************
409 **
410 **  test_attr_basic_read(): Test basic H5A (attribute) code.
411 **
412 ****************************************************************/
413 static void
test_attr_basic_read(hid_t fapl)414 test_attr_basic_read(hid_t fapl)
415 {
416     hid_t       fid1;        /* HDF5 File IDs        */
417     hid_t       dataset;     /* Dataset ID            */
418     hid_t       group;       /* Group ID            */
419     hid_t       attr;        /* Attribute ID            */
420     H5O_info_t  oinfo;       /* Object info                  */
421     int         read_data1[ATTR1_DIM1] = {0}; /* Buffer for reading 1st attribute */
422     int         read_data2[ATTR2_DIM1][ATTR2_DIM2] = {{0}}; /* Buffer for reading 2nd attribute */
423     int         i, j;       /* Local index variables        */
424     herr_t      ret;        /* Generic return value        */
425 
426     /* Output message about test being performed */
427     MESSAGE(5, ("Testing Basic Attribute Functions\n"));
428 
429     /* Create file */
430     fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
431     CHECK(fid1, FAIL, "H5Fopen");
432 
433     /* Open the dataset */
434     dataset = H5Dopen2(fid1, DSET1_NAME, H5P_DEFAULT);
435     CHECK(dataset, FAIL, "H5Dopen2");
436 
437     /* Verify the correct number of attributes */
438     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
439     CHECK(ret, FAIL, "H5Oget_info");
440     VERIFY(oinfo.num_attrs, 2, "H5Oget_info");
441 
442     /* Open first attribute for the dataset */
443     attr = H5Aopen(dataset, ATTR_TMP_NAME, H5P_DEFAULT);
444     CHECK(attr, FAIL, "H5Aopen");
445 
446     /* Read attribute information */
447     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
448     CHECK(ret, FAIL, "H5Aread");
449 
450     /* Verify values read in */
451     for(i = 0; i < ATTR1_DIM1; i++)
452         if(attr_data1[i] != read_data1[i])
453             TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
454 
455     /* Close attribute */
456     ret = H5Aclose(attr);
457     CHECK(ret, FAIL, "H5Aclose");
458 
459     ret = H5Dclose(dataset);
460     CHECK(ret, FAIL, "H5Dclose");
461 
462     /* Open the group */
463     group = H5Gopen2(fid1, GROUP1_NAME, H5P_DEFAULT);
464     CHECK(group, FAIL, "H5Gopen2");
465 
466     /* Verify the correct number of attributes */
467     ret = H5Oget_info2(group, &oinfo, H5O_INFO_NUM_ATTRS);
468     CHECK(ret, FAIL, "H5Oget_info");
469     VERIFY(oinfo.num_attrs, 1, "H5Oget_info");
470 
471     /* Open the attribute for the group */
472     attr = H5Aopen(group, ATTR2_NAME, H5P_DEFAULT);
473     CHECK(attr, FAIL, "H5Aopen");
474 
475     /* Read attribute information */
476     ret = H5Aread(attr, H5T_NATIVE_INT, read_data2);
477     CHECK(ret, FAIL, "H5Aread");
478 
479     /* Verify values read in */
480     for(i = 0; i < ATTR2_DIM1; i++)
481         for(j = 0; j < ATTR2_DIM2; j++)
482             if(attr_data2[i][j] != read_data2[i][j])
483                 TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n", __LINE__,  i, j, attr_data2[i][j], i, j, read_data1[i]);
484 
485     /* Close attribute */
486     ret = H5Aclose(attr);
487     CHECK(ret, FAIL, "H5Aclose");
488 
489     /* Close group */
490     ret = H5Gclose(group);
491     CHECK(ret, FAIL, "H5Gclose");
492 
493     /* Close file */
494     ret = H5Fclose(fid1);
495     CHECK(ret, FAIL, "H5Fclose");
496 }   /* test_attr_basic_read() */
497 
498 
499 /****************************************************************
500 **
501 **  test_attr_flush(): Test H5A (attribute) code for performing
502 **                      I/O when H5Fflush is used.
503 **
504 ****************************************************************/
505 static void
test_attr_flush(hid_t fapl)506 test_attr_flush(hid_t fapl)
507 {
508     hid_t fil,          /* File ID */
509         att,            /* Attribute ID */
510         spc,            /* Dataspace ID */
511         set;            /* Dataset ID */
512     double wdata=3.14159F;       /* Data to write */
513     double rdata;       /* Data read in */
514     herr_t ret;         /* Generic return value        */
515 
516     /* Output message about test being performed */
517     MESSAGE(5, ("Testing Attribute Flushing\n"));
518 
519     fil = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
520     CHECK(fil, FAIL, "H5Fcreate");
521 
522     spc = H5Screate(H5S_SCALAR);
523     CHECK(spc, FAIL, "H5Screate");
524 
525     set = H5Dcreate2(fil, DSET1_NAME, H5T_NATIVE_DOUBLE, spc, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
526     CHECK(set, FAIL, "H5Dcreate2");
527 
528     att = H5Acreate2(set, ATTR1_NAME, H5T_NATIVE_DOUBLE, spc, H5P_DEFAULT, H5P_DEFAULT);
529     CHECK(att, FAIL, "H5Acreate2");
530 
531     ret=H5Aread(att, H5T_NATIVE_DOUBLE, &rdata);
532     CHECK(ret, FAIL, "H5Awrite");
533 
534     if(!H5_DBL_ABS_EQUAL(rdata, H5_DOUBLE(0.0)))
535         TestErrPrintf("attribute value wrong: rdata=%f, should be %f\n",rdata,(double)0.0F);
536 
537     ret=H5Fflush(fil, H5F_SCOPE_GLOBAL);
538     CHECK(ret, FAIL, "H5Fflush");
539 
540     ret=H5Aread(att, H5T_NATIVE_DOUBLE, &rdata);
541     CHECK(ret, FAIL, "H5Awrite");
542 
543     if(!H5_DBL_ABS_EQUAL(rdata, H5_DOUBLE(0.0)))
544         TestErrPrintf("attribute value wrong: rdata=%f, should be %f\n",rdata,(double)0.0F);
545 
546     ret=H5Awrite(att, H5T_NATIVE_DOUBLE, &wdata);
547     CHECK(ret, FAIL, "H5Awrite");
548 
549     ret=H5Aread(att, H5T_NATIVE_DOUBLE, &rdata);
550     CHECK(ret, FAIL, "H5Awrite");
551 
552     if(!H5_DBL_ABS_EQUAL(rdata,wdata))
553         TestErrPrintf("attribute value wrong: rdata=%f, should be %f\n",rdata,wdata);
554 
555     ret=H5Sclose(spc);
556     CHECK(ret, FAIL, "H5Sclose");
557     ret=H5Aclose(att);
558     CHECK(ret, FAIL, "H5Aclose");
559     ret=H5Dclose(set);
560     CHECK(ret, FAIL, "H5Dclose");
561     ret=H5Fclose(fil);
562     CHECK(ret, FAIL, "H5Fclose");
563 }   /* test_attr_flush() */
564 
565 
566 /****************************************************************
567 **
568 **  test_attr_plist(): Test Attribute Creation Property Lists
569 **
570 ****************************************************************/
571 static void
test_attr_plist(hid_t fapl)572 test_attr_plist(hid_t fapl)
573 {
574     hid_t       fid = H5I_INVALID_HID;          /* File ID */
575     hid_t       did = H5I_INVALID_HID;          /* Dataset ID */
576     hid_t       dsid = H5I_INVALID_HID;         /* Dataspace ID (for dataset) */
577     hid_t       asid = H5I_INVALID_HID;         /* Dataspace ID (for attribute) */
578     hid_t       aid = H5I_INVALID_HID;          /* Attribute ID */
579     hid_t       acpl_id = H5I_INVALID_HID;      /* Attribute creation property list ID */
580     hid_t       aapl_id = H5I_INVALID_HID;      /* Attribute access property list ID */
581     hsize_t     dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
582     hsize_t     dims2[] = {ATTR1_DIM1};
583     H5T_cset_t  cset;                           /* Character set for attributes */
584     herr_t      ret;                            /* Generic return value */
585 
586     /* Output message about test being performed */
587     MESSAGE(5, ("Testing Attribute Property Lists\n"));
588 
589     /* Create file */
590     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
591     CHECK(fid, H5I_INVALID_HID, "H5Fcreate");
592 
593     /* Create dataspace for dataset */
594     dsid = H5Screate_simple(SPACE1_RANK, dims1, NULL);
595     CHECK(dsid, H5I_INVALID_HID, "H5Screate_simple");
596 
597     /* Create a dataset */
598     did = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, dsid, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
599     CHECK(did, H5I_INVALID_HID, "H5Dcreate2");
600 
601     /* Create dataspace for attribute */
602     asid = H5Screate_simple(ATTR1_RANK, dims2, NULL);
603     CHECK(asid, H5I_INVALID_HID, "H5Screate_simple");
604 
605     /* Create default creation property list for attribute */
606     acpl_id = H5Pcreate(H5P_ATTRIBUTE_CREATE);
607     CHECK(acpl_id, H5I_INVALID_HID, "H5Pcreate");
608 
609     /* Create default access property list for attribute
610      * This currently has no properties, but we need to test its creation
611      * and use.
612      */
613     aapl_id = H5Pcreate(H5P_ATTRIBUTE_ACCESS);
614     CHECK(aapl_id, H5I_INVALID_HID, "H5Pcreate");
615 
616     /* Get the character encoding and ensure that it is the default (ASCII) */
617     ret = H5Pget_char_encoding(acpl_id, &cset);
618     CHECK(ret, FAIL, "H5Pget_char_encoding");
619     VERIFY(cset, H5T_CSET_ASCII, "H5Pget_char_encoding");
620 
621     /* Create an attribute for the dataset using the property list */
622     aid = H5Acreate2(did, ATTR1_NAME, H5T_NATIVE_INT, asid, acpl_id, aapl_id);
623     CHECK(aid, H5I_INVALID_HID, "H5Acreate2");
624 
625     /* Close the property list, and get the attribute's creation property list */
626     ret = H5Pclose(acpl_id);
627     CHECK(ret, FAIL, "H5Pclose");
628     acpl_id = H5Aget_create_plist(aid);
629     CHECK(acpl_id, H5I_INVALID_HID, "H5Aget_create_plist");
630 
631     /* Get the character encoding and ensure that it is the default (ASCII) */
632     ret = H5Pget_char_encoding(acpl_id, &cset);
633     CHECK(ret, FAIL, "H5Pget_char_encoding");
634     VERIFY(cset, H5T_CSET_ASCII, "H5Pget_char_encoding");
635 
636     /* Close the property list and attribute */
637     ret = H5Pclose(acpl_id);
638     CHECK(ret, FAIL, "H5Pclose");
639     ret = H5Aclose(aid);
640     CHECK(ret, FAIL, "H5Aclose");
641 
642     /* Create a new property list and modify it to use a different encoding */
643     acpl_id = H5Pcreate(H5P_ATTRIBUTE_CREATE);
644     CHECK(acpl_id, H5I_INVALID_HID, "H5Pcreate");
645     ret = H5Pset_char_encoding(acpl_id, H5T_CSET_UTF8);
646     CHECK(ret, FAIL, "H5Pset_char_encoding");
647 
648     /* Get the character encoding and ensure that it has been changed */
649     ret = H5Pget_char_encoding(acpl_id, &cset);
650     CHECK(ret, FAIL, "H5Pget_char_encoding");
651     VERIFY(cset, H5T_CSET_UTF8, "H5Pget_char_encoding");
652 
653     /* Create an attribute for the dataset using the modified property list */
654     aid = H5Acreate2(did, ATTR2_NAME, H5T_NATIVE_INT, asid, acpl_id, aapl_id);
655     CHECK(aid, H5I_INVALID_HID, "H5Acreate2");
656 
657     /* Close the property list and attribute */
658     ret = H5Pclose(acpl_id);
659     CHECK(ret, FAIL, "H5Pclose");
660     ret = H5Aclose(aid);
661     CHECK(ret, FAIL, "H5Aclose");
662 
663     /* Re-open the second attribute and ensure that its character encoding is correct */
664     aid = H5Aopen(did, ATTR2_NAME, H5P_DEFAULT);
665     CHECK(aid, H5I_INVALID_HID, "H5Aopen");
666     acpl_id = H5Aget_create_plist(aid);
667     CHECK(acpl_id, H5I_INVALID_HID, "H5Aget_create_plist");
668     ret = H5Pget_char_encoding(acpl_id, &cset);
669     CHECK(ret, FAIL, "H5Pget_char_encoding");
670     VERIFY(cset, H5T_CSET_UTF8, "H5Pget_char_encoding");
671 
672     /* Close everything */
673     ret = H5Sclose(dsid);
674     CHECK(ret, FAIL, "H5Sclose");
675     ret = H5Sclose(asid);
676     CHECK(ret, FAIL, "H5Sclose");
677     ret = H5Pclose(aapl_id);
678     CHECK(ret, FAIL, "H5Pclose");
679     ret = H5Pclose(acpl_id);
680     CHECK(ret, FAIL, "H5Pclose");
681     ret = H5Aclose(aid);
682     CHECK(ret, FAIL, "H5Aclose");
683     ret = H5Dclose(did);
684     CHECK(ret, FAIL, "H5Dclose");
685     ret = H5Fclose(fid);
686     CHECK(ret, FAIL, "H5Fclose");
687 }  /* test_attr_plist() */
688 
689 
690 /****************************************************************
691 **
692 **  test_attr_compound_write(): Test H5A (attribute) code.
693 **      Tests compound datatype attributes
694 **
695 ****************************************************************/
696 static void
test_attr_compound_write(hid_t fapl)697 test_attr_compound_write(hid_t fapl)
698 {
699     hid_t        fid1;        /* HDF5 File IDs        */
700     hid_t        dataset;     /* Dataset ID            */
701     hid_t        tid1;        /* Attribute datatype ID */
702     hid_t        sid1,sid2;   /* Dataspace ID            */
703     hid_t        attr;        /* Attribute ID            */
704     hsize_t      dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
705     hsize_t      dims2[] = {ATTR4_DIM1,ATTR4_DIM2};
706     hid_t        ret_id;        /* Generic hid_t return value    */
707     herr_t       ret;           /* Generic return value        */
708 
709     /* Output message about test being performed */
710     MESSAGE(5, ("Testing Multiple Attribute Functions\n"));
711 
712     /* Create file */
713     fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
714     CHECK(fid1, FAIL, "H5Fcreate");
715 
716     /* Create dataspace for dataset */
717     sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
718     CHECK(sid1, FAIL, "H5Screate_simple");
719 
720     /* Create a dataset */
721     dataset = H5Dcreate2(fid1, DSET1_NAME, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
722     CHECK(dataset, FAIL, "H5Dcreate2");
723 
724     /* Close dataset's dataspace */
725     ret = H5Sclose(sid1);
726     CHECK(ret, FAIL, "H5Sclose");
727 
728     /* Create the attribute datatype.  */
729     tid1 = H5Tcreate(H5T_COMPOUND, sizeof(struct attr4_struct));
730     CHECK(tid1, FAIL, "H5Tcreate");
731     attr4_field1_off = HOFFSET(struct attr4_struct, i);
732     ret = H5Tinsert(tid1, ATTR4_FIELDNAME1, attr4_field1_off, H5T_NATIVE_INT);
733     CHECK(ret, FAIL, "H5Tinsert");
734     attr4_field2_off = HOFFSET(struct attr4_struct, d);
735     ret = H5Tinsert(tid1, ATTR4_FIELDNAME2, attr4_field2_off, H5T_NATIVE_DOUBLE);
736     CHECK(ret, FAIL, "H5Tinsert");
737     attr4_field3_off = HOFFSET(struct attr4_struct, c);
738     ret = H5Tinsert(tid1, ATTR4_FIELDNAME3, attr4_field3_off, H5T_NATIVE_SCHAR);
739     CHECK(ret, FAIL, "H5Tinsert");
740 
741     /* Create dataspace for 1st attribute */
742     sid2 = H5Screate_simple(ATTR4_RANK, dims2, NULL);
743     CHECK(sid2, FAIL, "H5Screate_simple");
744 
745     /* Create complex attribute for the dataset */
746     attr = H5Acreate2(dataset, ATTR4_NAME, tid1, sid2, H5P_DEFAULT, H5P_DEFAULT);
747     CHECK(attr, FAIL, "H5Acreate2");
748 
749     /* Try to create the same attribute again (should fail) */
750     ret_id = H5Acreate2(dataset, ATTR4_NAME, tid1, sid2, H5P_DEFAULT, H5P_DEFAULT);
751     VERIFY(ret_id, FAIL, "H5Acreate2");
752 
753     /* Write complex attribute data */
754     ret = H5Awrite(attr, tid1, attr_data4);
755     CHECK(ret, FAIL, "H5Awrite");
756 
757     /* Close attribute */
758     ret = H5Aclose(attr);
759     CHECK(ret, FAIL, "H5Aclose");
760 
761     /* Close attribute's dataspace */
762     ret = H5Sclose(sid2);
763     CHECK(ret, FAIL, "H5Sclose");
764 
765     /* Close attribute's datatype */
766     ret = H5Tclose(tid1);
767     CHECK(ret, FAIL, "H5Tclose");
768 
769     /* Close Dataset */
770     ret = H5Dclose(dataset);
771     CHECK(ret, FAIL, "H5Dclose");
772 
773     /* Close file */
774     ret = H5Fclose(fid1);
775     CHECK(ret, FAIL, "H5Fclose");
776 }   /* test_attr_compound_write() */
777 
778 
779 /****************************************************************
780 **
781 **  test_attr_compound_read(): Test basic H5A (attribute) code.
782 **
783 ****************************************************************/
784 static void
test_attr_compound_read(hid_t fapl)785 test_attr_compound_read(hid_t fapl)
786 {
787     hid_t   fid1;       /* HDF5 File ID        */
788     hid_t   dataset;    /* Dataset ID        */
789     hid_t   space;      /* Attribute dataspace  */
790     hid_t   type;       /* Attribute datatype   */
791     hid_t   attr;       /* Attribute ID         */
792     char    attr_name[ATTR_NAME_LEN]; /* Buffer for attribute names */
793     int     rank;       /* Attribute rank */
794     hsize_t dims[ATTR_MAX_DIMS];    /* Attribute dimensions */
795     H5T_class_t t_class;  /* Attribute datatype class */
796     H5T_order_t order;  /* Attribute datatype order */
797     size_t      size;   /* Attribute datatype size as stored in file */
798     int     fields;     /* # of Attribute datatype fields */
799     char *fieldname;    /* Name of a field */
800     size_t  offset;     /* Attribute datatype field offset */
801     hid_t   field;      /* Attribute field datatype */
802     struct attr4_struct read_data4[ATTR4_DIM1][ATTR4_DIM2]; /* Buffer for reading 4th attribute */
803     ssize_t  name_len;  /* Length of attribute name */
804     H5O_info_t oinfo;   /* Object info */
805     int     i, j;       /* Local index variables */
806     herr_t  ret;        /* Generic return value    */
807 
808     /* Output message about test being performed */
809     MESSAGE(5, ("Testing Basic Attribute Functions\n"));
810 
811     /* Open file */
812     fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
813     CHECK(fid1, FAIL, "H5Fopen");
814 
815     /* Open the dataset */
816     dataset = H5Dopen2(fid1, DSET1_NAME, H5P_DEFAULT);
817     CHECK(dataset, FAIL, "H5Dopen2");
818 
819     /* Verify the correct number of attributes */
820     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
821     CHECK(ret, FAIL, "H5Oget_info");
822     VERIFY(oinfo.num_attrs, 1, "H5Oget_info");
823 
824     /* Open 1st attribute for the dataset */
825     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, H5P_DEFAULT, H5P_DEFAULT);
826     CHECK(attr, FAIL, "H5Aopen_by_idx");
827 
828     /* Verify Dataspace */
829     space = H5Aget_space(attr);
830     CHECK(space, FAIL, "H5Aget_space");
831     rank = H5Sget_simple_extent_ndims(space);
832     VERIFY(rank, ATTR4_RANK, "H5Sget_simple_extent_ndims");
833     ret = H5Sget_simple_extent_dims(space, dims, NULL);
834     CHECK(ret, FAIL, "H5Sget_simple_extent_dims");
835     if(dims[0] != ATTR4_DIM1)
836         TestErrPrintf("attribute dimensions different: dims[0]=%d, should be %d\n", (int)dims[0], ATTR4_DIM1);
837     if(dims[1] != ATTR4_DIM2)
838         TestErrPrintf("attribute dimensions different: dims[1]=%d, should be %d\n", (int)dims[1], ATTR4_DIM2);
839     H5Sclose(space);
840 
841     /* Verify Datatype */
842     type = H5Aget_type(attr);
843     CHECK(type, FAIL, "H5Aget_type");
844     t_class = H5Tget_class(type);
845     VERIFY(t_class, H5T_COMPOUND, "H5Tget_class");
846     fields = H5Tget_nmembers(type);
847     VERIFY(fields, 3, "H5Tget_nmembers");
848     for(i = 0; i < fields; i++) {
849         fieldname = H5Tget_member_name(type, (unsigned)i);
850         if(!(HDstrcmp(fieldname, ATTR4_FIELDNAME1) ||
851                 HDstrcmp(fieldname, ATTR4_FIELDNAME2) ||
852                 HDstrcmp(fieldname, ATTR4_FIELDNAME3)))
853             TestErrPrintf("invalid field name for field #%d: %s\n", i, fieldname);
854         H5free_memory(fieldname);
855     } /* end for */
856     offset = H5Tget_member_offset(type, 0);
857     VERIFY(offset, attr4_field1_off, "H5Tget_member_offset");
858     offset = H5Tget_member_offset(type, 1);
859     VERIFY(offset, attr4_field2_off, "H5Tget_member_offset");
860     offset = H5Tget_member_offset(type, 2);
861     VERIFY(offset, attr4_field3_off, "H5Tget_member_offset");
862 
863     /* Verify each field's type, class & size */
864     field = H5Tget_member_type(type, 0);
865     CHECK(field, FAIL, "H5Tget_member_type");
866     t_class = H5Tget_class(field);
867     VERIFY(t_class, H5T_INTEGER, "H5Tget_class");
868     order = H5Tget_order(field);
869     VERIFY_TYPE(order, H5Tget_order(H5T_NATIVE_INT), H5T_order_t, "%d", "H5Tget_order");
870     size = H5Tget_size(field);
871     VERIFY(size, H5Tget_size(H5T_NATIVE_INT), "H5Tget_size");
872     H5Tclose(field);
873     field = H5Tget_member_type(type, 1);
874     CHECK(field, FAIL, "H5Tget_member_type");
875     t_class = H5Tget_class(field);
876     VERIFY(t_class, H5T_FLOAT, "H5Tget_class");
877     order = H5Tget_order(field);
878     VERIFY_TYPE(order, H5Tget_order(H5T_NATIVE_DOUBLE), H5T_order_t, "%d", "H5Tget_order");
879     size = H5Tget_size(field);
880     VERIFY(size, H5Tget_size(H5T_NATIVE_DOUBLE), "H5Tget_size");
881     H5Tclose(field);
882     field = H5Tget_member_type(type, 2);
883     CHECK(field, FAIL, "H5Tget_member_type");
884     t_class = H5Tget_class(field);
885     VERIFY(t_class, H5T_INTEGER, "H5Tget_class");
886     order = H5Tget_order(field);
887     VERIFY_TYPE(order, H5Tget_order(H5T_NATIVE_SCHAR), H5T_order_t, "%d", "H5Tget_order");
888     size = H5Tget_size(field);
889     VERIFY(size, H5Tget_size(H5T_NATIVE_SCHAR), "H5Tget_size");
890     H5Tclose(field);
891 
892     /* Read attribute information */
893     ret = H5Aread(attr, type, read_data4);
894     CHECK(ret, FAIL, "H5Aread");
895 
896     /* Verify values read in */
897     for(i = 0; i < ATTR4_DIM1; i++)
898         for(j = 0; j < ATTR4_DIM2; j++)
899             if(HDmemcmp(&attr_data4[i][j], &read_data4[i][j], sizeof(struct attr4_struct))) {
900                 HDprintf("%d: attribute data different: attr_data4[%d][%d].i=%d, read_data4[%d][%d].i=%d\n", __LINE__, i, j, attr_data4[i][j].i, i, j, read_data4[i][j].i);
901                 HDprintf("%d: attribute data different: attr_data4[%d][%d].d=%f, read_data4[%d][%d].d=%f\n", __LINE__, i, j, attr_data4[i][j].d, i, j, read_data4[i][j].d);
902                 TestErrPrintf("%d: attribute data different: attr_data4[%d][%d].c=%c, read_data4[%d][%d].c=%c\n", __LINE__, i, j, attr_data4[i][j].c, i, j, read_data4[i][j].c);
903             } /* end if */
904 
905     /* Verify Name */
906     name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
907     VERIFY(name_len, HDstrlen(ATTR4_NAME), "H5Aget_name");
908     if(HDstrcmp(attr_name, ATTR4_NAME))
909         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n", attr_name, ATTR4_NAME);
910 
911     /* Close attribute datatype */
912     ret = H5Tclose(type);
913     CHECK(ret, FAIL, "H5Tclose");
914 
915     /* Close attribute */
916     ret = H5Aclose(attr);
917     CHECK(ret, FAIL, "H5Aclose");
918 
919     /* Close dataset */
920     ret = H5Dclose(dataset);
921     CHECK(ret, FAIL, "H5Dclose");
922 
923     /* Close file */
924     ret = H5Fclose(fid1);
925     CHECK(ret, FAIL, "H5Fclose");
926 }   /* test_attr_compound_read() */
927 
928 
929 /****************************************************************
930 **
931 **  test_attr_scalar_write(): Test scalar H5A (attribute) writing code.
932 **
933 ****************************************************************/
934 static void
test_attr_scalar_write(hid_t fapl)935 test_attr_scalar_write(hid_t fapl)
936 {
937     hid_t        fid1;        /* HDF5 File IDs        */
938     hid_t        dataset;     /* Dataset ID            */
939     hid_t        sid1,sid2;   /* Dataspace ID            */
940     hid_t        attr;        /* Attribute ID            */
941     hsize_t      dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
942     hid_t        ret_id;        /* Generic hid_t return value    */
943     herr_t       ret;           /* Generic return value        */
944 
945     /* Output message about test being performed */
946     MESSAGE(5, ("Testing Basic Attribute Functions\n"));
947 
948     /* Create file */
949     fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
950     CHECK(fid1, FAIL, "H5Fcreate");
951 
952     /* Create dataspace for dataset */
953     sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
954     CHECK(sid1, FAIL, "H5Screate_simple");
955 
956     /* Create a dataset */
957     dataset = H5Dcreate2(fid1, DSET1_NAME, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
958     CHECK(dataset, FAIL, "H5Dcreate2");
959 
960     /* Create dataspace for attribute */
961     sid2 = H5Screate_simple(ATTR5_RANK, NULL, NULL);
962     CHECK(sid2, FAIL, "H5Screate_simple");
963 
964     /* Create an attribute for the dataset */
965     attr = H5Acreate2(dataset, ATTR5_NAME, H5T_NATIVE_FLOAT, sid2, H5P_DEFAULT, H5P_DEFAULT);
966     CHECK(attr, FAIL, "H5Acreate2");
967 
968     /* Try to create the same attribute again (should fail) */
969     ret_id = H5Acreate2(dataset, ATTR5_NAME, H5T_NATIVE_FLOAT, sid2, H5P_DEFAULT, H5P_DEFAULT);
970     VERIFY(ret_id, FAIL, "H5Acreate2");
971 
972     /* Write attribute information */
973     ret = H5Awrite(attr, H5T_NATIVE_FLOAT, &attr_data5);
974     CHECK(ret, FAIL, "H5Awrite");
975 
976     /* Close attribute */
977     ret = H5Aclose(attr);
978     CHECK(ret, FAIL, "H5Aclose");
979 
980     ret = H5Sclose(sid1);
981     CHECK(ret, FAIL, "H5Sclose");
982     ret = H5Sclose(sid2);
983     CHECK(ret, FAIL, "H5Sclose");
984 
985     /* Close Dataset */
986     ret = H5Dclose(dataset);
987     CHECK(ret, FAIL, "H5Dclose");
988 
989     /* Close file */
990     ret = H5Fclose(fid1);
991     CHECK(ret, FAIL, "H5Fclose");
992 }   /* test_attr_scalar_write() */
993 
994 
995 /****************************************************************
996 **
997 **  test_attr_scalar_read(): Test scalar H5A (attribute) reading code.
998 **
999 ****************************************************************/
1000 static void
test_attr_scalar_read(hid_t fapl)1001 test_attr_scalar_read(hid_t fapl)
1002 {
1003     hid_t    fid1;        /* HDF5 File IDs        */
1004     hid_t    dataset;     /* Dataset ID            */
1005     hid_t    sid;         /* Dataspace ID            */
1006     hid_t    attr;        /* Attribute ID            */
1007     H5S_class_t stype;          /* Dataspace class              */
1008     float       rdata = 0.0F;   /* Buffer for reading 1st attribute */
1009     H5O_info_t  oinfo;          /* Object info                  */
1010     herr_t      ret;            /* Generic return value        */
1011 
1012     /* Output message about test being performed */
1013     MESSAGE(5, ("Testing Basic Scalar Attribute Reading Functions\n"));
1014 
1015     /* Create file */
1016     fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1017     CHECK(fid1, FAIL, "H5Fopen");
1018 
1019     /* Open the dataset */
1020     dataset = H5Dopen2(fid1, DSET1_NAME, H5P_DEFAULT);
1021     CHECK(dataset, FAIL, "H5Dopen2");
1022 
1023     /* Verify the correct number of attributes */
1024     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1025     CHECK(ret, FAIL, "H5Oget_info");
1026     VERIFY(oinfo.num_attrs, 1, "H5Oget_info");
1027 
1028     /* Open an attribute for the dataset */
1029     attr = H5Aopen(dataset, ATTR5_NAME, H5P_DEFAULT);
1030     CHECK(attr, FAIL, "H5Aopen");
1031 
1032     /* Read attribute information */
1033     ret = H5Aread(attr, H5T_NATIVE_FLOAT, &rdata);
1034     CHECK(ret, FAIL, "H5Aread");
1035 
1036     /* Verify the floating-poing value in this way to avoid compiler warning. */
1037     if(!H5_FLT_ABS_EQUAL(rdata, attr_data5))
1038         HDprintf("*** UNEXPECTED VALUE from %s should be %f, but is %f at line %4d in %s\n",
1039                 "H5Aread", (double)attr_data5, (double)rdata, (int)__LINE__, __FILE__);
1040 
1041     /* Get the attribute's dataspace */
1042     sid = H5Aget_space(attr);
1043     CHECK(sid, FAIL, "H5Aget_space");
1044 
1045     /* Make certain the dataspace is scalar */
1046     stype = H5Sget_simple_extent_type(sid);
1047     VERIFY(stype, H5S_SCALAR, "H5Sget_simple_extent_type");
1048 
1049     /* Close dataspace */
1050     ret = H5Sclose(sid);
1051     CHECK(ret, FAIL, "H5Sclose");
1052 
1053     /* Close attribute */
1054     ret = H5Aclose(attr);
1055     CHECK(ret, FAIL, "H5Aclose");
1056 
1057     ret = H5Dclose(dataset);
1058     CHECK(ret, FAIL, "H5Dclose");
1059 
1060     /* Close file */
1061     ret = H5Fclose(fid1);
1062     CHECK(ret, FAIL, "H5Fclose");
1063 }   /* test_attr_scalar_read() */
1064 
1065 
1066 /****************************************************************
1067 **
1068 **  test_attr_mult_write(): Test basic H5A (attribute) code.
1069 **      Tests integer attributes on both datasets and groups
1070 **
1071 ****************************************************************/
1072 static void
test_attr_mult_write(hid_t fapl)1073 test_attr_mult_write(hid_t fapl)
1074 {
1075     hid_t        fid1;        /* HDF5 File IDs        */
1076     hid_t        dataset;     /* Dataset ID            */
1077     hid_t        sid1,sid2;   /* Dataspace ID            */
1078     hid_t        attr;        /* Attribute ID            */
1079     hsize_t      dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
1080     hsize_t      dims2[] = {ATTR1_DIM1};
1081     hsize_t      dims3[] = {ATTR2_DIM1,ATTR2_DIM2};
1082     hsize_t      dims4[] = {ATTR3_DIM1,ATTR3_DIM2,ATTR3_DIM3};
1083     hid_t        ret_id;        /* Generic hid_t return value    */
1084     herr_t       ret;           /* Generic return value        */
1085 
1086     /* Output message about test being performed */
1087     MESSAGE(5, ("Testing Multiple Attribute Functions\n"));
1088 
1089     /* Create file */
1090     fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
1091     CHECK(fid1, FAIL, "H5Fcreate");
1092 
1093     /* Create dataspace for dataset */
1094     sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
1095     CHECK(sid1, FAIL, "H5Screate_simple");
1096 
1097     /* Create a dataset */
1098     dataset = H5Dcreate2(fid1, DSET1_NAME, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
1099     CHECK(dataset, FAIL, "H5Dcreate2");
1100 
1101     /* Close dataset's dataspace */
1102     ret = H5Sclose(sid1);
1103     CHECK(ret, FAIL, "H5Sclose");
1104 
1105     /* Create dataspace for 1st attribute */
1106     sid2 = H5Screate_simple(ATTR1_RANK, dims2, NULL);
1107     CHECK(sid2, FAIL, "H5Screate_simple");
1108 
1109     /* Create 1st attribute for the dataset */
1110     attr = H5Acreate2(dataset, ATTR1_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
1111     CHECK(attr, FAIL, "H5Acreate2");
1112 
1113     /* Try to create the same attribute again (should fail) */
1114     ret_id = H5Acreate2(dataset, ATTR1_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
1115     VERIFY(ret_id, FAIL, "H5Acreate2");
1116 
1117     /* Write 1st attribute data */
1118     ret = H5Awrite(attr, H5T_NATIVE_INT, attr_data1);
1119     CHECK(ret, FAIL, "H5Awrite");
1120 
1121     /* Close 1st attribute */
1122     ret = H5Aclose(attr);
1123     CHECK(ret, FAIL, "H5Aclose");
1124 
1125     /* Close attribute's dataspace */
1126     ret = H5Sclose(sid2);
1127     CHECK(ret, FAIL, "H5Sclose");
1128 
1129     /* Create dataspace for 2nd attribute */
1130     sid2 = H5Screate_simple(ATTR2_RANK, dims3, NULL);
1131     CHECK(sid2, FAIL, "H5Screate_simple");
1132 
1133     /* Create 2nd attribute for the dataset */
1134     attr = H5Acreate2(dataset, ATTR2_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
1135     CHECK(attr, FAIL, "H5Acreate2");
1136 
1137     /* Try to create the same attribute again (should fail) */
1138     ret_id = H5Acreate2(dataset, ATTR2_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
1139     VERIFY(ret_id, FAIL, "H5Acreate2");
1140 
1141     /* Write 2nd attribute information */
1142     ret = H5Awrite(attr, H5T_NATIVE_INT, attr_data2);
1143     CHECK(ret, FAIL, "H5Awrite");
1144 
1145     /* Close 2nd attribute */
1146     ret = H5Aclose(attr);
1147     CHECK(ret, FAIL, "H5Aclose");
1148 
1149     /* Close 2nd attribute's dataspace */
1150     ret = H5Sclose(sid2);
1151     CHECK(ret, FAIL, "H5Sclose");
1152 
1153     /* Create dataspace for 3rd attribute */
1154     sid2 = H5Screate_simple(ATTR3_RANK, dims4, NULL);
1155     CHECK(sid2, FAIL, "H5Screate_simple");
1156 
1157     /* Create 3rd attribute for the dataset */
1158     attr = H5Acreate2(dataset, ATTR3_NAME, H5T_NATIVE_DOUBLE, sid2, H5P_DEFAULT, H5P_DEFAULT);
1159     CHECK(attr, FAIL, "H5Acreate2");
1160 
1161     /* Try to create the same attribute again (should fail) */
1162     ret_id = H5Acreate2(dataset, ATTR3_NAME, H5T_NATIVE_DOUBLE, sid2, H5P_DEFAULT, H5P_DEFAULT);
1163     VERIFY(ret_id, FAIL, "H5Acreate2");
1164 
1165     /* Write 3rd attribute information */
1166     ret = H5Awrite(attr, H5T_NATIVE_DOUBLE, attr_data3);
1167     CHECK(ret, FAIL, "H5Awrite");
1168 
1169     /* Close 3rd attribute */
1170     ret = H5Aclose(attr);
1171     CHECK(ret, FAIL, "H5Aclose");
1172 
1173     /* Close 3rd attribute's dataspace */
1174     ret = H5Sclose(sid2);
1175     CHECK(ret, FAIL, "H5Sclose");
1176 
1177     /* Close Dataset */
1178     ret = H5Dclose(dataset);
1179     CHECK(ret, FAIL, "H5Dclose");
1180 
1181     /* Close file */
1182     ret = H5Fclose(fid1);
1183     CHECK(ret, FAIL, "H5Fclose");
1184 }   /* test_attr_mult_write() */
1185 
1186 
1187 /****************************************************************
1188 **
1189 **  test_attr_mult_read(): Test basic H5A (attribute) code.
1190 **
1191 ****************************************************************/
1192 static void
test_attr_mult_read(hid_t fapl)1193 test_attr_mult_read(hid_t fapl)
1194 {
1195     hid_t   fid1;       /* HDF5 File ID        */
1196     hid_t   dataset;    /* Dataset ID        */
1197     hid_t   space;      /* Attribute dataspace  */
1198     hid_t   type;       /* Attribute datatype   */
1199     hid_t   attr;       /* Attribute ID        */
1200     char    attr_name[ATTR_NAME_LEN]; /* Buffer for attribute names */
1201     char    temp_name[ATTR_NAME_LEN]; /* Buffer for mangling attribute names */
1202     int     rank;       /* Attribute rank */
1203     hsize_t dims[ATTR_MAX_DIMS];        /* Attribute dimensions */
1204     H5T_class_t t_class;        /* Attribute datatype class */
1205     H5T_order_t order;          /* Attribute datatype order */
1206     size_t      size;           /* Attribute datatype size as stored in file */
1207     int     read_data1[ATTR1_DIM1] = {0}; /* Buffer for reading 1st attribute */
1208     int     read_data2[ATTR2_DIM1][ATTR2_DIM2] = {{0}}; /* Buffer for reading 2nd attribute */
1209     double  read_data3[ATTR3_DIM1][ATTR3_DIM2][ATTR3_DIM3] = {{{0}}}; /* Buffer for reading 3rd attribute */
1210     ssize_t name_len;   /* Length of attribute name */
1211     H5O_info_t oinfo;   /* Object info */
1212     int     i, j, k;    /* Local index values */
1213     herr_t  ret;        /* Generic return value */
1214 
1215     /* Output message about test being performed */
1216     MESSAGE(5, ("Testing Basic Attribute Functions\n"));
1217 
1218     /* Open file */
1219     fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1220     CHECK(fid1, FAIL, "H5Fopen");
1221 
1222     /* Open the dataset */
1223     dataset = H5Dopen2(fid1, DSET1_NAME, H5P_DEFAULT);
1224     CHECK(dataset, FAIL, "H5Dopen2");
1225 
1226     /* Verify the correct number of attributes */
1227     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1228     CHECK(ret, FAIL, "H5Oget_info");
1229     VERIFY(oinfo.num_attrs, 3, "H5Oget_info");
1230 
1231     /* Open 1st attribute for the dataset */
1232     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, H5P_DEFAULT, H5P_DEFAULT);
1233     CHECK(attr, FAIL, "H5Aopen_by_idx");
1234 
1235     /* Verify Dataspace */
1236     space = H5Aget_space(attr);
1237     CHECK(space, FAIL, "H5Aget_space");
1238     rank = H5Sget_simple_extent_ndims(space);
1239     VERIFY(rank, ATTR1_RANK, "H5Sget_simple_extent_ndims");
1240     ret = H5Sget_simple_extent_dims(space, dims, NULL);
1241     CHECK(ret, FAIL, "H5Sget_simple_extent_dims");
1242     if(dims[0] != ATTR1_DIM1)
1243         TestErrPrintf("attribute dimensions different: dims[0]=%d, should be %d\n", (int)dims[0], ATTR1_DIM1);
1244     H5Sclose(space);
1245 
1246     /* Verify Datatype */
1247     type = H5Aget_type(attr);
1248     CHECK(type, FAIL, "H5Aget_type");
1249     t_class = H5Tget_class(type);
1250     VERIFY(t_class, H5T_INTEGER, "H5Tget_class");
1251     order = H5Tget_order(type);
1252     VERIFY_TYPE(order, H5Tget_order(H5T_NATIVE_INT), H5T_order_t, "%d", "H5Tget_order");
1253     size = H5Tget_size(type);
1254     VERIFY(size, H5Tget_size(H5T_NATIVE_INT), "H5Tget_size");
1255     H5Tclose(type);
1256 
1257     /* Read attribute information */
1258     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
1259     CHECK(ret, FAIL, "H5Aread");
1260 
1261     /* Verify values read in */
1262     for(i = 0; i < ATTR1_DIM1; i++)
1263         if(attr_data1[i] != read_data1[i])
1264             TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
1265 
1266     /* Verify Name */
1267     name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
1268     VERIFY(name_len, HDstrlen(ATTR1_NAME), "H5Aget_name");
1269     if(HDstrcmp(attr_name, ATTR1_NAME))
1270         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n", attr_name, ATTR1_NAME);
1271 
1272     /* Verify Name with too small of a buffer */
1273     name_len = H5Aget_name(attr,HDstrlen(ATTR1_NAME), attr_name);
1274     VERIFY(name_len, HDstrlen(ATTR1_NAME), "H5Aget_name");
1275     HDstrcpy(temp_name, ATTR1_NAME);     /* make a copy of the name */
1276     temp_name[HDstrlen(ATTR1_NAME) - 1] = '\0';   /* truncate it to match the one retrieved */
1277     if(HDstrcmp(attr_name, temp_name))
1278         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n", attr_name, temp_name);
1279 
1280     /* Close attribute */
1281     ret = H5Aclose(attr);
1282     CHECK(ret, FAIL, "H5Aclose");
1283 
1284     /* Open 2nd attribute for the dataset */
1285     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)1, H5P_DEFAULT, H5P_DEFAULT);
1286     CHECK(attr, FAIL, "H5Aopen_by_idx");
1287 
1288     /* Verify Dataspace */
1289     space = H5Aget_space(attr);
1290     CHECK(space, FAIL, "H5Aget_space");
1291     rank = H5Sget_simple_extent_ndims(space);
1292     VERIFY(rank, ATTR2_RANK, "H5Sget_simple_extent_ndims");
1293     ret = H5Sget_simple_extent_dims(space, dims, NULL);
1294     CHECK(ret, FAIL, "H5Sget_simple_extent_dims");
1295     if(dims[0] != ATTR2_DIM1)
1296         TestErrPrintf("attribute dimensions different: dims[0]=%d, should be %d\n", (int)dims[0], ATTR2_DIM1);
1297     if(dims[1] != ATTR2_DIM2)
1298         TestErrPrintf("attribute dimensions different: dims[1]=%d, should be %d\n", (int)dims[1], ATTR2_DIM2);
1299     H5Sclose(space);
1300 
1301     /* Verify Datatype */
1302     type = H5Aget_type(attr);
1303     CHECK(type, FAIL, "H5Aget_type");
1304     t_class = H5Tget_class(type);
1305     VERIFY(t_class, H5T_INTEGER, "H5Tget_class");
1306     order = H5Tget_order(type);
1307     VERIFY_TYPE(order, H5Tget_order(H5T_NATIVE_INT), H5T_order_t, "%d", "H5Tget_order");
1308     size = H5Tget_size(type);
1309     VERIFY(size, H5Tget_size(H5T_NATIVE_INT), "H5Tget_size");
1310     H5Tclose(type);
1311 
1312     /* Read attribute information */
1313     ret = H5Aread(attr, H5T_NATIVE_INT, read_data2);
1314     CHECK(ret, FAIL, "H5Aread");
1315 
1316     /* Verify values read in */
1317     for(i = 0; i < ATTR2_DIM1; i++)
1318         for(j = 0; j < ATTR2_DIM2; j++)
1319             if(attr_data2[i][j] != read_data2[i][j])
1320                 TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n", __LINE__, i, j, attr_data2[i][j], i, j, read_data2[i][j]);
1321 
1322     /* Verify Name */
1323     name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
1324     VERIFY(name_len, HDstrlen(ATTR2_NAME), "H5Aget_name");
1325     if(HDstrcmp(attr_name, ATTR2_NAME))
1326         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n", attr_name, ATTR2_NAME);
1327 
1328     /* Verify Name with too small of a buffer */
1329     name_len = H5Aget_name(attr, HDstrlen(ATTR2_NAME), attr_name);
1330     VERIFY(name_len, HDstrlen(ATTR2_NAME), "H5Aget_name");
1331     HDstrcpy(temp_name, ATTR2_NAME);     /* make a copy of the name */
1332     temp_name[HDstrlen(ATTR2_NAME) - 1] = '\0';   /* truncate it to match the one retrieved */
1333     if(HDstrcmp(attr_name, temp_name))
1334         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n", attr_name, temp_name);
1335 
1336     /* Close attribute */
1337     ret = H5Aclose(attr);
1338     CHECK(ret, FAIL, "H5Aclose");
1339 
1340     /* Open 2nd attribute for the dataset */
1341     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)2, H5P_DEFAULT, H5P_DEFAULT);
1342     CHECK(attr, FAIL, "H5Aopen_by_idx");
1343 
1344     /* Verify Dataspace */
1345     space = H5Aget_space(attr);
1346     CHECK(space, FAIL, "H5Aget_space");
1347     rank = H5Sget_simple_extent_ndims(space);
1348     VERIFY(rank, ATTR3_RANK, "H5Sget_simple_extent_ndims");
1349     ret = H5Sget_simple_extent_dims(space, dims, NULL);
1350     CHECK(ret, FAIL, "H5Sget_simple_extent_dims");
1351     if(dims[0] != ATTR3_DIM1)
1352         TestErrPrintf("attribute dimensions different: dims[0]=%d, should be %d\n", (int)dims[0], ATTR3_DIM1);
1353     if(dims[1] != ATTR3_DIM2)
1354         TestErrPrintf("attribute dimensions different: dims[1]=%d, should be %d\n", (int)dims[1], ATTR3_DIM2);
1355     if(dims[2] != ATTR3_DIM3)
1356         TestErrPrintf("attribute dimensions different: dims[2]=%d, should be %d\n", (int)dims[2], ATTR3_DIM3);
1357     H5Sclose(space);
1358 
1359     /* Verify Datatype */
1360     type = H5Aget_type(attr);
1361     CHECK(type, FAIL, "H5Aget_type");
1362     t_class = H5Tget_class(type);
1363     VERIFY(t_class, H5T_FLOAT, "H5Tget_class");
1364     order = H5Tget_order(type);
1365     VERIFY_TYPE(order, H5Tget_order(H5T_NATIVE_DOUBLE), H5T_order_t, "%d", "H5Tget_order");
1366     size = H5Tget_size(type);
1367     VERIFY(size, H5Tget_size(H5T_NATIVE_DOUBLE), "H5Tget_size");
1368     H5Tclose(type);
1369 
1370     /* Read attribute information */
1371     ret = H5Aread(attr, H5T_NATIVE_DOUBLE, read_data3);
1372     CHECK(ret, FAIL, "H5Aread");
1373 
1374     /* Verify values read in */
1375     for(i = 0; i < ATTR3_DIM1; i++)
1376         for(j = 0; j < ATTR3_DIM2; j++)
1377             for(k = 0; k < ATTR3_DIM3; k++)
1378                 if(!H5_DBL_ABS_EQUAL(attr_data3[i][j][k], read_data3[i][j][k]))
1379                     TestErrPrintf("%d: attribute data different: attr_data3[%d][%d][%d]=%f, read_data3[%d][%d][%d]=%f\n", __LINE__, i, j, k, attr_data3[i][j][k], i, j, k, read_data3[i][j][k]);
1380 
1381     /* Verify Name */
1382     name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
1383     VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
1384     if(HDstrcmp(attr_name, ATTR3_NAME))
1385         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n", attr_name, ATTR3_NAME);
1386 
1387     /* Verify Name with too small of a buffer */
1388     name_len = H5Aget_name(attr, HDstrlen(ATTR3_NAME), attr_name);
1389     VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
1390     HDstrcpy(temp_name, ATTR3_NAME);     /* make a copy of the name */
1391     temp_name[HDstrlen(ATTR3_NAME) - 1] = '\0';   /* truncate it to match the one retrieved */
1392     if(HDstrcmp(attr_name, temp_name))
1393         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n", attr_name, temp_name);
1394 
1395     /* Close attribute */
1396     ret = H5Aclose(attr);
1397     CHECK(ret, FAIL, "H5Aclose");
1398 
1399     /* Close dataset */
1400     ret = H5Dclose(dataset);
1401     CHECK(ret, FAIL, "H5Dclose");
1402 
1403     /* Close file */
1404     ret = H5Fclose(fid1);
1405     CHECK(ret, FAIL, "H5Fclose");
1406 }   /* test_attr_mult_read() */
1407 
1408 
1409 /****************************************************************
1410 **
1411 **  attr_op1(): Attribute operator
1412 **
1413 ****************************************************************/
1414 static herr_t
attr_op1(hid_t H5_ATTR_UNUSED loc_id,const char * name,const H5A_info_t H5_ATTR_UNUSED * ainfo,void * op_data)1415 attr_op1(hid_t H5_ATTR_UNUSED loc_id, const char *name, const H5A_info_t H5_ATTR_UNUSED *ainfo,
1416     void *op_data)
1417 {
1418     int *count = (int *)op_data;
1419     herr_t ret = 0;
1420 
1421     switch(*count) {
1422         case 0:
1423             if(HDstrcmp(name, ATTR1_NAME))
1424                 TestErrPrintf("attribute name different: name=%s, should be %s\n", name, ATTR1_NAME);
1425              (*count)++;
1426              break;
1427 
1428         case 1:
1429             if(HDstrcmp(name, ATTR2_NAME))
1430                 TestErrPrintf("attribute name different: name=%s, should be %s\n", name, ATTR2_NAME);
1431              (*count)++;
1432              break;
1433 
1434         case 2:
1435             if(HDstrcmp(name, ATTR3_NAME))
1436                 TestErrPrintf("attribute name different: name=%s, should be %s\n", name, ATTR3_NAME);
1437              (*count)++;
1438              break;
1439 
1440         default:
1441             ret = -1;
1442             break;
1443     }  /* end switch() */
1444 
1445     return(ret);
1446 } /* end attr_op1() */
1447 
1448 
1449 /****************************************************************
1450 **
1451 **  test_attr_iterate(): Test H5A (attribute) iterator code.
1452 **
1453 ****************************************************************/
1454 static void
test_attr_iterate(hid_t fapl)1455 test_attr_iterate(hid_t fapl)
1456 {
1457     hid_t   file;       /* HDF5 File ID         */
1458     hid_t   dataset;    /* Dataset ID            */
1459     hid_t   sid;        /* Dataspace ID            */
1460     int     count;      /* operator data for the iterator */
1461     H5O_info_t oinfo;   /* Object info                  */
1462     herr_t  ret;        /* Generic return value        */
1463 
1464     /* Output message about test being performed */
1465     MESSAGE(5, ("Testing Basic Attribute Functions\n"));
1466 
1467     /* Open file */
1468     file = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1469     CHECK(file, FAIL, "H5Fopen");
1470 
1471     /* Create a dataspace */
1472     sid = H5Screate(H5S_SCALAR);
1473     CHECK(sid, FAIL, "H5Screate");
1474 
1475     /* Create a new dataset */
1476     dataset = H5Dcreate2(file, DSET2_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
1477     CHECK(dataset, FAIL, "H5Dcreate2");
1478 
1479     /* Close dataspace */
1480     ret = H5Sclose(sid);
1481     CHECK(ret, FAIL, "H5Sclose");
1482 
1483     /* Verify the correct number of attributes */
1484     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1485     CHECK(ret, FAIL, "H5Oget_info");
1486     VERIFY(oinfo.num_attrs, 0, "H5Oget_info");
1487 
1488     /* Iterate over attributes on dataset */
1489     count = 0;
1490     ret = H5Aiterate2(dataset, H5_INDEX_NAME, H5_ITER_INC, NULL, attr_op1, &count);
1491     VERIFY(ret, 0, "H5Aiterate2");
1492 
1493     /* Close dataset */
1494     ret = H5Dclose(dataset);
1495     CHECK(ret, FAIL, "H5Dclose");
1496 
1497     /* Open existing dataset w/attributes */
1498     dataset = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT);
1499     CHECK(dataset, FAIL, "H5Dopen2");
1500 
1501     /* Verify the correct number of attributes */
1502     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1503     CHECK(ret, FAIL, "H5Oget_info");
1504     VERIFY(oinfo.num_attrs, 3, "H5Oget_info");
1505 
1506     /* Iterate over attributes on dataset */
1507     count = 0;
1508     ret = H5Aiterate2(dataset, H5_INDEX_NAME, H5_ITER_INC, NULL, attr_op1, &count);
1509     VERIFY(ret, 0, "H5Aiterate2");
1510 
1511     /* Close dataset */
1512     ret = H5Dclose(dataset);
1513     CHECK(ret, FAIL, "H5Dclose");
1514 
1515     /* Close file */
1516     ret = H5Fclose(file);
1517     CHECK(ret, FAIL, "H5Fclose");
1518 }   /* test_attr_iterate() */
1519 
1520 
1521 /****************************************************************
1522 **
1523 **  test_attr_delete(): Test H5A (attribute) code for deleting objects.
1524 **
1525 ****************************************************************/
1526 static void
test_attr_delete(hid_t fapl)1527 test_attr_delete(hid_t fapl)
1528 {
1529     hid_t   fid1;       /* HDF5 File ID         */
1530     hid_t   dataset;    /* Dataset ID            */
1531     hid_t   attr;       /* Attribute ID            */
1532     char    attr_name[ATTR_NAME_LEN]; /* Buffer for attribute names */
1533     ssize_t name_len;   /* Length of attribute name     */
1534     H5O_info_t oinfo;   /* Object info                  */
1535     herr_t  ret;        /* Generic return value        */
1536 
1537     /* Output message about test being performed */
1538     MESSAGE(5, ("Testing Basic Attribute Functions\n"));
1539 
1540     /* Open file */
1541     fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1542     CHECK(fid1, FAIL, "H5Fopen");
1543 
1544     /* Open the dataset */
1545     dataset = H5Dopen2(fid1, DSET1_NAME, H5P_DEFAULT);
1546     CHECK(dataset, FAIL, "H5Dopen2");
1547 
1548     /* Verify the correct number of attributes */
1549     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1550     CHECK(ret, FAIL, "H5Oget_info");
1551     VERIFY(oinfo.num_attrs, 3, "H5Oget_info");
1552 
1553     /* Try to delete bogus attribute */
1554     ret = H5Adelete(dataset, "Bogus");
1555     VERIFY(ret, FAIL, "H5Adelete");
1556 
1557     /* Verify the correct number of attributes */
1558     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1559     CHECK(ret, FAIL, "H5Oget_info");
1560     VERIFY(oinfo.num_attrs, 3, "H5Oget_info");
1561 
1562     /* Delete middle (2nd) attribute */
1563     ret = H5Adelete(dataset, ATTR2_NAME);
1564     CHECK(ret, FAIL, "H5Adelete");
1565 
1566     /* Verify the correct number of attributes */
1567     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1568     CHECK(ret, FAIL, "H5Oget_info");
1569     VERIFY(oinfo.num_attrs, 2, "H5Oget_info");
1570 
1571     /* Open 1st attribute for the dataset */
1572     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, H5P_DEFAULT, H5P_DEFAULT);
1573     CHECK(attr, FAIL, "H5Aopen_by_idx");
1574 
1575     /* Verify Name */
1576     name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
1577     VERIFY(name_len, HDstrlen(ATTR1_NAME), "H5Aget_name");
1578     if(HDstrcmp(attr_name, ATTR1_NAME))
1579         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR1_NAME);
1580 
1581     /* Close attribute */
1582     ret = H5Aclose(attr);
1583     CHECK(ret, FAIL, "H5Aclose");
1584 
1585     /* Open last (formally 3rd) attribute for the dataset */
1586     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)1, H5P_DEFAULT, H5P_DEFAULT);
1587     CHECK(attr, FAIL, "H5Aopen_by_idx");
1588 
1589     /* Verify Name */
1590     name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
1591     VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
1592     if(HDstrcmp(attr_name, ATTR3_NAME))
1593         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR3_NAME);
1594 
1595     /* Close attribute */
1596     ret = H5Aclose(attr);
1597     CHECK(ret, FAIL, "H5Aclose");
1598 
1599     /* Delete first attribute */
1600     ret = H5Adelete(dataset, ATTR1_NAME);
1601     CHECK(ret, FAIL, "H5Adelete");
1602 
1603     /* Verify the correct number of attributes */
1604     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1605     CHECK(ret, FAIL, "H5Oget_info");
1606     VERIFY(oinfo.num_attrs, 1, "H5Oget_info");
1607 
1608     /* Open last (formally 3rd) attribute for the dataset */
1609     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, H5P_DEFAULT, H5P_DEFAULT);
1610     CHECK(attr, FAIL, "H5Aopen_by_idx");
1611 
1612     /* Verify Name */
1613     name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
1614     VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
1615     if(HDstrcmp(attr_name, ATTR3_NAME))
1616         TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR3_NAME);
1617 
1618     /* Close attribute */
1619     ret = H5Aclose(attr);
1620     CHECK(ret, FAIL, "H5Aclose");
1621 
1622     /* Delete first attribute */
1623     ret = H5Adelete(dataset, ATTR3_NAME);
1624     CHECK(ret, FAIL, "H5Adelete");
1625 
1626     /* Verify the correct number of attributes */
1627     ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
1628     CHECK(ret, FAIL, "H5Oget_info");
1629     VERIFY(oinfo.num_attrs, 0, "H5Oget_info");
1630 
1631     /* Close dataset */
1632     ret = H5Dclose(dataset);
1633     CHECK(ret, FAIL, "H5Dclose");
1634 
1635     /* Close file */
1636     ret = H5Fclose(fid1);
1637     CHECK(ret, FAIL, "H5Fclose");
1638 }   /* test_attr_delete() */
1639 
1640 
1641 /****************************************************************
1642 **
1643 **  test_attr_dtype_shared(): Test H5A (attribute) code for using
1644 **                              shared datatypes in attributes.
1645 **
1646 ****************************************************************/
1647 static void
test_attr_dtype_shared(hid_t fapl)1648 test_attr_dtype_shared(hid_t fapl)
1649 {
1650     hid_t file_id;              /* File ID */
1651     hid_t dset_id;              /* Dataset ID */
1652     hid_t space_id;             /* Dataspace ID for dataset & attribute */
1653     hid_t type_id;              /* Datatype ID for named datatype */
1654     hid_t attr_id;              /* Attribute ID */
1655     int data = 8;               /* Data to write */
1656     int rdata = 0;              /* Read read in */
1657     H5O_info_t oinfo;           /* Object's information */
1658     h5_stat_size_t empty_filesize;       /* Size of empty file */
1659     h5_stat_size_t filesize;             /* Size of file after modifications */
1660     herr_t  ret;                /* Generic return value        */
1661 
1662     /* Output message about test being performed */
1663     MESSAGE(5, ("Testing Shared Datatypes with Attributes\n"));
1664 
1665     /* Create a file */
1666     file_id = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
1667     CHECK(file_id, FAIL, "H5Fopen");
1668 
1669     /* Close file */
1670     ret = H5Fclose(file_id);
1671     CHECK(ret, FAIL, "H5Fclose");
1672 
1673     /* Get size of file */
1674     empty_filesize = h5_get_file_size(FILENAME, fapl);
1675     if(empty_filesize < 0)
1676         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
1677 
1678     /* Re-open file */
1679     file_id = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1680     CHECK(file_id, FAIL, "H5Fopen");
1681 
1682     /* Create a datatype to commit and use */
1683     type_id = H5Tcopy(H5T_NATIVE_INT);
1684     CHECK(type_id, FAIL, "H5Tcopy");
1685 
1686     /* Commit datatype to file */
1687     ret = H5Tcommit2(file_id, TYPE1_NAME, type_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1688     CHECK(ret, FAIL, "H5Tcommit2");
1689 
1690     /* Check reference count on named datatype */
1691     ret = H5Oget_info_by_name2(file_id, TYPE1_NAME, &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
1692     CHECK(ret, FAIL, "H5Oget_info_by_name");
1693     VERIFY(oinfo.rc, 1, "H5Oget_info_by_name");
1694 
1695     /* Create dataspace for dataset */
1696     space_id = H5Screate(H5S_SCALAR);
1697     CHECK(space_id, FAIL, "H5Screate");
1698 
1699     /* Create dataset */
1700     dset_id = H5Dcreate2(file_id, DSET1_NAME, type_id, space_id, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
1701     CHECK(dset_id, FAIL, "H5Dcreate2");
1702 
1703     /* Check reference count on named datatype */
1704     ret = H5Oget_info_by_name2(file_id, TYPE1_NAME, &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
1705     CHECK(ret, FAIL, "H5Oget_info_by_name");
1706     VERIFY(oinfo.rc, 2, "H5Oget_info_by_name");
1707 
1708     /* Create attribute on dataset */
1709     attr_id = H5Acreate2(dset_id, ATTR1_NAME, type_id, space_id, H5P_DEFAULT, H5P_DEFAULT);
1710     CHECK(attr_id, FAIL, "H5Acreate2");
1711 
1712     /* Check reference count on named datatype */
1713     ret = H5Oget_info_by_name2(file_id, TYPE1_NAME, &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
1714     CHECK(ret, FAIL, "H5Oget_info_by_name");
1715     VERIFY(oinfo.rc, 3, "H5Oget_info_by_name");
1716 
1717     /* Close attribute */
1718     ret = H5Aclose(attr_id);
1719     CHECK(ret, FAIL, "H5Aclose");
1720 
1721     /* Delete attribute */
1722     ret = H5Adelete(dset_id, ATTR1_NAME);
1723     CHECK(ret, FAIL, "H5Adelete");
1724 
1725     /* Check reference count on named datatype */
1726     ret = H5Oget_info_by_name2(file_id, TYPE1_NAME, &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
1727     CHECK(ret, FAIL, "H5Oget_info_by_name");
1728     VERIFY(oinfo.rc, 2, "H5Oget_info_by_name");
1729 
1730     /* Create attribute on dataset */
1731     attr_id = H5Acreate2(dset_id, ATTR1_NAME, type_id, space_id, H5P_DEFAULT, H5P_DEFAULT);
1732     CHECK(attr_id, FAIL, "H5Acreate2");
1733 
1734     /* Check reference count on named datatype */
1735     ret = H5Oget_info_by_name2(file_id, TYPE1_NAME, &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
1736     CHECK(ret, FAIL, "H5Oget_info_by_name");
1737     VERIFY(oinfo.rc, 3, "H5Oget_info_by_name");
1738 
1739     /* Write data into the attribute */
1740     ret = H5Awrite(attr_id, H5T_NATIVE_INT, &data);
1741     CHECK(ret, FAIL, "H5Awrite");
1742 
1743     /* Close attribute */
1744     ret = H5Aclose(attr_id);
1745     CHECK(ret, FAIL, "H5Aclose");
1746 
1747     /* Close dataset */
1748     ret = H5Dclose(dset_id);
1749     CHECK(ret, FAIL, "H5Dclose");
1750 
1751     /* Close dataspace */
1752     ret = H5Sclose(space_id);
1753     CHECK(ret, FAIL, "H5Sclose");
1754 
1755     /* Close datatype */
1756     ret = H5Tclose(type_id);
1757     CHECK(ret, FAIL, "H5Tclose");
1758 
1759     /* Close file */
1760     ret = H5Fclose(file_id);
1761     CHECK(ret, FAIL, "H5Fclose");
1762 
1763 
1764     /* Re-open file */
1765     file_id = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1766     CHECK(file_id, FAIL, "H5Fopen");
1767 
1768     /* Open dataset */
1769     dset_id = H5Dopen2(file_id, DSET1_NAME, H5P_DEFAULT);
1770     CHECK(dset_id, FAIL, "H5Dopen2");
1771 
1772     /* Open attribute */
1773     attr_id = H5Aopen(dset_id, ATTR1_NAME, H5P_DEFAULT);
1774     CHECK(attr_id, FAIL, "H5Aopen");
1775 
1776     /* Read data from the attribute */
1777     ret = H5Aread(attr_id, H5T_NATIVE_INT, &rdata);
1778     CHECK(ret, FAIL, "H5Aread");
1779     VERIFY(data, rdata, "H5Aread");
1780 
1781     /* Close attribute */
1782     ret = H5Aclose(attr_id);
1783     CHECK(ret, FAIL, "H5Aclose");
1784 
1785     /* Close dataset */
1786     ret = H5Dclose(dset_id);
1787     CHECK(ret, FAIL, "H5Dclose");
1788 
1789     /* Check reference count on named datatype */
1790     ret = H5Oget_info_by_name2(file_id, TYPE1_NAME, &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
1791     CHECK(ret, FAIL, "H5Oget_info_by_name");
1792     VERIFY(oinfo.rc, 3, "H5Oget_info_by_name");
1793 
1794     /* Unlink the dataset */
1795     ret = H5Ldelete(file_id, DSET1_NAME, H5P_DEFAULT);
1796     CHECK(ret, FAIL, "H5Ldelete");
1797 
1798     /* Check reference count on named datatype */
1799     ret = H5Oget_info_by_name2(file_id, TYPE1_NAME, &oinfo, H5O_INFO_BASIC, H5P_DEFAULT);
1800     CHECK(ret, FAIL, "H5Oget_info_by_name");
1801     VERIFY(oinfo.rc, 1, "H5Oget_info_by_name");
1802 
1803     /* Unlink the named datatype */
1804     ret = H5Ldelete(file_id, TYPE1_NAME, H5P_DEFAULT);
1805     CHECK(ret, FAIL, "H5Ldelete");
1806 
1807     /* Close file */
1808     ret = H5Fclose(file_id);
1809     CHECK(ret, FAIL, "H5Fclose");
1810 
1811     /* Check size of file */
1812     filesize = h5_get_file_size(FILENAME, fapl);
1813     VERIFY(filesize, empty_filesize, "h5_get_file_size");
1814 }   /* test_attr_dtype_shared() */
1815 
1816 
1817 /****************************************************************
1818 **
1819 **  test_attr_duplicate_ids(): Test operations with more than
1820 **      one ID handles.
1821 **
1822 ****************************************************************/
1823 static void
test_attr_duplicate_ids(hid_t fapl)1824 test_attr_duplicate_ids(hid_t fapl)
1825 {
1826     hid_t        fid1;         /* HDF5 File IDs        */
1827     hid_t        dataset;      /* Dataset ID            */
1828     hid_t        gid1, gid2;   /* Group ID            */
1829     hid_t        sid1,sid2;    /* Dataspace ID            */
1830     hid_t        attr, attr2;  /* Attribute ID        */
1831     hsize_t      dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
1832     hsize_t      dims2[] = {ATTR1_DIM1};
1833     int          read_data1[ATTR1_DIM1]={0}; /* Buffer for reading 1st attribute */
1834     int          rewrite_data[ATTR1_DIM1]={1234, -423, 9907256}; /* Test data for rewrite */
1835     int          i;
1836     herr_t       ret;        /* Generic return value        */
1837 
1838     /* Output message about test being performed */
1839     MESSAGE(5, ("Testing operations with two ID handles\n"));
1840 
1841     /*-----------------------------------------------------------------------------------
1842      *        Create an attribute in a new file and fill it with fill value.
1843      */
1844     /* Create file */
1845     fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
1846     CHECK(fid1, FAIL, "H5Fcreate");
1847 
1848     /* Create dataspace for dataset */
1849     sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
1850     CHECK(sid1, FAIL, "H5Screate_simple");
1851 
1852     /* Create a dataset */
1853     dataset = H5Dcreate2(fid1, DSET1_NAME, H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT,
1854             dcpl_g, H5P_DEFAULT);
1855     CHECK(dataset, FAIL, "H5Dcreate2");
1856 
1857     /* Create dataspace for attribute */
1858     sid2 = H5Screate_simple(ATTR1_RANK, dims2, NULL);
1859     CHECK(sid2, FAIL, "H5Screate_simple");
1860 
1861     /* Try to create an attribute on the dataset */
1862     attr = H5Acreate2(dataset, ATTR1_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
1863     CHECK(attr, FAIL, "H5Acreate2");
1864 
1865     /* Open the attribute just created and get a second ID */
1866     attr2 = H5Aopen(dataset, ATTR1_NAME, H5P_DEFAULT);
1867     CHECK(attr2, FAIL, "H5Aopen");
1868 
1869     /* Close attribute */
1870     ret = H5Aclose(attr2);
1871     CHECK(ret, FAIL, "H5Aclose");
1872 
1873     /* Close attribute */
1874     ret = H5Aclose(attr);
1875     CHECK(ret, FAIL, "H5Aclose");
1876 
1877     /* Close Dataset */
1878     ret = H5Dclose(dataset);
1879     CHECK(ret, FAIL, "H5Dclose");
1880 
1881     /* Close file */
1882     ret = H5Fclose(fid1);
1883     CHECK(ret, FAIL, "H5Fclose");
1884 
1885     /*-----------------------------------------------------------------------------------
1886      *        Reopen the file and verify the fill value for attribute.  Also write
1887      *        some real data.
1888      */
1889 
1890     /* Open file */
1891     fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1892     CHECK(fid1, FAIL, "H5Fopen");
1893 
1894     /* Open the dataset */
1895     dataset = H5Dopen2(fid1, DSET1_NAME, H5P_DEFAULT);
1896     CHECK(dataset, FAIL, "H5Dopen2");
1897 
1898     /* Open first attribute for the dataset */
1899     attr = H5Aopen(dataset, ATTR1_NAME, H5P_DEFAULT);
1900     CHECK(attr, FAIL, "H5Aopen");
1901 
1902     /* Read attribute with fill value */
1903     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
1904     CHECK(ret, FAIL, "H5Aread");
1905 
1906     /* Verify values read in */
1907     for(i = 0; i < ATTR1_DIM1; i++)
1908         if(0 != read_data1[i])
1909             TestErrPrintf("%d: attribute data different: read_data1[%d]=%d\n", __LINE__, i, read_data1[i]);
1910 
1911     /* Open attribute for the second time */
1912     attr2 = H5Aopen(dataset, ATTR1_NAME, H5P_DEFAULT);
1913     CHECK(attr, FAIL, "H5Aopen");
1914 
1915     /* Write attribute information */
1916     ret = H5Awrite(attr2, H5T_NATIVE_INT, attr_data1);
1917     CHECK(ret, FAIL, "H5Awrite");
1918 
1919     /* Close attribute */
1920     ret = H5Aclose(attr2);
1921     CHECK(ret, FAIL, "H5Aclose");
1922 
1923     /* Close attribute */
1924     ret = H5Aclose(attr);
1925     CHECK(ret, FAIL, "H5Aclose");
1926 
1927     /* Close Dataset */
1928     ret = H5Dclose(dataset);
1929     CHECK(ret, FAIL, "H5Dclose");
1930 
1931     /* Close file */
1932     ret = H5Fclose(fid1);
1933     CHECK(ret, FAIL, "H5Fclose");
1934 
1935     /*-----------------------------------------------------------------------------------
1936      *        Reopen the file and verify the data.  Also rewrite the data and verify it.
1937      */
1938 
1939     /* Open file */
1940     fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1941     CHECK(fid1, FAIL, "H5Fopen");
1942 
1943     /* Open the dataset */
1944     dataset = H5Dopen2(fid1, DSET1_NAME, H5P_DEFAULT);
1945     CHECK(dataset, FAIL, "H5Dopen2");
1946 
1947     /* Open first attribute for the dataset */
1948     attr = H5Aopen(dataset, ATTR1_NAME, H5P_DEFAULT);
1949     CHECK(attr, FAIL, "H5Aopen");
1950 
1951     /* Read attribute information */
1952     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
1953     CHECK(ret, FAIL, "H5Aread");
1954 
1955     /* Verify values read in */
1956     for(i = 0; i < ATTR1_DIM1; i++)
1957         if(attr_data1[i] != read_data1[i])
1958             TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
1959 
1960     /* Open attribute for the second time */
1961     attr2 = H5Aopen(dataset, ATTR1_NAME, H5P_DEFAULT);
1962     CHECK(attr, FAIL, "H5Aopen");
1963 
1964     /* Write attribute information */
1965     ret = H5Awrite(attr2, H5T_NATIVE_INT, rewrite_data);
1966     CHECK(ret, FAIL, "H5Awrite");
1967 
1968     /* Read attribute information */
1969     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
1970     CHECK(ret, FAIL, "H5Aread");
1971 
1972     /* Verify values read in */
1973     for(i = 0; i < ATTR1_DIM1; i++)
1974         if(read_data1[i] != rewrite_data[i])
1975             TestErrPrintf("%d: attribute data different: read_data1[%d]=%d, rewrite_data[%d]=%d\n", __LINE__, i, read_data1[i], i, rewrite_data[i]);
1976 
1977     /* Close attribute */
1978     ret = H5Aclose(attr);
1979     CHECK(ret, FAIL, "H5Aclose");
1980 
1981     ret = H5Aclose(attr2);
1982     CHECK(ret, FAIL, "H5Aclose");
1983 
1984     /* Close Dataset */
1985     ret = H5Dclose(dataset);
1986     CHECK(ret, FAIL, "H5Dclose");
1987 
1988     /* Close file */
1989     ret = H5Fclose(fid1);
1990     CHECK(ret, FAIL, "H5Fclose");
1991 
1992     /*-----------------------------------------------------------------------------------
1993      *        Verify that the attribute being pointed to by different paths shares
1994      *        the same data.
1995      */
1996     /* Open file */
1997     fid1 = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
1998     CHECK(fid1, FAIL, "H5Fopen");
1999 
2000     /* Create a group */
2001     gid1 = H5Gcreate2(fid1, GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
2002     CHECK(gid1, FAIL, "H5Gcreate2");
2003 
2004     /* Create hard link to the first group */
2005     ret = H5Lcreate_hard(gid1, GROUP1_NAME, H5L_SAME_LOC, GROUP2_NAME, H5P_DEFAULT,
2006         H5P_DEFAULT);
2007     CHECK(ret, FAIL, "H5Lcreate_hard");
2008 
2009     /* Try to create an attribute on the group */
2010     attr = H5Acreate2(gid1, ATTR2_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
2011     CHECK(attr, FAIL, "H5Acreate2");
2012 
2013     /* Open the hard link just created */
2014     gid2 = H5Gopen2(fid1, GROUP2_NAME, H5P_DEFAULT);
2015     CHECK(gid2, FAIL, "H5Gopen2");
2016 
2017     /* Open the attribute of the group for the second time */
2018     attr2 = H5Aopen(gid2, ATTR2_NAME, H5P_DEFAULT);
2019     CHECK(attr2, FAIL, "H5Aopen");
2020 
2021     /* Write attribute information with the first attribute handle */
2022     ret = H5Awrite(attr, H5T_NATIVE_INT, attr_data1);
2023     CHECK(ret, FAIL, "H5Awrite");
2024 
2025     /* Read attribute information with the second attribute handle */
2026     ret = H5Aread(attr2, H5T_NATIVE_INT, read_data1);
2027     CHECK(ret, FAIL, "H5Aread");
2028 
2029     /* Verify values read in */
2030     for(i = 0; i < ATTR1_DIM1; i++)
2031         if(attr_data1[i] != read_data1[i])
2032             TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
2033 
2034     /* Close attribute */
2035     ret = H5Aclose(attr);
2036     CHECK(ret, FAIL, "H5Aclose");
2037 
2038     ret = H5Aclose(attr2);
2039     CHECK(ret, FAIL, "H5Aclose");
2040 
2041     /* Close group */
2042     ret = H5Gclose(gid1);
2043     CHECK(ret, FAIL, "H5Gclose");
2044 
2045     ret = H5Gclose(gid2);
2046     CHECK(ret, FAIL, "H5Gclose");
2047 
2048     /* Close Attribute dataspace */
2049     ret = H5Sclose(sid2);
2050     CHECK(ret, FAIL, "H5Sclose");
2051 
2052     /* Close Dataset dataspace */
2053     ret = H5Sclose(sid1);
2054     CHECK(ret, FAIL, "H5Sclose");
2055 
2056     /* Close file */
2057     ret = H5Fclose(fid1);
2058     CHECK(ret, FAIL, "H5Fclose");
2059 }   /* test_attr_duplicate_ids() */
2060 
2061 
2062 /****************************************************************
2063 **
2064 **  test_attr_dense_verify(): Test basic H5A (attribute) code.
2065 **      Verify attributes on object
2066 **
2067 ****************************************************************/
2068 static int
test_attr_dense_verify(hid_t loc_id,unsigned max_attr)2069 test_attr_dense_verify(hid_t loc_id, unsigned max_attr)
2070 {
2071     char        attrname[NAME_BUF_SIZE];        /* Name of attribute */
2072     hid_t       attr;           /* Attribute ID    */
2073     unsigned    value;          /* Attribute value */
2074     unsigned    u;              /* Local index variable */
2075     int         old_nerrs;      /* Number of errors when entering this check */
2076     herr_t      ret;            /* Generic return value    */
2077 
2078     /* Retrieve the current # of reported errors */
2079     old_nerrs = GetTestNumErrs();
2080 
2081     /* Re-open all the attributes by name and verify the data */
2082     for(u = 0; u < max_attr; u++) {
2083         /* Open attribute */
2084         HDsprintf(attrname, "attr %02u", u);
2085         attr = H5Aopen(loc_id, attrname, H5P_DEFAULT);
2086         CHECK(attr, FAIL, "H5Aopen");
2087 
2088         /* Read data from the attribute */
2089         ret = H5Aread(attr, H5T_NATIVE_UINT, &value);
2090         CHECK(ret, FAIL, "H5Aread");
2091         VERIFY(value, u, "H5Aread");
2092 
2093         /* Close attribute */
2094         ret = H5Aclose(attr);
2095         CHECK(ret, FAIL, "H5Aclose");
2096     } /* end for */
2097 
2098     /* Re-open all the attributes by index and verify the data */
2099     for(u = 0; u < max_attr; u++) {
2100         ssize_t name_len;               /* Length of attribute name */
2101         char check_name[ATTR_NAME_LEN]; /* Buffer for checking attribute names */
2102 
2103         /* Open attribute */
2104         attr = H5Aopen_by_idx(loc_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT);
2105         CHECK(attr, FAIL, "H5Aopen_by_idx");
2106 
2107         /* Verify Name */
2108         HDsprintf(attrname, "attr %02u", u);
2109         name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, check_name);
2110         VERIFY(name_len, HDstrlen(attrname), "H5Aget_name");
2111         if(HDstrcmp(check_name, attrname))
2112             TestErrPrintf("attribute name different: attrname = '%s', should be '%s'\n", check_name, attrname);
2113 
2114         /* Read data from the attribute */
2115         ret = H5Aread(attr, H5T_NATIVE_UINT, &value);
2116         CHECK(ret, FAIL, "H5Aread");
2117         VERIFY(value, u, "H5Aread");
2118 
2119         /* Close attribute */
2120         ret = H5Aclose(attr);
2121         CHECK(ret, FAIL, "H5Aclose");
2122     } /* end for */
2123 
2124     /* Retrieve current # of errors */
2125     if(old_nerrs == GetTestNumErrs())
2126         return(0);
2127     else
2128         return(-1);
2129 }   /* test_attr_dense_verify() */
2130 
2131 
2132 /****************************************************************
2133 **
2134 **  test_attr_dense_create(): Test basic H5A (attribute) code.
2135 **      Tests "dense" attribute storage creation
2136 **
2137 ****************************************************************/
2138 static void
test_attr_dense_create(hid_t fcpl,hid_t fapl)2139 test_attr_dense_create(hid_t fcpl, hid_t fapl)
2140 {
2141     hid_t    fid;             /* HDF5 File ID            */
2142     hid_t    dataset;         /* Dataset ID            */
2143     hid_t    sid;             /* Dataspace ID            */
2144     hid_t    attr;            /* Attribute ID            */
2145     hid_t    dcpl;            /* Dataset creation property list ID */
2146     char     attrname[NAME_BUF_SIZE];        /* Name of attribute */
2147     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
2148     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
2149     htri_t      is_dense;       /* Are attributes stored densely? */
2150     unsigned    u;              /* Local index variable */
2151     h5_stat_size_t empty_filesize;       /* Size of empty file */
2152     h5_stat_size_t filesize;             /* Size of file after modifications */
2153     herr_t      ret;        /* Generic return value        */
2154 
2155     /* Output message about test being performed */
2156     MESSAGE(5, ("Testing Dense Attribute Storage Creation\n"));
2157 
2158     /* Create file */
2159     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
2160     CHECK(fid, FAIL, "H5Fcreate");
2161 
2162     /* Close file */
2163     ret = H5Fclose(fid);
2164     CHECK(ret, FAIL, "H5Fclose");
2165 
2166     /* Get size of file */
2167     empty_filesize = h5_get_file_size(FILENAME, fapl);
2168     if(empty_filesize < 0)
2169         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
2170 
2171     /* Re-open file */
2172     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2173     CHECK(fid, FAIL, "H5Fopen");
2174 
2175     /* Create dataspace for dataset */
2176     sid = H5Screate(H5S_SCALAR);
2177     CHECK(sid, FAIL, "H5Screate");
2178 
2179     /* need DCPL to query the group creation properties */
2180     if (dcpl_g == H5P_DEFAULT) {
2181         dcpl = H5Pcreate(H5P_DATASET_CREATE);
2182         CHECK(dcpl, FAIL, "H5Pcreate");
2183     } else {
2184         dcpl = H5Pcopy(dcpl_g);
2185         CHECK(dcpl, FAIL, "H5Pcopy");
2186     }
2187 
2188     /* Create a dataset */
2189     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
2190     CHECK(dataset, FAIL, "H5Dcreate2");
2191 
2192     /* Retrieve limits for compact/dense attribute storage */
2193     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
2194     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
2195 
2196     /* Close property list */
2197     ret = H5Pclose(dcpl);
2198     CHECK(ret, FAIL, "H5Pclose");
2199 
2200     /* Check on dataset's attribute storage status */
2201     is_dense = H5O_is_attr_dense_test(dataset);
2202     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
2203 
2204     /* Add attributes, until just before converting to dense storage */
2205     for(u = 0; u < max_compact; u++) {
2206         /* Create attribute */
2207         HDsprintf(attrname, "attr %02u", u);
2208         attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
2209         CHECK(attr, FAIL, "H5Acreate2");
2210 
2211         /* Write data into the attribute */
2212         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
2213         CHECK(ret, FAIL, "H5Awrite");
2214 
2215         /* Close attribute */
2216         ret = H5Aclose(attr);
2217         CHECK(ret, FAIL, "H5Aclose");
2218     } /* end for */
2219 
2220     /* Check on dataset's attribute storage status */
2221     is_dense = H5O_is_attr_dense_test(dataset);
2222     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
2223 
2224     /* Add one more attribute, to push into "dense" storage */
2225     /* Create attribute */
2226     HDsprintf(attrname, "attr %02u", u);
2227     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
2228     CHECK(attr, FAIL, "H5Acreate2");
2229 
2230     /* Check on dataset's attribute storage status */
2231     is_dense = H5O_is_attr_dense_test(dataset);
2232     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
2233 
2234     /* Write data into the attribute */
2235     ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
2236     CHECK(ret, FAIL, "H5Awrite");
2237 
2238     /* Close attribute */
2239     ret = H5Aclose(attr);
2240     CHECK(ret, FAIL, "H5Aclose");
2241 
2242     /* Attempt to add attribute again, which should fail */
2243     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
2244     VERIFY(attr, FAIL, "H5Acreate2");
2245 
2246     /* Close dataspace */
2247     ret = H5Sclose(sid);
2248     CHECK(ret, FAIL, "H5Sclose");
2249 
2250     /* Close Dataset */
2251     ret = H5Dclose(dataset);
2252     CHECK(ret, FAIL, "H5Dclose");
2253 
2254     /* Unlink dataset with attributes */
2255     ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
2256     CHECK(ret, FAIL, "H5Ldelete");
2257 
2258     /* Close file */
2259     ret = H5Fclose(fid);
2260     CHECK(ret, FAIL, "H5Fclose");
2261 
2262     /* Check size of file */
2263     filesize = h5_get_file_size(FILENAME, fapl);
2264     VERIFY(filesize, empty_filesize, "h5_get_file_size");
2265 }   /* test_attr_dense_create() */
2266 
2267 
2268 /****************************************************************
2269 **
2270 **  test_attr_dense_open(): Test basic H5A (attribute) code.
2271 **      Tests opening attributes in "dense" storage
2272 **
2273 ****************************************************************/
2274 static void
test_attr_dense_open(hid_t fcpl,hid_t fapl)2275 test_attr_dense_open(hid_t fcpl, hid_t fapl)
2276 {
2277     hid_t    fid;             /* HDF5 File ID            */
2278     hid_t    dataset;         /* Dataset ID            */
2279     hid_t    sid;             /* Dataspace ID            */
2280     hid_t    attr;            /* Attribute ID            */
2281     hid_t    dcpl;            /* Dataset creation property list ID */
2282     char     attrname[NAME_BUF_SIZE];        /* Name of attribute */
2283     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
2284     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
2285     htri_t      is_dense;       /* Are attributes stored densely? */
2286     unsigned    u;              /* Local index variable */
2287     h5_stat_size_t empty_filesize;       /* Size of empty file */
2288     h5_stat_size_t filesize;             /* Size of file after modifications */
2289     herr_t      ret;            /* Generic return value        */
2290 
2291     /* Output message about test being performed */
2292     MESSAGE(5, ("Testing Opening Attributes in Dense Storage\n"));
2293 
2294     /* Create file */
2295     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
2296     CHECK(fid, FAIL, "H5Fcreate");
2297 
2298     /* Close file */
2299     ret = H5Fclose(fid);
2300     CHECK(ret, FAIL, "H5Fclose");
2301 
2302     /* Get size of file */
2303     empty_filesize = h5_get_file_size(FILENAME, fapl);
2304     if(empty_filesize < 0)
2305         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
2306 
2307     /* Re-open file */
2308     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2309     CHECK(fid, FAIL, "H5Fopen");
2310 
2311     /* Create dataspace for dataset */
2312     sid = H5Screate(H5S_SCALAR);
2313     CHECK(sid, FAIL, "H5Screate");
2314 
2315     /* need DCPL to query the group creation properties */
2316     if (dcpl_g == H5P_DEFAULT) {
2317         dcpl = H5Pcreate(H5P_DATASET_CREATE);
2318         CHECK(dcpl, FAIL, "H5Pcreate");
2319     } else {
2320         dcpl = H5Pcopy(dcpl_g);
2321         CHECK(dcpl, FAIL, "H5Pcopy");
2322     }
2323 
2324     /* Enable creation order tracking on attributes, so creation order tests work */
2325     ret = H5Pset_attr_creation_order(dcpl, H5P_CRT_ORDER_TRACKED);
2326     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
2327 
2328     /* Create a dataset */
2329     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
2330     CHECK(dataset, FAIL, "H5Dcreate2");
2331 
2332     /* Retrieve limits for compact/dense attribute storage */
2333     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
2334     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
2335 
2336     /* Close property list */
2337     ret = H5Pclose(dcpl);
2338     CHECK(ret, FAIL, "H5Pclose");
2339 
2340     /* Check on dataset's attribute storage status */
2341     is_dense = H5O_is_attr_dense_test(dataset);
2342     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
2343 
2344     /* Add attributes, until just before converting to dense storage */
2345     for(u = 0; u < max_compact; u++) {
2346         /* Create attribute */
2347         HDsprintf(attrname, "attr %02u", u);
2348         attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
2349         CHECK(attr, FAIL, "H5Acreate2");
2350 
2351         /* Write data into the attribute */
2352         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
2353         CHECK(ret, FAIL, "H5Awrite");
2354 
2355         /* Close attribute */
2356         ret = H5Aclose(attr);
2357         CHECK(ret, FAIL, "H5Aclose");
2358 
2359         /* Verify attributes written so far */
2360         ret = test_attr_dense_verify(dataset, u);
2361         CHECK(ret, FAIL, "test_attr_dense_verify");
2362     } /* end for */
2363 
2364     /* Check on dataset's attribute storage status */
2365     is_dense = H5O_is_attr_dense_test(dataset);
2366     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
2367 
2368     /* Add one more attribute, to push into "dense" storage */
2369     /* Create attribute */
2370     HDsprintf(attrname, "attr %02u", u);
2371     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
2372     CHECK(attr, FAIL, "H5Acreate2");
2373 
2374     /* Check on dataset's attribute storage status */
2375     is_dense = H5O_is_attr_dense_test(dataset);
2376     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
2377 
2378     /* Write data into the attribute */
2379     ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
2380     CHECK(ret, FAIL, "H5Awrite");
2381 
2382     /* Close attribute */
2383     ret = H5Aclose(attr);
2384     CHECK(ret, FAIL, "H5Aclose");
2385 
2386     /* Close dataspace */
2387     ret = H5Sclose(sid);
2388     CHECK(ret, FAIL, "H5Sclose");
2389 
2390     /* Verify all the attributes written */
2391     ret = test_attr_dense_verify(dataset, (u + 1));
2392     CHECK(ret, FAIL, "test_attr_dense_verify");
2393 
2394     /* Close Dataset */
2395     ret = H5Dclose(dataset);
2396     CHECK(ret, FAIL, "H5Dclose");
2397 
2398     /* Unlink dataset with attributes */
2399     ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
2400     CHECK(ret, FAIL, "H5Ldelete");
2401 
2402     /* Close file */
2403     ret = H5Fclose(fid);
2404     CHECK(ret, FAIL, "H5Fclose");
2405 
2406     /* Check size of file */
2407     filesize = h5_get_file_size(FILENAME, fapl);
2408     VERIFY(filesize, empty_filesize, "h5_get_file_size");
2409 }   /* test_attr_dense_open() */
2410 
2411 
2412 /****************************************************************
2413 **
2414 **  test_attr_dense_delete(): Test basic H5A (attribute) code.
2415 **      Tests deleting attributes in "dense" storage
2416 **
2417 ****************************************************************/
2418 static void
test_attr_dense_delete(hid_t fcpl,hid_t fapl)2419 test_attr_dense_delete(hid_t fcpl, hid_t fapl)
2420 {
2421     hid_t    fid;               /* HDF5 File ID            */
2422     hid_t    dataset;           /* Dataset ID            */
2423     hid_t    sid;               /* Dataspace ID            */
2424     hid_t    attr;              /* Attribute ID            */
2425     hid_t    dcpl;              /* Dataset creation property list ID */
2426     char     attrname[NAME_BUF_SIZE];        /* Name of attribute */
2427     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
2428     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
2429     htri_t      is_dense;       /* Are attributes stored densely? */
2430     unsigned    u;              /* Local index variable */
2431     h5_stat_size_t empty_filesize;       /* Size of empty file */
2432     h5_stat_size_t filesize;             /* Size of file after modifications */
2433     H5O_info_t  oinfo;          /* Object info                  */
2434     int         use_min_dset_oh = (dcpl_g != H5P_DEFAULT);
2435     herr_t      ret;            /* Generic return value        */
2436 
2437     /* Output message about test being performed */
2438     MESSAGE(5, ("Testing Deleting Attributes in Dense Storage\n"));
2439 
2440     if (use_min_dset_oh) { /* using minimized dataset headers */
2441         /* modify fcpl...
2442          * sidestep "bug" where file space is lost with minimized dset ohdrs
2443          */
2444         fcpl = H5Pcopy(fcpl);
2445         CHECK(fcpl, FAIL, "H5Pcopy");
2446         ret = H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_FSM_AGGR, TRUE, 1);
2447         CHECK(ret, FAIL, "H5Pset_file_space_strategy");
2448     }
2449     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
2450     CHECK(fid, FAIL, "H5Fcreate");
2451     if (use_min_dset_oh)
2452         CHECK(H5Pclose(fcpl), FAIL, "H5Pclose");
2453 
2454     /* Close file */
2455     ret = H5Fclose(fid);
2456     CHECK(ret, FAIL, "H5Fclose");
2457 
2458     /* Get size of file */
2459     empty_filesize = h5_get_file_size(FILENAME, fapl);
2460     if(empty_filesize < 0)
2461         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
2462 
2463     /* Re-open file */
2464     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2465     CHECK(fid, FAIL, "H5Fopen");
2466 
2467     /* Create dataspace for dataset */
2468     sid = H5Screate(H5S_SCALAR);
2469     CHECK(sid, FAIL, "H5Screate");
2470 
2471     /* need DCPL to query the group creation properties */
2472     if (use_min_dset_oh) {
2473         dcpl = H5Pcopy(dcpl_g);
2474         CHECK(dcpl, FAIL, "H5Pcopy");
2475     } else {
2476         dcpl = H5Pcreate(H5P_DATASET_CREATE);
2477         CHECK(dcpl, FAIL, "H5Pcreate");
2478     }
2479 
2480     /* Enable creation order tracking on attributes, so creation order tests work */
2481     ret = H5Pset_attr_creation_order(dcpl, H5P_CRT_ORDER_TRACKED);
2482     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
2483 
2484     /* Create a dataset */
2485     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
2486     CHECK(dataset, FAIL, "H5Dcreate2");
2487 
2488     /* Retrieve limits for compact/dense attribute storage */
2489     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
2490     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
2491 
2492     /* Close property list */
2493     ret = H5Pclose(dcpl);
2494     CHECK(ret, FAIL, "H5Pclose");
2495 
2496     /* Check on dataset's attribute storage status */
2497     is_dense = H5O_is_attr_dense_test(dataset);
2498     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
2499 
2500     /* Add attributes, until well into dense storage */
2501     for(u = 0; u < (max_compact * 2); u++) {
2502         /* Create attribute */
2503         HDsprintf(attrname, "attr %02u", u);
2504         attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
2505         CHECK(attr, FAIL, "H5Acreate2");
2506 
2507         /* Write data into the attribute */
2508         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
2509         CHECK(ret, FAIL, "H5Awrite");
2510 
2511         /* Close attribute */
2512         ret = H5Aclose(attr);
2513         CHECK(ret, FAIL, "H5Aclose");
2514 
2515         /* Check # of attributes */
2516         ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
2517         CHECK(ret, FAIL, "H5Oget_info");
2518         VERIFY(oinfo.num_attrs, (u + 1), "H5Oget_info");
2519     } /* end for */
2520 
2521     /* Check on dataset's attribute storage status */
2522     is_dense = H5O_is_attr_dense_test(dataset);
2523     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
2524 
2525     /* Close dataspace */
2526     ret = H5Sclose(sid);
2527     CHECK(ret, FAIL, "H5Sclose");
2528 
2529     /* Close Dataset */
2530     ret = H5Dclose(dataset);
2531     CHECK(ret, FAIL, "H5Dclose");
2532 
2533     /* Close file */
2534     ret = H5Fclose(fid);
2535     CHECK(ret, FAIL, "H5Fclose");
2536 
2537 
2538     /* Re-open file */
2539     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2540     CHECK(fid, FAIL, "H5Fopen");
2541 
2542     /* Open dataset */
2543     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
2544     CHECK(dataset, FAIL, "H5Dopen2");
2545 
2546     /* Delete attributes until the attributes revert to compact storage again */
2547     for(u--; u >= min_dense; u--) {
2548         /* Delete attribute */
2549         HDsprintf(attrname, "attr %02u", u);
2550         ret = H5Adelete(dataset, attrname);
2551         CHECK(ret, FAIL, "H5Adelete");
2552 
2553         /* Verify attributes still left */
2554         ret = test_attr_dense_verify(dataset, u);
2555         CHECK(ret, FAIL, "test_attr_dense_verify");
2556     } /* end for */
2557 
2558     /* Check on dataset's attribute storage status */
2559     is_dense = H5O_is_attr_dense_test(dataset);
2560     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
2561 
2562     /* Delete one more attribute, which should cause reversion to compact storage */
2563     HDsprintf(attrname, "attr %02u", u);
2564     ret = H5Adelete(dataset, attrname);
2565     CHECK(ret, FAIL, "H5Adelete");
2566 
2567     /* Check on dataset's attribute storage status */
2568     is_dense = H5O_is_attr_dense_test(dataset);
2569     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
2570 
2571     /* Verify attributes still left */
2572     ret = test_attr_dense_verify(dataset, (u - 1));
2573     CHECK(ret, FAIL, "test_attr_dense_verify");
2574 
2575     /* Delete another attribute, to verify deletion in compact storage */
2576     HDsprintf(attrname, "attr %02u", (u - 1));
2577     ret = H5Adelete(dataset, attrname);
2578     CHECK(ret, FAIL, "H5Adelete");
2579 
2580     /* Check on dataset's attribute storage status */
2581     is_dense = H5O_is_attr_dense_test(dataset);
2582     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
2583 
2584     /* Verify attributes still left */
2585     ret = test_attr_dense_verify(dataset, (u - 2));
2586     CHECK(ret, FAIL, "test_attr_dense_verify");
2587 
2588     /* Close Dataset */
2589     ret = H5Dclose(dataset);
2590     CHECK(ret, FAIL, "H5Dclose");
2591 
2592     /* Unlink dataset with attributes */
2593     ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
2594     CHECK(ret, FAIL, "H5Ldelete");
2595 
2596     /* Close file */
2597     ret = H5Fclose(fid);
2598     CHECK(ret, FAIL, "H5Fclose");
2599 
2600     /* Check size of file */
2601     filesize = h5_get_file_size(FILENAME, fapl);
2602     VERIFY(filesize, empty_filesize, "h5_get_file_size");
2603 }   /* test_attr_dense_delete() */
2604 
2605 
2606 /****************************************************************
2607 **
2608 **  test_attr_dense_rename(): Test basic H5A (attribute) code.
2609 **      Tests renaming attributes in "dense" storage
2610 **
2611 ****************************************************************/
2612 static void
test_attr_dense_rename(hid_t fcpl,hid_t fapl)2613 test_attr_dense_rename(hid_t fcpl, hid_t fapl)
2614 {
2615     hid_t    fid;               /* HDF5 File ID            */
2616     hid_t    dataset;           /* Dataset ID            */
2617     hid_t    sid;               /* Dataspace ID            */
2618     hid_t    attr;              /* Attribute ID            */
2619     hid_t    dcpl;              /* Dataset creation property list ID */
2620     char     attrname[NAME_BUF_SIZE];        /* Name of attribute */
2621     char     new_attrname[NAME_BUF_SIZE];    /* New name of attribute */
2622     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
2623     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
2624     htri_t    is_dense;         /* Are attributes stored densely? */
2625     h5_stat_size_t empty_filesize;       /* Size of empty file */
2626     h5_stat_size_t filesize;             /* Size of file after modifications */
2627     H5O_info_t  oinfo;          /* Object info */
2628     unsigned    u;              /* Local index variable */
2629     int         use_min_dset_oh = (dcpl_g != H5P_DEFAULT);
2630     unsigned    use_corder;     /* Track creation order or not */
2631     herr_t      ret;            /* Generic return value        */
2632 
2633     /* Output message about test being performed */
2634     MESSAGE(5, ("Testing Renaming Attributes in Dense Storage\n"));
2635 
2636     if (use_min_dset_oh) { /* using minimized dataset headers */
2637         /* modify fcpl...
2638          * sidestep "bug" where file space is lost with minimized dset ohdrs
2639          */
2640         fcpl = H5Pcopy(fcpl);
2641         CHECK(fcpl, FAIL, "H5Pcopy");
2642         ret = H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_FSM_AGGR, TRUE, 1);
2643         CHECK(ret, FAIL, "H5Pset_file_space_strategy");
2644     }
2645     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
2646     CHECK(fid, H5I_INVALID_HID, "H5Fcreate");
2647     if (use_min_dset_oh)
2648         CHECK(H5Pclose(fcpl), FAIL, "H5Pclose");
2649 
2650     /* Close file */
2651     ret = H5Fclose(fid);
2652     CHECK(ret, FAIL, "H5Fclose");
2653 
2654     /* Get size of file */
2655     empty_filesize = h5_get_file_size(FILENAME, fapl);
2656     if(empty_filesize < 0)
2657         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
2658 
2659     /* Re-open file */
2660     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2661     CHECK(fid, H5I_INVALID_HID, "H5Fopen");
2662 
2663     /* Create dataspace for dataset */
2664     sid = H5Screate(H5S_SCALAR);
2665     CHECK(sid, H5I_INVALID_HID, "H5Screate");
2666 
2667     /* need DCPL to query the group creation properties */
2668     if (use_min_dset_oh) {
2669         dcpl = H5Pcopy(dcpl_g);
2670         CHECK(dcpl, H5I_INVALID_HID, "H5Pcopy");
2671     } else {
2672         dcpl = H5Pcreate(H5P_DATASET_CREATE);
2673         CHECK(dcpl, H5I_INVALID_HID, "H5Pcreate");
2674     }
2675 
2676     /* Retrieve limits for compact/dense attribute storage */
2677     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
2678     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
2679 
2680     /* Using creation order or not */
2681     for(use_corder = FALSE; use_corder <= TRUE; use_corder++) {
2682 
2683         if(use_corder) {
2684             ret = H5Pset_attr_creation_order(dcpl, H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED);
2685             CHECK(ret, FAIL, "H5Pset_attr_creation_order");
2686         }
2687 
2688         /* Create a dataset */
2689         dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
2690         CHECK(dataset, H5I_INVALID_HID, "H5Dcreate2");
2691 
2692         /* Check on dataset's attribute storage status */
2693         is_dense = H5O_is_attr_dense_test(dataset);
2694         VERIFY(is_dense, FALSE, "H5O__is_attr_dense_test");
2695 
2696         /* Add attributes, until well into dense storage */
2697         for(u = 0; u < (max_compact * 2); u++) {
2698             /* Create attribute */
2699             HDsprintf(attrname, "attr %02u", u);
2700             attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
2701             CHECK(attr, H5I_INVALID_HID, "H5Acreate2");
2702 
2703             /* Write data into the attribute */
2704             ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
2705             CHECK(ret, FAIL, "H5Awrite");
2706 
2707             /* Close attribute */
2708             ret = H5Aclose(attr);
2709             CHECK(ret, FAIL, "H5Aclose");
2710 
2711             /* Rename attribute */
2712             HDsprintf(new_attrname, "new attr %02u", u);
2713 
2714             /* Rename attribute */
2715             ret = H5Arename_by_name(fid, DSET1_NAME, attrname, new_attrname, H5P_DEFAULT);
2716             CHECK(ret, FAIL, "H5Arename_by_name");
2717 
2718             /* Check # of attributes */
2719             ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
2720             CHECK(ret, FAIL, "H5Oget_info");
2721             VERIFY(oinfo.num_attrs, (u + 1), "H5Oget_info");
2722         } /* end for */
2723 
2724         /* Check on dataset's attribute storage status */
2725         is_dense = H5O_is_attr_dense_test(dataset);
2726         VERIFY(is_dense, TRUE, "H5O__is_attr_dense_test");
2727 
2728         /* Close Dataset */
2729         ret = H5Dclose(dataset);
2730         CHECK(ret, FAIL, "H5Dclose");
2731 
2732         if(!use_corder) {
2733             /* Unlink dataset with attributes */
2734             ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
2735             CHECK(ret, FAIL, "H5Ldelete");
2736         }
2737 
2738     }  /* end for use_corder */
2739 
2740     /* Close dataspace */
2741     ret = H5Sclose(sid);
2742     CHECK(ret, FAIL, "H5Sclose");
2743 
2744     /* Close property list */
2745     ret = H5Pclose(dcpl);
2746     CHECK(ret, FAIL, "H5Pclose");
2747 
2748     /* Close file */
2749     ret = H5Fclose(fid);
2750     CHECK(ret, FAIL, "H5Fclose");
2751 
2752 
2753     /* Re-open file */
2754     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2755     CHECK(fid, H5I_INVALID_HID, "H5Fopen");
2756 
2757     /* Open dataset */
2758     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
2759     CHECK(dataset, H5I_INVALID_HID, "H5Dopen2");
2760 
2761     /* Verify renamed attributes */
2762     for(u = 0; u < (max_compact * 2); u++) {
2763         unsigned    value;          /* Attribute value */
2764 
2765         /* Open attribute */
2766         HDsprintf(attrname, "new attr %02u", u);
2767         attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
2768         CHECK(attr, H5I_INVALID_HID, "H5Aopen");
2769 
2770         /* Read data from the attribute */
2771         ret = H5Aread(attr, H5T_NATIVE_UINT, &value);
2772         CHECK(ret, FAIL, "H5Aread");
2773         VERIFY(value, u, "H5Aread");
2774 
2775         /* Close attribute */
2776         ret = H5Aclose(attr);
2777         CHECK(ret, FAIL, "H5Aclose");
2778     } /* end for */
2779 
2780     /* Close Dataset */
2781     ret = H5Dclose(dataset);
2782     CHECK(ret, FAIL, "H5Dclose");
2783 
2784     /* Unlink dataset with attributes */
2785     ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
2786     CHECK(ret, FAIL, "H5Ldelete");
2787 
2788     /* Close file */
2789     ret = H5Fclose(fid);
2790     CHECK(ret, FAIL, "H5Fclose");
2791 
2792     /* Check size of file */
2793     filesize = h5_get_file_size(FILENAME, fapl);
2794     VERIFY(filesize, empty_filesize, "h5_get_file_size");
2795 }   /* test_attr_dense_rename() */
2796 
2797 
2798 /****************************************************************
2799 **
2800 **  test_attr_dense_unlink(): Test basic H5A (attribute) code.
2801 **      Tests unlinking object with attributes in "dense" storage
2802 **
2803 ****************************************************************/
2804 static void
test_attr_dense_unlink(hid_t fcpl,hid_t fapl)2805 test_attr_dense_unlink(hid_t fcpl, hid_t fapl)
2806 {
2807     hid_t    fid;             /* HDF5 File ID            */
2808     hid_t    dataset;         /* Dataset ID            */
2809     hid_t    sid;             /* Dataspace ID            */
2810     hid_t    attr;            /* Attribute ID            */
2811     hid_t    dcpl;            /* Dataset creation property list ID */
2812     char     attrname[NAME_BUF_SIZE];        /* Name of attribute */
2813     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
2814     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
2815     htri_t    is_dense;         /* Are attributes stored densely? */
2816     size_t      mesg_count;     /* # of shared messages */
2817     h5_stat_size_t empty_filesize;       /* Size of empty file */
2818     h5_stat_size_t filesize;             /* Size of file after modifications */
2819     H5O_info_t  oinfo;          /* Object info */
2820     unsigned    u;              /* Local index variable */
2821     int         use_min_dset_oh = (dcpl_g != H5P_DEFAULT);
2822     herr_t      ret;            /* Generic return value        */
2823 
2824     /* Output message about test being performed */
2825     MESSAGE(5, ("Testing Unlinking Object with Attributes in Dense Storage\n"));
2826 
2827     if (use_min_dset_oh) { /* using minimized dataset headers */
2828         /* modify fcpl...
2829          * sidestep "bug" where file space is lost with minimized dset ohdrs
2830          */
2831         fcpl = H5Pcopy(fcpl);
2832         CHECK(fcpl, FAIL, "H5Pcopy");
2833         ret = H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_FSM_AGGR, TRUE, 1);
2834         CHECK(ret, FAIL, "H5Pset_file_space_strategy");
2835     }
2836     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
2837     CHECK(fid, FAIL, "H5Fcreate");
2838     if (use_min_dset_oh)
2839         CHECK(H5Pclose(fcpl), FAIL, "H5Pclose");
2840 
2841     ret = H5Fclose(fid);
2842     CHECK(ret, FAIL, "H5Fclose");
2843 
2844     empty_filesize = h5_get_file_size(FILENAME, fapl);
2845     if(empty_filesize < 0)
2846         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
2847 
2848     /* Re-open file */
2849     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2850     CHECK(fid, FAIL, "H5Fopen");
2851 
2852     /* Create dataspace for dataset */
2853     sid = H5Screate(H5S_SCALAR);
2854     CHECK(sid, FAIL, "H5Screate");
2855 
2856     /* need DCPL to query the group creation properties */
2857     if (use_min_dset_oh) {
2858         dcpl = H5Pcopy(dcpl_g);
2859         CHECK(dcpl, FAIL, "H5Pcopy");
2860     } else {
2861         dcpl = H5Pcreate(H5P_DATASET_CREATE);
2862         CHECK(dcpl, FAIL, "H5Pcreate");
2863     }
2864 
2865     /* Create a dataset */
2866     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
2867     CHECK(dataset, FAIL, "H5Dcreate2");
2868 
2869     /* Retrieve limits for compact/dense attribute storage */
2870     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
2871     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
2872 
2873     /* Close property list */
2874     ret = H5Pclose(dcpl);
2875     CHECK(ret, FAIL, "H5Pclose");
2876 
2877     /* Check on dataset's attribute storage status */
2878     is_dense = H5O_is_attr_dense_test(dataset);
2879     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
2880 
2881     /* Add attributes, until well into dense storage */
2882     for(u = 0; u < (max_compact * 2); u++) {
2883         /* Create attribute */
2884         HDsprintf(attrname, "attr %02u", u);
2885         attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
2886         CHECK(attr, FAIL, "H5Acreate2");
2887 
2888         /* Write data into the attribute */
2889         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
2890         CHECK(ret, FAIL, "H5Awrite");
2891 
2892         /* Close attribute */
2893         ret = H5Aclose(attr);
2894         CHECK(ret, FAIL, "H5Aclose");
2895 
2896         /* Check # of attributes */
2897         ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
2898         CHECK(ret, FAIL, "H5Oget_info");
2899         VERIFY(oinfo.num_attrs, (u + 1), "H5Oget_info");
2900     } /* end for */
2901 
2902     /* Check on dataset's attribute storage status */
2903     is_dense = H5O_is_attr_dense_test(dataset);
2904     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
2905 
2906     /* Close dataspace */
2907     ret = H5Sclose(sid);
2908     CHECK(ret, FAIL, "H5Sclose");
2909 
2910     /* Close Dataset */
2911     ret = H5Dclose(dataset);
2912     CHECK(ret, FAIL, "H5Dclose");
2913 
2914     /* Close file */
2915     ret = H5Fclose(fid);
2916     CHECK(ret, FAIL, "H5Fclose");
2917 
2918 
2919     /* Re-open file */
2920     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2921     CHECK(fid, FAIL, "H5Fopen");
2922 
2923     /* Unlink dataset */
2924     ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
2925     CHECK(ret, FAIL, "H5Ldelete");
2926 
2927     /* Check on dataset's attribute storage status */
2928     ret = H5F_get_sohm_mesg_count_test(fid, H5O_ATTR_ID, &mesg_count);
2929     CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
2930     VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
2931 
2932     /* Close file */
2933     ret = H5Fclose(fid);
2934     CHECK(ret, FAIL, "H5Fclose");
2935 
2936     /* Check size of file */
2937     filesize = h5_get_file_size(FILENAME, fapl);
2938     VERIFY(filesize, empty_filesize, "h5_get_file_size");
2939 }   /* test_attr_dense_unlink() */
2940 
2941 
2942 /****************************************************************
2943 **
2944 **  test_attr_dense_limits(): Test basic H5A (attribute) code.
2945 **      Tests attribute in "dense" storage limits
2946 **
2947 ****************************************************************/
2948 static void
test_attr_dense_limits(hid_t fcpl,hid_t fapl)2949 test_attr_dense_limits(hid_t fcpl, hid_t fapl)
2950 {
2951     hid_t    fid;        /* HDF5 File ID            */
2952     hid_t    dataset;    /* Dataset ID            */
2953     hid_t    sid;             /* Dataspace ID            */
2954     hid_t    attr;            /* Attribute ID            */
2955     hid_t    dcpl;            /* Dataset creation property list ID */
2956     char     attrname[NAME_BUF_SIZE];        /* Name of attribute */
2957     unsigned    max_compact, rmax_compact;      /* Maximum # of attributes to store compactly */
2958     unsigned    min_dense, rmin_dense;          /* Minimum # of attributes to store "densely" */
2959     htri_t      is_dense;       /* Are attributes stored densely? */
2960     unsigned    u;              /* Local index variable */
2961     h5_stat_size_t empty_filesize;       /* Size of empty file */
2962     h5_stat_size_t filesize;             /* Size of file after modifications */
2963     herr_t      ret;            /* Generic return value        */
2964 
2965     /* Output message about test being performed */
2966     MESSAGE(5, ("Testing Phase Change Limits For Attributes in Dense Storage\n"));
2967 
2968     /* Create file */
2969     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
2970     CHECK(fid, FAIL, "H5Fcreate");
2971 
2972     /* Close file */
2973     ret = H5Fclose(fid);
2974     CHECK(ret, FAIL, "H5Fclose");
2975 
2976     /* Get size of file */
2977     empty_filesize = h5_get_file_size(FILENAME, fapl);
2978     if(empty_filesize < 0)
2979         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
2980 
2981     /* Re-open file */
2982     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
2983     CHECK(fid, FAIL, "H5Fopen");
2984 
2985     /* Create dataspace for dataset */
2986     sid = H5Screate(H5S_SCALAR);
2987     CHECK(sid, FAIL, "H5Screate");
2988 
2989     /* need DCPL to query the group creation properties */
2990     if (dcpl_g == H5P_DEFAULT) {
2991         dcpl = H5Pcreate(H5P_DATASET_CREATE);
2992         CHECK(dcpl, FAIL, "H5Pcreate");
2993     } else {
2994         dcpl = H5Pcopy(dcpl_g);
2995         CHECK(dcpl, FAIL, "H5Pcopy");
2996     }
2997 
2998     /* Change limits on compact/dense attribute storage */
2999     max_compact = 0;
3000     min_dense = 0;
3001     ret = H5Pset_attr_phase_change(dcpl, max_compact, min_dense);
3002     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
3003 
3004     /* Create a dataset */
3005     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
3006     CHECK(dataset, FAIL, "H5Dcreate2");
3007 
3008     /* Retrieve limits for compact/dense attribute storage */
3009     ret = H5Pget_attr_phase_change(dcpl, &rmax_compact, &rmin_dense);
3010     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
3011     VERIFY(rmax_compact, max_compact, "H5Pget_attr_phase_change");
3012     VERIFY(rmin_dense, min_dense, "H5Pget_attr_phase_change");
3013 
3014     /* Close property list */
3015     ret = H5Pclose(dcpl);
3016     CHECK(ret, FAIL, "H5Pclose");
3017 
3018 
3019     /* Check on dataset's attribute storage status */
3020     is_dense = H5O_is_attr_dense_test(dataset);
3021     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3022 
3023 
3024     /* Add first attribute, which should be immediately in dense storage */
3025 
3026     /* Create attribute */
3027     u = 0;
3028     HDsprintf(attrname, "attr %02u", u);
3029     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
3030     CHECK(attr, FAIL, "H5Acreate2");
3031 
3032     /* Write data into the attribute */
3033     ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
3034     CHECK(ret, FAIL, "H5Awrite");
3035 
3036     /* Close attribute */
3037     ret = H5Aclose(attr);
3038     CHECK(ret, FAIL, "H5Aclose");
3039 
3040     /* Check on dataset's attribute storage status */
3041     is_dense = H5O_is_attr_dense_test(dataset);
3042     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3043 
3044 
3045     /* Add second attribute, to allow deletions to be checked easily */
3046 
3047     /* Create attribute */
3048     u = 1;
3049     HDsprintf(attrname, "attr %02u", u);
3050     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
3051     CHECK(attr, FAIL, "H5Acreate2");
3052 
3053     /* Write data into the attribute */
3054     ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
3055     CHECK(ret, FAIL, "H5Awrite");
3056 
3057     /* Close attribute */
3058     ret = H5Aclose(attr);
3059     CHECK(ret, FAIL, "H5Aclose");
3060 
3061     /* Check on dataset's attribute storage status */
3062     is_dense = H5O_is_attr_dense_test(dataset);
3063     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3064 
3065 
3066     /* Delete second attribute, attributes should still be stored densely */
3067 
3068     /* Delete attribute */
3069     ret = H5Adelete(dataset, attrname);
3070     CHECK(ret, FAIL, "H5Adelete");
3071 
3072     /* Check on dataset's attribute storage status */
3073     is_dense = H5O_is_attr_dense_test(dataset);
3074     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3075 
3076 
3077     /* Delete first attribute, attributes should not be stored densely */
3078 
3079     /* Delete attribute */
3080     u = 0;
3081     HDsprintf(attrname, "attr %02u", u);
3082     ret = H5Adelete(dataset, attrname);
3083     CHECK(ret, FAIL, "H5Adelete");
3084 
3085     /* Check on dataset's attribute storage status */
3086     is_dense = H5O_is_attr_dense_test(dataset);
3087     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3088 
3089 
3090     /* Close dataspace */
3091     ret = H5Sclose(sid);
3092     CHECK(ret, FAIL, "H5Sclose");
3093 
3094     /* Close Dataset */
3095     ret = H5Dclose(dataset);
3096     CHECK(ret, FAIL, "H5Dclose");
3097 
3098     /* Unlink dataset */
3099     ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
3100     CHECK(ret, FAIL, "H5Ldelete");
3101 
3102     /* Close file */
3103     ret = H5Fclose(fid);
3104     CHECK(ret, FAIL, "H5Fclose");
3105 
3106     /* Check size of file */
3107     filesize = h5_get_file_size(FILENAME, fapl);
3108     VERIFY(filesize, empty_filesize, "h5_get_file_size");
3109 }   /* test_attr_dense_limits() */
3110 
3111 
3112 /****************************************************************
3113 **
3114 **  test_attr_dense_dup_ids(): Test operations with multiple ID
3115 **      handles with "dense" attribute storage creation
3116 **
3117 ****************************************************************/
3118 static void
test_attr_dense_dup_ids(hid_t fcpl,hid_t fapl)3119 test_attr_dense_dup_ids(hid_t fcpl, hid_t fapl)
3120 {
3121     hid_t    fid;           /* HDF5 File ID            */
3122     hid_t    dataset;       /* Dataset ID            */
3123     hid_t    gid1, gid2;    /* Group ID            */
3124     hid_t    sid, sid2;     /* Dataspace ID            */
3125     hid_t    attr, attr2, add_attr;    /* Attribute ID            */
3126     hid_t    dcpl;            /* Dataset creation property list ID */
3127     char     attrname[NAME_BUF_SIZE];        /* Name of attribute */
3128     hsize_t    dims[] = {ATTR1_DIM1};
3129     int         read_data1[ATTR1_DIM1]={0}; /* Buffer for reading attribute */
3130     int         rewrite_data[ATTR1_DIM1]={1234, -423, 9907256}; /* Test data for rewrite */
3131     unsigned    scalar_data = 1317; /* scalar data for attribute */
3132     unsigned    read_scalar;    /* variable for reading attribute*/
3133     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
3134     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
3135     htri_t      is_dense;       /* Are attributes stored densely? */
3136     unsigned    u, i;           /* Local index variable */
3137     herr_t      ret;            /* Generic return value        */
3138 
3139     /* Output message about test being performed */
3140     MESSAGE(5, ("Testing operations with two IDs for Dense Storage\n"));
3141 
3142     /*-----------------------------------------------------------------------------------
3143      *        Create an attribute in dense storage and fill it with fill value.
3144      */
3145     /* Create file */
3146     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
3147     CHECK(fid, FAIL, "H5Fcreate");
3148 
3149     /* Close file */
3150     ret = H5Fclose(fid);
3151     CHECK(ret, FAIL, "H5Fclose");
3152 
3153     /* Re-open file */
3154     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3155     CHECK(fid, FAIL, "H5Fopen");
3156 
3157     /* Create dataspace for dataset */
3158     sid = H5Screate(H5S_SCALAR);
3159     CHECK(sid, FAIL, "H5Screate");
3160 
3161     /* need DCPL to query the group creation properties */
3162     if (dcpl_g == H5P_DEFAULT) {
3163         dcpl = H5Pcreate(H5P_DATASET_CREATE);
3164         CHECK(dcpl, FAIL, "H5Pcreate");
3165     } else {
3166         dcpl = H5Pcopy(dcpl_g);
3167         CHECK(dcpl, FAIL, "H5Pcopy");
3168     }
3169 
3170     /* Create a dataset */
3171     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
3172     CHECK(dataset, FAIL, "H5Dcreate2");
3173 
3174     /* Retrieve limits for compact/dense attribute storage */
3175     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
3176     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
3177 
3178     /* Close property list */
3179     ret = H5Pclose(dcpl);
3180     CHECK(ret, FAIL, "H5Pclose");
3181 
3182     /* Check on dataset's attribute storage status */
3183     is_dense = H5O_is_attr_dense_test(dataset);
3184     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3185 
3186     /* Add attributes, until just before converting to dense storage */
3187     for(u = 0; u < max_compact; u++) {
3188         /* Create attribute */
3189         HDsprintf(attrname, "attr %02u", u);
3190         attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
3191         CHECK(attr, FAIL, "H5Acreate2");
3192 
3193         /* Write data into the attribute */
3194         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
3195         CHECK(ret, FAIL, "H5Awrite");
3196 
3197         /* Close attribute */
3198         ret = H5Aclose(attr);
3199         CHECK(ret, FAIL, "H5Aclose");
3200     } /* end for */
3201 
3202     /* Check on dataset's attribute storage status */
3203     is_dense = H5O_is_attr_dense_test(dataset);
3204     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3205 
3206     /* Add one more attribute, to push into "dense" storage */
3207     /* Create dataspace for attribute */
3208     sid2 = H5Screate_simple(ATTR1_RANK, dims, NULL);
3209     CHECK(sid2, FAIL, "H5Screate_simple");
3210 
3211     /* Create attribute */
3212     HDsprintf(attrname, "attr %02u", u);
3213     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
3214     CHECK(attr, FAIL, "H5Acreate2");
3215 
3216     /* Check on dataset's attribute storage status */
3217     is_dense = H5O_is_attr_dense_test(dataset);
3218     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3219 
3220     /* Open the attribute just created and get a second ID */
3221     attr2 = H5Aopen(dataset, attrname, H5P_DEFAULT);
3222     CHECK(attr2, FAIL, "H5Aopen");
3223 
3224     /* Close attribute */
3225     ret = H5Aclose(attr);
3226     CHECK(ret, FAIL, "H5Aclose");
3227 
3228     ret = H5Aclose(attr2);
3229     CHECK(ret, FAIL, "H5Aclose");
3230 
3231     /* Close Dataset */
3232     ret = H5Dclose(dataset);
3233     CHECK(ret, FAIL, "H5Dclose");
3234 
3235     /* Close file */
3236     ret = H5Fclose(fid);
3237     CHECK(ret, FAIL, "H5Fclose");
3238 
3239     /*-----------------------------------------------------------------------------------
3240      *        Reopen the file and verify the fill value for attribute.  Also write
3241      *        some real data.
3242      */
3243     /* Open file */
3244     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3245     CHECK(fid, FAIL, "H5Fopen");
3246 
3247     /* Open the dataset */
3248     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
3249     CHECK(dataset, FAIL, "H5Dopen2");
3250 
3251     /* Check on dataset's attribute storage status */
3252     is_dense = H5O_is_attr_dense_test(dataset);
3253     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3254 
3255     /* Open first attribute for the dataset */
3256     attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
3257     CHECK(attr, FAIL, "H5Aopen");
3258 
3259     /* Read attribute with fill value */
3260     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
3261     CHECK(ret, FAIL, "H5Aread");
3262 
3263     /* Verify values read in */
3264     for(i = 0; i < ATTR1_DIM1; i++)
3265         if(0 != read_data1[i])
3266             TestErrPrintf("%d: attribute data different: read_data1[%d]=%d\n", __LINE__,
3267                 i, read_data1[i]);
3268 
3269     /* Open attribute for the second time */
3270     attr2 = H5Aopen(dataset, attrname, H5P_DEFAULT);
3271     CHECK(attr, FAIL, "H5Aopen");
3272 
3273     /* Write attribute information */
3274     ret = H5Awrite(attr2, H5T_NATIVE_INT, attr_data1);
3275     CHECK(ret, FAIL, "H5Awrite");
3276 
3277     /* Close attribute */
3278     ret = H5Aclose(attr2);
3279     CHECK(ret, FAIL, "H5Aclose");
3280 
3281     /* Close attribute */
3282     ret = H5Aclose(attr);
3283     CHECK(ret, FAIL, "H5Aclose");
3284 
3285     /* Close Dataset */
3286     ret = H5Dclose(dataset);
3287     CHECK(ret, FAIL, "H5Dclose");
3288 
3289     /* Close file */
3290     ret = H5Fclose(fid);
3291     CHECK(ret, FAIL, "H5Fclose");
3292 
3293     /*-----------------------------------------------------------------------------------
3294      *        Reopen the file and verify the data.  Also rewrite the data and verify it.
3295      */
3296     /* Open file */
3297     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3298     CHECK(fid, FAIL, "H5Fopen");
3299 
3300     /* Open the dataset */
3301     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
3302     CHECK(dataset, FAIL, "H5Dopen2");
3303 
3304     /* Check on dataset's attribute storage status */
3305     is_dense = H5O_is_attr_dense_test(dataset);
3306     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3307 
3308     /* Open first attribute for the dataset */
3309     attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
3310     CHECK(attr, FAIL, "H5Aopen");
3311 
3312     /* Read attribute information */
3313     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
3314     CHECK(ret, FAIL, "H5Aread");
3315 
3316     /* Verify values read in */
3317     for(i = 0; i < ATTR1_DIM1; i++)
3318         if(attr_data1[i] != read_data1[i])
3319             TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
3320 
3321     /* Open attribute for the second time */
3322     attr2 = H5Aopen(dataset, attrname, H5P_DEFAULT);
3323     CHECK(attr, FAIL, "H5Aopen");
3324 
3325     /* Write attribute information with the second ID */
3326     ret = H5Awrite(attr2, H5T_NATIVE_INT, rewrite_data);
3327     CHECK(ret, FAIL, "H5Awrite");
3328 
3329     /* Read attribute information with the first ID */
3330     ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
3331     CHECK(ret, FAIL, "H5Aread");
3332 
3333     /* Verify values read in */
3334     for(i = 0; i < ATTR1_DIM1; i++)
3335         if(read_data1[i] != rewrite_data[i])
3336             TestErrPrintf("%d: attribute data different: read_data1[%d]=%d, rewrite_data[%d]=%d\n", __LINE__, i, read_data1[i], i, rewrite_data[i]);
3337 
3338     /* Close attribute */
3339     ret = H5Aclose(attr);
3340     CHECK(ret, FAIL, "H5Aclose");
3341 
3342     ret = H5Aclose(attr2);
3343     CHECK(ret, FAIL, "H5Aclose");
3344 
3345     /* Close Dataset */
3346     ret = H5Dclose(dataset);
3347     CHECK(ret, FAIL, "H5Dclose");
3348 
3349     /* Close file */
3350     ret = H5Fclose(fid);
3351     CHECK(ret, FAIL, "H5Fclose");
3352 
3353     /*-----------------------------------------------------------------------------------
3354      *        Open the attribute by index.  Verify the data is shared when the attribute
3355      *        is opened twice.
3356      */
3357     /* Open file */
3358     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3359     CHECK(fid, FAIL, "H5Fopen");
3360 
3361     /* Open the dataset */
3362     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
3363     CHECK(dataset, FAIL, "H5Dopen2");
3364 
3365     /* Check on dataset's attribute storage status */
3366     is_dense = H5O_is_attr_dense_test(dataset);
3367     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3368 
3369     /* Open first attribute for the dataset */
3370     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)4,
3371         H5P_DEFAULT, H5P_DEFAULT);
3372     CHECK(attr, FAIL, "H5Aopen");
3373 
3374     /* Open attribute for the second time */
3375     attr2 = H5Aopen_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)4,
3376         H5P_DEFAULT, H5P_DEFAULT);
3377     CHECK(attr, FAIL, "H5Aopen");
3378 
3379     /* Write attribute information with the second ID */
3380     ret = H5Awrite(attr2, H5T_NATIVE_UINT, &scalar_data);
3381     CHECK(ret, FAIL, "H5Awrite");
3382 
3383     /* Read attribute information with the first ID */
3384     ret = H5Aread(attr, H5T_NATIVE_INT, &read_scalar);
3385     CHECK(ret, FAIL, "H5Aread");
3386 
3387     /* Verify values read in */
3388     if(read_scalar != scalar_data)
3389         TestErrPrintf("%d: attribute data different: read_scalar=%d, scalar_data=%d\n",
3390             __LINE__, read_scalar, scalar_data);
3391 
3392     /* Close attribute */
3393     ret = H5Aclose(attr);
3394     CHECK(ret, FAIL, "H5Aclose");
3395 
3396     ret = H5Aclose(attr2);
3397     CHECK(ret, FAIL, "H5Aclose");
3398 
3399     /* Close Dataset */
3400     ret = H5Dclose(dataset);
3401     CHECK(ret, FAIL, "H5Dclose");
3402 
3403     /* Close file */
3404     ret = H5Fclose(fid);
3405     CHECK(ret, FAIL, "H5Fclose");
3406 
3407     /*-----------------------------------------------------------------------------------
3408      *        Open one attribute.  As it remains open, delete some attributes.  The
3409      *        attribute storage should switch from dense to compact.  Then open the
3410      *        same attribute for the second time and verify that the attribute data
3411      *        is shared.
3412      */
3413     /* Open file */
3414     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3415     CHECK(fid, FAIL, "H5Fopen");
3416 
3417     /* Open the dataset */
3418     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
3419     CHECK(dataset, FAIL, "H5Dopen2");
3420 
3421     /* Check on dataset's attribute storage status */
3422     is_dense = H5O_is_attr_dense_test(dataset);
3423     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3424 
3425     /* Open attribute of the dataset for the first time */
3426     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)2,
3427         H5P_DEFAULT, H5P_DEFAULT);
3428     CHECK(attr, FAIL, "H5Aopen");
3429 
3430     /* Delete a few attributes until the storage switches to compact */
3431     for(u = max_compact; u >= min_dense - 1; u--) {
3432         ret = H5Adelete_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)u,
3433             H5P_DEFAULT);
3434         CHECK(ret, FAIL, "H5Adelete_by_idx");
3435     }
3436 
3437     /* Check on dataset's attribute storage status */
3438     is_dense = H5O_is_attr_dense_test(dataset);
3439     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3440 
3441     /* Open attribute for the second time */
3442     attr2 = H5Aopen_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)2,
3443         H5P_DEFAULT, H5P_DEFAULT);
3444     CHECK(attr, FAIL, "H5Aopen");
3445 
3446     /* Write attribute information with the second ID */
3447     ret = H5Awrite(attr2, H5T_NATIVE_UINT, &scalar_data);
3448     CHECK(ret, FAIL, "H5Awrite");
3449 
3450     /* Read attribute information with the first ID */
3451     ret = H5Aread(attr, H5T_NATIVE_INT, &read_scalar);
3452     CHECK(ret, FAIL, "H5Aread");
3453 
3454     /* Verify values read in */
3455     if(read_scalar != scalar_data)
3456         TestErrPrintf("%d: attribute data different: read_scalar=%d, scalar_data=%d\n",
3457             __LINE__, read_scalar, scalar_data);
3458 
3459     /* Close attribute */
3460     ret = H5Aclose(attr);
3461     CHECK(ret, FAIL, "H5Aclose");
3462 
3463     ret = H5Aclose(attr2);
3464     CHECK(ret, FAIL, "H5Aclose");
3465 
3466     /* Close Dataset */
3467     ret = H5Dclose(dataset);
3468     CHECK(ret, FAIL, "H5Dclose");
3469 
3470     /* Close file */
3471     ret = H5Fclose(fid);
3472     CHECK(ret, FAIL, "H5Fclose");
3473 
3474     /*-----------------------------------------------------------------------------------
3475      *        Open one attribute.  As it remains open, create some attributes.  The
3476      *        attribute storage should switch from compact to dense.  Then open the
3477      *        same attribute for the second time and verify that the attribute data
3478      *        is shared.
3479      */
3480     /* Open file */
3481     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3482     CHECK(fid, FAIL, "H5Fopen");
3483 
3484     /* Open the dataset */
3485     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
3486     CHECK(dataset, FAIL, "H5Dopen2");
3487 
3488     /* Check on dataset's attribute storage status */
3489     is_dense = H5O_is_attr_dense_test(dataset);
3490     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3491 
3492     /* Open attribute of the dataset for the first time */
3493     attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)3,
3494         H5P_DEFAULT, H5P_DEFAULT);
3495     CHECK(attr, FAIL, "H5Aopen");
3496 
3497     /* Delete a few attributes until the storage switches to compact */
3498     for(u = min_dense-1; u <= max_compact; u++) {
3499         /* Create attribute */
3500         HDsprintf(attrname, "attr %02u", u);
3501         add_attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
3502         CHECK(add_attr, FAIL, "H5Acreate2");
3503 
3504         /* Write data into the attribute */
3505         ret = H5Awrite(add_attr, H5T_NATIVE_UINT, &u);
3506         CHECK(ret, FAIL, "H5Awrite");
3507 
3508         /* Close attribute */
3509         ret = H5Aclose(add_attr);
3510         CHECK(ret, FAIL, "H5Aclose");
3511     }
3512 
3513     /* Check on dataset's attribute storage status */
3514     is_dense = H5O_is_attr_dense_test(dataset);
3515     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3516 
3517     /* Open attribute for the second time */
3518     attr2 = H5Aopen_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)3,
3519         H5P_DEFAULT, H5P_DEFAULT);
3520     CHECK(attr, FAIL, "H5Aopen");
3521 
3522     /* Write attribute information with the second ID */
3523     ret = H5Awrite(attr2, H5T_NATIVE_UINT, &scalar_data);
3524     CHECK(ret, FAIL, "H5Awrite");
3525 
3526     /* Read attribute information with the first ID */
3527     ret = H5Aread(attr, H5T_NATIVE_INT, &read_scalar);
3528     CHECK(ret, FAIL, "H5Aread");
3529 
3530     /* Verify values read in */
3531     if(read_scalar != scalar_data)
3532         TestErrPrintf("%d: attribute data different: read_scalar=%d, scalar_data=%d\n",
3533             __LINE__, read_scalar, scalar_data);
3534 
3535     /* Close attribute */
3536     ret = H5Aclose(attr);
3537     CHECK(ret, FAIL, "H5Aclose");
3538 
3539     ret = H5Aclose(attr2);
3540     CHECK(ret, FAIL, "H5Aclose");
3541 
3542     /* Close Dataset */
3543     ret = H5Dclose(dataset);
3544     CHECK(ret, FAIL, "H5Dclose");
3545 
3546     /* Close file */
3547     ret = H5Fclose(fid);
3548     CHECK(ret, FAIL, "H5Fclose");
3549 
3550     /*-----------------------------------------------------------------------------------
3551      *        Verify that the attribute being pointed to by different paths shares
3552      *        the same data.
3553      */
3554     /* Open file */
3555     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3556     CHECK(fid, FAIL, "H5Fopen");
3557 
3558     /* Create a group */
3559     gid1 = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
3560     CHECK(gid1, FAIL, "H5Gcreate2");
3561 
3562     /* Create hard link to the first group */
3563     ret = H5Lcreate_hard(gid1, GROUP1_NAME, H5L_SAME_LOC, GROUP2_NAME, H5P_DEFAULT,
3564         H5P_DEFAULT);
3565     CHECK(ret, FAIL, "H5Lcreate_hard");
3566 
3567     /* Add attributes, until just before converting to dense storage */
3568     for(u = 0; u < max_compact; u++) {
3569         /* Create attribute */
3570         HDsprintf(attrname, "attr %02u", u);
3571         attr = H5Acreate2(gid1, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
3572         CHECK(attr, FAIL, "H5Acreate2");
3573 
3574         /* Write data into the attribute */
3575         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
3576         CHECK(ret, FAIL, "H5Awrite");
3577 
3578         /* Close attribute */
3579         ret = H5Aclose(attr);
3580         CHECK(ret, FAIL, "H5Aclose");
3581     } /* end for */
3582 
3583     /* Try to create another attribute to make dense storage */
3584     attr = H5Acreate2(gid1, ATTR2_NAME, H5T_NATIVE_INT, sid2, H5P_DEFAULT, H5P_DEFAULT);
3585     CHECK(attr, FAIL, "H5Acreate2");
3586 
3587     /* Check on group's attribute storage status */
3588     is_dense = H5O_is_attr_dense_test(gid1);
3589     VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
3590 
3591     /* Open the hard link just created */
3592     gid2 = H5Gopen2(fid, GROUP2_NAME, H5P_DEFAULT);
3593     CHECK(gid2, FAIL, "H5Gopen2");
3594 
3595     /* Open the attribute of the group for the second time */
3596     attr2 = H5Aopen(gid2, ATTR2_NAME, H5P_DEFAULT);
3597     CHECK(attr2, FAIL, "H5Aopen");
3598 
3599     /* Write attribute information with the first attribute handle */
3600     ret = H5Awrite(attr, H5T_NATIVE_INT, attr_data1);
3601     CHECK(ret, FAIL, "H5Awrite");
3602 
3603     /* Read attribute information with the second attribute handle */
3604     ret = H5Aread(attr2, H5T_NATIVE_INT, read_data1);
3605     CHECK(ret, FAIL, "H5Aread");
3606 
3607     /* Verify values read in */
3608     for(i = 0; i < ATTR1_DIM1; i++)
3609         if(attr_data1[i] != read_data1[i])
3610             TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
3611 
3612     /* Close attribute */
3613     ret = H5Aclose(attr);
3614     CHECK(ret, FAIL, "H5Aclose");
3615 
3616     ret = H5Aclose(attr2);
3617     CHECK(ret, FAIL, "H5Aclose");
3618 
3619     /* Close group */
3620     ret = H5Gclose(gid1);
3621     CHECK(ret, FAIL, "H5Gclose");
3622 
3623     ret = H5Gclose(gid2);
3624     CHECK(ret, FAIL, "H5Gclose");
3625 
3626     /* Close Attribute dataspace */
3627     ret = H5Sclose(sid);
3628     CHECK(ret, FAIL, "H5Sclose");
3629 
3630     /* Close Dataset dataspace */
3631     ret = H5Sclose(sid2);
3632     CHECK(ret, FAIL, "H5Sclose");
3633 
3634     /* Close file */
3635     ret = H5Fclose(fid);
3636     CHECK(ret, FAIL, "H5Fclose");
3637 }   /* test_attr_dense_dup_ids() */
3638 
3639 
3640 /****************************************************************
3641 **
3642 **  test_attr_big(): Test basic H5A (attribute) code.
3643 **      Tests storing "big" attribute in dense storage immediately, if available
3644 **
3645 ****************************************************************/
3646 static void
test_attr_big(hid_t fcpl,hid_t fapl)3647 test_attr_big(hid_t fcpl, hid_t fapl)
3648 {
3649     hid_t    fid;        /* HDF5 File ID            */
3650     hid_t    dataset;    /* Dataset ID            */
3651     hid_t    sid;            /* Dataspace ID            */
3652     hid_t    big_sid;    /* "Big" dataspace ID        */
3653     hsize_t     dims[ATTR6_RANK] = {ATTR6_DIM1, ATTR6_DIM2, ATTR6_DIM3};           /* Attribute dimensions */
3654     hid_t    attr;            /* Attribute ID            */
3655     hid_t    dcpl;            /* Dataset creation property list ID */
3656     char    attrname[NAME_BUF_SIZE];        /* Name of attribute */
3657     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
3658     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
3659     unsigned    nshared_indices;        /* # of shared message indices */
3660     H5F_libver_t low, high;     /* File format bounds */
3661     htri_t    is_empty;    /* Are there any attributes? */
3662     htri_t    is_dense;    /* Are attributes stored densely? */
3663     unsigned    u;              /* Local index variable */
3664     h5_stat_size_t empty_filesize;       /* Size of empty file */
3665     h5_stat_size_t filesize;             /* Size of file after modifications */
3666     herr_t    ret;        /* Generic return value        */
3667 
3668     /* Output message about test being performed */
3669     MESSAGE(5, ("Testing Storing 'Big' Attributes in Dense Storage\n"));
3670 
3671     /* Create file */
3672     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
3673     CHECK(fid, FAIL, "H5Fcreate");
3674 
3675     /* Close file */
3676     ret = H5Fclose(fid);
3677     CHECK(ret, FAIL, "H5Fclose");
3678 
3679     /* Get size of file */
3680     empty_filesize = h5_get_file_size(FILENAME, fapl);
3681     if(empty_filesize < 0)
3682         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
3683 
3684     /* Re-open file */
3685     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3686     CHECK(fid, FAIL, "H5Fopen");
3687 
3688     /* Create dataspace for dataset & "small" attributes */
3689     sid = H5Screate(H5S_SCALAR);
3690     CHECK(sid, FAIL, "H5Screate");
3691 
3692     /* Create "big" dataspace for "big" attributes */
3693     big_sid = H5Screate_simple(ATTR6_RANK, dims, NULL);
3694     CHECK(big_sid, FAIL, "H5Screate_simple");
3695 
3696     /* need DCPL to query the group creation properties */
3697     if (dcpl_g == H5P_DEFAULT) {
3698         dcpl = H5Pcreate(H5P_DATASET_CREATE);
3699         CHECK(dcpl, FAIL, "H5Pcreate");
3700     } else {
3701         dcpl = H5Pcopy(dcpl_g);
3702         CHECK(dcpl, FAIL, "H5Pcopy");
3703     }
3704 
3705     /* Retrieve limits for compact/dense attribute storage */
3706     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
3707     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
3708 
3709     /* Retrieve # of shared message indices (ie. whether attributes are shared or not) */
3710     ret = H5Pget_shared_mesg_nindexes(fcpl, &nshared_indices);
3711     CHECK(ret, FAIL, "H5Pget_shared_mesg_nindexes");
3712 
3713     /* Retrieve the format bounds for creating objects in the file */
3714     ret = H5Pget_libver_bounds(fapl, &low, &high);
3715     CHECK(ret, FAIL, "H5Pget_libver_bounds");
3716 
3717     /* Create a dataset */
3718     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
3719     CHECK(dataset, FAIL, "H5Dcreate2");
3720 
3721     /* Close property list */
3722     ret = H5Pclose(dcpl);
3723     CHECK(ret, FAIL, "H5Pclose");
3724 
3725 
3726     /* Check on dataset's attribute storage status */
3727     is_empty = H5O_is_attr_empty_test(dataset);
3728     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
3729     is_dense = H5O_is_attr_dense_test(dataset);
3730     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3731 
3732 
3733     /* Add first "small" attribute, which should be in compact storage */
3734 
3735     /* Create attribute */
3736     u = 0;
3737     HDsprintf(attrname, "attr %02u", u);
3738     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
3739     CHECK(attr, FAIL, "H5Acreate2");
3740 
3741     /* Close attribute */
3742     ret = H5Aclose(attr);
3743     CHECK(ret, FAIL, "H5Aclose");
3744 
3745     /* Check on dataset's attribute storage status */
3746     is_empty = H5O_is_attr_empty_test(dataset);
3747     VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
3748     is_dense = H5O_is_attr_dense_test(dataset);
3749     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3750 
3751 
3752     /* Add second "small" attribute, which should stay in compact storage */
3753 
3754     /* Create attribute */
3755     u = 1;
3756     HDsprintf(attrname, "attr %02u", u);
3757     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
3758     CHECK(attr, FAIL, "H5Acreate2");
3759 
3760     /* Close attribute */
3761     ret = H5Aclose(attr);
3762     CHECK(ret, FAIL, "H5Aclose");
3763 
3764     /* Check on dataset's attribute storage status */
3765     is_empty = H5O_is_attr_empty_test(dataset);
3766     VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
3767     is_dense = H5O_is_attr_dense_test(dataset);
3768     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3769 
3770 
3771     /* Add first "big" attribute, which should push storage into dense form */
3772 
3773     /* Create attribute */
3774     u = 2;
3775     HDsprintf(attrname, "attr %02u", u);
3776     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, big_sid, H5P_DEFAULT, H5P_DEFAULT);
3777     if(low == H5F_LIBVER_LATEST) {
3778         CHECK(attr, FAIL, "H5Acreate2");
3779 
3780         /* Close attribute */
3781         ret = H5Aclose(attr);
3782         CHECK(ret, FAIL, "H5Aclose");
3783 
3784         /* Check on dataset's attribute storage status */
3785         /* (when attributes are shared, the "big" attribute goes into the shared
3786          *  message heap instead of forcing the attribute storage into the dense
3787          *  form - QAK)
3788          */
3789         is_empty = H5O_is_attr_empty_test(dataset);
3790         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
3791         is_dense = H5O_is_attr_dense_test(dataset);
3792         VERIFY(is_dense, (nshared_indices ? FALSE : TRUE), "H5O_is_attr_dense_test");
3793 
3794 
3795         /* Add second "big" attribute, which should leave storage in dense form */
3796 
3797         /* Create attribute */
3798         u = 3;
3799         HDsprintf(attrname, "attr %02u", u);
3800         attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, big_sid, H5P_DEFAULT, H5P_DEFAULT);
3801         CHECK(attr, FAIL, "H5Acreate2");
3802 
3803         /* Close attribute */
3804         ret = H5Aclose(attr);
3805         CHECK(ret, FAIL, "H5Aclose");
3806 
3807         /* Check on dataset's attribute storage status */
3808         /* (when attributes are shared, the "big" attribute goes into the shared
3809          *  message heap instead of forcing the attribute storage into the dense
3810          *  form - QAK)
3811          */
3812         is_empty = H5O_is_attr_empty_test(dataset);
3813         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
3814         is_dense = H5O_is_attr_dense_test(dataset);
3815         VERIFY(is_dense, (nshared_indices ? FALSE : TRUE), "H5O_is_attr_dense_test");
3816 
3817 
3818         /* Delete second "small" attribute, attributes should still be stored densely */
3819 
3820         /* Delete attribute */
3821         u = 1;
3822         HDsprintf(attrname, "attr %02u", u);
3823         ret = H5Adelete(dataset, attrname);
3824         CHECK(ret, FAIL, "H5Adelete");
3825 
3826         /* Check on dataset's attribute storage status */
3827         is_empty = H5O_is_attr_empty_test(dataset);
3828         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
3829         is_dense = H5O_is_attr_dense_test(dataset);
3830         VERIFY(is_dense, (nshared_indices ? FALSE : TRUE), "H5O_is_attr_dense_test");
3831 
3832 
3833         /* Delete second "big" attribute, attributes should still be stored densely */
3834 
3835         /* Delete attribute */
3836         u = 3;
3837         HDsprintf(attrname, "attr %02u", u);
3838         ret = H5Adelete(dataset, attrname);
3839         CHECK(ret, FAIL, "H5Adelete");
3840 
3841         /* Check on dataset's attribute storage status */
3842         is_empty = H5O_is_attr_empty_test(dataset);
3843         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
3844         is_dense = H5O_is_attr_dense_test(dataset);
3845         VERIFY(is_dense, (nshared_indices ? FALSE : TRUE), "H5O_is_attr_dense_test");
3846 
3847 
3848         /* Delete first "big" attribute, attributes should _not_ be stored densely */
3849 
3850         /* Delete attribute */
3851         u = 2;
3852         HDsprintf(attrname, "attr %02u", u);
3853         ret = H5Adelete(dataset, attrname);
3854         CHECK(ret, FAIL, "H5Adelete");
3855 
3856         /* Check on dataset's attribute storage status */
3857         is_empty = H5O_is_attr_empty_test(dataset);
3858         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
3859         is_dense = H5O_is_attr_dense_test(dataset);
3860         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3861 
3862 
3863         /* Delete first "small" attribute, should be no attributes now */
3864 
3865         /* Delete attribute */
3866         u = 0;
3867         HDsprintf(attrname, "attr %02u", u);
3868         ret = H5Adelete(dataset, attrname);
3869         CHECK(ret, FAIL, "H5Adelete");
3870 
3871         /* Check on dataset's attribute storage status */
3872         is_empty = H5O_is_attr_empty_test(dataset);
3873         VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
3874     } /* end if */
3875     else {
3876         /* Shouldn't be able to create "big" attributes with older version of format */
3877         VERIFY(attr, FAIL, "H5Acreate2");
3878 
3879         /* Check on dataset's attribute storage status */
3880         /* (when attributes are shared, the "big" attribute goes into the shared
3881          *  message heap instead of forcing the attribute storage into the dense
3882          *  form - QAK)
3883          */
3884         is_empty = H5O_is_attr_empty_test(dataset);
3885         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
3886         is_dense = H5O_is_attr_dense_test(dataset);
3887         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
3888     } /* end else */
3889 
3890 
3891     /* Close dataspaces */
3892     ret = H5Sclose(sid);
3893     CHECK(ret, FAIL, "H5Sclose");
3894     ret = H5Sclose(big_sid);
3895     CHECK(ret, FAIL, "H5Sclose");
3896 
3897     /* Close Dataset */
3898     ret = H5Dclose(dataset);
3899     CHECK(ret, FAIL, "H5Dclose");
3900 
3901     /* Unlink dataset */
3902     ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
3903     CHECK(ret, FAIL, "H5Ldelete");
3904 
3905     /* Close file */
3906     ret = H5Fclose(fid);
3907     CHECK(ret, FAIL, "H5Fclose");
3908 
3909     /* Check size of file */
3910     filesize = h5_get_file_size(FILENAME, fapl);
3911     VERIFY(filesize, empty_filesize, "h5_get_file_size");
3912 }   /* test_attr_big() */
3913 
3914 
3915 /****************************************************************
3916 **
3917 **  test_attr_null_space(): Test basic H5A (attribute) code.
3918 **      Tests storing attribute with "null" dataspace
3919 **
3920 ****************************************************************/
3921 static void
test_attr_null_space(hid_t fcpl,hid_t fapl)3922 test_attr_null_space(hid_t fcpl, hid_t fapl)
3923 {
3924     hid_t    fid;        /* HDF5 File ID            */
3925     hid_t    dataset;    /* Dataset ID            */
3926     hid_t    sid;            /* Dataspace ID            */
3927     hid_t    null_sid;    /* "null" dataspace ID        */
3928     hid_t    attr_sid;    /* Attribute's dataspace ID    */
3929     hid_t    attr;            /* Attribute ID            */
3930     char    attrname[NAME_BUF_SIZE];        /* Name of attribute */
3931     unsigned    value;          /* Attribute value */
3932     htri_t      cmp;            /* Results of comparison */
3933     hsize_t     storage_size;   /* Size of storage for attribute */
3934     H5A_info_t  ainfo;          /* Attribute info */
3935     h5_stat_size_t empty_filesize;       /* Size of empty file */
3936     h5_stat_size_t filesize;             /* Size of file after modifications */
3937     herr_t    ret;        /* Generic return value        */
3938 
3939     /* Output message about test being performed */
3940     MESSAGE(5, ("Testing Storing Attributes with 'null' dataspace\n"));
3941 
3942     /* Create file */
3943     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
3944     CHECK(fid, FAIL, "H5Fcreate");
3945 
3946     /* Close file */
3947     ret = H5Fclose(fid);
3948     CHECK(ret, FAIL, "H5Fclose");
3949 
3950     /* Get size of file */
3951     empty_filesize = h5_get_file_size(FILENAME, fapl);
3952     if(empty_filesize < 0)
3953         TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
3954 
3955     /* Re-open file */
3956     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
3957     CHECK(fid, FAIL, "H5Fopen");
3958 
3959     /* Create dataspace for dataset attributes */
3960     sid = H5Screate(H5S_SCALAR);
3961     CHECK(sid, FAIL, "H5Screate");
3962 
3963     /* Create "null" dataspace for attribute */
3964     null_sid = H5Screate(H5S_NULL);
3965     CHECK(null_sid, FAIL, "H5Screate");
3966 
3967     /* Create a dataset */
3968     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
3969     CHECK(dataset, FAIL, "H5Dcreate2");
3970 
3971 
3972     /* Add attribute with 'null' dataspace */
3973 
3974     /* Create attribute */
3975     HDstrcpy(attrname, "null attr");
3976     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, null_sid, H5P_DEFAULT, H5P_DEFAULT);
3977     CHECK(attr, FAIL, "H5Acreate2");
3978 
3979     /* Try to read data from the attribute */
3980     /* (shouldn't fail, but should leave buffer alone) */
3981     value = 23;
3982     ret = H5Aread(attr, H5T_NATIVE_UINT, &value);
3983     CHECK(ret, FAIL, "H5Aread");
3984     VERIFY(value, 23, "H5Aread");
3985 
3986     /* Get the dataspace for the attribute and make certain it's 'null' */
3987     attr_sid = H5Aget_space(attr);
3988     CHECK(attr_sid, FAIL, "H5Aget_space");
3989 
3990     /* Compare the dataspaces */
3991     cmp = H5Sextent_equal(attr_sid, null_sid);
3992     CHECK(cmp, FAIL, "H5Sextent_equal");
3993     VERIFY(cmp, TRUE, "H5Sextent_equal");
3994 
3995     /* Close dataspace */
3996     ret = H5Sclose(attr_sid);
3997     CHECK(ret, FAIL, "H5Sclose");
3998 
3999     /* Check the storage size for the attribute */
4000     storage_size = H5Aget_storage_size(attr);
4001     VERIFY(storage_size, 0, "H5Aget_storage_size");
4002 
4003     /* Get the attribute info */
4004     ret = H5Aget_info(attr, &ainfo);
4005     CHECK(ret, FAIL, "H5Aget_info");
4006     VERIFY(ainfo.data_size, storage_size, "H5Aget_info");
4007 
4008     /* Close attribute */
4009     ret = H5Aclose(attr);
4010     CHECK(ret, FAIL, "H5Aclose");
4011 
4012 
4013     /* Add another attribute with 'null' dataspace */
4014 
4015     /* Create attribute */
4016     HDstrcpy(attrname, "null attr #2");
4017     attr = H5Acreate2(dataset, attrname, H5T_NATIVE_UINT, null_sid, H5P_DEFAULT, H5P_DEFAULT);
4018     CHECK(attr, FAIL, "H5Acreate2");
4019 
4020     /* Try to write data to the attribute */
4021     /* (shouldn't fail, but should leave buffer alone) */
4022     value = 23;
4023     ret = H5Awrite(attr, H5T_NATIVE_UINT, &value);
4024     CHECK(ret, FAIL, "H5Awrite");
4025     VERIFY(value, 23, "H5Awrite");
4026 
4027     /* Close attribute */
4028     ret = H5Aclose(attr);
4029     CHECK(ret, FAIL, "H5Aclose");
4030 
4031     /* Close Dataset */
4032     ret = H5Dclose(dataset);
4033     CHECK(ret, FAIL, "H5Dclose");
4034 
4035     /* Close file */
4036     ret = H5Fclose(fid);
4037     CHECK(ret, FAIL, "H5Fclose");
4038 
4039 
4040     /* Re-open the file and check on the attributes */
4041 
4042     /* Re-open file */
4043     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
4044     CHECK(fid, FAIL, "H5Fopen");
4045 
4046     /* Open dataset */
4047     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
4048     CHECK(dataset, FAIL, "H5Dopen2");
4049 
4050 
4051     /* Open first attribute */
4052     HDstrcpy(attrname, "null attr #2");
4053     attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
4054     CHECK(attr, FAIL, "H5Aopen");
4055 
4056     /* Try to read data from the attribute */
4057     /* (shouldn't fail, but should leave buffer alone) */
4058     value = 23;
4059     ret = H5Aread(attr, H5T_NATIVE_UINT, &value);
4060     CHECK(ret, FAIL, "H5Aread");
4061     VERIFY(value, 23, "H5Aread");
4062 
4063     /* Get the dataspace for the attribute and make certain it's 'null' */
4064     attr_sid = H5Aget_space(attr);
4065     CHECK(attr_sid, FAIL, "H5Aget_space");
4066 
4067     /* Compare the dataspaces */
4068     cmp = H5Sextent_equal(attr_sid, null_sid);
4069     CHECK(cmp, FAIL, "H5Sextent_equal");
4070     VERIFY(cmp, TRUE, "H5Sextent_equal");
4071 
4072     /* Close dataspace */
4073     ret = H5Sclose(attr_sid);
4074     CHECK(ret, FAIL, "H5Sclose");
4075 
4076     /* Check the storage size for the attribute */
4077     storage_size = H5Aget_storage_size(attr);
4078     VERIFY(storage_size, 0, "H5Aget_storage_size");
4079 
4080     /* Get the attribute info */
4081     ret = H5Aget_info(attr, &ainfo);
4082     CHECK(ret, FAIL, "H5Aget_info");
4083     VERIFY(ainfo.data_size, storage_size, "H5Aget_info");
4084 
4085     /* Close attribute */
4086     ret = H5Aclose(attr);
4087     CHECK(ret, FAIL, "H5Aclose");
4088 
4089 
4090     /* Open second attribute */
4091     HDstrcpy(attrname, "null attr");
4092     attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
4093     CHECK(attr, FAIL, "H5Aopen");
4094 
4095     /* Try to write data to the attribute */
4096     /* (shouldn't fail, but should leave buffer alone) */
4097     value = 23;
4098     ret = H5Awrite(attr, H5T_NATIVE_UINT, &value);
4099     CHECK(ret, FAIL, "H5Awrite");
4100     VERIFY(value, 23, "H5Awrite");
4101 
4102     /* Close attribute */
4103     ret = H5Aclose(attr);
4104     CHECK(ret, FAIL, "H5Aclose");
4105 
4106 
4107     /* Close Dataset */
4108     ret = H5Dclose(dataset);
4109     CHECK(ret, FAIL, "H5Dclose");
4110 
4111     /* Unlink dataset */
4112     ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
4113     CHECK(ret, FAIL, "H5Ldelete");
4114 
4115     /* Close file */
4116     ret = H5Fclose(fid);
4117     CHECK(ret, FAIL, "H5Fclose");
4118 
4119 
4120     /* Close dataspaces */
4121     ret = H5Sclose(sid);
4122     CHECK(ret, FAIL, "H5Sclose");
4123     ret = H5Sclose(null_sid);
4124     CHECK(ret, FAIL, "H5Sclose");
4125 
4126 
4127     /* Check size of file */
4128     filesize = h5_get_file_size(FILENAME, fapl);
4129     VERIFY(filesize, empty_filesize, "h5_get_file_size");
4130 }   /* test_attr_null_space() */
4131 
4132 
4133 /****************************************************************
4134 **
4135 **  test_attr_deprec(): Test basic H5A (attribute) code.
4136 **      Tests deprecated API routines
4137 **
4138 ****************************************************************/
4139 static void
test_attr_deprec(hid_t fcpl,hid_t fapl)4140 test_attr_deprec(hid_t fcpl, hid_t fapl)
4141 {
4142 #ifndef H5_NO_DEPRECATED_SYMBOLS
4143     hid_t    fid;        /* HDF5 File ID            */
4144     hid_t    dataset;    /* Dataset ID            */
4145     hid_t    sid;            /* Dataspace ID            */
4146     hid_t    attr;            /* Attribute ID            */
4147     herr_t    ret;        /* Generic return value        */
4148 
4149     /* Output message about test being performed */
4150     MESSAGE(5, ("Testing Deprecated Attribute Routines\n"));
4151 
4152     /* Create file */
4153     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
4154     CHECK(fid, FAIL, "H5Fcreate");
4155 
4156     /* Create dataspace for dataset attributes */
4157     sid = H5Screate(H5S_SCALAR);
4158     CHECK(sid, FAIL, "H5Screate");
4159 
4160     /* Create a dataset */
4161     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
4162     CHECK(dataset, FAIL, "H5Dcreate2");
4163 
4164 
4165     /* Add attribute to dataset */
4166 
4167     /* Create attribute */
4168     attr = H5Acreate1(dataset, "attr", H5T_NATIVE_UINT, sid, H5P_DEFAULT);
4169     CHECK(attr, FAIL, "H5Acreate1");
4170 
4171     /* Close attribute */
4172     ret = H5Aclose(attr);
4173     CHECK(ret, FAIL, "H5Aclose");
4174 
4175     /* Close dataspaces */
4176     ret = H5Sclose(sid);
4177 
4178     /* Close Dataset */
4179     ret = H5Dclose(dataset);
4180     CHECK(ret, FAIL, "H5Dclose");
4181 
4182     /* Close file */
4183     ret = H5Fclose(fid);
4184     CHECK(ret, FAIL, "H5Fclose");
4185 
4186 
4187     /* Re-open the file and operate on the attribute */
4188 
4189     /* Re-open file */
4190     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
4191     CHECK(fid, FAIL, "H5Fopen");
4192 
4193     /* Open dataset */
4194     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
4195     CHECK(dataset, FAIL, "H5Dopen2");
4196 
4197 
4198     /* Get number of attributes with bad ID */
4199     ret = H5Aget_num_attrs((hid_t)-1);
4200     VERIFY(ret, FAIL, "H5Aget_num_attrs");
4201 
4202     /* Get number of attributes */
4203     ret = H5Aget_num_attrs(dataset);
4204     VERIFY(ret, 1, "H5Aget_num_attrs");
4205 
4206     /* Open the attribute by index */
4207     attr = H5Aopen_idx(dataset, 0);
4208     CHECK(attr, FAIL, "H5Aopen_idx");
4209 
4210     /* Close attribute */
4211     ret = H5Aclose(attr);
4212     CHECK(ret, FAIL, "H5Aclose");
4213 
4214     /* Open the attribute by name */
4215     attr = H5Aopen_name(dataset, "attr");
4216     CHECK(attr, FAIL, "H5Aopen_name");
4217 
4218     /* Close attribute */
4219     ret = H5Aclose(attr);
4220     CHECK(ret, FAIL, "H5Aclose");
4221 
4222 
4223     /* Close Dataset */
4224     ret = H5Dclose(dataset);
4225     CHECK(ret, FAIL, "H5Dclose");
4226 
4227     /* Close file */
4228     ret = H5Fclose(fid);
4229     CHECK(ret, FAIL, "H5Fclose");
4230 #else /* H5_NO_DEPRECATED_SYMBOLS */
4231     /* Shut compiler up */
4232     fcpl = fcpl; fapl = fapl;
4233 
4234     /* Output message about test being skipped */
4235     MESSAGE(5, ("Skipping Test On Deprecated Attribute Routines\n"));
4236 
4237 #endif /* H5_NO_DEPRECATED_SYMBOLS */
4238 }   /* test_attr_deprec() */
4239 
4240 
4241 /****************************************************************
4242 **
4243 **  test_attr_many(): Test basic H5A (attribute) code.
4244 **      Tests storing lots of attributes
4245 **
4246 ****************************************************************/
4247 static void
test_attr_many(hbool_t new_format,hid_t fcpl,hid_t fapl)4248 test_attr_many(hbool_t new_format, hid_t fcpl, hid_t fapl)
4249 {
4250     hid_t    fid;        /* HDF5 File ID            */
4251     hid_t    gid;            /* Group ID            */
4252     hid_t    sid;            /* Dataspace ID            */
4253     hid_t    aid;            /* Attribute ID            */
4254     char    attrname[NAME_BUF_SIZE];        /* Name of attribute */
4255     unsigned    nattr = (new_format ? NATTR_MANY_NEW : NATTR_MANY_OLD); /* Number of attributes */
4256     htri_t      exists;         /* Whether the attribute exists or not */
4257     unsigned    u;              /* Local index variable */
4258     herr_t    ret;        /* Generic return value        */
4259 
4260     /* Output message about test being performed */
4261     MESSAGE(5, ("Testing Storing Many Attributes\n"));
4262 
4263     /* Create file */
4264     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
4265     CHECK(fid, FAIL, "H5Fcreate");
4266 
4267     /* Create dataspace for attribute */
4268     sid = H5Screate(H5S_SCALAR);
4269     CHECK(sid, FAIL, "H5Screate");
4270 
4271     /* Create group for attributes */
4272     gid = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
4273     CHECK(gid, FAIL, "H5Gcreate2");
4274 
4275     /* Create many attributes */
4276     for(u = 0; u < nattr; u++) {
4277         HDsprintf(attrname, "a-%06u", u);
4278 
4279         exists = H5Aexists(gid, attrname);
4280         VERIFY(exists, FALSE, "H5Aexists");
4281 
4282         exists = H5Aexists_by_name(fid, GROUP1_NAME, attrname, H5P_DEFAULT);
4283         VERIFY(exists, FALSE, "H5Aexists_by_name");
4284 
4285         aid = H5Acreate2(gid, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
4286         CHECK(aid, FAIL, "H5Acreate2");
4287 
4288         exists = H5Aexists(gid, attrname);
4289         VERIFY(exists, TRUE, "H5Aexists");
4290 
4291         exists = H5Aexists_by_name(fid, GROUP1_NAME, attrname, H5P_DEFAULT);
4292         VERIFY(exists, TRUE, "H5Aexists_by_name");
4293 
4294         ret = H5Awrite(aid, H5T_NATIVE_UINT, &u);
4295         CHECK(ret, FAIL, "H5Awrite");
4296 
4297         ret = H5Aclose(aid);
4298         CHECK(ret, FAIL, "H5Aclose");
4299 
4300         exists = H5Aexists(gid, attrname);
4301         VERIFY(exists, TRUE, "H5Aexists");
4302 
4303         exists = H5Aexists_by_name(fid, GROUP1_NAME, attrname, H5P_DEFAULT);
4304         VERIFY(exists, TRUE, "H5Aexists_by_name");
4305     } /* end for */
4306 
4307     /* Close group */
4308     ret = H5Gclose(gid);
4309     CHECK(ret, FAIL, "H5Gclose");
4310 
4311     /* Close file */
4312     ret = H5Fclose(fid);
4313     CHECK(ret, FAIL, "H5Fclose");
4314 
4315 
4316     /* Re-open the file and check on the attributes */
4317 
4318     /* Re-open file */
4319     fid = H5Fopen(FILENAME, H5F_ACC_RDONLY, fapl);
4320     CHECK(fid, FAIL, "H5Fopen");
4321 
4322     /* Re-open group */
4323     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
4324     CHECK(gid, FAIL, "H5Gopen2");
4325 
4326     /* Verify attributes */
4327     for(u = 0; u < nattr; u++) {
4328         unsigned    value;          /* Attribute value */
4329 
4330         HDsprintf(attrname, "a-%06u", u);
4331 
4332         exists = H5Aexists(gid, attrname);
4333         VERIFY(exists, TRUE, "H5Aexists");
4334 
4335         exists = H5Aexists_by_name(fid, GROUP1_NAME, attrname, H5P_DEFAULT);
4336         VERIFY(exists, TRUE, "H5Aexists_by_name");
4337 
4338         aid = H5Aopen(gid, attrname, H5P_DEFAULT);
4339         CHECK(aid, FAIL, "H5Aopen");
4340 
4341         exists = H5Aexists(gid, attrname);
4342         VERIFY(exists, TRUE, "H5Aexists");
4343 
4344         exists = H5Aexists_by_name(fid, GROUP1_NAME, attrname, H5P_DEFAULT);
4345         VERIFY(exists, TRUE, "H5Aexists_by_name");
4346 
4347         ret = H5Aread(aid, H5T_NATIVE_UINT, &value);
4348         CHECK(ret, FAIL, "H5Aread");
4349         VERIFY(value, u, "H5Aread");
4350 
4351         ret = H5Aclose(aid);
4352         CHECK(ret, FAIL, "H5Aclose");
4353     } /* end for */
4354 
4355     /* Close group */
4356     ret = H5Gclose(gid);
4357     CHECK(ret, FAIL, "H5Gclose");
4358 
4359     /* Close file */
4360     ret = H5Fclose(fid);
4361     CHECK(ret, FAIL, "H5Fclose");
4362 
4363 
4364     /* Close dataspaces */
4365     ret = H5Sclose(sid);
4366     CHECK(ret, FAIL, "H5Sclose");
4367 }   /* test_attr_many() */
4368 
4369 
4370 /****************************************************************
4371 **
4372 **  test_attr_corder_create_empty(): Test basic H5A (attribute) code.
4373 **      Tests basic code to create objects with attribute creation order info
4374 **
4375 ****************************************************************/
4376 static void
test_attr_corder_create_basic(hid_t fcpl,hid_t fapl)4377 test_attr_corder_create_basic(hid_t fcpl, hid_t fapl)
4378 {
4379     hid_t    fid;        /* HDF5 File ID            */
4380     hid_t    dataset;    /* Dataset ID            */
4381     hid_t    sid;            /* Dataspace ID            */
4382     hid_t    dcpl;            /* Dataset creation property list ID */
4383     unsigned    crt_order_flags;/* Creation order flags */
4384     htri_t    is_empty;    /* Are there any attributes? */
4385     htri_t    is_dense;    /* Are attributes stored densely? */
4386     herr_t    ret;        /* Generic return value        */
4387 
4388     /* Output message about test being performed */
4389     MESSAGE(5, ("Testing Basic Code for Attributes with Creation Order Info\n"));
4390 
4391     /* Create file */
4392     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
4393     CHECK(fid, FAIL, "H5Fcreate");
4394 
4395     /* Create dataset creation property list */
4396     if (dcpl_g == H5P_DEFAULT) {
4397         dcpl = H5Pcreate(H5P_DATASET_CREATE);
4398         CHECK(dcpl, FAIL, "H5Pcreate");
4399     } else {
4400         dcpl = H5Pcopy(dcpl_g);
4401         CHECK(dcpl, FAIL, "H5Pcopy");
4402     }
4403 
4404     /* Get creation order indexing on object */
4405     ret = H5Pget_attr_creation_order(dcpl, &crt_order_flags);
4406     CHECK(ret, FAIL, "H5Pget_attr_creation_order");
4407     VERIFY(crt_order_flags, 0, "H5Pget_attr_creation_order");
4408 
4409     /* Setting invalid combination of a attribute order creation order indexing on should fail */
4410     ret = H5Pset_attr_creation_order(dcpl, H5P_CRT_ORDER_INDEXED);
4411     VERIFY(ret, FAIL, "H5Pset_attr_creation_order");
4412     ret = H5Pget_attr_creation_order(dcpl, &crt_order_flags);
4413     CHECK(ret, FAIL, "H5Pget_attr_creation_order");
4414     VERIFY(crt_order_flags, 0, "H5Pget_attr_creation_order");
4415 
4416     /* Set attribute creation order tracking & indexing for object */
4417     ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED));
4418     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
4419     ret = H5Pget_attr_creation_order(dcpl, &crt_order_flags);
4420     CHECK(ret, FAIL, "H5Pget_attr_creation_order");
4421     VERIFY(crt_order_flags, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED) , "H5Pget_attr_creation_order");
4422 
4423     /* Create dataspace for dataset */
4424     sid = H5Screate(H5S_SCALAR);
4425     CHECK(sid, FAIL, "H5Screate");
4426 
4427     /* Create a dataset */
4428     dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
4429     CHECK(dataset, FAIL, "H5Dcreate2");
4430 
4431     /* Close dataspace */
4432     ret = H5Sclose(sid);
4433     CHECK(ret, FAIL, "H5Sclose");
4434 
4435     /* Check on dataset's attribute storage status */
4436     is_empty = H5O_is_attr_empty_test(dataset);
4437     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
4438     is_dense = H5O_is_attr_dense_test(dataset);
4439     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
4440 
4441     /* Close Dataset */
4442     ret = H5Dclose(dataset);
4443     CHECK(ret, FAIL, "H5Dclose");
4444 
4445     /* Close property list */
4446     ret = H5Pclose(dcpl);
4447     CHECK(ret, FAIL, "H5Pclose");
4448 
4449     /* Close file */
4450     ret = H5Fclose(fid);
4451     CHECK(ret, FAIL, "H5Fclose");
4452 
4453 
4454     /* Re-open file */
4455     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
4456     CHECK(fid, FAIL, "H5Fopen");
4457 
4458     /* Open dataset created */
4459     dataset = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
4460     CHECK(dataset, FAIL, "H5Dopen2");
4461 
4462     /* Check on dataset's attribute storage status */
4463     is_empty = H5O_is_attr_empty_test(dataset);
4464     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
4465     is_dense = H5O_is_attr_dense_test(dataset);
4466     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
4467 
4468     /* Retrieve dataset creation property list for group */
4469     dcpl = H5Dget_create_plist(dataset);
4470     CHECK(dcpl, FAIL, "H5Dget_create_plist");
4471 
4472     /* Query the attribute creation properties */
4473     ret = H5Pget_attr_creation_order(dcpl, &crt_order_flags);
4474     CHECK(ret, FAIL, "H5Pget_attr_creation_order");
4475     VERIFY(crt_order_flags, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED) , "H5Pget_attr_creation_order");
4476 
4477     /* Close property list */
4478     ret = H5Pclose(dcpl);
4479     CHECK(ret, FAIL, "H5Pclose");
4480 
4481     /* Close Dataset */
4482     ret = H5Dclose(dataset);
4483     CHECK(ret, FAIL, "H5Dclose");
4484 
4485     /* Close file */
4486     ret = H5Fclose(fid);
4487     CHECK(ret, FAIL, "H5Fclose");
4488 }   /* test_attr_corder_create_basic() */
4489 
4490 
4491 /****************************************************************
4492 **
4493 **  test_attr_corder_create_compact(): Test basic H5A (attribute) code.
4494 **      Tests compact attribute storage on objects with attribute creation order info
4495 **
4496 ****************************************************************/
4497 static void
test_attr_corder_create_compact(hid_t fcpl,hid_t fapl)4498 test_attr_corder_create_compact(hid_t fcpl, hid_t fapl)
4499 {
4500     hid_t    fid;        /* HDF5 File ID            */
4501     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
4502     hid_t    my_dataset;    /* Current dataset ID        */
4503     hid_t    sid;            /* Dataspace ID            */
4504     hid_t    attr;            /* Attribute ID            */
4505     hid_t    dcpl;            /* Dataset creation property list ID */
4506     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
4507     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
4508     htri_t    is_empty;    /* Are there any attributes? */
4509     htri_t    is_dense;    /* Are attributes stored densely? */
4510     hsize_t     nattrs;         /* Number of attributes on object */
4511     char    attrname[NAME_BUF_SIZE];        /* Name of attribute */
4512     unsigned    curr_dset;      /* Current dataset to work on */
4513     unsigned    u;              /* Local index variable */
4514     herr_t    ret;        /* Generic return value        */
4515 
4516     /* Output message about test being performed */
4517     MESSAGE(5, ("Testing Compact Storage of Attributes with Creation Order Info\n"));
4518 
4519     /* Create file */
4520     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
4521     CHECK(fid, FAIL, "H5Fcreate");
4522 
4523     /* Create dataset creation property list */
4524     if (dcpl_g == H5P_DEFAULT) {
4525         dcpl = H5Pcreate(H5P_DATASET_CREATE);
4526         CHECK(dcpl, FAIL, "H5Pcreate");
4527     } else {
4528         dcpl = H5Pcopy(dcpl_g);
4529         CHECK(dcpl, FAIL, "H5Pcopy");
4530     }
4531 
4532     /* Set attribute creation order tracking & indexing for object */
4533     ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED));
4534     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
4535 
4536     /* Query the attribute creation properties */
4537     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
4538     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
4539 
4540     /* Create dataspace for dataset & attributes */
4541     sid = H5Screate(H5S_SCALAR);
4542     CHECK(sid, FAIL, "H5Screate");
4543 
4544     /* Create datasets */
4545     dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
4546     CHECK(dset1, FAIL, "H5Dcreate2");
4547     dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
4548     CHECK(dset2, FAIL, "H5Dcreate2");
4549     dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
4550     CHECK(dset3, FAIL, "H5Dcreate2");
4551 
4552     /* Work on all the datasets */
4553     for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
4554         switch(curr_dset) {
4555             case 0:
4556                 my_dataset = dset1;
4557                 break;
4558 
4559             case 1:
4560                 my_dataset = dset2;
4561                 break;
4562 
4563             case 2:
4564                 my_dataset = dset3;
4565                 break;
4566 
4567             default:
4568                 HDassert(0 && "Too many datasets!");
4569         } /* end switch */
4570 
4571         /* Check on dataset's attribute storage status */
4572         is_empty = H5O_is_attr_empty_test(my_dataset);
4573         VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
4574         is_dense = H5O_is_attr_dense_test(my_dataset);
4575         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
4576 
4577         /* Create several attributes, but keep storage in compact form */
4578         for(u = 0; u < max_compact; u++) {
4579             /* Create attribute */
4580             HDsprintf(attrname, "attr %02u", u);
4581             attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
4582             CHECK(attr, FAIL, "H5Acreate2");
4583 
4584             /* Write data into the attribute */
4585             ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
4586             CHECK(ret, FAIL, "H5Awrite");
4587 
4588             /* Close attribute */
4589             ret = H5Aclose(attr);
4590             CHECK(ret, FAIL, "H5Aclose");
4591 
4592             /* Verify state of object */
4593             ret = H5O_num_attrs_test(my_dataset, &nattrs);
4594             CHECK(ret, FAIL, "H5O_num_attrs_test");
4595             VERIFY(nattrs, (u + 1), "H5O_num_attrs_test");
4596             is_empty = H5O_is_attr_empty_test(my_dataset);
4597             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
4598             is_dense = H5O_is_attr_dense_test(my_dataset);
4599             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
4600         } /* end for */
4601     } /* end for */
4602 
4603     /* Close Datasets */
4604     ret = H5Dclose(dset1);
4605     CHECK(ret, FAIL, "H5Dclose");
4606     ret = H5Dclose(dset2);
4607     CHECK(ret, FAIL, "H5Dclose");
4608     ret = H5Dclose(dset3);
4609     CHECK(ret, FAIL, "H5Dclose");
4610 
4611     /* Close dataspace */
4612     ret = H5Sclose(sid);
4613     CHECK(ret, FAIL, "H5Sclose");
4614 
4615     /* Close property list */
4616     ret = H5Pclose(dcpl);
4617     CHECK(ret, FAIL, "H5Pclose");
4618 
4619     /* Close file */
4620     ret = H5Fclose(fid);
4621     CHECK(ret, FAIL, "H5Fclose");
4622 
4623 
4624     /* Re-open file */
4625     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
4626     CHECK(fid, FAIL, "H5Fopen");
4627 
4628     /* Open datasets created */
4629     dset1 = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
4630     CHECK(dset1, FAIL, "H5Dopen2");
4631     dset2 = H5Dopen2(fid, DSET2_NAME, H5P_DEFAULT);
4632     CHECK(dset2, FAIL, "H5Dopen2");
4633     dset3 = H5Dopen2(fid, DSET3_NAME, H5P_DEFAULT);
4634     CHECK(dset3, FAIL, "H5Dopen2");
4635 
4636     /* Work on all the datasets */
4637     for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
4638         switch(curr_dset) {
4639             case 0:
4640                 my_dataset = dset1;
4641                 break;
4642 
4643             case 1:
4644                 my_dataset = dset2;
4645                 break;
4646 
4647             case 2:
4648                 my_dataset = dset3;
4649                 break;
4650 
4651             default:
4652                 HDassert(0 && "Too many datasets!");
4653         } /* end switch */
4654 
4655         /* Check on dataset's attribute storage status */
4656         ret = H5O_num_attrs_test(my_dataset, &nattrs);
4657         CHECK(ret, FAIL, "H5O_num_attrs_test");
4658         VERIFY(nattrs, max_compact, "H5O_num_attrs_test");
4659         is_empty = H5O_is_attr_empty_test(my_dataset);
4660         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
4661         is_dense = H5O_is_attr_dense_test(my_dataset);
4662         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
4663 
4664         /* Loop through attributes, checking their creation order values */
4665         /* (the name index is used, but the creation order value is in the same order) */
4666         for(u = 0; u < max_compact; u++) {
4667             H5A_info_t ainfo;           /* Attribute information */
4668 
4669             /* Retrieve information for attribute */
4670             HDsprintf(attrname, "attr %02u", u);
4671             ret = H5Aget_info_by_name(my_dataset, ".", attrname, &ainfo, H5P_DEFAULT);
4672             CHECK(ret, FAIL, "H5Aget_info_by_name");
4673 
4674             /* Verify creation order of attribute */
4675             VERIFY(ainfo.corder_valid, TRUE, "H5Aget_info_by_name");
4676             VERIFY(ainfo.corder, u, "H5Aget_info_by_name");
4677         } /* end for */
4678     } /* end for */
4679 
4680     /* Close Datasets */
4681     ret = H5Dclose(dset1);
4682     CHECK(ret, FAIL, "H5Dclose");
4683     ret = H5Dclose(dset2);
4684     CHECK(ret, FAIL, "H5Dclose");
4685     ret = H5Dclose(dset3);
4686     CHECK(ret, FAIL, "H5Dclose");
4687 
4688     /* Close file */
4689     ret = H5Fclose(fid);
4690     CHECK(ret, FAIL, "H5Fclose");
4691 }   /* test_attr_corder_create_compact() */
4692 
4693 
4694 /****************************************************************
4695 **
4696 **  test_attr_corder_create_dense(): Test basic H5A (attribute) code.
4697 **      Tests dense attribute storage on objects with attribute creation order info
4698 **
4699 ****************************************************************/
4700 static void
test_attr_corder_create_dense(hid_t fcpl,hid_t fapl)4701 test_attr_corder_create_dense(hid_t fcpl, hid_t fapl)
4702 {
4703     hid_t    fid;        /* HDF5 File ID            */
4704     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
4705     hid_t    my_dataset;    /* Current dataset ID        */
4706     hid_t    sid;            /* Dataspace ID            */
4707     hid_t    attr;            /* Attribute ID            */
4708     hid_t    dcpl;            /* Dataset creation property list ID */
4709     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
4710     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
4711     htri_t    is_empty;    /* Are there any attributes? */
4712     htri_t    is_dense;    /* Are attributes stored densely? */
4713     hsize_t     nattrs;         /* Number of attributes on object */
4714     hsize_t     name_count;     /* # of records in name index */
4715     hsize_t     corder_count;   /* # of records in creation order index */
4716     char    attrname[NAME_BUF_SIZE];        /* Name of attribute */
4717     unsigned    curr_dset;      /* Current dataset to work on */
4718     unsigned    u;              /* Local index variable */
4719     herr_t    ret;        /* Generic return value        */
4720 
4721     /* Output message about test being performed */
4722     MESSAGE(5, ("Testing Dense Storage of Attributes with Creation Order Info\n"));
4723 
4724     /* Create file */
4725     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
4726     CHECK(fid, FAIL, "H5Fcreate");
4727 
4728     /* Create dataset creation property list */
4729     if (dcpl_g == H5P_DEFAULT) {
4730         dcpl = H5Pcreate(H5P_DATASET_CREATE);
4731         CHECK(dcpl, FAIL, "H5Pcreate");
4732     } else {
4733         dcpl = H5Pcopy(dcpl_g);
4734         CHECK(dcpl, FAIL, "H5Pcopy");
4735     }
4736 
4737     /* Set attribute creation order tracking & indexing for object */
4738     ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED));
4739     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
4740 
4741     /* Query the attribute creation properties */
4742     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
4743     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
4744 
4745     /* Create dataspace for dataset & attributes */
4746     sid = H5Screate(H5S_SCALAR);
4747     CHECK(sid, FAIL, "H5Screate");
4748 
4749     /* Create datasets */
4750     dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
4751     CHECK(dset1, FAIL, "H5Dcreate2");
4752     dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
4753     CHECK(dset2, FAIL, "H5Dcreate2");
4754     dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
4755     CHECK(dset3, FAIL, "H5Dcreate2");
4756 
4757     /* Work on all the datasets */
4758     for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
4759         switch(curr_dset) {
4760             case 0:
4761                 my_dataset = dset1;
4762                 break;
4763 
4764             case 1:
4765                 my_dataset = dset2;
4766                 break;
4767 
4768             case 2:
4769                 my_dataset = dset3;
4770                 break;
4771 
4772             default:
4773                 HDassert(0 && "Too many datasets!");
4774         } /* end switch */
4775 
4776         /* Check on dataset's attribute storage status */
4777         is_empty = H5O_is_attr_empty_test(my_dataset);
4778         VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
4779         is_dense = H5O_is_attr_dense_test(my_dataset);
4780         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
4781 
4782         /* Create several attributes, but keep storage in compact form */
4783         for(u = 0; u < max_compact; u++) {
4784             /* Create attribute */
4785             HDsprintf(attrname, "attr %02u", u);
4786             attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
4787             CHECK(attr, FAIL, "H5Acreate2");
4788 
4789             /* Write data into the attribute */
4790             ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
4791             CHECK(ret, FAIL, "H5Awrite");
4792 
4793             /* Close attribute */
4794             ret = H5Aclose(attr);
4795             CHECK(ret, FAIL, "H5Aclose");
4796 
4797             /* Verify state of object */
4798             ret = H5O_num_attrs_test(my_dataset, &nattrs);
4799             CHECK(ret, FAIL, "H5O_num_attrs_test");
4800             VERIFY(nattrs, (u + 1), "H5O_num_attrs_test");
4801             is_empty = H5O_is_attr_empty_test(my_dataset);
4802             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
4803             is_dense = H5O_is_attr_dense_test(my_dataset);
4804             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
4805         } /* end for */
4806 
4807         /* Create another attribute, to push into dense storage */
4808         HDsprintf(attrname, "attr %02u", max_compact);
4809         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
4810         CHECK(attr, FAIL, "H5Acreate2");
4811 
4812         /* Write data into the attribute */
4813         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
4814         CHECK(ret, FAIL, "H5Awrite");
4815 
4816         /* Close attribute */
4817         ret = H5Aclose(attr);
4818         CHECK(ret, FAIL, "H5Aclose");
4819 
4820         /* Verify state of object */
4821         ret = H5O_num_attrs_test(my_dataset, &nattrs);
4822         CHECK(ret, FAIL, "H5O_num_attrs_test");
4823         VERIFY(nattrs, (max_compact + 1), "H5O_num_attrs_test");
4824         is_empty = H5O_is_attr_empty_test(my_dataset);
4825         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
4826         is_dense = H5O_is_attr_dense_test(my_dataset);
4827         VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
4828 
4829         /* Retrieve & verify # of records in the name & creation order indices */
4830         ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
4831         CHECK(ret, FAIL, "H5O_attr_dense_info_test");
4832         VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
4833     } /* end for */
4834 
4835     /* Close Datasets */
4836     ret = H5Dclose(dset1);
4837     CHECK(ret, FAIL, "H5Dclose");
4838     ret = H5Dclose(dset2);
4839     CHECK(ret, FAIL, "H5Dclose");
4840     ret = H5Dclose(dset3);
4841     CHECK(ret, FAIL, "H5Dclose");
4842 
4843     /* Close dataspace */
4844     ret = H5Sclose(sid);
4845     CHECK(ret, FAIL, "H5Sclose");
4846 
4847     /* Close property list */
4848     ret = H5Pclose(dcpl);
4849     CHECK(ret, FAIL, "H5Pclose");
4850 
4851     /* Close file */
4852     ret = H5Fclose(fid);
4853     CHECK(ret, FAIL, "H5Fclose");
4854 
4855 
4856     /* Re-open file */
4857     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
4858     CHECK(fid, FAIL, "H5Fopen");
4859 
4860     /* Open datasets created */
4861     dset1 = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
4862     CHECK(dset1, FAIL, "H5Dopen2");
4863     dset2 = H5Dopen2(fid, DSET2_NAME, H5P_DEFAULT);
4864     CHECK(dset2, FAIL, "H5Dopen2");
4865     dset3 = H5Dopen2(fid, DSET3_NAME, H5P_DEFAULT);
4866     CHECK(dset3, FAIL, "H5Dopen2");
4867 
4868     /* Work on all the datasets */
4869     for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
4870         switch(curr_dset) {
4871             case 0:
4872                 my_dataset = dset1;
4873                 break;
4874 
4875             case 1:
4876                 my_dataset = dset2;
4877                 break;
4878 
4879             case 2:
4880                 my_dataset = dset3;
4881                 break;
4882 
4883             default:
4884                 HDassert(0 && "Too many datasets!");
4885         } /* end switch */
4886 
4887         /* Check on dataset's attribute storage status */
4888         ret = H5O_num_attrs_test(my_dataset, &nattrs);
4889         CHECK(ret, FAIL, "H5O_num_attrs_test");
4890         VERIFY(nattrs, (max_compact + 1), "H5O_num_attrs_test");
4891         is_empty = H5O_is_attr_empty_test(my_dataset);
4892         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
4893         is_dense = H5O_is_attr_dense_test(my_dataset);
4894         VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
4895 
4896         /* Loop through attributes, checking their creation order values */
4897         /* (the name index is used, but the creation order value is in the same order) */
4898         for(u = 0; u < (max_compact + 1); u++) {
4899             H5A_info_t ainfo;           /* Attribute information */
4900 
4901             /* Retrieve information for attribute */
4902             HDsprintf(attrname, "attr %02u", u);
4903             ret = H5Aget_info_by_name(my_dataset, ".", attrname, &ainfo, H5P_DEFAULT);
4904             CHECK(ret, FAIL, "H5Aget_info_by_name");
4905 
4906             /* Verify creation order of attribute */
4907             VERIFY(ainfo.corder_valid, TRUE, "H5Aget_info_by_name");
4908             VERIFY(ainfo.corder, u, "H5Aget_info_by_name");
4909         } /* end for */
4910     } /* end for */
4911 
4912     /* Close Datasets */
4913     ret = H5Dclose(dset1);
4914     CHECK(ret, FAIL, "H5Dclose");
4915     ret = H5Dclose(dset2);
4916     CHECK(ret, FAIL, "H5Dclose");
4917     ret = H5Dclose(dset3);
4918     CHECK(ret, FAIL, "H5Dclose");
4919 
4920     /* Close file */
4921     ret = H5Fclose(fid);
4922     CHECK(ret, FAIL, "H5Fclose");
4923 }   /* test_attr_corder_create_dense() */
4924 
4925 
4926 /****************************************************************
4927 **
4928 **  test_attr_corder_create_reopen(): Test basic H5A (attribute) code.
4929 **      Test creating attributes w/reopening file from using new format
4930 **      to using old format
4931 **
4932 ****************************************************************/
4933 static void
test_attr_corder_create_reopen(hid_t fcpl,hid_t fapl)4934 test_attr_corder_create_reopen(hid_t fcpl, hid_t fapl)
4935 {
4936     hid_t fid = -1;             /* File ID */
4937     hid_t gcpl_id = -1;         /* Group creation property list ID */
4938     hid_t gid = -1;             /* Group ID */
4939     hid_t sid = -1;             /* Dataspace ID */
4940     hid_t aid = -1;             /* Attribute ID */
4941     int buf;                    /* Attribute data */
4942     herr_t    ret;        /* Generic return value    */
4943 
4944     /* Output message about test being performed */
4945     MESSAGE(5, ("Testing Creating Attributes w/New & Old Format\n"));
4946 
4947     /* Create dataspace for attributes */
4948     sid = H5Screate(H5S_SCALAR);
4949     CHECK(sid, FAIL, "H5Screate");
4950 
4951     /* Create file */
4952     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
4953     CHECK(fid, FAIL, "H5Fcreate");
4954 
4955     /* Create group */
4956     gcpl_id = H5Pcreate(H5P_GROUP_CREATE);
4957     CHECK(gcpl_id, FAIL, "H5Pcreate");
4958     ret = H5Pset_attr_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED);
4959     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
4960     gid = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT);
4961     CHECK(gid, FAIL, "H5Gcreate2");
4962 
4963     /* Create a couple of attributes */
4964     aid = H5Acreate2(gid, "attr-003", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT);
4965     CHECK(aid, FAIL, "H5Acreate2");
4966     buf = 3;
4967     ret = H5Awrite(aid, H5T_NATIVE_INT, &buf);
4968     CHECK(ret, FAIL, "H5Awrite");
4969     ret = H5Aclose(aid);
4970     CHECK(ret, FAIL, "H5Aclose");
4971 
4972     aid = H5Acreate2(gid, "attr-004", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT);
4973     CHECK(aid, FAIL, "H5Acreate2");
4974     buf = 4;
4975     ret = H5Awrite(aid, H5T_NATIVE_INT, &buf);
4976     CHECK(ret, FAIL, "H5Awrite");
4977     ret = H5Aclose(aid);
4978     CHECK(ret, FAIL, "H5Aclose");
4979 
4980     /***** Close group & GCPL *****/
4981     ret = H5Gclose(gid);
4982     CHECK(ret, FAIL, "H5Gclose");
4983     ret = H5Pclose(gcpl_id);
4984     CHECK(ret, FAIL, "H5Pclose");
4985 
4986     /* Close file */
4987     ret = H5Fclose(fid);
4988     CHECK(ret, FAIL, "H5Fclose");
4989 
4990 
4991     /* Re-open file, without "use the latest format" flag */
4992     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
4993     CHECK(fid, FAIL, "H5Fopen");
4994 
4995     /* Re-open group */
4996     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
4997     CHECK(gid, FAIL, "H5Gopen2");
4998 
4999     /* Delete attribute */
5000     ret = H5Adelete(gid, "attr-003");
5001     CHECK(aid, FAIL, "H5Adelete");
5002 
5003     /* Create some additional attributes */
5004     aid = H5Acreate2(gid, "attr-008", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT);
5005     CHECK(aid, FAIL, "H5Acreate2");
5006     buf = 8;
5007     ret = H5Awrite(aid, H5T_NATIVE_INT, &buf);
5008     CHECK(ret, FAIL, "H5Awrite");
5009     ret = H5Aclose(aid);
5010     CHECK(ret, FAIL, "H5Aclose");
5011 
5012     aid = H5Acreate2(gid, "attr-006", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT);
5013     CHECK(aid, FAIL, "H5Acreate2");
5014     buf = 6;
5015     ret = H5Awrite(aid, H5T_NATIVE_INT, &buf);
5016     CHECK(ret, FAIL, "H5Awrite");
5017     ret = H5Aclose(aid);
5018     CHECK(ret, FAIL, "H5Aclose");
5019 
5020     /***** Close group *****/
5021     ret = H5Gclose(gid);
5022     CHECK(ret, FAIL, "H5Gclose");
5023 
5024     /* Close file */
5025     ret = H5Fclose(fid);
5026     CHECK(ret, FAIL, "H5Fclose");
5027 
5028     /* Close attribute dataspace */
5029     ret = H5Sclose(sid);
5030     CHECK(ret, FAIL, "H5Sclose");
5031 }   /* test_attr_corder_create_reopen() */
5032 
5033 
5034 /****************************************************************
5035 **
5036 **  test_attr_corder_transition(): Test basic H5A (attribute) code.
5037 **      Tests attribute storage transitions on objects with attribute creation order info
5038 **
5039 ****************************************************************/
5040 static void
test_attr_corder_transition(hid_t fcpl,hid_t fapl)5041 test_attr_corder_transition(hid_t fcpl, hid_t fapl)
5042 {
5043     hid_t    fid;        /* HDF5 File ID            */
5044     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
5045     hid_t    my_dataset;    /* Current dataset ID        */
5046     hid_t    sid;            /* Dataspace ID            */
5047     hid_t    attr;            /* Attribute ID            */
5048     hid_t    dcpl;            /* Dataset creation property list ID */
5049     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
5050     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
5051     htri_t    is_empty;    /* Are there any attributes? */
5052     htri_t    is_dense;    /* Are attributes stored densely? */
5053     hsize_t     nattrs;         /* Number of attributes on object */
5054     hsize_t     name_count;     /* # of records in name index */
5055     hsize_t     corder_count;   /* # of records in creation order index */
5056     char    attrname[NAME_BUF_SIZE];        /* Name of attribute */
5057     unsigned    curr_dset;      /* Current dataset to work on */
5058     unsigned    u;              /* Local index variable */
5059     herr_t    ret;        /* Generic return value        */
5060 
5061     /* Output message about test being performed */
5062     MESSAGE(5, ("Testing Storage Transitions of Attributes with Creation Order Info\n"));
5063 
5064     /* Create file */
5065     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
5066     CHECK(fid, FAIL, "H5Fcreate");
5067 
5068     /* Create dataset creation property list */
5069     if (dcpl_g == H5P_DEFAULT) {
5070         dcpl = H5Pcreate(H5P_DATASET_CREATE);
5071         CHECK(dcpl, FAIL, "H5Pcreate");
5072     } else {
5073         dcpl = H5Pcopy(dcpl_g);
5074         CHECK(dcpl, FAIL, "H5Pcopy");
5075     }
5076 
5077     /* Set attribute creation order tracking & indexing for object */
5078     ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED));
5079     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
5080 
5081     /* Query the attribute creation properties */
5082     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
5083     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
5084 
5085     /* Create dataspace for dataset & attributes */
5086     sid = H5Screate(H5S_SCALAR);
5087     CHECK(sid, FAIL, "H5Screate");
5088 
5089 /* XXX: Try to find a way to resize dataset's object header so that the object
5090  *      header can have one chunk, then retrieve "empty" file size and check
5091  *      that size after everything is deleted -QAK
5092  */
5093     /* Create datasets */
5094     dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5095     CHECK(dset1, FAIL, "H5Dcreate2");
5096     dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5097     CHECK(dset2, FAIL, "H5Dcreate2");
5098     dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5099     CHECK(dset3, FAIL, "H5Dcreate2");
5100 
5101     /* Work on all the datasets */
5102     for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
5103         switch(curr_dset) {
5104             case 0:
5105                 my_dataset = dset1;
5106                 break;
5107 
5108             case 1:
5109                 my_dataset = dset2;
5110                 break;
5111 
5112             case 2:
5113                 my_dataset = dset3;
5114                 break;
5115 
5116             default:
5117                 HDassert(0 && "Too many datasets!");
5118         } /* end switch */
5119 
5120         /* Check on dataset's attribute storage status */
5121         is_empty = H5O_is_attr_empty_test(my_dataset);
5122         VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
5123         is_dense = H5O_is_attr_dense_test(my_dataset);
5124         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
5125     } /* end for */
5126 
5127     /* Close Datasets */
5128     ret = H5Dclose(dset1);
5129     CHECK(ret, FAIL, "H5Dclose");
5130     ret = H5Dclose(dset2);
5131     CHECK(ret, FAIL, "H5Dclose");
5132     ret = H5Dclose(dset3);
5133     CHECK(ret, FAIL, "H5Dclose");
5134 
5135     /* Close property list */
5136     ret = H5Pclose(dcpl);
5137     CHECK(ret, FAIL, "H5Pclose");
5138 
5139     /* Close file */
5140     ret = H5Fclose(fid);
5141     CHECK(ret, FAIL, "H5Fclose");
5142 
5143 
5144     /* Re-open file */
5145     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
5146     CHECK(fid, FAIL, "H5Fopen");
5147 
5148     /* Open datasets created */
5149     dset1 = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
5150     CHECK(dset1, FAIL, "H5Dopen2");
5151     dset2 = H5Dopen2(fid, DSET2_NAME, H5P_DEFAULT);
5152     CHECK(dset2, FAIL, "H5Dopen2");
5153     dset3 = H5Dopen2(fid, DSET3_NAME, H5P_DEFAULT);
5154     CHECK(dset3, FAIL, "H5Dopen2");
5155 
5156     /* Work on all the datasets */
5157     for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
5158         switch(curr_dset) {
5159             case 0:
5160                 my_dataset = dset1;
5161                 break;
5162 
5163             case 1:
5164                 my_dataset = dset2;
5165                 break;
5166 
5167             case 2:
5168                 my_dataset = dset3;
5169                 break;
5170 
5171             default:
5172                 HDassert(0 && "Too many datasets!");
5173         } /* end switch */
5174 
5175         /* Create several attributes, but keep storage in compact form */
5176         for(u = 0; u < max_compact; u++) {
5177             /* Create attribute */
5178             HDsprintf(attrname, "attr %02u", u);
5179             attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
5180             CHECK(attr, FAIL, "H5Acreate2");
5181 
5182             /* Write data into the attribute */
5183             ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
5184             CHECK(ret, FAIL, "H5Awrite");
5185 
5186             /* Close attribute */
5187             ret = H5Aclose(attr);
5188             CHECK(ret, FAIL, "H5Aclose");
5189 
5190             /* Verify state of object */
5191             ret = H5O_num_attrs_test(my_dataset, &nattrs);
5192             CHECK(ret, FAIL, "H5O_num_attrs_test");
5193             VERIFY(nattrs, (u + 1), "H5O_num_attrs_test");
5194             is_empty = H5O_is_attr_empty_test(my_dataset);
5195             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5196             is_dense = H5O_is_attr_dense_test(my_dataset);
5197             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
5198         } /* end for */
5199 
5200         /* Create another attribute, to push into dense storage */
5201         HDsprintf(attrname, "attr %02u", max_compact);
5202         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
5203         CHECK(attr, FAIL, "H5Acreate2");
5204 
5205         /* Write data into the attribute */
5206         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
5207         CHECK(ret, FAIL, "H5Awrite");
5208 
5209         /* Close attribute */
5210         ret = H5Aclose(attr);
5211         CHECK(ret, FAIL, "H5Aclose");
5212 
5213         /* Verify state of object */
5214         ret = H5O_num_attrs_test(my_dataset, &nattrs);
5215         CHECK(ret, FAIL, "H5O_num_attrs_test");
5216         VERIFY(nattrs, (max_compact + 1), "H5O_num_attrs_test");
5217         is_empty = H5O_is_attr_empty_test(my_dataset);
5218         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5219         is_dense = H5O_is_attr_dense_test(my_dataset);
5220         VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
5221 
5222         /* Retrieve & verify # of records in the name & creation order indices */
5223         ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
5224         CHECK(ret, FAIL, "H5O_attr_dense_info_test");
5225         VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
5226 
5227         /* Delete several attributes from object, until attribute storage resumes compact form */
5228         for(u = max_compact; u >= min_dense; u--) {
5229             HDsprintf(attrname, "attr %02u", u);
5230             ret = H5Adelete(my_dataset, attrname);
5231             CHECK(ret, FAIL, "H5Adelete");
5232 
5233             /* Verify state of object */
5234             ret = H5O_num_attrs_test(my_dataset, &nattrs);
5235             CHECK(ret, FAIL, "H5O_num_attrs_test");
5236             VERIFY(nattrs, u, "H5O_num_attrs_test");
5237             is_empty = H5O_is_attr_empty_test(my_dataset);
5238             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5239             is_dense = H5O_is_attr_dense_test(my_dataset);
5240             VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
5241 
5242             /* Retrieve & verify # of records in the name & creation order indices */
5243             ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
5244             CHECK(ret, FAIL, "H5O_attr_dense_info_test");
5245             VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
5246         } /* end for */
5247 
5248         /* Delete another attribute, to push attribute storage into compact form */
5249         HDsprintf(attrname, "attr %02u", (min_dense - 1));
5250         ret = H5Adelete(my_dataset, attrname);
5251         CHECK(ret, FAIL, "H5Adelete");
5252 
5253         /* Verify state of object */
5254         ret = H5O_num_attrs_test(my_dataset, &nattrs);
5255         CHECK(ret, FAIL, "H5O_num_attrs_test");
5256         VERIFY(nattrs, (min_dense - 1), "H5O_num_attrs_test");
5257         is_empty = H5O_is_attr_empty_test(my_dataset);
5258         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5259         is_dense = H5O_is_attr_dense_test(my_dataset);
5260         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
5261 
5262         /* Re-add attributes to get back into dense form */
5263         for(u = (min_dense - 1); u < (max_compact + 1); u++) {
5264             /* Create attribute */
5265             HDsprintf(attrname, "attr %02u", u);
5266             attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
5267             CHECK(attr, FAIL, "H5Acreate2");
5268 
5269             /* Write data into the attribute */
5270             ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
5271             CHECK(ret, FAIL, "H5Awrite");
5272 
5273             /* Close attribute */
5274             ret = H5Aclose(attr);
5275             CHECK(ret, FAIL, "H5Aclose");
5276         } /* end for */
5277 
5278         /* Verify state of object */
5279         ret = H5O_num_attrs_test(my_dataset, &nattrs);
5280         CHECK(ret, FAIL, "H5O_num_attrs_test");
5281         VERIFY(nattrs, (max_compact + 1), "H5O_num_attrs_test");
5282         is_empty = H5O_is_attr_empty_test(my_dataset);
5283         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5284         is_dense = H5O_is_attr_dense_test(my_dataset);
5285         VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
5286 
5287         /* Retrieve & verify # of records in the name & creation order indices */
5288         ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
5289         CHECK(ret, FAIL, "H5O_attr_dense_info_test");
5290         VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
5291     } /* end for */
5292 
5293     /* Close Datasets */
5294     ret = H5Dclose(dset1);
5295     CHECK(ret, FAIL, "H5Dclose");
5296     ret = H5Dclose(dset2);
5297     CHECK(ret, FAIL, "H5Dclose");
5298     ret = H5Dclose(dset3);
5299     CHECK(ret, FAIL, "H5Dclose");
5300 
5301     /* Close file */
5302     ret = H5Fclose(fid);
5303     CHECK(ret, FAIL, "H5Fclose");
5304 
5305 
5306     /* Re-open file */
5307     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
5308     CHECK(fid, FAIL, "H5Fopen");
5309 
5310     /* Open datasets created */
5311     dset1 = H5Dopen2(fid, DSET1_NAME, H5P_DEFAULT);
5312     CHECK(dset1, FAIL, "H5Dopen2");
5313     dset2 = H5Dopen2(fid, DSET2_NAME, H5P_DEFAULT);
5314     CHECK(dset2, FAIL, "H5Dopen2");
5315     dset3 = H5Dopen2(fid, DSET3_NAME, H5P_DEFAULT);
5316     CHECK(dset3, FAIL, "H5Dopen2");
5317 
5318     /* Work on all the datasets */
5319     for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
5320         switch(curr_dset) {
5321             case 0:
5322                 my_dataset = dset1;
5323                 break;
5324 
5325             case 1:
5326                 my_dataset = dset2;
5327                 break;
5328 
5329             case 2:
5330                 my_dataset = dset3;
5331                 break;
5332 
5333             default:
5334                 HDassert(0 && "Too many datasets!");
5335         } /* end switch */
5336 
5337         /* Check on dataset's attribute storage status */
5338         ret = H5O_num_attrs_test(my_dataset, &nattrs);
5339         CHECK(ret, FAIL, "H5O_num_attrs_test");
5340         VERIFY(nattrs, (max_compact + 1), "H5O_num_attrs_test");
5341         is_empty = H5O_is_attr_empty_test(my_dataset);
5342         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5343         is_dense = H5O_is_attr_dense_test(my_dataset);
5344         VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
5345 
5346         /* Retrieve & verify # of records in the name & creation order indices */
5347         ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
5348         CHECK(ret, FAIL, "H5O_attr_dense_info_test");
5349         VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
5350 
5351         /* Delete several attributes from object, until attribute storage resumes compact form */
5352         for(u = max_compact; u >= min_dense; u--) {
5353             HDsprintf(attrname, "attr %02u", u);
5354             ret = H5Adelete(my_dataset, attrname);
5355             CHECK(ret, FAIL, "H5Adelete");
5356 
5357             /* Verify state of object */
5358             ret = H5O_num_attrs_test(my_dataset, &nattrs);
5359             CHECK(ret, FAIL, "H5O_num_attrs_test");
5360             VERIFY(nattrs, u, "H5O_num_attrs_test");
5361             is_empty = H5O_is_attr_empty_test(my_dataset);
5362             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5363             is_dense = H5O_is_attr_dense_test(my_dataset);
5364             VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
5365 
5366             /* Retrieve & verify # of records in the name & creation order indices */
5367             ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
5368             CHECK(ret, FAIL, "H5O_attr_dense_info_test");
5369             VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
5370         } /* end for */
5371 
5372         /* Delete another attribute, to push attribute storage into compact form */
5373         HDsprintf(attrname, "attr %02u", (min_dense - 1));
5374         ret = H5Adelete(my_dataset, attrname);
5375         CHECK(ret, FAIL, "H5Adelete");
5376 
5377         /* Verify state of object */
5378         ret = H5O_num_attrs_test(my_dataset, &nattrs);
5379         CHECK(ret, FAIL, "H5O_num_attrs_test");
5380         VERIFY(nattrs, (min_dense - 1), "H5O_num_attrs_test");
5381         is_empty = H5O_is_attr_empty_test(my_dataset);
5382         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5383         is_dense = H5O_is_attr_dense_test(my_dataset);
5384         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
5385 
5386         /* Re-add attributes to get back into dense form */
5387         for(u = (min_dense - 1); u < (max_compact + 1); u++) {
5388             /* Create attribute */
5389             HDsprintf(attrname, "attr %02u", u);
5390             attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
5391             CHECK(attr, FAIL, "H5Acreate2");
5392 
5393             /* Write data into the attribute */
5394             ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
5395             CHECK(ret, FAIL, "H5Awrite");
5396 
5397             /* Close attribute */
5398             ret = H5Aclose(attr);
5399             CHECK(ret, FAIL, "H5Aclose");
5400         } /* end for */
5401 
5402         /* Verify state of object */
5403         ret = H5O_num_attrs_test(my_dataset, &nattrs);
5404         CHECK(ret, FAIL, "H5O_num_attrs_test");
5405         VERIFY(nattrs, (max_compact + 1), "H5O_num_attrs_test");
5406         is_empty = H5O_is_attr_empty_test(my_dataset);
5407         VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5408         is_dense = H5O_is_attr_dense_test(my_dataset);
5409         VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
5410 
5411         /* Retrieve & verify # of records in the name & creation order indices */
5412         ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
5413         CHECK(ret, FAIL, "H5O_attr_dense_info_test");
5414         VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
5415 
5416         /* Delete all attributes */
5417         for(u = max_compact; u > 0; u--) {
5418             HDsprintf(attrname, "attr %02u", u);
5419             ret = H5Adelete(my_dataset, attrname);
5420             CHECK(ret, FAIL, "H5Adelete");
5421         } /* end for */
5422         HDsprintf(attrname, "attr %02u", 0);
5423         ret = H5Adelete(my_dataset, attrname);
5424         CHECK(ret, FAIL, "H5Adelete");
5425     } /* end for */
5426 
5427     /* Close Datasets */
5428     ret = H5Dclose(dset1);
5429     CHECK(ret, FAIL, "H5Dclose");
5430     ret = H5Dclose(dset2);
5431     CHECK(ret, FAIL, "H5Dclose");
5432     ret = H5Dclose(dset3);
5433     CHECK(ret, FAIL, "H5Dclose");
5434 
5435     /* Close file */
5436     ret = H5Fclose(fid);
5437     CHECK(ret, FAIL, "H5Fclose");
5438 
5439     /* Close dataspace */
5440     ret = H5Sclose(sid);
5441     CHECK(ret, FAIL, "H5Sclose");
5442 }   /* test_attr_corder_transition() */
5443 
5444 
5445 /****************************************************************
5446 **
5447 **  test_attr_corder_delete(): Test basic H5A (attribute) code.
5448 **      Tests deleting object w/dense attribute storage on objects with attribute creation order info
5449 **
5450 ****************************************************************/
5451 static void
test_attr_corder_delete(hid_t fcpl,hid_t fapl)5452 test_attr_corder_delete(hid_t fcpl, hid_t fapl)
5453 {
5454     hid_t    fid;        /* HDF5 File ID            */
5455     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
5456     hid_t    my_dataset;    /* Current dataset ID        */
5457     hid_t    sid;            /* Dataspace ID            */
5458     hid_t    attr;            /* Attribute ID            */
5459     hid_t    dcpl;            /* Dataset creation property list ID */
5460     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
5461     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
5462     htri_t    is_empty;    /* Are there any attributes? */
5463     htri_t    is_dense;    /* Are attributes stored densely? */
5464     hsize_t     nattrs;         /* Number of attributes on object */
5465     hsize_t     name_count;     /* # of records in name index */
5466     hsize_t     corder_count;   /* # of records in creation order index */
5467     unsigned     reopen_file;            /* Whether to re-open the file before deleting group */
5468     char    attrname[NAME_BUF_SIZE];        /* Name of attribute */
5469 #ifdef LATER
5470     h5_stat_size_t empty_size;  /* Size of empty file */
5471     h5_stat_size_t file_size;   /* Size of file after operating on it */
5472 #endif /* LATER */
5473     unsigned    curr_dset;      /* Current dataset to work on */
5474     unsigned    u;              /* Local index variable */
5475     herr_t    ret;        /* Generic return value        */
5476 
5477     /* Output message about test being performed */
5478     MESSAGE(5, ("Testing Deleting Object w/Dense Attribute Storage and Creation Order Info\n"));
5479 
5480     /* Create dataspace for dataset & attributes */
5481     sid = H5Screate(H5S_SCALAR);
5482     CHECK(sid, FAIL, "H5Screate");
5483 
5484     /* Create dataset creation property list */
5485     if (dcpl_g == H5P_DEFAULT) {
5486         dcpl = H5Pcreate(H5P_DATASET_CREATE);
5487         CHECK(dcpl, FAIL, "H5Pcreate");
5488     } else {
5489         dcpl = H5Pcopy(dcpl_g);
5490         CHECK(dcpl, FAIL, "H5Pcopy");
5491     }
5492 
5493     /* Set attribute creation order tracking & indexing for object */
5494     ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED));
5495     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
5496 
5497     /* Query the attribute creation properties */
5498     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
5499     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
5500 
5501 
5502 /* XXX: Try to find a way to resize dataset's object header so that the object
5503  *      header can have one chunk, then retrieve "empty" file size and check
5504  *      that size after everything is deleted -QAK
5505  */
5506 #ifdef LATER
5507     /* Create empty file */
5508     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
5509     CHECK(fid, FAIL, "H5Fcreate");
5510 
5511     /* Close file */
5512     ret = H5Fclose(fid);
5513     CHECK(ret, FAIL, "H5Fclose");
5514 
5515     /* Get the size of an empty file */
5516     empty_size = h5_get_file_size(FILENAME);
5517     CHECK(empty_size, FAIL, "h5_get_file_size");
5518 #endif /* LATER */
5519 
5520 
5521     /* Loop to leave file open when deleting dataset, or to close & re-open file
5522      *  before deleting dataset */
5523     for(reopen_file = FALSE; reopen_file <= TRUE; reopen_file++) {
5524         /* Create test file */
5525         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
5526         CHECK(fid, FAIL, "H5Fopen");
5527 
5528         /* Create datasets */
5529         dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5530         CHECK(dset1, FAIL, "H5Dcreate2");
5531         dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5532         CHECK(dset2, FAIL, "H5Dcreate2");
5533         dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5534         CHECK(dset3, FAIL, "H5Dcreate2");
5535 
5536         /* Work on all the datasets */
5537         for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
5538             switch(curr_dset) {
5539                 case 0:
5540                     my_dataset = dset1;
5541                     break;
5542 
5543                 case 1:
5544                     my_dataset = dset2;
5545                     break;
5546 
5547                 case 2:
5548                     my_dataset = dset3;
5549                     break;
5550 
5551                 default:
5552                     HDassert(0 && "Too many datasets!");
5553             } /* end switch */
5554 
5555             /* Check on dataset's attribute storage status */
5556             is_empty = H5O_is_attr_empty_test(my_dataset);
5557             VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
5558             is_dense = H5O_is_attr_dense_test(my_dataset);
5559             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
5560 
5561             /* Create attributes, until attribute storage is in dense form */
5562             for(u = 0; u < max_compact * 2; u++) {
5563                 /* Create attribute */
5564                 HDsprintf(attrname, "attr %02u", u);
5565                 attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
5566                 CHECK(attr, FAIL, "H5Acreate2");
5567 
5568                 /* Write data into the attribute */
5569                 ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
5570                 CHECK(ret, FAIL, "H5Awrite");
5571 
5572                 /* Close attribute */
5573                 ret = H5Aclose(attr);
5574                 CHECK(ret, FAIL, "H5Aclose");
5575             } /* end for */
5576 
5577             /* Verify state of object */
5578             ret = H5O_num_attrs_test(my_dataset, &nattrs);
5579             CHECK(ret, FAIL, "H5O_num_attrs_test");
5580             VERIFY(nattrs, (max_compact * 2), "H5O_num_attrs_test");
5581             is_empty = H5O_is_attr_empty_test(my_dataset);
5582             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5583             is_dense = H5O_is_attr_dense_test(my_dataset);
5584             VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
5585 
5586             /* Retrieve & verify # of records in the name & creation order indices */
5587             ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
5588             CHECK(ret, FAIL, "H5O_attr_dense_info_test");
5589             VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
5590         } /* end for */
5591 
5592         /* Close Datasets */
5593         ret = H5Dclose(dset1);
5594         CHECK(ret, FAIL, "H5Dclose");
5595         ret = H5Dclose(dset2);
5596         CHECK(ret, FAIL, "H5Dclose");
5597         ret = H5Dclose(dset3);
5598         CHECK(ret, FAIL, "H5Dclose");
5599 
5600         /* Check for deleting datasets without re-opening file */
5601         if(!reopen_file) {
5602             ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
5603             CHECK(ret, FAIL, "H5Ldelete");
5604             ret = H5Ldelete(fid, DSET2_NAME, H5P_DEFAULT);
5605             CHECK(ret, FAIL, "H5Ldelete");
5606             ret = H5Ldelete(fid, DSET3_NAME, H5P_DEFAULT);
5607             CHECK(ret, FAIL, "H5Ldelete");
5608         } /* end if */
5609 
5610         /* Close file */
5611         ret = H5Fclose(fid);
5612         CHECK(ret, FAIL, "H5Fclose");
5613 
5614         /* Check for deleting dataset after re-opening file */
5615         if(reopen_file) {
5616             /* Re-open file */
5617             fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
5618             CHECK(fid, FAIL, "H5Fopen");
5619 
5620             /* Delete the datasets */
5621             ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
5622             CHECK(ret, FAIL, "H5Ldelete");
5623             ret = H5Ldelete(fid, DSET2_NAME, H5P_DEFAULT);
5624             CHECK(ret, FAIL, "H5Ldelete");
5625             ret = H5Ldelete(fid, DSET3_NAME, H5P_DEFAULT);
5626             CHECK(ret, FAIL, "H5Ldelete");
5627 
5628             /* Close file */
5629             ret = H5Fclose(fid);
5630             CHECK(ret, FAIL, "H5Fclose");
5631         } /* end if */
5632 
5633 #ifdef LATER
5634         /* Get the size of the file now */
5635         file_size = h5_get_file_size(FILENAME);
5636         CHECK(file_size, FAIL, "h5_get_file_size");
5637         VERIFY(file_size, empty_size, "h5_get_file_size");
5638 #endif /* LATER */
5639     } /* end for */
5640 
5641     /* Close property list */
5642     ret = H5Pclose(dcpl);
5643     CHECK(ret, FAIL, "H5Pclose");
5644 
5645     /* Close dataspace */
5646     ret = H5Sclose(sid);
5647     CHECK(ret, FAIL, "H5Sclose");
5648 }   /* test_attr_corder_delete() */
5649 
5650 
5651 /*-------------------------------------------------------------------------
5652  * Function:    attr_info_by_idx_check
5653  *
5654  * Purpose:     Support routine for attr_info_by_idx, to verify the attribute
5655  *              info is correct for a attribute
5656  *
5657  * Note:    This routine assumes that the attributes have been added to the
5658  *              object in alphabetical order.
5659  *
5660  * Return:      Success:        0
5661  *              Failure:        -1
5662  *
5663  * Programmer:  Quincey Koziol
5664  *              Tuesday, Februrary 13, 2007
5665  *
5666  *-------------------------------------------------------------------------
5667  */
5668 static int
attr_info_by_idx_check(hid_t obj_id,const char * attrname,hsize_t n,hbool_t use_index)5669 attr_info_by_idx_check(hid_t obj_id, const char *attrname, hsize_t n,
5670     hbool_t use_index)
5671 {
5672     char tmpname[NAME_BUF_SIZE];        /* Temporary attribute name */
5673     H5A_info_t  ainfo;                  /* Attribute info struct */
5674     int         old_nerrs;              /* Number of errors when entering this check */
5675     herr_t    ret;                /* Generic return value */
5676 
5677     /* Retrieve the current # of reported errors */
5678     old_nerrs = GetTestNumErrs();
5679 
5680     /* Verify the information for first attribute, in increasing creation order */
5681     HDmemset(&ainfo, 0, sizeof(ainfo));
5682     ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, &ainfo, H5P_DEFAULT);
5683     CHECK(ret, FAIL, "H5Aget_info_by_idx");
5684     VERIFY(ainfo.corder, 0, "H5Aget_info_by_idx");
5685 
5686     /* Verify the information for new attribute, in increasing creation order */
5687     HDmemset(&ainfo, 0, sizeof(ainfo));
5688     ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, n, &ainfo, H5P_DEFAULT);
5689     CHECK(ret, FAIL, "H5Aget_info_by_idx");
5690     VERIFY(ainfo.corder, n, "H5Aget_info_by_idx");
5691 
5692     /* Verify the name for new link, in increasing creation order */
5693     HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
5694     ret = (herr_t)H5Aget_name_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, n, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
5695     CHECK(ret, FAIL, "H5Aget_name_by_idx");
5696     if(HDstrcmp(attrname, tmpname))
5697         TestErrPrintf("Line %d: attribute name size wrong!\n", __LINE__);
5698 
5699 
5700     /* Don't test "native" order if there is no creation order index, since
5701      *  there's not a good way to easily predict the attribute's order in the name
5702      *  index.
5703      */
5704     if(use_index) {
5705         /* Verify the information for first attribute, in native creation order */
5706         HDmemset(&ainfo, 0, sizeof(ainfo));
5707         ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, (hsize_t)0, &ainfo, H5P_DEFAULT);
5708         CHECK(ret, FAIL, "H5Aget_info_by_idx");
5709         VERIFY(ainfo.corder, 0, "H5Aget_info_by_idx");
5710 
5711         /* Verify the information for new attribute, in native creation order */
5712         HDmemset(&ainfo, 0, sizeof(ainfo));
5713         ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, n, &ainfo, H5P_DEFAULT);
5714         CHECK(ret, FAIL, "H5Aget_info_by_idx");
5715         VERIFY(ainfo.corder, n, "H5Aget_info_by_idx");
5716 
5717         /* Verify the name for new link, in increasing native order */
5718         HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
5719         ret = (herr_t)H5Aget_name_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, n, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
5720         CHECK(ret, FAIL, "H5Aget_name_by_idx");
5721         if(HDstrcmp(attrname, tmpname))
5722             TestErrPrintf("Line %d: attribute name size wrong!\n", __LINE__);
5723     } /* end if */
5724 
5725 
5726     /* Verify the information for first attribute, in decreasing creation order */
5727     HDmemset(&ainfo, 0, sizeof(ainfo));
5728     ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_DEC, n, &ainfo, H5P_DEFAULT);
5729     CHECK(ret, FAIL, "H5Aget_info_by_idx");
5730     VERIFY(ainfo.corder, 0, "H5Aget_info_by_idx");
5731 
5732     /* Verify the information for new attribute, in increasing creation order */
5733     HDmemset(&ainfo, 0, sizeof(ainfo));
5734     ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_DEC, (hsize_t)0, &ainfo, H5P_DEFAULT);
5735     CHECK(ret, FAIL, "H5Aget_info_by_idx");
5736     VERIFY(ainfo.corder, n, "H5Aget_info_by_idx");
5737 
5738     /* Verify the name for new link, in increasing creation order */
5739     HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
5740     ret = (herr_t)H5Aget_name_by_idx(obj_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_DEC, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
5741     CHECK(ret, FAIL, "H5Aget_name_by_idx");
5742     if(HDstrcmp(attrname, tmpname))
5743         TestErrPrintf("Line %d: attribute name size wrong!\n", __LINE__);
5744 
5745 
5746     /* Verify the information for first attribute, in increasing name order */
5747     HDmemset(&ainfo, 0, sizeof(ainfo));
5748     ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)0, &ainfo, H5P_DEFAULT);
5749     CHECK(ret, FAIL, "H5Aget_info_by_idx");
5750     VERIFY(ainfo.corder, 0, "H5Aget_info_by_idx");
5751 
5752     /* Verify the information for new attribute, in increasing name order */
5753     HDmemset(&ainfo, 0, sizeof(ainfo));
5754     ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_NAME, H5_ITER_INC, n, &ainfo, H5P_DEFAULT);
5755     CHECK(ret, FAIL, "H5Aget_info_by_idx");
5756     VERIFY(ainfo.corder, n, "H5Aget_info_by_idx");
5757 
5758     /* Verify the name for new link, in increasing name order */
5759     HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
5760     ret = (herr_t)H5Aget_name_by_idx(obj_id, ".", H5_INDEX_NAME, H5_ITER_INC, n, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
5761     CHECK(ret, FAIL, "H5Aget_name_by_idx");
5762     if(HDstrcmp(attrname, tmpname))
5763         TestErrPrintf("Line %d: attribute name size wrong!\n", __LINE__);
5764 
5765 
5766     /* Don't test "native" order queries on link name order, since there's not
5767      *  a good way to easily predict the order of the links in the name index.
5768      */
5769 
5770 
5771     /* Verify the information for first attribute, in decreasing name order */
5772     HDmemset(&ainfo, 0, sizeof(ainfo));
5773     ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_NAME, H5_ITER_DEC, n, &ainfo, H5P_DEFAULT);
5774     CHECK(ret, FAIL, "H5Aget_info_by_idx");
5775     VERIFY(ainfo.corder, 0, "H5Aget_info_by_idx");
5776 
5777     /* Verify the information for new attribute, in increasing name order */
5778     HDmemset(&ainfo, 0, sizeof(ainfo));
5779     ret = H5Aget_info_by_idx(obj_id, ".", H5_INDEX_NAME, H5_ITER_DEC, (hsize_t)0, &ainfo, H5P_DEFAULT);
5780     CHECK(ret, FAIL, "H5Aget_info_by_idx");
5781     VERIFY(ainfo.corder, n, "H5Aget_info_by_idx");
5782 
5783     /* Verify the name for new link, in increasing name order */
5784     HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
5785     ret = (herr_t)H5Aget_name_by_idx(obj_id, ".", H5_INDEX_NAME, H5_ITER_DEC, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
5786     CHECK(ret, FAIL, "H5Aget_name_by_idx");
5787     if(HDstrcmp(attrname, tmpname))
5788         TestErrPrintf("Line %d: attribute name size wrong!\n", __LINE__);
5789 
5790     /* Retrieve current # of errors */
5791     if(old_nerrs == GetTestNumErrs())
5792         return(0);
5793     else
5794         return(-1);
5795 } /* end attr_info_by_idx_check() */
5796 
5797 
5798 /****************************************************************
5799 **
5800 **  test_attr_info_by_idx(): Test basic H5A (attribute) code.
5801 **      Tests querying attribute info by index
5802 **
5803 ****************************************************************/
5804 static void
test_attr_info_by_idx(hbool_t new_format,hid_t fcpl,hid_t fapl)5805 test_attr_info_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
5806 {
5807     hid_t    fid;        /* HDF5 File ID            */
5808     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
5809     hid_t    my_dataset;    /* Current dataset ID        */
5810     hid_t    sid;            /* Dataspace ID            */
5811     hid_t    attr;            /* Attribute ID            */
5812     hid_t    dcpl;            /* Dataset creation property list ID */
5813     H5A_info_t  ainfo;          /* Attribute information */
5814     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
5815     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
5816     htri_t    is_empty;    /* Are there any attributes? */
5817     htri_t    is_dense;    /* Are attributes stored densely? */
5818     hsize_t     nattrs;         /* Number of attributes on object */
5819     hsize_t     name_count;     /* # of records in name index */
5820     hsize_t     corder_count;   /* # of records in creation order index */
5821     unsigned     use_index;     /* Use index on creation order values */
5822     char    attrname[NAME_BUF_SIZE];    /* Name of attribute */
5823     char        tmpname[NAME_BUF_SIZE];     /* Temporary attribute name */
5824     unsigned    curr_dset;      /* Current dataset to work on */
5825     unsigned    u;              /* Local index variable */
5826     herr_t    ret;        /* Generic return value        */
5827 
5828     /* Create dataspace for dataset & attributes */
5829     sid = H5Screate(H5S_SCALAR);
5830     CHECK(sid, FAIL, "H5Screate");
5831 
5832     /* Create dataset creation property list */
5833     if (dcpl_g == H5P_DEFAULT) {
5834         dcpl = H5Pcreate(H5P_DATASET_CREATE);
5835         CHECK(dcpl, FAIL, "H5Pcreate");
5836     } else {
5837         dcpl = H5Pcopy(dcpl_g);
5838         CHECK(dcpl, FAIL, "H5Pcopy");
5839     }
5840 
5841     /* Query the attribute creation properties */
5842     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
5843     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
5844 
5845     /* Loop over using index for creation order value */
5846     for(use_index = FALSE; use_index <= TRUE; use_index++) {
5847         /* Output message about test being performed */
5848         if(use_index)
5849             MESSAGE(5, ("Testing Querying Attribute Info By Index w/Creation Order Index\n"))
5850         else
5851             MESSAGE(5, ("Testing Querying Attribute Info By Index w/o Creation Order Index\n"))
5852 
5853         /* Create file */
5854         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
5855         CHECK(fid, FAIL, "H5Fcreate");
5856 
5857         /* Set attribute creation order tracking & indexing for object */
5858         if(new_format == TRUE) {
5859             ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
5860             CHECK(ret, FAIL, "H5Pset_attr_creation_order");
5861         } /* end if */
5862 
5863         /* Create datasets */
5864         dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5865         CHECK(dset1, FAIL, "H5Dcreate2");
5866         dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5867         CHECK(dset2, FAIL, "H5Dcreate2");
5868         dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
5869         CHECK(dset3, FAIL, "H5Dcreate2");
5870 
5871         /* Work on all the datasets */
5872         for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
5873             switch(curr_dset) {
5874                 case 0:
5875                     my_dataset = dset1;
5876                     break;
5877 
5878                 case 1:
5879                     my_dataset = dset2;
5880                     break;
5881 
5882                 case 2:
5883                     my_dataset = dset3;
5884                     break;
5885 
5886                 default:
5887                     HDassert(0 && "Too many datasets!");
5888             } /* end switch */
5889 
5890             /* Check on dataset's attribute storage status */
5891             is_empty = H5O_is_attr_empty_test(my_dataset);
5892             VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
5893             is_dense = H5O_is_attr_dense_test(my_dataset);
5894             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
5895 
5896             /* Check for query on non-existant attribute */
5897             ret = H5Aget_info_by_idx(my_dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, &ainfo, H5P_DEFAULT);
5898             VERIFY(ret, FAIL, "H5Aget_info_by_idx");
5899             ret = (herr_t)H5Aget_name_by_idx(my_dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
5900             VERIFY(ret, FAIL, "H5Aget_name_by_idx");
5901 
5902             /* Create attributes, up to limit of compact form */
5903             for(u = 0; u < max_compact; u++) {
5904                 /* Create attribute */
5905                 HDsprintf(attrname, "attr %02u", u);
5906                 attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
5907                 CHECK(attr, FAIL, "H5Acreate2");
5908 
5909                 /* Write data into the attribute */
5910                 ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
5911                 CHECK(ret, FAIL, "H5Awrite");
5912 
5913                 /* Close attribute */
5914                 ret = H5Aclose(attr);
5915                 CHECK(ret, FAIL, "H5Aclose");
5916 
5917                 /* Verify information for new attribute */
5918                 ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
5919                 CHECK(ret, FAIL, "attr_info_by_idx_check");
5920             } /* end for */
5921 
5922             /* Verify state of object */
5923             ret = H5O_num_attrs_test(my_dataset, &nattrs);
5924             CHECK(ret, FAIL, "H5O_num_attrs_test");
5925             VERIFY(nattrs, max_compact, "H5O_num_attrs_test");
5926             is_empty = H5O_is_attr_empty_test(my_dataset);
5927             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5928             is_dense = H5O_is_attr_dense_test(my_dataset);
5929             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
5930 
5931             /* Check for out of bound offset queries */
5932             ret = H5Aget_info_by_idx(my_dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, &ainfo, H5P_DEFAULT);
5933             VERIFY(ret, FAIL, "H5Aget_info_by_idx");
5934             ret = H5Aget_info_by_idx(my_dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_DEC, (hsize_t)u, &ainfo, H5P_DEFAULT);
5935             VERIFY(ret, FAIL, "H5Aget_info_by_idx");
5936             ret = (herr_t)H5Aget_name_by_idx(my_dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
5937             VERIFY(ret, FAIL, "H5Aget_name_by_idx");
5938 
5939             /* Create more attributes, to push into dense form */
5940             for(; u < (max_compact * 2); u++) {
5941                 /* Create attribute */
5942                 HDsprintf(attrname, "attr %02u", u);
5943                 attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
5944                 CHECK(attr, FAIL, "H5Acreate2");
5945 
5946                 /* Write data into the attribute */
5947                 ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
5948                 CHECK(ret, FAIL, "H5Awrite");
5949 
5950                 /* Close attribute */
5951                 ret = H5Aclose(attr);
5952                 CHECK(ret, FAIL, "H5Aclose");
5953 
5954                 /* Verify state of object */
5955                 is_dense = H5O_is_attr_dense_test(my_dataset);
5956                 VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
5957 
5958                 /* Verify information for new attribute */
5959                 ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
5960                 CHECK(ret, FAIL, "attr_info_by_idx_check");
5961             } /* end for */
5962 
5963             /* Verify state of object */
5964             ret = H5O_num_attrs_test(my_dataset, &nattrs);
5965             CHECK(ret, FAIL, "H5O_num_attrs_test");
5966             VERIFY(nattrs, (max_compact * 2), "H5O_num_attrs_test");
5967             is_empty = H5O_is_attr_empty_test(my_dataset);
5968             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
5969             is_dense = H5O_is_attr_dense_test(my_dataset);
5970             VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
5971 
5972             if(new_format) {
5973                 /* Retrieve & verify # of records in the name & creation order indices */
5974                 ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
5975                 CHECK(ret, FAIL, "H5O_attr_dense_info_test");
5976                 if(use_index)
5977                     VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
5978                 VERIFY(name_count, (max_compact * 2), "H5O_attr_dense_info_test");
5979             } /* end if */
5980 
5981             /* Check for out of bound offset queries */
5982             ret = H5Aget_info_by_idx(my_dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, &ainfo, H5P_DEFAULT);
5983             VERIFY(ret, FAIL, "H5Aget_info_by_idx");
5984             ret = H5Aget_info_by_idx(my_dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_DEC, (hsize_t)u, &ainfo, H5P_DEFAULT);
5985             VERIFY(ret, FAIL, "H5Aget_info_by_idx");
5986             ret = (herr_t)H5Aget_name_by_idx(my_dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
5987             VERIFY(ret, FAIL, "H5Aget_name_by_idx");
5988         } /* end for */
5989 
5990         /* Close Datasets */
5991         ret = H5Dclose(dset1);
5992         CHECK(ret, FAIL, "H5Dclose");
5993         ret = H5Dclose(dset2);
5994         CHECK(ret, FAIL, "H5Dclose");
5995         ret = H5Dclose(dset3);
5996         CHECK(ret, FAIL, "H5Dclose");
5997 
5998         /* Close file */
5999         ret = H5Fclose(fid);
6000         CHECK(ret, FAIL, "H5Fclose");
6001     } /* end for */
6002 
6003     /* Close property list */
6004     ret = H5Pclose(dcpl);
6005     CHECK(ret, FAIL, "H5Pclose");
6006 
6007     /* Close dataspace */
6008     ret = H5Sclose(sid);
6009     CHECK(ret, FAIL, "H5Sclose");
6010 }   /* test_attr_info_by_idx() */
6011 
6012 
6013 /****************************************************************
6014 **
6015 **  test_attr_delete_by_idx(): Test basic H5A (attribute) code.
6016 **      Tests deleting attribute by index
6017 **
6018 ****************************************************************/
6019 static void
test_attr_delete_by_idx(hbool_t new_format,hid_t fcpl,hid_t fapl)6020 test_attr_delete_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
6021 {
6022     hid_t    fid;        /* HDF5 File ID            */
6023     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
6024     hid_t    my_dataset;    /* Current dataset ID        */
6025     hid_t    sid;            /* Dataspace ID            */
6026     hid_t    attr;            /* Attribute ID            */
6027     hid_t    dcpl;            /* Dataset creation property list ID */
6028     H5A_info_t  ainfo;          /* Attribute information */
6029     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
6030     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
6031     htri_t    is_empty;    /* Are there any attributes? */
6032     htri_t    is_dense;    /* Are attributes stored densely? */
6033     hsize_t     nattrs;         /* Number of attributes on object */
6034     hsize_t     name_count;     /* # of records in name index */
6035     hsize_t     corder_count;   /* # of records in creation order index */
6036     H5_index_t idx_type;        /* Type of index to operate on */
6037     H5_iter_order_t order;      /* Order within in the index */
6038     unsigned     use_index;     /* Use index on creation order values */
6039     char    attrname[NAME_BUF_SIZE];    /* Name of attribute */
6040     char        tmpname[NAME_BUF_SIZE];     /* Temporary attribute name */
6041     unsigned    curr_dset;      /* Current dataset to work on */
6042     unsigned    u;              /* Local index variable */
6043     herr_t    ret;        /* Generic return value        */
6044 
6045     /* Create dataspace for dataset & attributes */
6046     sid = H5Screate(H5S_SCALAR);
6047     CHECK(sid, FAIL, "H5Screate");
6048 
6049     /* Create dataset creation property list */
6050     if (dcpl_g == H5P_DEFAULT) {
6051         dcpl = H5Pcreate(H5P_DATASET_CREATE);
6052         CHECK(dcpl, FAIL, "H5Pcreate");
6053     } else {
6054         dcpl = H5Pcopy(dcpl_g);
6055         CHECK(dcpl, FAIL, "H5Pcopy");
6056     }
6057 
6058     /* Query the attribute creation properties */
6059     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
6060     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
6061 
6062     /* Loop over operating on different indices on link fields */
6063     for(idx_type = H5_INDEX_NAME; idx_type <= H5_INDEX_CRT_ORDER; H5_INC_ENUM(H5_index_t, idx_type)) {
6064         /* Loop over operating in different orders */
6065         for(order = H5_ITER_INC; order <= H5_ITER_DEC; H5_INC_ENUM(H5_iter_order_t, order)) {
6066             /* Loop over using index for creation order value */
6067             for(use_index = FALSE; use_index <= TRUE; use_index++) {
6068                 /* Print appropriate test message */
6069                 if(idx_type == H5_INDEX_CRT_ORDER) {
6070                     if(order == H5_ITER_INC) {
6071                         if(use_index)
6072                             MESSAGE(5, ("Testing Deleting Attribute By Creation Order Index in Increasing Order w/Creation Order Index\n"))
6073                         else
6074                             MESSAGE(5, ("Testing Deleting Attribute By Creation Order Index in Increasing Order w/o Creation Order Index\n"))
6075                     } /* end if */
6076                     else {
6077                         if(use_index)
6078                             MESSAGE(5, ("Testing Deleting Attribute By Creation Order Index in Decreasing Order w/Creation Order Index\n"))
6079                         else
6080                             MESSAGE(5, ("Testing Deleting Attribute By Creation Order Index in Decreasing Order w/o Creation Order Index\n"))
6081                     } /* end else */
6082                 } /* end if */
6083                 else {
6084                     if(order == H5_ITER_INC) {
6085                         if(use_index)
6086                             MESSAGE(5, ("Testing Deleting Attribute By Name Index in Increasing Order w/Creation Order Index\n"))
6087                         else
6088                             MESSAGE(5, ("Testing Deleting Attribute By Name Index in Increasing Order w/o Creation Order Index\n"))
6089                     } /* end if */
6090                     else {
6091                         if(use_index)
6092                             MESSAGE(5, ("Testing Deleting Attribute By Name Index in Decreasing Order w/Creation Order Index\n"))
6093                         else
6094                             MESSAGE(5, ("Testing Deleting Attribute By Name Index in Decreasing Order w/o Creation Order Index\n"))
6095                     } /* end else */
6096                 } /* end else */
6097 
6098                 /* Create file */
6099                 fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
6100                 CHECK(fid, FAIL, "H5Fcreate");
6101 
6102                 /* Set attribute creation order tracking & indexing for object */
6103                 if(new_format == TRUE) {
6104                     ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
6105                     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
6106                 } /* end if */
6107 
6108                 /* Create datasets */
6109                 dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
6110                 CHECK(dset1, FAIL, "H5Dcreate2");
6111                 dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
6112                 CHECK(dset2, FAIL, "H5Dcreate2");
6113                 dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
6114                 CHECK(dset3, FAIL, "H5Dcreate2");
6115 
6116                 /* Work on all the datasets */
6117                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
6118                     switch(curr_dset) {
6119                         case 0:
6120                             my_dataset = dset1;
6121                             break;
6122 
6123                         case 1:
6124                             my_dataset = dset2;
6125                             break;
6126 
6127                         case 2:
6128                             my_dataset = dset3;
6129                             break;
6130 
6131                         default:
6132                             HDassert(0 && "Too many datasets!");
6133                     } /* end switch */
6134 
6135                     /* Check on dataset's attribute storage status */
6136                     is_empty = H5O_is_attr_empty_test(my_dataset);
6137                     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
6138                     is_dense = H5O_is_attr_dense_test(my_dataset);
6139                     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
6140 
6141                     /* Check for deleting non-existant attribute */
6142                     ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6143                     VERIFY(ret, FAIL, "H5Adelete_by_idx");
6144 
6145                     /* Create attributes, up to limit of compact form */
6146                     for(u = 0; u < max_compact; u++) {
6147                         /* Create attribute */
6148                         HDsprintf(attrname, "attr %02u", u);
6149                         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
6150                         CHECK(attr, FAIL, "H5Acreate2");
6151 
6152                         /* Write data into the attribute */
6153                         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
6154                         CHECK(ret, FAIL, "H5Awrite");
6155 
6156                         /* Close attribute */
6157                         ret = H5Aclose(attr);
6158                         CHECK(ret, FAIL, "H5Aclose");
6159 
6160                         /* Verify information for new attribute */
6161                         ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
6162                         CHECK(ret, FAIL, "attr_info_by_idx_check");
6163                     } /* end for */
6164 
6165                     /* Verify state of object */
6166                     ret = H5O_num_attrs_test(my_dataset, &nattrs);
6167                     CHECK(ret, FAIL, "H5O_num_attrs_test");
6168                     VERIFY(nattrs, max_compact, "H5O_num_attrs_test");
6169                     is_empty = H5O_is_attr_empty_test(my_dataset);
6170                     VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
6171                     is_dense = H5O_is_attr_dense_test(my_dataset);
6172                     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
6173 
6174                     /* Check for out of bound deletions */
6175                     ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT);
6176                     VERIFY(ret, FAIL, "H5Adelete_by_idx");
6177                 } /* end for */
6178 
6179                 /* Work on all the datasets */
6180                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
6181                     switch(curr_dset) {
6182                         case 0:
6183                             my_dataset = dset1;
6184                             break;
6185 
6186                         case 1:
6187                             my_dataset = dset2;
6188                             break;
6189 
6190                         case 2:
6191                             my_dataset = dset3;
6192                             break;
6193 
6194                         default:
6195                             HDassert(0 && "Too many datasets!");
6196                     } /* end switch */
6197 
6198                     /* Delete attributes from compact storage */
6199                     for(u = 0; u < (max_compact - 1); u++) {
6200                         /* Delete first attribute in appropriate order */
6201                         ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6202                         CHECK(ret, FAIL, "H5Adelete_by_idx");
6203 
6204                         /* Verify the attribute information for first attribute in appropriate order */
6205                         HDmemset(&ainfo, 0, sizeof(ainfo));
6206                         ret = H5Aget_info_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, &ainfo, H5P_DEFAULT);
6207                         if(new_format) {
6208                             if(order == H5_ITER_INC) {
6209                                 VERIFY(ainfo.corder, (u + 1), "H5Aget_info_by_idx");
6210                             } /* end if */
6211                             else {
6212                                 VERIFY(ainfo.corder, (max_compact - (u + 2)), "H5Aget_info_by_idx");
6213                             } /* end else */
6214                         } /* end if */
6215 
6216                         /* Verify the name for first attribute in appropriate order */
6217                         HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
6218                         ret = (herr_t)H5Aget_name_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
6219                         if(order == H5_ITER_INC)
6220                             HDsprintf(attrname, "attr %02u", (u + 1));
6221                         else
6222                             HDsprintf(attrname, "attr %02u", (max_compact - (u + 2)));
6223                         ret = HDstrcmp(attrname, tmpname);
6224                         VERIFY(ret, 0, "H5Aget_name_by_idx");
6225                     } /* end for */
6226 
6227                     /* Delete last attribute */
6228                     ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6229                     CHECK(ret, FAIL, "H5Adelete_by_idx");
6230 
6231                     /* Verify state of attribute storage (empty) */
6232                     is_empty = H5O_is_attr_empty_test(my_dataset);
6233                     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
6234                 } /* end for */
6235 
6236                 /* Work on all the datasets */
6237                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
6238                     switch(curr_dset) {
6239                         case 0:
6240                             my_dataset = dset1;
6241                             break;
6242 
6243                         case 1:
6244                             my_dataset = dset2;
6245                             break;
6246 
6247                         case 2:
6248                             my_dataset = dset3;
6249                             break;
6250 
6251                         default:
6252                             HDassert(0 && "Too many datasets!");
6253                     } /* end switch */
6254 
6255                     /* Create more attributes, to push into dense form */
6256                     for(u = 0; u < (max_compact * 2); u++) {
6257                         /* Create attribute */
6258                         HDsprintf(attrname, "attr %02u", u);
6259                         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
6260                         CHECK(attr, FAIL, "H5Acreate2");
6261 
6262                         /* Write data into the attribute */
6263                         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
6264                         CHECK(ret, FAIL, "H5Awrite");
6265 
6266                         /* Close attribute */
6267                         ret = H5Aclose(attr);
6268                         CHECK(ret, FAIL, "H5Aclose");
6269 
6270                         /* Verify state of object */
6271                         if(u >= max_compact) {
6272                             is_dense = H5O_is_attr_dense_test(my_dataset);
6273                             VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
6274                         } /* end if */
6275 
6276                         /* Verify information for new attribute */
6277                         ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
6278                         CHECK(ret, FAIL, "attr_info_by_idx_check");
6279                     } /* end for */
6280 
6281                     /* Verify state of object */
6282                     ret = H5O_num_attrs_test(my_dataset, &nattrs);
6283                     CHECK(ret, FAIL, "H5O_num_attrs_test");
6284                     VERIFY(nattrs, (max_compact * 2), "H5O_num_attrs_test");
6285                     is_empty = H5O_is_attr_empty_test(my_dataset);
6286                     VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
6287                     is_dense = H5O_is_attr_dense_test(my_dataset);
6288                     VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
6289 
6290                     if(new_format) {
6291                         /* Retrieve & verify # of records in the name & creation order indices */
6292                         ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
6293                         CHECK(ret, FAIL, "H5O_attr_dense_info_test");
6294                         if(use_index)
6295                             VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
6296                         VERIFY(name_count, (max_compact * 2), "H5O_attr_dense_info_test");
6297                     } /* end if */
6298 
6299                     /* Check for out of bound deletion */
6300                     ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT);
6301                     VERIFY(ret, FAIL, "H5Adelete_by_idx");
6302                 } /* end for */
6303 
6304                 /* Work on all the datasets */
6305                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
6306                     switch(curr_dset) {
6307                         case 0:
6308                             my_dataset = dset1;
6309                             break;
6310 
6311                         case 1:
6312                             my_dataset = dset2;
6313                             break;
6314 
6315                         case 2:
6316                             my_dataset = dset3;
6317                             break;
6318 
6319                         default:
6320                             HDassert(0 && "Too many datasets!");
6321                     } /* end switch */
6322 
6323                     /* Delete attributes from dense storage */
6324                     for(u = 0; u < ((max_compact * 2) - 1); u++) {
6325                         /* Delete first attribute in appropriate order */
6326                         ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6327                         CHECK(ret, FAIL, "H5Adelete_by_idx");
6328 
6329                         /* Verify the attribute information for first attribute in appropriate order */
6330                         HDmemset(&ainfo, 0, sizeof(ainfo));
6331                         ret = H5Aget_info_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, &ainfo, H5P_DEFAULT);
6332                         if(new_format) {
6333                             if(order == H5_ITER_INC) {
6334                                 VERIFY(ainfo.corder, (u + 1), "H5Aget_info_by_idx");
6335                             } /* end if */
6336                             else {
6337                                 VERIFY(ainfo.corder, ((max_compact * 2) - (u + 2)), "H5Aget_info_by_idx");
6338                             } /* end else */
6339                         } /* end if */
6340 
6341                         /* Verify the name for first attribute in appropriate order */
6342                         HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
6343                         ret = (herr_t)H5Aget_name_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
6344                         if(order == H5_ITER_INC)
6345                             HDsprintf(attrname, "attr %02u", (u + 1));
6346                         else
6347                             HDsprintf(attrname, "attr %02u", ((max_compact * 2) - (u + 2)));
6348                         ret = HDstrcmp(attrname, tmpname);
6349                         VERIFY(ret, 0, "H5Aget_name_by_idx");
6350                     } /* end for */
6351 
6352                     /* Delete last attribute */
6353                     ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6354                     CHECK(ret, FAIL, "H5Adelete_by_idx");
6355 
6356                     /* Verify state of attribute storage (empty) */
6357                     is_empty = H5O_is_attr_empty_test(my_dataset);
6358                     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
6359 
6360                     /* Check for deletion on empty attribute storage again */
6361                     ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6362                     VERIFY(ret, FAIL, "H5Adelete_by_idx");
6363                 } /* end for */
6364 
6365 
6366                     /* Delete attributes in middle */
6367 
6368 
6369                 /* Work on all the datasets */
6370                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
6371                     switch(curr_dset) {
6372                         case 0:
6373                             my_dataset = dset1;
6374                             break;
6375 
6376                         case 1:
6377                             my_dataset = dset2;
6378                             break;
6379 
6380                         case 2:
6381                             my_dataset = dset3;
6382                             break;
6383 
6384                         default:
6385                             HDassert(0 && "Too many datasets!");
6386                     } /* end switch */
6387 
6388                     /* Create attributes, to push into dense form */
6389                     for(u = 0; u < (max_compact * 2); u++) {
6390                         /* Create attribute */
6391                         HDsprintf(attrname, "attr %02u", u);
6392                         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
6393                         CHECK(attr, FAIL, "H5Acreate2");
6394 
6395                         /* Write data into the attribute */
6396                         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
6397                         CHECK(ret, FAIL, "H5Awrite");
6398 
6399                         /* Close attribute */
6400                         ret = H5Aclose(attr);
6401                         CHECK(ret, FAIL, "H5Aclose");
6402 
6403                         /* Verify state of object */
6404                         if(u >= max_compact) {
6405                             is_dense = H5O_is_attr_dense_test(my_dataset);
6406                             VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
6407                         } /* end if */
6408 
6409                         /* Verify information for new attribute */
6410                         ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
6411                         CHECK(ret, FAIL, "attr_info_by_idx_check");
6412                     } /* end for */
6413                 } /* end for */
6414 
6415                 /* Work on all the datasets */
6416                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
6417                     switch(curr_dset) {
6418                         case 0:
6419                             my_dataset = dset1;
6420                             break;
6421 
6422                         case 1:
6423                             my_dataset = dset2;
6424                             break;
6425 
6426                         case 2:
6427                             my_dataset = dset3;
6428                             break;
6429 
6430                         default:
6431                             HDassert(0 && "Too many datasets!");
6432                     } /* end switch */
6433 
6434                     /* Delete every other attribute from dense storage, in appropriate order */
6435                     for(u = 0; u < max_compact; u++) {
6436                         /* Delete attribute */
6437                         ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT);
6438                         CHECK(ret, FAIL, "H5Adelete_by_idx");
6439 
6440                         /* Verify the attribute information for first attribute in appropriate order */
6441                         HDmemset(&ainfo, 0, sizeof(ainfo));
6442                         ret = H5Aget_info_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, &ainfo, H5P_DEFAULT);
6443                         if(new_format) {
6444                             if(order == H5_ITER_INC) {
6445                                 VERIFY(ainfo.corder, ((u * 2) + 1), "H5Aget_info_by_idx");
6446                             } /* end if */
6447                             else {
6448                                 VERIFY(ainfo.corder, ((max_compact * 2) - ((u * 2) + 2)), "H5Aget_info_by_idx");
6449                             } /* end else */
6450                         } /* end if */
6451 
6452                         /* Verify the name for first attribute in appropriate order */
6453                         HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
6454                         ret = (herr_t)H5Aget_name_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
6455                         if(order == H5_ITER_INC)
6456                             HDsprintf(attrname, "attr %02u", ((u * 2) + 1));
6457                         else
6458                             HDsprintf(attrname, "attr %02u", ((max_compact * 2) - ((u * 2) + 2)));
6459                         ret = HDstrcmp(attrname, tmpname);
6460                         VERIFY(ret, 0, "H5Aget_name_by_idx");
6461                     } /* end for */
6462                 } /* end for */
6463 
6464                 /* Work on all the datasets */
6465                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
6466                     switch(curr_dset) {
6467                         case 0:
6468                             my_dataset = dset1;
6469                             break;
6470 
6471                         case 1:
6472                             my_dataset = dset2;
6473                             break;
6474 
6475                         case 2:
6476                             my_dataset = dset3;
6477                             break;
6478 
6479                         default:
6480                             HDassert(0 && "Too many datasets!");
6481                     } /* end switch */
6482 
6483                     /* Delete remaining attributes from dense storage, in appropriate order */
6484                     for(u = 0; u < (max_compact - 1); u++) {
6485                         /* Delete attribute */
6486                         ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6487                         CHECK(ret, FAIL, "H5Adelete_by_idx");
6488 
6489                         /* Verify the attribute information for first attribute in appropriate order */
6490                         HDmemset(&ainfo, 0, sizeof(ainfo));
6491                         ret = H5Aget_info_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, &ainfo, H5P_DEFAULT);
6492                         if(new_format) {
6493                             if(order == H5_ITER_INC) {
6494                                 VERIFY(ainfo.corder, ((u * 2) + 3), "H5Aget_info_by_idx");
6495                             } /* end if */
6496                             else {
6497                                 VERIFY(ainfo.corder, ((max_compact * 2) - ((u * 2) + 4)), "H5Aget_info_by_idx");
6498                             } /* end else */
6499                         } /* end if */
6500 
6501                         /* Verify the name for first attribute in appropriate order */
6502                         HDmemset(tmpname, 0, (size_t)NAME_BUF_SIZE);
6503                         ret = (herr_t)H5Aget_name_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, tmpname, (size_t)NAME_BUF_SIZE, H5P_DEFAULT);
6504                         if(order == H5_ITER_INC)
6505                             HDsprintf(attrname, "attr %02u", ((u * 2) + 3));
6506                         else
6507                             HDsprintf(attrname, "attr %02u", ((max_compact * 2) - ((u * 2) + 4)));
6508                         ret = HDstrcmp(attrname, tmpname);
6509                         VERIFY(ret, 0, "H5Aget_name_by_idx");
6510                     } /* end for */
6511 
6512                     /* Delete last attribute */
6513                     ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6514                     CHECK(ret, FAIL, "H5Adelete_by_idx");
6515 
6516                     /* Verify state of attribute storage (empty) */
6517                     is_empty = H5O_is_attr_empty_test(my_dataset);
6518                     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
6519 
6520                     /* Check for deletion on empty attribute storage again */
6521                     ret = H5Adelete_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT);
6522                     VERIFY(ret, FAIL, "H5Adelete_by_idx");
6523                 } /* end for */
6524 
6525                 /* Close Datasets */
6526                 ret = H5Dclose(dset1);
6527                 CHECK(ret, FAIL, "H5Dclose");
6528                 ret = H5Dclose(dset2);
6529                 CHECK(ret, FAIL, "H5Dclose");
6530                 ret = H5Dclose(dset3);
6531                 CHECK(ret, FAIL, "H5Dclose");
6532 
6533                 /* Close file */
6534                 ret = H5Fclose(fid);
6535                 CHECK(ret, FAIL, "H5Fclose");
6536             } /* end for */
6537         } /* end for */
6538     } /* end for */
6539 
6540     /* Close property list */
6541     ret = H5Pclose(dcpl);
6542     CHECK(ret, FAIL, "H5Pclose");
6543 
6544     /* Close dataspace */
6545     ret = H5Sclose(sid);
6546     CHECK(ret, FAIL, "H5Sclose");
6547 }   /* test_attr_delete_by_idx() */
6548 
6549 
6550 /****************************************************************
6551 **
6552 **  attr_iterate2_cb(): Revised attribute operator
6553 **
6554 ****************************************************************/
6555 static herr_t
attr_iterate2_cb(hid_t loc_id,const char * attr_name,const H5A_info_t * info,void * _op_data)6556 attr_iterate2_cb(hid_t loc_id, const char *attr_name, const H5A_info_t *info,
6557     void *_op_data)
6558 {
6559     attr_iter_info_t *op_data = (attr_iter_info_t *)_op_data;   /* User data */
6560     char attrname[NAME_BUF_SIZE]; /* Object name */
6561     H5A_info_t my_info;         /* Local attribute info */
6562 
6563 #ifdef QAK
6564 HDfprintf(stderr, "attr_name = '%s'\n", attr_name);
6565 if(info)
6566     HDfprintf(stderr, "info->corder = %u\n", (unsigned)info->corder);
6567 HDfprintf(stderr, "op_data->curr = %Hd\n", op_data->curr);
6568 #endif /* QAK */
6569 
6570     /* Increment # of times the callback was called */
6571     op_data->ncalled++;
6572 
6573     /* Get the attribute information directly to compare */
6574     if(H5Aget_info_by_name(loc_id, ".", attr_name, &my_info, H5P_DEFAULT) < 0)
6575         return(H5_ITER_ERROR);
6576 
6577     /* Check more things for revised attribute iteration (vs. older attribute iteration) */
6578     if(info) {
6579         /* Check for correct order of iteration */
6580         /* (if we are operating in increasing or decreasing order) */
6581         if(op_data->order != H5_ITER_NATIVE)
6582             if(info->corder != op_data->curr)
6583                 return(H5_ITER_ERROR);
6584 
6585         /* Compare attribute info structs */
6586         if(info->corder_valid != my_info.corder_valid)
6587             return(H5_ITER_ERROR);
6588         if(info->corder != my_info.corder)
6589             return(H5_ITER_ERROR);
6590         if(info->cset != my_info.cset)
6591             return(H5_ITER_ERROR);
6592         if(info->data_size != my_info.data_size)
6593             return(H5_ITER_ERROR);
6594     } /* end if */
6595 
6596     /* Verify name of link */
6597     HDsprintf(attrname, "attr %02u", (unsigned)my_info.corder);
6598     if(HDstrcmp(attr_name, attrname))
6599         return(H5_ITER_ERROR);
6600 
6601     /* Check if we've visited this link before */
6602     if((size_t)op_data->curr >= op_data->max_visit)
6603         return(H5_ITER_ERROR);
6604     if(op_data->visited[op_data->curr])
6605         return(H5_ITER_ERROR);
6606     op_data->visited[op_data->curr] = TRUE;
6607 
6608     /* Advance to next value, in correct direction */
6609     if(op_data->order != H5_ITER_DEC)
6610         op_data->curr++;
6611     else
6612         op_data->curr--;
6613 
6614     /* Check for stopping in the middle of iterating */
6615     if(op_data->stop > 0)
6616         if(--op_data->stop == 0)
6617             return(CORDER_ITER_STOP);
6618 
6619     return(H5_ITER_CONT);
6620 } /* end attr_iterate2_cb() */
6621 
6622 #ifndef H5_NO_DEPRECATED_SYMBOLS
6623 
6624 /****************************************************************
6625 **
6626 **  attr_iterate1_cb(): Attribute operator
6627 **
6628 ****************************************************************/
6629 static herr_t
attr_iterate1_cb(hid_t loc_id,const char * attr_name,void * _op_data)6630 attr_iterate1_cb(hid_t loc_id, const char *attr_name, void *_op_data)
6631 {
6632     return(attr_iterate2_cb(loc_id, attr_name, NULL, _op_data));
6633 } /* end attr_iterate1_cb() */
6634 #endif /* H5_NO_DEPRECATED_SYMBOLS */
6635 
6636 
6637 /*-------------------------------------------------------------------------
6638  * Function:    attr_iterate2_fail_cb
6639  *
6640  * Purpose:     Callback routine for iterating over attributes on object that
6641  *              always returns failure
6642  *
6643  * Return:      Success:        0
6644  *              Failure:        -1
6645  *
6646  * Programmer:  Quincey Koziol
6647  *              Tuesday, February 20, 2007
6648  *
6649  *-------------------------------------------------------------------------
6650  */
6651 static int
attr_iterate2_fail_cb(hid_t H5_ATTR_UNUSED group_id,const char H5_ATTR_UNUSED * attr_name,const H5A_info_t H5_ATTR_UNUSED * info,void H5_ATTR_UNUSED * _op_data)6652 attr_iterate2_fail_cb(hid_t H5_ATTR_UNUSED group_id, const char H5_ATTR_UNUSED *attr_name,
6653     const H5A_info_t H5_ATTR_UNUSED *info, void H5_ATTR_UNUSED *_op_data)
6654 {
6655     return(H5_ITER_ERROR);
6656 } /* end attr_iterate2_fail_cb() */
6657 
6658 
6659 /*-------------------------------------------------------------------------
6660  * Function:    attr_iterate_check
6661  *
6662  * Purpose:     Check iteration over attributes on an object
6663  *
6664  * Return:      Success:        0
6665  *              Failure:        -1
6666  *
6667  * Programmer:  Quincey Koziol
6668  *              Tuesday, February 20, 2007
6669  *
6670  *-------------------------------------------------------------------------
6671  */
6672 static int
attr_iterate_check(hid_t fid,const char * dsetname,hid_t obj_id,H5_index_t idx_type,H5_iter_order_t order,unsigned max_attrs,attr_iter_info_t * iter_info)6673 attr_iterate_check(hid_t fid, const char *dsetname, hid_t obj_id,
6674     H5_index_t idx_type, H5_iter_order_t order, unsigned max_attrs,
6675     attr_iter_info_t *iter_info)
6676 {
6677     unsigned    v;              /* Local index variable */
6678     hsize_t     skip;           /* # of attributes to skip on object */
6679 #ifndef H5_NO_DEPRECATED_SYMBOLS
6680     unsigned    oskip;          /* # of attributes to skip on object, with H5Aiterate1 */
6681 #endif /* H5_NO_DEPRECATED_SYMBOLS */
6682     int         old_nerrs;      /* Number of errors when entering this check */
6683     herr_t      ret;            /* Generic return value */
6684 
6685     /* Retrieve the current # of reported errors */
6686     old_nerrs = GetTestNumErrs();
6687 
6688     /* Iterate over attributes on object */
6689     iter_info->nskipped = (unsigned)(skip = 0);
6690     iter_info->order = order;
6691     iter_info->stop = -1;
6692     iter_info->ncalled = 0;
6693     iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1);
6694     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6695     ret = H5Aiterate2(obj_id, idx_type, order, &skip, attr_iterate2_cb, iter_info);
6696     CHECK(ret, FAIL, "H5Aiterate2");
6697 
6698     /* Verify that we visited all the attributes */
6699     VERIFY(skip, max_attrs, "H5Aiterate2");
6700     for(v = 0; v < max_attrs; v++)
6701         VERIFY(iter_info->visited[v], TRUE, "H5Aiterate2");
6702 
6703 
6704     /* Iterate over attributes on object */
6705     iter_info->nskipped = (unsigned)(skip = 0);
6706     iter_info->order = order;
6707     iter_info->stop = -1;
6708     iter_info->ncalled = 0;
6709     iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1);
6710     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6711     ret = H5Aiterate_by_name(fid, dsetname, idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT);
6712     CHECK(ret, FAIL, "H5Aiterate_by_name");
6713 
6714     /* Verify that we visited all the attributes */
6715     VERIFY(skip, max_attrs, "H5Aiterate_by_name");
6716     for(v = 0; v < max_attrs; v++)
6717         VERIFY(iter_info->visited[v], TRUE, "H5Aiterate_by_name");
6718 
6719 
6720     /* Iterate over attributes on object */
6721     iter_info->nskipped = (unsigned)(skip = 0);
6722     iter_info->order = order;
6723     iter_info->stop = -1;
6724     iter_info->ncalled = 0;
6725     iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1);
6726     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6727     ret = H5Aiterate_by_name(obj_id, ".", idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT);
6728     CHECK(ret, FAIL, "H5Aiterate_by_name");
6729 
6730     /* Verify that we visited all the attributes */
6731     VERIFY(skip, max_attrs, "H5Aiterate_by_name");
6732     for(v = 0; v < max_attrs; v++)
6733         VERIFY(iter_info->visited[v], TRUE, "H5Aiterate_by_name");
6734 
6735 
6736 #ifndef H5_NO_DEPRECATED_SYMBOLS
6737     /* Iterate over attributes on object, with H5Aiterate1 */
6738     iter_info->nskipped = oskip = 0;
6739     iter_info->order = order;
6740     iter_info->stop = -1;
6741     iter_info->ncalled = 0;
6742     iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1);
6743     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6744     ret = H5Aiterate1(obj_id, &oskip, attr_iterate1_cb, iter_info);
6745     CHECK(ret, FAIL, "H5Aiterate1");
6746 
6747     /* Verify that we visited all the attributes */
6748     VERIFY(skip, max_attrs, "H5Aiterate1");
6749     for(v = 0; v < max_attrs; v++)
6750         VERIFY(iter_info->visited[v], TRUE, "H5Aiterate1");
6751 #endif /* H5_NO_DEPRECATED_SYMBOLS */
6752 
6753 
6754     /* Skip over some attributes on object */
6755     iter_info->nskipped = (unsigned)(skip = max_attrs / 2);
6756     iter_info->order = order;
6757     iter_info->stop = -1;
6758     iter_info->ncalled = 0;
6759     iter_info->curr = order != H5_ITER_DEC ? skip : ((max_attrs - 1) - skip);
6760     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6761     ret = H5Aiterate2(obj_id, idx_type, order, &skip, attr_iterate2_cb, iter_info);
6762     CHECK(ret, FAIL, "H5Aiterate2");
6763 
6764     /* Verify that we visited all the attributes */
6765     VERIFY(skip, max_attrs, "H5Aiterate2");
6766     if(order == H5_ITER_INC) {
6767         for(v = 0; v < (max_attrs / 2); v++)
6768             VERIFY(iter_info->visited[v + (max_attrs / 2)], TRUE, "H5Aiterate2");
6769     } /* end if */
6770     else if(order == H5_ITER_DEC) {
6771         for(v = 0; v < (max_attrs / 2); v++)
6772             VERIFY(iter_info->visited[v], TRUE, "H5Aiterate2");
6773     } /* end if */
6774     else {
6775         unsigned nvisit = 0;        /* # of links visited */
6776 
6777         HDassert(order == H5_ITER_NATIVE);
6778         for(v = 0; v < max_attrs; v++)
6779             if(iter_info->visited[v] == TRUE)
6780                 nvisit++;
6781 
6782         VERIFY(skip, (max_attrs / 2), "H5Aiterate2");
6783     } /* end else */
6784 
6785 
6786     /* Skip over some attributes on object */
6787     iter_info->nskipped = (unsigned)(skip = max_attrs / 2);
6788     iter_info->order = order;
6789     iter_info->stop = -1;
6790     iter_info->ncalled = 0;
6791     iter_info->curr = order != H5_ITER_DEC ? skip : ((max_attrs - 1) - skip);
6792     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6793     ret = H5Aiterate_by_name(fid, dsetname, idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT);
6794     CHECK(ret, FAIL, "H5Aiterate_by_name");
6795 
6796     /* Verify that we visited all the attributes */
6797     VERIFY(skip, max_attrs, "H5Aiterate_by_name");
6798     if(order == H5_ITER_INC) {
6799         for(v = 0; v < (max_attrs / 2); v++)
6800             VERIFY(iter_info->visited[v + (max_attrs / 2)], TRUE, "H5Aiterate_by_name");
6801     } /* end if */
6802     else if(order == H5_ITER_DEC) {
6803         for(v = 0; v < (max_attrs / 2); v++)
6804             VERIFY(iter_info->visited[v], TRUE, "H5Aiterate_by_name");
6805     } /* end if */
6806     else {
6807         unsigned nvisit = 0;        /* # of links visited */
6808 
6809         HDassert(order == H5_ITER_NATIVE);
6810         for(v = 0; v < max_attrs; v++)
6811             if(iter_info->visited[v] == TRUE)
6812                 nvisit++;
6813 
6814         VERIFY(skip, (max_attrs / 2), "H5Aiterate_by_name");
6815     } /* end else */
6816 
6817 
6818     /* Skip over some attributes on object */
6819     iter_info->nskipped = (unsigned)(skip = max_attrs / 2);
6820     iter_info->order = order;
6821     iter_info->stop = -1;
6822     iter_info->ncalled = 0;
6823     iter_info->curr = order != H5_ITER_DEC ? skip : ((max_attrs - 1) - skip);
6824     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6825     ret = H5Aiterate_by_name(obj_id, ".", idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT);
6826     CHECK(ret, FAIL, "H5Aiterate_by_name");
6827 
6828     /* Verify that we visited all the attributes */
6829     VERIFY(skip, max_attrs, "H5Aiterate_by_name");
6830     if(order == H5_ITER_INC) {
6831         for(v = 0; v < (max_attrs / 2); v++)
6832             VERIFY(iter_info->visited[v + (max_attrs / 2)], TRUE, "H5Aiterate_by_name");
6833     } /* end if */
6834     else if(order == H5_ITER_DEC) {
6835         for(v = 0; v < (max_attrs / 2); v++)
6836             VERIFY(iter_info->visited[v], TRUE, "H5Aiterate_by_name");
6837     } /* end if */
6838     else {
6839         unsigned nvisit = 0;        /* # of links visited */
6840 
6841         HDassert(order == H5_ITER_NATIVE);
6842         for(v = 0; v < max_attrs; v++)
6843             if(iter_info->visited[v] == TRUE)
6844                 nvisit++;
6845 
6846         VERIFY(skip, (max_attrs / 2), "H5Aiterate_by_name");
6847     } /* end else */
6848 
6849 
6850 #ifndef H5_NO_DEPRECATED_SYMBOLS
6851     /* Skip over some attributes on object, with H5Aiterate1 */
6852     iter_info->nskipped = oskip = max_attrs / 2;
6853     iter_info->order = order;
6854     iter_info->stop = -1;
6855     iter_info->ncalled = 0;
6856     iter_info->curr = order != H5_ITER_DEC ? (unsigned)oskip : ((max_attrs - 1) - oskip);
6857     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6858     ret = H5Aiterate1(obj_id, &oskip, attr_iterate1_cb, iter_info);
6859     CHECK(ret, FAIL, "H5Aiterate1");
6860 
6861     /* Verify that we visited all the links */
6862     VERIFY(oskip, max_attrs, "H5Aiterate1");
6863     if(order == H5_ITER_INC) {
6864         for(v = 0; v < (max_attrs / 2); v++)
6865             VERIFY(iter_info->visited[v + (max_attrs / 2)], TRUE, "H5Aiterate1");
6866     } /* end if */
6867     else if(order == H5_ITER_DEC) {
6868         for(v = 0; v < (max_attrs / 2); v++)
6869             VERIFY(iter_info->visited[v], TRUE, "H5Aiterate1");
6870     } /* end if */
6871     else {
6872         unsigned nvisit = 0;        /* # of links visited */
6873 
6874         HDassert(order == H5_ITER_NATIVE);
6875         for(v = 0; v < max_attrs; v++)
6876             if(iter_info->visited[v] == TRUE)
6877                 nvisit++;
6878 
6879         VERIFY(skip, (max_attrs / 2), "H5Aiterate1");
6880     } /* end else */
6881 #endif /* H5_NO_DEPRECATED_SYMBOLS */
6882 
6883 
6884     /* Iterate over attributes on object, stopping in the middle */
6885     iter_info->nskipped = (unsigned)(skip = 0);
6886     iter_info->order = order;
6887     iter_info->stop = 3;
6888     iter_info->ncalled = 0;
6889     iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1);
6890     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6891     ret = H5Aiterate2(obj_id, idx_type, order, &skip, attr_iterate2_cb, iter_info);
6892     CHECK(ret, FAIL, "H5Aiterate2");
6893     VERIFY(ret, CORDER_ITER_STOP, "H5Aiterate2");
6894     VERIFY(iter_info->ncalled, 3, "H5Aiterate2");
6895 
6896 
6897     /* Iterate over attributes on object, stopping in the middle */
6898     iter_info->nskipped = (unsigned)(skip = 0);
6899     iter_info->order = order;
6900     iter_info->stop = 3;
6901     iter_info->ncalled = 0;
6902     iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1);
6903     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6904     ret = H5Aiterate_by_name(fid, dsetname, idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT);
6905     CHECK(ret, FAIL, "H5Aiterate_by_name");
6906     VERIFY(ret, CORDER_ITER_STOP, "H5Aiterate_by_name");
6907     VERIFY(iter_info->ncalled, 3, "H5Aiterate_by_name");
6908 
6909 
6910     /* Iterate over attributes on object, stopping in the middle */
6911     iter_info->nskipped = (unsigned)(skip = 0);
6912     iter_info->order = order;
6913     iter_info->stop = 3;
6914     iter_info->ncalled = 0;
6915     iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1);
6916     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6917     ret = H5Aiterate_by_name(obj_id, ".", idx_type, order, &skip, attr_iterate2_cb, iter_info, H5P_DEFAULT);
6918     CHECK(ret, FAIL, "H5Aiterate_by_name");
6919     VERIFY(ret, CORDER_ITER_STOP, "H5Aiterate_by_name");
6920     VERIFY(iter_info->ncalled, 3, "H5Aiterate_by_name");
6921 
6922 
6923 #ifndef H5_NO_DEPRECATED_SYMBOLS
6924     /* Iterate over attributes on object, stopping in the middle, with H5Aiterate1() */
6925     iter_info->nskipped = oskip = 0;
6926     iter_info->order = order;
6927     iter_info->stop = 3;
6928     iter_info->ncalled = 0;
6929     iter_info->curr = order != H5_ITER_DEC ? 0 : (max_attrs - 1);
6930     HDmemset(iter_info->visited, 0, sizeof(hbool_t) * iter_info->max_visit);
6931     ret = H5Aiterate1(obj_id, &oskip, attr_iterate1_cb, iter_info);
6932     CHECK(ret, FAIL, "H5Aiterate1");
6933     VERIFY(ret, CORDER_ITER_STOP, "H5Aiterate1");
6934     VERIFY(iter_info->ncalled, 3, "H5Aiterate1");
6935 #endif /* H5_NO_DEPRECATED_SYMBOLS */
6936 
6937 
6938     /* Check for iteration routine indicating failure */
6939     skip = 0;
6940     ret = H5Aiterate2(obj_id, idx_type, order, &skip, attr_iterate2_fail_cb, NULL);
6941     VERIFY(ret, FAIL, "H5Aiterate2");
6942 
6943     skip = 0;
6944     ret = H5Aiterate_by_name(fid, dsetname, idx_type, order, &skip, attr_iterate2_fail_cb, NULL, H5P_DEFAULT);
6945     VERIFY(ret, FAIL, "H5Aiterate_by_name");
6946 
6947     skip = 0;
6948     ret = H5Aiterate_by_name(obj_id, ".", idx_type, order, &skip, attr_iterate2_fail_cb, NULL, H5P_DEFAULT);
6949     VERIFY(ret, FAIL, "H5Aiterate_by_name");
6950 
6951     /* Retrieve current # of errors */
6952     if(old_nerrs == GetTestNumErrs())
6953         return(0);
6954     else
6955         return(-1);
6956 } /* end attr_iterate_check() */
6957 
6958 
6959 /****************************************************************
6960 **
6961 **  test_attr_iterate2(): Test basic H5A (attribute) code.
6962 **      Tests iterating over attributes by index
6963 **
6964 ****************************************************************/
6965 static void
test_attr_iterate2(hbool_t new_format,hid_t fcpl,hid_t fapl)6966 test_attr_iterate2(hbool_t new_format, hid_t fcpl, hid_t fapl)
6967 {
6968     hid_t    fid;        /* HDF5 File ID            */
6969     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
6970     hid_t    my_dataset;    /* Current dataset ID        */
6971     hid_t    sid;            /* Dataspace ID            */
6972     hid_t    attr;            /* Attribute ID            */
6973     hid_t    dcpl;            /* Dataset creation property list ID */
6974     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
6975     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
6976     htri_t    is_empty;    /* Are there any attributes? */
6977     htri_t    is_dense;    /* Are attributes stored densely? */
6978     hsize_t     nattrs;         /* Number of attributes on object */
6979     hsize_t     name_count;     /* # of records in name index */
6980     hsize_t     corder_count;   /* # of records in creation order index */
6981     H5_index_t idx_type;        /* Type of index to operate on */
6982     H5_iter_order_t order;      /* Order within in the index */
6983     attr_iter_info_t iter_info; /* Iterator info */
6984     hbool_t     *visited = NULL;        /* Array of flags for visiting links */
6985     hsize_t     idx;            /* Start index for iteration */
6986     unsigned     use_index;     /* Use index on creation order values */
6987     const char *dsetname;       /* Name of dataset for attributes */
6988     char    attrname[NAME_BUF_SIZE];    /* Name of attribute */
6989     unsigned    curr_dset;      /* Current dataset to work on */
6990     unsigned    u;              /* Local index variable */
6991     herr_t    ret;        /* Generic return value        */
6992 
6993     /* Create dataspace for dataset & attributes */
6994     sid = H5Screate(H5S_SCALAR);
6995     CHECK(sid, FAIL, "H5Screate");
6996 
6997     /* Create dataset creation property list */
6998     if (dcpl_g == H5P_DEFAULT) {
6999         dcpl = H5Pcreate(H5P_DATASET_CREATE);
7000         CHECK(dcpl, FAIL, "H5Pcreate");
7001     } else {
7002         dcpl = H5Pcopy(dcpl_g);
7003         CHECK(dcpl, FAIL, "H5Pcopy");
7004     }
7005 
7006     /* Query the attribute creation properties */
7007     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
7008     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
7009 
7010     /* Allocate the "visited link" array */
7011     iter_info.max_visit = max_compact * 2;
7012     visited = (hbool_t*)HDmalloc(sizeof(hbool_t) * iter_info.max_visit);
7013     CHECK_PTR(visited, "HDmalloc");
7014     iter_info.visited = visited;
7015 
7016     /* Loop over operating on different indices on link fields */
7017     for(idx_type = H5_INDEX_NAME; idx_type <= H5_INDEX_CRT_ORDER; H5_INC_ENUM(H5_index_t, idx_type)) {
7018         /* Loop over operating in different orders */
7019         for(order = H5_ITER_INC; order <= H5_ITER_DEC; H5_INC_ENUM(H5_iter_order_t, order)) {
7020             /* Loop over using index for creation order value */
7021             for(use_index = FALSE; use_index <= TRUE; use_index++) {
7022                 /* Print appropriate test message */
7023                 if(idx_type == H5_INDEX_CRT_ORDER) {
7024                     if(order == H5_ITER_INC) {
7025                         if(use_index)
7026                             MESSAGE(5, ("Testing Iterating over Attributes By Creation Order Index in Increasing Order w/Creation Order Index\n"))
7027                         else
7028                             MESSAGE(5, ("Testing Iterating over Attributes By Creation Order Index in Increasing Order w/o Creation Order Index\n"))
7029                     } /* end if */
7030                     else {
7031                         if(use_index)
7032                             MESSAGE(5, ("Testing Iterating over Attributes By Creation Order Index in Decreasing Order w/Creation Order Index\n"))
7033                         else
7034                             MESSAGE(5, ("Testing Iterating over Attributes By Creation Order Index in Decreasing Order w/o Creation Order Index\n"))
7035                     } /* end else */
7036                 } /* end if */
7037                 else {
7038                     if(order == H5_ITER_INC) {
7039                         if(use_index)
7040                             MESSAGE(5, ("Testing Iterating over Attributes By Name Index in Increasing Order w/Creation Order Index\n"))
7041                         else
7042                             MESSAGE(5, ("Testing Iterating over Attributes By Name Index in Increasing Order w/o Creation Order Index\n"))
7043                     } /* end if */
7044                     else {
7045                         if(use_index)
7046                             MESSAGE(5, ("Testing Iterating over Attributes By Name Index in Decreasing Order w/Creation Order Index\n"))
7047                         else
7048                             MESSAGE(5, ("Testing Iterating over Attributes By Name Index in Decreasing Order w/o Creation Order Index\n"))
7049                     } /* end else */
7050                 } /* end else */
7051 
7052                 /* Create file */
7053                 fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
7054                 CHECK(fid, FAIL, "H5Fcreate");
7055 
7056                 /* Set attribute creation order tracking & indexing for object */
7057                 if(new_format == TRUE) {
7058                     ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
7059                     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
7060                 } /* end if */
7061 
7062                 /* Create datasets */
7063                 dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7064                 CHECK(dset1, FAIL, "H5Dcreate2");
7065                 dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7066                 CHECK(dset2, FAIL, "H5Dcreate2");
7067                 dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7068                 CHECK(dset3, FAIL, "H5Dcreate2");
7069 
7070                 /* Work on all the datasets */
7071                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
7072                     switch(curr_dset) {
7073                         case 0:
7074                             my_dataset = dset1;
7075                             dsetname = DSET1_NAME;
7076                             break;
7077 
7078                         case 1:
7079                             my_dataset = dset2;
7080                             dsetname = DSET2_NAME;
7081                             break;
7082 
7083                         case 2:
7084                             my_dataset = dset3;
7085                             dsetname = DSET3_NAME;
7086                             break;
7087 
7088                         default:
7089                             HDassert(0 && "Too many datasets!");
7090                     } /* end switch */
7091 
7092                     /* Check on dataset's attribute storage status */
7093                     is_empty = H5O_is_attr_empty_test(my_dataset);
7094                     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
7095                     is_dense = H5O_is_attr_dense_test(my_dataset);
7096                     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
7097 
7098                     /* Check for iterating over object with no attributes (should be OK) */
7099                     ret = H5Aiterate2(my_dataset, idx_type, order, NULL, attr_iterate2_cb, NULL);
7100                     CHECK(ret, FAIL, "H5Aiterate2");
7101 
7102                     ret = H5Aiterate_by_name(fid, dsetname, idx_type, order, NULL, attr_iterate2_cb, NULL, H5P_DEFAULT);
7103                     CHECK(ret, FAIL, "H5Aiterate_by_name");
7104 
7105                     ret = H5Aiterate_by_name(my_dataset, ".", idx_type, order, NULL, attr_iterate2_cb, NULL, H5P_DEFAULT);
7106                     CHECK(ret, FAIL, "H5Aiterate_by_name");
7107 
7108                     /* Create attributes, up to limit of compact form */
7109                     for(u = 0; u < max_compact; u++) {
7110                         /* Create attribute */
7111                         HDsprintf(attrname, "attr %02u", u);
7112                         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
7113                         CHECK(attr, FAIL, "H5Acreate2");
7114 
7115                         /* Write data into the attribute */
7116                         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
7117                         CHECK(ret, FAIL, "H5Awrite");
7118 
7119                         /* Close attribute */
7120                         ret = H5Aclose(attr);
7121                         CHECK(ret, FAIL, "H5Aclose");
7122 
7123                         /* Verify information for new attribute */
7124                         ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
7125                         CHECK(ret, FAIL, "attr_info_by_idx_check");
7126                     } /* end for */
7127 
7128                     /* Verify state of object */
7129                     ret = H5O_num_attrs_test(my_dataset, &nattrs);
7130                     CHECK(ret, FAIL, "H5O_num_attrs_test");
7131                     VERIFY(nattrs, max_compact, "H5O_num_attrs_test");
7132                     is_empty = H5O_is_attr_empty_test(my_dataset);
7133                     VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
7134                     is_dense = H5O_is_attr_dense_test(my_dataset);
7135                     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
7136 
7137                     /* Check for out of bound iteration */
7138                     idx = u;
7139                     ret = H5Aiterate2(my_dataset, idx_type, order, &idx, attr_iterate2_cb, NULL);
7140                     VERIFY(ret, FAIL, "H5Aiterate2");
7141 
7142                     idx = u;
7143                     ret = H5Aiterate_by_name(fid, dsetname, idx_type, order, &idx, attr_iterate2_cb, NULL, H5P_DEFAULT);
7144                     VERIFY(ret, FAIL, "H5Aiterate_by_name");
7145 
7146                     idx = u;
7147                     ret = H5Aiterate_by_name(my_dataset, ".", idx_type, order, &idx, attr_iterate2_cb, NULL, H5P_DEFAULT);
7148                     VERIFY(ret, FAIL, "H5Aiterate_by_name");
7149 
7150                     /* Test iteration over attributes stored compactly */
7151                     ret = attr_iterate_check(fid, dsetname, my_dataset, idx_type, order, u, &iter_info);
7152                     CHECK(ret, FAIL, "attr_iterate_check");
7153                 } /* end for */
7154 
7155 
7156                 /* Work on all the datasets */
7157                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
7158                     switch(curr_dset) {
7159                         case 0:
7160                             my_dataset = dset1;
7161                             dsetname = DSET1_NAME;
7162                             break;
7163 
7164                         case 1:
7165                             my_dataset = dset2;
7166                             dsetname = DSET2_NAME;
7167                             break;
7168 
7169                         case 2:
7170                             my_dataset = dset3;
7171                             dsetname = DSET3_NAME;
7172                             break;
7173 
7174                         default:
7175                             HDassert(0 && "Too many datasets!");
7176                     } /* end switch */
7177 
7178                     /* Create more attributes, to push into dense form */
7179                     for(u = max_compact; u < (max_compact * 2); u++) {
7180                         /* Create attribute */
7181                         HDsprintf(attrname, "attr %02u", u);
7182                         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
7183                         CHECK(attr, FAIL, "H5Acreate2");
7184 
7185                         /* Write data into the attribute */
7186                         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
7187                         CHECK(ret, FAIL, "H5Awrite");
7188 
7189                         /* Close attribute */
7190                         ret = H5Aclose(attr);
7191                         CHECK(ret, FAIL, "H5Aclose");
7192 
7193                         /* Verify state of object */
7194                         if(u >= max_compact) {
7195                             is_dense = H5O_is_attr_dense_test(my_dataset);
7196                             VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
7197                         } /* end if */
7198 
7199                         /* Verify information for new attribute */
7200                         ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
7201                         CHECK(ret, FAIL, "attr_info_by_idx_check");
7202                     } /* end for */
7203 
7204                     /* Verify state of object */
7205                     ret = H5O_num_attrs_test(my_dataset, &nattrs);
7206                     CHECK(ret, FAIL, "H5O_num_attrs_test");
7207                     VERIFY(nattrs, (max_compact * 2), "H5O_num_attrs_test");
7208                     is_empty = H5O_is_attr_empty_test(my_dataset);
7209                     VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
7210                     is_dense = H5O_is_attr_dense_test(my_dataset);
7211                     VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
7212 
7213                     if(new_format) {
7214                         /* Retrieve & verify # of records in the name & creation order indices */
7215                         ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
7216                         CHECK(ret, FAIL, "H5O_attr_dense_info_test");
7217                         if(use_index)
7218                             VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
7219                         VERIFY(name_count, (max_compact * 2), "H5O_attr_dense_info_test");
7220                     } /* end if */
7221 
7222                     /* Check for out of bound iteration */
7223                     idx = u;
7224                     ret = H5Aiterate2(my_dataset, idx_type, order, &idx, attr_iterate2_cb, NULL);
7225                     VERIFY(ret, FAIL, "H5Aiterate2");
7226 
7227                     idx = u;
7228                     ret = H5Aiterate_by_name(fid, dsetname, idx_type, order, &idx, attr_iterate2_cb, NULL, H5P_DEFAULT);
7229                     VERIFY(ret, FAIL, "H5Aiterate_by_name");
7230 
7231                     idx = u;
7232                     ret = H5Aiterate_by_name(my_dataset, ".", idx_type, order, &idx, attr_iterate2_cb, NULL, H5P_DEFAULT);
7233                     VERIFY(ret, FAIL, "H5Aiterate_by_name");
7234 
7235                     /* Test iteration over attributes stored densely */
7236                     ret = attr_iterate_check(fid, dsetname, my_dataset, idx_type, order, u, &iter_info);
7237                     CHECK(ret, FAIL, "attr_iterate_check");
7238                 } /* end for */
7239 
7240                 /* Close Datasets */
7241                 ret = H5Dclose(dset1);
7242                 CHECK(ret, FAIL, "H5Dclose");
7243                 ret = H5Dclose(dset2);
7244                 CHECK(ret, FAIL, "H5Dclose");
7245                 ret = H5Dclose(dset3);
7246                 CHECK(ret, FAIL, "H5Dclose");
7247 
7248                 /* Close file */
7249                 ret = H5Fclose(fid);
7250                 CHECK(ret, FAIL, "H5Fclose");
7251             } /* end for */
7252         } /* end for */
7253     } /* end for */
7254 
7255     /* Close property list */
7256     ret = H5Pclose(dcpl);
7257     CHECK(ret, FAIL, "H5Pclose");
7258 
7259     /* Close dataspace */
7260     ret = H5Sclose(sid);
7261     CHECK(ret, FAIL, "H5Sclose");
7262 
7263     /* Free the "visited link" array */
7264     HDfree(visited);
7265 }   /* test_attr_iterate2() */
7266 
7267 
7268 /*-------------------------------------------------------------------------
7269  * Function:    attr_open_by_idx_check
7270  *
7271  * Purpose:     Check opening attribute by index on an object
7272  *
7273  * Return:      Success:        0
7274  *              Failure:        -1
7275  *
7276  * Programmer:  Quincey Koziol
7277  *              Wednesday, February 21, 2007
7278  *
7279  *-------------------------------------------------------------------------
7280  */
7281 static int
attr_open_by_idx_check(hid_t obj_id,H5_index_t idx_type,H5_iter_order_t order,unsigned max_attrs)7282 attr_open_by_idx_check(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order,
7283     unsigned max_attrs)
7284 {
7285     hid_t       attr_id;        /* ID of attribute to test */
7286     H5A_info_t  ainfo;          /* Attribute info */
7287     int         old_nerrs;      /* Number of errors when entering this check */
7288     unsigned    u;              /* Local index variable */
7289     herr_t    ret;        /* Generic return value    */
7290 
7291     /* Retrieve the current # of reported errors */
7292     old_nerrs = GetTestNumErrs();
7293 
7294     /* Open each attribute on object by index and check that it's the correct one */
7295     for(u = 0; u < max_attrs; u++) {
7296         /* Open the attribute */
7297         attr_id = H5Aopen_by_idx(obj_id, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT);
7298         CHECK(attr_id, FAIL, "H5Aopen_by_idx");
7299 
7300         /* Get the attribute's information */
7301         ret = H5Aget_info(attr_id, &ainfo);
7302         CHECK(ret, FAIL, "H5Aget_info");
7303 
7304         /* Check that the object is the correct one */
7305         if(order == H5_ITER_INC) {
7306             VERIFY(ainfo.corder, u, "H5Aget_info");
7307         } /* end if */
7308         else if(order == H5_ITER_DEC) {
7309             VERIFY(ainfo.corder, (max_attrs - (u + 1)), "H5Aget_info");
7310         } /* end if */
7311         else {
7312             /* XXX: What to do about native order? */
7313         } /* end else */
7314 
7315         /* Close attribute */
7316         ret = H5Aclose(attr_id);
7317         CHECK(ret, FAIL, "H5Aclose");
7318     } /* end for */
7319 
7320     /* Retrieve current # of errors */
7321     if(old_nerrs == GetTestNumErrs())
7322         return(0);
7323     else
7324         return(-1);
7325 } /* end attr_open_by_idx_check() */
7326 
7327 
7328 /****************************************************************
7329 **
7330 **  test_attr_open_by_idx(): Test basic H5A (attribute) code.
7331 **      Tests opening attributes by index
7332 **
7333 ****************************************************************/
7334 static void
test_attr_open_by_idx(hbool_t new_format,hid_t fcpl,hid_t fapl)7335 test_attr_open_by_idx(hbool_t new_format, hid_t fcpl, hid_t fapl)
7336 {
7337     hid_t    fid;        /* HDF5 File ID            */
7338     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
7339     hid_t    my_dataset;    /* Current dataset ID        */
7340     hid_t    sid;            /* Dataspace ID            */
7341     hid_t    attr;            /* Attribute ID            */
7342     hid_t    dcpl;            /* Dataset creation property list ID */
7343     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
7344     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
7345     htri_t    is_empty;    /* Are there any attributes? */
7346     htri_t    is_dense;    /* Are attributes stored densely? */
7347     hsize_t     nattrs;         /* Number of attributes on object */
7348     hsize_t     name_count;     /* # of records in name index */
7349     hsize_t     corder_count;   /* # of records in creation order index */
7350     H5_index_t idx_type;        /* Type of index to operate on */
7351     H5_iter_order_t order;      /* Order within in the index */
7352     unsigned     use_index;     /* Use index on creation order values */
7353     char    attrname[NAME_BUF_SIZE];    /* Name of attribute */
7354     unsigned    curr_dset;      /* Current dataset to work on */
7355     unsigned    u;              /* Local index variable */
7356     hid_t    ret_id;        /* Generic hid_t return value    */
7357     herr_t    ret;        /* Generic return value        */
7358 
7359     /* Create dataspace for dataset & attributes */
7360     sid = H5Screate(H5S_SCALAR);
7361     CHECK(sid, FAIL, "H5Screate");
7362 
7363     /* Create dataset creation property list */
7364     if (dcpl_g == H5P_DEFAULT) {
7365         dcpl = H5Pcreate(H5P_DATASET_CREATE);
7366         CHECK(dcpl, FAIL, "H5Pcreate");
7367     } else {
7368         dcpl = H5Pcopy(dcpl_g);
7369         CHECK(dcpl, FAIL, "H5Pcopy");
7370     }
7371 
7372     /* Query the attribute creation properties */
7373     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
7374     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
7375 
7376     /* Loop over operating on different indices on link fields */
7377     for(idx_type = H5_INDEX_NAME; idx_type <= H5_INDEX_CRT_ORDER; H5_INC_ENUM(H5_index_t, idx_type)) {
7378         /* Loop over operating in different orders */
7379         for(order = H5_ITER_INC; order <= H5_ITER_DEC; H5_INC_ENUM(H5_iter_order_t, order)) {
7380             /* Loop over using index for creation order value */
7381             for(use_index = FALSE; use_index <= TRUE; use_index++) {
7382                 /* Print appropriate test message */
7383                 if(idx_type == H5_INDEX_CRT_ORDER) {
7384                     if(order == H5_ITER_INC) {
7385                         if(use_index)
7386                             MESSAGE(5, ("Testing Opening Attributes By Creation Order Index in Increasing Order w/Creation Order Index\n"))
7387                         else
7388                             MESSAGE(5, ("Testing Opening Attributes By Creation Order Index in Increasing Order w/o Creation Order Index\n"))
7389                     } /* end if */
7390                     else {
7391                         if(use_index)
7392                             MESSAGE(5, ("Testing Opening Attributes By Creation Order Index in Decreasing Order w/Creation Order Index\n"))
7393                         else
7394                             MESSAGE(5, ("Testing Opening Attributes By Creation Order Index in Decreasing Order w/o Creation Order Index\n"))
7395                     } /* end else */
7396                 } /* end if */
7397                 else {
7398                     if(order == H5_ITER_INC) {
7399                         if(use_index)
7400                             MESSAGE(5, ("Testing Opening Attributes By Name Index in Increasing Order w/Creation Order Index\n"))
7401                         else
7402                             MESSAGE(5, ("Testing Opening Attributes By Name Index in Increasing Order w/o Creation Order Index\n"))
7403                     } /* end if */
7404                     else {
7405                         if(use_index)
7406                             MESSAGE(5, ("Testing Opening Attributes By Name Index in Decreasing Order w/Creation Order Index\n"))
7407                         else
7408                             MESSAGE(5, ("Testing Opening Attributes By Name Index in Decreasing Order w/o Creation Order Index\n"))
7409                     } /* end else */
7410                 } /* end else */
7411 
7412                 /* Create file */
7413                 fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
7414                 CHECK(fid, FAIL, "H5Fcreate");
7415 
7416                 /* Set attribute creation order tracking & indexing for object */
7417                 if(new_format == TRUE) {
7418                     ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
7419                     CHECK(ret, FAIL, "H5Pset_attr_creation_order");
7420                 } /* end if */
7421 
7422                 /* Create datasets */
7423                 dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7424                 CHECK(dset1, FAIL, "H5Dcreate2");
7425                 dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7426                 CHECK(dset2, FAIL, "H5Dcreate2");
7427                 dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7428                 CHECK(dset3, FAIL, "H5Dcreate2");
7429 
7430                 /* Work on all the datasets */
7431                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
7432                     switch(curr_dset) {
7433                         case 0:
7434                             my_dataset = dset1;
7435                             break;
7436 
7437                         case 1:
7438                             my_dataset = dset2;
7439                             break;
7440 
7441                         case 2:
7442                             my_dataset = dset3;
7443                             break;
7444 
7445                         default:
7446                             HDassert(0 && "Too many datasets!");
7447                     } /* end switch */
7448 
7449                     /* Check on dataset's attribute storage status */
7450                     is_empty = H5O_is_attr_empty_test(my_dataset);
7451                     VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
7452                     is_dense = H5O_is_attr_dense_test(my_dataset);
7453                     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
7454 
7455                     /* Check for opening an attribute on an object with no attributes */
7456                     ret_id = H5Aopen_by_idx(my_dataset, ".", idx_type, order, (hsize_t)0, H5P_DEFAULT, H5P_DEFAULT);
7457                     VERIFY(ret_id, FAIL, "H5Aopen_by_idx");
7458 
7459                     /* Create attributes, up to limit of compact form */
7460                     for(u = 0; u < max_compact; u++) {
7461                         /* Create attribute */
7462                         HDsprintf(attrname, "attr %02u", u);
7463                         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
7464                         CHECK(attr, FAIL, "H5Acreate2");
7465 
7466                         /* Write data into the attribute */
7467                         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
7468                         CHECK(ret, FAIL, "H5Awrite");
7469 
7470                         /* Close attribute */
7471                         ret = H5Aclose(attr);
7472                         CHECK(ret, FAIL, "H5Aclose");
7473 
7474                         /* Verify information for new attribute */
7475                         ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
7476                         CHECK(ret, FAIL, "attr_info_by_idx_check");
7477                     } /* end for */
7478 
7479                     /* Verify state of object */
7480                     ret = H5O_num_attrs_test(my_dataset, &nattrs);
7481                     CHECK(ret, FAIL, "H5O_num_attrs_test");
7482                     VERIFY(nattrs, max_compact, "H5O_num_attrs_test");
7483                     is_empty = H5O_is_attr_empty_test(my_dataset);
7484                     VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
7485                     is_dense = H5O_is_attr_dense_test(my_dataset);
7486                     VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
7487 
7488                     /* Check for out of bound opening an attribute on an object */
7489                     ret_id = H5Aopen_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT);
7490                     VERIFY(ret_id, FAIL, "H5Aopen_by_idx");
7491 
7492                     /* Test opening attributes by index stored compactly */
7493                     ret = attr_open_by_idx_check(my_dataset, idx_type, order, u);
7494                     CHECK(ret, FAIL, "attr_open_by_idx_check");
7495                 } /* end for */
7496 
7497 
7498                 /* Work on all the datasets */
7499                 for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
7500                     switch(curr_dset) {
7501                         case 0:
7502                             my_dataset = dset1;
7503                             break;
7504 
7505                         case 1:
7506                             my_dataset = dset2;
7507                             break;
7508 
7509                         case 2:
7510                             my_dataset = dset3;
7511                             break;
7512 
7513                         default:
7514                             HDassert(0 && "Too many datasets!");
7515                     } /* end switch */
7516 
7517                     /* Create more attributes, to push into dense form */
7518                     for(u = max_compact; u < (max_compact * 2); u++) {
7519                         /* Create attribute */
7520                         HDsprintf(attrname, "attr %02u", u);
7521                         attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
7522                         CHECK(attr, FAIL, "H5Acreate2");
7523 
7524                         /* Write data into the attribute */
7525                         ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
7526                         CHECK(ret, FAIL, "H5Awrite");
7527 
7528                         /* Close attribute */
7529                         ret = H5Aclose(attr);
7530                         CHECK(ret, FAIL, "H5Aclose");
7531 
7532                         /* Verify state of object */
7533                         if(u >= max_compact) {
7534                             is_dense = H5O_is_attr_dense_test(my_dataset);
7535                             VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
7536                         } /* end if */
7537 
7538                         /* Verify information for new attribute */
7539                         ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
7540                         CHECK(ret, FAIL, "attr_info_by_idx_check");
7541                     } /* end for */
7542 
7543                     /* Verify state of object */
7544                     ret = H5O_num_attrs_test(my_dataset, &nattrs);
7545                     CHECK(ret, FAIL, "H5O_num_attrs_test");
7546                     VERIFY(nattrs, (max_compact * 2), "H5O_num_attrs_test");
7547                     is_empty = H5O_is_attr_empty_test(my_dataset);
7548                     VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
7549                     is_dense = H5O_is_attr_dense_test(my_dataset);
7550                     VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
7551 
7552                     if(new_format) {
7553                         /* Retrieve & verify # of records in the name & creation order indices */
7554                         ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
7555                         CHECK(ret, FAIL, "H5O_attr_dense_info_test");
7556                         if(use_index)
7557                             VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
7558                         VERIFY(name_count, (max_compact * 2), "H5O_attr_dense_info_test");
7559                     } /* end if */
7560 
7561                     /* Check for out of bound opening an attribute on an object */
7562                     ret_id = H5Aopen_by_idx(my_dataset, ".", idx_type, order, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT);
7563                     VERIFY(ret_id, FAIL, "H5Aopen_by_idx");
7564 
7565                     /* Test opening attributes by index stored compactly */
7566                     ret = attr_open_by_idx_check(my_dataset, idx_type, order, u);
7567                     CHECK(ret, FAIL, "attr_open_by_idx_check");
7568                 } /* end for */
7569 
7570                 /* Close Datasets */
7571                 ret = H5Dclose(dset1);
7572                 CHECK(ret, FAIL, "H5Dclose");
7573                 ret = H5Dclose(dset2);
7574                 CHECK(ret, FAIL, "H5Dclose");
7575                 ret = H5Dclose(dset3);
7576                 CHECK(ret, FAIL, "H5Dclose");
7577 
7578                 /* Close file */
7579                 ret = H5Fclose(fid);
7580                 CHECK(ret, FAIL, "H5Fclose");
7581             } /* end for */
7582         } /* end for */
7583     } /* end for */
7584 
7585     /* Close property list */
7586     ret = H5Pclose(dcpl);
7587     CHECK(ret, FAIL, "H5Pclose");
7588 
7589     /* Close dataspace */
7590     ret = H5Sclose(sid);
7591     CHECK(ret, FAIL, "H5Sclose");
7592 }   /* test_attr_open_by_idx() */
7593 
7594 
7595 /*-------------------------------------------------------------------------
7596  * Function:    attr_open_check
7597  *
7598  * Purpose:     Check opening attribute on an object
7599  *
7600  * Return:      Success:        0
7601  *              Failure:        -1
7602  *
7603  * Programmer:  Quincey Koziol
7604  *              Wednesday, February 21, 2007
7605  *
7606  *-------------------------------------------------------------------------
7607  */
7608 static int
attr_open_check(hid_t fid,const char * dsetname,hid_t obj_id,unsigned max_attrs)7609 attr_open_check(hid_t fid, const char *dsetname, hid_t obj_id,
7610     unsigned max_attrs)
7611 {
7612     hid_t       attr_id;        /* ID of attribute to test */
7613     H5A_info_t  ainfo;          /* Attribute info */
7614     char    attrname[NAME_BUF_SIZE];    /* Name of attribute */
7615     int         old_nerrs;      /* Number of errors when entering this check */
7616     unsigned    u;              /* Local index variable */
7617     herr_t    ret;        /* Generic return value    */
7618 
7619     /* Retrieve the current # of reported errors */
7620     old_nerrs = GetTestNumErrs();
7621 
7622     /* Open each attribute on object by index and check that it's the correct one */
7623     for(u = 0; u < max_attrs; u++) {
7624         /* Open the attribute */
7625         HDsprintf(attrname, "attr %02u", u);
7626         attr_id = H5Aopen(obj_id, attrname, H5P_DEFAULT);
7627         CHECK(attr_id, FAIL, "H5Aopen");
7628 
7629         /* Get the attribute's information */
7630         ret = H5Aget_info(attr_id, &ainfo);
7631         CHECK(ret, FAIL, "H5Aget_info");
7632 
7633         /* Check that the object is the correct one */
7634         VERIFY(ainfo.corder, u, "H5Aget_info");
7635 
7636         /* Close attribute */
7637         ret = H5Aclose(attr_id);
7638         CHECK(ret, FAIL, "H5Aclose");
7639 
7640 
7641         /* Open the attribute */
7642         attr_id = H5Aopen_by_name(obj_id, ".", attrname, H5P_DEFAULT, H5P_DEFAULT);
7643         CHECK(attr_id, FAIL, "H5Aopen_by_name");
7644 
7645         /* Get the attribute's information */
7646         ret = H5Aget_info(attr_id, &ainfo);
7647         CHECK(ret, FAIL, "H5Aget_info");
7648 
7649         /* Check that the object is the correct one */
7650         VERIFY(ainfo.corder, u, "H5Aget_info");
7651 
7652         /* Close attribute */
7653         ret = H5Aclose(attr_id);
7654         CHECK(ret, FAIL, "H5Aclose");
7655 
7656 
7657         /* Open the attribute */
7658         attr_id = H5Aopen_by_name(fid, dsetname, attrname, H5P_DEFAULT, H5P_DEFAULT);
7659         CHECK(attr_id, FAIL, "H5Aopen_by_name");
7660 
7661         /* Get the attribute's information */
7662         ret = H5Aget_info(attr_id, &ainfo);
7663         CHECK(ret, FAIL, "H5Aget_info");
7664 
7665         /* Check that the object is the correct one */
7666         VERIFY(ainfo.corder, u, "H5Aget_info");
7667 
7668         /* Close attribute */
7669         ret = H5Aclose(attr_id);
7670         CHECK(ret, FAIL, "H5Aclose");
7671     } /* end for */
7672 
7673     /* Retrieve current # of errors */
7674     if(old_nerrs == GetTestNumErrs())
7675         return(0);
7676     else
7677         return(-1);
7678 } /* end attr_open_check() */
7679 
7680 
7681 /****************************************************************
7682 **
7683 **  test_attr_open_by_name(): Test basic H5A (attribute) code.
7684 **      Tests opening attributes by name
7685 **
7686 ****************************************************************/
7687 static void
test_attr_open_by_name(hbool_t new_format,hid_t fcpl,hid_t fapl)7688 test_attr_open_by_name(hbool_t new_format, hid_t fcpl, hid_t fapl)
7689 {
7690     hid_t    fid;        /* HDF5 File ID            */
7691     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
7692     hid_t    my_dataset;    /* Current dataset ID        */
7693     hid_t    sid;            /* Dataspace ID            */
7694     hid_t    attr;            /* Attribute ID            */
7695     hid_t    dcpl;            /* Dataset creation property list ID */
7696     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
7697     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
7698     htri_t    is_empty;    /* Are there any attributes? */
7699     htri_t    is_dense;    /* Are attributes stored densely? */
7700     hsize_t     nattrs;         /* Number of attributes on object */
7701     hsize_t     name_count;     /* # of records in name index */
7702     hsize_t     corder_count;   /* # of records in creation order index */
7703     unsigned    use_index;      /* Use index on creation order values */
7704     const char *dsetname;       /* Name of dataset for attributes */
7705     char    attrname[NAME_BUF_SIZE];    /* Name of attribute */
7706     unsigned    curr_dset;      /* Current dataset to work on */
7707     unsigned    u;              /* Local index variable */
7708     hid_t    ret_id;        /* Generic hid_t return value    */
7709     herr_t    ret;        /* Generic return value        */
7710 
7711     /* Create dataspace for dataset & attributes */
7712     sid = H5Screate(H5S_SCALAR);
7713     CHECK(sid, FAIL, "H5Screate");
7714 
7715     /* Create dataset creation property list */
7716     if (dcpl_g == H5P_DEFAULT) {
7717         dcpl = H5Pcreate(H5P_DATASET_CREATE);
7718         CHECK(dcpl, FAIL, "H5Pcreate");
7719     } else {
7720         dcpl = H5Pcopy(dcpl_g);
7721         CHECK(dcpl, FAIL, "H5Pcopy");
7722     }
7723 
7724     /* Query the attribute creation properties */
7725     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
7726     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
7727 
7728     /* Loop over using index for creation order value */
7729     for(use_index = FALSE; use_index <= TRUE; use_index++) {
7730         /* Print appropriate test message */
7731         if(use_index)
7732             MESSAGE(5, ("Testing Opening Attributes By Name w/Creation Order Index\n"))
7733         else
7734             MESSAGE(5, ("Testing Opening Attributes By Name w/o Creation Order Index\n"))
7735 
7736         /* Create file */
7737         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
7738         CHECK(fid, FAIL, "H5Fcreate");
7739 
7740         /* Set attribute creation order tracking & indexing for object */
7741         if(new_format == TRUE) {
7742             ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
7743             CHECK(ret, FAIL, "H5Pset_attr_creation_order");
7744         } /* end if */
7745 
7746         /* Create datasets */
7747         dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7748         CHECK(dset1, FAIL, "H5Dcreate2");
7749         dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7750         CHECK(dset2, FAIL, "H5Dcreate2");
7751         dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
7752         CHECK(dset3, FAIL, "H5Dcreate2");
7753 
7754         /* Work on all the datasets */
7755         for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
7756             switch(curr_dset) {
7757                 case 0:
7758                     my_dataset = dset1;
7759                     dsetname = DSET1_NAME;
7760                     break;
7761 
7762                 case 1:
7763                     my_dataset = dset2;
7764                     dsetname = DSET2_NAME;
7765                     break;
7766 
7767                 case 2:
7768                     my_dataset = dset3;
7769                     dsetname = DSET3_NAME;
7770                     break;
7771 
7772                 default:
7773                     HDassert(0 && "Too many datasets!");
7774             } /* end switch */
7775 
7776             /* Check on dataset's attribute storage status */
7777             is_empty = H5O_is_attr_empty_test(my_dataset);
7778             VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
7779             is_dense = H5O_is_attr_dense_test(my_dataset);
7780             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
7781 
7782             /* Check for opening a non-existant attribute on an object with no attributes */
7783             ret_id = H5Aopen(my_dataset, "foo", H5P_DEFAULT);
7784             VERIFY(ret_id, FAIL, "H5Aopen");
7785 
7786             ret_id = H5Aopen_by_name(my_dataset, ".", "foo", H5P_DEFAULT, H5P_DEFAULT);
7787             VERIFY(ret_id, FAIL, "H5Aopen_by_name");
7788 
7789             ret_id = H5Aopen_by_name(fid, dsetname, "foo", H5P_DEFAULT, H5P_DEFAULT);
7790             VERIFY(ret_id, FAIL, "H5Aopen_by_name");
7791 
7792             /* Create attributes, up to limit of compact form */
7793             for(u = 0; u < max_compact; u++) {
7794                 /* Create attribute */
7795                 HDsprintf(attrname, "attr %02u", u);
7796                 attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
7797                 CHECK(attr, FAIL, "H5Acreate2");
7798 
7799                 /* Write data into the attribute */
7800                 ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
7801                 CHECK(ret, FAIL, "H5Awrite");
7802 
7803                 /* Close attribute */
7804                 ret = H5Aclose(attr);
7805                 CHECK(ret, FAIL, "H5Aclose");
7806 
7807                 /* Verify information for new attribute */
7808                 ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
7809                 CHECK(ret, FAIL, "attr_info_by_idx_check");
7810             } /* end for */
7811 
7812             /* Verify state of object */
7813             ret = H5O_num_attrs_test(my_dataset, &nattrs);
7814             CHECK(ret, FAIL, "H5O_num_attrs_test");
7815             VERIFY(nattrs, max_compact, "H5O_num_attrs_test");
7816             is_empty = H5O_is_attr_empty_test(my_dataset);
7817             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
7818             is_dense = H5O_is_attr_dense_test(my_dataset);
7819             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
7820 
7821             /* Check for opening a non-existant attribute on an object with compact attribute storage */
7822             ret_id = H5Aopen(my_dataset, "foo", H5P_DEFAULT);
7823             VERIFY(ret_id, FAIL, "H5Aopen");
7824 
7825             ret_id = H5Aopen_by_name(my_dataset, ".", "foo", H5P_DEFAULT, H5P_DEFAULT);
7826             VERIFY(ret_id, FAIL, "H5Aopen_by_name");
7827 
7828             ret_id = H5Aopen_by_name(fid, dsetname, "foo", H5P_DEFAULT, H5P_DEFAULT);
7829             VERIFY(ret_id, FAIL, "H5Aopen_by_name");
7830 
7831             /* Test opening attributes stored compactly */
7832             ret = attr_open_check(fid, dsetname, my_dataset, u);
7833             CHECK(ret, FAIL, "attr_open_check");
7834         } /* end for */
7835 
7836 
7837         /* Work on all the datasets */
7838         for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
7839             switch(curr_dset) {
7840                 case 0:
7841                     my_dataset = dset1;
7842                     dsetname = DSET1_NAME;
7843                     break;
7844 
7845                 case 1:
7846                     my_dataset = dset2;
7847                     dsetname = DSET2_NAME;
7848                     break;
7849 
7850                 case 2:
7851                     my_dataset = dset3;
7852                     dsetname = DSET3_NAME;
7853                     break;
7854 
7855                 default:
7856                     HDassert(0 && "Too many datasets!");
7857             } /* end switch */
7858 
7859             /* Create more attributes, to push into dense form */
7860             for(u = max_compact; u < (max_compact * 2); u++) {
7861                 /* Create attribute */
7862                 HDsprintf(attrname, "attr %02u", u);
7863                 attr = H5Acreate2(my_dataset, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
7864                 CHECK(attr, FAIL, "H5Acreate2");
7865 
7866                 /* Write data into the attribute */
7867                 ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
7868                 CHECK(ret, FAIL, "H5Awrite");
7869 
7870                 /* Close attribute */
7871                 ret = H5Aclose(attr);
7872                 CHECK(ret, FAIL, "H5Aclose");
7873 
7874                 /* Verify state of object */
7875                 if(u >= max_compact) {
7876                     is_dense = H5O_is_attr_dense_test(my_dataset);
7877                     VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
7878                 } /* end if */
7879 
7880                 /* Verify information for new attribute */
7881                 ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
7882                 CHECK(ret, FAIL, "attr_info_by_idx_check");
7883             } /* end for */
7884 
7885             /* Verify state of object */
7886             ret = H5O_num_attrs_test(my_dataset, &nattrs);
7887             CHECK(ret, FAIL, "H5O_num_attrs_test");
7888             VERIFY(nattrs, (max_compact * 2), "H5O_num_attrs_test");
7889             is_empty = H5O_is_attr_empty_test(my_dataset);
7890             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
7891             is_dense = H5O_is_attr_dense_test(my_dataset);
7892             VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
7893 
7894             if(new_format) {
7895                 /* Retrieve & verify # of records in the name & creation order indices */
7896                 ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
7897                 CHECK(ret, FAIL, "H5O_attr_dense_info_test");
7898                 if(use_index)
7899                     VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
7900                 VERIFY(name_count, (max_compact * 2), "H5O_attr_dense_info_test");
7901             } /* end if */
7902 
7903             /* Check for opening a non-existant attribute on an object with dense attribute storage */
7904             ret_id = H5Aopen(my_dataset, "foo", H5P_DEFAULT);
7905             VERIFY(ret_id, FAIL, "H5Aopen");
7906 
7907             ret_id = H5Aopen_by_name(my_dataset, ".", "foo", H5P_DEFAULT, H5P_DEFAULT);
7908             VERIFY(ret_id, FAIL, "H5Aopen_by_name");
7909 
7910             ret_id = H5Aopen_by_name(fid, dsetname, "foo", H5P_DEFAULT, H5P_DEFAULT);
7911             VERIFY(ret_id, FAIL, "H5Aopen_by_name");
7912 
7913             /* Test opening attributes stored compactly */
7914             ret = attr_open_check(fid, dsetname, my_dataset, u);
7915             CHECK(ret, FAIL, "attr_open_check");
7916         } /* end for */
7917 
7918         /* Close Datasets */
7919         ret = H5Dclose(dset1);
7920         CHECK(ret, FAIL, "H5Dclose");
7921         ret = H5Dclose(dset2);
7922         CHECK(ret, FAIL, "H5Dclose");
7923         ret = H5Dclose(dset3);
7924         CHECK(ret, FAIL, "H5Dclose");
7925 
7926         /* Close file */
7927         ret = H5Fclose(fid);
7928         CHECK(ret, FAIL, "H5Fclose");
7929     } /* end for */
7930 
7931     /* Close property list */
7932     ret = H5Pclose(dcpl);
7933     CHECK(ret, FAIL, "H5Pclose");
7934 
7935     /* Close dataspace */
7936     ret = H5Sclose(sid);
7937     CHECK(ret, FAIL, "H5Sclose");
7938 }   /* test_attr_open_by_name() */
7939 
7940 
7941 /****************************************************************
7942 **
7943 **  test_attr_create_by_name(): Test basic H5A (attribute) code.
7944 **      Tests creating attributes by name
7945 **
7946 ****************************************************************/
7947 static void
test_attr_create_by_name(hbool_t new_format,hid_t fcpl,hid_t fapl)7948 test_attr_create_by_name(hbool_t new_format, hid_t fcpl, hid_t fapl)
7949 {
7950     hid_t    fid;        /* HDF5 File ID            */
7951     hid_t    dset1, dset2, dset3;    /* Dataset IDs            */
7952     hid_t    my_dataset;    /* Current dataset ID        */
7953     hid_t    sid;            /* Dataspace ID            */
7954     hid_t    attr;            /* Attribute ID            */
7955     hid_t    dcpl;            /* Dataset creation property list ID */
7956     unsigned    max_compact;    /* Maximum # of links to store in group compactly */
7957     unsigned    min_dense;      /* Minimum # of links to store in group "densely" */
7958     htri_t    is_empty;    /* Are there any attributes? */
7959     htri_t    is_dense;    /* Are attributes stored densely? */
7960     hsize_t     nattrs;         /* Number of attributes on object */
7961     hsize_t     name_count;     /* # of records in name index */
7962     hsize_t     corder_count;   /* # of records in creation order index */
7963     unsigned    use_index;      /* Use index on creation order values */
7964     const char *dsetname;       /* Name of dataset for attributes */
7965     char    attrname[NAME_BUF_SIZE];    /* Name of attribute */
7966     unsigned    curr_dset;      /* Current dataset to work on */
7967     unsigned    u;              /* Local index variable */
7968     herr_t    ret;        /* Generic return value        */
7969 
7970     /* Create dataspace for dataset & attributes */
7971     sid = H5Screate(H5S_SCALAR);
7972     CHECK(sid, FAIL, "H5Screate");
7973 
7974     /* Create dataset creation property list */
7975     if (dcpl_g == H5P_DEFAULT) {
7976         dcpl = H5Pcreate(H5P_DATASET_CREATE);
7977         CHECK(dcpl, FAIL, "H5Pcreate");
7978     } else {
7979         dcpl = H5Pcopy(dcpl_g);
7980         CHECK(dcpl, FAIL, "H5Pcopy");
7981     }
7982 
7983     /* Query the attribute creation properties */
7984     ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
7985     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
7986 
7987     /* Loop over using index for creation order value */
7988     for(use_index = FALSE; use_index <= TRUE; use_index++) {
7989         /* Print appropriate test message */
7990         if(use_index)
7991             MESSAGE(5, ("Testing Creating Attributes By Name w/Creation Order Index\n"))
7992         else
7993             MESSAGE(5, ("Testing Creating Attributes By Name w/o Creation Order Index\n"))
7994 
7995         /* Create file */
7996         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
7997         CHECK(fid, FAIL, "H5Fcreate");
7998 
7999         /* Set attribute creation order tracking & indexing for object */
8000         if(new_format == TRUE) {
8001             ret = H5Pset_attr_creation_order(dcpl, (H5P_CRT_ORDER_TRACKED | (use_index ? H5P_CRT_ORDER_INDEXED : (unsigned)0)));
8002             CHECK(ret, FAIL, "H5Pset_attr_creation_order");
8003         } /* end if */
8004 
8005         /* Create datasets */
8006         dset1 = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
8007         CHECK(dset1, FAIL, "H5Dcreate2");
8008         dset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
8009         CHECK(dset2, FAIL, "H5Dcreate2");
8010         dset3 = H5Dcreate2(fid, DSET3_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
8011         CHECK(dset3, FAIL, "H5Dcreate2");
8012 
8013         /* Work on all the datasets */
8014         for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
8015             switch(curr_dset) {
8016                 case 0:
8017                     my_dataset = dset1;
8018                     dsetname = DSET1_NAME;
8019                     break;
8020 
8021                 case 1:
8022                     my_dataset = dset2;
8023                     dsetname = DSET2_NAME;
8024                     break;
8025 
8026                 case 2:
8027                     my_dataset = dset3;
8028                     dsetname = DSET3_NAME;
8029                     break;
8030 
8031                 default:
8032                     HDassert(0 && "Too many datasets!");
8033             } /* end switch */
8034 
8035             /* Check on dataset's attribute storage status */
8036             is_empty = H5O_is_attr_empty_test(my_dataset);
8037             VERIFY(is_empty, TRUE, "H5O_is_attr_empty_test");
8038             is_dense = H5O_is_attr_dense_test(my_dataset);
8039             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8040 
8041             /* Create attributes, up to limit of compact form */
8042             for(u = 0; u < max_compact; u++) {
8043                 /* Create attribute */
8044                 HDsprintf(attrname, "attr %02u", u);
8045                 attr = H5Acreate_by_name(fid, dsetname, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
8046                 CHECK(attr, FAIL, "H5Acreate_by_name");
8047 
8048                 /* Write data into the attribute */
8049                 ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
8050                 CHECK(ret, FAIL, "H5Awrite");
8051 
8052                 /* Close attribute */
8053                 ret = H5Aclose(attr);
8054                 CHECK(ret, FAIL, "H5Aclose");
8055 
8056                 /* Verify information for new attribute */
8057                 ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
8058                 CHECK(ret, FAIL, "attr_info_by_idx_check");
8059             } /* end for */
8060 
8061             /* Verify state of object */
8062             ret = H5O_num_attrs_test(my_dataset, &nattrs);
8063             CHECK(ret, FAIL, "H5O_num_attrs_test");
8064             VERIFY(nattrs, max_compact, "H5O_num_attrs_test");
8065             is_empty = H5O_is_attr_empty_test(my_dataset);
8066             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
8067             is_dense = H5O_is_attr_dense_test(my_dataset);
8068             VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8069 
8070             /* Test opening attributes stored compactly */
8071             ret = attr_open_check(fid, dsetname, my_dataset, u);
8072             CHECK(ret, FAIL, "attr_open_check");
8073         } /* end for */
8074 
8075 
8076         /* Work on all the datasets */
8077         for(curr_dset = 0; curr_dset < NUM_DSETS; curr_dset++) {
8078             switch(curr_dset) {
8079                 case 0:
8080                     my_dataset = dset1;
8081                     dsetname = DSET1_NAME;
8082                     break;
8083 
8084                 case 1:
8085                     my_dataset = dset2;
8086                     dsetname = DSET2_NAME;
8087                     break;
8088 
8089                 case 2:
8090                     my_dataset = dset3;
8091                     dsetname = DSET3_NAME;
8092                     break;
8093 
8094                 default:
8095                     HDassert(0 && "Too many datasets!");
8096             } /* end switch */
8097 
8098             /* Create more attributes, to push into dense form */
8099             for(u = max_compact; u < (max_compact * 2); u++) {
8100                 /* Create attribute */
8101                 HDsprintf(attrname, "attr %02u", u);
8102                 attr = H5Acreate_by_name(fid, dsetname, attrname, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
8103                 CHECK(attr, FAIL, "H5Acreate_by_name");
8104 
8105                 /* Write data into the attribute */
8106                 ret = H5Awrite(attr, H5T_NATIVE_UINT, &u);
8107                 CHECK(ret, FAIL, "H5Awrite");
8108 
8109                 /* Close attribute */
8110                 ret = H5Aclose(attr);
8111                 CHECK(ret, FAIL, "H5Aclose");
8112 
8113                 /* Verify state of object */
8114                 if(u >= max_compact) {
8115                     is_dense = H5O_is_attr_dense_test(my_dataset);
8116                     VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
8117                 } /* end if */
8118 
8119                 /* Verify information for new attribute */
8120                 ret = attr_info_by_idx_check(my_dataset, attrname, (hsize_t)u, use_index);
8121                 CHECK(ret, FAIL, "attr_info_by_idx_check");
8122             } /* end for */
8123 
8124             /* Verify state of object */
8125             ret = H5O_num_attrs_test(my_dataset, &nattrs);
8126             CHECK(ret, FAIL, "H5O_num_attrs_test");
8127             VERIFY(nattrs, (max_compact * 2), "H5O_num_attrs_test");
8128             is_empty = H5O_is_attr_empty_test(my_dataset);
8129             VERIFY(is_empty, FALSE, "H5O_is_attr_empty_test");
8130             is_dense = H5O_is_attr_dense_test(my_dataset);
8131             VERIFY(is_dense, (new_format ? TRUE : FALSE), "H5O_is_attr_dense_test");
8132 
8133             if(new_format) {
8134                 /* Retrieve & verify # of records in the name & creation order indices */
8135                 ret = H5O_attr_dense_info_test(my_dataset, &name_count, &corder_count);
8136                 CHECK(ret, FAIL, "H5O_attr_dense_info_test");
8137                 if(use_index)
8138                     VERIFY(name_count, corder_count, "H5O_attr_dense_info_test");
8139                 VERIFY(name_count, (max_compact * 2), "H5O_attr_dense_info_test");
8140             } /* end if */
8141 
8142             /* Test opening attributes stored compactly */
8143             ret = attr_open_check(fid, dsetname, my_dataset, u);
8144             CHECK(ret, FAIL, "attr_open_check");
8145         } /* end for */
8146 
8147         /* Close Datasets */
8148         ret = H5Dclose(dset1);
8149         CHECK(ret, FAIL, "H5Dclose");
8150         ret = H5Dclose(dset2);
8151         CHECK(ret, FAIL, "H5Dclose");
8152         ret = H5Dclose(dset3);
8153         CHECK(ret, FAIL, "H5Dclose");
8154 
8155         /* Close file */
8156         ret = H5Fclose(fid);
8157         CHECK(ret, FAIL, "H5Fclose");
8158     } /* end for */
8159 
8160     /* Close property list */
8161     ret = H5Pclose(dcpl);
8162     CHECK(ret, FAIL, "H5Pclose");
8163 
8164     /* Close dataspace */
8165     ret = H5Sclose(sid);
8166     CHECK(ret, FAIL, "H5Sclose");
8167 }   /* test_attr_create_by_name() */
8168 
8169 /****************************************************************
8170 **
8171 **  test_attr_shared_write(): Test basic H5A (attribute) code.
8172 **      Tests writing mix of shared & un-shared attributes in "compact" & "dense" storage
8173 **
8174 ****************************************************************/
8175 static void
test_attr_shared_write(hid_t fcpl,hid_t fapl)8176 test_attr_shared_write(hid_t fcpl, hid_t fapl)
8177 {
8178     hid_t    fid;        /* File ID            */
8179     hid_t    my_fcpl;    /* File creation property list ID */
8180     hid_t    dataset, dataset2;    /* Dataset IDs            */
8181     hid_t    attr_tid;    /* Attribute's datatype ID    */
8182     hid_t    sid, big_sid;    /* Dataspace IDs        */
8183     hsize_t    big_dims[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};   /* Dimensions for "big" attribute */
8184     hid_t    attr;            /* Attribute ID            */
8185     hid_t    dcpl;            /* Dataset creation property list ID */
8186     char    attrname[NAME_BUF_SIZE];        /* Name of attribute */
8187     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
8188     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
8189     htri_t    is_dense;    /* Are attributes stored densely? */
8190     htri_t    is_shared;    /* Is attributes shared? */
8191     hsize_t     shared_refcount;        /* Reference count of shared attribute */
8192     unsigned    attr_value;     /* Attribute value */
8193     unsigned    *big_value;     /* Data for "big" attribute */
8194     size_t      mesg_count;     /* # of shared messages */
8195     unsigned    test_shared;    /* Index over shared component type */
8196     unsigned    u;              /* Local index variable */
8197     h5_stat_size_t empty_filesize;       /* Size of empty file */
8198     h5_stat_size_t filesize;             /* Size of file after modifications */
8199     herr_t    ret;        /* Generic return value        */
8200 
8201     /* Output message about test being performed */
8202     MESSAGE(5, ("Testing Writing Shared & Unshared Attributes in Compact & Dense Storage\n"));
8203 
8204     /* Allocate & initialize "big" attribute data */
8205     big_value = (unsigned *)HDmalloc((size_t)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3) * sizeof(unsigned));
8206     CHECK_PTR(big_value, "HDmalloc");
8207     HDmemset(big_value, 1, sizeof(unsigned) * (size_t)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3));
8208 
8209     /* Create dataspace for dataset */
8210     sid = H5Screate(H5S_SCALAR);
8211     CHECK(sid, FAIL, "H5Screate");
8212 
8213     /* Create "big" dataspace for "large" attributes */
8214     big_sid = H5Screate_simple(SPACE1_RANK, big_dims, NULL);
8215     CHECK(big_sid, FAIL, "H5Screate_simple");
8216 
8217     /* Loop over type of shared components */
8218     for(test_shared = 0; test_shared < 3; test_shared++) {
8219         /* Make copy of file creation property list */
8220         my_fcpl = H5Pcopy(fcpl);
8221         CHECK(my_fcpl, FAIL, "H5Pcopy");
8222 
8223         /* Set up datatype for attributes */
8224         attr_tid = H5Tcopy(H5T_NATIVE_UINT);
8225         CHECK(attr_tid, FAIL, "H5Tcopy");
8226 
8227         /* Special setup for each type of shared components */
8228         if(test_shared == 0) {
8229             /* Make attributes > 500 bytes shared */
8230             ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)1);
8231             CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
8232             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)500);
8233             CHECK_I(ret, "H5Pset_shared_mesg_index");
8234         } /* end if */
8235         else {
8236             /* Set up copy of file creation property list */
8237 
8238             ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)3);
8239             CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
8240 
8241             /* Make attributes > 500 bytes shared */
8242             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)500);
8243             CHECK_I(ret, "H5Pset_shared_mesg_index");
8244 
8245             /* Make datatypes & dataspaces > 1 byte shared (i.e. all of them :-) */
8246             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)1, H5O_SHMESG_DTYPE_FLAG, (unsigned)1);
8247             CHECK_I(ret, "H5Pset_shared_mesg_index");
8248             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)2, H5O_SHMESG_SDSPACE_FLAG, (unsigned)1);
8249             CHECK_I(ret, "H5Pset_shared_mesg_index");
8250         } /* end else */
8251 
8252         /* Create file */
8253         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, my_fcpl, fapl);
8254         CHECK(fid, FAIL, "H5Fcreate");
8255 
8256         /* Close FCPL copy */
8257         ret = H5Pclose(my_fcpl);
8258         CHECK(ret, FAIL, "H5Pclose");
8259 
8260         /* Close file */
8261         ret = H5Fclose(fid);
8262         CHECK(ret, FAIL, "H5Fclose");
8263 
8264         /* Get size of file */
8265         empty_filesize = h5_get_file_size(FILENAME, fapl);
8266         if(empty_filesize < 0)
8267             TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
8268 
8269 
8270         /* Re-open file */
8271         fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
8272         CHECK(fid, FAIL, "H5Fopen");
8273 
8274         /* Commit datatype to file */
8275         if(test_shared == 2) {
8276             ret = H5Tcommit2(fid, TYPE1_NAME, attr_tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
8277             CHECK(ret, FAIL, "H5Tcommit2");
8278         } /* end if */
8279 
8280         /* Set up to query the object creation properties */
8281         if (dcpl_g == H5P_DEFAULT) {
8282             dcpl = H5Pcreate(H5P_DATASET_CREATE);
8283             CHECK(dcpl, FAIL, "H5Pcreate");
8284         } else {
8285             dcpl = H5Pcopy(dcpl_g);
8286             CHECK(dcpl, FAIL, "H5Pcopy");
8287         }
8288 
8289         /* Create datasets */
8290         dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
8291         CHECK(dataset, FAIL, "H5Dcreate2");
8292         dataset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
8293         CHECK(dataset2, FAIL, "H5Dcreate2");
8294 
8295         /* Check on dataset's message storage status */
8296         if(test_shared != 0) {
8297             /* Datasets' datatypes can be shared */
8298             ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
8299             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8300             VERIFY(mesg_count, 1, "H5F_get_sohm_mesg_count_test");
8301 
8302             /* Datasets' dataspace can be shared */
8303             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
8304             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8305             VERIFY(mesg_count, 1, "H5F_get_sohm_mesg_count_test");
8306         } /* end if */
8307 
8308         /* Retrieve limits for compact/dense attribute storage */
8309         ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
8310         CHECK(ret, FAIL, "H5Pget_attr_phase_change");
8311 
8312         /* Close property list */
8313         ret = H5Pclose(dcpl);
8314         CHECK(ret, FAIL, "H5Pclose");
8315 
8316         /* Check on datasets' attribute storage status */
8317         is_dense = H5O_is_attr_dense_test(dataset);
8318         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8319         is_dense = H5O_is_attr_dense_test(dataset2);
8320         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8321 
8322         /* Add attributes to each dataset, until after converting to dense storage */
8323         for(u = 0; u < max_compact * 2; u++) {
8324             /* Create attribute name */
8325             HDsprintf(attrname, "attr %02u", u);
8326 
8327             /* Alternate between creating "small" & "big" attributes */
8328             if(u % 2) {
8329                 /* Create "small" attribute on first dataset */
8330                 attr = H5Acreate2(dataset, attrname, attr_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
8331                 CHECK(attr, FAIL, "H5Acreate2");
8332 
8333                 /* Check that attribute is not shared */
8334                 is_shared = H5A__is_shared_test(attr);
8335                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
8336 
8337                 /* Write data into the attribute */
8338                 attr_value = u + 1;
8339                 ret = H5Awrite(attr, attr_tid, &attr_value);
8340                 CHECK(ret, FAIL, "H5Awrite");
8341             } /* end if */
8342             else {
8343                 /* Create "big" attribute on first dataset */
8344                 attr = H5Acreate2(dataset, attrname, attr_tid, big_sid, H5P_DEFAULT, H5P_DEFAULT);
8345                 CHECK(attr, FAIL, "H5Acreate2");
8346 
8347                 /* Check that attribute is shared */
8348                 is_shared = H5A__is_shared_test(attr);
8349                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
8350 
8351                 /* Check refcount for attribute */
8352                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8353                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8354                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
8355 
8356                 /* Write data into the attribute */
8357                 big_value[0] = u + 1;
8358                 ret = H5Awrite(attr, attr_tid, big_value);
8359                 CHECK(ret, FAIL, "H5Awrite");
8360 
8361                 /* Check refcount for attribute */
8362                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8363                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8364                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
8365             } /* end else */
8366 
8367             /* Close attribute */
8368             ret = H5Aclose(attr);
8369             CHECK(ret, FAIL, "H5Aclose");
8370 
8371             /* Check on dataset's attribute storage status */
8372             is_dense = H5O_is_attr_dense_test(dataset);
8373             if(u < max_compact)
8374                 VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8375             else
8376                 VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
8377 
8378 
8379             /* Alternate between creating "small" & "big" attributes */
8380             if(u % 2) {
8381                 /* Create "small" attribute on second dataset */
8382                 attr = H5Acreate2(dataset2, attrname, attr_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
8383                 CHECK(attr, FAIL, "H5Acreate2");
8384 
8385                 /* Check that attribute is not shared */
8386                 is_shared = H5A__is_shared_test(attr);
8387                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
8388 
8389                 /* Write data into the attribute */
8390                 attr_value = u + 1;
8391                 ret = H5Awrite(attr, attr_tid, &attr_value);
8392                 CHECK(ret, FAIL, "H5Awrite");
8393             } /* end if */
8394             else {
8395                 /* Create "big" attribute on second dataset */
8396                 attr = H5Acreate2(dataset2, attrname, attr_tid, big_sid, H5P_DEFAULT, H5P_DEFAULT);
8397                 CHECK(attr, FAIL, "H5Acreate2");
8398 
8399                 /* Check that attribute is shared */
8400                 is_shared = H5A__is_shared_test(attr);
8401                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
8402 
8403                 /* Check refcount for attribute */
8404                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8405                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8406                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
8407 
8408                 /* Write data into the attribute */
8409                 big_value[0] = u + 1;
8410                 ret = H5Awrite(attr, attr_tid, big_value);
8411                 CHECK(ret, FAIL, "H5Awrite");
8412 
8413                 /* Check refcount for attribute */
8414                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8415                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8416                 VERIFY(shared_refcount, 2, "H5A__get_shared_rc_test");
8417             } /* end else */
8418 
8419             /* Close attribute */
8420             ret = H5Aclose(attr);
8421             CHECK(ret, FAIL, "H5Aclose");
8422 
8423             /* Check on dataset's attribute storage status */
8424             is_dense = H5O_is_attr_dense_test(dataset2);
8425             if(u < max_compact)
8426                 VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8427             else
8428                 VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
8429         } /* end for */
8430 
8431         /* Close attribute's datatype */
8432         ret = H5Tclose(attr_tid);
8433         CHECK(ret, FAIL, "H5Tclose");
8434 
8435         /* Close Datasets */
8436         ret = H5Dclose(dataset);
8437         CHECK(ret, FAIL, "H5Dclose");
8438         ret = H5Dclose(dataset2);
8439         CHECK(ret, FAIL, "H5Dclose");
8440 
8441         /* Check on shared message status now */
8442         if(test_shared != 0) {
8443             if(test_shared == 1) {
8444                 /* Check on datatype storage status */
8445                 ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
8446                 CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8447                 VERIFY(mesg_count, 2, "H5F_get_sohm_mesg_count_test");
8448             } /* end if */
8449 
8450             /* Check on dataspace storage status */
8451             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
8452             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8453             VERIFY(mesg_count, 2, "H5F_get_sohm_mesg_count_test");
8454         } /* end if */
8455 
8456         /* Unlink datasets with attributes */
8457         ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
8458         CHECK(ret, FAIL, "H5Ldelete");
8459         ret = H5Ldelete(fid, DSET2_NAME, H5P_DEFAULT);
8460         CHECK(ret, FAIL, "H5Ldelete");
8461 
8462         /* Unlink committed datatype */
8463         if(test_shared == 2) {
8464             ret = H5Ldelete(fid, TYPE1_NAME, H5P_DEFAULT);
8465             CHECK(ret, FAIL, "H5Ldelete");
8466         } /* end if */
8467 
8468         /* Check on attribute storage status */
8469         ret = H5F_get_sohm_mesg_count_test(fid, H5O_ATTR_ID, &mesg_count);
8470         CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8471         VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
8472 
8473         if(test_shared != 0) {
8474             /* Check on datatype storage status */
8475             ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
8476             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8477             VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
8478 
8479             /* Check on dataspace storage status */
8480             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
8481             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8482             VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
8483         } /* end if */
8484 
8485         /* Close file */
8486         ret = H5Fclose(fid);
8487         CHECK(ret, FAIL, "H5Fclose");
8488 
8489         /* Check size of file */
8490         filesize = h5_get_file_size(FILENAME, fapl);
8491         VERIFY(filesize, empty_filesize, "h5_get_file_size");
8492     } /* end for */
8493 
8494     /* Close dataspaces */
8495     ret = H5Sclose(sid);
8496     CHECK(ret, FAIL, "H5Sclose");
8497     ret = H5Sclose(big_sid);
8498     CHECK(ret, FAIL, "H5Sclose");
8499 
8500     /* Release memory */
8501     HDfree(big_value);
8502 }   /* test_attr_shared_write() */
8503 
8504 /****************************************************************
8505 **
8506 **  test_attr_shared_rename(): Test basic H5A (attribute) code.
8507 **      Tests renaming shared attributes in "compact" & "dense" storage
8508 **
8509 ****************************************************************/
8510 static void
test_attr_shared_rename(hid_t fcpl,hid_t fapl)8511 test_attr_shared_rename(hid_t fcpl, hid_t fapl)
8512 {
8513     hid_t    fid;        /* HDF5 File ID            */
8514     hid_t    my_fcpl;    /* File creation property list ID */
8515     hid_t    dataset, dataset2;    /* Dataset ID2            */
8516     hid_t    attr_tid;    /* Attribute's datatype ID    */
8517     hid_t    sid, big_sid;    /* Dataspace IDs        */
8518     hsize_t    big_dims[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};   /* Dimensions for "big" attribute */
8519     hid_t    attr;            /* Attribute ID            */
8520     hid_t    dcpl;            /* Dataset creation property list ID */
8521     char    attrname[NAME_BUF_SIZE];        /* Name of attribute on first dataset */
8522     char    attrname2[NAME_BUF_SIZE];       /* Name of attribute on second dataset */
8523     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
8524     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
8525     htri_t    is_dense;    /* Are attributes stored densely? */
8526     htri_t    is_shared;    /* Is attributes shared? */
8527     hsize_t     shared_refcount;        /* Reference count of shared attribute */
8528     unsigned    attr_value;     /* Attribute value */
8529     unsigned    *big_value;     /* Data for "big" attribute */
8530     size_t      mesg_count;     /* # of shared messages */
8531     unsigned    test_shared;    /* Index over shared component type */
8532     unsigned    u;              /* Local index variable */
8533     h5_stat_size_t empty_filesize;       /* Size of empty file */
8534     h5_stat_size_t filesize;             /* Size of file after modifications */
8535     herr_t    ret;        /* Generic return value        */
8536 
8537     /* Output message about test being performed */
8538     MESSAGE(5, ("Testing Renaming Shared & Unshared Attributes in Compact & Dense Storage\n"));
8539 
8540     /* Allocate & initialize "big" attribute data */
8541     big_value = (unsigned *)HDmalloc((size_t)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3) * sizeof(unsigned));
8542     CHECK_PTR(big_value, "HDmalloc");
8543     HDmemset(big_value, 1, sizeof(unsigned) * (size_t)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3));
8544 
8545     /* Create dataspace for dataset */
8546     sid = H5Screate(H5S_SCALAR);
8547     CHECK(sid, FAIL, "H5Screate");
8548 
8549     /* Create "big" dataspace for "large" attributes */
8550     big_sid = H5Screate_simple(SPACE1_RANK, big_dims, NULL);
8551     CHECK(big_sid, FAIL, "H5Screate_simple");
8552 
8553     /* Loop over type of shared components */
8554     for(test_shared = 0; test_shared < 3; test_shared++) {
8555         /* Make copy of file creation property list */
8556         my_fcpl = H5Pcopy(fcpl);
8557         CHECK(my_fcpl, FAIL, "H5Pcopy");
8558 
8559         /* Set up datatype for attributes */
8560         attr_tid = H5Tcopy(H5T_NATIVE_UINT);
8561         CHECK(attr_tid, FAIL, "H5Tcopy");
8562 
8563         /* Special setup for each type of shared components */
8564         if(test_shared == 0) {
8565             /* Make attributes > 500 bytes shared */
8566             ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)1);
8567             CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
8568             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)500);
8569             CHECK_I(ret, "H5Pset_shared_mesg_index");
8570         } /* end if */
8571         else {
8572             /* Set up copy of file creation property list */
8573 
8574             ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)3);
8575             CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
8576 
8577             /* Make attributes > 500 bytes shared */
8578             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)500);
8579             CHECK_I(ret, "H5Pset_shared_mesg_index");
8580 
8581             /* Make datatypes & dataspaces > 1 byte shared (i.e. all of them :-) */
8582             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)1, H5O_SHMESG_DTYPE_FLAG, (unsigned)1);
8583             CHECK_I(ret, "H5Pset_shared_mesg_index");
8584             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)2, H5O_SHMESG_SDSPACE_FLAG, (unsigned)1);
8585             CHECK_I(ret, "H5Pset_shared_mesg_index");
8586         } /* end else */
8587 
8588         /* Create file */
8589         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, my_fcpl, fapl);
8590         CHECK(fid, FAIL, "H5Fcreate");
8591 
8592         /* Close FCPL copy */
8593         ret = H5Pclose(my_fcpl);
8594         CHECK(ret, FAIL, "H5Pclose");
8595 
8596         /* Close file */
8597         ret = H5Fclose(fid);
8598         CHECK(ret, FAIL, "H5Fclose");
8599 
8600         /* Get size of file */
8601         empty_filesize = h5_get_file_size(FILENAME, fapl);
8602         if(empty_filesize < 0)
8603             TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
8604 
8605 
8606         /* Re-open file */
8607         fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
8608         CHECK(fid, FAIL, "H5Fopen");
8609 
8610         /* Commit datatype to file */
8611         if(test_shared == 2) {
8612             ret = H5Tcommit2(fid, TYPE1_NAME, attr_tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
8613             CHECK(ret, FAIL, "H5Tcommit2");
8614         } /* end if */
8615 
8616         /* Set up to query the object creation properties */
8617         if (dcpl_g == H5P_DEFAULT) {
8618             dcpl = H5Pcreate(H5P_DATASET_CREATE);
8619             CHECK(dcpl, FAIL, "H5Pcreate");
8620         } else {
8621             dcpl = H5Pcopy(dcpl_g);
8622             CHECK(dcpl, FAIL, "H5Pcopy");
8623         }
8624 
8625         /* Create datasets */
8626         dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
8627         CHECK(dataset, FAIL, "H5Dcreate2");
8628         dataset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
8629         CHECK(dataset2, FAIL, "H5Dcreate2");
8630 
8631         /* Check on dataset's message storage status */
8632         if(test_shared != 0) {
8633             /* Datasets' datatypes can be shared */
8634             ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
8635             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8636             VERIFY(mesg_count, 1, "H5F_get_sohm_mesg_count_test");
8637 
8638             /* Datasets' dataspace can be shared */
8639             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
8640             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8641             VERIFY(mesg_count, 1, "H5F_get_sohm_mesg_count_test");
8642         } /* end if */
8643 
8644         /* Retrieve limits for compact/dense attribute storage */
8645         ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
8646         CHECK(ret, FAIL, "H5Pget_attr_phase_change");
8647 
8648         /* Close property list */
8649         ret = H5Pclose(dcpl);
8650         CHECK(ret, FAIL, "H5Pclose");
8651 
8652         /* Check on datasets' attribute storage status */
8653         is_dense = H5O_is_attr_dense_test(dataset);
8654         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8655         is_dense = H5O_is_attr_dense_test(dataset2);
8656         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8657 
8658         /* Add attributes to each dataset, until after converting to dense storage */
8659         for(u = 0; u < max_compact * 2; u++) {
8660             /* Create attribute name */
8661             HDsprintf(attrname, "attr %02u", u);
8662 
8663             /* Alternate between creating "small" & "big" attributes */
8664             if(u % 2) {
8665                 /* Create "small" attribute on first dataset */
8666                 attr = H5Acreate2(dataset, attrname, attr_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
8667                 CHECK(attr, FAIL, "H5Acreate2");
8668 
8669                 /* Check that attribute is not shared */
8670                 is_shared = H5A__is_shared_test(attr);
8671                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
8672 
8673                 /* Write data into the attribute */
8674                 attr_value = u + 1;
8675                 ret = H5Awrite(attr, attr_tid, &attr_value);
8676                 CHECK(ret, FAIL, "H5Awrite");
8677             } /* end if */
8678             else {
8679                 /* Create "big" attribute on first dataset */
8680                 attr = H5Acreate2(dataset, attrname, attr_tid, big_sid, H5P_DEFAULT, H5P_DEFAULT);
8681                 CHECK(attr, FAIL, "H5Acreate2");
8682 
8683                 /* Check that attribute is shared */
8684                 is_shared = H5A__is_shared_test(attr);
8685                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
8686 
8687                 /* Check refcount for attribute */
8688                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8689                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8690                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
8691 
8692                 /* Write data into the attribute */
8693                 big_value[0] = u + 1;
8694                 ret = H5Awrite(attr, attr_tid, big_value);
8695                 CHECK(ret, FAIL, "H5Awrite");
8696 
8697                 /* Check refcount for attribute */
8698                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8699                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8700                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
8701             } /* end else */
8702 
8703             /* Close attribute */
8704             ret = H5Aclose(attr);
8705             CHECK(ret, FAIL, "H5Aclose");
8706 
8707             /* Check on dataset's attribute storage status */
8708             is_dense = H5O_is_attr_dense_test(dataset);
8709             if(u < max_compact)
8710                 VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8711             else
8712                 VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
8713 
8714 
8715             /* Alternate between creating "small" & "big" attributes */
8716             if(u % 2) {
8717                 /* Create "small" attribute on second dataset */
8718                 attr = H5Acreate2(dataset2, attrname, attr_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
8719                 CHECK(attr, FAIL, "H5Acreate2");
8720 
8721                 /* Check that attribute is not shared */
8722                 is_shared = H5A__is_shared_test(attr);
8723                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
8724 
8725                 /* Write data into the attribute */
8726                 attr_value = u + 1;
8727                 ret = H5Awrite(attr, attr_tid, &attr_value);
8728                 CHECK(ret, FAIL, "H5Awrite");
8729             } /* end if */
8730             else {
8731                 /* Create "big" attribute on second dataset */
8732                 attr = H5Acreate2(dataset2, attrname, attr_tid, big_sid, H5P_DEFAULT, H5P_DEFAULT);
8733                 CHECK(attr, FAIL, "H5Acreate2");
8734 
8735                 /* Check that attribute is shared */
8736                 is_shared = H5A__is_shared_test(attr);
8737                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
8738 
8739                 /* Check refcount for attribute */
8740                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8741                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8742                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
8743 
8744                 /* Write data into the attribute */
8745                 big_value[0] = u + 1;
8746                 ret = H5Awrite(attr, attr_tid, big_value);
8747                 CHECK(ret, FAIL, "H5Awrite");
8748 
8749                 /* Check refcount for attribute */
8750                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8751                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8752                 VERIFY(shared_refcount, 2, "H5A__get_shared_rc_test");
8753             } /* end else */
8754 
8755             /* Close attribute */
8756             ret = H5Aclose(attr);
8757             CHECK(ret, FAIL, "H5Aclose");
8758 
8759             /* Check on dataset's attribute storage status */
8760             is_dense = H5O_is_attr_dense_test(dataset2);
8761             if(u < max_compact)
8762                 VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
8763             else
8764                 VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
8765 
8766 
8767             /* Create new attribute name */
8768             HDsprintf(attrname2, "new attr %02u", u);
8769 
8770             /* Change second dataset's attribute's name */
8771             ret = H5Arename_by_name(fid, DSET2_NAME, attrname, attrname2, H5P_DEFAULT);
8772             CHECK(ret, FAIL, "H5Arename_by_name");
8773 
8774 
8775             /* Check refcount on attributes now */
8776 
8777             /* Check refcount on renamed attribute */
8778             attr = H5Aopen(dataset2, attrname2, H5P_DEFAULT);
8779             CHECK(attr, FAIL, "H5Aopen");
8780 
8781             if(u % 2) {
8782                 /* Check that attribute is not shared */
8783                 is_shared = H5A__is_shared_test(attr);
8784                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
8785             } /* end if */
8786             else {
8787                 /* Check that attribute is shared */
8788                 is_shared = H5A__is_shared_test(attr);
8789                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
8790 
8791                 /* Check refcount for attribute */
8792                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8793                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8794                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
8795             } /* end else */
8796 
8797             /* Close attribute */
8798             ret = H5Aclose(attr);
8799             CHECK(ret, FAIL, "H5Aclose");
8800 
8801             /* Check refcount on original attribute */
8802             attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
8803             CHECK(attr, FAIL, "H5Aopen");
8804 
8805             if(u % 2) {
8806                 /* Check that attribute is not shared */
8807                 is_shared = H5A__is_shared_test(attr);
8808                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
8809             } /* end if */
8810             else {
8811                 /* Check that attribute is shared */
8812                 is_shared = H5A__is_shared_test(attr);
8813                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
8814 
8815                 /* Check refcount for attribute */
8816                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8817                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8818                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
8819             } /* end else */
8820 
8821             /* Close attribute */
8822             ret = H5Aclose(attr);
8823             CHECK(ret, FAIL, "H5Aclose");
8824 
8825 
8826             /* Change second dataset's attribute's name back to original */
8827             ret = H5Arename_by_name(fid, DSET2_NAME, attrname2, attrname, H5P_DEFAULT);
8828             CHECK(ret, FAIL, "H5Arename_by_name");
8829 
8830 
8831             /* Check refcount on attributes now */
8832 
8833             /* Check refcount on renamed attribute */
8834             attr = H5Aopen(dataset2, attrname, H5P_DEFAULT);
8835             CHECK(attr, FAIL, "H5Aopen");
8836 
8837             if(u % 2) {
8838                 /* Check that attribute is not shared */
8839                 is_shared = H5A__is_shared_test(attr);
8840                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
8841             } /* end if */
8842             else {
8843                 /* Check that attribute is shared */
8844                 is_shared = H5A__is_shared_test(attr);
8845                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
8846 
8847                 /* Check refcount for attribute */
8848                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8849                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8850                 VERIFY(shared_refcount, 2, "H5A__get_shared_rc_test");
8851             } /* end else */
8852 
8853             /* Close attribute */
8854             ret = H5Aclose(attr);
8855             CHECK(ret, FAIL, "H5Aclose");
8856 
8857             /* Check refcount on original attribute */
8858             attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
8859             CHECK(attr, FAIL, "H5Aopen");
8860 
8861             if(u % 2) {
8862                 /* Check that attribute is not shared */
8863                 is_shared = H5A__is_shared_test(attr);
8864                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
8865             } /* end if */
8866             else {
8867                 /* Check that attribute is shared */
8868                 is_shared = H5A__is_shared_test(attr);
8869                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
8870 
8871                 /* Check refcount for attribute */
8872                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
8873                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
8874                 VERIFY(shared_refcount, 2, "H5A__get_shared_rc_test");
8875             } /* end else */
8876 
8877             /* Close attribute */
8878             ret = H5Aclose(attr);
8879             CHECK(ret, FAIL, "H5Aclose");
8880         } /* end for */
8881 
8882 
8883         /* Close attribute's datatype */
8884         ret = H5Tclose(attr_tid);
8885         CHECK(ret, FAIL, "H5Tclose");
8886 
8887         /* Close Datasets */
8888         ret = H5Dclose(dataset);
8889         CHECK(ret, FAIL, "H5Dclose");
8890         ret = H5Dclose(dataset2);
8891         CHECK(ret, FAIL, "H5Dclose");
8892 
8893         /* Check on shared message status now */
8894         if(test_shared != 0) {
8895             if(test_shared == 1) {
8896                 /* Check on datatype storage status */
8897                 ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
8898                 CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8899                 VERIFY(mesg_count, 2, "H5F_get_sohm_mesg_count_test");
8900             } /* end if */
8901 
8902             /* Check on dataspace storage status */
8903             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
8904             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8905             VERIFY(mesg_count, 2, "H5F_get_sohm_mesg_count_test");
8906         } /* end if */
8907 
8908         /* Unlink datasets with attributes */
8909         ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
8910         CHECK(ret, FAIL, "HLdelete");
8911         ret = H5Ldelete(fid, DSET2_NAME, H5P_DEFAULT);
8912         CHECK(ret, FAIL, "H5Ldelete");
8913 
8914         /* Unlink committed datatype */
8915         if(test_shared == 2) {
8916             ret = H5Ldelete(fid, TYPE1_NAME, H5P_DEFAULT);
8917             CHECK(ret, FAIL, "H5Ldelete");
8918         } /* end if */
8919 
8920         /* Check on attribute storage status */
8921         ret = H5F_get_sohm_mesg_count_test(fid, H5O_ATTR_ID, &mesg_count);
8922         CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8923         VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
8924 
8925         if(test_shared != 0) {
8926             /* Check on datatype storage status */
8927             ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
8928             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8929             VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
8930 
8931             /* Check on dataspace storage status */
8932             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
8933             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
8934             VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
8935         } /* end if */
8936 
8937         /* Close file */
8938         ret = H5Fclose(fid);
8939         CHECK(ret, FAIL, "H5Fclose");
8940 
8941         /* Check size of file */
8942         filesize = h5_get_file_size(FILENAME, fapl);
8943         VERIFY(filesize, empty_filesize, "h5_get_file_size");
8944     } /* end for */
8945 
8946     /* Close dataspaces */
8947     ret = H5Sclose(sid);
8948     CHECK(ret, FAIL, "H5Sclose");
8949     ret = H5Sclose(big_sid);
8950     CHECK(ret, FAIL, "H5Sclose");
8951 
8952     /* Release memory */
8953     HDfree(big_value);
8954 }   /* test_attr_shared_rename() */
8955 
8956 /****************************************************************
8957 **
8958 **  test_attr_shared_delete(): Test basic H5A (attribute) code.
8959 **      Tests deleting shared attributes in "compact" & "dense" storage
8960 **
8961 ****************************************************************/
8962 static void
test_attr_shared_delete(hid_t fcpl,hid_t fapl)8963 test_attr_shared_delete(hid_t fcpl, hid_t fapl)
8964 {
8965     hid_t    fid;        /* File ID            */
8966     hid_t    my_fcpl;    /* File creation property list ID */
8967     hid_t    dataset, dataset2;    /* Dataset IDs            */
8968     hid_t    attr_tid;    /* Attribute's datatype ID    */
8969     hid_t    sid, big_sid;    /* Dataspace IDs        */
8970     hsize_t    big_dims[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};   /* Dimensions for "big" attribute */
8971     hid_t    attr;            /* Attribute ID            */
8972     hid_t    dcpl;            /* Dataset creation property list ID */
8973     char    attrname[NAME_BUF_SIZE];        /* Name of attribute on first dataset */
8974     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
8975     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
8976     htri_t    is_dense;    /* Are attributes stored densely? */
8977     htri_t    is_shared;    /* Is attributes shared? */
8978     hsize_t     shared_refcount;        /* Reference count of shared attribute */
8979     unsigned    attr_value;     /* Attribute value */
8980     unsigned    *big_value;     /* Data for "big" attribute */
8981     size_t      mesg_count;     /* # of shared messages */
8982     unsigned    test_shared;    /* Index over shared component type */
8983     unsigned    u;              /* Local index variable */
8984     h5_stat_size_t empty_filesize;       /* Size of empty file */
8985     h5_stat_size_t filesize;             /* Size of file after modifications */
8986     herr_t    ret;        /* Generic return value        */
8987 
8988     /* Output message about test being performed */
8989     MESSAGE(5, ("Testing Deleting Shared & Unshared Attributes in Compact & Dense Storage\n"));
8990 
8991     /* Allocate & initialize "big" attribute data */
8992     big_value = (unsigned *)HDmalloc((size_t)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3) * sizeof(unsigned));
8993     CHECK_PTR(big_value, "HDmalloc");
8994     HDmemset(big_value, 1, sizeof(unsigned) * (size_t)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3));
8995 
8996     /* Create dataspace for dataset */
8997     sid = H5Screate(H5S_SCALAR);
8998     CHECK(sid, FAIL, "H5Screate");
8999 
9000     /* Create "big" dataspace for "large" attributes */
9001     big_sid = H5Screate_simple(SPACE1_RANK, big_dims, NULL);
9002     CHECK(big_sid, FAIL, "H5Screate_simple");
9003 
9004     /* Loop over type of shared components */
9005     for(test_shared = 0; test_shared < 3; test_shared++) {
9006         /* Make copy of file creation property list */
9007         my_fcpl = H5Pcopy(fcpl);
9008         CHECK(my_fcpl, FAIL, "H5Pcopy");
9009 
9010         /* Set up datatype for attributes */
9011         attr_tid = H5Tcopy(H5T_NATIVE_UINT);
9012         CHECK(attr_tid, FAIL, "H5Tcopy");
9013 
9014         /* Special setup for each type of shared components */
9015         if(test_shared == 0) {
9016             /* Make attributes > 500 bytes shared */
9017             ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)1);
9018             CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
9019             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)500);
9020             CHECK_I(ret, "H5Pset_shared_mesg_index");
9021         } /* end if */
9022         else {
9023             /* Set up copy of file creation property list */
9024 
9025             ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)3);
9026             CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
9027 
9028             /* Make attributes > 500 bytes shared */
9029             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)500);
9030             CHECK_I(ret, "H5Pset_shared_mesg_index");
9031 
9032             /* Make datatypes & dataspaces > 1 byte shared (i.e. all of them :-) */
9033             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)1, H5O_SHMESG_DTYPE_FLAG, (unsigned)1);
9034             CHECK_I(ret, "H5Pset_shared_mesg_index");
9035             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)2, H5O_SHMESG_SDSPACE_FLAG, (unsigned)1);
9036             CHECK_I(ret, "H5Pset_shared_mesg_index");
9037         } /* end else */
9038 
9039         /* Create file */
9040         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, my_fcpl, fapl);
9041         CHECK(fid, FAIL, "H5Fcreate");
9042 
9043         /* Close FCPL copy */
9044         ret = H5Pclose(my_fcpl);
9045         CHECK(ret, FAIL, "H5Pclose");
9046 
9047         /* Close file */
9048         ret = H5Fclose(fid);
9049         CHECK(ret, FAIL, "H5Fclose");
9050 
9051         /* Get size of file */
9052         empty_filesize = h5_get_file_size(FILENAME, fapl);
9053         if(empty_filesize < 0)
9054             TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
9055 
9056 
9057         /* Re-open file */
9058         fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
9059         CHECK(fid, FAIL, "H5Fopen");
9060 
9061         /* Commit datatype to file */
9062         if(test_shared == 2) {
9063             ret = H5Tcommit2(fid, TYPE1_NAME, attr_tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9064             CHECK(ret, FAIL, "H5Tcommit2");
9065         } /* end if */
9066 
9067         /* Set up to query the object creation properties */
9068         if (dcpl_g == H5P_DEFAULT) {
9069             dcpl = H5Pcreate(H5P_DATASET_CREATE);
9070             CHECK(dcpl, FAIL, "H5Pcreate");
9071         } else {
9072             dcpl = H5Pcopy(dcpl_g);
9073             CHECK(dcpl, FAIL, "H5Pcopy");
9074         }
9075 
9076         /* Create datasets */
9077         dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
9078         CHECK(dataset, FAIL, "H5Dcreate2");
9079         dataset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
9080         CHECK(dataset2, FAIL, "H5Dcreate2");
9081 
9082         /* Check on dataset's message storage status */
9083         if(test_shared != 0) {
9084             /* Datasets' datatypes can be shared */
9085             ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
9086             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9087             VERIFY(mesg_count, 1, "H5F_get_sohm_mesg_count_test");
9088 
9089             /* Datasets' dataspace can be shared */
9090             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
9091             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9092             VERIFY(mesg_count, 1, "H5F_get_sohm_mesg_count_test");
9093         } /* end if */
9094 
9095         /* Retrieve limits for compact/dense attribute storage */
9096         ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
9097         CHECK(ret, FAIL, "H5Pget_attr_phase_change");
9098 
9099         /* Close property list */
9100         ret = H5Pclose(dcpl);
9101         CHECK(ret, FAIL, "H5Pclose");
9102 
9103         /* Check on datasets' attribute storage status */
9104         is_dense = H5O_is_attr_dense_test(dataset);
9105         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
9106         is_dense = H5O_is_attr_dense_test(dataset2);
9107         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
9108 
9109         /* Add attributes to each dataset, until after converting to dense storage */
9110         for(u = 0; u < max_compact * 2; u++) {
9111             /* Create attribute name */
9112             HDsprintf(attrname, "attr %02u", u);
9113 
9114             /* Alternate between creating "small" & "big" attributes */
9115             if(u % 2) {
9116                 /* Create "small" attribute on first dataset */
9117                 attr = H5Acreate2(dataset, attrname, attr_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
9118                 CHECK(attr, FAIL, "H5Acreate2");
9119 
9120                 /* Check that attribute is not shared */
9121                 is_shared = H5A__is_shared_test(attr);
9122                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
9123 
9124                 /* Write data into the attribute */
9125                 attr_value = u + 1;
9126                 ret = H5Awrite(attr, attr_tid, &attr_value);
9127                 CHECK(ret, FAIL, "H5Awrite");
9128             } /* end if */
9129             else {
9130                 /* Create "big" attribute on first dataset */
9131                 attr = H5Acreate2(dataset, attrname, attr_tid, big_sid, H5P_DEFAULT, H5P_DEFAULT);
9132                 CHECK(attr, FAIL, "H5Acreate2");
9133 
9134                 /* Check that attribute is shared */
9135                 is_shared = H5A__is_shared_test(attr);
9136                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
9137 
9138                 /* Check refcount for attribute */
9139                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9140                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9141                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
9142 
9143                 /* Write data into the attribute */
9144                 big_value[0] = u + 1;
9145                 ret = H5Awrite(attr, attr_tid, big_value);
9146                 CHECK(ret, FAIL, "H5Awrite");
9147 
9148                 /* Check refcount for attribute */
9149                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9150                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9151                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
9152             } /* end else */
9153 
9154             /* Close attribute */
9155             ret = H5Aclose(attr);
9156             CHECK(ret, FAIL, "H5Aclose");
9157 
9158             /* Check on dataset's attribute storage status */
9159             is_dense = H5O_is_attr_dense_test(dataset);
9160             if(u < max_compact)
9161                 VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
9162             else
9163                 VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
9164 
9165 
9166             /* Alternate between creating "small" & "big" attributes */
9167             if(u % 2) {
9168                 /* Create "small" attribute on second dataset */
9169                 attr = H5Acreate2(dataset2, attrname, attr_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
9170                 CHECK(attr, FAIL, "H5Acreate2");
9171 
9172                 /* Check that attribute is not shared */
9173                 is_shared = H5A__is_shared_test(attr);
9174                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
9175 
9176                 /* Write data into the attribute */
9177                 attr_value = u + 1;
9178                 ret = H5Awrite(attr, attr_tid, &attr_value);
9179                 CHECK(ret, FAIL, "H5Awrite");
9180             } /* end if */
9181             else {
9182                 /* Create "big" attribute on second dataset */
9183                 attr = H5Acreate2(dataset2, attrname, attr_tid, big_sid, H5P_DEFAULT, H5P_DEFAULT);
9184                 CHECK(attr, FAIL, "H5Acreate2");
9185 
9186                 /* Check that attribute is shared */
9187                 is_shared = H5A__is_shared_test(attr);
9188                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
9189 
9190                 /* Check refcount for attribute */
9191                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9192                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9193                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
9194 
9195                 /* Write data into the attribute */
9196                 big_value[0] = u + 1;
9197                 ret = H5Awrite(attr, attr_tid, big_value);
9198                 CHECK(ret, FAIL, "H5Awrite");
9199 
9200                 /* Check refcount for attribute */
9201                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9202                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9203                 VERIFY(shared_refcount, 2, "H5A_get_shared_rc_test");
9204             } /* end else */
9205 
9206             /* Close attribute */
9207             ret = H5Aclose(attr);
9208             CHECK(ret, FAIL, "H5Aclose");
9209 
9210             /* Check on dataset's attribute storage status */
9211             is_dense = H5O_is_attr_dense_test(dataset2);
9212             if(u < max_compact)
9213                 VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
9214             else
9215                 VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
9216         } /* end for */
9217 
9218 
9219         /* Delete attributes from second dataset */
9220         for(u = 0; u < max_compact * 2; u++) {
9221             /* Create attribute name */
9222             HDsprintf(attrname, "attr %02u", u);
9223 
9224             /* Delete second dataset's attribute */
9225             ret = H5Adelete_by_name(fid, DSET2_NAME, attrname, H5P_DEFAULT);
9226             CHECK(ret, FAIL, "H5Adelete_by_name");
9227 
9228 
9229             /* Check refcount on attributes now */
9230 
9231             /* Check refcount on first dataset's attribute */
9232             attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
9233             CHECK(attr, FAIL, "H5Aopen");
9234 
9235             if(u % 2) {
9236                 /* Check that attribute is not shared */
9237                 is_shared = H5A__is_shared_test(attr);
9238                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
9239             } /* end if */
9240             else {
9241                 /* Check that attribute is shared */
9242                 is_shared = H5A__is_shared_test(attr);
9243                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
9244 
9245                 /* Check refcount for attribute */
9246                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9247                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9248                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
9249             } /* end else */
9250 
9251             /* Close attribute */
9252             ret = H5Aclose(attr);
9253             CHECK(ret, FAIL, "H5Aclose");
9254         } /* end for */
9255 
9256 
9257         /* Close attribute's datatype */
9258         ret = H5Tclose(attr_tid);
9259         CHECK(ret, FAIL, "H5Tclose");
9260 
9261         /* Close Datasets */
9262         ret = H5Dclose(dataset);
9263         CHECK(ret, FAIL, "H5Dclose");
9264         ret = H5Dclose(dataset2);
9265         CHECK(ret, FAIL, "H5Dclose");
9266 
9267         /* Check on shared message status now */
9268         if(test_shared != 0) {
9269             if(test_shared == 1) {
9270                 /* Check on datatype storage status */
9271                 ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
9272                 CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9273                 VERIFY(mesg_count, 2, "H5F_get_sohm_mesg_count_test");
9274             } /* end if */
9275 
9276             /* Check on dataspace storage status */
9277             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
9278             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9279             VERIFY(mesg_count, 2, "H5F_get_sohm_mesg_count_test");
9280         } /* end if */
9281 
9282         /* Unlink datasets with attributes */
9283         ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
9284         CHECK(ret, FAIL, "H5Ldelete");
9285         ret = H5Ldelete(fid, DSET2_NAME, H5P_DEFAULT);
9286         CHECK(ret, FAIL, "H5Ldelete");
9287 
9288         /* Unlink committed datatype */
9289         if(test_shared == 2) {
9290             ret = H5Ldelete(fid, TYPE1_NAME, H5P_DEFAULT);
9291             CHECK(ret, FAIL, "H5Ldelete");
9292         } /* end if */
9293 
9294         /* Check on attribute storage status */
9295         ret = H5F_get_sohm_mesg_count_test(fid, H5O_ATTR_ID, &mesg_count);
9296         CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9297         VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
9298 
9299         if(test_shared != 0) {
9300             /* Check on datatype storage status */
9301             ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
9302             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9303             VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
9304 
9305             /* Check on dataspace storage status */
9306             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
9307             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9308             VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
9309         } /* end if */
9310 
9311         /* Close file */
9312         ret = H5Fclose(fid);
9313         CHECK(ret, FAIL, "H5Fclose");
9314 
9315         /* Check size of file */
9316         filesize = h5_get_file_size(FILENAME, fapl);
9317         VERIFY(filesize, empty_filesize, "h5_get_file_size");
9318     } /* end for */
9319 
9320     /* Close dataspaces */
9321     ret = H5Sclose(sid);
9322     CHECK(ret, FAIL, "H5Sclose");
9323     ret = H5Sclose(big_sid);
9324     CHECK(ret, FAIL, "H5Sclose");
9325 
9326     /* Release memory */
9327     HDfree(big_value);
9328 }   /* test_attr_shared_delete() */
9329 
9330 /****************************************************************
9331 **
9332 **  test_attr_shared_unlink(): Test basic H5A (attribute) code.
9333 **      Tests unlinking object with  shared attributes in "compact" & "dense" storage
9334 **
9335 ****************************************************************/
9336 static void
test_attr_shared_unlink(hid_t fcpl,hid_t fapl)9337 test_attr_shared_unlink(hid_t fcpl, hid_t fapl)
9338 {
9339     hid_t    fid;        /* File ID            */
9340     hid_t    my_fcpl;    /* File creation property list ID */
9341     hid_t    dataset, dataset2;    /* Dataset IDs            */
9342     hid_t    attr_tid;    /* Attribute's datatype ID    */
9343     hid_t    sid, big_sid;    /* Dataspace IDs        */
9344     hsize_t    big_dims[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};   /* Dimensions for "big" attribute */
9345     hid_t    attr;            /* Attribute ID            */
9346     hid_t    dcpl;            /* Dataset creation property list ID */
9347     char    attrname[NAME_BUF_SIZE];        /* Name of attribute on first dataset */
9348     unsigned    max_compact;    /* Maximum # of attributes to store compactly */
9349     unsigned    min_dense;      /* Minimum # of attributes to store "densely" */
9350     htri_t    is_dense;    /* Are attributes stored densely? */
9351     htri_t    is_shared;    /* Is attributes shared? */
9352     hsize_t     shared_refcount;        /* Reference count of shared attribute */
9353     unsigned    attr_value;     /* Attribute value */
9354     unsigned    *big_value;     /* Data for "big" attribute */
9355     size_t      mesg_count;     /* # of shared messages */
9356     unsigned    test_shared;    /* Index over shared component type */
9357     unsigned    u;              /* Local index variable */
9358     h5_stat_size_t empty_filesize;       /* Size of empty file */
9359     h5_stat_size_t filesize;             /* Size of file after modifications */
9360     herr_t    ret;        /* Generic return value        */
9361 
9362     /* Output message about test being performed */
9363     MESSAGE(5, ("Testing Unlinking Object with Shared Attributes in Compact & Dense Storage\n"));
9364 
9365     /* Allocate & initialize "big" attribute data */
9366     big_value = (unsigned *)HDmalloc((size_t)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3) * sizeof(unsigned));
9367     CHECK_PTR(big_value, "HDmalloc");
9368     HDmemset(big_value, 1, sizeof(unsigned) * (size_t)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3));
9369 
9370     /* Create dataspace for dataset */
9371     sid = H5Screate(H5S_SCALAR);
9372     CHECK(sid, FAIL, "H5Screate");
9373 
9374     /* Create "big" dataspace for "large" attributes */
9375     big_sid = H5Screate_simple(SPACE1_RANK, big_dims, NULL);
9376     CHECK(big_sid, FAIL, "H5Screate_simple");
9377 
9378     /* Loop over type of shared components */
9379     for(test_shared = 0; test_shared < 3; test_shared++) {
9380         /* Make copy of file creation property list */
9381         my_fcpl = H5Pcopy(fcpl);
9382         CHECK(my_fcpl, FAIL, "H5Pcopy");
9383 
9384         /* Set up datatype for attributes */
9385         attr_tid = H5Tcopy(H5T_NATIVE_UINT);
9386         CHECK(attr_tid, FAIL, "H5Tcopy");
9387 
9388         /* Special setup for each type of shared components */
9389         if(test_shared == 0) {
9390             /* Make attributes > 500 bytes shared */
9391             ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)1);
9392             CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
9393             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)500);
9394             CHECK_I(ret, "H5Pset_shared_mesg_index");
9395         } /* end if */
9396         else {
9397             /* Set up copy of file creation property list */
9398 
9399             ret = H5Pset_shared_mesg_nindexes(my_fcpl, (unsigned)3);
9400             CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
9401 
9402             /* Make attributes > 500 bytes shared */
9403             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)500);
9404             CHECK_I(ret, "H5Pset_shared_mesg_index");
9405 
9406             /* Make datatypes & dataspaces > 1 byte shared (i.e. all of them :-) */
9407             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)1, H5O_SHMESG_DTYPE_FLAG, (unsigned)1);
9408             CHECK_I(ret, "H5Pset_shared_mesg_index");
9409             ret = H5Pset_shared_mesg_index(my_fcpl, (unsigned)2, H5O_SHMESG_SDSPACE_FLAG, (unsigned)1);
9410             CHECK_I(ret, "H5Pset_shared_mesg_index");
9411         } /* end else */
9412 
9413         /* Create file */
9414         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, my_fcpl, fapl);
9415         CHECK(fid, FAIL, "H5Fcreate");
9416 
9417         /* Close FCPL copy */
9418         ret = H5Pclose(my_fcpl);
9419         CHECK(ret, FAIL, "H5Pclose");
9420 
9421         /* Close file */
9422         ret = H5Fclose(fid);
9423         CHECK(ret, FAIL, "H5Fclose");
9424 
9425         /* Get size of file */
9426         empty_filesize = h5_get_file_size(FILENAME, fapl);
9427         if(empty_filesize < 0)
9428             TestErrPrintf("Line %d: file size wrong!\n", __LINE__);
9429 
9430 
9431         /* Re-open file */
9432         fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
9433         CHECK(fid, FAIL, "H5Fopen");
9434 
9435         /* Commit datatype to file */
9436         if(test_shared == 2) {
9437             ret = H5Tcommit2(fid, TYPE1_NAME, attr_tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9438             CHECK(ret, FAIL, "H5Tcommit2");
9439         } /* end if */
9440 
9441         /* Set up to query the object creation properties */
9442         if (dcpl_g == H5P_DEFAULT) {
9443             dcpl = H5Pcreate(H5P_DATASET_CREATE);
9444             CHECK(dcpl, FAIL, "H5Pcreate");
9445         } else {
9446             dcpl = H5Pcopy(dcpl_g);
9447             CHECK(dcpl, FAIL, "H5Pcopy");
9448         }
9449 
9450         /* Create datasets */
9451         dataset = H5Dcreate2(fid, DSET1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
9452         CHECK(dataset, FAIL, "H5Dcreate2");
9453         dataset2 = H5Dcreate2(fid, DSET2_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT);
9454         CHECK(dataset2, FAIL, "H5Dcreate2");
9455 
9456         /* Check on dataset's message storage status */
9457         if(test_shared != 0) {
9458             /* Datasets' datatypes can be shared */
9459             ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
9460             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9461             VERIFY(mesg_count, 1, "H5F_get_sohm_mesg_count_test");
9462 
9463             /* Datasets' dataspace can be shared */
9464             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
9465             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9466             VERIFY(mesg_count, 1, "H5F_get_sohm_mesg_count_test");
9467         } /* end if */
9468 
9469         /* Retrieve limits for compact/dense attribute storage */
9470         ret = H5Pget_attr_phase_change(dcpl, &max_compact, &min_dense);
9471         CHECK(ret, FAIL, "H5Pget_attr_phase_change");
9472 
9473         /* Close property list */
9474         ret = H5Pclose(dcpl);
9475         CHECK(ret, FAIL, "H5Pclose");
9476 
9477         /* Check on datasets' attribute storage status */
9478         is_dense = H5O_is_attr_dense_test(dataset);
9479         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
9480         is_dense = H5O_is_attr_dense_test(dataset2);
9481         VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
9482 
9483         /* Add attributes to each dataset, until after converting to dense storage */
9484         for(u = 0; u < max_compact * 2; u++) {
9485             /* Create attribute name */
9486             HDsprintf(attrname, "attr %02u", u);
9487 
9488             /* Alternate between creating "small" & "big" attributes */
9489             if(u % 2) {
9490                 /* Create "small" attribute on first dataset */
9491                 attr = H5Acreate2(dataset, attrname, attr_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
9492                 CHECK(attr, FAIL, "H5Acreate2");
9493 
9494                 /* Check that attribute is not shared */
9495                 is_shared = H5A__is_shared_test(attr);
9496                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
9497 
9498                 /* Write data into the attribute */
9499                 attr_value = u + 1;
9500                 ret = H5Awrite(attr, attr_tid, &attr_value);
9501                 CHECK(ret, FAIL, "H5Awrite");
9502             } /* end if */
9503             else {
9504                 /* Create "big" attribute on first dataset */
9505                 attr = H5Acreate2(dataset, attrname, attr_tid, big_sid, H5P_DEFAULT, H5P_DEFAULT);
9506                 CHECK(attr, FAIL, "H5Acreate2");
9507 
9508                 /* ChecFk that attribute is shared */
9509                 is_shared = H5A__is_shared_test(attr);
9510                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
9511 
9512                 /* Check refcount for attribute */
9513                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9514                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9515                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
9516 
9517                 /* Write data into the attribute */
9518                 big_value[0] = u + 1;
9519                 ret = H5Awrite(attr, attr_tid, big_value);
9520                 CHECK(ret, FAIL, "H5Awrite");
9521 
9522                 /* Check refcount for attribute */
9523                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9524                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9525                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
9526             } /* end else */
9527 
9528             /* Close attribute */
9529             ret = H5Aclose(attr);
9530             CHECK(ret, FAIL, "H5Aclose");
9531 
9532             /* Check on dataset's attribute storage status */
9533             is_dense = H5O_is_attr_dense_test(dataset);
9534             if(u < max_compact)
9535                 VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
9536             else
9537                 VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
9538 
9539 
9540             /* Alternate between creating "small" & "big" attributes */
9541             if(u % 2) {
9542                 /* Create "small" attribute on second dataset */
9543                 attr = H5Acreate2(dataset2, attrname, attr_tid, sid, H5P_DEFAULT, H5P_DEFAULT);
9544                 CHECK(attr, FAIL, "H5Acreate2");
9545 
9546                 /* Check that attribute is not shared */
9547                 is_shared = H5A__is_shared_test(attr);
9548                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
9549 
9550                 /* Write data into the attribute */
9551                 attr_value = u + 1;
9552                 ret = H5Awrite(attr, attr_tid, &attr_value);
9553                 CHECK(ret, FAIL, "H5Awrite");
9554             } /* end if */
9555             else {
9556                 /* Create "big" attribute on second dataset */
9557                 attr = H5Acreate2(dataset2, attrname, attr_tid, big_sid, H5P_DEFAULT, H5P_DEFAULT);
9558                 CHECK(attr, FAIL, "H5Acreate2");
9559 
9560                 /* Check that attribute is shared */
9561                 is_shared = H5A__is_shared_test(attr);
9562                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
9563 
9564                 /* Check refcount for attribute */
9565                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9566                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9567                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
9568 
9569                 /* Write data into the attribute */
9570                 big_value[0] = u + 1;
9571                 ret = H5Awrite(attr, attr_tid, big_value);
9572                 CHECK(ret, FAIL, "H5Awrite");
9573 
9574                 /* Check refcount for attribute */
9575                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9576                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9577                 VERIFY(shared_refcount, 2, "H5A__get_shared_rc_test");
9578             } /* end else */
9579 
9580             /* Close attribute */
9581             ret = H5Aclose(attr);
9582             CHECK(ret, FAIL, "H5Aclose");
9583 
9584             /* Check on dataset's attribute storage status */
9585             is_dense = H5O_is_attr_dense_test(dataset2);
9586             if(u < max_compact)
9587                 VERIFY(is_dense, FALSE, "H5O_is_attr_dense_test");
9588             else
9589                 VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
9590         } /* end for */
9591 
9592 
9593         /* Close attribute's datatype */
9594         ret = H5Tclose(attr_tid);
9595         CHECK(ret, FAIL, "H5Tclose");
9596 
9597         /* Close second dataset */
9598         ret = H5Dclose(dataset2);
9599         CHECK(ret, FAIL, "H5Dclose");
9600 
9601         /* Unlink second dataset */
9602         ret = H5Ldelete(fid, DSET2_NAME, H5P_DEFAULT);
9603         CHECK(ret, FAIL, "H5Ldelete");
9604 
9605 
9606         /* Check on first dataset's attribute storage status */
9607         is_dense = H5O_is_attr_dense_test(dataset);
9608         VERIFY(is_dense, TRUE, "H5O_is_attr_dense_test");
9609 
9610         /* Check ref count on  attributes of first dataset */
9611         for(u = 0; u < max_compact * 2; u++) {
9612             /* Create attribute name */
9613             HDsprintf(attrname, "attr %02u", u);
9614 
9615             /* Open attribute on first dataset */
9616             attr = H5Aopen(dataset, attrname, H5P_DEFAULT);
9617             CHECK(attr, FAIL, "H5Aopen");
9618 
9619             if(u % 2) {
9620                 /* Check that attribute is not shared */
9621                 is_shared = H5A__is_shared_test(attr);
9622                 VERIFY(is_shared, FALSE, "H5A__is_shared_test");
9623             } /* end if */
9624             else {
9625                 /* Check that attribute is shared */
9626                 is_shared = H5A__is_shared_test(attr);
9627                 VERIFY(is_shared, TRUE, "H5A__is_shared_test");
9628 
9629                 /* Check refcount for attribute */
9630                 ret = H5A__get_shared_rc_test(attr, &shared_refcount);
9631                 CHECK(ret, FAIL, "H5A__get_shared_rc_test");
9632                 VERIFY(shared_refcount, 1, "H5A__get_shared_rc_test");
9633             } /* end else */
9634 
9635             /* Close attribute */
9636             ret = H5Aclose(attr);
9637             CHECK(ret, FAIL, "H5Aclose");
9638         } /* end for */
9639 
9640         /* Close Datasets */
9641         ret = H5Dclose(dataset);
9642         CHECK(ret, FAIL, "H5Dclose");
9643 
9644         /* Unlink first dataset */
9645         ret = H5Ldelete(fid, DSET1_NAME, H5P_DEFAULT);
9646         CHECK(ret, FAIL, "H5Ldelete");
9647 
9648         /* Unlink committed datatype */
9649         if(test_shared == 2) {
9650             ret = H5Ldelete(fid, TYPE1_NAME, H5P_DEFAULT);
9651             CHECK(ret, FAIL, "H5Ldelete");
9652         } /* end if */
9653 
9654         /* Check on attribute storage status */
9655         ret = H5F_get_sohm_mesg_count_test(fid, H5O_ATTR_ID, &mesg_count);
9656         CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9657         VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
9658 
9659         if(test_shared != 0) {
9660             /* Check on datatype storage status */
9661             ret = H5F_get_sohm_mesg_count_test(fid, H5O_DTYPE_ID, &mesg_count);
9662             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9663             VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
9664 
9665             /* Check on dataspace storage status */
9666             ret = H5F_get_sohm_mesg_count_test(fid, H5O_SDSPACE_ID, &mesg_count);
9667             CHECK(ret, FAIL, "H5F_get_sohm_mesg_count_test");
9668             VERIFY(mesg_count, 0, "H5F_get_sohm_mesg_count_test");
9669         } /* end if */
9670 
9671         /* Close file */
9672         ret = H5Fclose(fid);
9673         CHECK(ret, FAIL, "H5Fclose");
9674 
9675         /* Check size of file */
9676         filesize = h5_get_file_size(FILENAME, fapl);
9677         VERIFY(filesize, empty_filesize, "h5_get_file_size");
9678     } /* end for */
9679 
9680     /* Close dataspaces */
9681     ret = H5Sclose(sid);
9682     CHECK(ret, FAIL, "H5Sclose");
9683     ret = H5Sclose(big_sid);
9684     CHECK(ret, FAIL, "H5Sclose");
9685 
9686     /* Release memory */
9687     HDfree(big_value);
9688 }   /* test_attr_shared_unlink() */
9689 
9690 /****************************************************************
9691 **
9692 **  test_attr_bug1(): Test basic H5A (attribute) code.
9693 **      Tests odd sequence of allocating and deallocating space in the file.
9694 **      The series of actions below constructs a file with an attribute
9695 **      in each object header chunk, except the first.  Then, the attributes
9696 **      are removed and re-created in a way that makes the object header
9697 **      allocation code remove an object header chunk "in the middle" of
9698 **      the sequence of the chunks.
9699 **
9700 ****************************************************************/
9701 static void
test_attr_bug1(hid_t fcpl,hid_t fapl)9702 test_attr_bug1(hid_t fcpl, hid_t fapl)
9703 {
9704     hid_t fid;          /* File ID */
9705     hid_t gid;          /* Group ID */
9706     hid_t aid;          /* Attribute ID */
9707     hid_t sid;          /* Dataspace ID */
9708     herr_t ret;         /* Generic return status */
9709 
9710     /* Output message about test being performed */
9711     MESSAGE(5, ("Testing Allocating and De-allocating Attributes in Unusual Way\n"));
9712 
9713     /* Create dataspace ID for attributes */
9714     sid = H5Screate(H5S_SCALAR);
9715     CHECK(sid, FAIL, "H5Screate");
9716 
9717     /* Create main group to operate on */
9718     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
9719     CHECK(fid, FAIL, "H5Fcreate");
9720 
9721     gid = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9722     CHECK(gid, FAIL, "H5Gcreate2");
9723 
9724     ret = H5Gclose(gid);
9725     CHECK(ret, FAIL, "H5Gclose");
9726 
9727     ret = H5Fclose(fid);
9728     CHECK(ret, FAIL, "H5Fclose");
9729 
9730 
9731     /* Re-open file and create another group, then attribute on first group */
9732     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
9733     CHECK(fid, FAIL, "H5Fopen");
9734 
9735     /* Create second group */
9736     gid = H5Gcreate2(fid, GROUP2_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9737     CHECK(gid, FAIL, "H5Gcreate2");
9738 
9739     ret = H5Gclose(gid);
9740     CHECK(ret, FAIL, "H5Gclose");
9741 
9742     /* Re-open first group */
9743     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
9744     CHECK(gid, FAIL, "H5Gopen2");
9745 
9746     /* Create attribute on first group */
9747     aid = H5Acreate2(gid, ATTR7_NAME, H5T_NATIVE_DOUBLE, sid, H5P_DEFAULT, H5P_DEFAULT);
9748     CHECK(aid, FAIL, "H5Acreate2");
9749 
9750     ret = H5Aclose(aid);
9751     CHECK(ret, FAIL, "H5Aclose");
9752 
9753     ret = H5Gclose(gid);
9754     CHECK(ret, FAIL, "H5Gclose");
9755 
9756     ret = H5Fclose(fid);
9757     CHECK(ret, FAIL, "H5Fclose");
9758 
9759 
9760     /* Re-open file and create another group, then another attribute on first group */
9761     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
9762     CHECK(fid, FAIL, "H5Fopen");
9763 
9764     /* Create third group */
9765     gid = H5Gcreate2(fid, GROUP3_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9766     CHECK(gid, FAIL, "H5Gcreate2");
9767 
9768     ret = H5Gclose(gid);
9769     CHECK(ret, FAIL, "H5Gclose");
9770 
9771     /* Unlink second group */
9772     ret = H5Ldelete(fid, GROUP2_NAME, H5P_DEFAULT);
9773     CHECK(ret, FAIL, "H5Ldelete");
9774 
9775     /* Re-open first group */
9776     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
9777     CHECK(gid, FAIL, "H5Gopen2");
9778 
9779     /* Create another attribute on first group */
9780     aid = H5Acreate2(gid, ATTR8_NAME, H5T_NATIVE_DOUBLE, sid, H5P_DEFAULT, H5P_DEFAULT);
9781     CHECK(aid, FAIL, "H5Acreate2");
9782 
9783     ret = H5Aclose(aid);
9784     CHECK(ret, FAIL, "H5Aclose");
9785 
9786     ret = H5Gclose(gid);
9787     CHECK(ret, FAIL, "H5Gclose");
9788 
9789     ret = H5Fclose(fid);
9790     CHECK(ret, FAIL, "H5Fclose");
9791 
9792 
9793     /* Re-open file and re-create attributes on first group */
9794     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
9795     CHECK(fid, FAIL, "H5Fopen");
9796 
9797     /* Re-open first group */
9798     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
9799     CHECK(gid, FAIL, "H5Gopen2");
9800 
9801     /* Delete first attribute */
9802     ret = H5Adelete(gid, ATTR7_NAME);
9803     CHECK(ret, FAIL, "H5Adelete");
9804 
9805     /* Re-create first attribute */
9806     aid = H5Acreate2(gid, ATTR7_NAME, H5T_NATIVE_DOUBLE, sid, H5P_DEFAULT, H5P_DEFAULT);
9807     CHECK(aid, FAIL, "H5Acreate2");
9808 
9809     ret = H5Aclose(aid);
9810     CHECK(ret, FAIL, "H5Aclose");
9811 
9812     /* Delete second attribute */
9813     ret = H5Adelete(gid, ATTR8_NAME);
9814     CHECK(ret, FAIL, "H5Adelete");
9815 
9816     /* Re-create second attribute */
9817     aid = H5Acreate2(gid, ATTR8_NAME, H5T_NATIVE_DOUBLE, sid, H5P_DEFAULT, H5P_DEFAULT);
9818     CHECK(aid, FAIL, "H5Acreate2");
9819 
9820     ret = H5Aclose(aid);
9821     CHECK(ret, FAIL, "H5Aclose");
9822 
9823     ret = H5Gclose(gid);
9824     CHECK(ret, FAIL, "H5Gclose");
9825 
9826     ret = H5Fclose(fid);
9827     CHECK(ret, FAIL, "H5Fclose");
9828 
9829 
9830     /* Close dataspace ID */
9831     ret = H5Sclose(sid);
9832     CHECK(ret, FAIL, "H5Gclose");
9833 }   /* test_attr_bug1() */
9834 
9835 /****************************************************************
9836 **
9837 **  test_attr_bug2(): Test basic H5A (attribute) code.
9838 **      Tests deleting a large number of attributes with the
9839 **      intention of creating a null message with a size that
9840 **      is too large.  This routine deletes every other
9841 **      attribute, but the original bug could also be
9842 **      reproduced by deleting every attribute except a few to
9843 **      keep the chunk open.
9844 **
9845 ****************************************************************/
9846 static void
test_attr_bug2(hid_t fcpl,hid_t fapl)9847 test_attr_bug2(hid_t fcpl, hid_t fapl)
9848 {
9849     hid_t   fid;            /* File ID */
9850     hid_t   gid;            /* Group ID */
9851     hid_t   aid;            /* Attribute ID */
9852     hid_t   sid;            /* Dataspace ID */
9853     hid_t   tid;            /* Datatype ID */
9854     hid_t   gcpl;           /* Group creation property list */
9855     hsize_t dims[2] = {10, 100}; /* Attribute dimensions */
9856     char    aname[16];       /* Attribute name */
9857     unsigned i;             /* index */
9858     herr_t  ret;            /* Generic return status */
9859     htri_t  tri_ret;        /* htri_t return status */
9860 
9861     /* Output message about test being performed */
9862     MESSAGE(5, ("Testing Allocating and De-allocating Attributes in Unusual Way\n"));
9863 
9864     /* Create group creation property list */
9865     gcpl = H5Pcreate(H5P_GROUP_CREATE);
9866     CHECK(gcpl, FAIL, "H5Pcreate");
9867 
9868     /* Prevent the library from switching to dense attribute storage */
9869     /* Not doing this with the latest format actually triggers a different bug.
9870      * This will be tested here as soon as it is fixed.  -NAF
9871      */
9872     ret = H5Pset_attr_phase_change (gcpl, BUG2_NATTR+10, BUG2_NATTR+5);
9873     CHECK(ret, FAIL, "H5Pset_attr_phase_change");
9874 
9875     /* Create dataspace ID for attributes */
9876     sid = H5Screate_simple(2, dims, NULL);
9877     CHECK(sid, FAIL, "H5Screate_simple");
9878 
9879     /* Create main group to operate on */
9880     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
9881     CHECK(fid, FAIL, "H5Fcreate");
9882 
9883     gid = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, gcpl, H5P_DEFAULT);
9884     CHECK(gid, FAIL, "H5Gcreate2");
9885 
9886     /* Create attributes on group */
9887     for (i=0; i<BUG2_NATTR; i++) {
9888         HDsprintf(aname, "%03u", i);
9889         aid = H5Acreate2(gid, aname, H5T_STD_I32LE, sid, H5P_DEFAULT, H5P_DEFAULT);
9890         CHECK(aid, FAIL, "H5Acreate2");
9891 
9892         ret = H5Aclose(aid);
9893         CHECK(ret, FAIL, "H5Aclose");
9894     }
9895 
9896     /* Delete every other attribute */
9897     for (i=1; i<BUG2_NATTR; i+=2) {
9898         HDsprintf(aname, "%03u", i);
9899         ret = H5Adelete(gid, aname);
9900         CHECK(ret, FAIL, "H5Adelete");
9901     }
9902 
9903     /* Close IDs */
9904     ret = H5Gclose(gid);
9905     CHECK(ret, FAIL, "H5Gclose");
9906 
9907     ret = H5Fclose(fid);
9908     CHECK(ret, FAIL, "H5Fclose");
9909 
9910     ret = H5Sclose(sid);
9911     CHECK(ret, FAIL, "H5Sclose");
9912 
9913     /* Reopen file and group */
9914     fid = H5Fopen(FILENAME, H5F_ACC_RDONLY, fapl);
9915     CHECK(fid, FAIL, "H5Fopen");
9916 
9917     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
9918     CHECK(gid, FAIL, "H5Gopen");
9919 
9920     /* Open an attribute in the middle */
9921     i = (BUG2_NATTR / 4) * 2;
9922     HDsprintf(aname, "%03u", i);
9923     aid = H5Aopen(gid, aname, H5P_DEFAULT);
9924     CHECK(aid, FAIL, "H5Aopen");
9925 
9926     /* Verify that the attribute has the correct datatype */
9927     tid = H5Aget_type(aid);
9928     CHECK(tid, FAIL, "H5Aget_type");
9929 
9930     tri_ret = H5Tequal(tid, H5T_STD_I32LE);
9931     VERIFY(tri_ret, TRUE, "H5Tequal");
9932 
9933     /* Close IDs */
9934     ret = H5Tclose(tid);
9935     CHECK(ret, FAIL, "H5Tclose");
9936 
9937     ret = H5Aclose(aid);
9938     CHECK(ret, FAIL, "H5Aclose");
9939 
9940     ret = H5Gclose(gid);
9941     CHECK(ret, FAIL, "H5Gclose");
9942 
9943     ret = H5Fclose(fid);
9944     CHECK(ret, FAIL, "H5Fclose");
9945 
9946     /* Now test a variation on this bug - where either the size of chunk 0 goes
9947      * down a "notch" or two, or chunk 1 becomes completely null at the same
9948      * time that a null message that is too large is formed */
9949     dims[0] = 25;
9950     dims[1] = 41; /* 1025*4 byte attribute size */
9951 
9952     /* Create dataspace ID for attributes */
9953     sid = H5Screate_simple(2, dims, NULL);
9954     CHECK(sid, FAIL, "H5Screate_simple");
9955 
9956     /* Create main group to operate on */
9957     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
9958     CHECK(fid, FAIL, "H5Fcreate");
9959 
9960     gid = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, gcpl, H5P_DEFAULT);
9961     CHECK(gid, FAIL, "H5Gcreate2");
9962 
9963     /* Create attributes on group */
9964     for (i=0; i<BUG2_NATTR2; i++) {
9965         HDsprintf(aname, "%03u", i);
9966         aid = H5Acreate2(gid, aname, H5T_STD_I32LE, sid, H5P_DEFAULT, H5P_DEFAULT);
9967         CHECK(aid, FAIL, "H5Acreate2");
9968 
9969         ret = H5Aclose(aid);
9970         CHECK(ret, FAIL, "H5Aclose");
9971     }
9972 
9973     /* Delete every other attribute */
9974     for (i=0; i<BUG2_NATTR2; i++) {
9975         HDsprintf(aname, "%03u", i);
9976         ret = H5Adelete(gid, aname);
9977         CHECK(ret, FAIL, "H5Adelete");
9978     }
9979 
9980     /* Close IDs */
9981     ret = H5Gclose(gid);
9982     CHECK(ret, FAIL, "H5Gclose");
9983 
9984     ret = H5Fclose(fid);
9985     CHECK(ret, FAIL, "H5Fclose");
9986 
9987     ret = H5Sclose(sid);
9988     CHECK(ret, FAIL, "H5Sclose");
9989 
9990     ret = H5Pclose(gcpl);
9991     CHECK(ret, FAIL, "H5Pclose");
9992 }   /* test_attr_bug2() */
9993 
9994 /****************************************************************
9995 **
9996 **  test_attr_bug3(): Test basic H5A (attribute) code.
9997 **      Tests creating and deleting attributes which use a
9998 **      datatype and/or dataspace stored in the same object
9999 **      header.
10000 **
10001 ****************************************************************/
10002 static void
test_attr_bug3(hid_t fcpl,hid_t fapl)10003 test_attr_bug3(hid_t fcpl, hid_t fapl)
10004 {
10005     hid_t   fid;            /* File ID */
10006     hid_t   aid1, aid2;     /* Attribute IDs */
10007     hid_t   sid1, sid2;     /* Dataspace ID */
10008     hid_t   tid1, tid2;     /* Datatype IDs */
10009     hid_t   did;            /* Dataset ID */
10010     hsize_t dims1[2] = {2, 2},
10011             dims2[2] = {3, 3}; /* Dimensions */
10012     int     wdata1[2][2];
10013     unsigned wdata2[3][3];  /* Write buffers */
10014     unsigned u, v;          /* Local index variables */
10015     herr_t  ret;            /* Generic return status */
10016 
10017     /* Output message about test being performed */
10018     MESSAGE(5, ("Testing Attributes in the Same Header as their Datatypes\n"));
10019 
10020     /* Create dataspaces */
10021     sid1 = H5Screate_simple(2, dims1, NULL);
10022     CHECK(sid1, FAIL, "H5Screate_simple");
10023     sid2 = H5Screate_simple(2, dims2, NULL);
10024     CHECK(sid2, FAIL, "H5Screate_simple");
10025 
10026     /* Create file to operate on */
10027     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
10028     CHECK(fid, FAIL, "H5Fcreate");
10029 
10030     /* Create datatypes and commit tid1 */
10031     tid1 = H5Tcopy(H5T_STD_I16BE);
10032     CHECK(tid1, FAIL, "H5Tcopy");
10033     tid2 = H5Tcopy(H5T_STD_U64LE);
10034     CHECK(tid1, FAIL, "H5Tcopy");
10035     ret = H5Tcommit2(fid, "dtype", tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
10036     CHECK(ret, FAIL, "H5Tcommit2");
10037 
10038     /* Create dataset */
10039     did = H5Dcreate2(fid, "dset", tid2, sid2, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
10040     CHECK(did, FAIL, "H5Dcreate2");
10041 
10042     /* Create attribute on datatype, using that datatype as its datatype */
10043     aid1 = H5Acreate2(tid1, "attr", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT);
10044     CHECK(aid1, FAIL, "H5Acreate2");
10045 
10046     /* Create attribute on dataset, using its datatype and dataspace */
10047     aid2 = H5Acreate2(did, "attr", tid2, sid2, H5P_DEFAULT, H5P_DEFAULT);
10048     CHECK(aid2, FAIL, "H5Acreate2");
10049 
10050     /* Close attributes */
10051     ret = H5Aclose(aid1);
10052     CHECK(ret, FAIL, "H5Aclose");
10053     ret = H5Aclose(aid2);
10054     CHECK(ret, FAIL, "H5Aclose");
10055 
10056     /* Reopen attributes */
10057     aid1 = H5Aopen(tid1, "attr", H5P_DEFAULT);
10058     CHECK(aid1, FAIL, "H5Aopen");
10059     aid2 = H5Aopen(did, "attr", H5P_DEFAULT);
10060     CHECK(aid2, FAIL, "H5Aopen");
10061 
10062     /* Initialize the write buffers */
10063     for(u = 0; u < dims1[0]; u++)
10064         for(v = 0; v < dims1[1]; v++)
10065             wdata1[u][v] = (int)((u * dims1[1]) + v);
10066     for(u = 0; u < dims2[0]; u++)
10067         for(v = 0; v < dims2[1]; v++)
10068             wdata2[u][v] = (unsigned)((u * dims2[1]) + v);
10069 
10070     /* Write data to the attributes */
10071     ret = H5Awrite(aid1, H5T_NATIVE_INT, wdata1);
10072     CHECK(ret, FAIL, "H5Awrite");
10073     ret = H5Awrite(aid2, H5T_NATIVE_UINT, wdata2);
10074     CHECK(ret, FAIL, "H5Awrite");
10075 
10076     /* Close attributes */
10077     ret = H5Aclose(aid1);
10078     CHECK(ret, FAIL, "H5Aclose");
10079     ret = H5Aclose(aid2);
10080     CHECK(ret, FAIL, "H5Aclose");
10081 
10082     /* Delete attributes */
10083     ret = H5Adelete(tid1, "attr");
10084     CHECK(ret, FAIL, "H5Adelete");
10085     ret = H5Adelete(did, "attr");
10086     CHECK(ret, FAIL, "H5Adelete");
10087 
10088     /* Recreate attributes */
10089     aid1 = H5Acreate2(tid1, "attr", tid1, sid1, H5P_DEFAULT, H5P_DEFAULT);
10090     CHECK(aid1, FAIL, "H5Acreate2");
10091     aid2 = H5Acreate2(did, "attr", tid2, sid2, H5P_DEFAULT, H5P_DEFAULT);
10092     CHECK(aid2, FAIL, "H5Acreate2");
10093 
10094     /* Delete attributes (note they are still open) */
10095     ret = H5Adelete(tid1, "attr");
10096     CHECK(ret, FAIL, "H5Adelete");
10097     ret = H5Adelete(did, "attr");
10098     CHECK(ret, FAIL, "H5Adelete");
10099 
10100     /* Close dataspaces and transient datatype */
10101     ret = H5Sclose(sid1);
10102     CHECK(ret, FAIL, "H5Sclose");
10103     ret = H5Sclose(sid2);
10104     CHECK(ret, FAIL, "H5Sclose");
10105     ret = H5Tclose(tid2);
10106     CHECK(ret, FAIL, "H5Tclose");
10107 
10108     /* Close dataset and committed datatype */
10109     ret = H5Tclose(tid1);
10110     CHECK(ret, FAIL, "H5Tclose");
10111     ret = H5Dclose(did);
10112     CHECK(ret, FAIL, "H5Dclose");
10113 
10114     /* Delete dataset and committed datatype */
10115     ret = H5Ldelete(fid, "dtype", H5P_DEFAULT);
10116     CHECK(ret, FAIL, "H5Tclose");
10117     ret = H5Ldelete(fid, "dset", H5P_DEFAULT);
10118     CHECK(ret, FAIL, "H5Dclose");
10119 
10120     /* Close attributes */
10121     ret = H5Aclose(aid1);
10122     CHECK(ret, FAIL, "H5Aclose");
10123     ret = H5Aclose(aid2);
10124     CHECK(ret, FAIL, "H5Aclose");
10125 
10126     /* Close file */
10127     ret = H5Fclose(fid);
10128     CHECK(ret, FAIL, "H5Fclose");
10129 }   /* test_attr_bug3() */
10130 
10131 /****************************************************************
10132 **
10133 **  test_attr_bug4(): Test basic H5A (attribute) code.
10134 **      Attempts to trigger a bug which would result in being
10135 **      unable to add an attribute to a named datatype.  This
10136 **      happened when an object header chunk was too small to
10137 **      hold a continuation message and could not be extended.
10138 **
10139 ****************************************************************/
10140 static void
test_attr_bug4(hid_t fcpl,hid_t fapl)10141 test_attr_bug4(hid_t fcpl, hid_t fapl)
10142 {
10143     hid_t   fid;            /* File ID */
10144     hid_t   gid;            /* Group ID */
10145     hid_t   aid1, aid2, aid3; /* Attribute IDs */
10146     hid_t   sid;            /* Dataspace ID */
10147     hid_t   tid;            /* Datatype ID */
10148     hid_t   did;            /* Dataset ID */
10149     hsize_t dims[1] = {5};  /* Attribute dimensions */
10150     herr_t  ret;            /* Generic return status */
10151 
10152     /* Output message about test being performed */
10153     MESSAGE(5, ("Testing that attributes can always be added to named datatypes\n"));
10154 
10155     /* Create dataspace */
10156     sid = H5Screate_simple(1, dims, NULL);
10157     CHECK(sid, FAIL, "H5Screate_simple");
10158 
10159     /* Create file */
10160     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
10161     CHECK(fid, FAIL, "H5Fcreate");
10162 
10163     /* Open root group */
10164     gid = H5Gopen2(fid, "/", H5P_DEFAULT);
10165     CHECK(gid, FAIL, "H5Gcreate2");
10166 
10167     /* Create committed datatype */
10168     tid = H5Tcopy(H5T_STD_I32LE);
10169     CHECK(tid, FAIL, "H5Tcopy");
10170     ret = H5Tcommit2(fid, "dtype", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
10171     CHECK(ret, FAIL, "H5Tcommit2");
10172 
10173     /* Create dataset */
10174     did = H5Dcreate2(fid, "dset", tid, sid, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
10175     CHECK(did, FAIL, "H5Dcreate2");
10176 
10177     /* Create attributes on group and dataset */
10178     aid1 = H5Acreate2(gid, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT);
10179     CHECK(aid1, FAIL, "H5Acreate2");
10180     aid2 = H5Acreate2(did, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT);
10181     CHECK(aid2, FAIL, "H5Acreate2");
10182 
10183     /* Create attribute on datatype (this is the main test) */
10184     aid3 = H5Acreate2(tid, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT);
10185     CHECK(aid3, FAIL, "H5Acreate2");
10186 
10187     /* Close IDs */
10188     ret = H5Aclose(aid3);
10189     CHECK(ret, FAIL, "H5Aclose");
10190 
10191     ret = H5Aclose(aid2);
10192     CHECK(ret, FAIL, "H5Aclose");
10193 
10194     ret = H5Aclose(aid1);
10195     CHECK(ret, FAIL, "H5Aclose");
10196 
10197     ret = H5Dclose(did);
10198     CHECK(ret, FAIL, "H5Dclose");
10199 
10200     ret = H5Tclose(tid);
10201     CHECK(ret, FAIL, "H5Tclose");
10202 
10203     ret = H5Gclose(gid);
10204     CHECK(ret, FAIL, "H5Gclose");
10205 
10206     ret = H5Fclose(fid);
10207     CHECK(ret, FAIL, "H5Fclose");
10208 
10209     ret = H5Sclose(sid);
10210     CHECK(ret, FAIL, "H5Sclose");
10211 }   /* test_attr_bug4() */
10212 
10213 /****************************************************************
10214 **
10215 **  test_attr_bug5(): Test basic H5A (attribute) code.
10216 **      Tests opening an attribute multiple times through
10217 **      objects opened through different file handles.
10218 **
10219 ****************************************************************/
10220 static void
test_attr_bug5(hid_t fcpl,hid_t fapl)10221 test_attr_bug5(hid_t fcpl, hid_t fapl)
10222 {
10223     hid_t   fid1, fid2;     /* File IDs */
10224     hid_t   gid1, gid2;     /* Group IDs */
10225     hid_t   did1, did2;     /* Dataset IDs */
10226     hid_t   tid1, tid2;     /* Datatype IDs */
10227     hid_t   aidg1, aidg2,
10228             aidd1, aidd2,
10229             aidt1, aidt2;   /* Attribute IDs */
10230     hid_t   sid;            /* Dataspace ID */
10231     hsize_t dims[1] = {5};  /* Attribute dimensions */
10232     herr_t  ret;            /* Generic return status */
10233 
10234     /* Output message about test being performed */
10235     MESSAGE(5, ("Testing Opening an Attribute Through Multiple Files Concurrently\n"));
10236 
10237     /* Create dataspace ID for attributes and datasets */
10238     sid = H5Screate_simple(1, dims, NULL);
10239     CHECK(sid, FAIL, "H5Screate_simple");
10240 
10241     /* Create file */
10242     fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
10243     CHECK(fid1, FAIL, "H5Fcreate");
10244 
10245     /* Open root group */
10246     gid1 = H5Gopen2(fid1, "/", H5P_DEFAULT);
10247     CHECK(gid1, FAIL, "H5Gopen2");
10248 
10249     /* Create and commit datatype */
10250     tid1 = H5Tcopy(H5T_STD_I32LE);
10251     CHECK(tid1, FAIL, "H5Tcopy");
10252     ret = H5Tcommit2(fid1, BUG3_DT_NAME, tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
10253     CHECK(ret, FAIL, "H5Tcommit2");
10254 
10255     /* Create dataset */
10256     did1 = H5Dcreate2(fid1, BUG3_DSET_NAME, tid1, sid, H5P_DEFAULT, dcpl_g, H5P_DEFAULT);
10257     CHECK(did1, FAIL, "H5Dcreate2");
10258 
10259     /* Create attribute on root group */
10260     aidg1 = H5Acreate2(gid1, BUG3_ATTR_NAME, tid1, sid, H5P_DEFAULT, H5P_DEFAULT);
10261     CHECK(aidg1, FAIL, "H5Acreate2");
10262 
10263     /* Create attribute on dataset */
10264     aidd1 = H5Acreate2(did1, BUG3_ATTR_NAME, tid1, sid, H5P_DEFAULT, H5P_DEFAULT);
10265     CHECK(aidd1, FAIL, "H5Acreate2");
10266 
10267     /* Create attribute on datatype */
10268     aidt1 = H5Acreate2(tid1, BUG3_ATTR_NAME, tid1, sid, H5P_DEFAULT, H5P_DEFAULT);
10269     CHECK(aidt1, FAIL, "H5Acreate2");
10270 
10271     /* Close all IDs */
10272     ret = H5Aclose(aidt1);
10273     CHECK(ret, FAIL, "H5Aclose");
10274     ret = H5Aclose(aidd1);
10275     CHECK(ret, FAIL, "H5Aclose");
10276     ret = H5Aclose(aidg1);
10277     CHECK(ret, FAIL, "H5Aclose");
10278     ret = H5Dclose(did1);
10279     CHECK(ret, FAIL, "H5Dclose");
10280     ret = H5Tclose(tid1);
10281     CHECK(ret, FAIL, "H5Tclose");
10282     ret = H5Gclose(gid1);
10283     CHECK(ret, FAIL, "H5Gclose");
10284     ret = H5Fclose(fid1);
10285     CHECK(ret, FAIL, "H5Fclose");
10286     ret = H5Sclose(sid);
10287     CHECK(ret, FAIL, "H5Sclose");
10288 
10289     /* Open file twice */
10290     fid1 = H5Fopen(FILENAME, H5F_ACC_RDONLY, fapl);
10291     CHECK(fid1, FAIL, "H5Fopen");
10292     fid2 = H5Fopen(FILENAME, H5F_ACC_RDONLY, fapl);
10293     CHECK(fid2, FAIL, "H5Fopen");
10294 
10295     /* Open the root group twice */
10296     gid1 = H5Gopen2(fid1, "/", H5P_DEFAULT);
10297     CHECK(gid1, FAIL, "H5Gopen2");
10298     gid2 = H5Gopen2(fid2, "/", H5P_DEFAULT);
10299     CHECK(gid2, FAIL, "H5Gopen2");
10300 
10301     /* Open the root group attribute twice */
10302     aidg1 = H5Aopen(gid1, BUG3_ATTR_NAME, H5P_DEFAULT);
10303     CHECK(aidg1, FAIL, "H5Aopen");
10304     aidg2 = H5Aopen(gid2, BUG3_ATTR_NAME, H5P_DEFAULT);
10305     CHECK(aidg1, FAIL, "H5Aopen");
10306 
10307     /* Open the dataset twice */
10308     did1 = H5Dopen2(fid1, BUG3_DSET_NAME, H5P_DEFAULT);
10309     CHECK(did1, FAIL, "H5Dopen2");
10310     did2 = H5Dopen2(fid2, BUG3_DSET_NAME, H5P_DEFAULT);
10311     CHECK(did2, FAIL, "H5Dopen2");
10312 
10313     /* Open the dataset attribute twice */
10314     aidd1 = H5Aopen(did1, BUG3_ATTR_NAME, H5P_DEFAULT);
10315     CHECK(aidd1, FAIL, "H5Aopen");
10316     aidd2 = H5Aopen(did2, BUG3_ATTR_NAME, H5P_DEFAULT);
10317     CHECK(aidd1, FAIL, "H5Aopen");
10318 
10319     /* Open the datatype twice */
10320     tid1 = H5Topen2(fid1, BUG3_DT_NAME, H5P_DEFAULT);
10321     CHECK(tid1, FAIL, "H5Topen2");
10322     tid2 = H5Topen2(fid2, BUG3_DT_NAME, H5P_DEFAULT);
10323     CHECK(tid2, FAIL, "H5Topen2");
10324 
10325     /* Open the datatype attribute twice */
10326     aidt1 = H5Aopen(tid1, BUG3_ATTR_NAME, H5P_DEFAULT);
10327     CHECK(aidt1, FAIL, "H5Aopen");
10328     aidt2 = H5Aopen(tid2, BUG3_ATTR_NAME, H5P_DEFAULT);
10329     CHECK(aidt2, FAIL, "H5Aopen");
10330 
10331     /* Close all attributes */
10332     ret = H5Aclose(aidg1);
10333     CHECK(ret, FAIL, "H5Aclose");
10334     ret = H5Aclose(aidg2);
10335     CHECK(ret, FAIL, "H5Aclose");
10336     ret = H5Aclose(aidd1);
10337     CHECK(ret, FAIL, "H5Aclose");
10338     ret = H5Aclose(aidd2);
10339     CHECK(ret, FAIL, "H5Aclose");
10340     ret = H5Aclose(aidt1);
10341     CHECK(ret, FAIL, "H5Aclose");
10342     ret = H5Aclose(aidt2);
10343     CHECK(ret, FAIL, "H5Aclose");
10344 
10345     /* Close root groups */
10346     ret = H5Gclose(gid1);
10347     CHECK(ret, FAIL, "H5Gclose");
10348     ret = H5Gclose(gid2);
10349     CHECK(ret, FAIL, "H5Gclose");
10350 
10351     /* Close datasets */
10352     ret = H5Dclose(did1);
10353     CHECK(ret, FAIL, "H5Dclose");
10354     ret = H5Dclose(did2);
10355     CHECK(ret, FAIL, "H5Dclose");
10356 
10357     /* Close datatypes */
10358     ret = H5Tclose(tid1);
10359     CHECK(ret, FAIL, "H5Tclose");
10360     ret = H5Tclose(tid2);
10361     CHECK(ret, FAIL, "H5Tclose");
10362 
10363     /* Close files */
10364     ret = H5Fclose(fid1);
10365     CHECK(ret, FAIL, "H5Fclose");
10366     ret = H5Fclose(fid2);
10367     CHECK(ret, FAIL, "H5Fclose");
10368 }   /* test_attr_bug5() */
10369 
10370 /****************************************************************
10371 **
10372 **  test_attr_bug6(): Test basic H5A (attribute) code.
10373 **      Tests if reading an empty attribute is OK.
10374 **
10375 ****************************************************************/
10376 static void
test_attr_bug6(hid_t fcpl,hid_t fapl)10377 test_attr_bug6(hid_t fcpl, hid_t fapl)
10378 {
10379     hid_t   fid;            /* File ID */
10380     hid_t   gid;            /* Group ID */
10381     hid_t   aid1, aid2;     /* Attribute IDs */
10382     hid_t   sid;            /* Dataspace ID */
10383     hsize_t dims[ATTR1_RANK] = {ATTR1_DIM1};  /* Attribute dimensions */
10384     int     intar[ATTR1_DIM1];       /* Data reading buffer */
10385     herr_t  ret;            /* Generic return status */
10386 
10387     /* Output message about test being performed */
10388     MESSAGE(5, ("Testing that empty attribute can be read\n"));
10389 
10390     /* Create file */
10391     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
10392     CHECK(fid, FAIL, "H5Fcreate");
10393 
10394     /* Open root group */
10395     gid = H5Gopen2(fid, "/", H5P_DEFAULT);
10396     CHECK(gid, FAIL, "H5Gopen2");
10397 
10398     /* Create dataspace */
10399     sid = H5Screate_simple(1, dims, NULL);
10400     CHECK(sid, FAIL, "H5Screate_simple");
10401 
10402     /* Create attribute on group */
10403     aid1 = H5Acreate2(gid, ATTR1_NAME, H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT);
10404     CHECK(aid1, FAIL, "H5Acreate2");
10405 
10406     ret = H5Aclose(aid1);
10407     CHECK(ret, FAIL, "H5Aclose");
10408 
10409     /* Open the attribute again */
10410     aid2 = H5Aopen(gid, ATTR1_NAME, H5P_DEFAULT);
10411     CHECK(aid2, FAIL, "H5Aopen");
10412 
10413     ret = H5Aread(aid2, H5T_NATIVE_INT, intar);
10414     CHECK(ret, FAIL, "H5Aread");
10415 
10416     /* Close IDs */
10417     ret = H5Aclose(aid2);
10418     CHECK(ret, FAIL, "H5Aclose");
10419 
10420     ret = H5Gclose(gid);
10421     CHECK(ret, FAIL, "H5Gclose");
10422 
10423     ret = H5Fclose(fid);
10424     CHECK(ret, FAIL, "H5Fclose");
10425 
10426     ret = H5Sclose(sid);
10427     CHECK(ret, FAIL, "H5Sclose");
10428 }   /* test_attr_bug6() */
10429 
10430 /****************************************************************
10431 **
10432 **  test_attr_bug7(): Test basic H5A (attribute) code.
10433 **      (Really tests object header allocation code).
10434 **      Tests creating and deleting attributes in such a way as
10435 **      to change the size of the "chunk #0 size" field.
10436 **      Includes testing "skipping" a possible size of the
10437 **      field, i.e. going from 1 to 4 bytes or 4 to 1 byte.
10438 **
10439 ****************************************************************/
10440 static void
test_attr_bug7(hid_t fcpl,hid_t fapl)10441 test_attr_bug7(hid_t fcpl, hid_t fapl)
10442 {
10443     hid_t   fid;            /* File ID */
10444     hid_t   aid;            /* Attribute ID */
10445     hid_t   sid;            /* Dataspace ID */
10446     hid_t   tid;            /* Datatype ID */
10447     hsize_t dims_s = 140;   /* Small attribute dimensions */
10448     hsize_t dims_l = 65480; /* Large attribute dimensions */
10449     H5A_info_t ainfo;       /* Attribute info */
10450     herr_t  ret;            /* Generic return status */
10451 
10452     /* Output message about test being performed */
10453     MESSAGE(5, ("Testing adding and deleting large attributes\n"));
10454 
10455 
10456     /* Create committed datatype to operate on.  Use a committed datatype so that
10457      * there is nothing after the object header and the first chunk can expand and
10458      * contract as necessary. */
10459     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
10460     CHECK(fid, FAIL, "H5Fcreate");
10461     tid = H5Tcopy(H5T_STD_I32LE);
10462     CHECK(tid, FAIL, "H5Tcopy");
10463     ret = H5Tcommit2(fid, TYPE1_NAME, tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
10464     CHECK(ret, FAIL, "H5Tcommit2");
10465 
10466     /*
10467      * Create small attribute
10468      */
10469     sid = H5Screate_simple(1, &dims_s, NULL);
10470     CHECK(sid, FAIL, "H5Screate_simple");
10471     aid = H5Acreate2(tid, ATTR1_NAME, H5T_STD_I8LE, sid, H5P_DEFAULT, H5P_DEFAULT);
10472     CHECK(aid, FAIL, "H5Acreate2");
10473 
10474     /* Close file */
10475     ret = H5Aclose(aid);
10476     CHECK(ret, FAIL, "H5Aclose");
10477     ret = H5Fclose(fid);
10478     CHECK(ret, FAIL, "H5Fclose");
10479     ret = H5Tclose(tid);
10480     CHECK(ret, FAIL, "H5Tclose");
10481 
10482     /* Open file */
10483     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
10484     CHECK(fid, FAIL, "H5Fopen");
10485 
10486     /* Check attribute */
10487     tid = H5Topen2(fid, TYPE1_NAME, H5P_DEFAULT);
10488     CHECK(tid, FAIL, "H5Topen2");
10489     ret = H5Aget_info_by_name(tid, ".", ATTR1_NAME, &ainfo, H5P_DEFAULT);
10490     CHECK(ret, FAIL, "H5Aget_info_by_name");
10491     if(ainfo.data_size != dims_s)
10492         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_s);
10493 
10494     /*
10495      * Create another small attribute.  Should cause chunk size field to expand by
10496      * 1 byte (1->2).
10497      */
10498     aid = H5Acreate2(tid, ATTR2_NAME, H5T_STD_I8LE, sid, H5P_DEFAULT, H5P_DEFAULT);
10499     CHECK(aid, FAIL, "H5Acreate2");
10500 
10501     /* Close file */
10502     ret = H5Aclose(aid);
10503     CHECK(ret, FAIL, "H5Aclose");
10504     ret = H5Fclose(fid);
10505     CHECK(ret, FAIL, "H5Fclose");
10506     ret = H5Tclose(tid);
10507     CHECK(ret, FAIL, "H5Tclose");
10508 
10509     /* Open file */
10510     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
10511     CHECK(fid, FAIL, "H5Fopen");
10512 
10513     /* Check attributes */
10514     tid = H5Topen2(fid, TYPE1_NAME, H5P_DEFAULT);
10515     CHECK(tid, FAIL, "H5Topen2");
10516     ret = H5Aget_info_by_name(tid, ".", ATTR1_NAME, &ainfo, H5P_DEFAULT);
10517     CHECK(ret, FAIL, "H5Aget_info_by_name");
10518     if(ainfo.data_size != dims_s)
10519         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_s);
10520     ret = H5Aget_info_by_name(tid, ".", ATTR2_NAME, &ainfo, H5P_DEFAULT);
10521     CHECK(ret, FAIL, "H5Aget_info_by_name");
10522     if(ainfo.data_size != dims_s)
10523         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_s);
10524 
10525     /*
10526      * Create large attribute.  Should cause chunk size field to expand by 2 bytes
10527      * (2->4).
10528      */
10529     ret = H5Sset_extent_simple(sid, 1, &dims_l, NULL);
10530     CHECK(ret, FAIL, "H5Sset_extent_simple");
10531     aid = H5Acreate2(tid, ATTR3_NAME, H5T_STD_I8LE, sid, H5P_DEFAULT, H5P_DEFAULT);
10532     CHECK(aid, FAIL, "H5Acreate2");
10533 
10534     /* Close file */
10535     ret = H5Aclose(aid);
10536     CHECK(ret, FAIL, "H5Aclose");
10537     ret = H5Fclose(fid);
10538     CHECK(ret, FAIL, "H5Fclose");
10539     ret = H5Tclose(tid);
10540     CHECK(ret, FAIL, "H5Tclose");
10541 
10542     /* Open file */
10543     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
10544     CHECK(fid, FAIL, "H5Fopen");
10545 
10546     /* Check attributes */
10547     tid = H5Topen2(fid, TYPE1_NAME, H5P_DEFAULT);
10548     CHECK(tid, FAIL, "H5Topen2");
10549     ret = H5Aget_info_by_name(tid, ".", ATTR1_NAME, &ainfo, H5P_DEFAULT);
10550     CHECK(ret, FAIL, "H5Aget_info_by_name");
10551     if(ainfo.data_size != dims_s)
10552         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_s);
10553     ret = H5Aget_info_by_name(tid, ".", ATTR2_NAME, &ainfo, H5P_DEFAULT);
10554     CHECK(ret, FAIL, "H5Aget_info_by_name");
10555     if(ainfo.data_size != dims_s)
10556         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_s);
10557     ret = H5Aget_info_by_name(tid, ".", ATTR3_NAME, &ainfo, H5P_DEFAULT);
10558     CHECK(ret, FAIL, "H5Aget_info_by_name");
10559     if(ainfo.data_size != dims_l)
10560         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_l);
10561 
10562     /*
10563      * Delete last two attributes - should merge into a null message that is too
10564      * large, causing the chunk size field to shrink by 3 bytes (4->1).
10565      */
10566     ret = H5Sset_extent_simple(sid, 1, &dims_l, NULL);
10567     CHECK(ret, FAIL, "H5Sset_extent_simple");
10568     ret = H5Adelete(tid, ATTR2_NAME);
10569     CHECK(ret, FAIL, "H5Adelete");
10570     ret = H5Adelete(tid, ATTR3_NAME);
10571     CHECK(ret, FAIL, "H5Adelete");
10572 
10573     /* Close file */
10574     ret = H5Fclose(fid);
10575     CHECK(ret, FAIL, "H5Fclose");
10576     ret = H5Tclose(tid);
10577     CHECK(ret, FAIL, "H5Tclose");
10578 
10579     /* Open file */
10580     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
10581     CHECK(fid, FAIL, "H5Fopen");
10582 
10583     /* Check attribute */
10584     tid = H5Topen2(fid, TYPE1_NAME, H5P_DEFAULT);
10585     CHECK(tid, FAIL, "H5Topen2");
10586     ret = H5Aget_info_by_name(tid, ".", ATTR1_NAME, &ainfo, H5P_DEFAULT);
10587     CHECK(ret, FAIL, "H5Aget_info_by_name");
10588     if(ainfo.data_size != dims_s)
10589         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_s);
10590 
10591     /*
10592      * Create large attribute.  Should cause chunk size field to expand by 3 bytes
10593      * (1->4).
10594      */
10595     aid = H5Acreate2(tid, ATTR2_NAME, H5T_STD_I8LE, sid, H5P_DEFAULT, H5P_DEFAULT);
10596     CHECK(aid, FAIL, "H5Acreate2");
10597 
10598     /* Close file */
10599     ret = H5Aclose(aid);
10600     CHECK(ret, FAIL, "H5Aclose");
10601     ret = H5Fclose(fid);
10602     CHECK(ret, FAIL, "H5Fclose");
10603     ret = H5Tclose(tid);
10604     CHECK(ret, FAIL, "H5Tclose");
10605 
10606     /* Open file */
10607     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
10608     CHECK(fid, FAIL, "H5Fopen");
10609 
10610     /* Check attributes */
10611     tid = H5Topen2(fid, TYPE1_NAME, H5P_DEFAULT);
10612     CHECK(tid, FAIL, "H5Topen2");
10613     ret = H5Aget_info_by_name(tid, ".", ATTR1_NAME, &ainfo, H5P_DEFAULT);
10614     CHECK(ret, FAIL, "H5Aget_info_by_name");
10615     if(ainfo.data_size != dims_s)
10616         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_s);
10617     ret = H5Aget_info_by_name(tid, ".", ATTR2_NAME, &ainfo, H5P_DEFAULT);
10618     CHECK(ret, FAIL, "H5Aget_info_by_name");
10619     if(ainfo.data_size != dims_l)
10620         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims_l);
10621 
10622     /* Close IDs */
10623     ret = H5Tclose(tid);
10624     CHECK(ret, FAIL, "H5Tclose");
10625     ret = H5Sclose(sid);
10626     CHECK(ret, FAIL, "H5Sclose");
10627     ret = H5Fclose(fid);
10628     CHECK(ret, FAIL, "H5Fclose");
10629 }   /* test_attr_bug7() */
10630 
10631 /****************************************************************
10632 **
10633 **  test_attr_bug8(): Test basic H5A (attribute) code.
10634 **      (Really tests object header code).
10635 **      Tests adding a link and attribute to a group in such a
10636 **      way as to cause the "chunk #0 size" field to expand
10637 **      when some object header messages are not loaded into
10638 **      cache.  Before the bug was fixed, this would prevent
10639 **      these messages from being shifted to the correct
10640 **      position as the expansion algorithm marked them dirty,
10641 **      invalidating the raw form, when there was no native
10642 **      form to encode.
10643 **
10644 ****************************************************************/
10645 static void
test_attr_bug8(hid_t fcpl,hid_t fapl)10646 test_attr_bug8(hid_t fcpl, hid_t fapl)
10647 {
10648     hid_t   fid;            /* File ID */
10649     hid_t   aid;            /* Attribute ID */
10650     hid_t   sid;            /* Dataspace ID */
10651     hid_t   gid;            /* Group ID */
10652     hid_t   oid;            /* Object ID */
10653     hsize_t dims = 256;     /* Attribute dimensions */
10654     H5O_info_t oinfo;       /* Object info */
10655     H5A_info_t ainfo;       /* Attribute info */
10656     haddr_t root_addr;      /* Root group address */
10657     herr_t  ret;            /* Generic return status */
10658 
10659     /* Output message about test being performed */
10660     MESSAGE(5, ("Testing attribute expanding object header with undecoded messages\n"));
10661 
10662 
10663     /* Create committed datatype to operate on.  Use a committed datatype so that
10664      * there is nothing after the object header and the first chunk can expand and
10665      * contract as necessary. */
10666     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
10667     CHECK(fid, FAIL, "H5Fcreate");
10668     gid = H5Gcreate2(fid, GROUP1_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
10669     CHECK(gid, FAIL, "H5Gcreate2");
10670 
10671     /* Get root group address */
10672     ret = H5Oget_info2(fid, &oinfo, H5O_INFO_BASIC);
10673     CHECK(ret, FAIL, "H5Oget_info");
10674     root_addr = oinfo.addr;
10675 
10676     /*
10677      * Create link to root group
10678      */
10679     ret = H5Lcreate_hard(fid, "/", gid, LINK1_NAME, H5P_DEFAULT, H5P_DEFAULT);
10680     CHECK(ret, FAIL, "H5Lcreate_hard");
10681 
10682     /* Close file */
10683     ret = H5Fclose(fid);
10684     CHECK(ret, FAIL, "H5Fclose");
10685     ret = H5Gclose(gid);
10686     CHECK(ret, FAIL, "H5Gclose");
10687 
10688     /* Open file */
10689     fid = H5Fopen(FILENAME, H5F_ACC_RDONLY, fapl);
10690     CHECK(fid, FAIL, "H5Fopen");
10691 
10692     /* Check link */
10693     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
10694     CHECK(gid, FAIL, "H5Gopen2");
10695     oid = H5Oopen(gid, LINK1_NAME, H5P_DEFAULT);
10696     CHECK(oid, FAIL, "H5Oopen");
10697     ret = H5Oget_info2(oid, &oinfo, H5O_INFO_BASIC);
10698     CHECK(ret, FAIL, "H5Oget_info");
10699     if(oinfo.addr != root_addr)
10700         TestErrPrintf("incorrect link target address: addr: %llu, expected: %llu\n", (long long unsigned)oinfo.addr, (long long unsigned)root_addr);
10701 
10702     /* Close file */
10703     ret = H5Fclose(fid);
10704     CHECK(ret, FAIL, "H5Fclose");
10705     ret = H5Gclose(gid);
10706     CHECK(ret, FAIL, "H5Gclose");
10707     ret = H5Oclose(oid);
10708     CHECK(ret, FAIL, "H5Oclose");
10709 
10710     /* Open file */
10711     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
10712     CHECK(fid, FAIL, "H5Fopen");
10713 
10714     /*
10715      * Create attribute.  Should cause chunk size field to expand by 1 byte
10716      * (1->2).
10717      */
10718     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
10719     CHECK(gid, FAIL, "H5Gopen2");
10720     sid = H5Screate_simple(1, &dims, NULL);
10721     CHECK(sid, FAIL, "H5Screate_simple");
10722     aid = H5Acreate2(gid, ATTR1_NAME, H5T_STD_I8LE, sid, H5P_DEFAULT, H5P_DEFAULT);
10723     CHECK(aid, FAIL, "H5Acreate2");
10724 
10725     /* Close file */
10726     ret = H5Aclose(aid);
10727     CHECK(ret, FAIL, "H5Aclose");
10728     ret = H5Fclose(fid);
10729     CHECK(ret, FAIL, "H5Fclose");
10730     ret = H5Gclose(gid);
10731     CHECK(ret, FAIL, "H5Gclose");
10732 
10733     /* Open file */
10734     fid = H5Fopen(FILENAME, H5F_ACC_RDONLY, fapl);
10735     CHECK(fid, FAIL, "H5Fopen");
10736 
10737     /* Check link and attribute */
10738     gid = H5Gopen2(fid, GROUP1_NAME, H5P_DEFAULT);
10739     CHECK(gid, FAIL, "H5Gopen2");
10740     oid = H5Oopen(gid, LINK1_NAME, H5P_DEFAULT);
10741     CHECK(oid, FAIL, "H5Oopen");
10742     ret = H5Oget_info2(oid, &oinfo, H5O_INFO_BASIC);
10743     CHECK(ret, FAIL, "H5Oget_info");
10744     if(oinfo.addr != root_addr)
10745         TestErrPrintf("incorrect link target address: addr: %llu, expected: %llu\n", (long long unsigned)oinfo.addr, (long long unsigned)root_addr);
10746     ret = H5Aget_info_by_name(gid, ".", ATTR1_NAME, &ainfo, H5P_DEFAULT);
10747     CHECK(ret, FAIL, "H5Aget_info_by_name");
10748     if(ainfo.data_size != dims)
10749         TestErrPrintf("attribute data size different: data_size=%llu, should be %llu\n", (long long unsigned)ainfo.data_size, (long long unsigned)dims);
10750 
10751     /* Close IDs */
10752     ret = H5Oclose(oid);
10753     CHECK(ret, FAIL, "H5Oclose");
10754     ret = H5Gclose(gid);
10755     CHECK(ret, FAIL, "H5Gclose");
10756     ret = H5Sclose(sid);
10757     CHECK(ret, FAIL, "H5Sclose");
10758     ret = H5Fclose(fid);
10759     CHECK(ret, FAIL, "H5Fclose");
10760 }   /* test_attr_bug8() */
10761 
10762 /****************************************************************
10763 **
10764 **  test_attr_bug9(): Test basic H5A (attribute) code.
10765 **      (Really tests object header code).
10766 **      Tests adding several large attributes to an object until
10767 **      they convert to dense storage.  The total size of all
10768 **      attributes is larger than 64K, causing the internal
10769 **      object header code to, after merging the deleted
10770 **      messages in to a NULL message, shrink the object header
10771 **      chunk.  Do this twice: once with only attributes in the
10772 **      object header chunk and once with a (small) soft link in
10773 **      the chunk as well.  In both cases, the shrunk chunk will
10774 **      initally be too small and a new NULL message must be
10775 **      created.
10776 **
10777 ****************************************************************/
10778 static void
test_attr_bug9(hid_t fcpl,hid_t fapl)10779 test_attr_bug9(hid_t fcpl, hid_t fapl)
10780 {
10781     hid_t   fid = -1;       /* File ID */
10782     hid_t   gid = -1;       /* Group ID */
10783     hid_t   aid = -1;       /* Attribute ID */
10784     hid_t   sid = -1;       /* Dataspace ID */
10785     hsize_t dims[1] = {32768}; /* Attribute dimensions */
10786     int create_link;        /* Whether to create a soft link */
10787     unsigned max_compact;   /* Setting from fcpl */
10788     unsigned min_dense;     /* Setting from fcpl */
10789     char aname[11];         /* Attribute name */
10790     unsigned i;             /* Local index variable */
10791     herr_t  ret;            /* Generic return status */
10792 
10793     /* Output message about test being performed */
10794     MESSAGE(5, ("Testing that attributes can always be added to named datatypes\n"));
10795 
10796     /* Create dataspace */
10797     sid = H5Screate_simple(1, dims, NULL);
10798     CHECK(sid, FAIL, "H5Screate_simple");
10799 
10800     /* Obtain attribute phase change settings */
10801     ret = H5Pget_attr_phase_change(fcpl, &max_compact, &min_dense);
10802     CHECK(ret, FAIL, "H5Pget_attr_phase_change");
10803 
10804     /* Run with and without the soft link */
10805     for(create_link = 0; create_link < 2; create_link++) {
10806         /* Create file */
10807         fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
10808         CHECK(fid, FAIL, "H5Fcreate");
10809 
10810         /* Create second group */
10811         gid = H5Gcreate2(fid, "group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
10812         CHECK(gid, FAIL, "H5Gcreate2");
10813 
10814         /* Close second group */
10815         ret = H5Gclose(gid);
10816         CHECK(ret, FAIL, "H5Gclose");
10817 
10818         /* Open root group */
10819         gid = H5Gopen2(fid, "/", H5P_DEFAULT);
10820         CHECK(gid, FAIL, "H5Gopen2");
10821 
10822         /* Create enough attributes to cause a change to dense storage */
10823         for(i = 0; i < max_compact + 1; i++) {
10824             /* Create attribute */
10825             HDsnprintf(aname, sizeof(aname), "%u", i);
10826             aid = H5Acreate2(gid, aname, H5T_NATIVE_CHAR, sid, H5P_DEFAULT, H5P_DEFAULT);
10827             CHECK(aid, FAIL, "H5Acreate2");
10828 
10829             /* Close attribute */
10830             ret = H5Aclose(aid);
10831             CHECK(ret, FAIL, "H5Aclose");
10832 
10833             /* Create enough soft links that exactly one goes into chunk 1 if
10834              * requested */
10835             if(i == 0 && create_link) {
10836                 ret = H5Lcreate_soft("b", gid, "a", H5P_DEFAULT, H5P_DEFAULT);
10837                 CHECK(ret, FAIL, "H5Lcreate_soft");
10838                 ret = H5Lcreate_soft("d", gid, "c", H5P_DEFAULT, H5P_DEFAULT);
10839                 CHECK(ret, FAIL, "H5Lcreate_soft");
10840                 ret = H5Lcreate_soft("f", gid, "e", H5P_DEFAULT, H5P_DEFAULT);
10841                 CHECK(ret, FAIL, "H5Lcreate_soft");
10842             } /* end if */
10843         } /* end for */
10844 
10845         /* Close IDs */
10846         ret = H5Gclose(gid);
10847         CHECK(ret, FAIL, "H5Gclose");
10848 
10849         ret = H5Fclose(fid);
10850         CHECK(ret, FAIL, "H5Fclose");
10851     } /* end for */
10852 
10853     /* Close dataspace */
10854     ret = H5Sclose(sid);
10855     CHECK(ret, FAIL, "H5Sclose");
10856 }   /* test_attr_bug9() */
10857 
10858 /****************************************************************
10859 **
10860 **  test_attr_delete_dense():
10861 **      This is to verify the error as described in HDFFV-9277
10862 **      is fixed when deleting the last "large" attribute that
10863 **      is stored densely.
10864 **
10865 ****************************************************************/
10866 static void
test_attr_delete_last_dense(hid_t fcpl,hid_t fapl)10867 test_attr_delete_last_dense(hid_t fcpl, hid_t fapl)
10868 {
10869     hid_t fid;      /* File ID */
10870     hid_t gid;      /* Group ID */
10871     hid_t aid;      /* Attribute ID */
10872     hid_t sid;      /* Dataspace ID */
10873     hsize_t dim2[2] = {DIM0, DIM1}; /* Dimension sizes */
10874     int i, j;       /* Local index variables */
10875     double *data = NULL;    /* Pointer to the data buffer */
10876     herr_t ret;     /* Generic return status */
10877 
10878     /* Output message about test being performed */
10879     MESSAGE(5, ("Testing Deleting the last large attribute stored densely\n"));
10880 
10881     /* Create the file */
10882     fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
10883     CHECK(fid, FAIL, "H5Fcreate");
10884 
10885     /* Create the group */
10886     gid = H5Gcreate2(fid, GRPNAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
10887     CHECK(gid, FAIL, "H5Gcreate");
10888 
10889     /* Create the dataspace */
10890     sid = H5Screate_simple(RANK, dim2, NULL);
10891     CHECK(sid, FAIL, "H5Screate_simple");
10892 
10893     /* Attach the attribute to the group */
10894     aid = H5Acreate2(gid, ATTRNAME, H5T_IEEE_F64LE, sid, H5P_DEFAULT, H5P_DEFAULT);
10895     CHECK(aid, FAIL, "H5Acreate2");
10896 
10897     /* Allocate the data buffer */
10898     data = (double *)HDmalloc((size_t)(DIM0 * DIM1) * sizeof(double));
10899     CHECK_PTR(data, "HDmalloc");
10900 
10901     /* Initialize the data */
10902     for(i = 0; i < DIM0; i++)
10903         for(j = 0; j < DIM1; j++)
10904             *(data + i * DIM1 + j) = i + j;
10905 
10906     /* Write to the attribute */
10907     ret = H5Awrite(aid, H5T_NATIVE_DOUBLE, data);
10908     CHECK(ret, FAIL, "H5Awrite");
10909 
10910     /* Closing */
10911     ret = H5Aclose(aid);
10912     CHECK(ret, FAIL, "H5Aclose");
10913     ret = H5Sclose(sid);
10914     CHECK(ret, FAIL, "H5Sclose");
10915     ret = H5Gclose(gid);
10916     CHECK(ret, FAIL, "H5Gclose");
10917     ret = H5Fclose(fid);
10918     CHECK(ret, FAIL, "H5Fclose");
10919 
10920     /* Re-open the file */
10921     fid = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl);
10922     CHECK(fid, FAIL, "H5Fopen");
10923 
10924     /* Open the group */
10925     gid = H5Gopen2(fid, GRPNAME, H5P_DEFAULT);
10926     CHECK(gid, FAIL, "H5Gopen");
10927 
10928     /* Delete the attribute */
10929     ret = H5Adelete(gid, ATTRNAME);
10930     CHECK(ret, FAIL, "H5Adelete");
10931 
10932     /* Closing */
10933     ret = H5Gclose(gid);
10934     CHECK(ret, FAIL, "H5Gclose");
10935     ret = H5Fclose(fid);
10936     CHECK(ret, FAIL, "H5Fclose");
10937 
10938     /* Free the data buffer */
10939     if(data)
10940         HDfree(data);
10941 
10942 }   /* test_attr_delete_last_dense() */
10943 
10944 /****************************************************************
10945 **
10946 **  test_attr(): Main H5A (attribute) testing routine.
10947 **
10948 ****************************************************************/
10949 void
test_attr(void)10950 test_attr(void)
10951 {
10952     hid_t    fapl = (-1), fapl2 = (-1);    /* File access property lists */
10953     hid_t    fcpl = (-1), fcpl2 = (-1);    /* File creation property lists */
10954     hid_t    dcpl = -1;         /* Dataset creation property list */
10955     unsigned new_format;        /* Whether to use the new format or not */
10956     unsigned use_shared;        /* Whether to use shared attributes or not */
10957     unsigned minimize_dset_oh;  /* Whether to use minimized dataset object headers */
10958     herr_t ret;                 /* Generic return value */
10959 
10960     MESSAGE(5, ("Testing Attributes\n"));
10961 
10962     fapl = H5Pcreate(H5P_FILE_ACCESS);
10963     CHECK(fapl, FAIL, "H5Pcreate");
10964 
10965     /* fapl2 uses "latest version of the format" for creating objects in the file */
10966     fapl2 = H5Pcopy(fapl);
10967     CHECK(fapl2, FAIL, "H5Pcopy");
10968     ret = H5Pset_libver_bounds(fapl2, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
10969     CHECK(ret, FAIL, "H5Pset_libver_bounds");
10970 
10971     fcpl = H5Pcreate(H5P_FILE_CREATE);
10972     CHECK(fcpl, FAIL, "H5Pcreate");
10973 
10974     /* files with fcpl2 make all attributes ( > 1 byte) shared
10975      * (i.e. all of them :-) */
10976     fcpl2 = H5Pcopy(fcpl);
10977     CHECK(fcpl2, FAIL, "H5Pcopy");
10978     ret = H5Pset_shared_mesg_nindexes(fcpl2, (unsigned)1);
10979     CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
10980     ret = H5Pset_shared_mesg_index(fcpl2, (unsigned)0, H5O_SHMESG_ATTR_FLAG, (unsigned)1);
10981     CHECK_I(ret, "H5Pset_shared_mesg_index");
10982 
10983     for(minimize_dset_oh = 0; minimize_dset_oh <= 1; minimize_dset_oh++) {
10984         if(minimize_dset_oh == 0) {
10985             MESSAGE(7, ("testing with default dataset object headers\n"));
10986             dcpl_g = H5P_DEFAULT;
10987         } else {
10988             MESSAGE(7, ("testing with minimzied dataset object headers\n"));
10989             dcpl = H5Pcreate(H5P_DATASET_CREATE);
10990             CHECK(dcpl, FAIL, "H5Pcreate");
10991             ret = H5Pset_dset_no_attrs_hint(dcpl, TRUE);
10992             CHECK_I(ret, "H5Pset_dset_no_attrs_hint");
10993             dcpl_g = dcpl;
10994         }
10995 
10996         for(new_format = FALSE; new_format <= TRUE; new_format++) {
10997             hid_t my_fapl;
10998 
10999             /* Set the FAPL for the type of format */
11000             if(new_format) {
11001                 MESSAGE(7, ("testing with new file format\n"));
11002                 my_fapl = fapl2;
11003             } else {
11004                 MESSAGE(7, ("testing with old file format\n"));
11005                 my_fapl = fapl;
11006             }
11007 
11008             /* These next two tests use the same file information */
11009             test_attr_basic_write(my_fapl);    /* Test basic H5A writing code */
11010             test_attr_basic_read(my_fapl);     /* Test basic H5A reading code */
11011 
11012             /* These next two tests use their own file information */
11013             test_attr_flush(my_fapl);          /* Test H5A I/O in the presence of H5Fflush calls */
11014             test_attr_plist(my_fapl);          /* Test attribute property lists */
11015 
11016             /* These next two tests use the same file information */
11017             test_attr_compound_write(my_fapl);  /* Test complex datatype H5A writing code */
11018             test_attr_compound_read(my_fapl);   /* Test complex datatype H5A reading code */
11019 
11020             /* These next two tests use the same file information */
11021             test_attr_scalar_write(my_fapl);  /* Test scalar dataspace H5A writing code */
11022             test_attr_scalar_read(my_fapl);   /* Test scalar dataspace H5A reading code */
11023 
11024             /* These next four tests use the same file information */
11025             test_attr_mult_write(my_fapl);     /* Test H5A writing code for multiple attributes */
11026             test_attr_mult_read(my_fapl);      /* Test H5A reading code for multiple attributes */
11027             test_attr_iterate(my_fapl);        /* Test H5A iterator code */
11028             test_attr_delete(my_fapl);         /* Test H5A code for deleting attributes */
11029 
11030             /* This next test uses its own file information */
11031             test_attr_dtype_shared(my_fapl);   /* Test using shared dataypes in attributes */
11032 
11033             /* This next test uses its own file information */
11034             test_attr_duplicate_ids(my_fapl);
11035 
11036             for(use_shared = FALSE; use_shared <= TRUE; use_shared++) {
11037                 hid_t my_fcpl;
11038 
11039                 if(new_format == TRUE && use_shared) {
11040                     MESSAGE(7, ("testing with shared attributes\n"));
11041                     my_fcpl = fcpl2;
11042                 } else {
11043                     MESSAGE(7, ("testing without shared attributes\n"));
11044                     my_fcpl = fcpl;
11045                 }
11046 
11047                 test_attr_big(my_fcpl, my_fapl);                /* Test storing big attribute */
11048                 test_attr_null_space(my_fcpl, my_fapl);         /* Test storing attribute with NULL dataspace */
11049                 test_attr_deprec(fcpl, my_fapl);                /* Test deprecated API routines */
11050                 test_attr_many(new_format, my_fcpl, my_fapl);               /* Test storing lots of attributes */
11051 
11052                 /* New attribute API routine tests */
11053                 test_attr_info_by_idx(new_format, my_fcpl, my_fapl);    /* Test querying attribute info by index */
11054                 test_attr_delete_by_idx(new_format, my_fcpl, my_fapl);  /* Test deleting attribute by index */
11055                 test_attr_iterate2(new_format, my_fcpl, my_fapl);       /* Test iterating over attributes by index */
11056                 test_attr_open_by_idx(new_format, my_fcpl, my_fapl);    /* Test opening attributes by index */
11057                 test_attr_open_by_name(new_format, my_fcpl, my_fapl);   /* Test opening attributes by name */
11058                 test_attr_create_by_name(new_format, my_fcpl, my_fapl); /* Test creating attributes by name */
11059 
11060                 /* Tests that address specific bugs */
11061                 test_attr_bug1(my_fcpl, my_fapl);               /* Test odd allocation operations */
11062                 test_attr_bug2(my_fcpl, my_fapl);               /* Test many deleted attributes */
11063                 test_attr_bug3(my_fcpl, my_fapl);               /* Test "self referential" attributes */
11064                 test_attr_bug4(my_fcpl, my_fapl);               /* Test attributes on named datatypes */
11065                 test_attr_bug5(my_fcpl, my_fapl);               /* Test opening/closing attributes through different file handles */
11066                 test_attr_bug6(my_fcpl, my_fapl);               /* Test reading empty attribute */
11067                 /* test_attr_bug7 is specific to the "new" object header format,
11068                  * and in fact fails if used with the old format due to the
11069                  * attributes being larger than 64K */
11070                 test_attr_bug8(my_fcpl, my_fapl);               /* Test attribute expanding object header with undecoded messages */
11071                 test_attr_bug9(my_fcpl, my_fapl);               /* Test large attributes converting to dense storage */
11072 
11073                 /* tests specific to the "new format" */
11074                 if (new_format == TRUE) {
11075                     /* General attribute tests */
11076                     test_attr_dense_create(my_fcpl, my_fapl);       /* Test dense attribute storage creation */
11077                     test_attr_dense_open(my_fcpl, my_fapl);         /* Test opening attributes in dense storage */
11078                     test_attr_dense_delete(my_fcpl, my_fapl);       /* Test deleting attributes in dense storage */
11079                     test_attr_dense_rename(my_fcpl, my_fapl);       /* Test renaming attributes in dense storage */
11080                     test_attr_dense_unlink(my_fcpl, my_fapl);       /* Test unlinking object with attributes in dense storage */
11081                     test_attr_dense_limits(my_fcpl, my_fapl);       /* Test dense attribute storage limits */
11082                     test_attr_dense_dup_ids(my_fcpl, my_fapl);      /* Test duplicated IDs for dense attribute storage */
11083 
11084                     /* Attribute creation order tests */
11085                     test_attr_corder_create_basic(my_fcpl, my_fapl);/* Test creating an object w/attribute creation order info */
11086                     test_attr_corder_create_compact(my_fcpl, my_fapl);  /* Test compact attribute storage on an object w/attribute creation order info */
11087                     test_attr_corder_create_dense(my_fcpl, my_fapl);/* Test dense attribute storage on an object w/attribute creation order info */
11088                     test_attr_corder_create_reopen(my_fcpl, my_fapl);/* Test creating attributes w/reopening file from using new format to using old format */
11089                     test_attr_corder_transition(my_fcpl, my_fapl);  /* Test attribute storage transitions on an object w/attribute creation order info */
11090                     test_attr_corder_delete(my_fcpl, my_fapl);      /* Test deleting object using dense storage w/attribute creation order info */
11091 
11092                     /* More complex tests with exclusively both "new format" and "shared" attributes */
11093                     if(use_shared == TRUE) {
11094                         test_attr_shared_write(my_fcpl, my_fapl);   /* Test writing to shared attributes in compact & dense storage */
11095                         test_attr_shared_rename(my_fcpl, my_fapl);  /* Test renaming shared attributes in compact & dense storage */
11096                         test_attr_shared_delete(my_fcpl, my_fapl);  /* Test deleting shared attributes in compact & dense storage */
11097                         test_attr_shared_unlink(my_fcpl, my_fapl);  /* Test unlinking object with shared attributes in compact & dense storage */
11098                     } /* if using shared attributes */
11099 
11100                     test_attr_delete_last_dense(my_fcpl, my_fapl);
11101 
11102                     /* test_attr_bug7 is specific to the "new" object header format,
11103                      * and in fact fails if used with the old format due to the
11104                      * attributes being larger than 64K */
11105                     test_attr_bug7(my_fcpl, my_fapl);               /* Test creating and deleting large attributes in ohdr chunk 0 */
11106 
11107                 } /* if using "new format" */
11108             } /* for unshared/shared attributes */
11109         } /* for old/new format */
11110 
11111         if (minimize_dset_oh != 0) {
11112             ret = H5Pclose(dcpl);
11113             CHECK(ret, FAIL, "H5Pclose");
11114             dcpl_g = H5P_DEFAULT;
11115         }
11116 
11117     } /* for default/minimized dataset object headers */
11118 
11119     /* Close  FCPLs */
11120     ret = H5Pclose(fcpl);
11121     CHECK(ret, FAIL, "H5Pclose");
11122     ret = H5Pclose(fcpl2);
11123     CHECK(ret, FAIL, "H5Pclose");
11124 
11125     /* Close  FAPLs */
11126     ret = H5Pclose(fapl);
11127     CHECK(ret, FAIL, "H5Pclose");
11128     ret = H5Pclose(fapl2);
11129     CHECK(ret, FAIL, "H5Pclose");
11130 }   /* test_attr() */
11131 
11132 
11133 /*-------------------------------------------------------------------------
11134  * Function:    cleanup_attr
11135  *
11136  * Purpose:    Cleanup temporary test files
11137  *
11138  * Return:    none
11139  *
11140  * Programmer:    Albert Cheng
11141  *              July 2, 1998
11142  *
11143  * Modifications:
11144  *
11145  *-------------------------------------------------------------------------
11146  */
11147 void
cleanup_attr(void)11148 cleanup_attr(void)
11149 {
11150     HDremove(FILENAME);
11151 }
11152 
11153