]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/experimental/filesystem/operations/last_write_time.cc
Handle negative times in filesystem::last_write_time
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / operations / last_write_time.cc
index dee55a53cdb1dfbdbc6bf267e97cd51f5f69e0a6..74be4f94dda42cc3dbad734bd79eff68953c0ff6 100644 (file)
@@ -35,6 +35,8 @@
 void
 test01()
 {
+  // read times
+
   using time_type = std::experimental::filesystem::file_time_type;
 
   auto p = __gnu_test::nonexistent_path();
@@ -103,8 +105,46 @@ test01()
 #endif
 }
 
+void
+test02()
+{
+  // write times
+
+  using time_type = std::experimental::filesystem::file_time_type;
+
+  __gnu_test::scoped_file f;
+  std::error_code ec;
+  time_type time;
+
+  time = last_write_time(f.path);
+  last_write_time(f.path, time, ec);
+  VERIFY( !ec );
+  VERIFY( last_write_time(f.path) == time );
+
+  time -= std::chrono::milliseconds(1000 * 60 * 10 + 15);
+  last_write_time(f.path, time, ec);
+  VERIFY( !ec );
+  VERIFY( last_write_time(f.path) == time );
+
+  time += std::chrono::milliseconds(1000 * 60 * 20 + 15);
+  last_write_time(f.path, time, ec);
+  VERIFY( !ec );
+  VERIFY( last_write_time(f.path) == time );
+
+  time = time_type();
+  last_write_time(f.path, time, ec);
+  VERIFY( !ec );
+  VERIFY( last_write_time(f.path) == time );
+
+  time -= std::chrono::milliseconds(1000 * 60 * 10 + 15);
+  last_write_time(f.path, time, ec);
+  VERIFY( !ec );
+  VERIFY( last_write_time(f.path) == time );
+}
+
 int
 main()
 {
   test01();
+  test02();
 }