1 #undef G_DISABLE_ASSERT
10 #define TEST_URI_0 "file:///abc/defgh/ijklmnopqrstuvwxyz"
11 #define TEST_URI_1 "file:///test/uri/1"
12 #define TEST_URI_2 "file:///test/uri/2"
14 #define TEST_MIME "text/plain"
16 #define TEST_APP_NAME "bookmarkfile-test"
17 #define TEST_APP_EXEC "bookmarkfile-test %f"
20 test_load (GBookmarkFile *bookmark,
21 const gchar *filename)
26 res = g_bookmark_file_load_from_file (bookmark, filename, &error);
29 g_print ("Load error: %s\n", error->message);
37 test_query (GBookmarkFile *bookmark)
44 size = g_bookmark_file_get_size (bookmark);
45 uris = g_bookmark_file_get_uris (bookmark, &uris_len);
49 g_print ("URI/size mismatch: URI count is %d (should be %d)\n", uris_len, size);
54 for (i = 0; i < uris_len; i++)
55 if (!g_bookmark_file_has_item (bookmark, uris[i]))
57 g_print ("URI/bookmark mismatch: bookmark for '%s' does not exist\n", uris[i]);
68 test_modify (GBookmarkFile *bookmark)
75 g_print ("\t=> check global title/description...");
76 g_bookmark_file_set_title (bookmark, NULL, "a file");
77 g_bookmark_file_set_description (bookmark, NULL, "a bookmark file");
79 text = g_bookmark_file_get_title (bookmark, NULL, &error);
80 g_assert_no_error (error);
81 g_assert_cmpstr (text, ==, "a file");
84 text = g_bookmark_file_get_description (bookmark, NULL, &error);
85 g_assert_no_error (error);
86 g_assert_cmpstr (text, ==, "a bookmark file");
90 g_print ("\t=> check bookmark title/description...");
91 g_bookmark_file_set_title (bookmark, TEST_URI_0, "a title");
92 g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description");
94 text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error);
95 g_assert_no_error (error);
96 g_assert_cmpstr (text, ==, "a title");
100 g_print ("\t=> check non existing bookmark...");
101 g_bookmark_file_get_description (bookmark, TEST_URI_1, &error);
102 g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
103 g_clear_error (&error);
106 g_print ("\t=> check application...");
107 g_bookmark_file_set_mime_type (bookmark, TEST_URI_0, TEST_MIME);
108 g_bookmark_file_add_application (bookmark, TEST_URI_0,
111 g_assert (g_bookmark_file_has_application (bookmark, TEST_URI_0, TEST_APP_NAME, NULL) == TRUE);
112 g_bookmark_file_get_app_info (bookmark, TEST_URI_0, TEST_APP_NAME,
117 g_assert_no_error (error);
118 g_assert (count == 1);
119 g_assert (stamp == g_bookmark_file_get_modified (bookmark, TEST_URI_0, NULL));
122 g_bookmark_file_get_app_info (bookmark, TEST_URI_0, "fail",
127 g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED);
128 g_clear_error (&error);
131 g_print ("\t=> check groups...");
132 g_bookmark_file_add_group (bookmark, TEST_URI_1, "Test");
133 g_assert (g_bookmark_file_has_group (bookmark, TEST_URI_1, "Test", NULL) == TRUE);
134 g_assert (g_bookmark_file_has_group (bookmark, TEST_URI_1, "Fail", NULL) == FALSE);
137 g_print ("\t=> check remove...");
138 g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == TRUE);
139 g_assert_no_error (error);
140 g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == FALSE);
141 g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
142 g_clear_error (&error);
149 test_file (const gchar *filename)
151 GBookmarkFile *bookmark_file;
154 g_return_val_if_fail (filename != NULL, 1);
156 g_print ("checking GBookmarkFile...\n");
158 bookmark_file = g_bookmark_file_new ();
159 g_assert (bookmark_file != NULL);
161 success = test_load (bookmark_file, filename);
165 success = test_query (bookmark_file);
166 success = test_modify (bookmark_file);
169 g_bookmark_file_free (bookmark_file);
173 return (success == TRUE ? 0 : 1);
181 return test_file (argv[1]);
184 fprintf (stderr, "Usage: bookmarkfile-test <bookmarkfile>\n");