test(tests): fixed broken tests
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <string>
|
||||
#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)
|
||||
{
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
@@ -1,133 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "opatIO.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#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> 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<double> 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<double> 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<double> index = {0.1, 0.001};
|
||||
TableIndex tableIndex = opatIO.getTableIndex(index);
|
||||
std::vector<unsigned char> hash = opatIO.computeChecksum(index);
|
||||
std::string hexRepr = picosha2::bytes_to_hex_string(hash);
|
||||
|
||||
std::vector<unsigned char> 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());
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
|
||||
@@ -7,9 +7,12 @@
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
#include <source_location>
|
||||
#include "config.h"
|
||||
#include <chrono>
|
||||
#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<std::string> 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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user