summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2019-09-05 17:10:32 +0100
committerPhilip Withnall <withnall@endlessm.com>2019-09-05 17:13:08 +0100
commit475b9b5f7cf09567d8c4c10007b85595f27a680f (patch)
treee2e1fb49d4176d82411eba7d31f0a60d9dfcce88
parentb99cdf56dc7186329a4ca4590a030c7fb2312903 (diff)
downloadglib-475b9b5f7cf09567d8c4c10007b85595f27a680f.tar.gz
tests: Add tests for GFileInfo modification time
Signed-off-by: Philip Withnall <withnall@endlessm.com>
-rw-r--r--gio/tests/g-file-info.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/gio/tests/g-file-info.c b/gio/tests/g-file-info.c
index 987552118..1fbdf71fa 100644
--- a/gio/tests/g-file-info.c
+++ b/gio/tests/g-file-info.c
@@ -141,6 +141,66 @@ test_g_file_info (void)
g_object_unref (info_copy);
}
+static void
+test_g_file_info_modification_time (void)
+{
+ GFile *file = NULL;
+ GFileIOStream *io_stream = NULL;
+ GFileInfo *info = NULL;
+ GDateTime *dt = NULL, *dt_usecs = NULL, *dt_new = NULL, *dt_new_usecs = NULL;
+ GTimeSpan ts;
+ GError *error = NULL;
+
+ g_test_summary ("Test that getting the modification time of a file works.");
+
+ file = g_file_new_tmp ("g-file-info-test-XXXXXX", &io_stream, &error);
+ g_assert_no_error (error);
+
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, &error);
+ g_assert_no_error (error);
+
+ /* Check the modification time is retrievable. */
+ dt = g_file_info_get_modification_date_time (info);
+ g_assert_nonnull (dt);
+
+ /* Try again with microsecond precision. */
+ g_clear_object (&info);
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED "," G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, &error);
+ g_assert_no_error (error);
+
+ dt_usecs = g_file_info_get_modification_date_time (info);
+ g_assert_nonnull (dt_usecs);
+
+ ts = g_date_time_difference (dt_usecs, dt);
+ g_assert_cmpint (ts, >, 0);
+ g_assert_cmpint (ts, <, G_USEC_PER_SEC);
+
+ /* Try round-tripping the modification time. */
+ dt_new = g_date_time_add (dt_usecs, G_USEC_PER_SEC + 50);
+ g_file_info_set_modification_date_time (info, dt_new);
+
+ dt_new_usecs = g_file_info_get_modification_date_time (info);
+ ts = g_date_time_difference (dt_new_usecs, dt_new);
+ g_assert_cmpint (ts, ==, 0);
+
+ /* Clean up. */
+ g_clear_object (&io_stream);
+ g_file_delete (file, NULL, NULL);
+ g_clear_object (&file);
+
+ g_clear_object (&info);
+ g_date_time_unref (dt);
+ g_date_time_unref (dt_usecs);
+ g_date_time_unref (dt_new);
+ g_date_time_unref (dt_new_usecs);
+}
+
#ifdef G_OS_WIN32
static void
test_internal_enhanced_stdio (void)
@@ -564,6 +624,7 @@ main (int argc,
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/g-file-info/test_g_file_info", test_g_file_info);
+ g_test_add_func ("/g-file-info/test_g_file_info/modification-time", test_g_file_info_modification_time);
#ifdef G_OS_WIN32
g_test_add_func ("/g-file-info/internal-enhanced-stdio", test_internal_enhanced_stdio);
#endif