add a few more unit tests for functions in utils

This commit is contained in:
Axel Kohlmeyer
2020-06-12 01:29:42 -04:00
parent 8c470b9e8b
commit 3c99471df8

View File

@ -15,6 +15,9 @@
#include "gmock/gmock.h"
#include "utils.h"
#include <string>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
using namespace LAMMPS_NS;
using ::testing::Eq;
@ -223,3 +226,35 @@ TEST(Utils, path_basename) {
ASSERT_THAT(utils::path_basename("/parent/folder/filename"), Eq("filename"));
#endif
}
TEST(Utils, getsyserror) {
#if defined(__linux__)
errno = ENOENT;
std::string errmesg = utils::getsyserror();
ASSERT_THAT(errmesg, Eq("No such file or directory"));
#else
GTEST_SKIP();
#endif
}
TEST(Utils, potential_file) {
FILE *fp;
fp = fopen("ctest.txt","w");
ASSERT_NE(fp,nullptr);
fputs("# DATE: 2020-02-20 CONTRIBUTOR: Nessuno\n",fp);
fclose(fp);
EXPECT_TRUE(utils::file_is_readable("ctest.txt"));
EXPECT_FALSE(utils::file_is_readable("no_such_file.txt"));
EXPECT_THAT(utils::get_potential_file_path("ctest.txt"),Eq("ctest.txt"));
const char *folder = getenv("LAMMPS_POTENTIALS");
if (folder != nullptr) {
std::string path=utils::path_join(folder,"Cu_u3.eam");
EXPECT_THAT(utils::get_potential_file_path("Cu_u3.eam"),Eq(path));
}
EXPECT_THAT(utils::get_potential_date("ctest.txt","Test"),Eq("2020-02-20"));
remove("ctest.txt");
}