port error check test from fortran wrapper to c-library interface test
This commit is contained in:
@ -434,6 +434,33 @@ TEST_F(LibraryProperties, neighlist)
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(LibraryProperties, has_error)
|
||||
{
|
||||
// need errors to throw exceptions to be able to intercept them.
|
||||
if (!lammps_config_has_exceptions()) GTEST_SKIP();
|
||||
|
||||
EXPECT_EQ(lammps_has_error(lmp), 0);
|
||||
|
||||
// trigger an error, but hide output
|
||||
::testing::internal::CaptureStdout();
|
||||
lammps_command(lmp, "this_is_not_a_known_command");
|
||||
::testing::internal::GetCapturedStdout();
|
||||
|
||||
EXPECT_EQ(lammps_has_error(lmp), 1);
|
||||
|
||||
// retrieve error message
|
||||
char errmsg[1024];
|
||||
int err = lammps_get_last_error_message(lmp, errmsg, 1024);
|
||||
EXPECT_EQ(err, 1);
|
||||
EXPECT_THAT(errmsg, HasSubstr("ERROR: Unknown command: this_is_not_a_known_command"));
|
||||
|
||||
// retrieving the error message clear the error status
|
||||
EXPECT_EQ(lammps_has_error(lmp), 0);
|
||||
err = lammps_get_last_error_message(lmp, errmsg, 1024);
|
||||
EXPECT_EQ(err, 0);
|
||||
EXPECT_THAT(errmsg, StrEq(""));
|
||||
};
|
||||
|
||||
class AtomProperties : public ::testing::Test {
|
||||
protected:
|
||||
void *lmp;
|
||||
|
||||
Reference in New Issue
Block a user