Debian Codegraph @

packages/epetraext/test/inout/EpetraExt_HDF5_UnitTest.cpp

raw
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux ([email protected])
38 //
39 // ***********************************************************************
40 //@HEADER
41
42 #include "Teuchos_UnitTestHarness.hpp"
43 #include "Teuchos_GlobalMPISession.hpp"
44
45 #ifdef HAVE_MPI
46 #include "mpi.h"
47 #include "Epetra_MpiComm.h"
48 #else
49 #include "Epetra_SerialComm.h"
50 #endif
51
52 #include "EpetraExt_HDF5.h"
53
54 namespace EpetraExt {
55
56 TEUCHOS_UNIT_TEST(EpetraExt_HDF5, WriteReadInt)
57 {
58 #ifdef EPETRA_MPI
59 Epetra_MpiComm comm(MPI_COMM_WORLD);
60 #else
61 Epetra_SerialComm comm;
62 #endif
63
64 HDF5 file1(comm);
65 file1.Create("HDF5_test.h5");
66
67 const int value1 = 5;
68 file1.Write("data", "int", value1);
69 file1.Close();
70
71 HDF5 file2(comm);
72 file2.Open("HDF5_test.h5");
73
74 int value2 = -1;
75 file2.Read("data", "int", value2);
76 file2.Close();
77
78 TEST_EQUALITY(value1, value2);
79 }
80
81 TEUCHOS_UNIT_TEST(EpetraExt_HDF5, WriteReadSerialData)
82 {
83 #ifdef EPETRA_MPI
84 Epetra_MpiComm comm(MPI_COMM_WORLD);
85 #else
86 Epetra_SerialComm comm;
87 #endif
88
89 HDF5 file1(comm);
90 file1.Create("HDF5_test.h5");
91
92 const int data1[2] = {1, 2};
93 file1.Write("data", "values", H5T_NATIVE_INT, 2, data1);
94 file1.Close();
95
96 HDF5 file2(comm);
97 file2.Open("HDF5_test.h5");
98
99 int data2[2] = {-1, -1};
100 file2.Read("data", "values", H5T_NATIVE_INT, 2, data2);
101 file2.Close();
102
103 TEST_EQUALITY(data1[0], data2[0]);
104 TEST_EQUALITY(data1[1], data2[1]);
105 }
106
107 TEUCHOS_UNIT_TEST(EpetraExt_HDF5, NestedGroups)
108 {
109 #ifdef EPETRA_MPI
110 Epetra_MpiComm comm(MPI_COMM_WORLD);
111 #else
112 Epetra_SerialComm comm;
113 #endif
114
115 HDF5 file1(comm);
116 file1.Create("HDF5_test.h5");
117
118 const int value1 = 5;
119 file1.CreateGroup("group 1");
120 file1.CreateGroup("group 1/group 2");
121 file1.Write("group 1/group 2/data", "int", value1);
122 file1.Close();
123
124 HDF5 file2(comm);
125 file2.Open("HDF5_test.h5");
126
127 int value2 = -1;
128 file2.Read("group 1/group 2/data", "int", value2);
129 file2.Close();
130
131 TEST_EQUALITY(value1, value2);
132 }
133
134 } // namespace EpetraExt
135
136 int main(int argc, char* argv[])
137 {
138 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
139 return Teuchos::UnitTestRepository::runUnitTestsFromMain(argc, argv);
140 }