File: | testsuite/ctk/recentmanager.c |
Warning: | line 281, column 3 Value stored to 'n' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* CTK - The GIMP Toolkit |
2 | * ctkrecentmanager.c: a manager for the recently used resources |
3 | * |
4 | * Copyright (C) 2006 Emmanuele Bassi |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #include <glib/gstdio.h> |
21 | #include <ctk/ctk.h> |
22 | |
23 | const gchar *uri = "file:///tmp/testrecentchooser.txt"; |
24 | const gchar *uri2 = "file:///tmp/testrecentchooser2.txt"; |
25 | |
26 | static void |
27 | recent_manager_get_default (void) |
28 | { |
29 | CtkRecentManager *manager; |
30 | CtkRecentManager *manager2; |
31 | |
32 | manager = ctk_recent_manager_get_default (); |
33 | g_assert (manager != NULL)do { if (manager != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 33, ((const char*) (__func__ )), "manager != NULL"); } while (0); |
34 | |
35 | manager2 = ctk_recent_manager_get_default (); |
36 | g_assert (manager == manager2)do { if (manager == manager2) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 36, ((const char*) (__func__ )), "manager == manager2"); } while (0); |
37 | } |
38 | |
39 | static void |
40 | recent_manager_add (void) |
41 | { |
42 | CtkRecentManager *manager; |
43 | CtkRecentData *recent_data; |
44 | gboolean res; |
45 | |
46 | manager = ctk_recent_manager_get_default (); |
47 | |
48 | recent_data = g_slice_new0 (CtkRecentData)((CtkRecentData*) g_slice_alloc0 (sizeof (CtkRecentData))); |
49 | |
50 | G_GNUC_BEGIN_IGNORE_DEPRECATIONSclang diagnostic push
clang diagnostic ignored "-Wdeprecated-declarations" ; |
51 | |
52 | /* mime type is mandatory */ |
53 | recent_data->mime_type = NULL((void*)0); |
54 | recent_data->app_name = "testrecentchooser"; |
55 | recent_data->app_exec = "testrecentchooser %u"; |
56 | if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) |
57 | { |
58 | res = ctk_recent_manager_add_full (manager, |
59 | uri, |
60 | recent_data); |
61 | } |
62 | g_test_trap_assert_failed ()g_test_trap_assertions (((gchar*) 0), "recentmanager.c", 62, ( (const char*) (__func__)), 1, 0); |
63 | |
64 | /* app name is mandatory */ |
65 | recent_data->mime_type = "text/plain"; |
66 | recent_data->app_name = NULL((void*)0); |
67 | recent_data->app_exec = "testrecentchooser %u"; |
68 | if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) |
69 | { |
70 | res = ctk_recent_manager_add_full (manager, |
71 | uri, |
72 | recent_data); |
73 | } |
74 | g_test_trap_assert_failed ()g_test_trap_assertions (((gchar*) 0), "recentmanager.c", 74, ( (const char*) (__func__)), 1, 0); |
75 | |
76 | /* app exec is mandatory */ |
77 | recent_data->mime_type = "text/plain"; |
78 | recent_data->app_name = "testrecentchooser"; |
79 | recent_data->app_exec = NULL((void*)0); |
80 | if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) |
81 | { |
82 | res = ctk_recent_manager_add_full (manager, |
83 | uri, |
84 | recent_data); |
85 | } |
86 | g_test_trap_assert_failed ()g_test_trap_assertions (((gchar*) 0), "recentmanager.c", 86, ( (const char*) (__func__)), 1, 0); |
87 | |
88 | G_GNUC_END_IGNORE_DEPRECATIONSclang diagnostic pop ; |
89 | |
90 | recent_data->mime_type = "text/plain"; |
91 | recent_data->app_name = "testrecentchooser"; |
92 | recent_data->app_exec = "testrecentchooser %u"; |
93 | res = ctk_recent_manager_add_full (manager, |
94 | uri, |
95 | recent_data); |
96 | g_assert (res == TRUE)do { if (res == (!(0))) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 96, ((const char*) (__func__)), "res == TRUE" ); } while (0); |
97 | |
98 | g_slice_free (CtkRecentData, recent_data)do { if (1) g_slice_free1 (sizeof (CtkRecentData), (recent_data )); else (void) ((CtkRecentData*) 0 == (recent_data)); } while (0); |
99 | } |
100 | |
101 | typedef struct { |
102 | GMainLoop *main_loop; |
103 | gint counter; |
104 | } AddManyClosure; |
105 | |
106 | static void |
107 | check_bulk (CtkRecentManager *manager G_GNUC_UNUSED__attribute__ ((__unused__)), |
108 | gpointer data) |
109 | { |
110 | AddManyClosure *closure = data; |
111 | |
112 | if (g_test_verbose ()(g_test_config_vars->test_verbose)) |
113 | g_print (G_STRLOC"recentmanager.c" ":" "113" ": counter = %d\n", closure->counter); |
114 | |
115 | g_assert_cmpint (closure->counter, ==, 100)do { gint64 __n1 = (closure->counter), __n2 = (100); if (__n1 == __n2) ; else g_assertion_message_cmpint (((gchar*) 0), "recentmanager.c" , 115, ((const char*) (__func__)), "closure->counter" " " "==" " " "100", (guint64)__n1, "==", (guint64)__n2, 'i'); } while (0); |
116 | |
117 | if (g_main_loop_is_running (closure->main_loop)) |
118 | g_main_loop_quit (closure->main_loop); |
119 | } |
120 | |
121 | static void |
122 | recent_manager_add_many (void) |
123 | { |
124 | CtkRecentManager *manager = g_object_new (CTK_TYPE_RECENT_MANAGER(ctk_recent_manager_get_type ()), |
125 | "filename", "recently-used.xbel", |
126 | NULL((void*)0)); |
127 | AddManyClosure *closure = g_new (AddManyClosure, 1)((AddManyClosure *) g_malloc_n ((1), sizeof (AddManyClosure)) ); |
128 | CtkRecentData *data = g_slice_new0 (CtkRecentData)((CtkRecentData*) g_slice_alloc0 (sizeof (CtkRecentData))); |
129 | gint i; |
130 | |
131 | closure->main_loop = g_main_loop_new (NULL((void*)0), FALSE(0)); |
132 | closure->counter = 0; |
133 | |
134 | g_signal_connect (manager, "changed", G_CALLBACK (check_bulk), closure)g_signal_connect_data ((manager), ("changed"), (((GCallback) ( check_bulk))), (closure), ((void*)0), (GConnectFlags) 0); |
135 | |
136 | for (i = 0; i < 100; i++) |
137 | { |
138 | gchar *new_uri; |
139 | |
140 | data->mime_type = "text/plain"; |
141 | data->app_name = "testrecentchooser"; |
142 | data->app_exec = "testrecentchooser %u"; |
143 | |
144 | if (g_test_verbose ()(g_test_config_vars->test_verbose)) |
145 | g_print (G_STRLOC"recentmanager.c" ":" "145" ": adding item %d\n", i); |
146 | |
147 | new_uri = g_strdup_printf ("file:///doesnotexist-%d.txt", i); |
148 | ctk_recent_manager_add_full (manager, new_uri, data); |
149 | g_free (new_uri); |
150 | |
151 | closure->counter += 1; |
152 | } |
153 | |
154 | g_main_loop_run (closure->main_loop); |
155 | |
156 | g_main_loop_unref (closure->main_loop); |
157 | g_slice_free (CtkRecentData, data)do { if (1) g_slice_free1 (sizeof (CtkRecentData), (data)); else (void) ((CtkRecentData*) 0 == (data)); } while (0); |
158 | g_free (closure); |
159 | g_object_unref (manager); |
160 | |
161 | g_assert_cmpint (g_unlink ("recently-used.xbel"), ==, 0)do { gint64 __n1 = (g_unlink ("recently-used.xbel")), __n2 = ( 0); if (__n1 == __n2) ; else g_assertion_message_cmpint (((gchar *) 0), "recentmanager.c", 161, ((const char*) (__func__)), "g_unlink (\"recently-used.xbel\")" " " "==" " " "0", (guint64)__n1, "==", (guint64)__n2, 'i'); } while (0); |
162 | } |
163 | |
164 | static void |
165 | recent_manager_has_item (void) |
166 | { |
167 | CtkRecentManager *manager; |
168 | gboolean res; |
169 | |
170 | manager = ctk_recent_manager_get_default (); |
171 | |
172 | res = ctk_recent_manager_has_item (manager, "file:///tmp/testrecentdoesnotexist.txt"); |
173 | g_assert (res == FALSE)do { if (res == (0)) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 173, ((const char*) (__func__)), "res == FALSE" ); } while (0); |
174 | |
175 | res = ctk_recent_manager_has_item (manager, uri); |
176 | g_assert (res == TRUE)do { if (res == (!(0))) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 176, ((const char*) (__func__)), "res == TRUE" ); } while (0); |
177 | } |
178 | |
179 | static void |
180 | recent_manager_move_item (void) |
181 | { |
182 | CtkRecentManager *manager; |
183 | gboolean res; |
184 | GError *error; |
185 | |
186 | manager = ctk_recent_manager_get_default (); |
187 | |
188 | error = NULL((void*)0); |
189 | res = ctk_recent_manager_move_item (manager, |
190 | "file:///tmp/testrecentdoesnotexist.txt", |
191 | uri2, |
192 | &error); |
193 | g_assert (res == FALSE)do { if (res == (0)) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 193, ((const char*) (__func__)), "res == FALSE" ); } while (0); |
194 | g_assert (error != NULL)do { if (error != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 194, ((const char*) (__func__ )), "error != NULL"); } while (0); |
195 | g_assert (error->domain == CTK_RECENT_MANAGER_ERROR)do { if (error->domain == (ctk_recent_manager_error_quark ( ))) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c" , 195, ((const char*) (__func__)), "error->domain == CTK_RECENT_MANAGER_ERROR" ); } while (0); |
196 | g_assert (error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND)do { if (error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND ) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c" , 196, ((const char*) (__func__)), "error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND" ); } while (0); |
197 | g_error_free (error); |
198 | |
199 | error = NULL((void*)0); |
200 | res = ctk_recent_manager_move_item (manager, uri, uri2, &error); |
201 | g_assert (res == TRUE)do { if (res == (!(0))) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 201, ((const char*) (__func__)), "res == TRUE" ); } while (0); |
202 | g_assert (error == NULL)do { if (error == ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 202, ((const char*) (__func__ )), "error == NULL"); } while (0); |
203 | |
204 | res = ctk_recent_manager_has_item (manager, uri); |
205 | g_assert (res == FALSE)do { if (res == (0)) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 205, ((const char*) (__func__)), "res == FALSE" ); } while (0); |
206 | |
207 | res = ctk_recent_manager_has_item (manager, uri2); |
208 | g_assert (res == TRUE)do { if (res == (!(0))) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 208, ((const char*) (__func__)), "res == TRUE" ); } while (0); |
209 | } |
210 | |
211 | static void |
212 | recent_manager_lookup_item (void) |
213 | { |
214 | CtkRecentManager *manager; |
215 | CtkRecentInfo *info; |
216 | GError *error; |
217 | |
218 | manager = ctk_recent_manager_get_default (); |
219 | |
220 | error = NULL((void*)0); |
221 | info = ctk_recent_manager_lookup_item (manager, |
222 | "file:///tmp/testrecentdoesnotexist.txt", |
223 | &error); |
224 | g_assert (info == NULL)do { if (info == ((void*)0)) ; else g_assertion_message_expr ( ((gchar*) 0), "recentmanager.c", 224, ((const char*) (__func__ )), "info == NULL"); } while (0); |
225 | g_assert (error != NULL)do { if (error != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 225, ((const char*) (__func__ )), "error != NULL"); } while (0); |
226 | g_assert (error->domain == CTK_RECENT_MANAGER_ERROR)do { if (error->domain == (ctk_recent_manager_error_quark ( ))) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c" , 226, ((const char*) (__func__)), "error->domain == CTK_RECENT_MANAGER_ERROR" ); } while (0); |
227 | g_assert (error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND)do { if (error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND ) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c" , 227, ((const char*) (__func__)), "error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND" ); } while (0); |
228 | g_error_free (error); |
229 | |
230 | error = NULL((void*)0); |
231 | info = ctk_recent_manager_lookup_item (manager, uri2, &error); |
232 | g_assert (info != NULL)do { if (info != ((void*)0)) ; else g_assertion_message_expr ( ((gchar*) 0), "recentmanager.c", 232, ((const char*) (__func__ )), "info != NULL"); } while (0); |
233 | g_assert (error == NULL)do { if (error == ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 233, ((const char*) (__func__ )), "error == NULL"); } while (0); |
234 | |
235 | g_assert (ctk_recent_info_has_application (info, "testrecentchooser"))do { if (ctk_recent_info_has_application (info, "testrecentchooser" )) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c" , 235, ((const char*) (__func__)), "ctk_recent_info_has_application (info, \"testrecentchooser\")" ); } while (0); |
236 | |
237 | ctk_recent_info_unref (info); |
238 | } |
239 | |
240 | static void |
241 | recent_manager_remove_item (void) |
242 | { |
243 | CtkRecentManager *manager; |
244 | gboolean res; |
245 | GError *error; |
246 | |
247 | manager = ctk_recent_manager_get_default (); |
248 | |
249 | error = NULL((void*)0); |
250 | res = ctk_recent_manager_remove_item (manager, |
251 | "file:///tmp/testrecentdoesnotexist.txt", |
252 | &error); |
253 | g_assert (res == FALSE)do { if (res == (0)) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 253, ((const char*) (__func__)), "res == FALSE" ); } while (0); |
254 | g_assert (error != NULL)do { if (error != ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 254, ((const char*) (__func__ )), "error != NULL"); } while (0); |
255 | g_assert (error->domain == CTK_RECENT_MANAGER_ERROR)do { if (error->domain == (ctk_recent_manager_error_quark ( ))) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c" , 255, ((const char*) (__func__)), "error->domain == CTK_RECENT_MANAGER_ERROR" ); } while (0); |
256 | g_assert (error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND)do { if (error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND ) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c" , 256, ((const char*) (__func__)), "error->code == CTK_RECENT_MANAGER_ERROR_NOT_FOUND" ); } while (0); |
257 | g_error_free (error); |
258 | |
259 | /* remove an item that's actually there */ |
260 | error = NULL((void*)0); |
261 | res = ctk_recent_manager_remove_item (manager, uri2, &error); |
262 | g_assert (res == TRUE)do { if (res == (!(0))) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 262, ((const char*) (__func__)), "res == TRUE" ); } while (0); |
263 | g_assert (error == NULL)do { if (error == ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 263, ((const char*) (__func__ )), "error == NULL"); } while (0); |
264 | |
265 | res = ctk_recent_manager_has_item (manager, uri2); |
266 | g_assert (res == FALSE)do { if (res == (0)) ; else g_assertion_message_expr (((gchar *) 0), "recentmanager.c", 266, ((const char*) (__func__)), "res == FALSE" ); } while (0); |
267 | } |
268 | |
269 | static void |
270 | recent_manager_purge (void) |
271 | { |
272 | CtkRecentManager *manager; |
273 | CtkRecentData *recent_data; |
274 | gint n; |
275 | GError *error; |
276 | |
277 | manager = ctk_recent_manager_get_default (); |
278 | |
279 | /* purge, add 1, purge again and check that 1 item has been purged */ |
280 | error = NULL((void*)0); |
281 | n = ctk_recent_manager_purge_items (manager, &error); |
Value stored to 'n' is never read | |
282 | g_assert (error == NULL)do { if (error == ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 282, ((const char*) (__func__ )), "error == NULL"); } while (0); |
283 | |
284 | recent_data = g_slice_new0 (CtkRecentData)((CtkRecentData*) g_slice_alloc0 (sizeof (CtkRecentData))); |
285 | recent_data->mime_type = "text/plain"; |
286 | recent_data->app_name = "testrecentchooser"; |
287 | recent_data->app_exec = "testrecentchooser %u"; |
288 | ctk_recent_manager_add_full (manager, uri, recent_data); |
289 | g_slice_free (CtkRecentData, recent_data)do { if (1) g_slice_free1 (sizeof (CtkRecentData), (recent_data )); else (void) ((CtkRecentData*) 0 == (recent_data)); } while (0); |
290 | |
291 | error = NULL((void*)0); |
292 | n = ctk_recent_manager_purge_items (manager, &error); |
293 | g_assert (error == NULL)do { if (error == ((void*)0)) ; else g_assertion_message_expr (((gchar*) 0), "recentmanager.c", 293, ((const char*) (__func__ )), "error == NULL"); } while (0); |
294 | g_assert (n == 1)do { if (n == 1) ; else g_assertion_message_expr (((gchar*) 0 ), "recentmanager.c", 294, ((const char*) (__func__)), "n == 1" ); } while (0); |
295 | } |
296 | |
297 | int |
298 | main (int argc, |
299 | char **argv) |
300 | { |
301 | ctk_test_init (&argc, &argv, NULL((void*)0)); |
302 | |
303 | g_test_add_func ("/recent-manager/get-default", recent_manager_get_default); |
304 | g_test_add_func ("/recent-manager/add", recent_manager_add); |
305 | g_test_add_func ("/recent-manager/add-many", recent_manager_add_many); |
306 | g_test_add_func ("/recent-manager/has-item", recent_manager_has_item); |
307 | g_test_add_func ("/recent-manager/move-item", recent_manager_move_item); |
308 | g_test_add_func ("/recent-manager/lookup-item", recent_manager_lookup_item); |
309 | g_test_add_func ("/recent-manager/remove-item", recent_manager_remove_item); |
310 | g_test_add_func ("/recent-manager/purge", recent_manager_purge); |
311 | |
312 | return g_test_run (); |
313 | } |