Skip to content
Snippets Groups Projects
Commit 9c11cfee authored by mkirsz's avatar mkirsz
Browse files

replaced std::tmpnam

parent 81e181ae
No related branches found
No related tags found
1 merge request!12Develop
...@@ -56,63 +56,84 @@ TEST_CASE( "Testing Structure virial pressure calculations", "[structure_virial_ ...@@ -56,63 +56,84 @@ TEST_CASE( "Testing Structure virial pressure calculations", "[structure_virial_
REQUIRE(fac*st.get_virial_pressure() == Approx(499.93)); REQUIRE(fac*st.get_virial_pressure() == Approx(499.93));
} }
TEST_CASE( "Testing Structure read and write", "[structure_read_write]" ) { TEST_CASE("Testing Structure read and write", "[structure_read_write]") {
Structure st; Structure st;
st.read("tests_data/structure_1.dat"); st.read("tests_data/structure_1.dat");
REQUIRE(st.get_volume() == Approx(989.521812));
REQUIRE(st.get_volume() == Approx(989.521812)); REQUIRE(fac * st.get_virial_pressure() == Approx(26.705578));
REQUIRE(fac * st.get_pressure(300) == Approx(28.965914));
REQUIRE(fac * st.get_pressure(0) == Approx(26.705578));
REQUIRE(fac*st.get_virial_pressure() == Approx(26.705578)); // Create a temporary file
REQUIRE(fac*st.get_pressure(300) == Approx(28.965914)); std::FILE* tmpFile = std::tmpfile();
REQUIRE(fac*st.get_pressure(0) == Approx(26.705578)); if (!tmpFile) {
FAIL("Unable to create temporary file");
}
std::string tempfile = std::tmpnam(nullptr); const int fd = fileno(tmpFile);
st.save(tempfile); REQUIRE(fd != -1);
Structure st_temp; char tempfile[256];
st_temp.read(tempfile); snprintf(tempfile, sizeof(tempfile), "/proc/self/fd/%d", fd);
REQUIRE(st_temp.get_volume() == Approx(989.521812)); st.save(tempfile);
REQUIRE(fac*st_temp.get_virial_pressure() == Approx(26.705578)); Structure st_temp;
REQUIRE(fac*st_temp.get_pressure(300) == Approx(28.965914)); st_temp.read(tempfile);
REQUIRE(fac*st_temp.get_pressure(0) == Approx(26.705578));
REQUIRE(st==st_temp); REQUIRE(st_temp.get_volume() == Approx(989.521812));
REQUIRE(fac * st_temp.get_virial_pressure() == Approx(26.705578));
REQUIRE(fac * st_temp.get_pressure(300) == Approx(28.965914));
REQUIRE(fac * st_temp.get_pressure(0) == Approx(26.705578));
std::remove(tempfile.c_str()); REQUIRE(st == st_temp);
// Temporary file will be closed automatically
} }
TEST_CASE( "Testing Structure compare", "[structure_compare]" ) { TEST_CASE("Testing Structure compare", "[structure_compare]") {
Structure st; Structure st;
st.read("tests_data/structure_1.dat"); st.read("tests_data/structure_1.dat");
std::string tempfile = std::tmpnam(nullptr);
st.save(tempfile); // Create a temporary file
std::FILE* tmpFile = std::tmpfile();
Structure st_temp; if (!tmpFile) {
st_temp.read(tempfile); FAIL("Unable to create temporary file");
}
SECTION("Compare unchanged") {
REQUIRE(st==st_temp); const int fd = fileno(tmpFile);
} REQUIRE(fd != -1);
SECTION("Compare symbols") {
REQUIRE(st==st_temp); char tempfile[256];
st_temp.atoms[0].symbol[0]='X'; snprintf(tempfile, sizeof(tempfile), "/proc/self/fd/%d", fd);
st_temp.atoms[0].symbol[1]='X';
REQUIRE(!(st==st_temp)); st.save(tempfile);
}
SECTION("Compare position") { Structure st_temp;
REQUIRE(st==st_temp); st_temp.read(tempfile);
st_temp.atoms[0].position(0.12,0.13,10.14);
REQUIRE(!(st==st_temp)); SECTION("Compare unchanged") {
} REQUIRE(st == st_temp);
SECTION("Compare force") { }
REQUIRE(st==st_temp); SECTION("Compare symbols") {
st_temp.atoms[0].force(1.12, 0.13, 0.134); REQUIRE(st == st_temp);
REQUIRE(!(st==st_temp)); st_temp.atoms[0].symbol[0] = 'X';
} st_temp.atoms[0].symbol[1] = 'X';
REQUIRE(!(st == st_temp));
std::remove(tempfile.c_str()); }
SECTION("Compare position") {
REQUIRE(st == st_temp);
st_temp.atoms[0].position(0.12, 0.13, 10.14);
REQUIRE(!(st == st_temp));
}
SECTION("Compare force") {
REQUIRE(st == st_temp);
st_temp.atoms[0].force(1.12, 0.13, 0.134);
REQUIRE(!(st == st_temp));
}
// Temporary file will be closed automatically
} }
TEST_CASE( "Testing Structure copy", "[structure_copy]" ) { TEST_CASE( "Testing Structure copy", "[structure_copy]" ) {
Structure st; Structure st;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment