tests: Update GBookmarkFile tests to use new APIs

In preparation for deprecating the old APIs. This shouldn’t functionally
affect the tests.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1931
This commit is contained in:
Philip Withnall 2020-05-28 13:03:44 +01:00
parent fbc1456971
commit 9b82fd021a

View File

@ -127,7 +127,7 @@ test_misc (void)
gboolean res; gboolean res;
GError *error = NULL; GError *error = NULL;
gchar *s; gchar *s;
time_t before, after, t; GDateTime *before, *after, *t;
gchar *cmd, *exec; gchar *cmd, *exec;
guint count; guint count;
@ -196,47 +196,55 @@ test_misc (void)
g_assert_no_error (error); g_assert_no_error (error);
g_assert_true (res); g_assert_true (res);
time (&before); before = g_date_time_new_now_utc ();
g_bookmark_file_set_added (bookmark, g_bookmark_file_set_added_date_time (bookmark,
"file:///tmp/schedule3.ps", "file:///tmp/schedule3.ps",
(time_t)-1); before);
t = g_bookmark_file_get_added (bookmark, t = g_bookmark_file_get_added_date_time (bookmark,
"file:///tmp/schedule3.ps", "file:///tmp/schedule3.ps",
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
time (&after); after = g_date_time_new_now_utc ();
g_assert_cmpint (before, <=, t); g_assert_cmpint (g_date_time_compare (before, t), <=, 0);
g_assert_cmpint (t, <=, after); g_assert_cmpint (g_date_time_compare (t, after), <=, 0);
time (&before); g_date_time_unref (after);
g_date_time_unref (before);
g_bookmark_file_set_modified (bookmark, before = g_date_time_new_now_utc ();
"file:///tmp/schedule4.ps",
(time_t)-1); g_bookmark_file_set_modified_date_time (bookmark,
t = g_bookmark_file_get_modified (bookmark, "file:///tmp/schedule4.ps",
"file:///tmp/schedule4.ps", before);
&error); t = g_bookmark_file_get_modified_date_time (bookmark,
"file:///tmp/schedule4.ps",
&error);
g_assert_no_error (error); g_assert_no_error (error);
time (&after); after = g_date_time_new_now_utc ();
g_assert_cmpint (before, <=, t); g_assert_cmpint (g_date_time_compare (before, t), <=, 0);
g_assert_cmpint (t, <=, after); g_assert_cmpint (g_date_time_compare (t, after), <=, 0);
time (&before); g_date_time_unref (after);
g_date_time_unref (before);
g_bookmark_file_set_visited (bookmark, before = g_date_time_new_now_utc ();
"file:///tmp/schedule5.ps",
(time_t)-1); g_bookmark_file_set_visited_date_time (bookmark,
t = g_bookmark_file_get_visited (bookmark, "file:///tmp/schedule5.ps",
"file:///tmp/schedule5.ps", before);
&error); t = g_bookmark_file_get_visited_date_time (bookmark,
"file:///tmp/schedule5.ps",
&error);
g_assert_no_error (error); g_assert_no_error (error);
time (&after); after = g_date_time_new_now_utc ();
g_assert_cmpint (before, <=, t); g_assert_cmpint (g_date_time_compare (before, t), <=, 0);
g_assert_cmpint (t, <=, after); g_assert_cmpint (g_date_time_compare (t, after), <=, 0);
g_date_time_unref (after);
g_date_time_unref (before);
g_bookmark_file_set_icon (bookmark, g_bookmark_file_set_icon (bookmark,
"file:///tmp/schedule6.ps", "file:///tmp/schedule6.ps",
@ -271,16 +279,16 @@ test_misc (void)
g_assert_false (res); g_assert_false (res);
g_clear_error (&error); g_clear_error (&error);
time (&before); before = g_date_time_new_now_utc ();
g_bookmark_file_add_application (bookmark, g_bookmark_file_add_application (bookmark,
"file:///tmp/schedule7.ps", "file:///tmp/schedule7.ps",
NULL, NULL); NULL, NULL);
res = g_bookmark_file_get_app_info (bookmark, res = g_bookmark_file_get_application_info (bookmark,
"file:///tmp/schedule7.ps", "file:///tmp/schedule7.ps",
g_get_application_name (), g_get_application_name (),
&exec, &count, &t, &exec, &count, &t,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_true (res); g_assert_true (res);
cmd = g_strconcat (g_get_prgname (), " file:///tmp/schedule7.ps", NULL); cmd = g_strconcat (g_get_prgname (), " file:///tmp/schedule7.ps", NULL);
@ -288,9 +296,13 @@ test_misc (void)
g_free (cmd); g_free (cmd);
g_free (exec); g_free (exec);
g_assert_cmpuint (count, ==, 1); g_assert_cmpuint (count, ==, 1);
time (&after);
g_assert_cmpint (before, <=, t); after = g_date_time_new_now_utc ();
g_assert_cmpint (t, <=, after); g_assert_cmpint (g_date_time_compare (before, t), <=, 0);
g_assert_cmpint (g_date_time_compare (t, after), <=, 0);
g_date_time_unref (after);
g_date_time_unref (before);
g_bookmark_file_free (bookmark); g_bookmark_file_free (bookmark);
} }
@ -349,8 +361,8 @@ test_modify (GBookmarkFile *bookmark)
{ {
gchar *text; gchar *text;
guint count; guint count;
time_t stamp; GDateTime *stamp;
time_t now; GDateTime *now = NULL;
GError *error = NULL; GError *error = NULL;
gchar **groups; gchar **groups;
gsize length; gsize length;
@ -380,17 +392,17 @@ test_modify (GBookmarkFile *bookmark)
g_bookmark_file_set_title (bookmark, TEST_URI_0, "a title"); g_bookmark_file_set_title (bookmark, TEST_URI_0, "a title");
g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description"); g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description");
g_bookmark_file_set_is_private (bookmark, TEST_URI_0, TRUE); g_bookmark_file_set_is_private (bookmark, TEST_URI_0, TRUE);
time (&now); now = g_date_time_new_now_utc ();
g_bookmark_file_set_added (bookmark, TEST_URI_0, now); g_bookmark_file_set_added_date_time (bookmark, TEST_URI_0, now);
g_bookmark_file_set_visited (bookmark, TEST_URI_0, now); g_bookmark_file_set_visited_date_time (bookmark, TEST_URI_0, now);
g_bookmark_file_set_icon (bookmark, TEST_URI_0, "testicon", "image/png"); g_bookmark_file_set_icon (bookmark, TEST_URI_0, "testicon", "image/png");
/* Check the modification date by itself, as its updated whenever we modify /* Check the modification date by itself, as its updated whenever we modify
* other properties. */ * other properties. */
g_bookmark_file_set_modified (bookmark, TEST_URI_0, now); g_bookmark_file_set_modified_date_time (bookmark, TEST_URI_0, now);
stamp = g_bookmark_file_get_modified (bookmark, TEST_URI_0, &error); stamp = g_bookmark_file_get_modified_date_time (bookmark, TEST_URI_0, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpint (stamp, ==, now); g_assert_cmpint (g_date_time_compare (stamp, now), ==, 0);
text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error); text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error);
g_assert_no_error (error); g_assert_no_error (error);
@ -402,12 +414,12 @@ test_modify (GBookmarkFile *bookmark)
g_free (text); g_free (text);
g_assert_true (g_bookmark_file_get_is_private (bookmark, TEST_URI_0, &error)); g_assert_true (g_bookmark_file_get_is_private (bookmark, TEST_URI_0, &error));
g_assert_no_error (error); g_assert_no_error (error);
stamp = g_bookmark_file_get_added (bookmark, TEST_URI_0, &error); stamp = g_bookmark_file_get_added_date_time (bookmark, TEST_URI_0, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpint (stamp, ==, now); g_assert_cmpint (g_date_time_compare (stamp, now), ==, 0);
stamp = g_bookmark_file_get_visited (bookmark, TEST_URI_0, &error); stamp = g_bookmark_file_get_visited_date_time (bookmark, TEST_URI_0, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpint (stamp, ==, now); g_assert_cmpint (g_date_time_compare (stamp, now), ==, 0);
g_assert_true (g_bookmark_file_get_icon (bookmark, TEST_URI_0, &icon, &mime, &error)); g_assert_true (g_bookmark_file_get_icon (bookmark, TEST_URI_0, &icon, &mime, &error));
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpstr (icon, ==, "testicon"); g_assert_cmpstr (icon, ==, "testicon");
@ -425,13 +437,13 @@ test_modify (GBookmarkFile *bookmark)
g_bookmark_file_get_is_private (bookmark, TEST_URI_1, &error); g_bookmark_file_get_is_private (bookmark, TEST_URI_1, &error);
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND); g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
g_clear_error (&error); g_clear_error (&error);
g_bookmark_file_get_added (bookmark, TEST_URI_1, &error); g_bookmark_file_get_added_date_time (bookmark, TEST_URI_1, &error);
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND); g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
g_clear_error (&error); g_clear_error (&error);
g_bookmark_file_get_modified (bookmark, TEST_URI_1, &error); g_bookmark_file_get_modified_date_time (bookmark, TEST_URI_1, &error);
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND); g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
g_clear_error (&error); g_clear_error (&error);
g_bookmark_file_get_visited (bookmark, TEST_URI_1, &error); g_bookmark_file_get_visited_date_time (bookmark, TEST_URI_1, &error);
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND); g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
g_clear_error (&error); g_clear_error (&error);
if (g_test_verbose ()) if (g_test_verbose ())
@ -445,14 +457,14 @@ test_modify (GBookmarkFile *bookmark)
TEST_APP_NAME, TEST_APP_NAME,
TEST_APP_EXEC); TEST_APP_EXEC);
g_assert_true (g_bookmark_file_has_application (bookmark, TEST_URI_0, TEST_APP_NAME, NULL)); g_assert_true (g_bookmark_file_has_application (bookmark, TEST_URI_0, TEST_APP_NAME, NULL));
g_bookmark_file_get_app_info (bookmark, TEST_URI_0, TEST_APP_NAME, g_bookmark_file_get_application_info (bookmark, TEST_URI_0, TEST_APP_NAME,
&text, &text,
&count, &count,
&stamp, &stamp,
&error); &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpuint (count, ==, 1); g_assert_cmpuint (count, ==, 1);
g_assert_cmpint (stamp, ==, g_bookmark_file_get_modified (bookmark, TEST_URI_0, NULL)); g_assert_cmpint (g_date_time_compare (stamp, g_bookmark_file_get_modified_date_time (bookmark, TEST_URI_0, NULL)), <=, 0);
g_free (text); g_free (text);
g_assert_true (g_bookmark_file_remove_application (bookmark, TEST_URI_0, TEST_APP_NAME, &error)); g_assert_true (g_bookmark_file_remove_application (bookmark, TEST_URI_0, TEST_APP_NAME, &error));
g_assert_no_error (error); g_assert_no_error (error);
@ -463,11 +475,11 @@ test_modify (GBookmarkFile *bookmark)
g_assert_cmpstr (apps[0], ==, TEST_APP_NAME); g_assert_cmpstr (apps[0], ==, TEST_APP_NAME);
g_strfreev (apps); g_strfreev (apps);
g_bookmark_file_get_app_info (bookmark, TEST_URI_0, "fail", g_bookmark_file_get_application_info (bookmark, TEST_URI_0, "fail",
&text, &text,
&count, &count,
&stamp, &stamp,
&error); &error);
g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED); g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED);
g_clear_error (&error); g_clear_error (&error);
@ -508,7 +520,9 @@ test_modify (GBookmarkFile *bookmark)
g_clear_error (&error); g_clear_error (&error);
if (g_test_verbose ()) if (g_test_verbose ())
g_printerr ("ok\n"); g_printerr ("ok\n");
g_date_time_unref (now);
return TRUE; return TRUE;
} }