libcryfs/test/cpp-utils/system/FiletimeTest.cpp
Sebastian Messmer 9ccb006f61 - Switch some CI jobs to clang 15
- Fix clang-tidy warnings from Clang 15
2023-07-08 14:48:59 -07:00

30 lines
1.0 KiB
C++

#include <gtest/gtest.h>
#include <cpp-utils/system/filetime.h>
#include <cpp-utils/tempfile/TempFile.h>
using cpputils::TempFile;
using cpputils::set_filetime;
using cpputils::get_filetime;
TEST(FiletimeTest, SetAndGetTime_ReturnsCorrectTime) {
const TempFile file;
const struct timespec accessTime { 1535965242, 12345000 };
const struct timespec modificationTime { 1435965242, 98765000 };
int retval = set_filetime(file.path().string().c_str(), accessTime, modificationTime);
EXPECT_EQ(0, retval);
struct timespec readAccessTime{};
struct timespec readModificationTime{};
retval = get_filetime(file.path().string().c_str(), &readAccessTime, &readModificationTime);
EXPECT_EQ(0, retval);
EXPECT_EQ(accessTime.tv_sec, readAccessTime.tv_sec);
EXPECT_EQ(modificationTime.tv_sec, readModificationTime.tv_sec);
// Apple unfortunately doesn't give us nanoseconds at all
#if !defined(__APPLE__)
EXPECT_EQ(accessTime.tv_nsec, readAccessTime.tv_nsec);
EXPECT_EQ(modificationTime.tv_nsec, readModificationTime.tv_nsec);
#endif
}