1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.nio.charset.StandardCharsets;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.HDFNativeData;
import hdf.hdf5lib.callbacks.H5P_cls_close_func_cb;
import hdf.hdf5lib.callbacks.H5P_cls_close_func_t;
import hdf.hdf5lib.callbacks.H5P_cls_copy_func_cb;
import hdf.hdf5lib.callbacks.H5P_cls_copy_func_t;
import hdf.hdf5lib.callbacks.H5P_cls_create_func_cb;
import hdf.hdf5lib.callbacks.H5P_cls_create_func_t;
import hdf.hdf5lib.callbacks.H5P_prp_set_func_cb;
import hdf.hdf5lib.callbacks.H5P_prp_get_func_cb;
import hdf.hdf5lib.callbacks.H5P_prp_delete_func_cb;
import hdf.hdf5lib.callbacks.H5P_prp_copy_func_cb;
import hdf.hdf5lib.callbacks.H5P_prp_compare_func_cb;
import hdf.hdf5lib.callbacks.H5P_prp_close_func_cb;
import hdf.hdf5lib.callbacks.H5P_prp_create_func_cb;
import hdf.hdf5lib.callbacks.H5P_iterate_cb;
import hdf.hdf5lib.callbacks.H5P_iterate_t;
import hdf.hdf5lib.exceptions.HDF5Exception;
import hdf.hdf5lib.exceptions.HDF5LibraryException;
import hdf.hdf5lib.structs.H5AC_cache_config_t;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
public class TestH5Plist {
@Rule public TestName testname = new TestName();
// Property definitions
private static final String CLASS1_NAME = "Class 1";
private static final String CLASS1_PATH = "root/Class 1";
private static final String CLASS2_NAME = "Class 2";
private static final String CLASS2_PATH = "root/Class 1/Class 2";
// Property definitions
private static final String PROP1_NAME = "Property 1";
private static final int prop1_def = 10; // Property 1 default value
private static final int PROP1_SIZE = 2;
private static final String PROP2_NAME = "Property 2";
private static final float prop2_def = 3.14F; // Property 2 default value
private static final int PROP2_SIZE = 8;
private static final String PROP3_NAME = "Property 3";
private static final char[] prop3_def = {'T','e','n',' ','c','h','a','r','s',' '}; // Property 3 default value
private static final int PROP3_SIZE = 10;
private static final String PROP4_NAME = "Property 4";
private static final double prop4_def = 1.41F; // Property 4 default value
private static final int PROP4_SIZE = 8;
private static final String [] pnames = { // Names of properties for iterator
PROP1_NAME,
PROP2_NAME,
PROP3_NAME,
PROP4_NAME};
long plist_class_id = HDF5Constants.H5I_INVALID_HID;
@Before
public void createPropClass()throws NullPointerException, HDF5Exception
{
assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
System.out.print(testname.getMethodName());
// Create a new generic class, derived from the root of the class hierarchy
try {
plist_class_id = H5.H5Pcreate_class_nocb(HDF5Constants.H5P_ROOT, CLASS1_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5Plist.H5Pcreate_class: " + err);
}
assertTrue(plist_class_id > 0);
}
@After
public void deleteFileAccess() throws HDF5LibraryException {
if (plist_class_id > 0)
try {H5.H5Pclose(plist_class_id);} catch (Exception ex) {}
System.out.println();
}
// Test basic generic property list code. Tests creating new generic classes.
@Test
public void testH5P_genprop_basic_class() {
int status = -1;
long cid1 = HDF5Constants.H5I_INVALID_HID; // Generic Property class ID
long cid2 = HDF5Constants.H5I_INVALID_HID; // Generic Property class ID
long cid3 = HDF5Constants.H5I_INVALID_HID; // Generic Property class ID
String name = null; // Name of class
try {
// Check class name
try {
name = H5.H5Pget_class_name(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_class_name plist_class_id: " + err);
}
assertTrue("Class names don't match!, "+name+"="+CLASS1_NAME+"\n", name.compareTo(CLASS1_NAME)==0);
// Check class parent
try {
cid2 = H5.H5Pget_class_parent(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_class_parent cid2: " + err);
}
// Verify class parent correct
try {
status = H5.H5Pequal(cid2, HDF5Constants.H5P_ROOT);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pequal cid2: " + err);
}
assertTrue("H5Pequal cid2", status >= 0);
// Make certain false positives aren't being returned
try {
status = H5.H5Pequal(cid2, HDF5Constants.H5P_FILE_CREATE);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pequal cid2: " + err);
}
assertTrue("H5Pequal cid2", status >= 0);
// Close parent class
try {
H5.H5Pclose_class(cid2);
cid2 = HDF5Constants.H5I_INVALID_HID;
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pclose_class cid2: " + err);
}
// Close class
try {
H5.H5Pclose_class(plist_class_id);
plist_class_id = HDF5Constants.H5I_INVALID_HID;
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pclose_class plist_class_id: " + err);
}
// Create another new generic class, derived from file creation class
try {
cid1 = H5.H5Pcreate_class_nocb(HDF5Constants.H5P_FILE_CREATE, CLASS2_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pcreate_class cid1: " + err);
}
assertTrue("H5Pcreate_class cid1", cid1 >= 0);
// Check class name
try {
name = H5.H5Pget_class_name(cid1);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_class_name cid1: " + err);
}
assertTrue("Class names don't match!, "+name+"="+CLASS2_NAME+"\n", name.compareTo(CLASS2_NAME)==0);
// Check class parent
try {
cid2 = H5.H5Pget_class_parent(cid1);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_class_parent cid2: " + err);
}
assertTrue("H5Pget_class_parent cid2 ", cid2 >= 0);
// Verify class parent correct
try {
status = H5.H5Pequal(cid2, HDF5Constants.H5P_FILE_CREATE);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pequal cid2: " + err);
}
assertTrue("H5Pequal cid2 ", status >= 0);
// Check class parent's parent
try {
cid3 = H5.H5Pget_class_parent(cid2);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_class_parent cid3: " + err);
}
assertTrue("H5Pget_class_parent cid3", cid3 >= 0);
// Verify class parent's parent correct
try {
status = H5.H5Pequal(cid3, HDF5Constants.H5P_GROUP_CREATE);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pequal cid3: " + err);
}
assertTrue("H5Pequal cid3 ", status >= 0);
// Close parent class's parent
try {
H5.H5Pclose_class(cid3);
cid3 = HDF5Constants.H5I_INVALID_HID;
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pclose_class cid3: " + err);
}
// Close parent class's parent
try {
H5.H5Pclose_class(cid2);
cid2 = HDF5Constants.H5I_INVALID_HID;
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pclose_class cid2: " + err);
}
// Close parent class's parent
try {
H5.H5Pclose_class(cid1);
cid1 = HDF5Constants.H5I_INVALID_HID;
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pclose_class cid1: " + err);
}
}
finally {
if (cid3 > 0)
try {H5.H5Pclose_class(cid3);} catch (Throwable err) {}
if (cid2 > 0)
try {H5.H5Pclose_class(cid2);} catch (Throwable err) {}
if (cid1 > 0)
try {H5.H5Pclose_class(cid1);} catch (Throwable err) {}
}
}
// Test basic generic property list code. Tests adding properties to generic classes.
@Test
public void testH5P_genprop_basic_class_prop() {
boolean status = false;
long size = -1; // Generic Property size
long nprops = -1; // Generic Property class number
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops plist_class_id: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==0);
// Check the existence of the first property (should fail)
try {
status = H5.H5Pexist(plist_class_id, PROP1_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pexist plist_class_id: " + err);
}
assertFalse("H5Pexist plist_class_id "+PROP1_NAME, status);
// Insert first property into class (with no callbacks)
try {
byte[] prop_value = HDFNativeData.intToByte(prop1_def);
H5.H5Pregister2_nocb(plist_class_id, PROP1_NAME, PROP1_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP1_NAME + err);
}
// Try to insert the first property again (should fail)
try {
byte[] prop_value = HDFNativeData.intToByte(prop1_def);
H5.H5Pregister2_nocb(plist_class_id, PROP1_NAME, PROP1_SIZE, prop_value);
fail("H5Pregister2 plist_class_id: "+PROP1_NAME);
}
catch (Throwable err) {
}
// Check the existence of the first property
try {
status = H5.H5Pexist(plist_class_id, PROP1_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pexist plist_class_id: " + err);
}
assertTrue("H5Pexist plist_class_id "+PROP1_NAME, status);
// Check the size of the first property
try {
size = H5.H5Pget_size(plist_class_id, PROP1_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_size PROP1_NAME: " + err);
}
assertTrue("H5Pget_size "+PROP1_NAME +" size: "+size, size == PROP1_SIZE);
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops plist_class_id: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==1);
// Insert second property into class (with no callbacks)
try {
byte[] prop_value = HDFNativeData.floatToByte(prop2_def);
H5.H5Pregister2_nocb(plist_class_id, PROP2_NAME, PROP2_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP2_NAME + err);
}
// Try to insert the second property again (should fail)
try {
byte[] prop_value = HDFNativeData.floatToByte(prop2_def);
H5.H5Pregister2_nocb(plist_class_id, PROP2_NAME, PROP2_SIZE, prop_value);
fail("H5Pregister2 plist_class_id: "+PROP2_NAME);
}
catch (Throwable err) {
}
// Check the existence of the second property
try {
status = H5.H5Pexist(plist_class_id, PROP2_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pexist plist_class_id: " + err);
}
assertTrue("H5Pexist plist_class_id "+PROP2_NAME, status);
// Check the size of the second property
try {
size = H5.H5Pget_size(plist_class_id, PROP2_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_size PROP2_NAME: " + err);
}
assertTrue("H5Pget_size "+PROP2_NAME +" size: "+size, size == PROP2_SIZE);
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops plist_class_id: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==2);
// Insert third property into class (with no callbacks)
try {
byte[] prop_value = new String(prop3_def).getBytes(StandardCharsets.UTF_8);
H5.H5Pregister2_nocb(plist_class_id, PROP3_NAME, PROP3_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP3_NAME + err);
}
// Check the existence of the third property
try {
status = H5.H5Pexist(plist_class_id, PROP3_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pexist plist_class_id: " + err);
}
assertTrue("H5Pexist plist_class_id "+PROP3_NAME, status);
// Check the size of the third property
try {
size = H5.H5Pget_size(plist_class_id, PROP3_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_size PROP3_NAME: " + err);
}
assertTrue("H5Pget_size "+PROP3_NAME +" size: "+size, size == PROP3_SIZE);
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops plist_class_id: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==3);
// Unregister first property
try {
H5.H5Punregister(plist_class_id, PROP1_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Punregister plist_class_id: "+PROP1_NAME + err);
}
// Try to check the size of the first property (should fail)
try {
size = H5.H5Pget_size(plist_class_id, PROP1_NAME);
fail("H5Pget_size PROP1_NAME");
}
catch (Throwable err) {
}
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops plist_class_id: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==2);
// Unregister second property
try {
H5.H5Punregister(plist_class_id, PROP2_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Punregister plist_class_id: "+PROP2_NAME + err);
}
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops plist_class_id: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==1);
// Unregister third property
try {
H5.H5Punregister(plist_class_id, PROP3_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Punregister plist_class_id: "+PROP3_NAME + err);
}
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops plist_class_id: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==0);
}
// Test basic generic property list code. Tests iterating over properties in a generic class.
@Test
public void testH5P_genprop_class_iter() {
class idata {
public String[] iter_names= null;
public int iter_count = -1;
idata(String[] names, int count) {
this.iter_names = names;
this.iter_count = count;
}
}
class H5P_iter_data implements H5P_iterate_t {
public ArrayList<idata> iterdata = new ArrayList<idata>();
}
H5P_iterate_t iter_data = new H5P_iter_data();
class H5P_iter_callback implements H5P_iterate_cb {
public int callback(long list_id, String name, H5P_iterate_t op_data) {
idata id = ((H5P_iter_data)op_data).iterdata.get(0);
return name.compareTo(id.iter_names[id.iter_count++]);
}
}
H5P_iterate_cb iter_cb = new H5P_iter_callback();
long size = -1; // Generic Property size
long nprops = -1; // Generic Property class number
int[] idx = {0}; // Index to start iteration at
// Insert first property into class (with no callbacks) */
try {
byte[] prop_value = HDFNativeData.intToByte(prop1_def);
H5.H5Pregister2_nocb(plist_class_id, PROP1_NAME, PROP1_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP1_NAME + err);
}
// Insert second property into class (with no callbacks) */
try {
byte[] prop_value = HDFNativeData.floatToByte(prop2_def);
H5.H5Pregister2_nocb(plist_class_id, PROP2_NAME, PROP2_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP2_NAME + err);
}
// Insert third property into class (with no callbacks) */
try {
byte[] prop_value = new String(prop3_def).getBytes(StandardCharsets.UTF_8);
H5.H5Pregister2_nocb(plist_class_id, PROP3_NAME, PROP3_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP3_NAME + err);
}
// Insert fourth property into class (with no callbacks) */
try {
byte[] prop_value = HDFNativeData.doubleToByte(prop4_def);
H5.H5Pregister2_nocb(plist_class_id, PROP4_NAME, PROP4_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP4_NAME + err);
}
// Check the number of properties in class */
try {
nprops = H5.H5Pget_nprops(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops plist_class_id: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==4);
// Iterate over all properties in class */
idata id = new idata(pnames, 0);
((H5P_iter_data)iter_data).iterdata.add(id);
try {
H5.H5Piterate(plist_class_id, null, iter_cb, iter_data);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5.H5Piterate: " + err);
}
assertFalse("H5Piterate ",((H5P_iter_data)iter_data).iterdata.isEmpty());
assertTrue("H5Piterate "+((H5P_iter_data)iter_data).iterdata.size(),((H5P_iter_data)iter_data).iterdata.size()==1);
assertTrue("H5Piterate "+(((H5P_iter_data)iter_data).iterdata.get(0)).iter_count,((idata)((H5P_iter_data)iter_data).iterdata.get(0)).iter_count==4);
// Iterate over last three properties in class */
idx[0] = 1;
((H5P_iter_data)iter_data).iterdata.get(0).iter_count = 1;
try {
H5.H5Piterate(plist_class_id, idx, iter_cb, iter_data);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5.H5Piterate: " + err);
}
assertFalse("H5Piterate ",((H5P_iter_data)iter_data).iterdata.isEmpty());
assertTrue("H5Piterate "+((H5P_iter_data)iter_data).iterdata.size(),((H5P_iter_data)iter_data).iterdata.size()==1);
assertTrue("H5Piterate "+(((H5P_iter_data)iter_data).iterdata.get(0)).iter_count,((idata)((H5P_iter_data)iter_data).iterdata.get(0)).iter_count==4);
assertTrue("H5Piterate: "+nprops+"="+idx[0], nprops == idx[0]);
}
// Test basic generic property list code.
// Tests creating new generic property lists and adding and
// removing properties from them.
@Test
public void testH5P_genprop_basic_list_prop() {
boolean status = false;
long lid1 = HDF5Constants.H5I_INVALID_HID; // Generic Property list ID
long nprops = -1; // Number of properties in class
try {
// Add several properties (several w/default values)
// Insert first property into class (with no callbacks)
try {
byte[] prop_value = HDFNativeData.intToByte(prop1_def);
H5.H5Pregister2_nocb(plist_class_id, PROP1_NAME, PROP1_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP1_NAME + err);
}
// Insert second property into class (with no callbacks)
try {
byte[] prop_value = HDFNativeData.floatToByte(prop2_def);
H5.H5Pregister2_nocb(plist_class_id, PROP2_NAME, PROP2_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pregister2 plist_class_id: "+PROP2_NAME + err);
}
// Create a property list from the class
try {
lid1 = H5.H5Pcreate(plist_class_id);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pcreate lid1: " + err);
}
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(lid1);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops lid1: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==2);
// Add temporary properties
// Insert first temporary property into list (with no callbacks)
try {
byte[] prop_value = new String(prop3_def).getBytes(StandardCharsets.UTF_8);
H5.H5Pinsert2_nocb(lid1, PROP3_NAME, PROP3_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pinsertr2 lid1: "+PROP3_NAME + err);
}
// Insert second temporary property into list (with no callbacks)
try {
byte[] prop_value = HDFNativeData.doubleToByte(prop4_def);
H5.H5Pinsert2_nocb(lid1, PROP4_NAME, PROP4_SIZE, prop_value);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pinsert2 lid1: "+PROP4_NAME + err);
}
// Check the number of properties in class
try {
nprops = H5.H5Pget_nprops(lid1);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pget_nprops lid1: " + err);
}
assertTrue("H5Pget_nprops: "+nprops, nprops==4);
// Check existence of all properties
try {
status = H5.H5Pexist(lid1, PROP1_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pexist plist_class_id: " + err);
}
assertTrue("H5Pexist lid1 "+PROP1_NAME, status);
try {
status = H5.H5Pexist(lid1, PROP2_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pexist plist_class_id: " + err);
}
assertTrue("H5Pexist lid1 "+PROP2_NAME, status);
try {
status = H5.H5Pexist(lid1, PROP3_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pexist plist_class_id: " + err);
}
assertTrue("H5Pexist lid1 "+PROP3_NAME, status);
try {
status = H5.H5Pexist(lid1, PROP4_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5Pexist plist_class_id: " + err);
}
assertTrue("H5Pexist lid1 "+PROP4_NAME, status);
}
finally {
if (lid1 > 0)
try {H5.H5Pclose(lid1);} catch (Throwable err) {}
}
}
// // Test basic generic property list code. Tests callbacks for property lists in a generic class.
// @Test
// public void testH5P_genprop_class_callback() {
// class cdata {
// public long cls_id = HDF5Constants.H5I_INVALID_HID;
// public int cls_count = -1;
// cdata(long id, int count) {
// this.cls_id = id;
// this.cls_count = count;
// }
// }
// class H5P_cls_create_data implements H5P_cls_create_func_t {
// public ArrayList<cdata> clsdata = new ArrayList<cdata>();
// }
// H5P_cls_create_func_t cls_create_data = new H5P_cls_create_data();
//
// class H5P_cls_create_callback implements H5P_cls_create_func_cb {
// public int callback(long list_id, H5P_cls_create_func_t cls_data) {
// System.err.println("H5P_cls_create_callback enter");
// cdata cd = ((H5P_cls_create_data)cls_create_data).clsdata.get(0);
// cd.cls_count++;
// cd.cls_id = list_id;
// return 0;
// }
// }
// H5P_cls_create_func_cb cls_create_cb = new H5P_cls_create_callback();
//
// class H5P_cls_copy_data implements H5P_cls_copy_func_t {
// public ArrayList<cdata> clsdata = new ArrayList<cdata>();
// }
// H5P_cls_copy_func_t cls_copy_data = new H5P_cls_copy_data();
//
// class H5P_cls_copy_callback implements H5P_cls_copy_func_cb {
// public int callback(long list_id1, long list_id2, H5P_cls_copy_func_t cls_data) {
// cdata cd = ((H5P_cls_copy_data)cls_copy_data).clsdata.get(0);
// cd.cls_count++;
// cd.cls_id = list_id1;
// return 0;
// }
// }
// H5P_cls_copy_func_cb cls_copy_cb = new H5P_cls_copy_callback();
//
// class H5P_cls_close_data implements H5P_cls_close_func_t {
// public ArrayList<cdata> clsdata = new ArrayList<cdata>();
// }
// H5P_cls_close_func_t cls_close_data = new H5P_cls_close_data();
//
// class H5P_cls_close_callback implements H5P_cls_close_func_cb {
// public int callback(long list_id, H5P_cls_close_func_t cls_data) {
// cdata cd = ((H5P_cls_close_data)cls_close_data).clsdata.get(0);
// cd.cls_count++;
// cd.cls_id = list_id;
// return 0;
// }
// }
// H5P_cls_close_func_cb cls_close_cb = new H5P_cls_close_callback();
//
// long cid1 = HDF5Constants.H5I_INVALID_HID; // Generic Property class ID
// long cid2 = HDF5Constants.H5I_INVALID_HID; // Generic Property class ID
// long lid1 = HDF5Constants.H5I_INVALID_HID; // Generic Property list ID
// long lid2 = HDF5Constants.H5I_INVALID_HID; // Generic Property list ID
// long lid3 = HDF5Constants.H5I_INVALID_HID; // Generic Property list ID
// long nprops = -1; // Number of properties in class
//
// try {
// // Create a new generic class, derived from the root of the class hierarchy
// try {
// cid1 = H5.H5Pcreate_class(HDF5Constants.H5P_ROOT, CLASS1_NAME, cls_create_cb, cls_create_data, cls_copy_cb, cls_copy_data, cls_close_cb, cls_close_data);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pcreate_class cid1: " + err);
// }
// assertTrue("H5Pcreate_class cid1", cid1 >= 0);
//
// // Insert first property into class (with no callbacks)
// try {
// byte[] prop_value = HDFNativeData.intToByte(prop1_def);
//
// H5.H5Pregister2(cid1, PROP1_NAME, PROP1_SIZE, prop_value, null, null, null, null, null, null, null);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pregister2 cid1: "+PROP1_NAME + err);
// }
//
// // Insert second property into class (with no callbacks)
// try {
// byte[] prop_value = HDFNativeData.floatToByte(prop2_def);
//
// H5.H5Pregister2(cid1, PROP2_NAME, PROP2_SIZE, prop_value, null, null, null, null, null, null, null);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pregister2 cid1: "+PROP2_NAME + err);
// }
//
// // Insert third property into class (with no callbacks)
// try {
// byte[] prop_value = new String(prop3_def).getBytes(StandardCharsets.UTF_8);
//
// H5.H5Pregister2(cid1, PROP3_NAME, PROP3_SIZE, prop_value, null, null, null, null, null, null, null);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pregister2 cid1: "+PROP3_NAME + err);
// }
//
// // Check the number of properties in class
// try {
// nprops = H5.H5Pget_nprops(cid1);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pget_nprops cid1: " + err);
// }
// assertTrue("H5Pget_nprops: "+nprops, nprops==3);
//
// // Initialize class callback structs
// cdata create_id = new cdata(-1, 0);
// cdata copy_id = new cdata(-1, 0);
// cdata close_id = new cdata(-1, 0);
// ((H5P_cls_create_data)cls_create_data).clsdata.add(create_id);
// ((H5P_cls_copy_data)cls_copy_data).clsdata.add(copy_id);
// ((H5P_cls_close_data)cls_close_data).clsdata.add(close_id);
//
// // Create a property list from the class
// try {
// lid1 = H5.H5Pcreate(cid1);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pcreate lid1: " + err);
// }
//
// // Verify that the creation callback occurred
// assertFalse("H5Pcreate ",((H5P_cls_create_data)cls_create_data).clsdata.isEmpty());
// assertTrue("H5Pcreate "+((H5P_cls_create_data)cls_create_data).clsdata.get(0).cls_id ,((H5P_cls_create_data)cls_create_data).clsdata.get(0).cls_id == lid1);
// assertTrue("H5Pcreate "+(((H5P_cls_create_data)cls_create_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_create_data)cls_create_data).clsdata.get(0)).cls_count==1);
//
// // Check the number of properties in list
// try {
// nprops = H5.H5Pget_nprops(lid1);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pget_nprops lid1: " + err);
// }
// assertTrue("H5Pget_nprops: "+nprops, nprops==3);
//
// // Create another property list from the class
// try {
// lid2 = H5.H5Pcreate(cid1);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pcreate lid2: " + err);
// }
//
// /* Verify that the creation callback occurred */
// assertFalse("H5Pcreate ",((H5P_cls_create_data)cls_create_data).clsdata.isEmpty());
// assertTrue("H5Pcreate "+((H5P_cls_create_data)cls_create_data).clsdata.get(0).cls_id ,((H5P_cls_create_data)cls_create_data).clsdata.get(0).cls_id == lid2);
// assertTrue("H5Pcreate "+(((H5P_cls_create_data)cls_create_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_create_data)cls_create_data).clsdata.get(0)).cls_count==2);
//
// // Check the number of properties in list
// try {
// nprops = H5.H5Pget_nprops(lid2);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pget_nprops lid2: " + err);
// }
// assertTrue("H5Pget_nprops: "+nprops, nprops==3);
//
// // Create another property list by copying an existing list
// try {
// lid3= H5.H5Pcopy(lid1);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pcopy lid3: " + err);
// }
//
// // Verify that the copy callback occurred
// assertFalse("H5Pcopy ",((H5P_cls_copy_data)cls_copy_data).clsdata.isEmpty());
// assertTrue("H5Pcopy "+((H5P_cls_copy_data)cls_copy_data).clsdata.get(0).cls_id ,((H5P_cls_copy_data)cls_copy_data).clsdata.get(0).cls_id == lid3);
// assertTrue("H5Pcopy "+(((H5P_cls_copy_data)cls_copy_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_copy_data)cls_copy_data).clsdata.get(0)).cls_count==1);
//
// // Check the number of properties in list
// try {
// nprops = H5.H5Pget_nprops(lid3);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pget_nprops lid3: " + err);
// }
// assertTrue("H5Pget_nprops: "+nprops, nprops==3);
//
// // Close first list
// try {
// H5.H5Pclose(lid1);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pclose lid1: " + err);
// }
//
// /* Verify that the close callback occurred */
// assertFalse("H5Pclose ",((H5P_cls_close_data)cls_close_data).clsdata.isEmpty());
// assertTrue("H5Pclose "+((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id ,((H5P_cls_close_data)cls_copy_data).clsdata.get(0).cls_id == lid1);
// assertTrue("H5Pclose "+(((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_close_data)cls_copy_data).clsdata.get(0)).cls_count==1);
//
// // Close second list
// try {
// H5.H5Pclose(lid2);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pclose lid2: " + err);
// }
//
// // Verify that the close callback occurred
// assertTrue("H5Pclose "+((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id ,((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id == lid2);
// assertTrue("H5Pclose "+(((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count==2);
//
// // Close third list
// try {
// H5.H5Pclose(lid3);
// }
// catch (Throwable err) {
// err.printStackTrace();
// fail("H5Pclose lid3: " + err);
// }
//
// // Verify that the close callback occurred
// assertTrue("H5Pclose "+((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id ,((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id == lid3);
// assertTrue("H5Pclose "+(((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count==3);
// }
// finally {
// if (lid3 > 0)
// try {H5.H5Pclose(lid3);} catch (Throwable err) {}
// if (lid2 > 0)
// try {H5.H5Pclose(lid2);} catch (Throwable err) {}
// if (lid1 > 0)
// try {H5.H5Pclose(lid1);} catch (Throwable err) {}
// if (cid2 > 0)
// try {H5.H5Pclose_class(cid2);} catch (Throwable err) {}
// if (cid1 > 0)
// try {H5.H5Pclose_class(cid1);} catch (Throwable err) {}
// }
// }
}
|