From f1035bd84f924299cb68c309399b288e2a69dd86 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Wed, 19 Feb 2025 16:12:23 -0500 Subject: [PATCH] test(tests/config): config tests added --- tests/config/configTest.cpp | 60 +++++++++++++++++++++++++++++++++++++ tests/config/example.yaml | 32 ++++++++++++++++++++ tests/config/meson.build | 25 ++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/config/configTest.cpp create mode 100644 tests/config/example.yaml create mode 100644 tests/config/meson.build diff --git a/tests/config/configTest.cpp b/tests/config/configTest.cpp new file mode 100644 index 0000000..817ead7 --- /dev/null +++ b/tests/config/configTest.cpp @@ -0,0 +1,60 @@ +#include +#include "config.h" +#include +#include +#include +#include +#include + +std::string EXAMPLE_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/config/example.yaml"; +/** + * @file configTest.cpp + * @brief Unit tests for the Config class. + */ + +/** + * @brief Test suite for the Config class. + */ +class configTest : public ::testing::Test {}; + +/** + * @brief Test the constructor of the Config class. + */ +TEST_F(configTest, constructor) { + EXPECT_NO_THROW(Config::getInstance()); +} + +TEST_F(configTest, loadConfig) { + Config& config = Config::getInstance(); + EXPECT_TRUE(config.loadConfig(EXAMPLE_FILENAME)); +} + +TEST_F(configTest, singletonTest) { + Config& config1 = Config::getInstance(); + Config& config2 = Config::getInstance(); + EXPECT_EQ(&config1, &config2); +} + +TEST_F(configTest, getTest) { + Config& config = Config::getInstance(); + config.loadConfig(EXAMPLE_FILENAME); + int maxIter = config.get("opac:lowTemp:numeric:maxIter", 10); + EXPECT_EQ(maxIter, 100); + EXPECT_NE(maxIter, 10); + + std::string logLevel = config.get("logLevel", "DEBUG"); + EXPECT_EQ(logLevel, "INFO"); + EXPECT_NE(logLevel, "DEBUG"); + + float polytropicIndex = config.get("poly:physics:index", 2); + EXPECT_EQ(polytropicIndex, 1.5); + EXPECT_NE(polytropicIndex, 2); + + float polytropicIndex2 = config.get("poly:physics:index2", 2.0); + EXPECT_EQ(polytropicIndex2, 2.0); +} + +TEST_F(configTest, secondSingleton) { + Config& config = Config::getInstance(); + EXPECT_EQ(config.get("opac:lowTemp:numeric:maxIter", 10), 100); +} diff --git a/tests/config/example.yaml b/tests/config/example.yaml new file mode 100644 index 0000000..de7fc5f --- /dev/null +++ b/tests/config/example.yaml @@ -0,0 +1,32 @@ +# High level options +logLevel: "INFO" +outputDir: output + +# Module options +poly: + numeric: + newtonTol: 1e-6 + newtonMaxIter: 100 + gmresTol: 1e-6 + gmresMaxIter: 100 + physics: + index: 1.5 + +# Module options +opac: + highTemp: + physics: + table: "/path/to/highTempTable.dat" + numeric: + tol: 1e-6 + maxIter: 100 + lowTemp: + physics: + table: "/path/to/lowTempTable.dat" + numeric: + tol: 1e-6 + maxIter: 100 + +mesh: + structure: + refine: 2 \ No newline at end of file diff --git a/tests/config/meson.build b/tests/config/meson.build new file mode 100644 index 0000000..7ae9ae9 --- /dev/null +++ b/tests/config/meson.build @@ -0,0 +1,25 @@ +# Test files for const +test_sources = [ + 'configTest.cpp', +] + +foreach test_file : test_sources + exe_name = test_file.split('.')[0] + message('Building test: ' + exe_name) + + # Create an executable target for each test + test_exe = executable( + exe_name, + test_file, + dependencies: [gtest_dep, config_dep], + include_directories: include_directories('../../src/config/public'), + link_with: libconst, # Link the dobj library + install_rpath: '@loader_path/../../src' # Ensure runtime library path resolves correctly + ) + + # Add the executable as a test + test( + exe_name, + test_exe, + env: ['MESON_SOURCE_ROOT=' + meson.project_source_root(), 'MESON_BUILD_ROOT=' + meson.project_build_root()]) +endforeach