From 8926821fa31698d15889dcb39ee83225bdc14159 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 17 Nov 2017 23:17:08 +0100 Subject: [PATCH] Fix building if hdf5 is not found --- src/tests/CMakeLists.txt | 4 ++++ src/tests/test_main.cc | 2 ++ src/tests/unit-tests/arithmetic/matio_test.cc | 22 ++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 53d04cc9d..30b20eadb 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -161,6 +161,10 @@ if(GNUPLOT_FOUND) add_definitions(-DGNUPLOT_EXECUTABLE="${GNUPLOT_EXECUTABLE}") endif(GNUPLOT_FOUND) +if(MATIO_FOUND OR MATIO_LOCAL) + add_definitions(-DMATIO_TEST=1) +endif(MATIO_FOUND OR MATIO_LOCAL) + ################################################################################ # Optional generator ################################################################################ diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index efb2ee422..ce8de7097 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -70,7 +70,9 @@ DECLARE_string(log_dir); #include "unit-tests/arithmetic/code_generation_test.cc" #include "unit-tests/arithmetic/fft_length_test.cc" #include "unit-tests/arithmetic/fft_speed_test.cc" +#if MATIO_TEST #include "unit-tests/arithmetic/matio_test.cc" +#endif #include "unit-tests/control-plane/file_configuration_test.cc" #include "unit-tests/control-plane/in_memory_configuration_test.cc" diff --git a/src/tests/unit-tests/arithmetic/matio_test.cc b/src/tests/unit-tests/arithmetic/matio_test.cc index e49cf7b63..00bfb1bba 100644 --- a/src/tests/unit-tests/arithmetic/matio_test.cc +++ b/src/tests/unit-tests/arithmetic/matio_test.cc @@ -101,8 +101,28 @@ TEST(MatioTest, WriteAndReadGrComplex) matvar = Mat_VarCreate("x", MAT_C_SINGLE, MAT_T_SINGLE, 2, dims, &x, MAT_F_COMPLEX); ASSERT_FALSE(reinterpret_cast(matvar) == NULL) << "Error creating variable for ’x’"; + std::vector y_v = { {1.1, -10}, {2, -9}, {3, -8}, {4, -7}, {5, 6}, {6, -5}, {7, -4}, {8, 3}, {9, 2}, {10, 1}}; + const unsigned int size_y = y_v.size(); + float y_real[size_y]; + float y_imag[size_y]; + i = 0; + for (std::vector::const_iterator it = y_v.cbegin(); it != y_v.cend(); it++) + { + y_real[i] = it->real(); + y_imag[i] = it->imag(); + i++; + } + + struct mat_complex_split_t y = {y_real, y_imag}; + size_t dims_y[2] = {static_cast(size_y), 1}; + matvar_t *matvar_y; + matvar_y = Mat_VarCreate("y", MAT_C_SINGLE, MAT_T_SINGLE, 2, dims_y, &y, MAT_F_COMPLEX); + ASSERT_FALSE(reinterpret_cast(matvar_y) == NULL) << "Error creating variable for ’y’"; + Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE + Mat_VarWrite(matfp, matvar_y, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE Mat_VarFree(matvar); + Mat_VarFree(matvar_y); Mat_Close(matfp); @@ -134,5 +154,5 @@ TEST(MatioTest, WriteAndReadGrComplex) EXPECT_FLOAT_EQ(x_v[i].real(), x_v_read[i].real()); EXPECT_FLOAT_EQ(x_v[i].imag(), x_v_read[i].imag()); } - ASSERT_EQ(remove(filename.c_str()), 0); + //ASSERT_EQ(remove(filename.c_str()), 0); }