1 /* GLib testing framework examples and tests
3 * Copyright (C) 2011 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "gconstructor.h"
22 #include "test_resources2.h"
25 test_resource (GResource
*resource
)
28 gboolean found
, success
;
35 const gchar
*not_found_paths
[] =
43 for (i
= 0; i
< G_N_ELEMENTS (not_found_paths
); i
++)
45 found
= g_resource_get_info (resource
,
47 G_RESOURCE_LOOKUP_FLAGS_NONE
,
48 &size
, &flags
, &error
);
49 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
50 g_clear_error (&error
);
51 g_assert_false (found
);
54 found
= g_resource_get_info (resource
,
56 G_RESOURCE_LOOKUP_FLAGS_NONE
,
57 &size
, &flags
, &error
);
59 g_assert_no_error (error
);
60 g_assert_cmpint (size
, ==, 6);
61 g_assert_cmpuint (flags
, ==, G_RESOURCE_FLAGS_COMPRESSED
);
63 found
= g_resource_get_info (resource
,
64 "/a_prefix/test2.txt",
65 G_RESOURCE_LOOKUP_FLAGS_NONE
,
66 &size
, &flags
, &error
);
68 g_assert_no_error (error
);
69 g_assert_cmpint (size
, ==, 6);
70 g_assert_cmpuint (flags
, ==, 0);
72 found
= g_resource_get_info (resource
,
73 "/a_prefix/test2-alias.txt",
74 G_RESOURCE_LOOKUP_FLAGS_NONE
,
75 &size
, &flags
, &error
);
77 g_assert_no_error (error
);
78 g_assert_cmpint (size
, ==, 6);
79 g_assert_cmpuint (flags
, ==, 0);
81 for (i
= 0; i
< G_N_ELEMENTS (not_found_paths
); i
++)
83 data
= g_resource_lookup_data (resource
,
85 G_RESOURCE_LOOKUP_FLAGS_NONE
,
87 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
88 g_clear_error (&error
);
92 data
= g_resource_lookup_data (resource
,
94 G_RESOURCE_LOOKUP_FLAGS_NONE
,
96 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test1\n");
97 g_assert_no_error (error
);
100 for (i
= 0; i
< G_N_ELEMENTS (not_found_paths
); i
++)
102 in
= g_resource_open_stream (resource
,
104 G_RESOURCE_LOOKUP_FLAGS_NONE
,
106 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
107 g_clear_error (&error
);
111 in
= g_resource_open_stream (resource
,
113 G_RESOURCE_LOOKUP_FLAGS_NONE
,
115 g_assert (in
!= NULL
);
116 g_assert_no_error (error
);
118 success
= g_input_stream_read_all (in
, buffer
, sizeof (buffer
) - 1,
122 g_assert_no_error (error
);
123 g_assert_cmpint (size
, ==, 6);
125 g_assert_cmpstr (buffer
, ==, "test1\n");
127 g_input_stream_close (in
, NULL
, &error
);
128 g_assert_no_error (error
);
129 g_clear_object (&in
);
131 data
= g_resource_lookup_data (resource
,
132 "/a_prefix/test2.txt",
133 G_RESOURCE_LOOKUP_FLAGS_NONE
,
135 g_assert (data
!= NULL
);
136 g_assert_no_error (error
);
137 size
= g_bytes_get_size (data
);
138 g_assert_cmpint (size
, ==, 6);
139 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test2\n");
140 g_bytes_unref (data
);
142 data
= g_resource_lookup_data (resource
,
143 "/a_prefix/test2-alias.txt",
144 G_RESOURCE_LOOKUP_FLAGS_NONE
,
146 g_assert (data
!= NULL
);
147 g_assert_no_error (error
);
148 size
= g_bytes_get_size (data
);
149 g_assert_cmpint (size
, ==, 6);
150 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test2\n");
151 g_bytes_unref (data
);
153 for (i
= 0; i
< G_N_ELEMENTS (not_found_paths
); i
++)
155 if (g_str_equal (not_found_paths
[i
], "/"))
158 children
= g_resource_enumerate_children (resource
,
160 G_RESOURCE_LOOKUP_FLAGS_NONE
,
162 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
163 g_clear_error (&error
);
164 g_assert_null (children
);
167 children
= g_resource_enumerate_children (resource
,
169 G_RESOURCE_LOOKUP_FLAGS_NONE
,
171 g_assert (children
!= NULL
);
172 g_assert_no_error (error
);
173 g_assert_cmpint (g_strv_length (children
), ==, 2);
174 g_strfreev (children
);
176 /* Test the preferred lookup where we have a trailing slash. */
177 children
= g_resource_enumerate_children (resource
,
179 G_RESOURCE_LOOKUP_FLAGS_NONE
,
181 g_assert (children
!= NULL
);
182 g_assert_no_error (error
);
183 g_assert_cmpint (g_strv_length (children
), ==, 2);
184 g_strfreev (children
);
186 /* test with a path > 256 and no trailing slash to test the
187 * slow path of resources where we allocate a modified path.
189 children
= g_resource_enumerate_children (resource
,
190 "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
191 "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
192 "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
193 "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
194 "/not/here/not/here/not/here/not/here/not/here/not/here/not/here"
195 "/with/no/trailing/slash",
196 G_RESOURCE_LOOKUP_FLAGS_NONE
,
198 g_assert (children
== NULL
);
199 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
200 g_clear_error (&error
);
204 test_resource_file (void)
207 GError
*error
= NULL
;
209 resource
= g_resource_load ("not-there", &error
);
210 g_assert (resource
== NULL
);
211 g_assert_error (error
, G_FILE_ERROR
, G_FILE_ERROR_NOENT
);
212 g_clear_error (&error
);
214 resource
= g_resource_load (g_test_get_filename (G_TEST_BUILT
, "test.gresource", NULL
), &error
);
215 g_assert (resource
!= NULL
);
216 g_assert_no_error (error
);
218 test_resource (resource
);
219 g_resource_unref (resource
);
223 test_resource_file_path (void)
225 static const struct {
227 const gchar
*expected
;
229 { "resource://", "resource:///" },
230 { "resource:///", "resource:///" },
231 { "resource://////", "resource:///" },
232 { "resource:///../../../", "resource:///" },
233 { "resource:///../../..", "resource:///" },
234 { "resource://abc", "resource:///abc" },
235 { "resource:///abc/", "resource:///abc" },
236 { "resource:/a/b/../c/", "resource:///a/c" },
237 { "resource://../a/b/../c/../", "resource:///a" },
238 { "resource://a/b/cc//bb//a///", "resource:///a/b/cc/bb/a" },
239 { "resource://././././", "resource:///" },
240 { "resource://././././../", "resource:///" },
241 { "resource://a/b/c/d.png", "resource:///a/b/c/d.png" },
242 { "resource://a/b/c/..png", "resource:///a/b/c/..png" },
243 { "resource://a/b/c/./png", "resource:///a/b/c/png" },
247 for (i
= 0; i
< G_N_ELEMENTS (test_uris
); i
++)
252 file
= g_file_new_for_uri (test_uris
[i
].input
);
253 g_assert (file
!= NULL
);
255 uri
= g_file_get_uri (file
);
256 g_assert (uri
!= NULL
);
258 g_assert_cmpstr (uri
, ==, test_uris
[i
].expected
);
260 g_object_unref (file
);
266 test_resource_data (void)
269 GError
*error
= NULL
;
270 gboolean loaded_file
;
275 loaded_file
= g_file_get_contents (g_test_get_filename (G_TEST_BUILT
, "test.gresource", NULL
),
276 &content
, &content_size
, NULL
);
277 g_assert (loaded_file
);
279 data
= g_bytes_new_take (content
, content_size
);
280 resource
= g_resource_new_from_data (data
, &error
);
281 g_bytes_unref (data
);
282 g_assert (resource
!= NULL
);
283 g_assert_no_error (error
);
285 test_resource (resource
);
287 g_resource_unref (resource
);
291 test_resource_data_unaligned (void)
294 GError
*error
= NULL
;
295 gboolean loaded_file
;
296 char *content
, *content_copy
;
300 loaded_file
= g_file_get_contents (g_test_get_filename (G_TEST_BUILT
, "test.gresource", NULL
),
301 &content
, &content_size
, NULL
);
302 g_assert (loaded_file
);
304 content_copy
= g_new (char, content_size
+ 1);
305 memcpy (content_copy
+ 1, content
, content_size
);
307 data
= g_bytes_new_with_free_func (content_copy
+ 1, content_size
,
308 (GDestroyNotify
) g_free
, content_copy
);
310 resource
= g_resource_new_from_data (data
, &error
);
311 g_bytes_unref (data
);
312 g_assert (resource
!= NULL
);
313 g_assert_no_error (error
);
315 test_resource (resource
);
317 g_resource_unref (resource
);
321 test_resource_registered (void)
324 GError
*error
= NULL
;
325 gboolean found
, success
;
333 resource
= g_resource_load (g_test_get_filename (G_TEST_BUILT
, "test.gresource", NULL
), &error
);
334 g_assert (resource
!= NULL
);
335 g_assert_no_error (error
);
337 found
= g_resources_get_info ("/test1.txt",
338 G_RESOURCE_LOOKUP_FLAGS_NONE
,
339 &size
, &flags
, &error
);
341 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
342 g_clear_error (&error
);
344 g_resources_register (resource
);
346 found
= g_resources_get_info ("/test1.txt",
347 G_RESOURCE_LOOKUP_FLAGS_NONE
,
348 &size
, &flags
, &error
);
350 g_assert_no_error (error
);
351 g_assert_cmpint (size
, ==, 6);
352 g_assert (flags
== (G_RESOURCE_FLAGS_COMPRESSED
));
354 found
= g_resources_get_info ("/a_prefix/test2.txt",
355 G_RESOURCE_LOOKUP_FLAGS_NONE
,
356 &size
, &flags
, &error
);
358 g_assert_no_error (error
);
359 g_assert_cmpint (size
, ==, 6);
360 g_assert_cmpint (flags
, ==, 0);
362 found
= g_resources_get_info ("/a_prefix/test2-alias.txt",
363 G_RESOURCE_LOOKUP_FLAGS_NONE
,
364 &size
, &flags
, &error
);
366 g_assert_no_error (error
);
367 g_assert_cmpint (size
, ==, 6);
368 g_assert_cmpuint (flags
, ==, 0);
370 data
= g_resources_lookup_data ("/test1.txt",
371 G_RESOURCE_LOOKUP_FLAGS_NONE
,
373 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test1\n");
374 g_assert_no_error (error
);
375 g_bytes_unref (data
);
377 in
= g_resources_open_stream ("/test1.txt",
378 G_RESOURCE_LOOKUP_FLAGS_NONE
,
380 g_assert (in
!= NULL
);
381 g_assert_no_error (error
);
383 success
= g_input_stream_read_all (in
, buffer
, sizeof (buffer
) - 1,
387 g_assert_no_error (error
);
388 g_assert_cmpint (size
, ==, 6);
390 g_assert_cmpstr (buffer
, ==, "test1\n");
392 g_input_stream_close (in
, NULL
, &error
);
393 g_assert_no_error (error
);
394 g_clear_object (&in
);
396 data
= g_resources_lookup_data ("/a_prefix/test2.txt",
397 G_RESOURCE_LOOKUP_FLAGS_NONE
,
399 g_assert (data
!= NULL
);
400 g_assert_no_error (error
);
401 size
= g_bytes_get_size (data
);
402 g_assert_cmpint (size
, ==, 6);
403 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test2\n");
404 g_bytes_unref (data
);
406 data
= g_resources_lookup_data ("/a_prefix/test2-alias.txt",
407 G_RESOURCE_LOOKUP_FLAGS_NONE
,
409 g_assert (data
!= NULL
);
410 g_assert_no_error (error
);
411 size
= g_bytes_get_size (data
);
412 g_assert_cmpint (size
, ==, 6);
413 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test2\n");
414 g_bytes_unref (data
);
416 children
= g_resources_enumerate_children ("/not/here",
417 G_RESOURCE_LOOKUP_FLAGS_NONE
,
419 g_assert (children
== NULL
);
420 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
421 g_clear_error (&error
);
423 children
= g_resources_enumerate_children ("/a_prefix",
424 G_RESOURCE_LOOKUP_FLAGS_NONE
,
426 g_assert (children
!= NULL
);
427 g_assert_no_error (error
);
428 g_assert_cmpint (g_strv_length (children
), ==, 2);
429 g_strfreev (children
);
431 g_resources_unregister (resource
);
432 g_resource_unref (resource
);
434 found
= g_resources_get_info ("/test1.txt",
435 G_RESOURCE_LOOKUP_FLAGS_NONE
,
436 &size
, &flags
, &error
);
438 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
439 g_clear_error (&error
);
443 test_resource_automatic (void)
445 GError
*error
= NULL
;
451 found
= g_resources_get_info ("/auto_loaded/test1.txt",
452 G_RESOURCE_LOOKUP_FLAGS_NONE
,
453 &size
, &flags
, &error
);
455 g_assert_no_error (error
);
456 g_assert_cmpint (size
, ==, 6);
457 g_assert_cmpint (flags
, ==, 0);
459 data
= g_resources_lookup_data ("/auto_loaded/test1.txt",
460 G_RESOURCE_LOOKUP_FLAGS_NONE
,
462 g_assert (data
!= NULL
);
463 g_assert_no_error (error
);
464 size
= g_bytes_get_size (data
);
465 g_assert_cmpint (size
, ==, 6);
466 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test1\n");
467 g_bytes_unref (data
);
471 test_resource_manual (void)
473 GError
*error
= NULL
;
479 found
= g_resources_get_info ("/manual_loaded/test1.txt",
480 G_RESOURCE_LOOKUP_FLAGS_NONE
,
481 &size
, &flags
, &error
);
483 g_assert_no_error (error
);
484 g_assert_cmpint (size
, ==, 6);
485 g_assert_cmpuint (flags
, ==, 0);
487 data
= g_resources_lookup_data ("/manual_loaded/test1.txt",
488 G_RESOURCE_LOOKUP_FLAGS_NONE
,
490 g_assert (data
!= NULL
);
491 g_assert_no_error (error
);
492 size
= g_bytes_get_size (data
);
493 g_assert_cmpint (size
, ==, 6);
494 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test1\n");
495 g_bytes_unref (data
);
499 test_resource_manual2 (void)
504 GError
*error
= NULL
;
506 resource
= _g_test2_get_resource ();
508 data
= g_resource_lookup_data (resource
,
509 "/manual_loaded/test1.txt",
510 G_RESOURCE_LOOKUP_FLAGS_NONE
,
512 g_assert (data
!= NULL
);
513 g_assert_no_error (error
);
514 size
= g_bytes_get_size (data
);
515 g_assert_cmpint (size
, ==, 6);
516 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test1\n");
517 g_bytes_unref (data
);
519 g_resource_unref (resource
);
523 test_resource_module (void)
532 if (g_module_supported ())
534 /* For in-tree, this will find the .la file and use it to get to the .so in .libs/ */
535 module
= g_io_module_new (g_test_get_filename (G_TEST_BUILT
, "libresourceplugin", NULL
));
539 found
= g_resources_get_info ("/resourceplugin/test1.txt",
540 G_RESOURCE_LOOKUP_FLAGS_NONE
,
541 &size
, &flags
, &error
);
543 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
544 g_clear_error (&error
);
546 g_type_module_use (G_TYPE_MODULE (module
));
548 found
= g_resources_get_info ("/resourceplugin/test1.txt",
549 G_RESOURCE_LOOKUP_FLAGS_NONE
,
550 &size
, &flags
, &error
);
552 g_assert_no_error (error
);
553 g_assert_cmpint (size
, ==, 6);
554 g_assert_cmpuint (flags
, ==, 0);
556 data
= g_resources_lookup_data ("/resourceplugin/test1.txt",
557 G_RESOURCE_LOOKUP_FLAGS_NONE
,
559 g_assert (data
!= NULL
);
560 g_assert_no_error (error
);
561 size
= g_bytes_get_size (data
);
562 g_assert_cmpint (size
, ==, 6);
563 g_assert_cmpstr (g_bytes_get_data (data
, NULL
), ==, "test1\n");
564 g_bytes_unref (data
);
566 g_type_module_unuse (G_TYPE_MODULE (module
));
568 found
= g_resources_get_info ("/resourceplugin/test1.txt",
569 G_RESOURCE_LOOKUP_FLAGS_NONE
,
570 &size
, &flags
, &error
);
572 g_assert_error (error
, G_RESOURCE_ERROR
, G_RESOURCE_ERROR_NOT_FOUND
);
573 g_clear_error (&error
);
578 test_uri_query_info (void)
581 GError
*error
= NULL
;
582 gboolean loaded_file
;
588 const char *content_type
;
589 gchar
*mime_type
= NULL
;
593 loaded_file
= g_file_get_contents (g_test_get_filename (G_TEST_BUILT
, "test.gresource", NULL
),
594 &content
, &content_size
, NULL
);
595 g_assert (loaded_file
);
597 data
= g_bytes_new_take (content
, content_size
);
598 resource
= g_resource_new_from_data (data
, &error
);
599 g_bytes_unref (data
);
600 g_assert (resource
!= NULL
);
601 g_assert_no_error (error
);
603 g_resources_register (resource
);
605 file
= g_file_new_for_uri ("resource://" "/a_prefix/test2-alias.txt");
607 info
= g_file_query_info (file
, "*", 0, NULL
, &error
);
608 g_assert_no_error (error
);
610 content_type
= g_file_info_get_content_type (info
);
611 g_assert (content_type
);
612 mime_type
= g_content_type_get_mime_type (content_type
);
613 g_assert (mime_type
);
614 g_assert_cmpstr (mime_type
, ==, "text/plain");
617 g_object_unref (info
);
619 info
= g_file_query_filesystem_info (file
, "*", NULL
, &error
);
620 g_assert_no_error (error
);
622 fs_type
= g_file_info_get_attribute_string (info
, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE
);
623 g_assert_cmpstr (fs_type
, ==, "resource");
624 readonly
= g_file_info_get_attribute_boolean (info
, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY
);
625 g_assert_true (readonly
);
627 g_object_unref (info
);
629 g_assert_cmpuint (g_file_hash (file
), !=, 0);
631 g_object_unref (file
);
633 g_resources_unregister (resource
);
634 g_resource_unref (resource
);
641 GError
*error
= NULL
;
642 gboolean loaded_file
;
649 GFile
*file2
, *parent
;
650 GFileEnumerator
*enumerator
;
652 GFileAttributeInfoList
*attrs
;
653 GInputStream
*stream
;
658 loaded_file
= g_file_get_contents (g_test_get_filename (G_TEST_BUILT
, "test.gresource", NULL
),
659 &content
, &content_size
, NULL
);
660 g_assert (loaded_file
);
662 data
= g_bytes_new_take (content
, content_size
);
663 resource
= g_resource_new_from_data (data
, &error
);
664 g_bytes_unref (data
);
665 g_assert (resource
!= NULL
);
666 g_assert_no_error (error
);
668 g_resources_register (resource
);
670 file
= g_file_new_for_uri ("resource://" "/a_prefix/test2-alias.txt");
672 g_assert (g_file_get_path (file
) == NULL
);
674 name
= g_file_get_parse_name (file
);
675 g_assert_cmpstr (name
, ==, "resource:///a_prefix/test2-alias.txt");
678 name
= g_file_get_uri (file
);
679 g_assert_cmpstr (name
, ==, "resource:///a_prefix/test2-alias.txt");
682 g_assert (!g_file_is_native (file
));
683 g_assert (!g_file_has_uri_scheme (file
, "http"));
684 g_assert (g_file_has_uri_scheme (file
, "resource"));
685 scheme
= g_file_get_uri_scheme (file
);
686 g_assert_cmpstr (scheme
, ==, "resource");
689 file2
= g_file_dup (file
);
690 g_assert (g_file_equal (file
, file2
));
691 g_object_unref (file2
);
693 parent
= g_file_get_parent (file
);
694 enumerator
= g_file_enumerate_children (parent
, G_FILE_ATTRIBUTE_STANDARD_NAME
, 0, NULL
, &error
);
695 g_assert_no_error (error
);
697 file2
= g_file_get_child_for_display_name (parent
, "test2-alias.txt", &error
);
698 g_assert_no_error (error
);
699 g_assert (g_file_equal (file
, file2
));
700 g_object_unref (file2
);
702 info
= g_file_enumerator_next_file (enumerator
, NULL
, &error
);
703 g_assert_no_error (error
);
704 g_assert (info
!= NULL
);
705 g_object_unref (info
);
707 info
= g_file_enumerator_next_file (enumerator
, NULL
, &error
);
708 g_assert_no_error (error
);
709 g_assert (info
!= NULL
);
710 g_object_unref (info
);
712 info
= g_file_enumerator_next_file (enumerator
, NULL
, &error
);
713 g_assert_no_error (error
);
714 g_assert (info
== NULL
);
716 g_file_enumerator_close (enumerator
, NULL
, &error
);
717 g_assert_no_error (error
);
718 g_object_unref (enumerator
);
720 file2
= g_file_new_for_uri ("resource://" "a_prefix/../a_prefix//test2-alias.txt");
721 g_assert (g_file_equal (file
, file2
));
723 g_assert (g_file_has_prefix (file
, parent
));
725 name
= g_file_get_relative_path (parent
, file
);
726 g_assert_cmpstr (name
, ==, "test2-alias.txt");
729 g_object_unref (parent
);
731 attrs
= g_file_query_settable_attributes (file
, NULL
, &error
);
732 g_assert_no_error (error
);
733 g_file_attribute_info_list_unref (attrs
);
735 attrs
= g_file_query_writable_namespaces (file
, NULL
, &error
);
736 g_assert_no_error (error
);
737 g_file_attribute_info_list_unref (attrs
);
739 stream
= G_INPUT_STREAM (g_file_read (file
, NULL
, &error
));
740 g_assert_no_error (error
);
741 g_assert_cmpint (g_seekable_tell (G_SEEKABLE (stream
)), ==, 0);
742 g_assert (g_seekable_can_seek (G_SEEKABLE (G_SEEKABLE (stream
))));
743 ret
= g_seekable_seek (G_SEEKABLE (stream
), 1, G_SEEK_SET
, NULL
, &error
);
745 g_assert_no_error (error
);
746 skipped
= g_input_stream_skip (stream
, 1, NULL
, &error
);
747 g_assert_cmpint (skipped
, ==, 1);
748 g_assert_no_error (error
);
750 memset (buf
, 0, 1024);
751 ret
= g_input_stream_read_all (stream
, &buf
, 1024, NULL
, NULL
, &error
);
753 g_assert_no_error (error
);
754 g_assert_cmpstr (buf
, ==, "st2\n");
755 info
= g_file_input_stream_query_info (G_FILE_INPUT_STREAM (stream
),
756 G_FILE_ATTRIBUTE_STANDARD_SIZE
,
759 g_assert_no_error (error
);
760 g_assert (info
!= NULL
);
761 g_assert_cmpint (g_file_info_get_size (info
), ==, 6);
762 g_object_unref (info
);
764 ret
= g_input_stream_close (stream
, NULL
, &error
);
766 g_assert_no_error (error
);
767 g_object_unref (stream
);
769 g_object_unref (file
);
770 g_object_unref (file2
);
772 g_resources_unregister (resource
);
773 g_resource_unref (resource
);
780 g_test_init (&argc
, &argv
, NULL
);
782 _g_test2_register_resource ();
784 g_test_add_func ("/resource/file", test_resource_file
);
785 g_test_add_func ("/resource/file-path", test_resource_file_path
);
786 g_test_add_func ("/resource/data", test_resource_data
);
787 g_test_add_func ("/resource/data_unaligned", test_resource_data_unaligned
);
788 g_test_add_func ("/resource/registered", test_resource_registered
);
789 g_test_add_func ("/resource/manual", test_resource_manual
);
790 g_test_add_func ("/resource/manual2", test_resource_manual2
);
791 #ifdef G_HAS_CONSTRUCTORS
792 g_test_add_func ("/resource/automatic", test_resource_automatic
);
793 /* This only uses automatic resources too, so it tests the constructors and destructors */
794 g_test_add_func ("/resource/module", test_resource_module
);
796 g_test_add_func ("/resource/uri/query-info", test_uri_query_info
);
797 g_test_add_func ("/resource/uri/file", test_uri_file
);