From aaf9aa6d69b1ba06ff9df5a40c2384f79b8c32a5 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 29 Mar 2021 14:27:42 -0400 Subject: [PATCH] Refactoring of more tests --- unittest/commands/test_kim_commands.cpp | 183 +++++------ unittest/commands/test_lattice_region.cpp | 170 ++++------ unittest/commands/test_reset_ids.cpp | 149 ++++----- unittest/commands/test_variables.cpp | 153 ++++----- unittest/formats/compressed_dump_test.h | 16 +- unittest/formats/test_atom_styles.cpp | 299 +++++++++--------- unittest/formats/test_dump_atom.cpp | 36 +-- .../formats/test_dump_atom_compressed.cpp | 8 +- unittest/formats/test_dump_cfg.cpp | 8 +- unittest/formats/test_dump_cfg_compressed.cpp | 8 +- unittest/formats/test_dump_custom.cpp | 32 +- .../formats/test_dump_local_compressed.cpp | 12 +- unittest/formats/test_dump_xyz_compressed.cpp | 8 +- .../test_eim_potential_file_reader.cpp | 44 ++- unittest/formats/test_file_operations.cpp | 43 +-- unittest/formats/test_image_flags.cpp | 51 ++- unittest/formats/test_molecule_file.cpp | 47 +-- unittest/formats/test_pair_unit_convert.cpp | 186 ++++++----- unittest/testing/core.h | 21 +- 19 files changed, 627 insertions(+), 847 deletions(-) diff --git a/unittest/commands/test_kim_commands.cpp b/unittest/commands/test_kim_commands.cpp index 2d044b86eb..83e1e5b2d2 100644 --- a/unittest/commands/test_kim_commands.cpp +++ b/unittest/commands/test_kim_commands.cpp @@ -22,6 +22,7 @@ #include "variable.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -29,57 +30,23 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::MatchesRegex; using ::testing::StrEq; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } -class KimCommandsTest : public ::testing::Test { +class KimCommandsTest : public LAMMPSTest { protected: - LAMMPS *lmp; Variable *variable; void SetUp() override { - const char *args[] = {"KimCommandsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "KimCommandsTest"; + LAMMPSTest::SetUp(); variable = lmp->input->variable; } - - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(KimCommandsTest, kim) @@ -115,9 +82,9 @@ TEST_F(KimCommandsTest, kim_init) // TEST_FAILURE(".*ERROR: KIM Model does not support the requested unit system.*", // command("kim init ex_model_Ar_P_Morse real");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim init LennardJones_Ar real"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); int ifix = lmp->modify->find_fix("KIM_MODEL_STORE"); ASSERT_GE(ifix, 0); @@ -129,81 +96,81 @@ TEST_F(KimCommandsTest, kim_interactions) TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", command("kim interactions");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim init LennardJones_Ar real"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Must use 'kim interactions' command " "after simulation box is defined.*", command("kim interactions Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim init LennardJones_Ar real"); command("lattice fcc 4.4300"); command("region box block 0 10 0 10 0 10"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", command("kim interactions Ar Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("lattice fcc 4.4300"); command("region box block 0 20 0 20 0 20"); command("create_box 4 box"); command("create_atoms 4 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", command("kim interactions Ar Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("lattice fcc 4.4300"); command("region box block 0 10 0 10 0 10"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Must use 'kim init' before 'kim interactions'.*", command("kim interactions Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones_Ar real"); command("lattice fcc 4.4300"); command("region box block 0 10 0 10 0 10"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: fixed_types cannot be used with a KIM Portable Model.*", command("kim interactions fixed_types");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("pair_style kim LennardJones_Ar"); command("region box block 0 1 0 1 0 1"); command("create_box 4 box"); command("pair_coeff * * Ar Ar Ar Ar"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); command("lattice fcc 4.920"); command("region box block 0 10 0 10 0 10"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Species 'Ar' is not supported by this KIM Simulator Model.*", command("kim interactions Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); command("lattice fcc 4.08"); @@ -211,13 +178,13 @@ TEST_F(KimCommandsTest, kim_interactions) command("create_box 1 box"); command("create_atoms 1 box"); command("kim interactions Au"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // ASSERT_EQ(lmp->output->var_kim_periodic, 1); // TEST_FAILURE(".*ERROR: Incompatible units for KIM Simulator Model.*", // command("kim interactions Au");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones_Ar real"); command("lattice fcc 4.4300"); @@ -226,12 +193,12 @@ TEST_F(KimCommandsTest, kim_interactions) command("create_atoms 1 box"); command("kim interactions Ar"); command("mass 1 39.95"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); int ifix = lmp->modify->find_fix("KIM_MODEL_STORE"); ASSERT_GE(ifix, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones_Ar real"); command("lattice fcc 4.4300"); @@ -243,7 +210,7 @@ TEST_F(KimCommandsTest, kim_interactions) command("run 1"); command("kim interactions Ar"); command("run 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } TEST_F(KimCommandsTest, kim_param) @@ -255,18 +222,18 @@ TEST_F(KimCommandsTest, kim_param) "'kim param get/set' is mandatory.*", command("kim param unknown shift 1 shift");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: 'kim param' can only be used with a KIM Portable Model.*", command("kim param get shift 1 shift");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal 'kim param get' command.\nTo get the new " "parameter values, pair style must be assigned.\nMust use 'kim" @@ -278,7 +245,7 @@ TEST_F(KimCommandsTest, kim_param) " interactions' or 'pair_style kim' before 'kim param set'.*", command("kim param set shift 1 2");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); command("lattice fcc 4.4300"); @@ -287,7 +254,7 @@ TEST_F(KimCommandsTest, kim_param) command("create_atoms 1 box"); command("kim interactions Ar"); command("mass 1 39.95"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal index '0' for " "'shift' parameter with the extent of '1'.*", @@ -312,9 +279,9 @@ TEST_F(KimCommandsTest, kim_param) "Model does not have the requested 'unknown' parameter.*", command("kim param get unknown 1 unknown");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get shift 1 shift"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_FALSE(variable->find("shift") == -1); ASSERT_THAT(variable->retrieve("shift"), StrEq("1")); @@ -334,11 +301,11 @@ TEST_F(KimCommandsTest, kim_param) "Model does not have the requested '0.4989030' parameter.*", command("kim param set sigmas 1:1 0.5523570 0.4989030");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable new_shift equal 2"); command("kim param set shift 1 ${new_shift}"); command("kim param get shift 1 shift"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("shift"), StrEq("2")); @@ -363,51 +330,51 @@ TEST_F(KimCommandsTest, kim_param) "split' is mandatory.*", command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3 explicit"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get cutoffs 1:3 cutoffs split"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get cutoffs 1:3 cutoffs list"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.20943 2.10252 5.666115")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param set cutoffs 1 2.21 cutoffs 2 2.11"); command("kim param get cutoffs 1:2 cutoffs list"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.21 2.11")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param set cutoffs 1:3 2.3 2.2 5.7"); command("kim param get cutoffs 1:3 cutoffs list"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.3 2.2 5.7")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("lattice fcc 4.4300"); @@ -417,19 +384,19 @@ TEST_F(KimCommandsTest, kim_param) command("mass 1 39.95"); command("pair_style kim LennardJones612_UniversalShifted__MO_959249795837_003"); command("pair_coeff * * Ar"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get shift 1 shift"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("shift"), StrEq("1")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable new_shift equal 2"); command("kim param set shift 1 ${new_shift}"); command("kim param get shift 1 shift"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("shift"), StrEq("2")); } @@ -467,13 +434,13 @@ TEST_F(KimCommandsTest, kim_property) command("kim property remove 1 key short-name");); TEST_FAILURE(".*ERROR: There is no property instance to dump the content.*", command("kim property dump results.edn");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); command("kim property create 1 cohesive-potential-energy-cubic-crystal"); command("kim property modify 1 key short-name source-value 1 fcc"); command("kim property destroy 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); #endif } @@ -608,16 +575,16 @@ TEST_F(KimCommandsTest, kim_query) command(squery);); #if defined(KIM_EXTRA_UNITTESTS) - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query latconst_1 get_lattice_constant_cubic " "crystal=[fcc] species=[Al] units=[angstrom] " "model=[EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); command("kim query latconst_1 get_lattice_constant_cubic crystal=[fcc] species=[Al] " @@ -626,71 +593,71 @@ TEST_F(KimCommandsTest, kim_query) command("kim query latconst_2 get_lattice_constant_cubic crystal=[fcc] species=[Al] " "units=[angstrom] " "model=[LennardJones612_UniversalShifted__MO_959249795837_003]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349")); ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("3.328125931322575")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal"); command("kim query latconst split get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] " "units=[angstrom]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("3.234055244384789")); ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("5.167650199630013")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query latconst index get_lattice_constant_hexagonal " "crystal=[hcp] species=[Zr] units=[angstrom] " "model=[EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable latconst delete"); command("clear"); command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal"); command("kim query latconst list get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] " "units=[angstrom]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789 5.167650199630013")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); command("kim query alpha get_linear_thermal_expansion_coefficient_cubic " "crystal=[fcc] species=[Al] units=[1/K] temperature=[293.15] " "temperature_units=[K]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("alpha"), StrEq("1.654960564704273e-05")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query model_list list get_available_models species=[Al]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); std::string model_list = variable->retrieve("model_list"); auto n = model_list.find("EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005"); ASSERT_TRUE(n != std::string::npos); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query model_name index get_available_models species=[Al]"); command("variable model_name delete"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query model_name index get_available_models " @@ -708,7 +675,7 @@ TEST_F(KimCommandsTest, kim_query) command("kim query model_name index get_available_models " "species=[Al] potential_type=[\"eam\",meam]"); command("variable model_name delete"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); #endif } } // namespace LAMMPS_NS @@ -718,7 +685,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index 2924c75d9f..eb6d577652 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -22,6 +22,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -32,12 +33,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { @@ -45,51 +40,22 @@ using ::testing::ExitedWithCode; using ::testing::MatchesRegex; using ::testing::StrEq; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } -class LatticeRegionTest : public ::testing::Test { +class LatticeRegionTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"LatticeRegionTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - lmp->input->one("units metal"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "LatticeRegionTest"; + LAMMPSTest::SetUp(); + command("units metal"); } - - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(LatticeRegionTest, lattice_none) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice none 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::NONE); ASSERT_EQ(lattice->xlattice, 2.0); @@ -103,10 +69,10 @@ TEST_F(LatticeRegionTest, lattice_none) TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice none 1.0 origin");); TEST_FAILURE(".*ERROR: Expected floating point.*", command("lattice none xxx");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units lj"); command("lattice none 1.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); lattice = lmp->domain->lattice; ASSERT_EQ(lattice->xlattice, 1.0); ASSERT_EQ(lattice->ylattice, 1.0); @@ -168,27 +134,27 @@ TEST_F(LatticeRegionTest, lattice_sc) TEST_FAILURE(".*ERROR: Lattice spacings are invalid.*", command("lattice sc 1.0 spacing 1.0 -0.1 1.0");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units lj"); command("lattice sc 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); lattice = lmp->domain->lattice; ASSERT_DOUBLE_EQ(lattice->xlattice, pow(0.5, 1.0 / 3.0)); ASSERT_DOUBLE_EQ(lattice->ylattice, pow(0.5, 1.0 / 3.0)); ASSERT_DOUBLE_EQ(lattice->zlattice, pow(0.5, 1.0 / 3.0)); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice sc 1.0");); } TEST_F(LatticeRegionTest, lattice_bcc) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice bcc 4.2 orient x 1 1 0 orient y -1 1 0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::BCC); ASSERT_DOUBLE_EQ(lattice->xlattice, sqrt(2.0) * 4.2); @@ -202,18 +168,18 @@ TEST_F(LatticeRegionTest, lattice_bcc) ASSERT_EQ(lattice->basis[1][1], 0.5); ASSERT_EQ(lattice->basis[1][2], 0.5); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice bcc 1.0");); } TEST_F(LatticeRegionTest, lattice_fcc) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 3.5 origin 0.5 0.5 0.5"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::FCC); ASSERT_DOUBLE_EQ(lattice->xlattice, 3.5); @@ -239,18 +205,18 @@ TEST_F(LatticeRegionTest, lattice_fcc) command("lattice fcc 1.0 a1 0.0 1.0 0.0");); TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice fcc 1.0 orient w 1 0 0");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice fcc 1.0");); } TEST_F(LatticeRegionTest, lattice_hcp) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice hcp 3.0 orient z 0 0 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::HCP); ASSERT_DOUBLE_EQ(lattice->xlattice, 3.0); @@ -283,18 +249,18 @@ TEST_F(LatticeRegionTest, lattice_hcp) command("lattice hcp 1.0 a2 0.0 1.0 0.0");); TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", command("lattice hcp 1.0 a3 0.0 1.0 0.0");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice hcp 1.0");); } TEST_F(LatticeRegionTest, lattice_diamond) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice diamond 4.1 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::DIAMOND); ASSERT_DOUBLE_EQ(lattice->xlattice, 6.6952719636073539); @@ -335,19 +301,19 @@ TEST_F(LatticeRegionTest, lattice_diamond) ASSERT_EQ(lattice->a3[1], 0.0); ASSERT_EQ(lattice->a3[2], 1.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice diamond 1.0");); } TEST_F(LatticeRegionTest, lattice_sq) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); command("lattice sq 3.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::SQ); ASSERT_DOUBLE_EQ(lattice->xlattice, 3.0); @@ -361,19 +327,19 @@ TEST_F(LatticeRegionTest, lattice_sq) TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", command("lattice sq 1.0 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice sq 1.0");); } TEST_F(LatticeRegionTest, lattice_sq2) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); command("lattice sq2 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::SQ2); ASSERT_DOUBLE_EQ(lattice->xlattice, 2.0); @@ -387,19 +353,19 @@ TEST_F(LatticeRegionTest, lattice_sq2) ASSERT_EQ(lattice->basis[1][1], 0.5); ASSERT_EQ(lattice->basis[1][2], 0.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice sq2 1.0");); } TEST_F(LatticeRegionTest, lattice_hex) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); command("lattice hex 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::HEX); ASSERT_DOUBLE_EQ(lattice->xlattice, 2.0); @@ -422,16 +388,16 @@ TEST_F(LatticeRegionTest, lattice_hex) ASSERT_EQ(lattice->a3[1], 0.0); ASSERT_EQ(lattice->a3[2], 1.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice hex 1.0");); } TEST_F(LatticeRegionTest, lattice_custom) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable a equal 4.34"); command("variable b equal $a*sqrt(3.0)"); command("variable c equal $a*sqrt(8.0/3.0)"); @@ -449,7 +415,7 @@ TEST_F(LatticeRegionTest, lattice_custom) "basis 0.5 0.5 0.625 " "basis $t 0.0 0.125 " "basis $f 0.5 0.125 "); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::CUSTOM); ASSERT_DOUBLE_EQ(lattice->xlattice, 4.34); @@ -495,9 +461,9 @@ TEST_F(LatticeRegionTest, lattice_custom) TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice custom 1.0 basis 0.0 1.0 0");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: No basis atoms in lattice.*", command("lattice custom 1.0");); TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", command("lattice custom 1.0 origin 0.5 0.5 0.5 basis 0.0 0.0 0.0");); @@ -511,28 +477,28 @@ TEST_F(LatticeRegionTest, lattice_custom) TEST_F(LatticeRegionTest, region_fail) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice none 2.0"); command("region box block 0 1 0 1 0 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Create_atoms command before simulation box is defined.*", command("create_atoms 1 box");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Cannot create atoms with undefined lattice.*", command("create_atoms 1 box");); } TEST_F(LatticeRegionTest, region_block_lattice) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice sc 1.5"); command("region box block 0 2 0 2 0 2 units lattice"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); auto x = lmp->atom->x; @@ -553,12 +519,12 @@ TEST_F(LatticeRegionTest, region_block_lattice) TEST_F(LatticeRegionTest, region_block_box) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice sc 1.5 origin 0.75 0.75 0.75"); command("region box block 0 2 0 2 0 2 units box"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); auto x = lmp->atom->x; @@ -570,84 +536,84 @@ TEST_F(LatticeRegionTest, region_block_box) TEST_F(LatticeRegionTest, region_cone) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region box cone x 1.0 1.0 0.5 2.1 0.0 2.0"); command("create_box 1 box"); command("create_atoms 1 region box"); command("write_dump all atom init.lammpstrj"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 42); } TEST_F(LatticeRegionTest, region_cylinder) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region box cylinder z 1.0 1.0 2.1 0.0 2.0 "); command("create_box 1 box"); command("create_atoms 1 region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 114); } TEST_F(LatticeRegionTest, region_prism) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice bcc 2.5 origin 0.75 0.75 0.75"); command("region box prism 0 2 0 2 0 2 0.5 0.0 0.0"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 1); ASSERT_EQ(lmp->atom->natoms, 16); } TEST_F(LatticeRegionTest, region_sphere) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region box sphere 1.0 1.0 1.0 1.1"); command("create_box 1 box"); command("create_atoms 1 region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 14); } TEST_F(LatticeRegionTest, region_union) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region part1 sphere 2.0 1.0 1.0 1.1"); command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0"); command("region box union 2 part1 part2"); command("create_box 1 box"); command("create_atoms 1 region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 67); } TEST_F(LatticeRegionTest, region_intersect) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region part1 sphere 2.0 1.0 1.0 1.8"); command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0"); command("region box intersect 2 part1 part2"); command("create_box 1 box"); command("create_atoms 1 region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 21); } TEST_F(LatticeRegionTest, region_plane) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region box block 0.0 2.0 0.0 2.0 0.0 2.0"); command("region part1 plane 0.5 1.0 0.0 0.75 0.0 0.0"); @@ -656,7 +622,7 @@ TEST_F(LatticeRegionTest, region_plane) command("create_box 1 box"); command("create_atoms 1 region atoms"); command("write_dump all atom init.lammpstrj"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 16); } @@ -668,7 +634,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/commands/test_reset_ids.cpp b/unittest/commands/test_reset_ids.cpp index 89e09b53a6..694fc9ac77 100644 --- a/unittest/commands/test_reset_ids.cpp +++ b/unittest/commands/test_reset_ids.cpp @@ -21,6 +21,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -28,12 +29,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { @@ -41,52 +36,23 @@ using ::testing::MatchesRegex; #define GETIDX(i) lmp->atom->map(i) -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } #define STRINGIFY(val) XSTR(val) #define XSTR(val) #val -class ResetIDsTest : public ::testing::Test { +class ResetIDsTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"ResetIDsTest", "-log", "none", "-nocite", "-echo", "screen"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - Info *info = new Info(lmp); + testbinary = "ResetIDsTest"; + LAMMPSTest::SetUp(); if (info->has_style("atom", "full")) { - lmp->input->one("variable input_dir index " STRINGIFY(TEST_INPUT_FOLDER)); - lmp->input->one("include ${input_dir}/in.fourmol"); + BEGIN_HIDE_OUTPUT(); + command("variable input_dir index " STRINGIFY(TEST_INPUT_FOLDER)); + command("include ${input_dir}/in.fourmol"); + END_HIDE_OUTPUT(); } - delete info; - if (!verbose) ::testing::internal::GetCapturedStdout(); } - - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(ResetIDsTest, MolIDAll) @@ -126,9 +92,9 @@ TEST_F(ResetIDsTest, MolIDAll) // the original data file has two different molecule IDs // for two residues of the same molecule/fragment. - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids all"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(1)], 1); ASSERT_EQ(molid[GETIDX(2)], 1); @@ -168,12 +134,12 @@ TEST_F(ResetIDsTest, DeletePlusAtomID) auto molid = lmp->atom->molecule; // delete two water molecules - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group allwater molecule 3:6"); command("group twowater molecule 4:6:2"); command("delete_atoms group twowater compress no bond yes"); command("reset_mol_ids all"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); @@ -230,9 +196,9 @@ TEST_F(ResetIDsTest, DeletePlusAtomID) ASSERT_GE(GETIDX(25), 0); ASSERT_GE(GETIDX(26), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 23); for (int i = 1; i <= 23; ++i) @@ -246,11 +212,11 @@ TEST_F(ResetIDsTest, PartialOffset) auto molid = lmp->atom->molecule; // delete two water molecules - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group allwater molecule 3:6"); command("group nowater subtract all allwater"); command("reset_mol_ids allwater offset 4"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 29); ASSERT_EQ(lmp->atom->map_tag_max, 29); @@ -284,9 +250,9 @@ TEST_F(ResetIDsTest, PartialOffset) ASSERT_EQ(molid[GETIDX(28)], 8); ASSERT_EQ(molid[GETIDX(29)], 8); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids nowater offset 0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(1)], 1); ASSERT_EQ(molid[GETIDX(2)], 1); @@ -326,13 +292,13 @@ TEST_F(ResetIDsTest, DeleteAdd) auto molid = lmp->atom->molecule; // delete two water molecules - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group allwater molecule 3:6"); command("group twowater molecule 4:6:2"); command("group nowater subtract all allwater"); command("delete_atoms group twowater compress no bond yes mol yes"); command("reset_mol_ids allwater"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); @@ -389,17 +355,17 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_GE(GETIDX(25), 0); ASSERT_GE(GETIDX(26), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids sort yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 23); for (int i = 1; i <= 23; ++i) ASSERT_GE(GETIDX(i), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids nowater offset 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(1)], 2); ASSERT_EQ(molid[GETIDX(2)], 2); @@ -425,13 +391,13 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(22)], 4); ASSERT_EQ(molid[GETIDX(23)], 4); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_atoms 1 single 0.0 0.0 0.0"); command("create_atoms 2 single 1.0 0.0 0.0"); command("create_atoms 3 single 2.0 0.0 0.0"); command("create_atoms 4 single 3.0 0.0 0.0"); command("reset_mol_ids all single yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 27); ASSERT_EQ(lmp->atom->map_tag_max, 27); @@ -443,9 +409,9 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(26)], 6); ASSERT_EQ(molid[GETIDX(27)], 7); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids all single no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(21)], 3); ASSERT_EQ(molid[GETIDX(22)], 3); @@ -455,9 +421,9 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(26)], 0); ASSERT_EQ(molid[GETIDX(27)], 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids all compress no single yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(21)], 21); ASSERT_EQ(molid[GETIDX(22)], 21); @@ -473,12 +439,12 @@ TEST_F(ResetIDsTest, TopologyData) if (lmp->atom->natoms == 0) GTEST_SKIP(); // delete two water molecules - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group allwater molecule 3:6"); command("group twowater molecule 4:6:2"); command("group nowater subtract all allwater"); command("delete_atoms group twowater compress no bond yes mol yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); @@ -562,9 +528,9 @@ TEST_F(ResetIDsTest, TopologyData) ASSERT_EQ(angle_atom2[GETIDX(24)][0], 24); ASSERT_EQ(angle_atom3[GETIDX(24)][0], 26); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids sort yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); num_bond = lmp->atom->num_bond; num_angle = lmp->atom->num_angle; @@ -679,41 +645,40 @@ TEST_F(ResetIDsTest, DeathTests) command("reset_mol_ids all single xxx");); } -TEST(ResetMolIds, CMDFail) +class ResetMolIDsTest : public LAMMPSTest { +protected: + void SetUp() override + { + testbinary = "ResetIDsTest"; + LAMMPSTest::SetUp(); + } +}; + +TEST_F(ResetMolIDsTest, FailBeforeBox) { - LAMMPS *lmp; - const char *args[] = {"ResetIDsTest", "-log", "none", "-nocite", "-echo", "screen"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); - TEST_FAILURE(".*ERROR: Reset_mol_ids command before simulation box is.*", - lmp->input->one("reset_mol_ids all");); + command("reset_mol_ids all");); +} - auto command = [&](const std::string &line) { - lmp->input->one(line.c_str()); - }; - - if (!verbose) ::testing::internal::CaptureStdout(); +TEST_F(ResetMolIDsTest, FailMissingId) +{ + BEGIN_HIDE_OUTPUT(); command("atom_modify id no"); command("region box block 0 1 0 1 0 1"); command("create_box 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Cannot use reset_mol_ids unless.*", command("reset_mol_ids all");); +} - if (!verbose) ::testing::internal::CaptureStdout(); +TEST_F(ResetMolIDsTest, FailOnlyMolecular) +{ + BEGIN_HIDE_OUTPUT(); command("clear"); command("region box block 0 1 0 1 0 1"); command("create_box 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Can only use reset_mol_ids.*", command("reset_mol_ids all");); - - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); -}; +} } // namespace LAMMPS_NS @@ -722,7 +687,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 45183a2e54..d41ad52e57 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -24,6 +24,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -31,12 +32,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::MathConst::MY_PI; using LAMMPS_NS::utils::split_words; @@ -45,39 +40,18 @@ using ::testing::ExitedWithCode; using ::testing::MatchesRegex; using ::testing::StrEq; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - if (verbose) std::cout << mesg; \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - if (verbose) std::cout << mesg; \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } -class VariableTest : public ::testing::Test { +class VariableTest : public LAMMPSTest { protected: - LAMMPS *lmp; Group *group; Domain *domain; Variable *variable; void SetUp() override { - const char *args[] = {"VariableTest", "-log", "none", "-echo", "screen", - "-nocite", "-v", "num", "1"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "VariableTest"; + args = {"-log", "none", "-echo", "screen", "-nocite", "-v", "num", "1"}; + LAMMPSTest::SetUp(); group = lmp->group; domain = lmp->domain; variable = lmp->input->variable; @@ -85,19 +59,14 @@ protected: void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - std::cout.flush(); + LAMMPSTest::TearDown(); unlink("test_variable.file"); unlink("test_variable.atomfile"); } - void command(const std::string &cmd) { lmp->input->one(cmd); } - void atomic_system() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("lattice sc 1.0 origin 0.125 0.125 0.125"); command("region box block -2 2 -2 2 -2 2"); @@ -109,23 +78,23 @@ protected: command("region top block INF INF -2.0 -1.0 INF INF"); command("set region left type 2"); command("set region right type 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void molecular_system() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("fix props all property/atom mol rmass q"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); atomic_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable molid atom floor(id/4)+1"); command("variable charge atom 2.0*sin(PI/32*id)"); command("set atom * mol v_molid"); command("set atom * charge v_charge"); command("set type 1 mass 0.5"); command("set type 2*4 mass 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void file_vars() @@ -152,7 +121,7 @@ TEST_F(VariableTest, CreateDelete) { file_vars(); ASSERT_EQ(variable->nvar, 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1 2 3 4"); command("variable two equal 1"); command("variable two equal 2"); @@ -173,11 +142,11 @@ TEST_F(VariableTest, CreateDelete) command("variable ten2 uloop 4"); command("variable ten3 uloop 4 pad"); command("variable dummy index 0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(variable->nvar, 17); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable dummy delete"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(variable->nvar, 16); ASSERT_THAT(variable->retrieve("three"), StrEq("three")); variable->set_string("three", "four"); @@ -235,7 +204,7 @@ TEST_F(VariableTest, AtomicSystem) atomic_system(); file_vars(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1 2 3 4"); command("variable id atom type"); command("variable id atom id"); @@ -262,7 +231,7 @@ TEST_F(VariableTest, AtomicSystem) command("variable rgsum equal sum(v_rg)"); command("variable loop equal v_loop+1"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(variable->atomstyle(variable->find("one")), 0); ASSERT_EQ(variable->atomstyle(variable->find("id")), 1); @@ -294,7 +263,7 @@ TEST_F(VariableTest, AtomicSystem) TEST_F(VariableTest, Expressions) { atomic_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1"); command("variable two equal 2"); command("variable three equal v_one+v_two"); @@ -321,7 +290,7 @@ TEST_F(VariableTest, Expressions) command("variable err2 equal v_one%v_ten7"); command("variable err3 equal v_ten7^-v_one"); variable->set("dummy index 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); int ivar = variable->find("one"); ASSERT_FALSE(variable->equalstyle(ivar)); @@ -364,7 +333,7 @@ TEST_F(VariableTest, Functions) atomic_system(); file_vars(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1"); command("variable two equal random(1,2,643532)"); command("variable three equal atan2(v_one,1)"); @@ -377,7 +346,7 @@ TEST_F(VariableTest, Functions) command("variable ten equal floor(1.85)+ceil(1.85)"); command("variable ten1 equal tan(v_eight/2.0)"); command("variable ten2 equal asin(-1.0)+acos(0.0)"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_GT(variable->compute_equal(variable->find("two")), 0.99); ASSERT_LT(variable->compute_equal(variable->find("two")), 2.01); @@ -396,74 +365,64 @@ TEST_F(VariableTest, Functions) TEST_F(VariableTest, IfCommand) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if 1>0 then 'print \"bingo!\"'"); - auto text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + auto text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if (1<=0) then 'print \"bingo!\"' else 'print \"nope?\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if (-1.0e-1<0.0E+0)|^(1<0) then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if (${one}==1.0)&&(2>=1) then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if !((${one}!=1.0)||(2|^1)) then 'print \"missed\"' else 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if (1>=2)&&(0&&1) then 'print \"missed\"' else 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if !1 then 'print \"missed\"' else 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if !(a==b) then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if x==x|^1==0 then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if x!=x|^a!=b then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", @@ -492,34 +451,34 @@ TEST_F(VariableTest, NextCommand) { file_vars(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1 2"); command("variable two equal 2"); command("variable three file test_variable.file"); command("variable four loop 2 4"); command("variable five index 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_DOUBLE_EQ(variable->compute_equal("v_one"), 1); ASSERT_THAT(variable->retrieve("three"), StrEq("one")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("next one"); command("next three"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_DOUBLE_EQ(variable->compute_equal("v_one"), 2); ASSERT_THAT(variable->retrieve("three"), StrEq("two")); ASSERT_GE(variable->find("one"), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("next one"); command("next three"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // index style variable is deleted if no more next element ASSERT_EQ(variable->find("one"), -1); ASSERT_GE(variable->find("three"), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("next three"); command("next three"); command("next three"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // file style variable is deleted if no more next element ASSERT_EQ(variable->find("three"), -1); @@ -536,7 +495,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h index c8afb2aac3..6bc26e123d 100644 --- a/unittest/formats/compressed_dump_test.h +++ b/unittest/formats/compressed_dump_test.h @@ -45,14 +45,14 @@ public: void enable_triclinic() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); if (!dump_modify_options.empty()) { @@ -60,7 +60,7 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, @@ -76,7 +76,7 @@ public: std::string text_modify_options, std::string compressed_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, text_options)); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, compressed_options)); @@ -89,17 +89,17 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } std::string convert_compressed_to_text(std::string compressed_file) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string cmdline = fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); return converted_file; } }; diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index b787076495..67ee9742e5 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -24,6 +24,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -98,38 +99,28 @@ const double EPSILON = 5.0e-14; namespace LAMMPS_NS { using ::testing::Eq; -class AtomStyleTest : public ::testing::Test { +class AtomStyleTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"SimpleCommandsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "AtomStyleTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("dimension 3"); command("pair_style zero 4.0"); command("region box block -4 4 -4 4 -4 4"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("test_atom_styles.data"); remove("input_atom_styles.data"); remove("test_atom_styles.restart"); } - - void command(const std::string cmd) { lmp->input->one(cmd); } }; // default class Atom state @@ -503,17 +494,17 @@ TEST_F(AtomStyleTest, atomic_after_charge) expected.has_v = true; expected.has_f = true; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style charge"); command("atom_style atomic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_ATOM_STATE_EQ(lmp->atom, expected); } TEST_F(AtomStyleTest, atomic) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_modify map hash"); command("create_box 2 box"); command("create_atoms 1 single -2.0 2.0 0.1"); @@ -523,7 +514,7 @@ TEST_F(AtomStyleTest, atomic) command("mass 1 4.0"); command("mass 2 2.4"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -541,7 +532,7 @@ TEST_F(AtomStyleTest, atomic) ASSERT_EQ(lmp->atom->map_style, Atom::MAP_HASH); ASSERT_EQ(lmp->atom->map_user, 2); ASSERT_EQ(lmp->atom->map_tag_max, 4); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("write_data test_atom_styles.data nocoeff"); command("clear"); @@ -550,7 +541,7 @@ TEST_F(AtomStyleTest, atomic) command("atom_modify map array"); command("units real"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -598,14 +589,14 @@ TEST_F(AtomStyleTest, atomic) ASSERT_EQ(lmp->atom->map_tag_max, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); command("clear"); command("read_restart test_atom_styles.restart"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 2); @@ -639,16 +630,16 @@ TEST_F(AtomStyleTest, atomic) ASSERT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); ASSERT_EQ(lmp->atom->map_user, 1); ASSERT_EQ(lmp->atom->map_tag_max, 3); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 2); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("comm_style tiled"); command("change_box all triclinic"); command("replicate 2 2 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 16); x = lmp->atom->x; tag = lmp->atom->tag; @@ -704,9 +695,9 @@ TEST_F(AtomStyleTest, atomic) TEST_F(AtomStyleTest, charge) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style charge"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "charge"; @@ -721,7 +712,7 @@ TEST_F(AtomStyleTest, charge) expected.q_flag = 1; ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 2 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -734,7 +725,7 @@ TEST_F(AtomStyleTest, charge) command("set atom 3 charge -1.0"); command("set atom 4 charge 1.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("charge")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -747,7 +738,7 @@ TEST_F(AtomStyleTest, charge) ASSERT_NE(lmp->atom->mass, nullptr); ASSERT_NE(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("write_data test_atom_styles.data nocoeff"); command("clear"); @@ -756,7 +747,7 @@ TEST_F(AtomStyleTest, charge) command("units real"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("charge")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -810,7 +801,7 @@ TEST_F(AtomStyleTest, charge) ASSERT_EQ(lmp->atom->mass_setflag[1], 1); ASSERT_EQ(lmp->atom->mass_setflag[2], 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -818,7 +809,7 @@ TEST_F(AtomStyleTest, charge) command("clear"); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); command("read_restart test_atom_styles.restart"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("charge")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 2); @@ -854,11 +845,11 @@ TEST_F(AtomStyleTest, charge) ASSERT_EQ(lmp->atom->mass_setflag[1], 1); ASSERT_EQ(lmp->atom->mass_setflag[2], 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); command("change_box all triclinic"); command("replicate 2 2 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 16); q = lmp->atom->q; EXPECT_NEAR(q[GETIDX(1)], -0.5, EPSILON); @@ -881,9 +872,9 @@ TEST_F(AtomStyleTest, charge) TEST_F(AtomStyleTest, sphere) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style sphere"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "sphere"; @@ -903,7 +894,7 @@ TEST_F(AtomStyleTest, sphere) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 2 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -918,7 +909,7 @@ TEST_F(AtomStyleTest, sphere) command("set atom 3 omega -1.0 0.0 0.0"); command("set atom 4 omega 0.0 1.0 0.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("sphere")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -932,7 +923,7 @@ TEST_F(AtomStyleTest, sphere) ASSERT_EQ(lmp->atom->mass, nullptr); ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("write_data test_atom_styles.data nocoeff"); command("clear"); @@ -941,7 +932,7 @@ TEST_F(AtomStyleTest, sphere) command("units real"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("sphere")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -1005,7 +996,7 @@ TEST_F(AtomStyleTest, sphere) EXPECT_NEAR(omega[GETIDX(4)][1], 1.0, EPSILON); EXPECT_NEAR(omega[GETIDX(4)][2], 0.0, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -1015,7 +1006,7 @@ TEST_F(AtomStyleTest, sphere) command("read_restart test_atom_styles.restart"); command("replicate 1 1 2"); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("sphere")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -1052,9 +1043,9 @@ TEST_F(AtomStyleTest, ellipsoid) { if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style ellipsoid"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "ellipsoid"; @@ -1073,7 +1064,7 @@ TEST_F(AtomStyleTest, ellipsoid) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -1091,7 +1082,7 @@ TEST_F(AtomStyleTest, ellipsoid) command("set atom 3 quat 1.0 0.0 1.0 30.0"); command("set atom 4 quat 1.0 1.0 1.0 60.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("ellipsoid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1119,7 +1110,7 @@ TEST_F(AtomStyleTest, ellipsoid) ASSERT_NE(lmp->atom->ellipsoid, nullptr); ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("atom_style ellipsoid"); @@ -1128,7 +1119,7 @@ TEST_F(AtomStyleTest, ellipsoid) command("atom_modify map array"); command("read_data test_atom_styles.data"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("ellipsoid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1238,7 +1229,7 @@ TEST_F(AtomStyleTest, ellipsoid) EXPECT_NEAR(bonus[3].quat[2], sqrt(5.0 / 30.0), EPSILON); EXPECT_NEAR(bonus[3].quat[3], sqrt(5.0 / 30.0), EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 2:4:2"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -1246,7 +1237,7 @@ TEST_F(AtomStyleTest, ellipsoid) command("read_restart test_atom_styles.restart"); command("comm_style tiled"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("ellipsoid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -1319,9 +1310,9 @@ TEST_F(AtomStyleTest, ellipsoid) EXPECT_NEAR(bonus[3].quat[2], 0.0, EPSILON); EXPECT_NEAR(bonus[3].quat[3], 0.25056280708573159, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->nellipsoids, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -1389,10 +1380,10 @@ TEST_F(AtomStyleTest, line) { if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); command("atom_style line"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "line"; @@ -1414,7 +1405,7 @@ TEST_F(AtomStyleTest, line) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box"); command("create_atoms 1 single -2.0 2.0 0.0"); command("create_atoms 1 single -2.0 -2.0 0.0"); @@ -1432,7 +1423,7 @@ TEST_F(AtomStyleTest, line) command("set atom 3 theta 30.0"); command("set atom 4 theta 60.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("line")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1448,7 +1439,7 @@ TEST_F(AtomStyleTest, line) ASSERT_NE(lmp->atom->rmass, nullptr); ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("dimension 2"); @@ -1457,7 +1448,7 @@ TEST_F(AtomStyleTest, line) command("units real"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("line")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1547,7 +1538,7 @@ TEST_F(AtomStyleTest, line) EXPECT_NEAR(bonus[3].length, 3.0, EPSILON); EXPECT_NEAR(bonus[3].theta, MathConst::MY_PI / 3.0, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -1557,7 +1548,7 @@ TEST_F(AtomStyleTest, line) command("comm_style tiled"); command("change_box all triclinic"); command("replicate 1 2 1 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("line")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -1610,9 +1601,9 @@ TEST_F(AtomStyleTest, line) EXPECT_NEAR(bonus[3].length, 3.0, EPSILON); EXPECT_NEAR(bonus[3].theta, MathConst::MY_PI / 6.0, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->nlines, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -1660,9 +1651,9 @@ TEST_F(AtomStyleTest, tri) { if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style tri"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "tri"; @@ -1685,7 +1676,7 @@ TEST_F(AtomStyleTest, tri) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -1703,7 +1694,7 @@ TEST_F(AtomStyleTest, tri) command("set atom 3 quat 1.0 0.0 1.0 30.0"); command("set atom 4 quat 1.0 1.0 1.0 60.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("tri")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1731,7 +1722,7 @@ TEST_F(AtomStyleTest, tri) ASSERT_NE(lmp->atom->tri, nullptr); ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("atom_style tri"); @@ -1740,7 +1731,7 @@ TEST_F(AtomStyleTest, tri) command("atom_modify map array"); command("read_data test_atom_styles.data"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("tri")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1893,7 +1884,7 @@ TEST_F(AtomStyleTest, tri) EXPECT_NEAR(bonus[3].c3[1], 0.64304946932374796, EPSILON); EXPECT_NEAR(bonus[3].c3[2], -0.32808266428854477, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 2:4:2"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -1901,7 +1892,7 @@ TEST_F(AtomStyleTest, tri) command("read_restart test_atom_styles.restart"); command("change_box all triclinic"); command("replicate 1 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("tri")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -2019,9 +2010,9 @@ TEST_F(AtomStyleTest, tri) EXPECT_NEAR(bonus[3].c3[1], 0.85047049833171351, EPSILON); EXPECT_NEAR(bonus[3].c3[2], -0.15731490073748589, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->ntris, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -2064,9 +2055,9 @@ TEST_F(AtomStyleTest, body_nparticle) { if (!LAMMPS::is_installed_pkg("BODY")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style body nparticle 2 4"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "body"; @@ -2129,7 +2120,7 @@ TEST_F(AtomStyleTest, body_nparticle) FILE *fp = fopen("input_atom_styles.data", "w"); fputs(data_file, fp); fclose(fp); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_modify map array"); command("read_data input_atom_styles.data"); command("create_atoms 3 single 2.0 2.0 -2.1"); @@ -2140,7 +2131,7 @@ TEST_F(AtomStyleTest, body_nparticle) command("set atom 3 quat 1.0 0.0 1.0 30.0"); command("set atom 4 quat 1.0 1.0 1.0 60.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("body")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -2306,7 +2297,7 @@ TEST_F(AtomStyleTest, body_nparticle) ASSERT_NE(bonus[2].dvalue, nullptr); ASSERT_NE(bonus[3].dvalue, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("atom_style body nparticle 2 4"); @@ -2315,7 +2306,7 @@ TEST_F(AtomStyleTest, body_nparticle) command("atom_modify map array"); command("read_data test_atom_styles.data"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("body")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -2479,7 +2470,7 @@ TEST_F(AtomStyleTest, body_nparticle) ASSERT_NE(bonus[2].dvalue, nullptr); ASSERT_NE(bonus[3].dvalue, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 2:4:2"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -2487,7 +2478,7 @@ TEST_F(AtomStyleTest, body_nparticle) command("read_restart test_atom_styles.restart"); command("comm_style tiled"); command("replicate 1 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("body")); avec = (AtomVecBody *)lmp->atom->avec; ASSERT_THAT(std::string(avec->bptr->style), Eq("nparticle")); @@ -2594,9 +2585,9 @@ TEST_F(AtomStyleTest, body_nparticle) ASSERT_NE(bonus[2].dvalue, nullptr); ASSERT_NE(bonus[3].dvalue, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->nbodies, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -2632,11 +2623,11 @@ TEST_F(AtomStyleTest, template) { if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); create_molecule_files(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("atom_style template twomols"); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "template"; @@ -2658,7 +2649,7 @@ TEST_F(AtomStyleTest, template) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 4 box bond/types 2 angle/types 2 "); command("create_atoms 0 single -2.0 2.0 0.1 mol twomols 65234"); command("create_atoms 0 single -2.0 -2.0 -0.1 mol twomols 62346"); @@ -2676,7 +2667,7 @@ TEST_F(AtomStyleTest, template) command("angle_style zero"); command("angle_coeff * 109.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 12); @@ -2706,7 +2697,7 @@ TEST_F(AtomStyleTest, template) ASSERT_NE(lmp->atom->mass, nullptr); ASSERT_NE(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data"); command("clear"); command("units real"); @@ -2718,7 +2709,7 @@ TEST_F(AtomStyleTest, template) command("angle_style zero"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -2780,7 +2771,7 @@ TEST_F(AtomStyleTest, template) ASSERT_EQ(molatom[GETIDX(11)], -1); ASSERT_EQ(molatom[GETIDX(12)], -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); @@ -2790,7 +2781,7 @@ TEST_F(AtomStyleTest, template) command("angle_style zero"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -2902,7 +2893,7 @@ TEST_F(AtomStyleTest, template) ASSERT_EQ(type[GETIDX(11)], 3); ASSERT_EQ(type[GETIDX(12)], 4); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 7:10"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -2910,7 +2901,7 @@ TEST_F(AtomStyleTest, template) command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 16); @@ -2980,9 +2971,9 @@ TEST_F(AtomStyleTest, template) ASSERT_EQ(molatom[GETIDX(23)], -1); ASSERT_EQ(molatom[GETIDX(24)], -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 16); @@ -3028,11 +3019,11 @@ TEST_F(AtomStyleTest, template_charge) { if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); create_molecule_files(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("atom_style hybrid template twomols charge"); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "hybrid"; @@ -3063,7 +3054,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_NE(hybrid->styles[0], nullptr); ASSERT_NE(hybrid->styles[1], nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 4 box bond/types 2 angle/types 2 "); command("create_atoms 0 single -2.0 2.0 0.1 mol twomols 65234"); command("create_atoms 0 single -2.0 -2.0 -0.1 mol twomols 62346"); @@ -3084,7 +3075,7 @@ TEST_F(AtomStyleTest, template_charge) command("angle_style zero"); command("angle_coeff * 109.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_NE(lmp->atom->avec, nullptr); hybrid = (AtomVecHybrid *)lmp->atom->avec; ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); @@ -3122,7 +3113,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_NE(lmp->atom->mass, nullptr); ASSERT_NE(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data"); command("clear"); command("units real"); @@ -3134,7 +3125,7 @@ TEST_F(AtomStyleTest, template_charge) command("angle_style zero"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3196,7 +3187,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_EQ(molatom[GETIDX(11)], -1); ASSERT_EQ(molatom[GETIDX(12)], -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); @@ -3206,7 +3197,7 @@ TEST_F(AtomStyleTest, template_charge) command("angle_style zero"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3331,7 +3322,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_EQ(type[GETIDX(11)], 3); ASSERT_EQ(type[GETIDX(12)], 4); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 7:10"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -3339,7 +3330,7 @@ TEST_F(AtomStyleTest, template_charge) command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 16); @@ -3409,9 +3400,9 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_EQ(molatom[GETIDX(23)], -1); ASSERT_EQ(molatom[GETIDX(24)], -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 16); @@ -3457,10 +3448,10 @@ TEST_F(AtomStyleTest, bond) { if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style bond"); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "bond"; @@ -3480,7 +3471,7 @@ TEST_F(AtomStyleTest, bond) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box bond/types 2 " "extra/bond/per/atom 2 extra/special/per/atom 4"); command("create_atoms 1 single -2.0 2.0 0.1"); @@ -3500,7 +3491,7 @@ TEST_F(AtomStyleTest, bond) command("create_bonds single/bond 2 3 5"); command("create_bonds single/bond 2 3 6"); command("create_bonds single/bond 2 5 6"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -3533,7 +3524,7 @@ TEST_F(AtomStyleTest, bond) lmp->atom->bond_type[GETIDX(1)][0] *= -1; lmp->atom->bond_type[GETIDX(5)][0] *= -1; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("units real"); @@ -3545,7 +3536,7 @@ TEST_F(AtomStyleTest, bond) command("read_data test_atom_styles.data"); command("pair_coeff * *"); command("bond_coeff * 4.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3594,7 +3585,7 @@ TEST_F(AtomStyleTest, bond) ASSERT_EQ(bond_atom[GETIDX(6)][0], 3); ASSERT_EQ(bond_atom[GETIDX(6)][1], 5); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("atom_style bond"); @@ -3604,7 +3595,7 @@ TEST_F(AtomStyleTest, bond) command("read_data test_atom_styles.data"); command("pair_coeff * *"); command("bond_coeff * 4.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3692,7 +3683,7 @@ TEST_F(AtomStyleTest, bond) lmp->atom->bond_type[GETIDX(1)][0] *= -1; lmp->atom->bond_type[GETIDX(5)][0] *= -1; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -3700,7 +3691,7 @@ TEST_F(AtomStyleTest, bond) command("clear"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -3754,10 +3745,10 @@ TEST_F(AtomStyleTest, bond) ASSERT_EQ(bond_type[GETIDX(9)][1], 2); ASSERT_EQ(bond_type[GETIDX(11)][0], 2); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("delete_bonds all bond 2"); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -3805,10 +3796,10 @@ TEST_F(AtomStyleTest, angle) { if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style angle"); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "angle"; @@ -3829,7 +3820,7 @@ TEST_F(AtomStyleTest, angle) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box bond/types 2 angle/types 2 " "extra/bond/per/atom 2 extra/angle/per/atom 1 " "extra/special/per/atom 4"); @@ -3854,7 +3845,7 @@ TEST_F(AtomStyleTest, angle) command("create_bonds single/bond 2 5 6"); command("create_bonds single/angle 1 1 3 5"); command("create_bonds single/angle 2 3 5 6"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -3889,7 +3880,7 @@ TEST_F(AtomStyleTest, angle) lmp->atom->angle_type[GETIDX(3)][0] *= -1; lmp->atom->angle_type[GETIDX(5)][0] *= -1; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("units real"); @@ -3903,7 +3894,7 @@ TEST_F(AtomStyleTest, angle) command("pair_coeff * *"); command("bond_coeff * 4.0"); command("angle_coeff * 90.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3987,7 +3978,7 @@ TEST_F(AtomStyleTest, angle) ASSERT_EQ(angle_atom2[GETIDX(6)][0], 5); ASSERT_EQ(angle_atom3[GETIDX(6)][0], 6); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("atom_style angle"); @@ -3997,7 +3988,7 @@ TEST_F(AtomStyleTest, angle) command("read_data test_atom_styles.data"); command("pair_coeff * *"); command("bond_coeff * 4.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -4086,7 +4077,7 @@ TEST_F(AtomStyleTest, angle) ASSERT_EQ(angle_type[GETIDX(3)][0], 1); ASSERT_EQ(angle_type[GETIDX(5)][0], 2); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -4094,7 +4085,7 @@ TEST_F(AtomStyleTest, angle) command("clear"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -4131,10 +4122,10 @@ TEST_F(AtomStyleTest, angle) ASSERT_EQ(angle_type[GETIDX(9)][0], 1); ASSERT_EQ(angle_type[GETIDX(11)][0], 2); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("delete_bonds all angle 2"); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -4166,9 +4157,9 @@ TEST_F(AtomStyleTest, full_ellipsoid) if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style hybrid full ellipsoid"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "hybrid"; @@ -4204,7 +4195,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) ASSERT_NE(hybrid->styles[0], nullptr); ASSERT_NE(hybrid->styles[1], nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box bond/types 2 " "extra/bond/per/atom 2 extra/special/per/atom 4"); command("create_atoms 1 single -2.0 2.0 0.1"); @@ -4239,7 +4230,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) command("create_bonds single/bond 2 3 5"); command("create_bonds single/bond 2 3 6"); command("create_bonds single/bond 2 5 6"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -4269,7 +4260,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) ASSERT_NE(lmp->atom->ellipsoid, nullptr); ASSERT_NE(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("units real"); @@ -4280,7 +4271,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) command("read_data test_atom_styles.data"); command("pair_coeff * *"); command("bond_coeff * 4.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); hybrid = (AtomVecHybrid *)lmp->atom->avec; @@ -4405,7 +4396,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) EXPECT_NEAR(bonus[3].quat[2], sqrt(5.0 / 30.0), EPSILON); EXPECT_NEAR(bonus[3].quat[3], sqrt(5.0 / 30.0), EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -4413,7 +4404,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) command("clear"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); hybrid = (AtomVecHybrid *)lmp->atom->avec; ASSERT_EQ(hybrid->nstyles, 2); @@ -4492,9 +4483,9 @@ TEST_F(AtomStyleTest, full_ellipsoid) EXPECT_NEAR(bonus[3].quat[2], 0.0, EPSILON); EXPECT_NEAR(bonus[3].quat[3], 0.25056280708573159, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->nellipsoids, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -4561,10 +4552,10 @@ TEST_F(AtomStyleTest, full_ellipsoid) TEST_F(AtomStyleTest, property_atom) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_modify map array"); command("fix Properties all property/atom i_one d_two mol d_three q rmass ghost yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "atomic"; @@ -4596,7 +4587,7 @@ TEST_F(AtomStyleTest, property_atom) expected.nextra_border_max = 1; ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 2 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -4623,7 +4614,7 @@ TEST_F(AtomStyleTest, property_atom) command("set atom 3 d_three 0.5"); command("set atom 4 d_three 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); expected.natoms = 4; expected.nlocal = 4; expected.map_tag_max = 4; @@ -4637,7 +4628,7 @@ TEST_F(AtomStyleTest, property_atom) ASSERT_NE(lmp->atom->nmax, -1); ASSERT_NE(lmp->atom->rmass, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("write_data test_atom_styles.data nocoeff"); command("clear"); @@ -4648,7 +4639,7 @@ TEST_F(AtomStyleTest, property_atom) command("fix props all property/atom i_one d_two mol d_three q rmass ghost yes"); command("read_data test_atom_styles.data fix props NULL Properties"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -4726,7 +4717,7 @@ TEST_F(AtomStyleTest, property_atom) EXPECT_NEAR(three[GETIDX(3)], 0.5, EPSILON); EXPECT_NEAR(three[GETIDX(4)], 2.0, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -4735,7 +4726,7 @@ TEST_F(AtomStyleTest, property_atom) ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); command("read_restart test_atom_styles.restart"); command("fix props all property/atom i_one d_two mol d_three q rmass ghost yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); expected.natoms = 2; expected.nlocal = 2; expected.nghost = 0; @@ -4773,10 +4764,10 @@ TEST_F(AtomStyleTest, property_atom) EXPECT_NEAR(three[GETIDX(1)], -2.5, EPSILON); EXPECT_NEAR(three[GETIDX(3)], 0.5, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 2); q = lmp->atom->q; EXPECT_NEAR(q[GETIDX(1)], -0.5, EPSILON); diff --git a/unittest/formats/test_dump_atom.cpp b/unittest/formats/test_dump_atom.cpp index 39cefdccea..46c6b7dfa7 100644 --- a/unittest/formats/test_dump_atom.cpp +++ b/unittest/formats/test_dump_atom.cpp @@ -32,14 +32,14 @@ class DumpAtomTest : public MeltTest { public: void enable_triclinic() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); if (!dump_modify_options.empty()) { @@ -47,13 +47,13 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_text_and_binary_dump(std::string text_file, std::string binary_file, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id1 all {} 1 {}", dump_style, binary_file)); @@ -63,15 +63,15 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } std::string convert_binary_to_text(std::string binary_file) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file); system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); return fmt::format("{}.txt", binary_file); } }; @@ -504,27 +504,27 @@ TEST_F(DumpAtomTest, per_processor_multi_file_run1) TEST_F(DumpAtomTest, dump_modify_scale_invalid) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dump id all atom 1 dump.txt"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id scale true");); } TEST_F(DumpAtomTest, dump_modify_image_invalid) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dump id all atom 1 dump.txt"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id image true");); } TEST_F(DumpAtomTest, dump_modify_invalid) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dump id all atom 1 dump.txt"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id true");); } @@ -534,12 +534,12 @@ TEST_F(DumpAtomTest, write_dump) auto reference = "dump_ref_run0.melt"; auto dump_file = "write_dump_atom_run0.melt"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all atom 1 {}", reference)); command("dump_modify id scale no units yes"); command("run 0"); command("write_dump all atom write_dump_atom_run*.melt modify scale no units yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_FILE_EXISTS(reference); ASSERT_FILE_EXISTS(dump_file); @@ -556,12 +556,12 @@ TEST_F(DumpAtomTest, binary_write_dump) auto reference = "dump_run0.melt.bin"; auto dump_file = "write_dump_atom_run0_p0.melt.bin"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all atom 1 {}", reference)); command("dump_modify id scale no units yes"); command("run 0"); command("write_dump all atom write_dump_atom_run*_p%.melt.bin modify scale no units yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_FILE_EXISTS(reference); ASSERT_FILE_EXISTS(dump_file); diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index ed591184c3..5a519e06a1 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -340,9 +340,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_bad_param) { if (compression_style != "atom/gz") GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt"))); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -353,9 +353,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_multi_bad_param) { if (compression_style != "atom/gz") GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt"))); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_cfg.cpp b/unittest/formats/test_dump_cfg.cpp index 327a9caca7..b8f879de6f 100644 --- a/unittest/formats/test_dump_cfg.cpp +++ b/unittest/formats/test_dump_cfg.cpp @@ -30,7 +30,7 @@ public: void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); if (!dump_modify_options.empty()) { @@ -38,7 +38,7 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } }; @@ -54,9 +54,9 @@ TEST_F(DumpCfgTest, require_multifile) auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all cfg 1 {} {}", dump_file, fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*Dump cfg requires one snapshot per file.*", command("run 0");); } diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp index 834a71db70..20f902091b 100644 --- a/unittest/formats/test_dump_cfg_compressed.cpp +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -230,9 +230,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_bad_param) if (compression_style != "cfg/gz") GTEST_SKIP(); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.cfg"), fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -244,9 +244,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_multi_bad_param) if (compression_style != "cfg/gz") GTEST_SKIP(); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.cfg"), fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_custom.cpp b/unittest/formats/test_dump_custom.cpp index f2d7935426..b90d77e966 100644 --- a/unittest/formats/test_dump_custom.cpp +++ b/unittest/formats/test_dump_custom.cpp @@ -30,15 +30,15 @@ class DumpCustomTest : public MeltTest { public: void enable_triclinic() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); if (!dump_modify_options.empty()) { @@ -46,14 +46,14 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_text_and_binary_dump(std::string text_file, std::string binary_file, std::string fields, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", dump_style, binary_file, fields)); @@ -63,15 +63,15 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } std::string convert_binary_to_text(std::string binary_file) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file); system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); return fmt::format("{}.txt", binary_file); } }; @@ -113,9 +113,9 @@ TEST_F(DumpCustomTest, thresh_run0) TEST_F(DumpCustomTest, compute_run0) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("compute comp all property/atom x y z"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto dump_file = "dump_custom_compute_run0.melt"; auto fields = "id type x y z c_comp[1] c_comp[2] c_comp[3]"; @@ -134,9 +134,9 @@ TEST_F(DumpCustomTest, compute_run0) TEST_F(DumpCustomTest, fix_run0) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("fix numdiff all numdiff 1 0.0001"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto dump_file = "dump_custom_compute_run0.melt"; auto fields = "id x y z f_numdiff[1] f_numdiff[2] f_numdiff[3]"; @@ -155,10 +155,10 @@ TEST_F(DumpCustomTest, fix_run0) TEST_F(DumpCustomTest, custom_run0) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("fix prop all property/atom i_flag1 d_flag2"); command("compute 1 all property/atom i_flag1 d_flag2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto dump_file = "dump_custom_custom_run0.melt"; auto fields = "id x y z i_flag1 d_flag2"; @@ -242,10 +242,10 @@ TEST_F(DumpCustomTest, binary_triclinic_run1) TEST_F(DumpCustomTest, with_variable_run1) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("compute 1 all property/atom proc"); command("variable p atom (c_1%10)+1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto dump_file = "dump_custom_with_variable_run1.melt"; auto fields = "id type x y z v_p"; diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp index 20f90984a1..95656071fc 100644 --- a/unittest/formats/test_dump_local_compressed.cpp +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -31,9 +31,9 @@ public: void SetUp() override { CompressedDumpTest::SetUp(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } }; @@ -205,9 +205,9 @@ TEST_F(DumpLocalCompressTest, compressed_modify_bad_param) auto fields = "index c_comp[1]"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.local"), fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -220,9 +220,9 @@ TEST_F(DumpLocalCompressTest, compressed_modify_multi_bad_param) auto fields = "index c_comp[1]"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.local"), fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp index f80201872c..dad7911b4c 100644 --- a/unittest/formats/test_dump_xyz_compressed.cpp +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -191,9 +191,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_bad_param) { if (compression_style != "xyz/gz") GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.xyz"))); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -204,9 +204,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_multi_bad_param) { if (compression_style != "xyz/gz") GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.xyz"))); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_eim_potential_file_reader.cpp b/unittest/formats/test_eim_potential_file_reader.cpp index 9992fb8662..26f2795a85 100644 --- a/unittest/formats/test_eim_potential_file_reader.cpp +++ b/unittest/formats/test_eim_potential_file_reader.cpp @@ -18,6 +18,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -28,28 +29,23 @@ using utils::split_words; // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -class EIMPotentialFileReaderTest : public ::testing::Test { +class EIMPotentialFileReaderTest : public LAMMPSTest { protected: - LAMMPS *lmp; PairEIM::Setfl setfl; static const int nelements = 9; void SetUp() override { - const char *args[] = { - "PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - lmp->input->one("units metal"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "EIMPotentialFileReaderTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); + + BEGIN_HIDE_OUTPUT(); + command("units metal"); + END_HIDE_OUTPUT(); // check if the prerequisite eim pair style is available - Info *info = new Info(lmp); ASSERT_TRUE(info->has_style("pair", "eim")); - delete info; int npair = nelements * (nelements + 1) / 2; setfl.ielement = new int[nelements]; @@ -99,17 +95,15 @@ protected: delete[] setfl.rs; delete[] setfl.tp; - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); } }; TEST_F(EIMPotentialFileReaderTest, global_line) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_global(&setfl); ASSERT_DOUBLE_EQ(setfl.division, 2.0); @@ -119,9 +113,9 @@ TEST_F(EIMPotentialFileReaderTest, global_line) TEST_F(EIMPotentialFileReaderTest, element_line_sequential) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_element(&setfl, 0, "Li"); ASSERT_EQ(setfl.ielement[0], 3); @@ -144,9 +138,9 @@ TEST_F(EIMPotentialFileReaderTest, element_line_sequential) TEST_F(EIMPotentialFileReaderTest, element_line_random) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_element(&setfl, 0, "Id"); ASSERT_EQ(setfl.ielement[0], 53); @@ -160,9 +154,9 @@ TEST_F(EIMPotentialFileReaderTest, element_line_random) TEST_F(EIMPotentialFileReaderTest, pair_line) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_pair(&setfl, 0, "Li", "Li"); ASSERT_DOUBLE_EQ(setfl.rcutphiA[0], 6.0490e+00); @@ -183,9 +177,9 @@ TEST_F(EIMPotentialFileReaderTest, pair_line) TEST_F(EIMPotentialFileReaderTest, pair_identical) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_pair(&setfl, 0, "Li", "Na"); reader.get_pair(&setfl, 1, "Na", "Li"); diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index cf85d810df..80082bc53c 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -17,6 +17,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -31,43 +32,17 @@ using utils::sfgets; using utils::sfread; using utils::split_words; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } - // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -class FileOperationsTest : public ::testing::Test { +class FileOperationsTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"FileOperationsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "FileOperationsTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); + FILE *fp = fopen("safe_file_read_test.txt", "wb"); ASSERT_NE(fp, nullptr); fputs("one line\n", fp); @@ -79,13 +54,9 @@ protected: void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("safe_file_read_test.txt"); } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; #define MAX_BUF_SIZE 128 @@ -179,7 +150,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/formats/test_image_flags.cpp b/unittest/formats/test_image_flags.cpp index 6b3a333328..63d85789e6 100644 --- a/unittest/formats/test_image_flags.cpp +++ b/unittest/formats/test_image_flags.cpp @@ -15,6 +15,7 @@ #include "input.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -28,20 +29,14 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::Eq; -class ImageFlagsTest : public ::testing::Test { +class ImageFlagsTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"ImageFlagsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "ImageFlagsTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("dimension 3"); command("region box block -2 2 -2 2 -2 2"); @@ -54,18 +49,14 @@ protected: command("set atom 1 image -1 2 3"); command("set atom 2 image -2 1 -1"); command("write_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("test_image_flags.data"); } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(ImageFlagsTest, change_box) @@ -87,9 +78,9 @@ TEST_F(ImageFlagsTest, change_box) ASSERT_EQ(imy, 1); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all boundary f p p"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -108,9 +99,9 @@ TEST_F(ImageFlagsTest, change_box) ASSERT_EQ(imy, 1); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all boundary f s p"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -129,9 +120,9 @@ TEST_F(ImageFlagsTest, change_box) ASSERT_EQ(imy, 0); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all boundary p p m"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -153,14 +144,14 @@ TEST_F(ImageFlagsTest, change_box) TEST_F(ImageFlagsTest, read_data) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("dimension 3"); command("boundary p p p"); command("pair_style zero 2.0"); command("read_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto image = lmp->atom->image; int imx = (image[0] & IMGMASK) - IMGMAX; @@ -179,14 +170,14 @@ TEST_F(ImageFlagsTest, read_data) ASSERT_EQ(imy, 1); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("dimension 3"); command("boundary f p p"); command("pair_style zero 2.0"); command("read_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -205,14 +196,14 @@ TEST_F(ImageFlagsTest, read_data) ASSERT_EQ(imy, 1); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("dimension 3"); command("boundary p s p"); command("pair_style zero 2.0"); command("read_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -231,14 +222,14 @@ TEST_F(ImageFlagsTest, read_data) ASSERT_EQ(imy, 0); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("dimension 3"); command("boundary p p m"); command("pair_style zero 2.0"); command("read_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index 204a1bd061..4bcf375dff 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -19,6 +19,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -33,26 +34,6 @@ using utils::split_words; #define test_name test_info_->name() -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } static void create_molecule_files() { @@ -96,27 +77,21 @@ static void create_molecule_files() // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -class MoleculeFileTest : public ::testing::Test { +class MoleculeFileTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"MoleculeFileTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - create_molecule_files(); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "MoleculeFileTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); + BEGIN_HIDE_OUTPUT(); + create_molecule_files(); + END_HIDE_OUTPUT(); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("h2o.mol"); remove("co2.mol"); } @@ -128,11 +103,9 @@ protected: fputs(content.c_str(), fp); fclose(fp); - lmp->input->one(fmt::format("molecule {} {} {}", name, file, args)); + command(fmt::format("molecule {} {} {}", name, file, args)); remove(file.c_str()); } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(MoleculeFileTest, nofile) @@ -292,7 +265,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/formats/test_pair_unit_convert.cpp b/unittest/formats/test_pair_unit_convert.cpp index f0c2f0d031..bdd66f67a6 100644 --- a/unittest/formats/test_pair_unit_convert.cpp +++ b/unittest/formats/test_pair_unit_convert.cpp @@ -20,6 +20,7 @@ #include "thermo.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -42,23 +43,17 @@ const double p_convert = 1.01325; // of data in update.cpp. could be 1.0e-12 const double rel_error = 5.0e-7; -class PairUnitConvertTest : public ::testing::Test { +class PairUnitConvertTest : public LAMMPSTest { protected: - LAMMPS *lmp; - Info *info; double fold[4][3]; void SetUp() override { - const char *args[] = {"PairUnitConvertTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "PairUnitConvertTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); - info = new Info(lmp); + + BEGIN_HIDE_OUTPUT(); command("units metal"); command("dimension 3"); command("region box block -4 4 -4 4 -4 4"); @@ -72,19 +67,14 @@ protected: command("mass * 1.0"); command("write_data test_pair_unit_convert.data nocoeff"); command("clear"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete info; - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("test_pair_unit_convert.data"); } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(PairUnitConvertTest, zero) @@ -92,13 +82,13 @@ TEST_F(PairUnitConvertTest, zero) // check if the prerequisite pair style is available if (!info->has_style("pair", "zero")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style zero 6.0"); command("pair_coeff * *"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -109,14 +99,14 @@ TEST_F(PairUnitConvertTest, zero) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style zero 6.0"); command("pair_coeff * *"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -135,7 +125,7 @@ TEST_F(PairUnitConvertTest, lj_cut) // check if the prerequisite pair style is available if (!info->has_style("pair", "lj/cut")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style lj/cut 6.0"); @@ -145,7 +135,7 @@ TEST_F(PairUnitConvertTest, lj_cut) command("pair_write 1 2 1000 r 0.1 6.0 test.table.metal lj_1_2"); command("pair_write 2 2 1000 r 0.1 6.0 test.table.metal lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -156,7 +146,7 @@ TEST_F(PairUnitConvertTest, lj_cut) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); @@ -167,7 +157,7 @@ TEST_F(PairUnitConvertTest, lj_cut) command("pair_write 1 2 1000 r 0.1 6.0 test.table.real lj_1_2"); command("pair_write 2 2 1000 r 0.1 6.0 test.table.real lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -186,13 +176,13 @@ TEST_F(PairUnitConvertTest, eam) // check if the prerequisite pair style is available if (!info->has_style("pair", "eam")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eam"); command("pair_coeff * * Cu_u3.eam"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -203,14 +193,14 @@ TEST_F(PairUnitConvertTest, eam) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eam"); command("pair_coeff * * Cu_u3.eam"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -229,13 +219,13 @@ TEST_F(PairUnitConvertTest, eam_alloy) // check if the prerequisite pair style is available if (!info->has_style("pair", "eam/alloy")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/alloy"); command("pair_coeff * * AlCu.eam.alloy Al Cu"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -246,14 +236,14 @@ TEST_F(PairUnitConvertTest, eam_alloy) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/alloy"); command("pair_coeff * * AlCu.eam.alloy Al Cu"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -272,13 +262,13 @@ TEST_F(PairUnitConvertTest, eam_fs) // check if the prerequisite pair style is available if (!info->has_style("pair", "eam/fs")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/fs"); command("pair_coeff * * FeP_mm.eam.fs Fe P"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -289,14 +279,14 @@ TEST_F(PairUnitConvertTest, eam_fs) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/fs"); command("pair_coeff * * FeP_mm.eam.fs Fe P"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -315,13 +305,13 @@ TEST_F(PairUnitConvertTest, eam_cd) // check if the prerequisite pair style is available if (!info->has_style("pair", "eam/cd")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/cd"); command("pair_coeff * * FeCr.cdeam Cr Fe"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -332,14 +322,14 @@ TEST_F(PairUnitConvertTest, eam_cd) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/cd"); command("pair_coeff * * FeCr.cdeam Cr Fe"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -358,13 +348,13 @@ TEST_F(PairUnitConvertTest, eim) // check if the prerequisite pair style is available if (!info->has_style("pair", "eim")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eim"); command("pair_coeff * * Na Cl ffield.eim Na Cl"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -375,14 +365,14 @@ TEST_F(PairUnitConvertTest, eim) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eim"); command("pair_coeff * * Na Cl ffield.eim Na Cl"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -401,13 +391,13 @@ TEST_F(PairUnitConvertTest, gw) // check if the prerequisite pair style is available if (!info->has_style("pair", "gw")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style gw"); command("pair_coeff * * SiC.gw Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -418,14 +408,14 @@ TEST_F(PairUnitConvertTest, gw) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style gw"); command("pair_coeff * * SiC.gw Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -444,13 +434,13 @@ TEST_F(PairUnitConvertTest, gw_zbl) // check if the prerequisite pair style is available if (!info->has_style("pair", "gw/zbl")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style gw/zbl"); command("pair_coeff * * SiC.gw.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -461,14 +451,14 @@ TEST_F(PairUnitConvertTest, gw_zbl) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style gw/zbl"); command("pair_coeff * * SiC.gw.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -487,13 +477,13 @@ TEST_F(PairUnitConvertTest, nb3b_harmonic) // check if the prerequisite pair style is available if (!info->has_style("pair", "nb3b/harmonic")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style nb3b/harmonic"); command("pair_coeff * * MOH.nb3b.harmonic M O"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -504,14 +494,14 @@ TEST_F(PairUnitConvertTest, nb3b_harmonic) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style nb3b/harmonic"); command("pair_coeff * * MOH.nb3b.harmonic M O"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -530,13 +520,13 @@ TEST_F(PairUnitConvertTest, sw) // check if the prerequisite pair style is available if (!info->has_style("pair", "sw")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style sw"); command("pair_coeff * * GaN.sw Ga N"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -547,14 +537,14 @@ TEST_F(PairUnitConvertTest, sw) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style sw"); command("pair_coeff * * GaN.sw Ga N"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -573,7 +563,7 @@ TEST_F(PairUnitConvertTest, table_metal2real) // check if the prerequisite pair style is available if (!info->has_style("pair", "table")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style table linear 1000"); @@ -581,7 +571,7 @@ TEST_F(PairUnitConvertTest, table_metal2real) command("pair_coeff 1 2 test.table.metal lj_1_2"); command("pair_coeff 2 2 test.table.metal lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -592,7 +582,7 @@ TEST_F(PairUnitConvertTest, table_metal2real) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); @@ -601,7 +591,7 @@ TEST_F(PairUnitConvertTest, table_metal2real) command("pair_coeff 1 2 test.table.metal lj_1_2"); command("pair_coeff 2 2 test.table.metal lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -620,7 +610,7 @@ TEST_F(PairUnitConvertTest, table_real2metal) // check if the prerequisite pair style is available if (!info->has_style("pair", "table")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style table linear 1000"); @@ -628,7 +618,7 @@ TEST_F(PairUnitConvertTest, table_real2metal) command("pair_coeff 1 2 test.table.real lj_1_2"); command("pair_coeff 2 2 test.table.real lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -639,7 +629,7 @@ TEST_F(PairUnitConvertTest, table_real2metal) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units metal"); command("read_data test_pair_unit_convert.data"); @@ -648,7 +638,7 @@ TEST_F(PairUnitConvertTest, table_real2metal) command("pair_coeff 1 2 test.table.real lj_1_2"); command("pair_coeff 2 2 test.table.real lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -667,13 +657,13 @@ TEST_F(PairUnitConvertTest, tersoff) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff"); command("pair_coeff * * SiC.tersoff Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -684,14 +674,14 @@ TEST_F(PairUnitConvertTest, tersoff) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff"); command("pair_coeff * * SiC.tersoff Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -710,13 +700,13 @@ TEST_F(PairUnitConvertTest, tersoff_mod) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/mod")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/mod"); command("pair_coeff * * Si.tersoff.mod Si Si"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -727,14 +717,14 @@ TEST_F(PairUnitConvertTest, tersoff_mod) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/mod"); command("pair_coeff * * Si.tersoff.mod Si Si"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -753,13 +743,13 @@ TEST_F(PairUnitConvertTest, tersoff_mod_c) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/mod/c")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/mod/c"); command("pair_coeff * * Si.tersoff.modc Si Si"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -770,14 +760,14 @@ TEST_F(PairUnitConvertTest, tersoff_mod_c) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/mod/c"); command("pair_coeff * * Si.tersoff.modc Si Si"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -796,13 +786,13 @@ TEST_F(PairUnitConvertTest, tersoff_table) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/table")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/table"); command("pair_coeff * * SiC.tersoff Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -813,14 +803,14 @@ TEST_F(PairUnitConvertTest, tersoff_table) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/table"); command("pair_coeff * * SiC.tersoff Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -839,13 +829,13 @@ TEST_F(PairUnitConvertTest, tersoff_zbl) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/zbl")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/zbl"); command("pair_coeff * * SiC.tersoff.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -856,14 +846,14 @@ TEST_F(PairUnitConvertTest, tersoff_zbl) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/zbl"); command("pair_coeff * * SiC.tersoff.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -882,14 +872,14 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/zbl/omp")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("package omp 4"); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/zbl/omp"); command("pair_coeff * * SiC.tersoff.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -900,7 +890,7 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("package omp 4"); command("units real"); @@ -908,7 +898,7 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp) command("pair_style tersoff/zbl/omp"); command("pair_coeff * * SiC.tersoff.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -927,13 +917,13 @@ TEST_F(PairUnitConvertTest, vashishta) // check if the prerequisite pair style is available if (!info->has_style("pair", "vashishta")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style vashishta"); command("pair_coeff * * SiC.vashishta Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -944,14 +934,14 @@ TEST_F(PairUnitConvertTest, vashishta) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style vashishta"); command("pair_coeff * * SiC.vashishta Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 01c5872579..deab845573 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -22,6 +22,8 @@ #include "exceptions.h" #include +#include +#include using namespace LAMMPS_NS; @@ -103,20 +105,31 @@ public: } protected: - const char *testbinary = "LAMMPSTest"; + std::string testbinary = "LAMMPSTest"; + std::vector args = {"-log", "none", "-echo", "screen", "-nocite"}; LAMMPS *lmp; Info *info; void SetUp() override { - const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = args.size() + 1; + char ** argv = new char*[argc]; + argv[0] = utils::strdup(testbinary); + for(int i = 1; i < argc; i++) { + argv[i] = utils::strdup(args[i-1]); + } + HIDE_OUTPUT([&] { lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); info = new Info(lmp); }); InitSystem(); + + for(int i = 0; i < argc; i++) { + delete [] argv[i]; + argv[i] = nullptr; + } + delete [] argv; } virtual void InitSystem() {}