diff --git a/tests/meshIO/meshIOTest.cpp b/tests/meshIO/meshIOTest.cpp index 23f845a..52696a5 100644 --- a/tests/meshIO/meshIOTest.cpp +++ b/tests/meshIO/meshIOTest.cpp @@ -3,7 +3,7 @@ #include #include "mfem.hpp" -std::string EXAMPLE_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/src/resources/mesh/sphere.msh"; +std::string EXAMPLE_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/assets/dynamic/mesh/sphere.msh"; double ComputeMeshVolume(mfem::Mesh &mesh) { diff --git a/tests/meson.build b/tests/meson.build index 1632bbd..aeff502 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -6,7 +6,6 @@ gtest_nomain_dep = dependency('gtest', main: false, required : true) # Subdirectories for unit and integration tests subdir('dobj') subdir('const') -subdir('opatIO') subdir('meshIO') subdir('config') subdir('probe') diff --git a/tests/opatIO/meson.build b/tests/opatIO/meson.build deleted file mode 100644 index eeff066..0000000 --- a/tests/opatIO/meson.build +++ /dev/null @@ -1,25 +0,0 @@ -# Test files for opatIO -test_sources = [ - 'opatIOTest.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, picosha2_dep, gtest_main, opatio_dep], - 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 diff --git a/tests/opatIO/opatIOTest.cpp b/tests/opatIO/opatIOTest.cpp deleted file mode 100644 index f950e86..0000000 --- a/tests/opatIO/opatIOTest.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include -#include "opatIO.h" -#include -#include -#include -#include -#include -#include -#include "picosha2.h" - -std::string EXAMPLE_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/opatIO/synthetic_tables.opat"; - -/** - * @file opatIOTest.cpp - * @brief Unit tests for the OpatIO class and associated structs. - */ - -/** - * @brief Test suite for the const class. - */ -class opatIOTest : public ::testing::Test {}; - -/** - * @test Verify default constructor initializes correctly. - */ -TEST_F(opatIOTest, DefaultConstructor) { - EXPECT_NO_THROW(OpatIO()); -} - -/* - * @test Verify constructor initializes correctly with a file. - */ -TEST_F(opatIOTest, Constructor) { - OpatIO opatIO(EXAMPLE_FILENAME); -} - -/** - * @test Verify the header is read correctly. - */ -TEST_F(opatIOTest, Header) { - OpatIO opatIO(EXAMPLE_FILENAME); - Header header = opatIO.getHeader(); - EXPECT_EQ(header.version, 1); - EXPECT_EQ(header.numTables, 20); - EXPECT_EQ(header.headerSize, 256); - EXPECT_EQ(header.indexOffset, 416416); - EXPECT_EQ(std::string(header.creationDate), "Feb 17, 2025"); - EXPECT_EQ(std::string(header.sourceInfo), "utils/opatio/utils/mkTestData.py"); - EXPECT_EQ(std::string(header.comment), "Synthetic Opacity Tables"); - EXPECT_EQ(header.numIndex, 2); -} - -/** - * @test Verify the number of index values is correct. Also check the byte position and index vector - */ -TEST_F(opatIOTest, TableIndex) { - OpatIO opatIO(EXAMPLE_FILENAME); - std::vector tableIndex = opatIO.getTableIndex(); - EXPECT_EQ(tableIndex.size(), 20); - EXPECT_EQ(tableIndex[0].index.at(0), 0.1); - EXPECT_EQ(tableIndex[0].index.at(1), 0.001); - EXPECT_EQ(tableIndex[0].byteStart, 256); - EXPECT_EQ(tableIndex[0].byteEnd, 21064); -} - -/** - * @test Verify the maxQDepth (for caching) - */ -TEST_F(opatIOTest, MaxQDepth) { - OpatIO opatIO(EXAMPLE_FILENAME); - EXPECT_EQ(opatIO.getMaxQDepth(), 20); - opatIO.setMaxQDepth(5); - EXPECT_EQ(opatIO.getMaxQDepth(), 5); -} - -/** - * @test Verify the Unload function - */ -TEST_F(opatIOTest, Unload){ - OpatIO opatIO(EXAMPLE_FILENAME); - EXPECT_NO_THROW(opatIO.unload()); - EXPECT_FALSE(opatIO.isLoaded()); -} - -/** - * @test Verify the lookupTableID function - */ -TEST_F(opatIOTest, LookupTableID) { - OpatIO opatIO(EXAMPLE_FILENAME); - std::vector index = {0.321053, 0.0116842}; - EXPECT_EQ(opatIO.lookupTableID(index), 7); -} - -/** - * @test Verify the GetTable function by checking the first 2x2 square of the table - */ -TEST_F(opatIOTest, GetTable) { - OpatIO opatIO(EXAMPLE_FILENAME); - std::vector index = {0.1, 0.001}; - OPATTable tab = opatIO.getTable(index); - EXPECT_EQ(tab.N_R, 50); - EXPECT_EQ(tab.N_T, 50); - EXPECT_DOUBLE_EQ(tab.logR[0], -8.0); - EXPECT_DOUBLE_EQ(tab.logT[0], 3.0); - EXPECT_DOUBLE_EQ(tab.logKappa[0][0], -0.50183952461055); - EXPECT_DOUBLE_EQ(tab.logKappa[0][1], 1.8028572256396647); - EXPECT_DOUBLE_EQ(tab.logKappa[1][0], 1.8783385110582342); - EXPECT_DOUBLE_EQ(tab.logKappa[1][1], 1.1005312934444582); -} - - - -/** - * @test Verify the GetTable function by computing the checksum of the first table and - * comparing it to the stored checksum - */ -TEST_F(opatIOTest, Checksum) { - OpatIO opatIO(EXAMPLE_FILENAME); - std::vector index = {0.1, 0.001}; - TableIndex tableIndex = opatIO.getTableIndex(index); - std::vector hash = opatIO.computeChecksum(index); - std::string hexRepr = picosha2::bytes_to_hex_string(hash); - - std::vector storedHashVec(tableIndex.sha256, tableIndex.sha256 + 32); - std::string storedHexRepr = picosha2::bytes_to_hex_string(storedHashVec); - EXPECT_EQ(hexRepr, storedHexRepr); -} - -TEST_F(opatIOTest, ChecksumAll) { - OpatIO opatIO(EXAMPLE_FILENAME); - opatIO.setMaxQDepth(5); - EXPECT_TRUE(opatIO.validateAll()); -} \ No newline at end of file diff --git a/tests/opatIO/synthetic_tables.opat b/tests/opatIO/synthetic_tables.opat deleted file mode 100644 index b65f569..0000000 Binary files a/tests/opatIO/synthetic_tables.opat and /dev/null differ diff --git a/tests/opatIO/test.opat b/tests/opatIO/test.opat deleted file mode 100644 index f321eff..0000000 Binary files a/tests/opatIO/test.opat and /dev/null differ diff --git a/tests/probe/meson.build b/tests/probe/meson.build index 882369f..6720bc8 100644 --- a/tests/probe/meson.build +++ b/tests/probe/meson.build @@ -16,5 +16,8 @@ foreach test_file : test_sources ) # Add the executable as a test - test(exe_name, test_exe) + test( + exe_name, + test_exe, + env: ['MESON_SOURCE_ROOT=' + meson.project_source_root(), 'MESON_BUILD_ROOT=' + meson.project_build_root()]) endforeach diff --git a/tests/probe/probeTest.cpp b/tests/probe/probeTest.cpp index 2014488..fbe6bef 100644 --- a/tests/probe/probeTest.cpp +++ b/tests/probe/probeTest.cpp @@ -7,9 +7,12 @@ #include #include #include +#include "config.h" #include #include "quill/LogMacros.h" +std::string TEST_CONFIG = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/testsConfig.yaml"; + std::string getLastLine(const std::string& filename) { std::ifstream file(filename); std::string line, lastLine; @@ -38,6 +41,7 @@ std::string stripTimestamps(const std::string& logLine) { class probeTest : public ::testing::Test {}; TEST_F(probeTest, DefaultConstructorTest) { + Config::getInstance().loadConfig(TEST_CONFIG); EXPECT_NO_THROW(Probe::LogManager::getInstance()); } @@ -50,20 +54,23 @@ TEST_F(probeTest, waitTest) { } TEST_F(probeTest, getLoggerTest) { + Config::getInstance().loadConfig(TEST_CONFIG); Probe::LogManager& logManager = Probe::LogManager::getInstance(); - std::string loggerName = "log"; - quill::Logger* logger = logManager.getLogger(loggerName); + const std::string loggerName = "testLog"; + const std::string filename = "test.log"; + quill::Logger* logger = logManager.newFileLogger(filename, loggerName); EXPECT_NE(logger, nullptr); LOG_INFO(logger, "This is a test message"); // Wait for the log to be written by calling getLastLine until it is non empty std::string lastLine; while (lastLine.empty()) { - lastLine = getLastLine("4DSSE.log"); + lastLine = getLastLine("test.log"); } EXPECT_EQ(stripTimestamps(lastLine), "This is a test message"); } TEST_F(probeTest, newFileLoggerTest) { + Config::getInstance().loadConfig(TEST_CONFIG); Probe::LogManager& logManager = Probe::LogManager::getInstance(); const std::string loggerName = "newLog"; const std::string filename = "newLog.log"; @@ -79,10 +86,12 @@ TEST_F(probeTest, newFileLoggerTest) { } TEST_F(probeTest, getLoggerNames) { + Config::getInstance().loadConfig(TEST_CONFIG); Probe::LogManager& logManager = Probe::LogManager::getInstance(); std::vector loggerNames = logManager.getLoggerNames(); - EXPECT_EQ(loggerNames.size(), 3); + EXPECT_EQ(loggerNames.size(), 4); EXPECT_EQ(loggerNames.at(0), "log"); EXPECT_EQ(loggerNames.at(1), "newLog"); EXPECT_EQ(loggerNames.at(2), "stdout"); + EXPECT_EQ(loggerNames.at(3), "testLog"); }