diff --git a/tests/meson.build b/tests/meson.build index e68b8a2..45693ff 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -5,6 +5,7 @@ gtest_nomain_dep = dependency('gtest', main: false, required : true) # Subdirectories for unit and integration tests subdir('dobj') subdir('const') +subdir('opatIO') # Subdirectories for sandbox tests subdir('dobj_sandbox') diff --git a/tests/opatIO/example.opat b/tests/opatIO/example.opat new file mode 100755 index 0000000..7b7e918 Binary files /dev/null and b/tests/opatIO/example.opat differ diff --git a/tests/opatIO/meson.build b/tests/opatIO/meson.build new file mode 100644 index 0000000..8722176 --- /dev/null +++ b/tests/opatIO/meson.build @@ -0,0 +1,27 @@ +# 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], + include_directories: include_directories('../../src/opatIO/public'), + link_with: libopatIO, # 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 diff --git a/tests/opatIO/opatIOTest.cpp b/tests/opatIO/opatIOTest.cpp new file mode 100644 index 0000000..2356ff7 --- /dev/null +++ b/tests/opatIO/opatIOTest.cpp @@ -0,0 +1,78 @@ +#include +#include "opatIO.h" +#include +#include +#include +#include +#include + +std::string EXAMPLE_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/opatIO/example.opat"; + +class TestableOpatIO : public OpatIO { +public: + using OpatIO::flushQueue; +}; +/** + * @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_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, 417856); + EXPECT_EQ(std::string(header.creationDate), "Feb 14, 2025"); + EXPECT_EQ(std::string(header.sourceInfo), "MESA 12700, Synthetic Opacity Data"); + EXPECT_EQ(std::string(header.comment), "log10 kappa (cm^2/g)"); +} + +TEST_F(opatIOTest, TableIndex) { + OpatIO opatIO(EXAMPLE_FILENAME); + std::vector tableIndex = opatIO.getTableIndex(); + EXPECT_EQ(tableIndex.size(), 20); + EXPECT_EQ(tableIndex[0].X, 0.1); + EXPECT_EQ(tableIndex[0].Z, 0.001); + EXPECT_EQ(tableIndex[0].byteStart, 1696); + EXPECT_EQ(tableIndex[0].byteEnd, 22504); +} + +TEST_F(opatIOTest, MaxQDepth) { + OpatIO opatIO(EXAMPLE_FILENAME); + EXPECT_EQ(opatIO.getMaxQDepth(), 10); + opatIO.setMaxQDepth(5); + EXPECT_EQ(opatIO.getMaxQDepth(), 5); +} + +TEST_F(opatIOTest, unload){ + OpatIO opatIO(EXAMPLE_FILENAME); + EXPECT_NO_THROW(opatIO.unload()); + EXPECT_FALSE(opatIO.isLoaded()); +} + +TEST_F(opatIOTest, FlushQueue){ + TestableOpatIO opatIO; + EXPECT_NO_THROW(opatIO.flushQueue()); +} \ No newline at end of file