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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.exceptions.HDF5Exception;
import hdf.hdf5lib.exceptions.HDF5LibraryException;
import hdf.hdf5lib.structs.H5FD_ros3_fapl_t;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
public class TestH5Pfapls3 {
@Rule public TestName testname = new TestName();
long fapl_id = HDF5Constants.H5I_INVALID_HID;
long plapl_id = HDF5Constants.H5I_INVALID_HID;
long dapl_id = HDF5Constants.H5I_INVALID_HID;
long plist_id = HDF5Constants.H5I_INVALID_HID;
long btplist_id = HDF5Constants.H5I_INVALID_HID;
@Before
public void createFileAccess() throws NullPointerException, HDF5Exception
{
assertTrue("H5 open ids is 0", H5.getOpenIDCount() == 0);
System.out.print(testname.getMethodName());
try {
fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5Pfapl.createFileAccess: " + err);
}
assertTrue(fapl_id > 0);
try {
plapl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_ACCESS);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5Pfapl.createFileAccess: " + err);
}
assertTrue(plapl_id > 0);
try {
plist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
btplist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
dapl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_ACCESS);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5Pfapl.createFileAccess: " + err);
}
assertTrue(plist_id > 0);
assertTrue(btplist_id > 0);
assertTrue(dapl_id > 0);
}
@After
public void deleteFileAccess() throws HDF5LibraryException
{
if (fapl_id > 0)
try {H5.H5Pclose(fapl_id);} catch (Exception ex) {}
if (plapl_id > 0)
try {H5.H5Pclose(plapl_id);} catch (Exception ex) {}
if (dapl_id > 0)
try {H5.H5Pclose(dapl_id);} catch (Exception ex) {}
if (plist_id > 0)
try {H5.H5Pclose(plist_id);} catch (Exception ex) {}
if (btplist_id > 0)
try {H5.H5Pclose(btplist_id);} catch (Exception ex) {}
System.out.println();
}
@Test
public void testH5Pset_fapl_ros3() throws Exception
{
if (HDF5Constants.H5FD_ROS3 < 0)
return;
final H5FD_ros3_fapl_t config = new H5FD_ros3_fapl_t();
assertEquals("Default fapl has unexpected contents",
new H5FD_ros3_fapl_t("", "", ""), config);
H5.H5Pset_fapl_ros3(fapl_id, config);
assertEquals("driver types don't match",
HDF5Constants.H5FD_ROS3, H5.H5Pget_driver(fapl_id));
/* get_fapl_ros3 can throw exception in error cases */
H5FD_ros3_fapl_t copy = H5.H5Pget_fapl_ros3(fapl_id);
assertEquals("contents of fapl set and get don't match",
new H5FD_ros3_fapl_t("", "", ""), copy);
}
@Test(expected = HDF5LibraryException.class)
public void testH5Pget_fapl_ros3_invalid_fapl_id() throws Exception
{
if (HDF5Constants.H5FD_ROS3 < 0)
throw new HDF5LibraryException("skip");
H5FD_ros3_fapl_t fails = H5.H5Pget_fapl_ros3(-1);
}
@Test(expected = HDF5LibraryException.class)
public void testH5Pget_fapl_ros3_fapl_id_of_wrong_driver_type() throws Exception
{
if (HDF5Constants.H5FD_ROS3 < 0)
throw new HDF5LibraryException("skip");
if (HDF5Constants.H5FD_SEC2 < 0 )
throw new HDF5LibraryException("skip");
/* TODO: for now, test against a sec2 fapl only */
H5.H5Pset_fapl_sec2(fapl_id);
assertEquals("fapl_id was not set properly",
HDF5Constants.H5FD_SEC2, H5.H5Pget_driver(fapl_id));
H5FD_ros3_fapl_t fails = H5.H5Pget_fapl_ros3(fapl_id);
}
@Test
public void testH5Pset_fapl_ros3_specified() throws Exception
{
if (HDF5Constants.H5FD_ROS3 < 0)
return;
String region = "us-east-1";
String acc_id = "my_access_id";
String acc_key = "my_access_key";
final H5FD_ros3_fapl_t config = new H5FD_ros3_fapl_t(region, acc_id, acc_key);
H5.H5Pset_fapl_ros3(fapl_id, config);
assertEquals("driver types don't match",
HDF5Constants.H5FD_ROS3, H5.H5Pget_driver(fapl_id));
H5FD_ros3_fapl_t copy = H5.H5Pget_fapl_ros3(fapl_id);
assertEquals("contents of fapl set and get don't match",
new H5FD_ros3_fapl_t(region, acc_id, acc_key), copy);
}
}
|