MCPcopy Create free account
hub / github.com/boostorg/filesystem / write_time_tests

Function write_time_tests

test/operations_test.cpp:1604–1641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1602 // write_time_tests ----------------------------------------------------------------//
1603
1604 void write_time_tests(const fs::path& dir)
1605 {
1606 cout << "write_time_tests..." << endl;
1607
1608 fs::path f1 = dir / "foobar2";
1609 create_file(f1, "foobar2");
1610 BOOST_TEST(fs::exists(f1));
1611 BOOST_TEST(!fs::is_directory(f1));
1612 BOOST_TEST(fs::is_regular_file(f1));
1613 BOOST_TEST(fs::file_size(f1) == 7);
1614 verify_file(f1, "foobar2");
1615
1616 // Some file system report last write time as local (FAT), while
1617 // others (NTFS) report it as UTC. The C standard does not specify
1618 // if time_t is local or UTC.
1619
1620 std::time_t ft = fs::last_write_time(f1);
1621 cout << "\n UTC last_write_time() for a file just created is "
1622 << std::asctime(std::gmtime(&ft)) << endl;
1623
1624 std::tm * tmp = std::localtime(&ft);
1625 cout << "\n Year is " << tmp->tm_year << endl;
1626 --tmp->tm_year;
1627 cout << " Change year to " << tmp->tm_year << endl;
1628 fs::last_write_time(f1, std::mktime(tmp));
1629 std::time_t ft2 = fs::last_write_time(f1);
1630 cout << " last_write_time() for the file is now "
1631 << std::asctime(std::gmtime(&ft2)) << endl;
1632 BOOST_TEST(ft != fs::last_write_time(f1));
1633
1634 cout << "\n Reset to current time" << endl;
1635 fs::last_write_time(f1, ft);
1636 double time_diff = std::difftime(ft, fs::last_write_time(f1));
1637 cout
1638 << " original last_write_time() - current last_write_time() is "
1639 << time_diff << " seconds" << endl;
1640 BOOST_TEST(time_diff >= -60.0 && time_diff <= 60.0);
1641 }
1642
1643 // platform_specific_tests ---------------------------------------------------------//
1644

Callers 1

cpp_mainFunction · 0.85

Calls 7

create_fileFunction · 0.85
existsFunction · 0.85
is_directoryFunction · 0.85
is_regular_fileFunction · 0.85
file_sizeFunction · 0.85
verify_fileFunction · 0.85
last_write_timeFunction · 0.50

Tested by

no test coverage detected