Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Differential D49774 Diff 157349 test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp
Changeset View
Changeset View
Standalone View
Standalone View
test/libcxx/experimental/filesystem/class.directory_entry/directory_entry.mods/last_write_time.sh.cpp
Show All 35 Lines | TEST_CASE(last_write_time_not_representable_error) { | ||||
scoped_test_env env; | scoped_test_env env; | ||||
const path dir = env.create_dir("dir"); | const path dir = env.create_dir("dir"); | ||||
const path file = env.create_file("dir/file", 42); | const path file = env.create_file("dir/file", 42); | ||||
TimeSpec ToTime; | TimeSpec ToTime; | ||||
ToTime.tv_sec = std::numeric_limits<decltype(ToTime.tv_sec)>::max(); | ToTime.tv_sec = std::numeric_limits<decltype(ToTime.tv_sec)>::max(); | ||||
ToTime.tv_nsec = duration_cast<nanoseconds>(seconds(1)).count() - 1; | ToTime.tv_nsec = duration_cast<nanoseconds>(seconds(1)).count() - 1; | ||||
TimeStructArray TS; | std::array<TimeSpec, 2> TS = {ToTime, ToTime}; | ||||
SetTimeStructTo(TS[0], ToTime); | |||||
SetTimeStructTo(TS[1], ToTime); | |||||
file_time_type old_time = last_write_time(file); | file_time_type old_time = last_write_time(file); | ||||
directory_entry ent(file); | directory_entry ent(file); | ||||
file_time_type start_time = file_time_type::clock::now() - hours(1); | file_time_type start_time = file_time_type::clock::now() - hours(1); | ||||
last_write_time(file, start_time); | last_write_time(file, start_time); | ||||
TEST_CHECK(ent.last_write_time() == old_time); | TEST_CHECK(ent.last_write_time() == old_time); | ||||
bool IsRepresentable = true; | bool IsRepresentable = true; | ||||
file_time_type rep_value; | file_time_type rep_value; | ||||
{ | { | ||||
std::error_code ec; | std::error_code ec; | ||||
if (SetFileTimes(file, TS, ec)) { | TEST_REQUIRE(!set_file_times(file, TS, ec)); | ||||
TEST_REQUIRE(false && "unsupported"); | |||||
} | |||||
ec.clear(); | ec.clear(); | ||||
rep_value = last_write_time(file, ec); | rep_value = last_write_time(file, ec); | ||||
IsRepresentable = !bool(ec); | IsRepresentable = !bool(ec); | ||||
} | } | ||||
if (!IsRepresentable) { | if (!IsRepresentable) { | ||||
std::error_code rec = GetTestEC(); | std::error_code rec = GetTestEC(); | ||||
ent.refresh(rec); | ent.refresh(rec); | ||||
TEST_CHECK(!rec); | TEST_CHECK(!rec); | ||||
const std::errc expected_err = std::errc::value_too_large; | const std::errc expected_err = std::errc::value_too_large; | ||||
std::error_code ec = GetTestEC(); | std::error_code ec = GetTestEC(); | ||||
TEST_CHECK(ent.last_write_time(ec) == file_time_type::min()); | TEST_CHECK(ent.last_write_time(ec) == file_time_type::min()); | ||||
TEST_CHECK(ErrorIs(ec, expected_err)); | TEST_CHECK(ErrorIs(ec, expected_err)); | ||||
ec = GetTestEC(); | ec = GetTestEC(); | ||||
TEST_CHECK(last_write_time(file, ec) == file_time_type::min()); | TEST_CHECK(last_write_time(file, ec) == file_time_type::min()); | ||||
TEST_CHECK(ErrorIs(ec, expected_err)); | TEST_CHECK(ErrorIs(ec, expected_err)); | ||||
ExceptionChecker CheckExcept(file, expected_err, | ExceptionChecker CheckExcept(file, expected_err, | ||||
"directory_entry::last_write_time"); | "directory_entry::last_write_time"); | ||||
TEST_CHECK_THROW_RESULT(fs::filesystem_error, CheckExcept, | TEST_CHECK_THROW_RESULT(filesystem_error, CheckExcept, | ||||
ent.last_write_time()); | ent.last_write_time()); | ||||
} else { | } else { | ||||
ent.refresh(); | ent.refresh(); | ||||
std::error_code ec = GetTestEC(); | std::error_code ec = GetTestEC(); | ||||
TEST_CHECK(ent.last_write_time(ec) == rep_value); | TEST_CHECK(ent.last_write_time(ec) == rep_value); | ||||
TEST_CHECK(!ec); | TEST_CHECK(!ec); | ||||
} | } | ||||
} | } | ||||
TEST_SUITE_END() | TEST_SUITE_END() |