1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * Copyright by The HDF Group. * 3 * Copyright by the Board of Trustees of the University of Illinois. * 4 * All rights reserved. * 5 * * 6 * This file is part of HDF5. The full HDF5 copyright notice, including * 7 * terms governing use, modification, and redistribution, is contained in * 8 * the COPYING file, which can be found at the root of the source code * 9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * 10 * If you do not have access to either file, you may request a copy from * 11 * help@hdfgroup.org. * 12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 13 14 package test; 15 16 import static org.junit.Assert.assertTrue; 17 import static org.junit.Assert.fail; 18 import hdf.hdf5lib.H5; 19 import hdf.hdf5lib.HDF5Constants; 20 import hdf.hdf5lib.exceptions.HDF5LibraryException; 21 22 import org.junit.After; 23 import org.junit.Before; 24 import org.junit.Ignore; 25 import org.junit.Rule; 26 import org.junit.Test; 27 import org.junit.rules.TestName; 28 29 public class TestH5PL { 30 @Rule public TestName testname = new TestName(); 31 private static String FILENAME = "h5_dlopenChunk.h5"; 32 private static String DATASETNAME = "DS1"; 33 private static final int DIM_X = 6; 34 private static final int DIM_Y = 8; 35 private static final int CHUNK_X = 4; 36 private static final int CHUNK_Y = 4; 37 private static final int RANK = 2; 38 private static final int NDIMS = 2; 39 private static final int H5Z_FILTER_DYNLIB4 = 260; 40 41 @Before checkOpenIDs()42 public void checkOpenIDs() { 43 assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0); 44 System.out.print(testname.getMethodName()); 45 } 46 @After nextTestName()47 public void nextTestName() { 48 System.out.println(); 49 } 50 51 @Test TestH5PLplugins()52 public void TestH5PLplugins() { 53 try { 54 int plugin_flags = H5.H5PLget_loading_state(); 55 assertTrue("H5.H5PLget_loading_state: "+plugin_flags, plugin_flags == HDF5Constants.H5PL_ALL_PLUGIN); 56 int new_setting = plugin_flags & ~HDF5Constants.H5PL_FILTER_PLUGIN; 57 H5.H5PLset_loading_state (new_setting); 58 int changed_flags = H5.H5PLget_loading_state(); 59 assertTrue("H5.H5PLget_loading_state: "+changed_flags, changed_flags == new_setting); 60 H5.H5PLset_loading_state (plugin_flags); 61 changed_flags = H5.H5PLget_loading_state(); 62 assertTrue("H5.H5PLget_loading_state: "+changed_flags, changed_flags == HDF5Constants.H5PL_ALL_PLUGIN); 63 } 64 catch (Throwable err) { 65 err.printStackTrace(); 66 fail("TestH5PLplugins " + err); 67 } 68 } 69 70 @Test TestH5PLpaths()71 public void TestH5PLpaths() { 72 try { 73 // Get the original number of paths 74 int nStartPaths = H5.H5PLsize(); 75 76 int nPaths; /* # paths from H5PLSize() */ 77 int nTruePaths = nStartPaths; /* What the # paths should be */ 78 int index; /* Path table index */ 79 String path; /* Path from H5PLget() */ 80 81 // APPEND a path and ensure it was added correctly 82 String pathAppend = "path_append"; 83 H5.H5PLappend(pathAppend); 84 85 nPaths = H5.H5PLsize(); 86 nTruePaths++; 87 assertTrue("# paths should be " + nTruePaths + " but was " + nPaths, nTruePaths == nPaths); 88 89 index = nTruePaths - 1; 90 path = H5.H5PLget(index); 91 assertTrue("Path should be " + pathAppend + " but was " + path, path.compareToIgnoreCase(pathAppend) == 0); 92 93 // PREPEND a path and ensure it was added correctly 94 String pathPrepend = "path_prepend"; 95 H5.H5PLprepend(pathPrepend); 96 97 nPaths = H5.H5PLsize(); 98 nTruePaths++; 99 assertTrue("# paths should be " + nTruePaths + " but was " + nPaths, nTruePaths == nPaths); 100 101 index = 0; 102 path = H5.H5PLget(index); 103 assertTrue("Path should be " + pathPrepend + " but was " + path, path.compareToIgnoreCase(pathPrepend) == 0); 104 105 // INSERT a path and ensure it was added correctly 106 // Inserting at the index == # of start paths ensures we're in the middle 107 String pathInsert = "path_insert"; 108 index = nStartPaths; 109 H5.H5PLinsert(pathInsert, index); 110 111 nPaths = H5.H5PLsize(); 112 nTruePaths++; 113 assertTrue("# paths should be " + nTruePaths + " but was " + nPaths, nTruePaths == nPaths); 114 115 path = H5.H5PLget(index); 116 assertTrue("Path should be " + pathInsert + " but was " + path, path.compareToIgnoreCase(pathInsert) == 0); 117 118 // REPLACE the path we just added and ensure it updated correctly 119 String pathReplace = "path_replace"; 120 index = nStartPaths; 121 H5.H5PLreplace(pathReplace, index); 122 123 nPaths = H5.H5PLsize(); 124 assertTrue("# paths should be " + nTruePaths + " but was " + nPaths, nTruePaths == nPaths); 125 126 path = H5.H5PLget(index); 127 assertTrue("Path should be " + pathReplace + " but was " + path, path.compareToIgnoreCase(pathReplace) == 0); 128 129 // REMOVE the path we just replaced and check that the table was compacted 130 // The (index+1) path should move down to fill the space when the path is removed. 131 index = nStartPaths; 132 String pathRemove = H5.H5PLget(index + 1); 133 H5.H5PLremove(index); 134 135 nPaths = H5.H5PLsize(); 136 nTruePaths--; 137 assertTrue("# paths should be " + nTruePaths + " but was " + nPaths, nTruePaths == nPaths); 138 139 path = H5.H5PLget(index); 140 assertTrue("Path should be " + pathRemove + " but was " + path, path.compareToIgnoreCase(pathRemove) == 0); 141 } 142 catch (Throwable err) { 143 err.printStackTrace(); 144 fail("TestH5PLpaths " + err); 145 } 146 } 147 148 @Ignore TestH5PLdlopen()149 public void TestH5PLdlopen() { 150 long file_id = -1; 151 long filespace_id = -1; 152 long dataset_id = -1; 153 long fapl_id = -1; 154 long dcpl_id = -1; 155 try { 156 int[] cd_values = {9, 0, 0, 0}; 157 int[] libversion = {0, 0, 0}; 158 long[] dims = { DIM_X, DIM_Y }; 159 long[] chunk_dims = { CHUNK_X, CHUNK_Y }; 160 int[][] dset_data = new int[DIM_X][DIM_Y]; 161 int[] mdc_nelmts = {0}; 162 long[] rdcc_nelmts = {0}; 163 long[] rdcc_nbytes = {0}; 164 double[] rdcc_w0 = {0}; 165 166 // Initialize data to "1", to make it easier to see the selections. 167 for (int indx = 0; indx < DIM_X; indx++) 168 for (int jndx = 0; jndx < DIM_Y; jndx++) 169 dset_data[indx][jndx] = 1; 170 171 // Create a new file using default properties. 172 try { 173 file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, 174 HDF5Constants.H5P_DEFAULT); 175 } 176 catch (Exception e) { 177 e.printStackTrace(); 178 fail("TestH5PLdlopen H5Fcreate:" + e); 179 } 180 181 // Create dataspace. Setting maximum size to NULL sets the maximum 182 // size to be the current size. 183 try { 184 filespace_id = H5.H5Screate_simple(RANK, dims, null); 185 } 186 catch (Exception e) { 187 e.printStackTrace(); 188 fail("TestH5PLdlopen H5Screate_simple:" + e); 189 } 190 191 // Create the dataset creation property list. 192 try { 193 dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE); 194 } 195 catch (Exception e) { 196 e.printStackTrace(); 197 fail("TestH5PLdlopen H5Pcreate:" + e); 198 } 199 200 // Set the chunk size. 201 try { 202 if (dcpl_id >= 0) 203 H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims); 204 } 205 catch (Exception e) { 206 e.printStackTrace(); 207 fail("TestH5PLdlopen H5Pset_chunk:" + e); 208 } 209 210 try { 211 H5.H5get_libversion(libversion); 212 cd_values[1] = libversion[0]; 213 cd_values[2] = libversion[1]; 214 cd_values[3] = libversion[2]; 215 if (dcpl_id >= 0) 216 H5.H5Pset_filter(dcpl_id, H5Z_FILTER_DYNLIB4, HDF5Constants.H5Z_FLAG_MANDATORY, 4, cd_values); 217 } 218 catch (Exception e) { 219 e.printStackTrace(); 220 fail("TestH5PLdlopen H5Pset_filter:" + e); 221 } 222 223 // Create the chunked dataset. 224 try { 225 if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) 226 dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_NATIVE_INT, filespace_id, 227 HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); 228 } 229 catch (Exception e) { 230 e.printStackTrace(); 231 fail("TestH5PLdlopen H5Dcreate:" + e); 232 } 233 234 try { 235 if (dataset_id >= 0) 236 H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, 237 HDF5Constants.H5S_ALL, dset_data); 238 } 239 catch (Exception e) { 240 e.printStackTrace(); 241 fail("TestH5PLdlopen H5Dwrite:" + e); 242 } 243 } 244 catch (Throwable err) { 245 err.printStackTrace(); 246 fail("TestH5PLdlopen " + err); 247 } 248 finally { 249 // End access to the dataset and release resources used by it. 250 if (dcpl_id >= 0) 251 try {H5.H5Pclose_class(dcpl_id);} catch (Throwable err) {} 252 if (dataset_id >= 0) 253 try {H5.H5Dclose(dataset_id);} catch (Throwable err) {} 254 if (filespace_id >= 0) 255 try {H5.H5Sclose(filespace_id);} catch (Throwable err) {} 256 if (file_id >= 0) 257 try {H5.H5Fclose(file_id);} catch (Throwable err) {} 258 } 259 } 260 } 261