mirror of
https://github.com/HDFGroup/hdf5.git
synced 2024-11-21 01:04:10 +08:00
216bff5778
* OESS-98 convert plugin option to FetchContent, add tests * Fixes for pkcfg files because of plugin option * OESS-98 fix tools test for plugins * Keep doxygen comments under 100 chars long - format hint * Whitespace * HDFFV-11144 - Reclassify CMake messages * HDFFV-11099/11100 added help text * Reworked switch statement to compare string instead * Fix typo * Update CDash mode * Correct name of threadsafe * Correct option name * Undo accidental commit * Note LLVM 10 to 11 format default changes * Update format plugin * Undo clang-format version 11 changes * One more correction * Update supported platforms * Revert whitespace changes * Correct whitespace * Changes from PR#3 * HDFFV-11213 added option to control gcc10 warnings diagnostics * HDFFV-11212 Use the new references correctly in JNI utility and tests * format source * Fix typo * Add new test file * HDFFV-11212 - update test and remove unused arg * Minor non-space formatting changes * Use H5I_INVALID_ID instead of "-1" * source formatting * add missing testfile, update jni function * Undo commit of debug code * remove mislocated file * Fix h5repack test for handling of fapls and id close * Update h5diff test files usage text * HDFFV-11212 add new ref tests for JNI export dataset * src format update * Remove blank line typo * src format typo * long double requires %Lg * Another long double foramt specifer S.B. %Lg * issue with t128bit test * Windows issue with h5dump and type. * Fix review issues * refactor function nesting and fix error checks * format fixes * Remove untested functions and javadoc quiet comments * Restore TRY block. * Change string append errors to memory exception * revert to H5_JNI_FATAL_ERROR - support functions need work * Add assertion error for h5util functions * remove duplicate function * format fix * Revert HD function error handling * Update copyright comments * GH #386 java folder copyright corrections * Whitespace
135 lines
4.9 KiB
Java
135 lines
4.9 KiB
Java
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
* 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.assertNotNull;
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.Assert.fail;
|
|
import hdf.hdf5lib.H5;
|
|
import hdf.hdf5lib.HDF5Constants;
|
|
import hdf.hdf5lib.exceptions.HDF5LibraryException;
|
|
import hdf.hdf5lib.structs.H5G_info_t;
|
|
import hdf.hdf5lib.structs.H5O_token_t;
|
|
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.rules.TestName;
|
|
|
|
public class TestH5Giterate {
|
|
@Rule public TestName testname = new TestName();
|
|
private static final String H5_FILE = "h5ex_g_iterate.hdf";
|
|
long H5fid = HDF5Constants.H5I_INVALID_HID;
|
|
|
|
private final long _openGroup(long fid, String name) {
|
|
long gid = HDF5Constants.H5I_INVALID_HID;
|
|
try {
|
|
gid = H5.H5Gopen(fid, name, HDF5Constants.H5P_DEFAULT);
|
|
}
|
|
catch (Throwable err) {
|
|
gid = HDF5Constants.H5I_INVALID_HID;
|
|
err.printStackTrace();
|
|
fail("H5.H5Gcreate: " + err);
|
|
}
|
|
|
|
return gid;
|
|
}
|
|
|
|
@Before
|
|
public void openH5file()
|
|
throws HDF5LibraryException, NullPointerException {
|
|
assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
|
|
System.out.print(testname.getMethodName());
|
|
|
|
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) {}
|
|
}
|
|
System.out.println();
|
|
}
|
|
|
|
@Test
|
|
public void testH5Gget_obj_info_all() {
|
|
H5G_info_t info = null;
|
|
|
|
long 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];
|
|
H5O_token_t objTokens[] = new H5O_token_t[(int) info.nlinks];
|
|
|
|
int names_found = 0;
|
|
try {
|
|
names_found = H5.H5Gget_obj_info_all(H5fid, "/", objNames,
|
|
objTypes, lnkTypes, objTokens, 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]);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|