From 909a8856efee40ebffcae2682c9c969bffa73211 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sat, 30 May 2020 17:09:40 +0100 Subject: [PATCH 1/2] Initialize the visited time of a new GBookmarkFile Just like we do for the other fields. Otherwise, when we serialise the item, we're going to hit a segmentation fault when trying to format a NULL GDateTime. --- glib/gbookmarkfile.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/glib/gbookmarkfile.c b/glib/gbookmarkfile.c index 5b612127a..d796b253a 100644 --- a/glib/gbookmarkfile.c +++ b/glib/gbookmarkfile.c @@ -2041,6 +2041,9 @@ g_bookmark_file_add_item (GBookmarkFile *bookmark, if (item->modified == NULL) item->modified = g_date_time_new_now_utc (); + + if (item->visited == NULL) + item->visited = g_date_time_new_now_utc (); } /** From 9f7f2b4d55e4dbd54bbabb235f5bef8297bb8d65 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sat, 30 May 2020 17:40:52 +0100 Subject: [PATCH 2/2] Add a GBookmarkFile serialization test case We're roundtripping from a valid file, but we should also roundtrip from a newly created GBookmarkFile, to ensure that we set all the necessary fields. --- glib/tests/bookmarkfile.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/glib/tests/bookmarkfile.c b/glib/tests/bookmarkfile.c index 2722ebe48..bc1a7a213 100644 --- a/glib/tests/bookmarkfile.c +++ b/glib/tests/bookmarkfile.c @@ -43,10 +43,36 @@ test_to_file (void) const gchar *filename; gboolean res; GError *error = NULL; - gchar *in, *out; + char *in, *out; bookmark = g_bookmark_file_new (); + g_test_message ("Roundtrip from newly created bookmark file"); + g_bookmark_file_set_title (bookmark, "file:///tmp/schedule.ps", "schedule.ps"); + g_bookmark_file_set_mime_type (bookmark, "file:///tmp/schedule.ps", "application/postscript"); + g_bookmark_file_add_application (bookmark, "file:///tmp/schedule.ps", "ghostscript", "ghostscript %F"); + + res = g_bookmark_file_to_file (bookmark, "out.xbel", &error); + g_assert_no_error (error); + g_assert_true (res); + + res = g_bookmark_file_load_from_file (bookmark, "out.xbel", &error); + g_assert_no_error (error); + g_assert_true (res); + + out = g_bookmark_file_get_title (bookmark, "file:///tmp/schedule.ps", &error); + g_assert_no_error (error); + g_assert_cmpstr (out, ==, "schedule.ps"); + g_free (out); + + out = g_bookmark_file_get_mime_type (bookmark, "file:///tmp/schedule.ps", &error); + g_assert_no_error (error); + g_assert_cmpstr (out, ==, "application/postscript"); + g_free (out); + + remove ("out.xbel"); + + g_test_message ("Roundtrip from a valid bookmark file"); filename = g_test_get_filename (G_TEST_DIST, "bookmarks", "valid-01.xbel", NULL); res = g_bookmark_file_load_from_file (bookmark, filename, &error); g_assert_no_error (error);