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 #include <stdlib.h>
15 #include <string.h>
16 #include "h5hltest.h"
17 #include "H5srcdir.h"
18 #include "H5LTpublic.h"
19
20 #define FILE_NAME "test_lite1.h5"
21 #define FILE_NAME2 "test_lite2.h5"
22 #define FILE_NAME3 "test_lite3.h5"
23 #define FILE_NAME4 "test_lite4.h5"
24 #define INPUT_FILE "dtype_file.txt"
25
26 #define DSET0_NAME "2D int array"
27 #define DSET1_NAME "dataset char"
28 #define DSET2_NAME "dataset short"
29 #define DSET3_NAME "dataset int"
30 #define DSET4_NAME "dataset long"
31 #define DSET5_NAME "dataset float"
32 #define DSET6_NAME "dataset double"
33 #define DSET7_NAME "dataset string"
34
35 #define DIM 6
36
37 #define ATTR_NAME_SUB "att"
38 #define ATTR1_NAME "attr string"
39 #define ATTR2_NAME "attr char"
40 #define ATTR3_NAME "attr short"
41 #define ATTR4_NAME "attr int"
42 #define ATTR_NAME_EXT "att int ext"
43 #define ATTR5_NAME "attr long"
44 #define ATTR6_NAME "attr uchar"
45 #define ATTR7_NAME "attr ushort"
46 #define ATTR8_NAME "attr uint"
47 #define ATTR9_NAME "attr ulong"
48 #define ATTR10_NAME "attr float"
49 #define ATTR11_NAME "attr double"
50
51 static herr_t make_attributes( hid_t loc_id, const char* obj_name );
52
53
54 /*-------------------------------------------------------------------------
55 * test dataset functions
56 *-------------------------------------------------------------------------
57 */
58
test_dsets(void)59 static int test_dsets( void )
60 {
61 int rank = 2;
62 hsize_t dims[2] = {2,3};
63 hid_t file_id;
64 hid_t dataset_id;
65 char data_char_in[DIM] = {1,2,3,4,5,6};
66 char data_char_out[DIM];
67 short data_short_in[DIM] = {1,2,3,4,5,6};
68 short data_short_out[DIM];
69 int data_int_in[DIM] = {1,2,3,4,5,6};
70 int data_int_out[DIM];
71 long data_long_in[DIM] = {1,2,3,4,5,6};
72 long data_long_out[DIM];
73 float data_float_in[DIM] = {1,2,3,4,5,6};
74 float data_float_out[DIM];
75 double data_double_in[DIM] = {1,2,3,4,5,6};
76 double data_double_out[DIM];
77 const char *data_string_in = "This is a string";
78 char data_string_out[20];
79 int i;
80
81
82 /* Create a new file using default properties. */
83 file_id = H5Fcreate( FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
84
85 /*-------------------------------------------------------------------------
86 * H5LTmake_dataset test
87 *-------------------------------------------------------------------------
88 */
89
90 TESTING("H5LTmake_dataset");
91
92 /* Make dataset */
93 if ( H5LTmake_dataset( file_id, DSET0_NAME, rank, dims, H5T_NATIVE_INT, data_int_in ) < 0 )
94 goto out;
95
96 /* Read dataset using the basic HDF5 API */
97
98 if ( ( dataset_id = H5Dopen2(file_id, DSET0_NAME, H5P_DEFAULT) ) < 0 )
99 goto out;
100
101 if ( H5Dread ( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_int_out ) < 0 )
102 goto out;
103
104 if ( H5Dclose( dataset_id ) < 0 )
105 goto out;
106
107 for (i = 0; i < DIM; i++)
108 {
109 if ( data_int_in[i] != data_int_out[i] ) {
110 goto out;
111 }
112 }
113
114 PASSED();
115
116 /*-------------------------------------------------------------------------
117 * read using the LT function H5LTread_dataset
118 *-------------------------------------------------------------------------
119 */
120
121 TESTING("H5LTread_dataset");
122
123 if ( H5LTread_dataset( file_id, DSET0_NAME, H5T_NATIVE_INT, data_int_out ) < 0 )
124 goto out;
125
126 for (i = 0; i < DIM; i++)
127 {
128 if ( data_int_in[i] != data_int_out[i] ) {
129 goto out;
130 }
131 }
132
133 PASSED();
134
135 /*-------------------------------------------------------------------------
136 * test the H5LTmake_dataset_ functions
137 *-------------------------------------------------------------------------
138 */
139
140
141 /*-------------------------------------------------------------------------
142 * H5LTmake_dataset_char
143 *-------------------------------------------------------------------------
144 */
145
146 TESTING("H5LTmake_dataset_char");
147
148 /* Make dataset char */
149 if ( H5LTmake_dataset_char( file_id, DSET1_NAME, rank, dims, data_char_in ) < 0 )
150 goto out;
151
152 /* Read dataset */
153 if ( H5LTread_dataset( file_id, DSET1_NAME, H5T_NATIVE_CHAR, data_char_out ) < 0 )
154 goto out;
155
156 for (i = 0; i < DIM; i++)
157 {
158 if ( data_char_in[i] != data_char_out[i] ) {
159 goto out;
160 }
161 }
162
163 /* Read dataset */
164 if ( H5LTread_dataset_char( file_id, DSET1_NAME, data_char_out ) < 0 )
165 goto out;
166
167 for (i = 0; i < DIM; i++)
168 {
169 if ( data_char_in[i] != data_char_out[i] ) {
170 goto out;
171 }
172 }
173
174 PASSED();
175
176
177 /*-------------------------------------------------------------------------
178 * H5LTmake_dataset_short
179 *-------------------------------------------------------------------------
180 */
181
182 TESTING("H5LTmake_dataset_short");
183
184 /* Make dataset short */
185 if ( H5LTmake_dataset_short( file_id, DSET2_NAME, rank, dims, data_short_in ) < 0 )
186 goto out;
187
188 /* Read dataset */
189 if ( H5LTread_dataset( file_id, DSET2_NAME, H5T_NATIVE_SHORT, data_short_out ) < 0 )
190 goto out;
191
192 for (i = 0; i < DIM; i++)
193 {
194 if ( data_short_in[i] != data_short_out[i] ) {
195 goto out;
196 }
197 }
198
199 /* Read dataset */
200 if ( H5LTread_dataset_short( file_id, DSET2_NAME, data_short_out ) < 0 )
201 goto out;
202
203 for (i = 0; i < DIM; i++)
204 {
205 if ( data_short_in[i] != data_short_out[i] ) {
206 goto out;
207 }
208 }
209
210 PASSED();
211
212 /*-------------------------------------------------------------------------
213 * H5LTmake_dataset_int
214 *-------------------------------------------------------------------------
215 */
216
217 TESTING("H5LTmake_dataset_int");
218
219 /* Make dataset int */
220 if ( H5LTmake_dataset_int( file_id, DSET3_NAME, rank, dims, data_int_in ) < 0 )
221 goto out;
222
223 /* Read dataset */
224 if ( H5LTread_dataset( file_id, DSET3_NAME, H5T_NATIVE_INT, data_int_out ) < 0 )
225 goto out;
226
227 for (i = 0; i < DIM; i++)
228 {
229 if ( data_int_in[i] != data_int_out[i] ) {
230 goto out;
231 }
232 }
233
234 /* Read dataset */
235 if ( H5LTread_dataset_int( file_id, DSET3_NAME, data_int_out ) < 0 )
236 goto out;
237
238 for (i = 0; i < DIM; i++)
239 {
240 if ( data_int_in[i] != data_int_out[i] ) {
241 goto out;
242 }
243 }
244
245 PASSED();
246
247
248 /*-------------------------------------------------------------------------
249 * H5LTmake_dataset_long
250 *-------------------------------------------------------------------------
251 */
252
253 TESTING("H5LTmake_dataset_long");
254
255 /* Make dataset long */
256 if ( H5LTmake_dataset_long( file_id, DSET4_NAME, rank, dims, data_long_in ) < 0 )
257 goto out;
258
259 /* Read dataset */
260 if ( H5LTread_dataset( file_id, DSET4_NAME, H5T_NATIVE_LONG, data_long_out ) < 0 )
261 goto out;
262
263 for (i = 0; i < DIM; i++)
264 {
265 if ( data_long_in[i] != data_long_out[i] ) {
266 goto out;
267 }
268 }
269
270 /* Read dataset */
271 if ( H5LTread_dataset_long( file_id, DSET4_NAME, data_long_out ) < 0 )
272 goto out;
273
274 for (i = 0; i < DIM; i++)
275 {
276 if ( data_long_in[i] != data_long_out[i] ) {
277 goto out;
278 }
279 }
280
281 PASSED();
282
283
284 /*-------------------------------------------------------------------------
285 * H5LTmake_dataset_float
286 *-------------------------------------------------------------------------
287 */
288
289 TESTING("H5LTmake_dataset_float");
290
291 /* Make dataset float */
292 if ( H5LTmake_dataset_float( file_id, DSET5_NAME, rank, dims, data_float_in ) < 0 )
293 goto out;
294
295 /* Read dataset */
296 if ( H5LTread_dataset( file_id, DSET5_NAME, H5T_NATIVE_FLOAT, data_float_out ) < 0 )
297 goto out;
298
299 for (i = 0; i < DIM; i++)
300 {
301 if(!FLT_ABS_EQUAL(data_float_in[i],data_float_out[i])) {
302 goto out;
303 }
304 }
305
306 /* Read dataset */
307 if ( H5LTread_dataset_float( file_id, DSET5_NAME, data_float_out ) < 0 )
308 goto out;
309
310 for (i = 0; i < DIM; i++)
311 {
312 if(!FLT_ABS_EQUAL(data_float_in[i],data_float_out[i])) {
313 goto out;
314 }
315 }
316
317 PASSED();
318
319
320 /*-------------------------------------------------------------------------
321 * H5LTmake_dataset_double
322 *-------------------------------------------------------------------------
323 */
324
325 TESTING("H5LTmake_dataset_double");
326
327 /* Make dataset double */
328 if ( H5LTmake_dataset_double( file_id, DSET6_NAME, rank, dims, data_double_in ) < 0 )
329 goto out;
330
331 /* Read dataset */
332 if ( H5LTread_dataset( file_id, DSET6_NAME, H5T_NATIVE_DOUBLE, data_double_out ) < 0 )
333 goto out;
334
335 for (i = 0; i < DIM; i++)
336 {
337 if(!DBL_ABS_EQUAL(data_double_in[i],data_double_out[i])) {
338 goto out;
339 }
340 }
341
342 /* Read dataset */
343 if ( H5LTread_dataset_double( file_id, DSET6_NAME, data_double_out ) < 0 )
344 goto out;
345
346 for (i = 0; i < DIM; i++)
347 {
348 if(!DBL_ABS_EQUAL(data_double_in[i],data_double_out[i])) {
349 goto out;
350 }
351 }
352
353 PASSED();
354
355
356 /*-------------------------------------------------------------------------
357 * H5LTmake_dataset_string
358 *-------------------------------------------------------------------------
359 */
360
361 TESTING("H5LTmake_dataset_string");
362
363 /* Make dataset string */
364 if ( H5LTmake_dataset_string(file_id,DSET7_NAME,data_string_in) < 0 )
365 goto out;
366
367 /* Read dataset */
368 if ( H5LTread_dataset_string(file_id,DSET7_NAME,data_string_out) < 0 )
369 goto out;
370
371 if ( HDstrcmp(data_string_in,data_string_out) != 0 )
372 goto out;
373
374
375
376 /*-------------------------------------------------------------------------
377 * end tests
378 *-------------------------------------------------------------------------
379 */
380
381 /* Close the file. */
382 H5Fclose( file_id );
383
384 PASSED();
385
386
387 return 0;
388
389 out:
390 /* Close the file. */
391 H5_FAILED();
392 return -1;
393 }
394
395 /*-------------------------------------------------------------------------
396 * test attribute functions
397 *-------------------------------------------------------------------------
398 */
399
test_attr(void)400 static int test_attr(void)
401 {
402 hid_t file_id;
403 hid_t dataset_id;
404 hid_t group_id;
405 hid_t space_id;
406 hsize_t dims[1] = { 5 };
407
408 /* Create a new file using default properties. */
409 file_id = H5Fcreate(FILE_NAME2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
410
411 /*-------------------------------------------------------------------------
412 * Create a dataset named "dset" on the root group
413 *-------------------------------------------------------------------------
414 */
415
416 /* Create the data space */
417 if((space_id = H5Screate_simple(1, dims, NULL)) < 0) goto out;
418
419 /* Create the dataset */
420 if((dataset_id = H5Dcreate2(file_id , "dset", H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out;
421
422 /* Close */
423 H5Dclose(dataset_id);
424
425 /*-------------------------------------------------------------------------
426 * Create a group named "grp" on the root group
427 *-------------------------------------------------------------------------
428 */
429
430 /* Create a group. */
431 if((group_id = H5Gcreate2(file_id, "grp", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out;
432
433 /* Close */
434 H5Gclose(group_id);
435
436 /*-------------------------------------------------------------------------
437 *
438 * Create attributes in the root group
439 * Note that we are calling the H5LTset_attribute functions with the name "."
440 *
441 *-------------------------------------------------------------------------
442 */
443 if(make_attributes(file_id, ".") < 0) goto out;
444
445 /*-------------------------------------------------------------------------
446 *
447 * Create attributes in the dataset "dset"
448 *
449 *-------------------------------------------------------------------------
450 */
451 if(make_attributes(file_id, "dset") < 0) goto out;
452
453 /*-------------------------------------------------------------------------
454 *
455 * Create attributes in the group "grp"
456 *
457 *-------------------------------------------------------------------------
458 */
459 if(make_attributes(file_id, "grp") < 0) goto out;
460
461 /*-------------------------------------------------------------------------
462 * end
463 *-------------------------------------------------------------------------
464 */
465 /* Close the file. */
466 H5Fclose(file_id);
467
468 return 0;
469
470 out:
471 /* Close the file. */
472 H5Fclose(file_id);
473
474 H5_FAILED();
475 return -1;
476 }
477
478 /*-------------------------------------------------------------------------
479 * make_attributes
480 *-------------------------------------------------------------------------
481 */
482
make_attributes(hid_t loc_id,const char * obj_name)483 static herr_t make_attributes( hid_t loc_id, const char* obj_name )
484 {
485
486 int rank_out;
487 hsize_t *dims_out = 0;
488 H5T_class_t type_class;
489 size_t type_size;
490 int i;
491
492 char attr_str_in[] = {"My attribute"};
493 char attr_str_out[20];
494 char attr_char_in[5] = {1,2,3,4,5};
495 char attr_char_out[5];
496 short attr_short_in[5] = {1,2,3,4,5};
497 short attr_short_out[5];
498 int attr_int_in[5] = {1,2,3,4,5};
499 int attr_int_out[5];
500 long attr_long_in[5] = {1,2,3,4,5};
501 long attr_long_out[5];
502 float attr_float_in[5] = {1,2,3,4,5};
503 float attr_float_out[5];
504 double attr_double_in[5] = {1,2,3,4,5};
505 double attr_double_out[5];
506 unsigned char attr_uchar_in[5] = {1,2,3,4,5};
507 unsigned char attr_uchar_out[5];
508 unsigned short attr_ushort_in[5] = {1,2,3,4,5};
509 unsigned short attr_ushort_out[5];
510 unsigned int attr_uint_in[5] = {1,2,3,4,5};
511 unsigned int attr_uint_out[5];
512 unsigned long attr_ulong_in[5] = {1,2,3,4,5};
513 unsigned long attr_ulong_out[5];
514
515 /*-------------------------------------------------------------------------
516 * H5LTset_attribute_string test
517 *-------------------------------------------------------------------------
518 */
519
520 TESTING("H5LTset_attribute_string");
521
522 /* Set the attribute */
523 if ( H5LTset_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_in ) < 0 )
524 return -1;
525
526 PASSED();
527
528 /*-------------------------------------------------------------------------
529 * H5LTset_attribute_string test
530 *-------------------------------------------------------------------------
531 */
532
533 TESTING("H5LTget_attribute_string");
534
535
536 /* Get the attribute */
537 if ( H5LTget_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_out ) < 0 )
538 return -1;
539
540 if ( HDstrcmp( attr_str_in, attr_str_out ) != 0 )
541 {
542 return -1;
543 }
544
545 PASSED();
546
547
548 /*-------------------------------------------------------------------------
549 * H5LTset_attribute_char test
550 *-------------------------------------------------------------------------
551 */
552
553 TESTING("H5LTset_attribute_char");
554
555 /* Set the attribute */
556 if ( H5LTset_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_in, (size_t)5 ) < 0 )
557 return -1;
558
559 PASSED();
560
561 /*-------------------------------------------------------------------------
562 * H5LTget_attribute_char test
563 *-------------------------------------------------------------------------
564 */
565
566 TESTING("H5LTget_attribute_char");
567
568 /* Get the attribute */
569 if ( H5LTget_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_out ) < 0 )
570 return -1;
571
572 for (i = 0; i < 5; i++)
573 {
574 if ( attr_char_in[i] != attr_char_out[i] ) {
575 return -1;
576 }
577 }
578
579 /* Get the attribute */
580 if ( H5LTget_attribute( loc_id, obj_name, ATTR2_NAME, H5T_NATIVE_CHAR, attr_char_out ) < 0 )
581 return -1;
582
583 for (i = 0; i < 5; i++)
584 {
585 if ( attr_char_in[i] != attr_char_out[i] ) {
586 return -1;
587 }
588 }
589
590 PASSED();
591
592 /*-------------------------------------------------------------------------
593 * H5LTset_attribute_short test
594 *-------------------------------------------------------------------------
595 */
596
597 TESTING("H5LTset_attribute_short");
598
599 /* Set the attribute */
600 if ( H5LTset_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_in, (size_t)5 ) < 0 )
601 return -1;
602
603 PASSED();
604
605
606 /*-------------------------------------------------------------------------
607 * H5LTget_attribute_short test
608 *-------------------------------------------------------------------------
609 */
610
611 TESTING("H5LTget_attribute_short");
612
613 /* Get the attribute */
614 if ( H5LTget_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_out ) < 0 )
615 return -1;
616
617 for (i = 0; i < 5; i++)
618 {
619 if ( attr_short_in[i] != attr_short_out[i] ) {
620 return -1;
621 }
622 }
623
624 /* Get the attribute */
625 if ( H5LTget_attribute( loc_id, obj_name, ATTR3_NAME, H5T_NATIVE_SHORT, attr_short_out ) < 0 )
626 return -1;
627
628 for (i = 0; i < 5; i++)
629 {
630 if ( attr_short_in[i] != attr_short_out[i] ) {
631 return -1;
632 }
633 }
634
635 PASSED();
636
637
638 /*-------------------------------------------------------------------------
639 * H5LTset_attribute_int test
640 *-------------------------------------------------------------------------
641 */
642
643 TESTING("H5LTset_attribute_int");
644
645 /* Set the attribute */
646 if ( H5LTset_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_in, (size_t)5 ) < 0 )
647 return -1;
648
649 /* Set the attribute which is a substring of an existing attribute */
650 if ( H5LTset_attribute_int( loc_id, obj_name, ATTR_NAME_SUB, attr_int_in, (size_t)5 ) < 0 )
651 return -1;
652
653 /* Set the attribute which is an extension of an existing attribute */
654 if ( H5LTset_attribute_int( loc_id, obj_name, ATTR_NAME_EXT, attr_int_in, (size_t)5 ) < 0 )
655 return -1;
656
657 PASSED();
658
659 /*-------------------------------------------------------------------------
660 * H5LTget_attribute_int test
661 *-------------------------------------------------------------------------
662 */
663
664 TESTING("H5LTget_attribute_int");
665
666 /* Get the attribute */
667 if ( H5LTget_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_out ) < 0 )
668 return -1;
669
670 for (i = 0; i < 5; i++)
671 {
672 if ( attr_int_in[i] != attr_int_out[i] ) {
673 return -1;
674 }
675 }
676
677 if ( H5LTget_attribute_int( loc_id, obj_name, ATTR_NAME_SUB, attr_int_out ) < 0 )
678 return -1;
679
680 for (i = 0; i < 5; i++)
681 {
682 if ( attr_int_in[i] != attr_int_out[i] ) {
683 return -1;
684 }
685 }
686
687 if ( H5LTget_attribute_int( loc_id, obj_name, ATTR_NAME_EXT, attr_int_out ) < 0 )
688 return -1;
689
690 for (i = 0; i < 5; i++)
691 {
692 if ( attr_int_in[i] != attr_int_out[i] ) {
693 return -1;
694 }
695 }
696
697 /* Get the attribute */
698 if ( H5LTget_attribute( loc_id, obj_name, ATTR4_NAME, H5T_NATIVE_INT, attr_int_out ) < 0 )
699 return -1;
700
701 for (i = 0; i < 5; i++)
702 {
703 if ( attr_int_in[i] != attr_int_out[i] ) {
704 return -1;
705 }
706 }
707
708 PASSED();
709
710 /*-------------------------------------------------------------------------
711 * H5LTset_attribute_long test
712 *-------------------------------------------------------------------------
713 */
714
715 TESTING("H5LTset_attribute_long");
716
717 /* Set the attribute */
718 if ( H5LTset_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_in, (size_t)5 ) < 0 )
719 return -1;
720
721 PASSED();
722
723 /*-------------------------------------------------------------------------
724 * H5LTget_attribute_long test
725 *-------------------------------------------------------------------------
726 */
727
728 TESTING("H5LTget_attribute_long");
729
730 /* Get the attribute */
731 if ( H5LTget_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_out ) < 0 )
732 return -1;
733
734 for (i = 0; i < 5; i++)
735 {
736 if ( attr_long_in[i] != attr_long_out[i] ) {
737 return -1;
738 }
739 }
740
741 /* Get the attribute */
742 if ( H5LTget_attribute( loc_id, obj_name, ATTR5_NAME, H5T_NATIVE_LONG, attr_long_out ) < 0 )
743 return -1;
744
745 for (i = 0; i < 5; i++)
746 {
747 if ( attr_long_in[i] != attr_long_out[i] ) {
748 return -1;
749 }
750 }
751
752 PASSED();
753
754 /*-------------------------------------------------------------------------
755 * H5LTset_attribute_uchar test
756 *-------------------------------------------------------------------------
757 */
758
759 TESTING("H5LTset_attribute_uchar");
760
761 /* Set the attribute */
762 if ( H5LTset_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_in, (size_t)5 ) < 0 )
763 return -1;
764
765 PASSED();
766
767 /*-------------------------------------------------------------------------
768 * H5LTget_attribute_uchar test
769 *-------------------------------------------------------------------------
770 */
771
772 TESTING("H5LTget_attribute_uchar");
773
774 /* Get the attribute */
775 if ( H5LTget_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_out ) < 0 )
776 return -1;
777
778 for (i = 0; i < 5; i++)
779 {
780 if ( attr_uchar_in[i] != attr_uchar_out[i] ) {
781 return -1;
782 }
783 }
784
785 /* Get the attribute */
786 if ( H5LTget_attribute( loc_id, obj_name, ATTR6_NAME, H5T_NATIVE_UCHAR, attr_uchar_out ) < 0 )
787 return -1;
788
789 for (i = 0; i < 5; i++)
790 {
791 if ( attr_uchar_in[i] != attr_uchar_out[i] ) {
792 return -1;
793 }
794 }
795
796 PASSED();
797
798 /*-------------------------------------------------------------------------
799 * H5LTset_attribute_ushort test
800 *-------------------------------------------------------------------------
801 */
802
803 TESTING("H5LTset_attribute_ushort");
804
805 /* Set the attribute */
806 if ( H5LTset_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_in, (size_t)5 ) < 0 )
807 return -1;
808
809 PASSED();
810
811
812 /*-------------------------------------------------------------------------
813 * H5LTget_attribute_ushort test
814 *-------------------------------------------------------------------------
815 */
816
817 TESTING("H5LTget_attribute_ushort");
818
819 /* Get the attribute */
820 if ( H5LTget_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_out ) < 0 )
821 return -1;
822
823 for (i = 0; i < 5; i++)
824 {
825 if ( attr_ushort_in[i] != attr_ushort_out[i] ) {
826 return -1;
827 }
828 }
829
830 /* Get the attribute */
831 if ( H5LTget_attribute( loc_id, obj_name, ATTR7_NAME, H5T_NATIVE_USHORT, attr_ushort_out ) < 0 )
832 return -1;
833
834 for (i = 0; i < 5; i++)
835 {
836 if ( attr_ushort_in[i] != attr_ushort_out[i] ) {
837 return -1;
838 }
839 }
840
841 PASSED();
842
843
844 /*-------------------------------------------------------------------------
845 * H5LTset_attribute_int test
846 *-------------------------------------------------------------------------
847 */
848
849 TESTING("H5LTset_attribute_uint");
850
851 /* Set the attribute */
852 if ( H5LTset_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_in, (size_t)5 ) < 0 )
853 return -1;
854
855 PASSED();
856
857 /*-------------------------------------------------------------------------
858 * H5LTget_attribute_int test
859 *-------------------------------------------------------------------------
860 */
861
862 TESTING("H5LTget_attribute_uint");
863
864 /* Get the attribute */
865 if ( H5LTget_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_out ) < 0 )
866 return -1;
867
868 for (i = 0; i < 5; i++)
869 {
870 if ( attr_uint_in[i] != attr_uint_out[i] ) {
871 return -1;
872 }
873 }
874
875 /* Get the attribute */
876 if ( H5LTget_attribute( loc_id, obj_name, ATTR8_NAME, H5T_NATIVE_UINT, attr_uint_out ) < 0 )
877 return -1;
878
879 for (i = 0; i < 5; i++)
880 {
881 if ( attr_uint_in[i] != attr_uint_out[i] ) {
882 return -1;
883 }
884 }
885
886 PASSED();
887
888 /*-------------------------------------------------------------------------
889 * H5LTset_attribute_ulong test
890 *-------------------------------------------------------------------------
891 */
892
893 TESTING("H5LTset_attribute_ulong");
894
895 /* Set the attribute */
896 if ( H5LTset_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_in, (size_t)5 ) < 0 )
897 return -1;
898
899 PASSED();
900
901 /*-------------------------------------------------------------------------
902 * H5LTget_attribute_long test
903 *-------------------------------------------------------------------------
904 */
905
906 TESTING("H5LTget_attribute_ulong");
907
908 /* Get the attribute */
909 if ( H5LTget_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_out ) < 0 )
910 return -1;
911
912 for (i = 0; i < 5; i++)
913 {
914 if ( attr_ulong_in[i] != attr_ulong_out[i] ) {
915 return -1;
916 }
917 }
918
919 /* Get the attribute */
920 if ( H5LTget_attribute( loc_id, obj_name, ATTR9_NAME, H5T_NATIVE_ULONG, attr_ulong_out ) < 0 )
921 return -1;
922
923 for (i = 0; i < 5; i++)
924 {
925 if ( attr_ulong_in[i] != attr_ulong_out[i] ) {
926 return -1;
927 }
928 }
929
930 PASSED();
931
932
933 /*-------------------------------------------------------------------------
934 * H5LTset_attribute_float test
935 *-------------------------------------------------------------------------
936 */
937
938 TESTING("H5LTset_attribute_float");
939
940 /* Set the attribute */
941 if ( H5LTset_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_in, (size_t)5 ) < 0 )
942 return -1;
943
944 PASSED();
945
946 /*-------------------------------------------------------------------------
947 * H5LTget_attribute_float test
948 *-------------------------------------------------------------------------
949 */
950
951 TESTING("H5LTget_attribute_float");
952
953
954 /* Get the attribute */
955 if ( H5LTget_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_out ) < 0 )
956 return -1;
957
958 for (i = 0; i < 5; i++)
959 {
960 if(!FLT_ABS_EQUAL(attr_float_in[i],attr_float_out[i])) {
961 return -1;
962 }
963 }
964
965 /* Get the attribute */
966 if ( H5LTget_attribute( loc_id, obj_name, ATTR10_NAME, H5T_NATIVE_FLOAT, attr_float_out ) < 0 )
967 return -1;
968
969 for (i = 0; i < 5; i++)
970 {
971 if(!FLT_ABS_EQUAL(attr_float_in[i],attr_float_out[i])) {
972 return -1;
973 }
974 }
975
976 PASSED();
977
978 /*-------------------------------------------------------------------------
979 * H5LTset_attribute_double test
980 *-------------------------------------------------------------------------
981 */
982
983 TESTING("H5LTset_attribute_double");
984
985 /* Set the attribute */
986 if ( H5LTset_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_in, (size_t)5 ) < 0 )
987 return -1;
988
989 PASSED();
990
991 /*-------------------------------------------------------------------------
992 * H5LTget_attribute_double test
993 *-------------------------------------------------------------------------
994 */
995
996 TESTING("H5LTget_attribute_double");
997
998 /* Get the attribute */
999 if ( H5LTget_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_out ) < 0 )
1000 return -1;
1001
1002 for (i = 0; i < 5; i++)
1003 {
1004 if(!DBL_ABS_EQUAL(attr_double_in[i],attr_double_out[i])) {
1005 return -1;
1006 }
1007 }
1008
1009 /* Get the attribute */
1010 if ( H5LTget_attribute( loc_id, obj_name, ATTR11_NAME, H5T_NATIVE_DOUBLE, attr_double_out ) < 0 )
1011 return -1;
1012
1013 for (i = 0; i < 5; i++)
1014 {
1015 if(!DBL_ABS_EQUAL(attr_double_in[i],attr_double_out[i])) {
1016 return -1;
1017 }
1018 }
1019
1020 PASSED();
1021
1022
1023 /*-------------------------------------------------------------------------
1024 * H5LTget_attribute_ndims test
1025 *-------------------------------------------------------------------------
1026 */
1027
1028
1029 TESTING("H5LTget_attribute_ndims");
1030
1031 if ( H5LTget_attribute_ndims( loc_id, obj_name, ATTR2_NAME, &rank_out ) < 0 )
1032 return -1;
1033
1034 if ( rank_out != 1 ) {
1035 return -1;
1036 }
1037
1038 PASSED();
1039
1040 /*-------------------------------------------------------------------------
1041 * H5LTget_attribute_info test
1042 *-------------------------------------------------------------------------
1043 */
1044
1045 TESTING("H5LTget_attribute_info");
1046
1047 if(NULL==(dims_out = (hsize_t*) HDmalloc( sizeof(hsize_t) * (size_t)rank_out ))) return -1;
1048
1049 if ( H5LTget_attribute_info( loc_id, obj_name, ATTR2_NAME, dims_out, &type_class, &type_size) < 0 ) {
1050 HDfree( dims_out );
1051 return -1;
1052 }
1053
1054 for (i = 0; i < rank_out; i++) {
1055 if ( dims_out[i] != 5 ) {
1056 HDfree( dims_out );
1057 return -1;
1058 }
1059 }
1060
1061 if ( type_class != H5T_INTEGER ) {
1062 HDfree( dims_out );
1063 return -1;
1064 }
1065 HDfree( dims_out );
1066
1067 PASSED();
1068
1069 return 0;
1070 }
1071
1072 /*-------------------------------------------------------------------------
1073 * subroutine for test_text_dtype(): test_integers().
1074 *-------------------------------------------------------------------------
1075 */
test_integers(void)1076 static int test_integers(void)
1077 {
1078 hid_t dtype;
1079 char* dt_str;
1080 size_t str_len;
1081
1082 TESTING3("\n text for integer types");
1083
1084 if((dtype = H5LTtext_to_dtype("H5T_NATIVE_INT\n", H5LT_DDL))<0)
1085 goto out;
1086 if(!H5Tequal(dtype, H5T_NATIVE_INT))
1087 goto out;
1088 if(H5Tclose(dtype)<0)
1089 goto out;
1090
1091 if((dtype = H5LTtext_to_dtype("H5T_STD_I8BE\n", H5LT_DDL))<0)
1092 goto out;
1093 if(!H5Tequal(dtype, H5T_STD_I8BE))
1094 goto out;
1095
1096 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1097 goto out;
1098
1099 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1100 goto out;
1101 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1102 HDfree(dt_str);
1103 goto out;
1104 }
1105 if(HDstrcmp(dt_str, "H5T_STD_I8BE")) {
1106 HDfree(dt_str);
1107 goto out;
1108 }
1109 HDfree(dt_str);
1110
1111 if(H5Tclose(dtype)<0)
1112 goto out;
1113
1114 if((dtype = H5LTtext_to_dtype("H5T_STD_U16LE\n", H5LT_DDL))<0)
1115 goto out;
1116 if(!H5Tequal(dtype, H5T_STD_U16LE))
1117 goto out;
1118 if(H5Tclose(dtype)<0)
1119 goto out;
1120
1121 PASSED();
1122 return 0;
1123
1124 out:
1125 H5_FAILED();
1126 return -1;
1127 }
1128
1129 /*-------------------------------------------------------------------------
1130 * subroutine for test_text_dtype(): test_fps().
1131 *-------------------------------------------------------------------------
1132 */
test_fps(void)1133 static int test_fps(void)
1134 {
1135 hid_t dtype;
1136 char* dt_str;
1137 size_t str_len;
1138
1139 TESTING3(" text for floating-point types");
1140
1141 if((dtype = H5LTtext_to_dtype("H5T_NATIVE_LDOUBLE\n", H5LT_DDL))<0)
1142 goto out;
1143 if(!H5Tequal(dtype, H5T_NATIVE_LDOUBLE))
1144 goto out;
1145 if(H5Tclose(dtype)<0)
1146 goto out;
1147
1148 if((dtype = H5LTtext_to_dtype("H5T_IEEE_F32BE\n", H5LT_DDL))<0)
1149 goto out;
1150 if(!H5Tequal(dtype, H5T_IEEE_F32BE))
1151 goto out;
1152
1153 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1154 goto out;
1155
1156 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1157 goto out;
1158 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1159 HDfree(dt_str);
1160 goto out;
1161 }
1162 if(HDstrcmp(dt_str, "H5T_IEEE_F32BE")) {
1163 HDfree(dt_str);
1164 goto out;
1165 }
1166 HDfree(dt_str);
1167
1168 if(H5Tclose(dtype)<0)
1169 goto out;
1170
1171 if((dtype = H5LTtext_to_dtype("H5T_IEEE_F64LE\n", H5LT_DDL))<0)
1172 goto out;
1173 if(!H5Tequal(dtype, H5T_IEEE_F64LE))
1174 goto out;
1175 if(H5Tclose(dtype)<0)
1176 goto out;
1177
1178 PASSED();
1179 return 0;
1180
1181 out:
1182 H5_FAILED();
1183 return -1;
1184 }
1185
1186 /*-------------------------------------------------------------------------
1187 * subroutine for test_text_dtype(): test_strings().
1188 *-------------------------------------------------------------------------
1189 */
test_strings(void)1190 static int test_strings(void)
1191 {
1192 hid_t dtype;
1193 size_t str_size;
1194 H5T_str_t str_pad;
1195 H5T_cset_t str_cset;
1196 H5T_class_t type_class;
1197 char* dt_str;
1198 size_t str_len;
1199
1200 TESTING3(" text for string types");
1201
1202 if((dtype = H5LTtext_to_dtype("H5T_STRING { STRSIZE 13; STRPAD H5T_STR_NULLTERM; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1; }", H5LT_DDL))<0)
1203 goto out;
1204
1205 if((type_class = H5Tget_class(dtype))<0)
1206 goto out;
1207 if(type_class != H5T_STRING)
1208 goto out;
1209
1210 str_size = H5Tget_size(dtype);
1211 if(str_size != 13)
1212 goto out;
1213
1214 str_pad = H5Tget_strpad(dtype);
1215 if(str_pad != H5T_STR_NULLTERM)
1216 goto out;
1217
1218 str_cset = H5Tget_cset(dtype);
1219 if(str_cset != H5T_CSET_ASCII)
1220 goto out;
1221
1222 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1223 goto out;
1224 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1225 goto out;
1226 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1227 HDfree(dt_str);
1228 goto out;
1229 }
1230 if(HDstrcmp(dt_str, "H5T_STRING {\n STRSIZE 13;\n STRPAD H5T_STR_NULLTERM;\n CSET H5T_CSET_ASCII;\n CTYPE H5T_C_S1;\n }")) {
1231 printf("dt=\n%s\n", dt_str);
1232 HDfree(dt_str);
1233 goto out;
1234 }
1235 HDfree(dt_str);
1236
1237 if(H5Tclose(dtype)<0)
1238 goto out;
1239
1240 if((dtype = H5LTtext_to_dtype("H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_STR_NULLPAD; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1; }", H5LT_DDL))<0)
1241 goto out;
1242
1243 if(!H5Tis_variable_str(dtype))
1244 goto out;
1245
1246 str_pad = H5Tget_strpad(dtype);
1247 if(str_pad != H5T_STR_NULLPAD)
1248 goto out;
1249
1250 str_cset = H5Tget_cset(dtype);
1251 if(str_cset != H5T_CSET_ASCII)
1252 goto out;
1253
1254 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1255 goto out;
1256 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1257 goto out;
1258 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1259 HDfree(dt_str);
1260 goto out;
1261 }
1262 if(HDstrcmp(dt_str, "H5T_STRING {\n STRSIZE H5T_VARIABLE;\n STRPAD H5T_STR_NULLPAD;\n CSET H5T_CSET_ASCII;\n CTYPE H5T_C_S1;\n }")) {
1263 printf("dt=\n%s\n", dt_str);
1264 HDfree(dt_str);
1265 goto out;
1266 }
1267 HDfree(dt_str);
1268
1269 /* Length of the character buffer is larger then needed */
1270 str_len = str_len + 10;
1271 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1272 goto out;
1273
1274 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1275 HDfree(dt_str);
1276 goto out;
1277 }
1278 if(HDstrncmp(dt_str, "H5T_STRING {\n STRSIZE H5T_VARIABLE;\n STRPAD H5T_STR_NULLPAD;\n CSET H5T_CSET_ASCII;\n CTYPE H5T_C_S1;\n }", str_len-1)) {
1279 printf("dt=\n%s\n", dt_str);
1280 HDfree(dt_str);
1281 goto out;
1282 }
1283
1284 /* Length of the character buffer is smaller then needed */
1285 str_len = 21;
1286 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1287 goto out;
1288
1289 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1290 HDfree(dt_str);
1291 goto out;
1292 }
1293 /* check the truncated string */
1294 if(strlen(dt_str) != str_len-1) goto out;
1295 str_len = strlen(dt_str);
1296 if(HDstrncmp(dt_str, "H5T_STRING {\n STRSIZE H5T_VARIABLE;\n STRPAD H5T_STR_NULLPAD;\n CSET H5T_CSET_ASCII;\n CTYPE H5T_C_S1;\n }", str_len)) {
1297 printf("dt=\n%s\n", dt_str);
1298 HDfree(dt_str);
1299 goto out;
1300 }
1301
1302 HDfree(dt_str);
1303
1304 if(H5Tclose(dtype)<0)
1305 goto out;
1306
1307 PASSED();
1308 return 0;
1309
1310 out:
1311 if(dt_str)
1312 HDfree(dt_str);
1313
1314 H5_FAILED();
1315 return -1;
1316 }
1317
1318 /*-------------------------------------------------------------------------
1319 * subroutine for test_text_dtype(): test_opaques().
1320 *-------------------------------------------------------------------------
1321 */
test_opaques(void)1322 static int test_opaques(void)
1323 {
1324 hid_t dtype;
1325 size_t opq_size;
1326 H5T_class_t type_class;
1327 char* dt_str;
1328 size_t str_len;
1329
1330 TESTING3(" text for opaque types");
1331
1332 if((dtype = H5LTtext_to_dtype("H5T_OPAQUE { OPQ_SIZE 19; OPQ_TAG \"This is a tag for opaque type\"; }", H5LT_DDL))<0)
1333 goto out;
1334
1335 if((type_class = H5Tget_class(dtype))<0)
1336 goto out;
1337 if(type_class != H5T_OPAQUE)
1338 goto out;
1339
1340 if((opq_size = H5Tget_size(dtype)) == 0)
1341 goto out;
1342 if(opq_size != 19)
1343 goto out;
1344
1345 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1346 goto out;
1347 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1348 goto out;
1349 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1350 HDfree(dt_str);
1351 goto out;
1352 }
1353 if(HDstrcmp(dt_str, "H5T_OPAQUE {\n OPQ_SIZE 19;\n OPQ_TAG \"This is a tag for opaque type\";\n }")) {
1354 printf("dt=\n%s\n", dt_str);
1355 HDfree(dt_str);
1356 goto out;
1357 }
1358 HDfree(dt_str);
1359
1360 if(H5Tclose(dtype)<0)
1361 goto out;
1362
1363 PASSED();
1364 return 0;
1365
1366 out:
1367 H5_FAILED();
1368 return -1;
1369 }
1370
1371 /*-------------------------------------------------------------------------
1372 * subroutine for test_text_dtype(): test_enums().
1373 *-------------------------------------------------------------------------
1374 */
test_enums(void)1375 static int test_enums(void)
1376 {
1377 hid_t dtype;
1378 size_t size = 16;
1379 char name1[16];
1380 int value1 = 7;
1381 const char *name2 = "WHITE";
1382 int value2;
1383 H5T_class_t type_class;
1384 char* dt_str;
1385 size_t str_len;
1386
1387 TESTING3(" text for enum types");
1388
1389 if((dtype = H5LTtext_to_dtype("H5T_ENUM { H5T_STD_I32LE; \"RED\" 5; \"GREEN\" 6; \"BLUE\" 7; \"WHITE\" 8; }", H5LT_DDL))<0)
1390 goto out;
1391
1392 if((type_class = H5Tget_class(dtype))<0)
1393 goto out;
1394 if(type_class != H5T_ENUM)
1395 goto out;
1396
1397 /* Convert the variable before using it */
1398 if(!H5Tequal(H5T_STD_I32LE, H5T_NATIVE_INT)) {
1399 if(H5Tconvert(H5T_NATIVE_INT, H5T_STD_I32LE, 1, &value1, NULL, H5P_DEFAULT) < 0)
1400 goto out;
1401 }
1402
1403 if(H5Tenum_nameof(dtype, &value1, name1, size)<0)
1404 goto out;
1405 if(HDstrcmp(name1, "BLUE"))
1406 goto out;
1407
1408 if(H5Tenum_valueof(dtype, name2, &value2)<0)
1409 goto out;
1410
1411 /* Convert the variable before comparing it */
1412 if(!H5Tequal(H5T_STD_I32LE, H5T_NATIVE_INT)) {
1413 if(H5Tconvert(H5T_NATIVE_INT, H5T_STD_I32LE, 1, &value2, NULL, H5P_DEFAULT) < 0)
1414 goto out;
1415 }
1416
1417 if(value2 != 8)
1418 goto out;
1419
1420 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1421 goto out;
1422 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1423 goto out;
1424 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1425 HDfree(dt_str);
1426 goto out;
1427 }
1428 if(HDstrcmp(dt_str, "H5T_ENUM {\n H5T_STD_I32LE;\n \"RED\" 5;\n \"GREEN\" 6;\n \"BLUE\" 7;\n \"WHITE\" 8;\n }")) {
1429
1430 printf("dt=\n%s\n", dt_str);
1431 HDfree(dt_str);
1432 goto out;
1433 }
1434
1435 HDfree(dt_str);
1436
1437 if(H5Tclose(dtype)<0)
1438 goto out;
1439
1440 PASSED();
1441 return 0;
1442
1443 out:
1444 H5_FAILED();
1445 return -1;
1446 }
1447
1448 /*-------------------------------------------------------------------------
1449 * subroutine for test_text_dtype(): test_variables().
1450 *-------------------------------------------------------------------------
1451 */
test_variables(void)1452 static int test_variables(void)
1453 {
1454 hid_t dtype;
1455 H5T_class_t type_class;
1456 char* dt_str;
1457 size_t str_len;
1458
1459 TESTING3(" text for variable types");
1460
1461 if((dtype = H5LTtext_to_dtype("H5T_VLEN { H5T_NATIVE_CHAR }\n", H5LT_DDL))<0)
1462 goto out;
1463
1464 if((type_class = H5Tget_class(dtype))<0)
1465 goto out;
1466 if(type_class != H5T_VLEN)
1467 goto out;
1468
1469 if(H5Tis_variable_str(dtype))
1470 goto out;
1471
1472 if(H5Tclose(dtype)<0)
1473 goto out;
1474
1475 if((dtype = H5LTtext_to_dtype("H5T_VLEN { H5T_VLEN { H5T_STD_I32BE } }", H5LT_DDL))<0)
1476 goto out;
1477
1478 if(H5Tis_variable_str(dtype))
1479 goto out;
1480
1481 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1482 goto out;
1483 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1484 goto out;
1485 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1486 HDfree(dt_str);
1487 goto out;
1488 }
1489 if(HDstrcmp(dt_str, "H5T_VLEN {\n H5T_VLEN {\n H5T_STD_I32BE\n }\n }")) {
1490 printf("dt=\n%s\n", dt_str);
1491 HDfree(dt_str);
1492 goto out;
1493 }
1494 HDfree(dt_str);
1495
1496 if(H5Tclose(dtype)<0)
1497 goto out;
1498
1499 PASSED();
1500 return 0;
1501
1502 out:
1503 H5_FAILED();
1504 return -1;
1505 }
1506
1507 /*-------------------------------------------------------------------------
1508 * subroutine for test_text_dtype(): test_arrays().
1509 *-------------------------------------------------------------------------
1510 */
test_arrays(void)1511 static int test_arrays(void)
1512 {
1513 hid_t dtype;
1514 int ndims;
1515 hsize_t dims[3];
1516 H5T_class_t type_class;
1517 char* dt_str;
1518 size_t str_len;
1519
1520 TESTING3(" text for array types");
1521
1522 if((dtype = H5LTtext_to_dtype("H5T_ARRAY { [5][7][13] H5T_ARRAY { [17][19] H5T_COMPOUND { H5T_STD_I8BE \"arr_compound_1\"; H5T_STD_I32BE \"arr_compound_2\"; } } }", H5LT_DDL))<0)
1523 goto out;
1524
1525 if((type_class = H5Tget_class(dtype))<0)
1526 goto out;
1527 if(type_class != H5T_ARRAY)
1528 goto out;
1529
1530 if((ndims = H5Tget_array_ndims(dtype))<0)
1531 goto out;
1532 if(ndims != 3)
1533 goto out;
1534
1535 if(H5Tget_array_dims2(dtype, dims) < 0)
1536 goto out;
1537 if(dims[0] != 5 || dims[1] != 7 || dims[2] != 13)
1538 goto out;
1539
1540 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1541 goto out;
1542 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1543 goto out;
1544 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1545 HDfree(dt_str);
1546 goto out;
1547 }
1548 if(HDstrcmp(dt_str, "H5T_ARRAY {\n [5][7][13] H5T_ARRAY {\n [17][19] H5T_COMPOUND {\n H5T_STD_I8BE \"arr_compound_1\" : 0;\n H5T_STD_I32BE \"arr_compound_2\" : 1;\n }\n }\n }")) {
1549 printf("dt=\n%s\n", dt_str);
1550 HDfree(dt_str);
1551 goto out;
1552 }
1553
1554 HDfree(dt_str);
1555
1556 if(H5Tclose(dtype)<0)
1557 goto out;
1558
1559 PASSED();
1560 return 0;
1561
1562 out:
1563 H5_FAILED();
1564 return -1;
1565 }
1566
1567 /*-------------------------------------------------------------------------
1568 * subroutine for test_text_dtype(): test_compounds().
1569 *-------------------------------------------------------------------------
1570 */
test_compounds(void)1571 static int test_compounds(void)
1572 {
1573 hid_t dtype;
1574 int nmembs;
1575 char *memb_name = NULL;
1576 H5T_class_t memb_class;
1577 H5T_class_t type_class;
1578 char* dt_str;
1579 size_t str_len;
1580
1581 TESTING3(" text for compound types");
1582
1583 if((dtype = H5LTtext_to_dtype("H5T_COMPOUND { H5T_STD_I16BE \"one_field\" : 2; H5T_STD_U8LE \"two_field\" : 6; }", H5LT_DDL))<0)
1584 goto out;
1585
1586 if((type_class = H5Tget_class(dtype))<0)
1587 goto out;
1588 if(type_class != H5T_COMPOUND)
1589 goto out;
1590
1591 if((nmembs = H5Tget_nmembers(dtype))<0)
1592 goto out;
1593 if(nmembs != 2)
1594 goto out;
1595
1596 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1597 goto out;
1598 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1599 goto out;
1600 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1601 HDfree(dt_str);
1602 goto out;
1603 }
1604 if(HDstrcmp(dt_str, "H5T_COMPOUND {\n H5T_STD_I16BE \"one_field\" : 2;\n H5T_STD_U8LE \"two_field\" : 6;\n }")) {
1605 printf("dt=\n%s\n", dt_str);
1606 HDfree(dt_str);
1607 goto out;
1608 }
1609 HDfree(dt_str);
1610
1611 if(H5Tclose(dtype)<0)
1612 goto out;
1613
1614 if((dtype = H5LTtext_to_dtype("H5T_COMPOUND { H5T_STD_I32BE \"i32_field\"; H5T_STD_I16BE \"i16_field\"; H5T_COMPOUND { H5T_STD_I16BE \"sec_field\"; H5T_COMPOUND { H5T_STD_I32BE \"thd_field\"; } \"grandchild\"; } \"child_compound\"; H5T_STD_I8BE \"i8_field\"; }", H5LT_DDL))<0)
1615 goto out;
1616
1617 if((memb_name = H5Tget_member_name(dtype, 1)) == NULL)
1618 goto out;
1619 if(HDstrcmp(memb_name, "i16_field")) {
1620 H5free_memory(memb_name);
1621 goto out;
1622 }
1623 H5free_memory(memb_name);
1624
1625 if((memb_class = H5Tget_member_class(dtype, 2))<0)
1626 goto out;
1627 if(memb_class != H5T_COMPOUND)
1628 goto out;
1629
1630 PASSED();
1631 return 0;
1632
1633 out:
1634 H5_FAILED();
1635 return -1;
1636 }
1637
1638 /*-------------------------------------------------------------------------
1639 * subroutine for test_text_dtype(): test_compound_bug(). Test case for
1640 * issue 7701.
1641 *-------------------------------------------------------------------------
1642 */
test_compound_bug(void)1643 static int test_compound_bug(void)
1644 {
1645 hid_t dtype;
1646 H5T_class_t type_class;
1647 int nmembs;
1648 char* memb_name = NULL;
1649 char* dt_str;
1650 size_t str_len;
1651 char text[] = "H5T_COMPOUND { H5T_STD_I32LE \"state_________________________________________________________________________________\"; H5T_STD_I32LE \"desc_________________________________________________________________________________________\"; H5T_VLEN { H5T_COMPOUND { H5T_ENUM { H5T_STD_I16LE; \"ZERO\" 0; \"ONE\" 1; \"TWO\" 2; \"THREE\" 3; } \"type____\"; H5T_STD_I32LE \"sub_______________________________________________________________________________________________________________\"; H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_STR_SPACEPAD; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1; } \"sub_desc\"; H5T_STD_I32LE \"final___________________________________________________________________________________________________\"; } } \"sub\"; }";
1652 char text2[] =
1653 "H5T_COMPOUND {\n"
1654 " H5T_STD_I16LE \"state___________________________"
1655 "__________________________________________________"
1656 "____\" : 0;\n"
1657 " H5T_STD_I16LE \"desc____________________________"
1658 "__________________________________________________"
1659 "___________\" : 2;\n"
1660 " H5T_VLEN { H5T_COMPOUND {\n"
1661 " H5T_ENUM { H5T_STD_I16LE; \"ZERO\" 0; \"ONE\" "
1662 "1; \"TWO\" 2; \"THREE\" 3; } \"type____\" : 0;\n"
1663 " H5T_STD_I32LE \"sub___________________________"
1664 "__________________________________________________"
1665 "__________________________________1\" : 4;\n"
1666 " H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_"
1667 "STR_SPACEPAD; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1;"
1668 " } \"sub_desc\" : 8;\n"
1669 " H5T_STD_I32LE \"final_________________________"
1670 "__________________________________________________"
1671 "________________________\" : 16;\n"
1672 " } } \"sub\" : 8;\n"
1673 "}\n";
1674
1675 TESTING3(" text for compound type of bug fix");
1676
1677 if((dtype = H5LTtext_to_dtype(text, H5LT_DDL))<0)
1678 goto out;
1679
1680 if((type_class = H5Tget_class(dtype))<0)
1681 goto out;
1682 if(type_class != H5T_COMPOUND)
1683 goto out;
1684
1685 if((memb_name = H5Tget_member_name(dtype, 2)) == NULL)
1686 goto out;
1687 if(HDstrcmp(memb_name, "sub")) {
1688 H5free_memory(memb_name);
1689 goto out;
1690 }
1691 H5free_memory(memb_name);
1692
1693 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1694 goto out;
1695
1696 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1697 goto out;
1698 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1699 HDfree(dt_str);
1700 goto out;
1701 }
1702 HDfree(dt_str);
1703
1704 if(H5Tclose(dtype)<0)
1705 goto out;
1706
1707
1708 /* Test similar datatype in another format */
1709 if((dtype = H5LTtext_to_dtype(text2, H5LT_DDL))<0)
1710 goto out;
1711
1712 if((type_class = H5Tget_class(dtype))<0)
1713 goto out;
1714 if(type_class != H5T_COMPOUND)
1715 goto out;
1716
1717 if((nmembs = H5Tget_nmembers(dtype))<0)
1718 goto out;
1719 if(nmembs != 3)
1720 goto out;
1721
1722 if((memb_name = H5Tget_member_name(dtype, 1)) == NULL)
1723 goto out;
1724 if(HDstrcmp(memb_name, "desc_________________________________________________________________________________________")) {
1725 H5free_memory(memb_name);
1726 goto out;
1727 }
1728 H5free_memory(memb_name);
1729
1730 if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
1731 goto out;
1732
1733 if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
1734 goto out;
1735 if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
1736 HDfree(dt_str);
1737 goto out;
1738 }
1739
1740 HDfree(dt_str);
1741
1742 if(H5Tclose(dtype)<0)
1743 goto out;
1744
1745 PASSED();
1746 return 0;
1747
1748 out:
1749 H5_FAILED();
1750 return -1;
1751 }
1752
1753 /*-------------------------------------------------------------------------
1754 * subroutine for test_text_dtype(): test_complicated_compound().
1755 *-------------------------------------------------------------------------
1756 */
test_complicated_compound(void)1757 static int test_complicated_compound(void)
1758 {
1759 hid_t dtype;
1760 int nmembs;
1761 H5T_class_t type_class;
1762 char *line = NULL;
1763 FILE *fp = NULL;
1764 size_t size = 1024;
1765 char *srcdir = getenv("srcdir"); /* the source directory */
1766 char filename[1024]="";
1767
1768 TESTING3(" text for complicated compound types");
1769
1770 /* compose the name of the file to open, using the srcdir, if appropriate */
1771 if(srcdir) {
1772 HDstrcpy(filename, srcdir);
1773 HDstrcat(filename, "/");
1774 }
1775 HDstrcat(filename, INPUT_FILE);
1776
1777 /* Open input file */
1778 fp = HDfopen(filename, "r");
1779 if(fp == NULL) {
1780 printf( "Could not find file %s. Try set $srcdir \n", filename);
1781 goto out;
1782 }
1783
1784 /* This part reads in the input as a string in a slow manner. GNU C
1785 * Library has convenient function getline() but isn't available on
1786 * all machines.
1787 */
1788 if((line = (char*)HDcalloc(size, sizeof(char)))==NULL)
1789 goto out;
1790 if(HDfgets(line, (int)size, fp)==NULL)
1791 goto out;
1792 while(HDstrlen(line)==size-1) {
1793 size *= 2;
1794 if(line)
1795 HDfree(line);
1796 if((line = (char*)HDcalloc(size, sizeof(char)))==NULL)
1797 goto out;
1798 if(HDfseek(fp, 0L, SEEK_SET)!=0)
1799 goto out;
1800 if(HDfgets(line, (int)size, fp)==NULL)
1801 goto out;
1802 }
1803
1804 HDfclose(fp);
1805 fp = NULL;
1806
1807 if((dtype = H5LTtext_to_dtype(line, H5LT_DDL))<0)
1808 goto out;
1809
1810 if((type_class = H5Tget_class(dtype))<0)
1811 goto out;
1812 if(type_class != H5T_COMPOUND)
1813 goto out;
1814
1815 /* There should be 101 compound members */
1816 if((nmembs = H5Tget_nmembers(dtype))<0)
1817 goto out;
1818 if(nmembs != 101)
1819 goto out;
1820
1821 if(line)
1822 HDfree(line);
1823
1824 PASSED();
1825 return 0;
1826
1827 out:
1828
1829 if(line)
1830 HDfree(line);
1831 if(fp)
1832 HDfclose(fp);
1833
1834 H5_FAILED();
1835 return -1;
1836 }
1837
1838 /*-------------------------------------------------------------------------
1839 * test H5LTtext_to_dtype function
1840 *-------------------------------------------------------------------------
1841 */
test_text_dtype(void)1842 static int test_text_dtype(void)
1843 {
1844 TESTING("H5LTtext_to_dtype");
1845
1846 if(test_integers()<0)
1847 goto out;
1848
1849 if(test_fps()<0)
1850 goto out;
1851
1852 if(test_strings()<0)
1853 goto out;
1854
1855 if(test_opaques()<0)
1856 goto out;
1857
1858 if(test_enums()<0)
1859 goto out;
1860
1861 if(test_variables()<0)
1862 goto out;
1863
1864 if(test_arrays()<0)
1865 goto out;
1866
1867 if(test_compounds()<0)
1868 goto out;
1869
1870 if(test_compound_bug()<0)
1871 goto out;
1872
1873 if(test_complicated_compound()<0)
1874 goto out;
1875
1876 return 0;
1877
1878 out:
1879 return -1;
1880 }
1881
1882 /*-------------------------------------------------------------------------
1883 * test H5LTpath_valid function
1884 *-------------------------------------------------------------------------
1885 */
test_valid_path(void)1886 static int test_valid_path(void)
1887 {
1888 hid_t file_id, group;
1889 htri_t path_valid;
1890 const char *data_string_in = "test";
1891
1892 TESTING("H5LTpath_valid");
1893
1894 /* Create a new file using default properties. */
1895
1896 /**************************************************************
1897 * The file structure should look like this:
1898 *
1899 * +----------------------------------+
1900 * | / |
1901 * +----------------------------------+
1902 * / | \ \
1903 * / | \ \
1904 * / | \ \
1905 * / | \ G8 (dangled external link)
1906 * / DS \
1907 * / \
1908 * G1 G2
1909 * | --> DS1 |
1910 * / \--> DS3 / \
1911 * / / \
1912 * G2 DS4 G7
1913 * | (hard link (dangled soft link
1914 * | to /G1/DS3) to /G1/G20 )
1915 * |
1916 * |
1917 * | --- Gcyc (soft link to /G1)
1918 * / \
1919 * / \
1920 * G5 \
1921 * (soft link G6 (external link /G1 in FILENAME4)
1922 * to /G2)
1923 *
1924 ****************************************************************/
1925
1926 file_id = H5Fcreate(FILE_NAME3, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
1927
1928 /*
1929 * Create dataset "/DS"
1930 */
1931 if(H5LTmake_dataset_string(file_id, "DS", data_string_in)<0)
1932 goto out;
1933
1934 /*
1935 * Create an external dangled link
1936 */
1937 if(H5Lcreate_external("NonExistant_File.h5", "G8", file_id, "DangledExternalLink", H5P_DEFAULT, H5P_DEFAULT)<0)
1938 goto out;
1939
1940 /*
1941 * Create a group named "G2" in the file.
1942 */
1943 if((group = H5Gcreate2(file_id, "G2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT))<0)
1944 goto out;
1945
1946 /*
1947 * Create a dataset named "G2/DS4" in the file.
1948 */
1949 if(H5LTmake_dataset_string(group, "/G2/DS4", data_string_in)<0)
1950 goto out;
1951
1952 /*
1953 * Create a soft link
1954 */
1955 if(H5Lcreate_soft("/G1/G20", file_id, "/G2/G7", H5P_DEFAULT, H5P_DEFAULT) <0)
1956 goto out;
1957
1958 if(H5Gclose(group)<0)
1959 goto out;
1960
1961 /*
1962 * Create a group named "G1" in the file.
1963 */
1964 if((group = H5Gcreate2(file_id, "G1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT))<0)
1965 goto out;
1966
1967 /*
1968 * Create a group named "G1/DS1" in the file.
1969 */
1970 if(H5LTmake_dataset_string(group, "/G1/DS1", data_string_in)<0)
1971 goto out;
1972
1973 if(H5Gclose(group)<0)
1974 goto out;
1975
1976 /*
1977 * Create a hard link
1978 */
1979 if(H5Lcreate_hard(file_id, "/G2/DS4", file_id, "/G1/DS3",H5P_DEFAULT, H5P_DEFAULT)<0)
1980 goto out;
1981 /*
1982 * Create a group named "/G1/G2" in the file.
1983 */
1984 if((group = H5Gcreate2(file_id, "/G1/G2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT))<0)
1985 goto out;
1986
1987 /*
1988 * Create a soft link
1989 */
1990 if(H5Lcreate_soft("/G2", file_id, "/G1/G2/G5", H5P_DEFAULT, H5P_DEFAULT)<0)
1991 goto out;
1992
1993 /*
1994 * Create a cyclic soft link
1995 */
1996 if(H5Lcreate_soft("/G1", file_id, "/G1/G2/Gcyc", H5P_DEFAULT, H5P_DEFAULT)<0)
1997 goto out;
1998
1999 if(H5Gclose(group)<0)
2000 goto out;
2001
2002 /*
2003 * Create a group named "/G1/G2/G6" in the file.
2004 */
2005 if((group = H5Gcreate2(file_id, "/G1/G2/G6", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT))<0)
2006 goto out;
2007
2008 /*
2009 * Create an external link
2010 */
2011 if(H5Lcreate_external( FILE_NAME4, "G1", group, "ExternalLink", H5P_DEFAULT, H5P_DEFAULT)<0)
2012 goto out;
2013
2014 if(H5Gclose(group)<0)
2015 goto out;
2016 /*
2017 * Close the file.
2018 */
2019 if(H5Fclose (file_id) < 0)
2020 goto out;
2021
2022 /* Create another file for checking external links */
2023
2024 /**************************************************************
2025 * The file structure should look like this:
2026 *
2027 * +----+
2028 * | / |
2029 * +----+
2030 * |
2031 * |
2032 * |
2033 * G1
2034 * / \
2035 * / \
2036 * DS1 G2
2037 * (dangled soft link to /G1/G20)
2038 *
2039 ****************************************************************/
2040
2041 /* Make external link file */
2042 file_id = H5Fcreate(FILE_NAME4, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
2043
2044 /*
2045 * Create a group named "G1" in the file.
2046 */
2047 if((group = H5Gcreate2(file_id, "G1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT))<0)
2048 goto out;
2049 /*
2050 * Create a dataset named "G1/DS1" in the file.
2051 */
2052 if(H5LTmake_dataset_string(group, "/G1/DS1", data_string_in)<0)
2053 goto out;
2054
2055 /*
2056 * Create a dangling soft link
2057 */
2058
2059 if(H5Lcreate_soft("/G1/G2", file_id, "/G1/G20", H5P_DEFAULT, H5P_DEFAULT)<0)
2060 goto out;
2061
2062 if(H5Gclose(group)<0)
2063 goto out;
2064
2065 H5Fclose(file_id);
2066
2067 /* Open input file */
2068 if((file_id = H5Fopen(FILE_NAME3,H5F_ACC_RDONLY, H5P_DEFAULT))<0)
2069 goto out;
2070
2071 /**************************************
2072 * CHECK ABSOLUTE PATHS
2073 **************************************/
2074
2075 if( (path_valid = H5LTpath_valid(file_id, "/", TRUE)) != FALSE) {
2076 goto out;
2077 }
2078
2079 if( (path_valid = H5LTpath_valid(file_id, "/", FALSE)) != FALSE) {
2080 goto out;
2081 }
2082
2083 if( (path_valid = H5LTpath_valid(file_id, "/G1", TRUE)) != TRUE) {
2084 goto out;
2085 }
2086
2087 if((path_valid = H5LTpath_valid(file_id, "/G1/DS1", TRUE)) != TRUE)
2088 goto out;
2089
2090 if( (path_valid = H5LTpath_valid(file_id, "/G1/DS3", TRUE)) != TRUE)
2091 goto out;
2092
2093 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2", TRUE)) != TRUE)
2094 goto out;
2095
2096 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/G5", TRUE)) != TRUE)
2097 goto out;
2098
2099 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/Gcyc/DS1", FALSE)) != TRUE)
2100 goto out;
2101
2102 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/Gcyc/DS1", TRUE)) != TRUE)
2103 goto out;
2104
2105 if( (path_valid = H5LTpath_valid(file_id, "/G2", TRUE)) != TRUE)
2106 goto out;
2107
2108 /* check soft link points to a valid object*/
2109 if( (path_valid = H5LTpath_valid(file_id, "/G2/DS4", TRUE)) != TRUE)
2110 goto out;
2111
2112 /* check if path exist, but not the object */
2113 if( (path_valid = H5LTpath_valid(file_id, "/G2/G7", FALSE)) != TRUE )
2114 goto out;
2115 /* check if path exist and if the object exists. It should fail
2116 * since it is a dangling soft link
2117 */
2118 if( (path_valid = H5LTpath_valid(file_id, "/G2/G7", TRUE)) == TRUE)
2119 goto out;
2120
2121 /* check soft links */
2122 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/G5/DS4", TRUE)) != TRUE)
2123 goto out;
2124
2125 /**************************************
2126 * CHECK RELATIVE PATHS
2127 ***************************************/
2128
2129 if( (group = H5Gopen2(file_id, "/", H5P_DEFAULT)) < 0)
2130 goto out;
2131
2132 if( (path_valid = H5LTpath_valid(group, "/", TRUE)) != FALSE) {
2133 goto out;
2134 }
2135
2136 if( (path_valid = H5LTpath_valid(group, "/", FALSE)) != FALSE) {
2137 goto out;
2138 }
2139
2140 if(H5Gclose(group)<0)
2141 goto out;
2142
2143 if( (group = H5Gopen2(file_id, "/G1", H5P_DEFAULT)) < 0)
2144 goto out;
2145
2146 /* The identifier (file id) is the object itself, i.e. "." */
2147
2148 if((path_valid = H5LTpath_valid(file_id, ".", FALSE)) != TRUE)
2149 goto out;
2150
2151 if( (path_valid = H5LTpath_valid(file_id, ".", TRUE)) != TRUE)
2152 goto out;
2153
2154 /* The identifier (group id) is the object itself, i.e. "." */
2155
2156 if( (path_valid = H5LTpath_valid(group, ".", TRUE)) != TRUE)
2157 goto out;
2158
2159 if( (path_valid = H5LTpath_valid(group, "DS3", FALSE)) != TRUE)
2160 goto out;
2161
2162 if( (path_valid = H5LTpath_valid(group, "DS3", TRUE)) != TRUE)
2163 goto out;
2164
2165 if( (path_valid = H5LTpath_valid(group, "G2/G5", TRUE)) != TRUE)
2166 goto out;
2167
2168 /* Check the "./" case */
2169 if( (path_valid = H5LTpath_valid(group, "./DS3", TRUE)) != TRUE)
2170 goto out;
2171
2172 if( (path_valid = H5LTpath_valid(group, "./G2/G5", TRUE)) != TRUE)
2173 goto out;
2174
2175 /* Should fail, does not exist */
2176 if( (path_valid = H5LTpath_valid(group, "./G2/G20", FALSE)) == TRUE)
2177 goto out;
2178
2179 /* Should fail, does not exist */
2180 if( (path_valid = H5LTpath_valid(group, "./G2/G20", TRUE)) == TRUE)
2181 goto out;
2182
2183 if(H5Gclose(group)<0)
2184 goto out;
2185
2186 /*****************************
2187 * Check external links
2188 *****************************/
2189
2190 /* The dangled external link path is valid */
2191 if( (path_valid = H5LTpath_valid(file_id, "/DangledExternalLink", FALSE)) != TRUE)
2192 goto out;
2193
2194 /* The file however does not exists, so the link dangles -> should return false */
2195 if( (path_valid = H5LTpath_valid(file_id, "/DangledExternalLink", TRUE)) == TRUE)
2196 goto out;
2197
2198 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/G6/ExternalLink", FALSE)) != TRUE)
2199 goto out;
2200
2201 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/G6/ExternalLink", TRUE)) != TRUE)
2202 goto out;
2203
2204 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/Gcyc/G2/G6/ExternalLink/DS1", TRUE)) != TRUE)
2205 goto out;
2206
2207 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/Gcyc/G2/G6/ExternalLink/G20", FALSE)) != TRUE)
2208 goto out;
2209
2210 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/G6/ExternalLink/DS1", TRUE)) != TRUE)
2211 goto out;
2212
2213 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/G6/ExternalLink/G20", FALSE)) != TRUE)
2214 goto out;
2215
2216 /* Should fail, does not exist */
2217 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/G6/ExternalLink/G20", TRUE)) == TRUE)
2218 goto out;
2219
2220 if( (path_valid = H5LTpath_valid(file_id, "/G1/G2/Gcyc/G2/G6/ExternalLink/G20", TRUE)) == TRUE)
2221 goto out;
2222
2223
2224 if(H5Fclose(file_id)<0)
2225 goto out;
2226
2227 PASSED();
2228 return 0;
2229
2230 out:
2231 H5_FAILED();
2232 return -1;
2233 }
2234
2235 /*-------------------------------------------------------------------------
2236 * the main program
2237 *-------------------------------------------------------------------------
2238 */
main(void)2239 int main( void )
2240 {
2241 int nerrors=0;
2242
2243 /* test dataset functions */
2244 nerrors += test_dsets();
2245
2246 /* test attribute functions */
2247 nerrors += test_attr();
2248
2249 /* test valid path functions */
2250 nerrors += test_valid_path();
2251
2252 /* test text-dtype functions */
2253 nerrors += test_text_dtype();
2254
2255 /* check for errors */
2256 if (nerrors)
2257 goto error;
2258
2259 return 0;
2260
2261 error:
2262 return 1;
2263 }
2264