Branch data Line data Source code
1 : : /* GLib testing framework examples and tests
2 : : *
3 : : * Copyright (C) 2011 Red Hat, Inc.
4 : : *
5 : : * SPDX-License-Identifier: LGPL-2.1-or-later
6 : : *
7 : : * This library is free software; you can redistribute it and/or
8 : : * modify it under the terms of the GNU Lesser General Public
9 : : * License as published by the Free Software Foundation; either
10 : : * version 2.1 of the License, or (at your option) any later version.
11 : : *
12 : : * This library is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : : * Lesser General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU Lesser General
18 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 : : */
20 : :
21 : : #include <string.h>
22 : : #include <gio/gio.h>
23 : : #include <glibconfig.h>
24 : : #include "gconstructor.h"
25 : : #include "test_resources2.h"
26 : : #include "digit_test_resources.h"
27 : :
28 : : #ifdef _MSC_VER
29 : : # define MODULE_FILENAME_PREFIX ""
30 : : #else
31 : : # define MODULE_FILENAME_PREFIX "lib"
32 : : #endif
33 : :
34 : : static void
35 : 3 : test_resource (GResource *resource)
36 : : {
37 : 3 : GError *error = NULL;
38 : : gboolean found, success;
39 : : gsize size;
40 : : guint32 flags;
41 : : GBytes *data;
42 : : char **children;
43 : : GInputStream *in;
44 : : char buffer[128];
45 : 3 : const gchar *not_found_paths[] =
46 : : {
47 : : "/not/there",
48 : : "/",
49 : : "",
50 : : };
51 : : gsize i;
52 : :
53 [ + + ]: 12 : for (i = 0; i < G_N_ELEMENTS (not_found_paths); i++)
54 : : {
55 : 9 : found = g_resource_get_info (resource,
56 : 9 : not_found_paths[i],
57 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
58 : : &size, &flags, &error);
59 : 9 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
60 : 9 : g_clear_error (&error);
61 : 9 : g_assert_false (found);
62 : : }
63 : :
64 : 3 : found = g_resource_get_info (resource,
65 : : "/test1.txt",
66 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
67 : : &size, &flags, &error);
68 : 3 : g_assert_true (found);
69 : 3 : g_assert_no_error (error);
70 : 3 : g_assert_cmpint (size, ==, 6);
71 : 3 : g_assert_cmpuint (flags, ==, G_RESOURCE_FLAGS_COMPRESSED);
72 : :
73 : 3 : found = g_resource_get_info (resource,
74 : : "/empty.txt",
75 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
76 : : &size, &flags, &error);
77 : 3 : g_assert_true (found);
78 : 3 : g_assert_no_error (error);
79 : 3 : g_assert_cmpint (size, ==, 0);
80 : 3 : g_assert_cmpuint (flags, ==, G_RESOURCE_FLAGS_COMPRESSED);
81 : :
82 : 3 : found = g_resource_get_info (resource,
83 : : "/a_prefix/test2.txt",
84 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
85 : : &size, &flags, &error);
86 : 3 : g_assert_true (found);
87 : 3 : g_assert_no_error (error);
88 : 3 : g_assert_cmpint (size, ==, 6);
89 : 3 : g_assert_cmpuint (flags, ==, 0);
90 : :
91 : 3 : found = g_resource_get_info (resource,
92 : : "/a_prefix/test2-alias.txt",
93 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
94 : : &size, &flags, &error);
95 : 3 : g_assert_true (found);
96 : 3 : g_assert_no_error (error);
97 : 3 : g_assert_cmpint (size, ==, 6);
98 : 3 : g_assert_cmpuint (flags, ==, 0);
99 : :
100 [ + + ]: 12 : for (i = 0; i < G_N_ELEMENTS (not_found_paths); i++)
101 : : {
102 : 9 : data = g_resource_lookup_data (resource,
103 : 9 : not_found_paths[i],
104 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
105 : : &error);
106 : 9 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
107 : 9 : g_clear_error (&error);
108 : 9 : g_assert_null (data);
109 : : }
110 : :
111 : 3 : data = g_resource_lookup_data (resource,
112 : : "/test1.txt",
113 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
114 : : &error);
115 : 3 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
116 : 3 : g_assert_no_error (error);
117 : 3 : g_bytes_unref (data);
118 : :
119 : 3 : data = g_resource_lookup_data (resource,
120 : : "/empty.txt",
121 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
122 : : &error);
123 : 3 : g_assert_cmpuint (g_bytes_get_size (data), ==, 0);
124 : 3 : g_assert_no_error (error);
125 : 3 : g_bytes_unref (data);
126 : :
127 [ + + ]: 12 : for (i = 0; i < G_N_ELEMENTS (not_found_paths); i++)
128 : : {
129 : 18 : in = g_resource_open_stream (resource,
130 : 9 : not_found_paths[i],
131 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
132 : : &error);
133 : 9 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
134 : 9 : g_clear_error (&error);
135 : 9 : g_assert_null (in);
136 : : }
137 : :
138 : 3 : in = g_resource_open_stream (resource,
139 : : "/test1.txt",
140 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
141 : : &error);
142 : 3 : g_assert_nonnull (in);
143 : 3 : g_assert_no_error (error);
144 : :
145 : 3 : success = g_input_stream_read_all (in, buffer, sizeof (buffer) - 1,
146 : : &size,
147 : : NULL, &error);
148 : 3 : g_assert_true (success);
149 : 3 : g_assert_no_error (error);
150 : 3 : g_assert_cmpint (size, ==, 6);
151 : 3 : buffer[size] = 0;
152 : 3 : g_assert_cmpstr (buffer, ==, "test1\n");
153 : :
154 : 3 : g_input_stream_close (in, NULL, &error);
155 : 3 : g_assert_no_error (error);
156 : 3 : g_clear_object (&in);
157 : :
158 : 3 : in = g_resource_open_stream (resource,
159 : : "/empty.txt",
160 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
161 : : &error);
162 : 3 : g_assert_no_error (error);
163 : 3 : g_assert_nonnull (in);
164 : :
165 : 3 : success = g_input_stream_read_all (in, buffer, sizeof (buffer) - 1,
166 : : &size,
167 : : NULL, &error);
168 : 3 : g_assert_no_error (error);
169 : 3 : g_assert_true (success);
170 : 3 : g_assert_cmpint (size, ==, 0);
171 : :
172 : 3 : g_input_stream_close (in, NULL, &error);
173 : 3 : g_assert_no_error (error);
174 : 3 : g_clear_object (&in);
175 : :
176 : 3 : data = g_resource_lookup_data (resource,
177 : : "/a_prefix/test2.txt",
178 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
179 : : &error);
180 : 3 : g_assert_nonnull (data);
181 : 3 : g_assert_no_error (error);
182 : 3 : size = g_bytes_get_size (data);
183 : 3 : g_assert_cmpint (size, ==, 6);
184 : 3 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test2\n");
185 : 3 : g_bytes_unref (data);
186 : :
187 : 3 : data = g_resource_lookup_data (resource,
188 : : "/a_prefix/test2-alias.txt",
189 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
190 : : &error);
191 : 3 : g_assert_nonnull (data);
192 : 3 : g_assert_no_error (error);
193 : 3 : size = g_bytes_get_size (data);
194 : 3 : g_assert_cmpint (size, ==, 6);
195 : 3 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test2\n");
196 : 3 : g_bytes_unref (data);
197 : :
198 [ + + ]: 12 : for (i = 0; i < G_N_ELEMENTS (not_found_paths); i++)
199 : : {
200 [ + + ]: 9 : if (g_str_equal (not_found_paths[i], "/"))
201 : 3 : continue;
202 : :
203 : 6 : children = g_resource_enumerate_children (resource,
204 : 6 : not_found_paths[i],
205 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
206 : : &error);
207 : 6 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
208 : 6 : g_clear_error (&error);
209 : 6 : g_assert_null (children);
210 : : }
211 : :
212 : 3 : children = g_resource_enumerate_children (resource,
213 : : "/a_prefix",
214 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
215 : : &error);
216 : 3 : g_assert_nonnull (children);
217 : 3 : g_assert_no_error (error);
218 : 3 : g_assert_cmpint (g_strv_length (children), ==, 2);
219 : 3 : g_strfreev (children);
220 : :
221 : : /* Test the preferred lookup where we have a trailing slash. */
222 : 3 : children = g_resource_enumerate_children (resource,
223 : : "/a_prefix/",
224 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
225 : : &error);
226 : 3 : g_assert_nonnull (children);
227 : 3 : g_assert_no_error (error);
228 : 3 : g_assert_cmpint (g_strv_length (children), ==, 2);
229 : 3 : g_strfreev (children);
230 : :
231 : : /* test with a path > 256 and no trailing slash to test the
232 : : * slow path of resources where we allocate a modified path.
233 : : */
234 : 3 : children = g_resource_enumerate_children (resource,
235 : : "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
236 : : "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
237 : : "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
238 : : "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
239 : : "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
240 : : "/with/no/trailing/slash",
241 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
242 : : &error);
243 : 3 : g_assert_null (children);
244 : 3 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
245 : 3 : g_clear_error (&error);
246 : 3 : }
247 : :
248 : : static void
249 : 1 : test_resource_file (void)
250 : : {
251 : : GResource *resource;
252 : 1 : GError *error = NULL;
253 : :
254 : 1 : resource = g_resource_load ("not-there", &error);
255 : 1 : g_assert_null (resource);
256 : 1 : g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
257 : 1 : g_clear_error (&error);
258 : :
259 : 1 : resource = g_resource_load (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL), &error);
260 : 1 : g_assert_nonnull (resource);
261 : 1 : g_assert_no_error (error);
262 : :
263 : 1 : test_resource (resource);
264 : 1 : g_resource_unref (resource);
265 : 1 : }
266 : :
267 : : static void
268 : 1 : test_resource_file_path (void)
269 : : {
270 : : static const struct {
271 : : const gchar *input;
272 : : const gchar *expected;
273 : : } test_uris[] = {
274 : : { "resource://", "resource:///" },
275 : : { "resource:///", "resource:///" },
276 : : { "resource://////", "resource:///" },
277 : : { "resource:///../../../", "resource:///" },
278 : : { "resource:///../../..", "resource:///" },
279 : : { "resource://abc", "resource:///abc" },
280 : : { "resource:///abc/", "resource:///abc" },
281 : : { "resource:/a/b/../c/", "resource:///a/c" },
282 : : { "resource://../a/b/../c/../", "resource:///a" },
283 : : { "resource://a/b/cc//bb//a///", "resource:///a/b/cc/bb/a" },
284 : : { "resource://././././", "resource:///" },
285 : : { "resource://././././../", "resource:///" },
286 : : { "resource://a/b/c/d.png", "resource:///a/b/c/d.png" },
287 : : { "resource://a/b/c/..png", "resource:///a/b/c/..png" },
288 : : { "resource://a/b/c/./png", "resource:///a/b/c/png" },
289 : : };
290 : : guint i;
291 : :
292 [ + + ]: 16 : for (i = 0; i < G_N_ELEMENTS (test_uris); i++)
293 : : {
294 : : GFile *file;
295 : : gchar *uri;
296 : :
297 : 15 : file = g_file_new_for_uri (test_uris[i].input);
298 : 15 : g_assert_nonnull (file);
299 : :
300 : 15 : uri = g_file_get_uri (file);
301 : 15 : g_assert_nonnull (uri);
302 : :
303 : 15 : g_assert_cmpstr (uri, ==, test_uris[i].expected);
304 : :
305 : 15 : g_object_unref (file);
306 : 15 : g_free (uri);
307 : : }
308 : 1 : }
309 : :
310 : : static void
311 : 1 : test_resource_data (void)
312 : : {
313 : : GResource *resource;
314 : 1 : GError *error = NULL;
315 : : gboolean loaded_file;
316 : : char *content;
317 : : gsize content_size;
318 : : GBytes *data;
319 : :
320 : 1 : loaded_file = g_file_get_contents (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL),
321 : : &content, &content_size, NULL);
322 : 1 : g_assert_true (loaded_file);
323 : :
324 : 1 : data = g_bytes_new_take (content, content_size);
325 : 1 : resource = g_resource_new_from_data (data, &error);
326 : 1 : g_bytes_unref (data);
327 : 1 : g_assert_nonnull (resource);
328 : 1 : g_assert_no_error (error);
329 : :
330 : 1 : test_resource (resource);
331 : :
332 : 1 : g_resource_unref (resource);
333 : 1 : }
334 : :
335 : : static void
336 : 1 : test_resource_data_unaligned (void)
337 : : {
338 : : GResource *resource;
339 : 1 : GError *error = NULL;
340 : : gboolean loaded_file;
341 : : char *content, *content_copy;
342 : : gsize content_size;
343 : : GBytes *data;
344 : :
345 : 1 : loaded_file = g_file_get_contents (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL),
346 : : &content, &content_size, NULL);
347 : 1 : g_assert_true (loaded_file);
348 : :
349 : 1 : content_copy = g_new (char, content_size + 1);
350 : 1 : memcpy (content_copy + 1, content, content_size);
351 : :
352 : 1 : data = g_bytes_new_with_free_func (content_copy + 1, content_size,
353 : : (GDestroyNotify) g_free, content_copy);
354 : 1 : g_free (content);
355 : 1 : resource = g_resource_new_from_data (data, &error);
356 : 1 : g_bytes_unref (data);
357 : 1 : g_assert_nonnull (resource);
358 : 1 : g_assert_no_error (error);
359 : :
360 : 1 : test_resource (resource);
361 : :
362 : 1 : g_resource_unref (resource);
363 : 1 : }
364 : :
365 : : /* Test error handling for corrupt GResource files (specifically, a corrupt
366 : : * GVDB header). */
367 : : static void
368 : 1 : test_resource_data_corrupt (void)
369 : : {
370 : : /* A GVDB header is 6 guint32s, and requires a magic number in the first two
371 : : * guint32s. A set of zero bytes of a greater length is considered corrupt. */
372 : : static const guint8 data[sizeof (guint32) * 7] = { 0, };
373 : 1 : GBytes *bytes = NULL;
374 : 1 : GResource *resource = NULL;
375 : 1 : GError *local_error = NULL;
376 : :
377 : 1 : bytes = g_bytes_new_static (data, sizeof (data));
378 : 1 : resource = g_resource_new_from_data (bytes, &local_error);
379 : 1 : g_bytes_unref (bytes);
380 : 1 : g_assert_error (local_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_INTERNAL);
381 : 1 : g_assert_null (resource);
382 : :
383 : 1 : g_clear_error (&local_error);
384 : 1 : }
385 : :
386 : : /* Test handling for empty GResource files. They should also be treated as
387 : : * corrupt. */
388 : : static void
389 : 1 : test_resource_data_empty (void)
390 : : {
391 : 1 : GBytes *bytes = NULL;
392 : 1 : GResource *resource = NULL;
393 : 1 : GError *local_error = NULL;
394 : :
395 : 1 : bytes = g_bytes_new_static (NULL, 0);
396 : 1 : resource = g_resource_new_from_data (bytes, &local_error);
397 : 1 : g_bytes_unref (bytes);
398 : 1 : g_assert_error (local_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_INTERNAL);
399 : 1 : g_assert_null (resource);
400 : :
401 : 1 : g_clear_error (&local_error);
402 : 1 : }
403 : :
404 : : static void
405 : 1 : test_resource_registered (void)
406 : : {
407 : : GResource *resource;
408 : 1 : GError *error = NULL;
409 : : gboolean found, success;
410 : : gsize size;
411 : : guint32 flags;
412 : : GBytes *data;
413 : : char **children;
414 : : GInputStream *in;
415 : : char buffer[128];
416 : :
417 : 1 : resource = g_resource_load (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL), &error);
418 : 1 : g_assert_nonnull (resource);
419 : 1 : g_assert_no_error (error);
420 : :
421 : 1 : found = g_resources_get_info ("/test1.txt",
422 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
423 : : &size, &flags, &error);
424 : 1 : g_assert_false (found);
425 : 1 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
426 : 1 : g_clear_error (&error);
427 : :
428 : 1 : g_resources_register (resource);
429 : :
430 : 1 : found = g_resources_get_info ("/test1.txt",
431 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
432 : : &size, &flags, &error);
433 : 1 : g_assert_true (found);
434 : 1 : g_assert_no_error (error);
435 : 1 : g_assert_cmpint (size, ==, 6);
436 : 1 : g_assert_cmpint (flags, ==, G_RESOURCE_FLAGS_COMPRESSED);
437 : :
438 : 1 : found = g_resources_get_info ("/empty.txt",
439 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
440 : : &size, &flags, &error);
441 : 1 : g_assert_no_error (error);
442 : 1 : g_assert_true (found);
443 : 1 : g_assert_cmpint (size, ==, 0);
444 : 1 : g_assert_cmpint (flags, ==, G_RESOURCE_FLAGS_COMPRESSED);
445 : :
446 : 1 : found = g_resources_get_info ("/a_prefix/test2.txt",
447 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
448 : : &size, &flags, &error);
449 : 1 : g_assert_true (found);
450 : 1 : g_assert_no_error (error);
451 : 1 : g_assert_cmpint (size, ==, 6);
452 : 1 : g_assert_cmpint (flags, ==, 0);
453 : :
454 : 1 : found = g_resources_get_info ("/a_prefix/test2-alias.txt",
455 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
456 : : &size, &flags, &error);
457 : 1 : g_assert_true (found);
458 : 1 : g_assert_no_error (error);
459 : 1 : g_assert_cmpint (size, ==, 6);
460 : 1 : g_assert_cmpuint (flags, ==, 0);
461 : :
462 : 1 : data = g_resources_lookup_data ("/test1.txt",
463 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
464 : : &error);
465 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
466 : 1 : g_assert_no_error (error);
467 : 1 : g_bytes_unref (data);
468 : :
469 : 1 : in = g_resources_open_stream ("/test1.txt",
470 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
471 : : &error);
472 : 1 : g_assert_nonnull (in);
473 : 1 : g_assert_no_error (error);
474 : :
475 : 1 : success = g_input_stream_read_all (in, buffer, sizeof (buffer) - 1,
476 : : &size,
477 : : NULL, &error);
478 : 1 : g_assert_true (success);
479 : 1 : g_assert_no_error (error);
480 : 1 : g_assert_cmpint (size, ==, 6);
481 : 1 : buffer[size] = 0;
482 : 1 : g_assert_cmpstr (buffer, ==, "test1\n");
483 : :
484 : 1 : g_input_stream_close (in, NULL, &error);
485 : 1 : g_assert_no_error (error);
486 : 1 : g_clear_object (&in);
487 : :
488 : 1 : data = g_resources_lookup_data ("/empty.txt",
489 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
490 : : &error);
491 : 1 : g_assert_no_error (error);
492 : 1 : g_assert_cmpuint (g_bytes_get_size (data), ==, 0);
493 : 1 : g_bytes_unref (data);
494 : :
495 : 1 : in = g_resources_open_stream ("/empty.txt",
496 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
497 : : &error);
498 : 1 : g_assert_no_error (error);
499 : 1 : g_assert_nonnull (in);
500 : :
501 : 1 : success = g_input_stream_read_all (in, buffer, sizeof (buffer) - 1,
502 : : &size,
503 : : NULL, &error);
504 : 1 : g_assert_no_error (error);
505 : 1 : g_assert_true (success);
506 : 1 : g_assert_cmpint (size, ==, 0);
507 : :
508 : 1 : g_input_stream_close (in, NULL, &error);
509 : 1 : g_assert_no_error (error);
510 : 1 : g_clear_object (&in);
511 : :
512 : 1 : data = g_resources_lookup_data ("/a_prefix/test2.txt",
513 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
514 : : &error);
515 : 1 : g_assert_nonnull (data);
516 : 1 : g_assert_no_error (error);
517 : 1 : size = g_bytes_get_size (data);
518 : 1 : g_assert_cmpint (size, ==, 6);
519 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test2\n");
520 : 1 : g_bytes_unref (data);
521 : :
522 : 1 : data = g_resources_lookup_data ("/a_prefix/test2-alias.txt",
523 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
524 : : &error);
525 : 1 : g_assert_nonnull (data);
526 : 1 : g_assert_no_error (error);
527 : 1 : size = g_bytes_get_size (data);
528 : 1 : g_assert_cmpint (size, ==, 6);
529 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test2\n");
530 : 1 : g_bytes_unref (data);
531 : :
532 : 1 : children = g_resources_enumerate_children ("/not/here",
533 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
534 : : &error);
535 : 1 : g_assert_null (children);
536 : 1 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
537 : 1 : g_clear_error (&error);
538 : :
539 : 1 : children = g_resources_enumerate_children ("/a_prefix",
540 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
541 : : &error);
542 : 1 : g_assert_nonnull (children);
543 : 1 : g_assert_no_error (error);
544 : 1 : g_assert_cmpint (g_strv_length (children), ==, 2);
545 : 1 : g_strfreev (children);
546 : :
547 : 1 : g_resources_unregister (resource);
548 : 1 : g_resource_unref (resource);
549 : :
550 : 1 : found = g_resources_get_info ("/test1.txt",
551 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
552 : : &size, &flags, &error);
553 : 1 : g_assert_false (found);
554 : 1 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
555 : 1 : g_clear_error (&error);
556 : 1 : }
557 : :
558 : : static void
559 : 1 : test_resource_automatic (void)
560 : : {
561 : 1 : GError *error = NULL;
562 : : gboolean found;
563 : : gsize size;
564 : : guint32 flags;
565 : : GBytes *data;
566 : :
567 : 1 : found = g_resources_get_info ("/auto_loaded/test1.txt",
568 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
569 : : &size, &flags, &error);
570 : 1 : g_assert_true (found);
571 : 1 : g_assert_no_error (error);
572 : 1 : g_assert_cmpint (size, ==, 6);
573 : 1 : g_assert_cmpint (flags, ==, 0);
574 : :
575 : 1 : data = g_resources_lookup_data ("/auto_loaded/test1.txt",
576 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
577 : : &error);
578 : 1 : g_assert_nonnull (data);
579 : 1 : g_assert_no_error (error);
580 : 1 : size = g_bytes_get_size (data);
581 : 1 : g_assert_cmpint (size, ==, 6);
582 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
583 : 1 : g_bytes_unref (data);
584 : 1 : }
585 : :
586 : : static void
587 : 1 : test_resource_manual (void)
588 : : {
589 : 1 : GError *error = NULL;
590 : : gboolean found;
591 : : gsize size;
592 : : guint32 flags;
593 : : GBytes *data;
594 : :
595 : 1 : found = g_resources_get_info ("/manual_loaded/test1.txt",
596 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
597 : : &size, &flags, &error);
598 : 1 : g_assert_true (found);
599 : 1 : g_assert_no_error (error);
600 : 1 : g_assert_cmpint (size, ==, 6);
601 : 1 : g_assert_cmpuint (flags, ==, 0);
602 : :
603 : 1 : data = g_resources_lookup_data ("/manual_loaded/test1.txt",
604 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
605 : : &error);
606 : 1 : g_assert_nonnull (data);
607 : 1 : g_assert_no_error (error);
608 : 1 : size = g_bytes_get_size (data);
609 : 1 : g_assert_cmpint (size, ==, 6);
610 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
611 : 1 : g_bytes_unref (data);
612 : 1 : }
613 : :
614 : : static void
615 : 1 : test_resource_manual2 (void)
616 : : {
617 : : GResource *resource;
618 : : GBytes *data;
619 : : gsize size;
620 : 1 : GError *error = NULL;
621 : :
622 : 1 : resource = _g_test2_get_resource ();
623 : :
624 : 1 : data = g_resource_lookup_data (resource,
625 : : "/manual_loaded/test1.txt",
626 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
627 : : &error);
628 : 1 : g_assert_nonnull (data);
629 : 1 : g_assert_no_error (error);
630 : 1 : size = g_bytes_get_size (data);
631 : 1 : g_assert_cmpint (size, ==, 6);
632 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
633 : 1 : g_bytes_unref (data);
634 : :
635 : 1 : g_resource_unref (resource);
636 : 1 : }
637 : :
638 : : /* Test building resources with external data option,
639 : : * where data is linked in as binary instead of compiled in.
640 : : * Checks if resources are automatically registered and
641 : : * data can be found and read. */
642 : : static void
643 : 1 : test_resource_binary_linked (void)
644 : : {
645 : : #ifdef NO_EXTERNAL_DATA
646 : : g_test_skip ("--external-data cannot be tested: " NO_EXTERNAL_DATA);
647 : : return;
648 : : #else /* !NO_EXTERNAL_DATA */
649 : 1 : GError *error = NULL;
650 : : gboolean found;
651 : : gsize size;
652 : : guint32 flags;
653 : : GBytes *data;
654 : :
655 : 1 : found = g_resources_get_info ("/binary_linked/test1.txt",
656 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
657 : : &size, &flags, &error);
658 : 1 : g_assert_true (found);
659 : 1 : g_assert_no_error (error);
660 : 1 : g_assert_cmpint (size, ==, 6);
661 : 1 : g_assert_cmpuint (flags, ==, 0);
662 : :
663 : 1 : data = g_resources_lookup_data ("/binary_linked/test1.txt",
664 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
665 : : &error);
666 : 1 : g_assert_nonnull (data);
667 : 1 : g_assert_no_error (error);
668 : 1 : size = g_bytes_get_size (data);
669 : 1 : g_assert_cmpint (size, ==, 6);
670 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
671 : 1 : g_bytes_unref (data);
672 : : #endif /* !NO_EXTERNAL_DATA */
673 : 1 : }
674 : :
675 : : /* Test resource whose xml file starts with more than one digit
676 : : * and where no explicit c-name is given
677 : : * Checks if resources are successfully registered and
678 : : * data can be found and read. */
679 : : static void
680 : 1 : test_resource_digits (void)
681 : : {
682 : 1 : GError *error = NULL;
683 : : gboolean found;
684 : : gsize size;
685 : : guint32 flags;
686 : : GBytes *data;
687 : :
688 : 1 : found = g_resources_get_info ("/digit_test/test1.txt",
689 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
690 : : &size, &flags, &error);
691 : 1 : g_assert_true (found);
692 : 1 : g_assert_no_error (error);
693 : 1 : g_assert_cmpint (size, ==, 6);
694 : 1 : g_assert_cmpuint (flags, ==, 0);
695 : :
696 : 1 : data = g_resources_lookup_data ("/digit_test/test1.txt",
697 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
698 : : &error);
699 : 1 : g_assert_nonnull (data);
700 : 1 : g_assert_no_error (error);
701 : 1 : size = g_bytes_get_size (data);
702 : 1 : g_assert_cmpint (size, ==, 6);
703 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
704 : 1 : g_bytes_unref (data);
705 : 1 : }
706 : :
707 : : static void
708 : 1 : test_resource_module (void)
709 : : {
710 : : GIOModule *module;
711 : : gboolean found;
712 : : gsize size;
713 : : guint32 flags;
714 : : GBytes *data;
715 : : GError *error;
716 : :
717 : : #ifdef GLIB_STATIC_COMPILATION
718 : : /* The resource module is statically linked with a separate copy
719 : : * of a GLib so g_static_resource_init won't work as expected. */
720 : : g_test_skip ("Resource modules aren't supported in static builds.");
721 : : return;
722 : : #endif
723 : :
724 [ + - ]: 1 : if (g_module_supported ())
725 : : {
726 : 1 : module = g_io_module_new (g_test_get_filename (G_TEST_BUILT,
727 : : MODULE_FILENAME_PREFIX "resourceplugin",
728 : : NULL));
729 : :
730 : 1 : error = NULL;
731 : :
732 : 1 : found = g_resources_get_info ("/resourceplugin/test1.txt",
733 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
734 : : &size, &flags, &error);
735 : 1 : g_assert_false (found);
736 : 1 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
737 : 1 : g_clear_error (&error);
738 : :
739 : 1 : g_type_module_use (G_TYPE_MODULE (module));
740 : :
741 : 1 : found = g_resources_get_info ("/resourceplugin/test1.txt",
742 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
743 : : &size, &flags, &error);
744 : 1 : g_assert_true (found);
745 : 1 : g_assert_no_error (error);
746 : 1 : g_assert_cmpint (size, ==, 6);
747 : 1 : g_assert_cmpuint (flags, ==, 0);
748 : :
749 : 1 : data = g_resources_lookup_data ("/resourceplugin/test1.txt",
750 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
751 : : &error);
752 : 1 : g_assert_nonnull (data);
753 : 1 : g_assert_no_error (error);
754 : 1 : size = g_bytes_get_size (data);
755 : 1 : g_assert_cmpint (size, ==, 6);
756 : 1 : g_assert_cmpstr (g_bytes_get_data (data, NULL), ==, "test1\n");
757 : 1 : g_bytes_unref (data);
758 : :
759 : 1 : g_type_module_unuse (G_TYPE_MODULE (module));
760 : :
761 : 1 : found = g_resources_get_info ("/resourceplugin/test1.txt",
762 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
763 : : &size, &flags, &error);
764 : 1 : g_assert_false (found);
765 : 1 : g_assert_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
766 : 1 : g_clear_error (&error);
767 : :
768 : 1 : g_clear_object (&module);
769 : : }
770 : 1 : }
771 : :
772 : : static void
773 : 1 : test_uri_query_info (void)
774 : : {
775 : : GResource *resource;
776 : 1 : GError *error = NULL;
777 : : gboolean loaded_file;
778 : : char *content;
779 : : gsize content_size;
780 : : GBytes *data;
781 : : GFile *file;
782 : : GFileInfo *info;
783 : : const char *content_type;
784 : 1 : gchar *mime_type = NULL;
785 : : const char *fs_type;
786 : : gboolean readonly;
787 : :
788 : 1 : loaded_file = g_file_get_contents (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL),
789 : : &content, &content_size, NULL);
790 : 1 : g_assert_true (loaded_file);
791 : :
792 : 1 : data = g_bytes_new_take (content, content_size);
793 : 1 : resource = g_resource_new_from_data (data, &error);
794 : 1 : g_bytes_unref (data);
795 : 1 : g_assert_nonnull (resource);
796 : 1 : g_assert_no_error (error);
797 : :
798 : 1 : g_resources_register (resource);
799 : :
800 : 1 : file = g_file_new_for_uri ("resource://" "/a_prefix/test2-alias.txt");
801 : 1 : info = g_file_query_info (file, "*", 0, NULL, &error);
802 : 1 : g_assert_no_error (error);
803 : :
804 : 1 : content_type = g_file_info_get_content_type (info);
805 : 1 : g_assert_nonnull (content_type);
806 : 1 : mime_type = g_content_type_get_mime_type (content_type);
807 : 1 : g_assert_nonnull (mime_type);
808 : : #ifdef __APPLE__
809 : : g_assert_cmpstr (mime_type, ==, "text/*");
810 : : #else
811 : 1 : g_assert_cmpstr (mime_type, ==, "text/plain");
812 : : #endif
813 : 1 : g_free (mime_type);
814 : :
815 : 1 : g_object_unref (info);
816 : :
817 : 1 : info = g_file_query_filesystem_info (file, "*", NULL, &error);
818 : 1 : g_assert_no_error (error);
819 : :
820 : 1 : fs_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
821 : 1 : g_assert_cmpstr (fs_type, ==, "resource");
822 : 1 : readonly = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY);
823 : 1 : g_assert_true (readonly);
824 : :
825 : 1 : g_object_unref (info);
826 : :
827 : 1 : g_assert_cmpuint (g_file_hash (file), !=, 0);
828 : :
829 : 1 : g_object_unref (file);
830 : :
831 : 1 : g_resources_unregister (resource);
832 : 1 : g_resource_unref (resource);
833 : 1 : }
834 : :
835 : : static void
836 : 1 : test_uri_file (void)
837 : : {
838 : : GResource *resource;
839 : 1 : GError *error = NULL;
840 : : gboolean loaded_file;
841 : : char *content;
842 : : gsize content_size;
843 : : GBytes *data;
844 : : GFile *file;
845 : : GFileInfo *info;
846 : : gchar *name;
847 : : GFile *file2, *parent;
848 : : GFileEnumerator *enumerator;
849 : : gchar *scheme;
850 : : GFileAttributeInfoList *attrs;
851 : : GInputStream *stream;
852 : : gchar buf[1024];
853 : : gboolean ret;
854 : : gssize skipped;
855 : :
856 : 1 : loaded_file = g_file_get_contents (g_test_get_filename (G_TEST_BUILT, "test.gresource", NULL),
857 : : &content, &content_size, NULL);
858 : 1 : g_assert_true (loaded_file);
859 : :
860 : 1 : data = g_bytes_new_take (content, content_size);
861 : 1 : resource = g_resource_new_from_data (data, &error);
862 : 1 : g_bytes_unref (data);
863 : 1 : g_assert_nonnull (resource);
864 : 1 : g_assert_no_error (error);
865 : :
866 : 1 : g_resources_register (resource);
867 : :
868 : 1 : file = g_file_new_for_uri ("resource://" "/a_prefix/test2-alias.txt");
869 : :
870 : 1 : g_assert_null (g_file_get_path (file));
871 : :
872 : 1 : name = g_file_get_parse_name (file);
873 : 1 : g_assert_cmpstr (name, ==, "resource:///a_prefix/test2-alias.txt");
874 : 1 : g_free (name);
875 : :
876 : 1 : name = g_file_get_uri (file);
877 : 1 : g_assert_cmpstr (name, ==, "resource:///a_prefix/test2-alias.txt");
878 : 1 : g_free (name);
879 : :
880 : 1 : g_assert_false (g_file_is_native (file));
881 : 1 : g_assert_false (g_file_has_uri_scheme (file, "http"));
882 : 1 : g_assert_true (g_file_has_uri_scheme (file, "resource"));
883 : 1 : scheme = g_file_get_uri_scheme (file);
884 : 1 : g_assert_cmpstr (scheme, ==, "resource");
885 : 1 : g_free (scheme);
886 : :
887 : 1 : file2 = g_file_dup (file);
888 : 1 : g_assert_true (g_file_equal (file, file2));
889 : 1 : g_object_unref (file2);
890 : :
891 : 1 : parent = g_file_get_parent (file);
892 : 1 : enumerator = g_file_enumerate_children (parent, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
893 : 1 : g_assert_no_error (error);
894 : :
895 : 1 : file2 = g_file_get_child_for_display_name (parent, "test2-alias.txt", &error);
896 : 1 : g_assert_no_error (error);
897 : 1 : g_assert_true (g_file_equal (file, file2));
898 : 1 : g_object_unref (file2);
899 : :
900 : 1 : info = g_file_enumerator_next_file (enumerator, NULL, &error);
901 : 1 : g_assert_no_error (error);
902 : 1 : g_assert_nonnull (info);
903 : 1 : g_object_unref (info);
904 : :
905 : 1 : info = g_file_enumerator_next_file (enumerator, NULL, &error);
906 : 1 : g_assert_no_error (error);
907 : 1 : g_assert_nonnull (info);
908 : 1 : g_object_unref (info);
909 : :
910 : 1 : info = g_file_enumerator_next_file (enumerator, NULL, &error);
911 : 1 : g_assert_no_error (error);
912 : 1 : g_assert_null (info);
913 : :
914 : 1 : g_file_enumerator_close (enumerator, NULL, &error);
915 : 1 : g_assert_no_error (error);
916 : 1 : g_object_unref (enumerator);
917 : :
918 : 1 : file2 = g_file_new_for_uri ("resource://" "a_prefix/../a_prefix//test2-alias.txt");
919 : 1 : g_assert_true (g_file_equal (file, file2));
920 : :
921 : 1 : g_assert_true (g_file_has_prefix (file, parent));
922 : :
923 : 1 : name = g_file_get_relative_path (parent, file);
924 : 1 : g_assert_cmpstr (name, ==, "test2-alias.txt");
925 : 1 : g_free (name);
926 : :
927 : 1 : g_object_unref (parent);
928 : :
929 : 1 : attrs = g_file_query_settable_attributes (file, NULL, &error);
930 : 1 : g_assert_no_error (error);
931 : 1 : g_file_attribute_info_list_unref (attrs);
932 : :
933 : 1 : attrs = g_file_query_writable_namespaces (file, NULL, &error);
934 : 1 : g_assert_no_error (error);
935 : 1 : g_file_attribute_info_list_unref (attrs);
936 : :
937 : 1 : stream = G_INPUT_STREAM (g_file_read (file, NULL, &error));
938 : 1 : g_assert_no_error (error);
939 : 1 : g_assert_cmpint (g_seekable_tell (G_SEEKABLE (stream)), ==, 0);
940 : 1 : g_assert_true (g_seekable_can_seek (G_SEEKABLE (G_SEEKABLE (stream))));
941 : 1 : ret = g_seekable_seek (G_SEEKABLE (stream), 1, G_SEEK_SET, NULL, &error);
942 : 1 : g_assert_true (ret);
943 : 1 : g_assert_no_error (error);
944 : 1 : skipped = g_input_stream_skip (stream, 1, NULL, &error);
945 : 1 : g_assert_cmpint (skipped, ==, 1);
946 : 1 : g_assert_no_error (error);
947 : :
948 : 1 : memset (buf, 0, 1024);
949 : 1 : ret = g_input_stream_read_all (stream, &buf, 1024, NULL, NULL, &error);
950 : 1 : g_assert_true (ret);
951 : 1 : g_assert_no_error (error);
952 : 1 : g_assert_cmpstr (buf, ==, "st2\n");
953 : 1 : info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (stream),
954 : : G_FILE_ATTRIBUTE_STANDARD_SIZE,
955 : : NULL,
956 : : &error);
957 : 1 : g_assert_no_error (error);
958 : 1 : g_assert_nonnull (info);
959 : 1 : g_assert_cmpint (g_file_info_get_size (info), ==, 6);
960 : 1 : g_object_unref (info);
961 : :
962 : 1 : ret = g_input_stream_close (stream, NULL, &error);
963 : 1 : g_assert_true (ret);
964 : 1 : g_assert_no_error (error);
965 : 1 : g_object_unref (stream);
966 : :
967 : 1 : g_object_unref (file);
968 : 1 : g_object_unref (file2);
969 : :
970 : 1 : g_resources_unregister (resource);
971 : 1 : g_resource_unref (resource);
972 : 1 : }
973 : :
974 : : static void
975 : 1 : test_resource_64k (void)
976 : : {
977 : 1 : GError *error = NULL;
978 : : gboolean found;
979 : : gsize size;
980 : : guint32 flags;
981 : : GBytes *data;
982 : : gchar **tokens;
983 : :
984 : 1 : found = g_resources_get_info ("/big_prefix/gresource-big-test.txt",
985 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
986 : : &size, &flags, &error);
987 : 1 : g_assert_true (found);
988 : 1 : g_assert_no_error (error);
989 : :
990 : : /* Check size: 100 of all lower case letters + newline char +
991 : : * 100 all upper case letters + newline char +
992 : : * 100 of all numbers between 0 to 9 + newline char
993 : : * (for 12 iterations)
994 : : */
995 : :
996 : 1 : g_assert_cmpint (size, ==, (26 + 26 + 10) * (100 + 1) * 12);
997 : 1 : g_assert_cmpuint (flags, ==, 0);
998 : 1 : data = g_resources_lookup_data ("/big_prefix/gresource-big-test.txt",
999 : : G_RESOURCE_LOOKUP_FLAGS_NONE,
1000 : : &error);
1001 : 1 : g_assert_nonnull (data);
1002 : 1 : g_assert_no_error (error);
1003 : 1 : size = g_bytes_get_size (data);
1004 : :
1005 : 1 : g_assert_cmpint (size, ==, (26 + 26 + 10) * (100 + 1) * 12);
1006 : 1 : tokens = g_strsplit ((const gchar *) g_bytes_get_data (data, NULL), "\n", -1);
1007 : :
1008 : : /* check tokens[x] == entry at gresource-big-test.txt's line, where x = line - 1 */
1009 : 1 : g_assert_cmpstr (tokens[0], ==, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
1010 : 1 : g_assert_cmpstr (tokens[27], ==, "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
1011 : 1 : g_assert_cmpstr (tokens[183], ==, "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777");
1012 : 1 : g_assert_cmpstr (tokens[600], ==, "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ");
1013 : 1 : g_assert_cmpstr (tokens[742], ==, "8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888");
1014 : 1 : g_strfreev (tokens);
1015 : 1 : g_bytes_unref (data);
1016 : 1 : }
1017 : :
1018 : : /* Check that g_resources_get_info() respects G_RESOURCE_OVERLAYS */
1019 : : static void
1020 : 2 : test_overlay (void)
1021 : : {
1022 [ + + ]: 2 : if (g_test_subprocess ())
1023 : : {
1024 : 1 : GError *error = NULL;
1025 : : gboolean res;
1026 : : gsize size;
1027 : : char *overlay;
1028 : : char *path;
1029 : :
1030 : 1 : path = g_test_build_filename (G_TEST_DIST, "test1.overlay", NULL);
1031 : 1 : overlay = g_strconcat ("/auto_loaded/test1.txt=", path, NULL);
1032 : :
1033 : 1 : g_setenv ("G_RESOURCE_OVERLAYS", overlay, TRUE);
1034 : 1 : res = g_resources_get_info ("/auto_loaded/test1.txt", 0, &size, NULL, &error);
1035 : 1 : g_assert_true (res);
1036 : 1 : g_assert_no_error (error);
1037 : : /* test1.txt is 6 bytes, test1.overlay is 23 */
1038 : 1 : g_assert_cmpint (size, ==, 23);
1039 : :
1040 : 1 : g_free (overlay);
1041 : 1 : g_free (path);
1042 : :
1043 : 1 : return;
1044 : : }
1045 : 1 : g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDERR);
1046 : 1 : g_test_trap_assert_passed ();
1047 : : }
1048 : :
1049 : : int
1050 : 2 : main (int argc,
1051 : : char *argv[])
1052 : : {
1053 : 2 : g_test_init (&argc, &argv, NULL);
1054 : :
1055 : 2 : _g_test2_register_resource ();
1056 : 2 : _digit_test_register_resource ();
1057 : :
1058 : 2 : g_test_add_func ("/resource/file", test_resource_file);
1059 : 2 : g_test_add_func ("/resource/file-path", test_resource_file_path);
1060 : 2 : g_test_add_func ("/resource/data", test_resource_data);
1061 : 2 : g_test_add_func ("/resource/data_unaligned", test_resource_data_unaligned);
1062 : 2 : g_test_add_func ("/resource/data-corrupt", test_resource_data_corrupt);
1063 : 2 : g_test_add_func ("/resource/data-empty", test_resource_data_empty);
1064 : 2 : g_test_add_func ("/resource/registered", test_resource_registered);
1065 : 2 : g_test_add_func ("/resource/manual", test_resource_manual);
1066 : 2 : g_test_add_func ("/resource/manual2", test_resource_manual2);
1067 : : #ifdef G_HAS_CONSTRUCTORS
1068 : 2 : g_test_add_func ("/resource/automatic", test_resource_automatic);
1069 : : /* This only uses automatic resources too, so it tests the constructors and destructors */
1070 : 2 : g_test_add_func ("/resource/module", test_resource_module);
1071 : 2 : g_test_add_func ("/resource/binary-linked", test_resource_binary_linked);
1072 : : #endif
1073 : 2 : g_test_add_func ("/resource/uri/query-info", test_uri_query_info);
1074 : 2 : g_test_add_func ("/resource/uri/file", test_uri_file);
1075 : 2 : g_test_add_func ("/resource/64k", test_resource_64k);
1076 : 2 : g_test_add_func ("/resource/overlay", test_overlay);
1077 : 2 : g_test_add_func ("/resource/digits", test_resource_digits);
1078 : :
1079 : 2 : return g_test_run();
1080 : : }
|