Repository navigation
Expand file tree
/
Copy pathTestH5Giterate.java
More file actions
116 lines (102 loc) · 3.81 KB
/
Copy pathTestH5Giterate.java
File metadata and controls
116 lines (102 loc) · 3.81 KB
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
package test.hdf5lib;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import ncsa.hdf.hdf5lib.H5;
import ncsa.hdf.hdf5lib.HDF5Constants;
import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException;
import ncsa.hdf.hdf5lib.structs.H5G_info_t;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestH5Giterate {
private static final String H5_FILE = "test/hdf5lib/h5ex_g_iterate.hdf";
int H5fid = -1;
private final int _openGroup(int fid, String name) {
int gid = -1;
try {
gid = H5.H5Gopen(fid, name, HDF5Constants.H5P_DEFAULT);
}
catch (Throwable err) {
gid = -1;
err.printStackTrace();
fail("H5.H5Gcreate: " + err);
}
return gid;
}
@Before
public void openH5file()
throws HDF5LibraryException, NullPointerException {
assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
try {
H5fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDONLY,
HDF5Constants.H5P_DEFAULT);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5.H5Fopen: openH5file: " + err);
}
}
@After
public void deleteH5file() throws HDF5LibraryException {
if (H5fid > 0) {
try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
}
}
@Test
public void testH5Gget_obj_info_all() {
H5G_info_t info = null;
int gid = _openGroup(H5fid, "/");
try {
info = H5.H5Gget_info(gid);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5.H5Gget_info: " + err);
}
try {
H5.H5Gclose(gid);
}
catch (Exception ex) {
}
assertNotNull(info);
assertTrue("number of links is empty", info.nlinks > 0);
String objNames[] = new String[(int) info.nlinks];
int objTypes[] = new int[(int) info.nlinks];
int lnkTypes[] = new int[(int) info.nlinks];
long objRefs[] = new long[(int) info.nlinks];
int names_found = 0;
try {
names_found = H5.H5Gget_obj_info_all(H5fid, "/", objNames,
objTypes, lnkTypes, objRefs, HDF5Constants.H5_INDEX_NAME);
}
catch (Throwable err) {
err.printStackTrace();
fail("H5.H5Gget_obj_info_all: " + err);
}
assertTrue("number found[" + names_found + "] different than expected["
+ objNames.length + "]", names_found == objNames.length);
for (int i = 0; i < objNames.length; i++) {
assertNotNull("name #" + i + " does not exist", objNames[i]);
assertTrue(objNames[i].length() > 0);
if (objTypes[i]==HDF5Constants.H5O_TYPE_GROUP) {
assertTrue("Group is index: "+i + " ",i==2);
assertTrue("Group is : "+objNames[i] + " ",objNames[i].compareToIgnoreCase("G1")==0);
}
else if (objTypes[i]==HDF5Constants.H5O_TYPE_DATASET) {
assertTrue("Dataset is index: "+i + " ",(i==0)||(i==3));
if(i==0)
assertTrue("Dataset is : "+objNames[i] + " ",objNames[i].compareToIgnoreCase("DS1")==0);
else
assertTrue("Dataset is : "+objNames[i] + " ",objNames[i].compareToIgnoreCase("L1")==0);
}
else if (objTypes[i]==HDF5Constants.H5O_TYPE_NAMED_DATATYPE) {
assertTrue("Datatype is index: "+i + " ",i==1);
assertTrue("Datatype is : "+objNames[i] + " ",objNames[i].compareToIgnoreCase("DT1")==0);
}
else {
fail(" Unknown at index: " + i + " " + objNames[i]);
}
}
}
}