diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2015-09-17 15:13:16 +1000 |
---|---|---|
committer | Tim Mayberry <mojofunk@gmail.com> | 2015-09-17 23:26:38 +1000 |
commit | e44212321e436ee12bffb76361202b5efc83a172 (patch) | |
tree | a5013e20b82ca53bff40e6c878b96858cc755032 /libs/pbd/test | |
parent | 95b55c7346f85f92751f74b3c6b91cc35d1d5909 (diff) |
Add test to libpbd to check PBD::touch_file and pbd/gstdio_compat.h
GStatBuf is not usable on 32 bit Windows without the redefinition in
pbd/gstdio_compat.h so add a test to check for the correct behavior of
g_stat and g_utime on all platforms now that the issue is fixed.
Diffstat (limited to 'libs/pbd/test')
-rw-r--r-- | libs/pbd/test/filesystem_test.cc | 76 | ||||
-rw-r--r-- | libs/pbd/test/filesystem_test.h | 4 |
2 files changed, 80 insertions, 0 deletions
diff --git a/libs/pbd/test/filesystem_test.cc b/libs/pbd/test/filesystem_test.cc index adff0c409b..1eaba54968 100644 --- a/libs/pbd/test/filesystem_test.cc +++ b/libs/pbd/test/filesystem_test.cc @@ -8,9 +8,16 @@ #include <fcntl.h> +#ifdef COMPILER_MSVC +#include <sys/utime.h> +#else +#include <utime.h> +#endif + #include <glibmm/miscutils.h> #include <glibmm/fileutils.h> #include <glibmm/convert.h> +#include <glibmm/timer.h> #include "pbd/file_utils.h" #include "pbd/pathexpand.h" @@ -363,3 +370,72 @@ FilesystemTest::testCanonicalPath () CPPUNIT_ASSERT (expanded_path == expected_path); #endif } + +void +FilesystemTest::testTouchFile () +{ + const string filename = "touch.me"; + + const string test_dir = test_output_directory ("testTouchFile"); + const string touch_file_path = Glib::build_filename (test_dir, filename); + + CPPUNIT_ASSERT (touch_file(touch_file_path)); + + CPPUNIT_ASSERT (Glib::file_test (touch_file_path, Glib::FILE_TEST_EXISTS)); +} + +void +FilesystemTest::testStatFile () +{ + const string filename1 = "touch.me"; + const string filename2 = "touch.me.2"; + + const string test_dir = test_output_directory ("testStatFile"); + + const string path1 = Glib::build_filename (test_dir, filename1); + const string path2 = Glib::build_filename (test_dir, filename2); + + CPPUNIT_ASSERT (touch_file(path1)); + + Glib::usleep (2000000); + + CPPUNIT_ASSERT (touch_file(path2)); + + GStatBuf gsb1; + GStatBuf gsb2; + + CPPUNIT_ASSERT (g_stat (path1.c_str(), &gsb1) == 0); + CPPUNIT_ASSERT (g_stat (path2.c_str(), &gsb2) == 0); + + cerr << endl; + cerr << "StatFile: " << path1 << " access time: " << gsb1.st_atime << endl; + cerr << "StatFile: " << path1 << " modification time: " << gsb1.st_mtime << endl; + cerr << "StatFile: " << path2 << " access time: " << gsb2.st_atime << endl; + cerr << "StatFile: " << path2 << " modification time: " << gsb2.st_mtime << endl; + + CPPUNIT_ASSERT (gsb1.st_atime == gsb1.st_mtime); + CPPUNIT_ASSERT (gsb2.st_atime == gsb2.st_mtime); + + // at least access time works on windows(or at least on ntfs) + CPPUNIT_ASSERT (gsb1.st_atime < gsb2.st_atime); + CPPUNIT_ASSERT (gsb1.st_mtime < gsb2.st_mtime); + + struct utimbuf tbuf; + + tbuf.actime = gsb1.st_atime; + tbuf.modtime = gsb1.st_mtime; + + // update the file access/modification times to be the same + CPPUNIT_ASSERT (g_utime (path2.c_str(), &tbuf) == 0); + + CPPUNIT_ASSERT (g_stat (path2.c_str(), &gsb2) == 0); + + cerr << endl; + cerr << "StatFile: " << path1 << " access time: " << gsb1.st_atime << endl; + cerr << "StatFile: " << path1 << " modification time: " << gsb1.st_mtime << endl; + cerr << "StatFile: " << path2 << " access time: " << gsb2.st_atime << endl; + cerr << "StatFile: " << path2 << " modification time: " << gsb2.st_mtime << endl; + + CPPUNIT_ASSERT (gsb1.st_atime == gsb2.st_atime); + CPPUNIT_ASSERT (gsb1.st_mtime == gsb2.st_mtime); +} diff --git a/libs/pbd/test/filesystem_test.h b/libs/pbd/test/filesystem_test.h index c200bb2ba7..0274d61139 100644 --- a/libs/pbd/test/filesystem_test.h +++ b/libs/pbd/test/filesystem_test.h @@ -12,6 +12,8 @@ class FilesystemTest : public CppUnit::TestFixture CPPUNIT_TEST (testClearDirectory); CPPUNIT_TEST (testRemoveDirectory); CPPUNIT_TEST (testCanonicalPath); + CPPUNIT_TEST (testTouchFile); + CPPUNIT_TEST (testStatFile); CPPUNIT_TEST_SUITE_END (); public: @@ -23,5 +25,7 @@ public: void testClearDirectory (); void testRemoveDirectory (); void testCanonicalPath (); + void testTouchFile (); + void testStatFile (); }; |