File: TestH4.java

package info (click to toggle)
libhdf4 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 29,892 kB
  • sloc: ansic: 128,688; sh: 14,969; fortran: 12,444; java: 5,864; xml: 1,305; makefile: 900; yacc: 678; pascal: 418; perl: 360; javascript: 203; lex: 163; csh: 41
file content (289 lines) | stat: -rw-r--r-- 8,675 bytes parent folder | download
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF Products. The full HDF copyright                 *
 * notice, including terms governing use, modification, and redistribution,  *
 * is contained in the file, COPYING.  COPYING can be found at the root of   *
 * the source code distribution tree. You can also access it online  at      *
 * https://www.hdfgroup.org/licenses.  If you do not have access to the      *
 * 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.io.File;

import hdf.hdflib.HDFConstants;
import hdf.hdflib.HDFLibrary;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

/**
 * @author xcao
 *
 */
public class TestH4 {
    @Rule
    public TestName testname            = new TestName();
    private static final String H4_FILE = "test.hdf";
    long Hfid                           = -1;

    private final void _deleteFile(String filename)
    {
        File file = new File(filename);

        if (file.exists()) {
            try {
                file.delete();
            }
            catch (SecurityException e) {
            }
        }
    }

    @Before
    public void showTestName()
    {
        System.out.print(testname.getMethodName());
    }

    @After
    public void nextTestName()
    {
        if (Hfid > 0)
            try {
                HDFLibrary.Hclose(Hfid);
            }
            catch (Exception ex) {
            }

        _deleteFile(H4_FILE);
        System.out.println();
    }

    /**
     * Test method for {@link hdf.hdflib.HDFLibrary#J2C(int)}.
     */
    @Test
    public void testJ2C()
    {
        int DFACC_RDONLY  = 0x0001;
        int DFACC_RDWR    = 0x0003;
        int DFACC_CREATE  = 0x004;
        int AN_DATA_LABEL = 0x0000;
        int AN_DATA_DESC  = 0x0001;
        int AN_FILE_LABEL = 0x0002;
        int AN_FILE_DESC  = 0x0003;
        int DFREF_NONE    = 0x0000;

        int definedValues[] = {DFACC_RDONLY, DFACC_RDWR,    DFACC_CREATE, AN_DATA_LABEL,
                               AN_DATA_DESC, AN_FILE_LABEL, AN_FILE_DESC, DFREF_NONE};

        int j2cValues[] = {HDFConstants.DFACC_RDONLY,  HDFConstants.DFACC_RDWR,   HDFConstants.DFACC_CREATE,
                           HDFConstants.AN_DATA_LABEL, HDFConstants.AN_DATA_DESC, HDFConstants.AN_FILE_LABEL,
                           HDFConstants.AN_FILE_DESC,  HDFConstants.DFREF_NONE};

        for (int i = 0; i < definedValues.length; i++) {
            assertEquals(definedValues[i], j2cValues[i]);
        }

        assertFalse(DFACC_RDONLY == HDFConstants.DFACC_RDWR);
        assertFalse(AN_DATA_LABEL == HDFConstants.AN_FILE_DESC);
    }

    /**
     * Test method for {@link hdf.hdflib.HDFLibrary#Hgetlibversion(int[], String[])}.
     */
    @Test
    public void testHgetlibversion()
    {
        int LIB_VERSION[] = {4, 3, 0};
        int libversion[]  = {0, 0, 0};
        String version[]  = {""};

        try {
            HDFLibrary.Hgetlibversion(libversion, version);
            System.err.println("HDFLibrary.Hgetlibversion: " + libversion[0] + ": " + libversion[1] + ": " +
                               libversion[2]);
            System.err.println("HDFLibrary.Hgetlibversion: " + version[0]);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hgetlibversion: " + err);
        }

        for (int i = 0; i < 3; i++)
            assertEquals(LIB_VERSION[i], libversion[i]);

        for (int i = 0; i < 2; i++)
            assertFalse(libversion[i] == 0);
    }

    /**
     * Test method for {@link hdf.hdflib.HDFLibrary#Hopen()}.
     */
    @Test
    public void testCreateCloseOpen()
    {
        try {
            Hfid = HDFLibrary.Hopen(H4_FILE, HDFConstants.DFACC_CREATE);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hopen create failed: " + err);
        }
        assertTrue(Hfid > 0);
        try {
            HDFLibrary.Hclose(Hfid);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hclose close failed: " + err);
        }
        try {
            Hfid = HDFLibrary.Hopen(H4_FILE, HDFConstants.DFACC_RDWR);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hopen open failed: " + err);
        }
        assertTrue(Hfid > 0);
    }

    /**
     * Test method for {@link hdf.hdflib.HDFLibrary#Hishdf()}.
     */
    @Test
    public void testHishdf()
    {
        boolean fileIsHDF4 = false;

        try {
            Hfid = HDFLibrary.Hopen(H4_FILE, HDFConstants.DFACC_CREATE);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hopen create failed: " + err);
        }
        assertTrue(Hfid > 0);
        try {
            HDFLibrary.Hclose(Hfid);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hclose close failed: " + err);
        }
        try {
            fileIsHDF4 = HDFLibrary.Hishdf(H4_FILE);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hishdf failed: " + err);
        }
        assertTrue(fileIsHDF4);
    }

    /**
     * Test method for {@link hdf.hdflib.HDFLibrary#HDgetNTdesc()}.
     */
    @Test
    public void testHDgetNTdesc()
    {
        String teststr = null;

        try {
            teststr = HDFLibrary.HDgetNTdesc(HDFConstants.DFNT_NATIVE);
        }
        catch (Throwable err) {
            fail("HDFLibrary.HDgetNTdesc DFNT_NATIVE failed: " + err);
        }
        assertEquals("native format number-type not set", teststr);
        try {
            teststr = HDFLibrary.HDgetNTdesc(HDFConstants.DFNT_CUSTOM);
        }
        catch (Throwable err) {
            fail("HDFLibrary.HDgetNTdesc DFNT_CUSTOM failed: " + err);
        }
        assertEquals("custom format number-type not set", teststr);
        try {
            teststr = HDFLibrary.HDgetNTdesc(HDFConstants.DFNT_FLOAT32);
        }
        catch (Throwable err) {
            fail("HDFLibrary.HDgetNTdesc DFNT_FLOAT32 failed: " + err);
        }
        assertEquals("32-bit floating point", teststr);
        try {
            teststr = HDFLibrary.HDgetNTdesc(HDFConstants.DFNT_INT8);
        }
        catch (Throwable err) {
            fail("HDFLibrary.HDgetNTdesc DFNT_INT8 failed: " + err);
        }
        assertEquals("8-bit signed integer", teststr);
        try {
            teststr = HDFLibrary.HDgetNTdesc(HDFConstants.DFNT_CHAR8);
        }
        catch (Throwable err) {
            fail("HDFLibrary.HDgetNTdesc DFNT_CHAR8 failed: " + err);
        }
        assertEquals("8-bit signed char", teststr);
    }

    /**
     * Test method for {@link hdf.hdflib.HDFLibrary#Hnumber()}.
     */
    @Test
    public void testHnumber()
    {
        int numberobjs = -1;

        try {
            Hfid = HDFLibrary.Hopen(H4_FILE, HDFConstants.DFACC_CREATE);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hopen create failed: " + err);
        }
        assertTrue(Hfid > 0);
        try {
            numberobjs = HDFLibrary.Hnumber(Hfid);
        }
        catch (Throwable err) {
            fail("HDFLibrary.Hnumber failed: " + err);
        }
        assertTrue(numberobjs > 0);
    }

    /**
     * Test method for {@link hdf.hdflib.HDFLibrary#DFKNTsize()}.
     */
    @Test
    public void testDFKNTsize()
    {
        int testsize = -1;

        try {
            testsize = HDFLibrary.DFKNTsize(HDFConstants.DFNT_FLOAT64);
        }
        catch (Throwable err) {
            fail("HDFLibrary.DFKNTsize DFNT_FLOAT64 failed: " + err);
        }
        assertEquals(8, testsize);
        try {
            testsize = HDFLibrary.DFKNTsize(HDFConstants.DFNT_INT16);
        }
        catch (Throwable err) {
            fail("HDFLibrary.DFKNTsize DFNT_INT16 failed: " + err);
        }
        assertEquals(2, testsize);
        try {
            testsize = HDFLibrary.DFKNTsize(HDFConstants.DFNT_CHAR);
        }
        catch (Throwable err) {
            fail("HDFLibrary.DFKNTsize DFNT_CHAR failed: " + err);
        }
        assertEquals(1, testsize);
    }
}