mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 16:44:49 +01:00
test: Load databases and scripts during runtime
This commit is contained in:
parent
6961d6f167
commit
e14797ace2
@ -3,6 +3,7 @@ enable_testing()
|
||||
add_executable(
|
||||
poet_test
|
||||
testPhreeqcMatrix.cpp
|
||||
utils.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
@ -14,9 +15,9 @@ target_link_libraries(
|
||||
target_include_directories(poet_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# read file and store in variable
|
||||
file(READ "${PROJECT_SOURCE_DIR}/database/phreeqc.dat" POET_PHREEQCDAT_DB)
|
||||
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/barite_db.dat" POET_BARITE_DB)
|
||||
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/barite_het.pqi" POET_BARITE_PQI)
|
||||
file(REAL_PATH "${PROJECT_SOURCE_DIR}/database/phreeqc.dat" POET_PHREEQCDAT_DB)
|
||||
file(REAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/barite_db.dat" POET_BARITE_DB)
|
||||
file(REAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/barite_het.pqi" POET_BARITE_PQI)
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/testPhreeqcMatrix.hpp.in" "${CMAKE_CURRENT_BINARY_DIR}/testPhreeqcMatrix.hpp")
|
||||
|
||||
|
||||
@ -5,16 +5,18 @@
|
||||
#include <testPhreeqcMatrix.hpp>
|
||||
|
||||
#include "PhreeqcMatrix.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
#define POET_TEST(name) TEST(TestPOET, name)
|
||||
|
||||
const std::string base_db = readFile(base_test::phreeqc_database);
|
||||
|
||||
POET_TEST(PhreeqcInit) {
|
||||
EXPECT_NO_THROW(
|
||||
PhreeqcMatrix(base_test::phreeqc_database, base_test::script));
|
||||
EXPECT_NO_THROW(PhreeqcMatrix(base_db, base_test::script));
|
||||
}
|
||||
|
||||
POET_TEST(PhreeqcMatrixOneSolution) {
|
||||
PhreeqcMatrix pqc_mat(base_test::phreeqc_database, base_test::script);
|
||||
PhreeqcMatrix pqc_mat(base_db, base_test::script);
|
||||
const auto ids = pqc_mat.getIds();
|
||||
EXPECT_EQ(ids.size(), 1);
|
||||
EXPECT_EQ(ids[0], 1);
|
||||
@ -44,8 +46,20 @@ POET_TEST(PhreeqcMatrixOneSolution) {
|
||||
EXPECT_EQ(equilibrium, expected_equilibrium);
|
||||
}
|
||||
|
||||
POET_TEST(PhreeqcMatrixBracketOperator) {
|
||||
PhreeqcMatrix pqc_mat(base_db, base_test::script);
|
||||
|
||||
EXPECT_NO_THROW(pqc_mat(1, "H"));
|
||||
EXPECT_NEAR(pqc_mat(1, "H"), base_test::expected_values[1], 1e-5);
|
||||
EXPECT_ANY_THROW(pqc_mat(1, "J"));
|
||||
EXPECT_ANY_THROW(pqc_mat(2, "H"));
|
||||
}
|
||||
|
||||
const std::string barite_db = readFile(barite_test::database);
|
||||
const std::string barite_script = readFile(barite_test::script);
|
||||
|
||||
POET_TEST(PhreeqcMatrixMultiSolution) {
|
||||
PhreeqcMatrix pqc_mat(barite_test::database, barite_test::script);
|
||||
PhreeqcMatrix pqc_mat(barite_db, barite_script);
|
||||
|
||||
const auto ids = pqc_mat.getIds();
|
||||
EXPECT_EQ(ids.size(), 4);
|
||||
@ -94,7 +108,7 @@ POET_TEST(PhreeqcMatrixMultiSolution) {
|
||||
}
|
||||
|
||||
POET_TEST(PhreeqcMatrixCtor) {
|
||||
PhreeqcMatrix pqc_mat(barite_test::database, barite_test::script);
|
||||
PhreeqcMatrix pqc_mat(barite_db, barite_script);
|
||||
PhreeqcMatrix pqc_mat_copy(pqc_mat);
|
||||
PhreeqcMatrix pqc_mat_move(std::move(pqc_mat_copy));
|
||||
|
||||
@ -119,7 +133,7 @@ POET_TEST(PhreeqcMatrixCtor) {
|
||||
}
|
||||
|
||||
POET_TEST(PhreeqcMatrixOperator) {
|
||||
PhreeqcMatrix pqc_mat(barite_test::database, barite_test::script);
|
||||
PhreeqcMatrix pqc_mat(barite_db, barite_script);
|
||||
PhreeqcMatrix pqc_mat_copy = pqc_mat;
|
||||
|
||||
const auto ids = pqc_mat_copy.getIds();
|
||||
@ -144,7 +158,7 @@ POET_TEST(PhreeqcMatrixOperator) {
|
||||
}
|
||||
|
||||
POET_TEST(PhreeqcMatrixRvalueManipulation) {
|
||||
PhreeqcMatrix pqc_mat(barite_test::database, barite_test::script);
|
||||
PhreeqcMatrix pqc_mat(barite_db, barite_script);
|
||||
|
||||
PhreeqcMatrix pqc_erased = pqc_mat.erase({1});
|
||||
|
||||
@ -175,7 +189,7 @@ POET_TEST(PhreeqcMatrixRvalueManipulation) {
|
||||
}
|
||||
|
||||
POET_TEST(PhreeqcMatrixColumnMajorExport) {
|
||||
PhreeqcMatrix pqc_mat(barite_test::database, barite_test::script);
|
||||
PhreeqcMatrix pqc_mat(barite_db, barite_script);
|
||||
|
||||
pqc_mat = pqc_mat.subset({2, 3});
|
||||
|
||||
@ -193,12 +207,3 @@ POET_TEST(PhreeqcMatrixColumnMajorExport) {
|
||||
EXPECT_EQ(exported.values[0], 2);
|
||||
EXPECT_EQ(exported.values[1], 3);
|
||||
}
|
||||
|
||||
POET_TEST(PhreeqcMatrixBracketOperator) {
|
||||
PhreeqcMatrix pqc_mat(base_test::phreeqc_database, base_test::script);
|
||||
|
||||
EXPECT_NO_THROW(pqc_mat(1, "H"));
|
||||
EXPECT_NEAR(pqc_mat(1, "H"), base_test::expected_values[1], 1e-5);
|
||||
EXPECT_ANY_THROW(pqc_mat(1, "J"));
|
||||
EXPECT_ANY_THROW(pqc_mat(2, "H"));
|
||||
}
|
||||
25
poet/test/utils.cpp
Normal file
25
poet/test/utils.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <linux/limits.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
std::string readFile(const std::string &path) {
|
||||
std::string string_rpath(PATH_MAX, '\0');
|
||||
|
||||
if (realpath(path.c_str(), string_rpath.data()) == nullptr) {
|
||||
throw std::runtime_error("Failed to resolve the realpath to file " + path);
|
||||
}
|
||||
|
||||
std::ifstream file(string_rpath);
|
||||
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("Failed to open file: " + path);
|
||||
}
|
||||
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
|
||||
return buffer.str();
|
||||
}
|
||||
5
poet/test/utils.hpp
Normal file
5
poet/test/utils.hpp
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string readFile(const std::string &path);
|
||||
Loading…
x
Reference in New Issue
Block a user