#define TEST_APP_NAME "bookmarkfile-test"
#define TEST_APP_EXEC "bookmarkfile-test %f"
-static void
-test_assert_empty_error (GError **error)
-{
- if (*error != NULL)
- {
- g_warning ("Unexpected error (d: %s, c: %d): %s\n",
- g_quark_to_string ((*error)->domain),
- (*error)->code,
- (*error)->message);
- g_error_free (*error);
-
- g_assert_not_reached ();
- }
-}
-
-static void
-test_assert_not_empty_error (GError **error,
- GQuark domain,
- gint code)
-{
- if (*error == NULL)
- {
- g_warning ("Unexpected success (%s domain expected)\n",
- g_quark_to_string (domain));
-
- g_assert_not_reached ();
- }
-
- if ((*error)->domain != domain)
- {
- g_warning ("Unexpected domain %s (%s domain expected)\n",
- g_quark_to_string ((*error)->domain),
- g_quark_to_string (domain));
-
- g_assert_not_reached ();
- }
-
- if ((*error)->code != code)
- {
- g_warning ("Unexpected code %d (%d code expected)\n",
- (*error)->code,
- code);
-
- g_assert_not_reached ();
- }
-
- g_error_free (*error);
- *error = NULL;
-}
-
-static void
-test_assert_str_equal (const gchar *str,
- const gchar *cmp)
-{
- if (strcmp (str, cmp) != 0)
- {
- g_warning ("Unexpected string '%s' ('%s' expected)\n", str, cmp);
-
- g_assert_not_reached ();
- }
-}
-
static gboolean
test_load (GBookmarkFile *bookmark,
const gchar *filename)
g_bookmark_file_set_description (bookmark, NULL, "a bookmark file");
text = g_bookmark_file_get_title (bookmark, NULL, &error);
- test_assert_empty_error (&error);
- test_assert_str_equal (text, "a file");
+ g_assert_no_error (error);
+ g_assert_cmpstr (text, ==, "a file");
g_free (text);
text = g_bookmark_file_get_description (bookmark, NULL, &error);
- test_assert_empty_error (&error);
- test_assert_str_equal (text, "a bookmark file");
+ g_assert_no_error (error);
+ g_assert_cmpstr (text, ==, "a bookmark file");
g_free (text);
g_print ("ok\n");
g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description");
text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error);
- test_assert_empty_error (&error);
- test_assert_str_equal (text, "a title");
+ g_assert_no_error (error);
+ g_assert_cmpstr (text, ==, "a title");
g_free (text);
g_print ("ok\n");
g_print ("\t=> check non existing bookmark...");
g_bookmark_file_get_description (bookmark, TEST_URI_1, &error);
- test_assert_not_empty_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_print ("ok\n");
g_print ("\t=> check application...");
&count,
&stamp,
&error);
- test_assert_empty_error (&error);
+ g_assert_no_error (error);
g_assert (count == 1);
g_assert (stamp == g_bookmark_file_get_modified (bookmark, TEST_URI_0, NULL));
g_free (text);
&count,
&stamp,
&error);
- test_assert_not_empty_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_print ("ok\n");
g_print ("\t=> check groups...");
g_assert (g_bookmark_file_has_group (bookmark, TEST_URI_1, "Test", NULL) == TRUE);
g_assert (g_bookmark_file_has_group (bookmark, TEST_URI_1, "Fail", NULL) == FALSE);
g_print ("ok\n");
+
+ g_print ("\t=> check remove...");
+ g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == TRUE);
+ g_assert_no_error (error);
+ g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == FALSE);
+ g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
+ g_clear_error (&error);
+ g_print ("ok\n");
return TRUE;
}