build(libconstants): changed over to use external libconstants
this is the same module as before just broken out into its own subproject
This commit is contained in:
@@ -13,7 +13,6 @@ foreach test_file : test_sources
|
||||
test_file,
|
||||
dependencies: [gtest_dep, config_dep, gtest_main],
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "const.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* @file constTest.cpp
|
||||
* @brief Unit tests for the const class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Test suite for the const class.
|
||||
*/
|
||||
class constTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
serif::constant::Constants::getInstance();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @test Verify default constructor initializes correctly.
|
||||
*/
|
||||
TEST_F(constTest, DefaultConstructor) {
|
||||
EXPECT_NO_THROW(serif::constant::Constants::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify constructor initializes with provided data and metadata.
|
||||
*/
|
||||
TEST_F(constTest, isLoaded) {
|
||||
|
||||
EXPECT_NO_THROW(serif::constant::Constants::getInstance().isLoaded());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify get method returns the correct constant.
|
||||
*/
|
||||
TEST_F(constTest, GetMethod) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
EXPECT_DOUBLE_EQ(obj.get("c").value, 2.99792458e10);
|
||||
EXPECT_EQ(obj.get("c").unit, "cm / s");
|
||||
EXPECT_DOUBLE_EQ(obj.get("c").uncertainty, 0.0);
|
||||
EXPECT_EQ(obj.get("c").reference, "CODATA2022");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify [] opperators returns the correct constant.
|
||||
*/
|
||||
TEST_F(constTest, SubscriptOperator) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
EXPECT_DOUBLE_EQ(obj["c"].value, 2.99792458e10);
|
||||
EXPECT_EQ(obj["c"].unit, "cm / s");
|
||||
EXPECT_DOUBLE_EQ(obj["c"].uncertainty, 0.0);
|
||||
EXPECT_EQ(obj["c"].reference, "CODATA2022");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test Verify that the has method returns the correct values
|
||||
*/
|
||||
TEST_F(constTest, HasMethod) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
|
||||
EXPECT_TRUE(obj.has("c"));
|
||||
EXPECT_FALSE(obj.has("c4"));
|
||||
EXPECT_TRUE(obj.has("hbar"));
|
||||
}
|
||||
|
||||
TEST_F(constTest, KeysMethod) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
std::set<std::string> checkKeys;
|
||||
checkKeys.insert("c");
|
||||
checkKeys.insert("wienK");
|
||||
checkKeys.insert("hbar");
|
||||
checkKeys.insert("g_h");
|
||||
checkKeys.insert("R_sun");
|
||||
|
||||
std::set<std::string> keys = obj.keys();
|
||||
|
||||
for (const auto& key : checkKeys) {
|
||||
bool found = keys.find(key) != keys.end();
|
||||
EXPECT_TRUE(found);
|
||||
}
|
||||
|
||||
std::set<std::string> checkBadKeys;
|
||||
checkBadKeys.insert("c4");
|
||||
checkBadKeys.insert("wienK4");
|
||||
checkBadKeys.insert("hbar4");
|
||||
checkBadKeys.insert("g_h4");
|
||||
checkBadKeys.insert("R_sun4");
|
||||
|
||||
for (const auto& key : checkBadKeys) {
|
||||
bool found = keys.find(key) != keys.end();
|
||||
EXPECT_FALSE(found);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(constTest, StreamOperator) {
|
||||
serif::constant::Constants& obj = serif::constant::Constants::getInstance();
|
||||
std::ostringstream os;
|
||||
|
||||
os << obj.get("c");
|
||||
std::string expected = "<speed of light in vacuum: 2.99792e+10±0 cm / s (CODATA2022)>\n";
|
||||
|
||||
EXPECT_EQ(os.str(), expected);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
# Test files for const
|
||||
test_sources = [
|
||||
'constTest.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, const_dep, gtest_main],
|
||||
include_directories: include_directories('../../src/constants/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)
|
||||
endforeach
|
||||
@@ -4,7 +4,6 @@ gtest_main = dependency('gtest_main', required: true)
|
||||
gtest_nomain_dep = dependency('gtest', main: false, required : true)
|
||||
|
||||
# Subdirectories for unit and integration tests
|
||||
subdir('const')
|
||||
subdir('meshIO')
|
||||
subdir('probe')
|
||||
subdir('config')
|
||||
|
||||
Reference in New Issue
Block a user