add tests for lammps configuration introspection via library interface

This commit is contained in:
Axel Kohlmeyer
2020-09-14 12:17:24 -04:00
parent 155e7de859
commit f4601235c9
2 changed files with 80 additions and 0 deletions

View 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);
};