test(opatIO): added tests for opatIO
This commit is contained in:
@@ -5,6 +5,7 @@ gtest_nomain_dep = dependency('gtest', main: false, required : true)
|
|||||||
# Subdirectories for unit and integration tests
|
# Subdirectories for unit and integration tests
|
||||||
subdir('dobj')
|
subdir('dobj')
|
||||||
subdir('const')
|
subdir('const')
|
||||||
|
subdir('opatIO')
|
||||||
|
|
||||||
# Subdirectories for sandbox tests
|
# Subdirectories for sandbox tests
|
||||||
subdir('dobj_sandbox')
|
subdir('dobj_sandbox')
|
||||||
|
|||||||
BIN
tests/opatIO/example.opat
Executable file
BIN
tests/opatIO/example.opat
Executable file
Binary file not shown.
27
tests/opatIO/meson.build
Normal file
27
tests/opatIO/meson.build
Normal file
@@ -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
|
||||||
78
tests/opatIO/opatIOTest.cpp
Normal file
78
tests/opatIO/opatIOTest.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include "opatIO.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
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> 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());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user