Repository navigation
Expand file tree
/
Copy pathCompoundDSTest.java
More file actions
141 lines (131 loc) · 5.12 KB
/
Copy pathCompoundDSTest.java
File metadata and controls
141 lines (131 loc) · 5.12 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
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
/**
*
*/
package test.unittests;
import ncsa.hdf.hdf5lib.H5;
import ncsa.hdf.hdf5lib.HDF5Constants;
import ncsa.hdf.object.Datatype;
import ncsa.hdf.object.FileFormat;
import ncsa.hdf.object.h5.H5File;
import junit.framework.TestCase;
import ncsa.hdf.object.CompoundDS;
/**
* @author rsinha
*
*/
public class CompoundDSTest extends TestCase {
private static final H5File H5FILE = new H5File();
private H5File testFile = null;
private CompoundDS testDS = null;
/**
* @param arg0
*/
public CompoundDSTest(String arg0) {
super(arg0);
}
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
testFile = (H5File)H5FILE.open(H5TestFile.NAME_FILE_H5, FileFormat.WRITE);
assertNotNull(testFile);
testDS = (CompoundDS) testFile.get(H5TestFile.NAME_DATASET_COMPOUND);
assertNotNull(testDS);
testDS.init();
}
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
final int fid = testFile.getFID();
if (fid > 0) {
int nObjs = 0;
try { nObjs = H5.H5Fget_obj_count(fid, HDF5Constants.H5F_OBJ_ALL); }
catch (final Exception ex) { fail("H5.H5Fget_obj_count() failed. "+ ex); }
assertEquals(1, nObjs); // file id should be the only one left open
}
if (testFile != null) {
try { testFile.close(); } catch (final Exception ex) {}
testFile = null;
}
}
/**
* For the Compund Dataset in the Test File, we are checking
* <ul>
* <li> geting the memberCount.
* <li> the names of each member in the dataset.
* <li> the types of each member in the dataset.
* <li> the orders of each member in the dataset.
* <li> the dims of each member in the dataset.
* </ul>
*/
public final void testFieldsHaveCorrectNameTypeOrderAndDims() {
int correctMemberCount = H5TestFile.COMPOUND_MEMBER_NAMES.length;
assertEquals(testDS.getMemberCount(), correctMemberCount);
String[] names = testDS.getMemberNames();
for (int i = 0; i < correctMemberCount; i++) {
if (!names[i].equals(H5TestFile.COMPOUND_MEMBER_NAMES[i])) {
fail("Member Name at position " + i + "should be " + H5TestFile.COMPOUND_MEMBER_NAMES[i] +
", while getMemberNames returns " + names[i]);
}
}
Datatype[] types = testDS.getMemberTypes();
for (int i = 0; i < correctMemberCount; i++) {
if (!types[i].getDatatypeDescription().equals(H5TestFile.COMPOUND_MEMBER_DATATYPES[i].getDatatypeDescription())) {
fail("Member Type at position " + i + "should be " +
H5TestFile.COMPOUND_MEMBER_DATATYPES[i].getDatatypeDescription() +
", while getMemberTypes returns " + types[i].getDatatypeDescription());
}
}
int[] orders = testDS.getMemberOrders();
for (int i = 0; i < correctMemberCount; i++) {
if (orders[i] != 1) {
fail("Member Order at position " + i + "should be " + 1 + ", while getMemberOrders returns " + orders[i]);
}
}
for (int i = 0; i < correctMemberCount; i++) {
assertNull(testDS.getMemeberDims(i)); // all scalar data
}
}
/**
* For the Compund Dataset in the Test File, we are checking
* <ul>
* <li> Geting the selectMemberCount method on the default selection.
* <li> setting ths member selection so that no member is selected.
* <li> setting the member selection so that all members are exlplicitly selected.
* <li> Adding one member at a time and checking if the addition is working properly.
* </ul>
*/
public final void testSelectionDeselectionCountWorks() {
if (testDS.getSelectedMemberCount() != H5TestFile.COMPOUND_MEMBER_NAMES.length) {
fail("Right after init getSelectedMemberCount returns" + testDS.getSelectedMemberCount()
+ ", when it should return " + H5TestFile.COMPOUND_MEMBER_NAMES.length);
}
testDS.setMemberSelection(false);
assertEquals(testDS.getSelectedMemberCount(), 0);
testDS.setMemberSelection(true);
assertEquals(testDS.getSelectedMemberCount(), H5TestFile.COMPOUND_MEMBER_NAMES.length);
testDS.setMemberSelection(false);
assertEquals(testDS.getSelectedMemberCount(), 0);
for (int i = 0; i < testDS.getMemberCount(); i++) {
testDS.selectMember(i);
int[] orders = testDS.getSelectedMemberOrders();
Datatype[] types = testDS.getMemberTypes();
for (int j = 0; j <= i; j++) {
if (!testDS.isMemberSelected(j)) {
fail("Member " + j + "was selected while isMemberSelected says it wasnt.");
}
if (orders[j] != 1) {
fail("Member Order at position " + j + "should be " + 1 + ", while getMemberOrders returns " + orders[j]);
}
if (!types[j].getDatatypeDescription().equals(H5TestFile.COMPOUND_MEMBER_DATATYPES[j].getDatatypeDescription())) {
fail("Member Type at position " + i + "should be " +
H5TestFile.COMPOUND_MEMBER_DATATYPES[j].getDatatypeDescription() +
", while getMemberTypes returns " + types[j].getDatatypeDescription());
}
}
}
}
}