-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMetadataTest.java
More file actions
135 lines (119 loc) · 3.81 KB
/
Copy pathMetadataTest.java
File metadata and controls
135 lines (119 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
*
*/
package test.object;
import java.util.List;
import junit.framework.TestCase;
import ncsa.hdf.hdf5lib.H5;
import ncsa.hdf.hdf5lib.HDF5Constants;
import ncsa.hdf.object.Attribute;
import ncsa.hdf.object.FileFormat;
import ncsa.hdf.object.Metadata;
import ncsa.hdf.object.h5.H5File;
import ncsa.hdf.object.h5.H5Group;
/**
* @author Rishi R. Sinha This has to be removed because both the methods tested
* here are actually abstract methods and should be tested elsewhere.
*
*/
public class MetadataTest extends TestCase {
private static final H5File H5FILE = new H5File();
private H5File testFile = null;
private H5Group testGroup = null;
private Metadata strAttr = null;
private Metadata arrayIntAttr = null;
/**
* @param arg0
*/
public MetadataTest(String arg0) {
super(arg0);
}
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
testFile = (H5File) H5FILE.open(H5TestFile.NAME_FILE_H5,
FileFormat.WRITE);
assertNotNull(testFile);
testGroup = (H5Group) testFile.get(H5TestFile.NAME_GROUP_ATTR);
assertNotNull(testGroup);
List testAttrs = testGroup.getMetadata();
assertNotNull(testAttrs);
strAttr = (Attribute) testAttrs.get(0);
assertNotNull(strAttr);
arrayIntAttr = (Attribute) testAttrs.get(1);
assertNotNull(arrayIntAttr);
}
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
super.tearDown();
// make sure all objects are closed
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;
}
}
/**
* Test method for {@link ncsa.hdf.object.Metadata#getValue()}.
*/
public final void testGetValue() {
String[] value = (String[]) strAttr.getValue();
if (!value[0].equals("String attribute.")) {
fail("getValue() fails.");
}
int[] intValue = (int[]) arrayIntAttr.getValue();
for (int i = 0; i < 10; i++) {
if (intValue[i] != i + 1) {
fail("getValue() fails");
}
}
}
/**
* Test method for
* {@link ncsa.hdf.object.Metadata#setValue(java.lang.Object)}.
*/
public final void testSetValue() {
String[] tempValue = { "Temp String Value" };
String[] prevValue = (String[]) strAttr.getValue();
strAttr.setValue(tempValue);
String[] value = (String[]) strAttr.getValue();
if (!value[0].equals("Temp String Value")) {
fail("setValue() fails.");
}
strAttr.setValue(prevValue);
int[] tempIntArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[] intPrevValue = (int[]) arrayIntAttr.getValue();
arrayIntAttr.setValue(tempIntArray);
int[] intValue = (int[]) arrayIntAttr.getValue();
for (int i = 0; i < 10; i++) {
if (intValue[i] != i) {
fail("getValue() fails");
}
}
arrayIntAttr.setValue(intPrevValue);
}
}