1 // Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC and
2 // other Axom Project Developers. See the top-level LICENSE file for details.
3 //
4 // SPDX-License-Identifier: (BSD-3-Clause)
5 
6 //-----------------------------------------------------------------------------
7 ///
8 /// file: hdf5_smoke.cpp
9 ///
10 /// Simple smoke test for hdf5 library
11 ///
12 /// The test assumes an Axom configuration with HDF5 enabled
13 /// and does not guard against its availability.
14 //-----------------------------------------------------------------------------
15 
16 #include "axom/config.hpp"  // Brings in AXOM_USE_HDF5
17 
18 #include "hdf5.h"
19 
20 #include <iostream>
21 #include "gtest/gtest.h"
22 
23 //-----------------------------------------------------------------------------
TEST(hdf5_smoke,check_axom_define)24 TEST(hdf5_smoke, check_axom_define)
25 {
26   // This test checks that axom has the correct defines for hdf5
27   // This is brought in through axom's config.hpp
28 
29 #ifdef AXOM_USE_HDF5
30   SUCCEED();
31 #else
32   FAIL() << "Bad configuration of Axom. "
33          << "Using HDF5 smoke test, but AXOM_USE_HDF5 not defined";
34 #endif
35 }
36 
TEST(hdf5_smoke,print_version)37 TEST(hdf5_smoke, print_version)
38 {
39   // This test prints the version of hdf5. It uses only the hdf5 headers
40   std::cout << "HDF5 version is " << H5_VERSION << std::endl;
41 }
42 
TEST(hdf5_smoke,create_dset)43 TEST(hdf5_smoke, create_dset)
44 {
45   // This test uses the hdf5 dset API from a compiled library.
46   // It is a slightly modified version of an hdf5 example obtained from:
47   //   https://support.hdfgroup.org/HDF5/examples/intro.html#c
48   // Valid return codes are non-negative
49 
50   hid_t file_id, dataset_id, dataspace_id;  // identifiers
51   hsize_t dims[2];
52   herr_t status;
53   const char* FILE = "dset.h5";
54 
55   // Create a new file using default properties.
56   file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
57   EXPECT_GE(file_id, 0);
58 
59   // Create the data space for the dataset.
60   dims[0] = 4;
61   dims[1] = 6;
62   dataspace_id = H5Screate_simple(2, dims, NULL);
63   EXPECT_GE(dataspace_id, 0);
64 
65   // Create the dataset.
66   dataset_id = H5Dcreate2(file_id,
67                           "/dset",
68                           H5T_STD_I32BE,
69                           dataspace_id,
70                           H5P_DEFAULT,
71                           H5P_DEFAULT,
72                           H5P_DEFAULT);
73   EXPECT_GE(dataset_id, 0);
74 
75   // End access to the dataset and release resources used by it.
76   status = H5Dclose(dataset_id);
77   EXPECT_GE(status, 0);
78 
79   // Terminate access to the data space.
80   status = H5Sclose(dataspace_id);
81   EXPECT_GE(status, 0);
82 
83   // Close the file.
84   status = H5Fclose(file_id);
85   EXPECT_GE(status, 0);
86 }
87