Skip to content

Commit

Permalink
Update test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Aug 16, 2024
1 parent 2508b1b commit 6ba3cc6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
30 changes: 28 additions & 2 deletions ModelicaTableAdditions/Resources/BuildProjects/CMake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,35 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Disable building GMock
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)

# Do not install GTest
# Do not install GTest
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(googletest)

set_target_properties(gtest gtest_main PROPERTIES FOLDER "Test/Third-party")
FetchContent_Declare(
zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.3.1
)

# Do not build zlib examples
set(ZLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

# Do not install zlib
set(SKIP_INSTALL_ALL TRUE CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(zlib)

# Patch zlib1.rc file to avoid syntax error
if(CYGWIN)
file(READ "${zlib_SOURCE_DIR}/win32/zlib1.rc" ZLIB_RC_CONTENT)
string(REPLACE " MOVEABLE IMPURE LOADONCALL DISCARDABLE" "" ZLIB_RC_CONTENT "${ZLIB_RC_CONTENT}")
file(WRITE "${zlib_SOURCE_DIR}/win32/zlib1.rc" "${ZLIB_RC_CONTENT}")
endif()

set(ZLIB_INCLUDE_DIR ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})

set_target_properties(gtest gtest_main zlib zlibstatic PROPERTIES FOLDER "Test/Third-party")

set(MODELICA_TABLE_ADDITIONS_TEST_DIR "${MODELICA_TABLE_ADDITIONS_RESOURCES_DIR}/Test")
if(EXISTS "${MODELICA_TABLE_ADDITIONS_TEST_DIR}")
Expand Down Expand Up @@ -59,6 +82,8 @@ if(EXISTS "${MODELICA_TABLE_ADDITIONS_TEST_DIR}")
if(MSVC)
target_compile_options(ModelicaTableAdditionsTestCommon PRIVATE /wd4267)
endif()
target_compile_definitions(ModelicaTableAdditionsTestCommon PRIVATE -DHAVE_ZLIB=1)
target_include_directories(ModelicaTableAdditionsTestCommon PRIVATE ${ZLIB_INCLUDE_DIR})

set(MODELICA_TESTS
Tables
Expand All @@ -81,6 +106,7 @@ if(EXISTS "${MODELICA_TABLE_ADDITIONS_TEST_DIR}")
ModelicaTableAdditionsTestCommon
parson
gtest
zlibstatic
)
if(UNIX)
target_link_libraries(Test${TEST} PRIVATE m)
Expand Down
Binary file removed ModelicaTableAdditions/Resources/Data/Tables/test.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 19 additions & 4 deletions ModelicaTableAdditions/Resources/Test/TablesFromMatFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
namespace
{

TEST(CombiTable1D, Steffen_47x2) {
class CombiTable1DTest
: public ::testing::TestWithParam<std::pair<const char *, const char *>> {
protected:
void SetUp() override {}
void TearDown() override {}
};

TEST_P(CombiTable1DTest, Steffen_47x2) {
double dummy = 0.0;
constexpr const auto cols = std::array<int, 1>{2};
auto table = ModelicaTableAdditions_CombiTable1D_init2(
"../Data/Tables/test.mat", "tab1", &dummy, 0, 0, cols.data(), cols.size(),
smooth_steffen, extrapol_error, verbose_on);
std::get<0>(GetParam()), std::get<1>(GetParam()), &dummy, 0, 0,
cols.data(), cols.size(), smooth_steffen, extrapol_error, verbose_on);
const auto umin = ModelicaTableAdditions_CombiTable1D_minimumAbscissa(table);
EXPECT_NEAR(umin, 0.0, 1e-10);
const auto umax = ModelicaTableAdditions_CombiTable1D_maximumAbscissa(table);
Expand All @@ -21,7 +28,15 @@ TEST(CombiTable1D, Steffen_47x2) {
ModelicaTableAdditions_CombiTable1D_close(table);
}

} // namespace
INSTANTIATE_TEST_SUITE_P(
TablesFromMatFile, CombiTable1DTest,
::testing::Values(
std::make_pair("../Data/Tables/test_v4.mat", "tab1"),
std::make_pair("../Data/Tables/test_v6.mat", "tab1"),
std::make_pair("../Data/Tables/test_v7.mat", "tab1"))
);

} // namespace

int main(int argc, char **argv)
{
Expand Down

0 comments on commit 6ba3cc6

Please sign in to comment.