Skip to content

Commit a2f5409

Browse files
gicmojgrewe
authored andcommitted
[test] test for bitfield2bool converter
1 parent 5810714 commit a2f5409

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/hdf5/TestH5.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <iterator>
2121
#include <stdexcept>
2222
#include <limits>
23+
#include <cstring>
2324

2425

2526
unsigned int & TestH5::open_mode()
@@ -265,6 +266,34 @@ void TestH5::testDataType() {
265266
etlb.insert("FALSE", 0UL);
266267
etlb.insert("TRUE", 1UL);
267268
CPPUNIT_ASSERT(etlb.enum_equal(etib));
269+
270+
h5x::DataType blt = nix::hdf5::data_type_to_h5_memtype(nix::DataType::Bool);
271+
272+
struct ConverTest {
273+
char input;
274+
bool output;
275+
} cttests[] = {
276+
{0, false},
277+
{1, true},
278+
{2, true}
279+
};
280+
281+
char buf[sizeof(bool)];
282+
283+
for (size_t i = 0; i < (sizeof(cttests)/sizeof(ConverTest)); i++) {
284+
ConverTest tt = cttests[i];
285+
286+
buf[0] = tt.input;
287+
nix::hdf5::HErr res = H5Tconvert(H5T_STD_B8LE, blt.h5id(), 1, buf, nullptr, H5P_DEFAULT);
288+
CPPUNIT_ASSERT(!res.isError());
289+
memcpy(&b, buf, sizeof(bool));
290+
bool lvout = tt.output;
291+
292+
int eq = memcmp(&buf, &lvout, sizeof(bool));
293+
CPPUNIT_ASSERT_EQUAL(0, eq);
294+
}
295+
296+
//const bool lvfalse = 0;
268297
}
269298

270299
void TestH5::testDataSpace() {

0 commit comments

Comments
 (0)