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.assertEquals; 17 import static org.junit.Assert.assertFalse; 18 import static org.junit.Assert.assertNull; 19 import static org.junit.Assert.assertTrue; 20 import static org.junit.Assert.fail; 21 22 import hdf.hdf5lib.H5; 23 import hdf.hdf5lib.HDF5Constants; 24 import hdf.hdf5lib.exceptions.HDF5Exception; 25 import hdf.hdf5lib.exceptions.HDF5LibraryException; 26 import hdf.hdf5lib.structs.H5FD_ros3_fapl_t; 27 28 import org.junit.After; 29 import org.junit.Before; 30 import org.junit.Rule; 31 import org.junit.Test; 32 import org.junit.rules.TestName; 33 34 public class TestH5Pfapls3 { 35 @Rule public TestName testname = new TestName(); 36 37 long fapl_id = -1; 38 long plapl_id = -1; 39 long dapl_id = -1; 40 long plist_id = -1; 41 long btplist_id = -1; 42 43 @Before createFileAccess()44 public void createFileAccess() throws NullPointerException, HDF5Exception 45 { 46 assertTrue("H5 open ids is 0", H5.getOpenIDCount() == 0); 47 System.out.print(testname.getMethodName()); 48 49 try { 50 fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS); 51 } 52 catch (Throwable err) { 53 err.printStackTrace(); 54 fail("TestH5Pfapl.createFileAccess: " + err); 55 } 56 assertTrue(fapl_id > 0); 57 try { 58 plapl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_ACCESS); 59 } 60 catch (Throwable err) { 61 err.printStackTrace(); 62 fail("TestH5Pfapl.createFileAccess: " + err); 63 } 64 assertTrue(plapl_id > 0); 65 try { 66 plist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER); 67 btplist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER); 68 dapl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_ACCESS); 69 } 70 catch (Throwable err) { 71 err.printStackTrace(); 72 fail("TestH5Pfapl.createFileAccess: " + err); 73 } 74 assertTrue(plist_id > 0); 75 assertTrue(btplist_id > 0); 76 assertTrue(dapl_id > 0); 77 } 78 79 @After deleteFileAccess()80 public void deleteFileAccess() throws HDF5LibraryException 81 { 82 if (fapl_id > 0) 83 try {H5.H5Pclose(fapl_id);} catch (Exception ex) {} 84 if (plapl_id > 0) 85 try {H5.H5Pclose(plapl_id);} catch (Exception ex) {} 86 if (dapl_id > 0) 87 try {H5.H5Pclose(dapl_id);} catch (Exception ex) {} 88 if (plist_id > 0) 89 try {H5.H5Pclose(plist_id);} catch (Exception ex) {} 90 if (btplist_id > 0) 91 try {H5.H5Pclose(btplist_id);} catch (Exception ex) {} 92 System.out.println(); 93 } 94 95 @Test testH5Pset_fapl_ros3()96 public void testH5Pset_fapl_ros3() throws Exception 97 { 98 if (HDF5Constants.H5FD_ROS3 < 0) 99 return; 100 101 final H5FD_ros3_fapl_t config = new H5FD_ros3_fapl_t(); 102 assertEquals("Default fapl has unexpected contents", 103 new H5FD_ros3_fapl_t("", "", ""), config); 104 105 H5.H5Pset_fapl_ros3(fapl_id, config); 106 107 assertEquals("driver types don't match", 108 HDF5Constants.H5FD_ROS3, H5.H5Pget_driver(fapl_id)); 109 110 /* get_fapl_ros3 can throw exception in error cases */ 111 H5FD_ros3_fapl_t copy = H5.H5Pget_fapl_ros3(fapl_id); 112 assertEquals("contents of fapl set and get don't match", 113 new H5FD_ros3_fapl_t("", "", ""), copy); 114 } 115 116 @Test(expected = HDF5LibraryException.class) testH5Pget_fapl_ros3_invalid_fapl_id()117 public void testH5Pget_fapl_ros3_invalid_fapl_id() throws Exception 118 { 119 if (HDF5Constants.H5FD_ROS3 < 0) 120 throw new HDF5LibraryException("skip"); 121 H5FD_ros3_fapl_t fails = H5.H5Pget_fapl_ros3(-1); 122 } 123 124 @Test(expected = HDF5LibraryException.class) testH5Pget_fapl_ros3_fapl_id_of_wrong_driver_type()125 public void testH5Pget_fapl_ros3_fapl_id_of_wrong_driver_type() throws Exception 126 { 127 if (HDF5Constants.H5FD_ROS3 < 0) 128 throw new HDF5LibraryException("skip"); 129 if (HDF5Constants.H5FD_SEC2 < 0 ) 130 throw new HDF5LibraryException("skip"); 131 /* TODO: for now, test against a sec2 fapl only */ 132 133 H5.H5Pset_fapl_sec2(fapl_id); 134 assertEquals("fapl_id was not set properly", 135 HDF5Constants.H5FD_SEC2, H5.H5Pget_driver(fapl_id)); 136 H5FD_ros3_fapl_t fails = H5.H5Pget_fapl_ros3(fapl_id); 137 } 138 139 @Test testH5Pset_fapl_ros3_specified()140 public void testH5Pset_fapl_ros3_specified() throws Exception 141 { 142 if (HDF5Constants.H5FD_ROS3 < 0) 143 return; 144 145 String region = "us-east-1"; 146 String acc_id = "my_access_id"; 147 String acc_key = "my_access_key"; 148 149 final H5FD_ros3_fapl_t config = new H5FD_ros3_fapl_t(region, acc_id, acc_key); 150 H5.H5Pset_fapl_ros3(fapl_id, config); 151 assertEquals("driver types don't match", 152 HDF5Constants.H5FD_ROS3, H5.H5Pget_driver(fapl_id)); 153 154 H5FD_ros3_fapl_t copy = H5.H5Pget_fapl_ros3(fapl_id); 155 assertEquals("contents of fapl set and get don't match", 156 new H5FD_ros3_fapl_t(region, acc_id, acc_key), copy); 157 } 158 159 } 160