add tests for lammps configuration introspection via library interface
This commit is contained in:
@ -11,3 +11,22 @@ add_executable(test_library_properties test_library_properties.cpp test_main.cpp
|
|||||||
target_link_libraries(test_library_properties PRIVATE lammps GTest::GTest GTest::GMock)
|
target_link_libraries(test_library_properties PRIVATE lammps GTest::GTest GTest::GMock)
|
||||||
target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR})
|
target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
add_test(LibraryProperties test_library_properties)
|
add_test(LibraryProperties test_library_properties)
|
||||||
|
|
||||||
|
set(PKG_COUNT 0)
|
||||||
|
foreach(PKG ${STANDARD_PACKAGES} ${SUFFIX_PACKAGES})
|
||||||
|
if(PKG_${PKG})
|
||||||
|
MATH(EXPR PKG_COUNT "${PKG_COUNT}+1")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if(PKG_MANYBODY)
|
||||||
|
set(HAS_MANYBODY 1)
|
||||||
|
else()
|
||||||
|
set(HAS_MANYBODY 0)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(test_library_config test_library_config.cpp test_main.cpp)
|
||||||
|
target_link_libraries(test_library_config PRIVATE lammps GTest::GTest GTest::GMock)
|
||||||
|
target_compile_definitions(test_library_config PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
-DNUM_LAMMPS_PACKAGES=${PKG_COUNT} -DLAMMPS_HAS_MANYBODY=${HAS_MANYBODY})
|
||||||
|
add_test(LibraryConfig test_library_config)
|
||||||
|
|||||||
61
unittest/c-library/test_library_config.cpp
Normal file
61
unittest/c-library/test_library_config.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// unit tests for checking LAMMPS configuration settings through the library interface
|
||||||
|
|
||||||
|
#include "library.h"
|
||||||
|
#include "lammps.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "test_main.h"
|
||||||
|
|
||||||
|
#define STRINGIFY(val) XSTR(val)
|
||||||
|
#define XSTR(val) #val
|
||||||
|
|
||||||
|
using ::testing::HasSubstr;
|
||||||
|
using ::testing::StartsWith;
|
||||||
|
|
||||||
|
class LAMMPS_config : public ::testing::Test {
|
||||||
|
protected:
|
||||||
|
void *lmp;
|
||||||
|
std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER);
|
||||||
|
|
||||||
|
LAMMPS_config(){};
|
||||||
|
~LAMMPS_config() override{};
|
||||||
|
|
||||||
|
void SetUp() override
|
||||||
|
{
|
||||||
|
const char *args[] = {"LAMMPS_test", "-log", "none",
|
||||||
|
"-echo", "screen", "-nocite",
|
||||||
|
"-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)};
|
||||||
|
|
||||||
|
char **argv = (char **)args;
|
||||||
|
int argc = sizeof(args) / sizeof(char *);
|
||||||
|
|
||||||
|
::testing::internal::CaptureStdout();
|
||||||
|
lmp = lammps_open_no_mpi(argc, argv, NULL);
|
||||||
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
|
if (verbose) std::cout << output;
|
||||||
|
EXPECT_THAT(output, StartsWith("LAMMPS ("));
|
||||||
|
}
|
||||||
|
void TearDown() override
|
||||||
|
{
|
||||||
|
::testing::internal::CaptureStdout();
|
||||||
|
lammps_close(lmp);
|
||||||
|
std::string output = ::testing::internal::GetCapturedStdout();
|
||||||
|
EXPECT_THAT(output, HasSubstr("Total wall time:"));
|
||||||
|
if (verbose) std::cout << output;
|
||||||
|
lmp = nullptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(LAMMPS_config, package_count)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(lammps_config_package_count(), NUM_LAMMPS_PACKAGES);
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(LAMMPS_config, has_package)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(lammps_config_has_package("MANYBODY"), LAMMPS_HAS_MANYBODY);
|
||||||
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user