1 /* GLib testing framework examples and tests
2 * Copyright (C) 2008 Red Hat, Inc.
3 * Authors: Tomas Bzatek <tbzatek@redhat.com>
5 * This work is provided "as is"; redistribution and modification
6 * in whole or in part, in any medium, physical or electronic is
7 * permitted without restriction.
9 * This work is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * In no event shall the authors or contributors be liable for any
14 * direct, indirect, incidental, special, exemplary, or consequential
15 * damages (including, but not limited to, procurement of substitute
16 * goods or services; loss of use, data, or profits; or business
17 * interruption) however caused and on any theory of liability, whether
18 * in contract, strict liability, or tort (including negligence or
19 * otherwise) arising in any way out of the use of this software, even
20 * if advised of the possibility of such damage.
23 #include <glib/glib.h>
28 #include <sys/types.h>
32 #define DEFAULT_TEST_DIR "testdir_live-g-file"
34 #define PATTERN_FILE_SIZE 0x10000
35 #define TEST_HANDLE_SPECIAL TRUE
37 enum StructureExtraFlags
39 TEST_DELETE_NORMAL
= 1 << 0,
40 TEST_DELETE_TRASH
= 1 << 1,
41 TEST_DELETE_NON_EMPTY
= 1 << 2,
42 TEST_DELETE_FAILURE
= 1 << 3,
43 TEST_NOT_EXISTS
= 1 << 4,
44 TEST_ENUMERATE_FILE
= 1 << 5,
45 TEST_NO_ACCESS
= 1 << 6,
48 TEST_COPY_ERROR_RECURSE
= 1 << 9,
49 TEST_ALREADY_EXISTS
= 1 << 10,
50 TEST_TARGET_IS_FILE
= 1 << 11,
51 TEST_CREATE
= 1 << 12,
52 TEST_REPLACE
= 1 << 13,
53 TEST_APPEND
= 1 << 14,
55 TEST_OVERWRITE
= 1 << 16,
56 TEST_INVALID_SYMLINK
= 1 << 17,
57 TEST_HIDDEN
= 1 << 18,
58 TEST_DOT_HIDDEN
= 1 << 19,
66 GFileCreateFlags create_flags
;
68 gboolean handle_special
;
69 enum StructureExtraFlags extra_flags
;
72 #define TEST_DIR_NO_ACCESS "dir_no-access"
73 #define TEST_DIR_NO_WRITE "dir_no-write"
74 #define TEST_DIR_TARGET "dir-target"
75 #define TEST_NAME_NOT_EXISTS "not_exists"
76 #define TEST_TARGET_FILE "target-file"
79 static const struct StructureItem sample_struct
[] = {
80 /* filename link file_type create_flags mode | handle_special | extra_flags */
81 {"dir1", NULL
, G_FILE_TYPE_DIRECTORY
, G_FILE_CREATE_NONE
, 0, 0, TEST_DELETE_NORMAL
| TEST_DELETE_NON_EMPTY
| TEST_REPLACE
| TEST_OPEN
},
82 {"dir1/subdir", NULL
, G_FILE_TYPE_DIRECTORY
, G_FILE_CREATE_NONE
, 0, 0, TEST_COPY
| TEST_COPY_ERROR_RECURSE
| TEST_APPEND
},
83 {"dir2", NULL
, G_FILE_TYPE_DIRECTORY
, G_FILE_CREATE_NONE
, 0, 0, TEST_DELETE_NORMAL
| TEST_MOVE
| TEST_CREATE
},
84 {TEST_DIR_TARGET
, NULL
, G_FILE_TYPE_DIRECTORY
, G_FILE_CREATE_NONE
, 0, 0, TEST_COPY
| TEST_COPY_ERROR_RECURSE
},
85 {TEST_DIR_NO_ACCESS
, NULL
, G_FILE_TYPE_DIRECTORY
, G_FILE_CREATE_PRIVATE
, S_IRUSR
+ S_IWUSR
+ S_IRGRP
+ S_IWGRP
+ S_IROTH
+ S_IWOTH
, 0, TEST_NO_ACCESS
| TEST_OPEN
},
86 {TEST_DIR_NO_WRITE
, NULL
, G_FILE_TYPE_DIRECTORY
, G_FILE_CREATE_PRIVATE
, S_IRUSR
+ S_IXUSR
+ S_IRGRP
+ S_IXGRP
+ S_IROTH
+ S_IXOTH
, 0, 0},
87 {TEST_TARGET_FILE
, NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, 0, TEST_COPY
| TEST_OPEN
},
88 {"normal_file", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, 0, TEST_ENUMERATE_FILE
| TEST_CREATE
| TEST_OVERWRITE
},
89 {"normal_file-symlink", "normal_file", G_FILE_TYPE_SYMBOLIC_LINK
, G_FILE_CREATE_NONE
, 0, 0, TEST_ENUMERATE_FILE
| TEST_COPY
| TEST_OPEN
},
90 {"executable_file", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, S_IRWXU
+ S_IRWXG
+ S_IRWXO
, 0, TEST_DELETE_TRASH
| TEST_COPY
| TEST_OPEN
| TEST_OVERWRITE
| TEST_REPLACE
},
91 {"private_file", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_PRIVATE
, 0, 0, TEST_COPY
| TEST_OPEN
| TEST_OVERWRITE
| TEST_APPEND
},
92 {"normal_file2", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, 0, TEST_COPY
| TEST_OVERWRITE
| TEST_REPLACE
},
93 {"readonly_file", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, S_IRUSR
+ S_IRGRP
+ S_IROTH
, 0, TEST_DELETE_NORMAL
| TEST_OPEN
},
94 {"UTF_pr\xcc\x8ci\xcc\x81lis\xcc\x8c z",
95 NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, 0, TEST_COPY
| TEST_CREATE
| TEST_OPEN
| TEST_OVERWRITE
},
96 {"dir_pr\xcc\x8ci\xcc\x81lis\xcc\x8c z",
97 NULL
, G_FILE_TYPE_DIRECTORY
, G_FILE_CREATE_NONE
, 0, 0, TEST_DELETE_NORMAL
| TEST_CREATE
},
98 {"pattern_file", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, TEST_HANDLE_SPECIAL
, TEST_COPY
| TEST_OPEN
| TEST_APPEND
},
99 {TEST_NAME_NOT_EXISTS
, NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, TEST_HANDLE_SPECIAL
, TEST_DELETE_NORMAL
| TEST_NOT_EXISTS
| TEST_COPY
| TEST_OPEN
},
100 {TEST_NAME_NOT_EXISTS
, NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, TEST_HANDLE_SPECIAL
, TEST_DELETE_TRASH
| TEST_NOT_EXISTS
| TEST_MOVE
},
101 {"not_exists2", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, TEST_HANDLE_SPECIAL
, TEST_NOT_EXISTS
| TEST_CREATE
},
102 {"not_exists3", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, TEST_HANDLE_SPECIAL
, TEST_NOT_EXISTS
| TEST_REPLACE
},
103 {"not_exists4", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, TEST_HANDLE_SPECIAL
, TEST_NOT_EXISTS
| TEST_APPEND
},
104 {"dir_no-execute/file", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, TEST_HANDLE_SPECIAL
, TEST_DELETE_NORMAL
| TEST_DELETE_FAILURE
| TEST_NOT_EXISTS
| TEST_OPEN
},
105 {"lost_symlink", "nowhere", G_FILE_TYPE_SYMBOLIC_LINK
, G_FILE_CREATE_NONE
, 0, 0, TEST_COPY
| TEST_DELETE_NORMAL
| TEST_OPEN
| TEST_INVALID_SYMLINK
},
106 {"dir_hidden", NULL
, G_FILE_TYPE_DIRECTORY
, G_FILE_CREATE_NONE
, 0, 0, 0},
107 {"dir_hidden/.hidden", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, TEST_HANDLE_SPECIAL
, 0},
108 {"dir_hidden/.a-hidden-file", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, 0, TEST_HIDDEN
},
109 {"dir_hidden/file-in-.hidden1", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, 0, TEST_HIDDEN
| TEST_DOT_HIDDEN
},
110 {"dir_hidden/file-in-.hidden2", NULL
, G_FILE_TYPE_REGULAR
, G_FILE_CREATE_NONE
, 0, 0, TEST_HIDDEN
| TEST_DOT_HIDDEN
},
113 static gboolean test_suite
;
114 static gboolean write_test
;
115 static gboolean verbose
;
116 static gboolean posix_compat
;
118 #ifdef G_HAVE_ISO_VARARGS
119 #define log(...) if (verbose) g_printerr (__VA_ARGS__)
120 #elif defined(G_HAVE_GNUC_VARARGS)
121 #define log(msg...) if (verbose) g_printerr (msg)
122 #else /* no varargs macros */
123 static void log (const g_char
*format
, ...)
126 va_start (args
, format
);
127 if (verbose
) g_printerr (format
, args
);
133 create_empty_file (GFile
* parent
, const char *filename
,
134 GFileCreateFlags create_flags
)
138 GFileOutputStream
*outs
;
140 child
= g_file_get_child (parent
, filename
);
141 g_assert (child
!= NULL
);
144 outs
= g_file_replace (child
, NULL
, FALSE
, create_flags
, NULL
, &error
);
145 g_assert_no_error (error
);
146 g_assert (outs
!= NULL
);
148 g_output_stream_close (G_OUTPUT_STREAM (outs
), NULL
, &error
);
149 g_object_unref (outs
);
154 create_empty_dir (GFile
* parent
, const char *filename
)
160 child
= g_file_get_child (parent
, filename
);
161 g_assert (child
!= NULL
);
163 res
= g_file_make_directory (child
, NULL
, &error
);
164 g_assert_cmpint (res
, ==, TRUE
);
165 g_assert_no_error (error
);
170 create_symlink (GFile
* parent
, const char *filename
, const char *points_to
)
176 child
= g_file_get_child (parent
, filename
);
177 g_assert (child
!= NULL
);
179 res
= g_file_make_symbolic_link (child
, points_to
, NULL
, &error
);
180 g_assert_cmpint (res
, ==, TRUE
);
181 g_assert_no_error (error
);
186 test_create_structure (gconstpointer test_data
)
192 GFileOutputStream
*outs
;
193 GDataOutputStream
*outds
;
195 struct StructureItem item
;
197 g_assert (test_data
!= NULL
);
198 log ("\n Going to create testing structure in '%s'...\n",
201 root
= g_file_new_for_commandline_arg ((char *) test_data
);
202 g_assert (root
!= NULL
);
204 /* create root directory */
205 res
= g_file_make_directory (root
, NULL
, NULL
);
206 /* don't care about errors here */
208 /* create any other items */
209 for (i
= 0; i
< G_N_ELEMENTS (sample_struct
); i
++)
211 item
= sample_struct
[i
];
212 if ((item
.handle_special
)
214 && (item
.file_type
== G_FILE_TYPE_SYMBOLIC_LINK
)))
218 switch (item
.file_type
)
220 case G_FILE_TYPE_REGULAR
:
221 log (" Creating file '%s'...\n", item
.filename
);
222 child
= create_empty_file (root
, item
.filename
, item
.create_flags
);
224 case G_FILE_TYPE_DIRECTORY
:
225 log (" Creating directory '%s'...\n", item
.filename
);
226 child
= create_empty_dir (root
, item
.filename
);
228 case G_FILE_TYPE_SYMBOLIC_LINK
:
229 log (" Creating symlink '%s' --> '%s'...\n", item
.filename
,
231 child
= create_symlink (root
, item
.filename
, item
.link_to
);
233 case G_FILE_TYPE_UNKNOWN
:
234 case G_FILE_TYPE_SPECIAL
:
235 case G_FILE_TYPE_SHORTCUT
:
236 case G_FILE_TYPE_MOUNTABLE
:
240 g_assert (child
!= NULL
);
242 if ((item
.mode
> 0) && (posix_compat
))
246 g_file_set_attribute_uint32 (child
, G_FILE_ATTRIBUTE_UNIX_MODE
,
248 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
250 g_assert_cmpint (res
, ==, TRUE
);
251 g_assert_no_error (error
);
254 if ((item
.extra_flags
& TEST_DOT_HIDDEN
) == TEST_DOT_HIDDEN
)
256 gchar
*dir
, *path
, *basename
;
259 dir
= g_path_get_dirname (item
.filename
);
260 basename
= g_path_get_basename (item
.filename
);
261 path
= g_build_filename (test_data
, dir
, ".hidden", NULL
);
263 f
= fopen (path
, "a");
264 fprintf (f
, "%s\n", basename
);
272 g_object_unref (child
);
275 /* create a pattern file */
276 log (" Creating pattern file...");
277 child
= g_file_get_child (root
, "pattern_file");
278 g_assert (child
!= NULL
);
282 g_file_replace (child
, NULL
, FALSE
, G_FILE_CREATE_NONE
, NULL
, &error
);
283 g_assert_no_error (error
);
285 g_assert (outs
!= NULL
);
286 outds
= g_data_output_stream_new (G_OUTPUT_STREAM (outs
));
287 g_assert (outds
!= NULL
);
288 for (i
= 0; i
< PATTERN_FILE_SIZE
; i
++)
291 res
= g_data_output_stream_put_byte (outds
, i
% 256, NULL
, &error
);
292 g_assert_no_error (error
);
295 res
= g_output_stream_close (G_OUTPUT_STREAM (outs
), NULL
, &error
);
296 g_assert_no_error (error
);
297 g_object_unref (outds
);
298 g_object_unref (outs
);
299 g_object_unref (child
);
302 g_object_unref (root
);
306 file_exists (GFile
* parent
, const char *filename
, gboolean
* result
)
314 child
= g_file_get_child (parent
, filename
);
315 g_assert (child
!= NULL
);
316 res
= g_file_query_exists (child
, NULL
);
324 test_attributes (struct StructureItem item
, GFileInfo
* info
)
328 const char *name
, *display_name
, *edit_name
, *copy_name
, *symlink_target
;
333 gboolean can_read
, can_write
;
336 has_attr
= g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_TYPE
);
337 g_assert_cmpint (has_attr
, ==, TRUE
);
338 ftype
= g_file_info_get_file_type (info
);
339 g_assert_cmpint (ftype
, !=, G_FILE_TYPE_UNKNOWN
);
340 g_assert_cmpint (ftype
, ==, item
.file_type
);
343 if ((item
.mode
> 0) && (posix_compat
))
346 g_file_info_get_attribute_uint32 (info
,
347 G_FILE_ATTRIBUTE_UNIX_MODE
) & 0xFFF;
348 g_assert_cmpint (mode
, ==, item
.mode
);
351 /* access::can-read */
352 if (item
.file_type
!= G_FILE_TYPE_SYMBOLIC_LINK
)
355 g_file_info_get_attribute_boolean (info
,
356 G_FILE_ATTRIBUTE_ACCESS_CAN_READ
);
357 g_assert_cmpint (can_read
, ==, TRUE
);
360 /* access::can-write */
361 if ((write_test
) && ((item
.extra_flags
& TEST_OVERWRITE
) == TEST_OVERWRITE
))
364 g_file_info_get_attribute_boolean (info
,
365 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE
);
366 g_assert_cmpint (can_write
, ==, TRUE
);
370 name
= g_file_info_get_name (info
);
371 g_assert (name
!= NULL
);
373 /* standard::display-name */
374 display_name
= g_file_info_get_display_name (info
);
375 g_assert (display_name
!= NULL
);
376 utf8_valid
= g_utf8_validate (display_name
, -1, NULL
);
377 g_assert_cmpint (utf8_valid
, ==, TRUE
);
379 /* standard::edit-name */
380 edit_name
= g_file_info_get_edit_name (info
);
383 utf8_valid
= g_utf8_validate (edit_name
, -1, NULL
);
384 g_assert_cmpint (utf8_valid
, ==, TRUE
);
387 /* standard::copy-name */
389 g_file_info_get_attribute_string (info
,
390 G_FILE_ATTRIBUTE_STANDARD_COPY_NAME
);
393 utf8_valid
= g_utf8_validate (copy_name
, -1, NULL
);
394 g_assert_cmpint (utf8_valid
, ==, TRUE
);
397 /* standard::is-symlink */
400 is_symlink
= g_file_info_get_is_symlink (info
);
401 g_assert_cmpint (is_symlink
, ==,
402 item
.file_type
== G_FILE_TYPE_SYMBOLIC_LINK
);
405 /* standard::symlink-target */
406 if ((item
.file_type
== G_FILE_TYPE_SYMBOLIC_LINK
) && (posix_compat
))
408 symlink_target
= g_file_info_get_symlink_target (info
);
409 g_assert_cmpstr (symlink_target
, ==, item
.link_to
);
412 /* standard::is-hidden */
413 if ((item
.extra_flags
& TEST_HIDDEN
) == TEST_HIDDEN
)
416 g_file_info_get_attribute_boolean (info
,
417 G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN
);
418 g_assert_cmpint (is_hidden
, ==, TRUE
);
421 /* unix::is-mountpoint */
424 gboolean is_mountpoint
=
425 g_file_info_get_attribute_boolean (info
,
426 G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT
);
427 g_assert_false (is_mountpoint
);
432 test_initial_structure (gconstpointer test_data
)
438 GFileInputStream
*ins
;
443 gssize read
, total_read
;
444 struct StructureItem item
;
447 g_assert (test_data
!= NULL
);
448 log ("\n Testing sample structure in '%s'...\n", (char *) test_data
);
450 root
= g_file_new_for_commandline_arg ((char *) test_data
);
451 g_assert (root
!= NULL
);
452 res
= g_file_query_exists (root
, NULL
);
453 g_assert_cmpint (res
, ==, TRUE
);
455 /* test the structure */
456 for (i
= 0; i
< G_N_ELEMENTS (sample_struct
); i
++)
458 item
= sample_struct
[i
];
459 if (((!posix_compat
) && (item
.file_type
== G_FILE_TYPE_SYMBOLIC_LINK
))
460 || (item
.handle_special
))
463 log (" Testing file '%s'...\n", item
.filename
);
465 child
= file_exists (root
, item
.filename
, &res
);
466 g_assert (child
!= NULL
);
467 g_assert_cmpint (res
, ==, TRUE
);
471 g_file_query_info (child
, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
473 g_assert_no_error (error
);
474 g_assert (info
!= NULL
);
476 test_attributes (item
, info
);
478 g_object_unref (child
);
479 g_object_unref (info
);
482 /* read and test the pattern file */
483 log (" Testing pattern file...\n");
484 child
= file_exists (root
, "pattern_file", &res
);
485 g_assert (child
!= NULL
);
486 g_assert_cmpint (res
, ==, TRUE
);
490 g_file_query_info (child
, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
, NULL
,
492 g_assert_no_error (error
);
493 g_assert (info
!= NULL
);
494 size
= g_file_info_get_size (info
);
495 g_assert_cmpint (size
, ==, PATTERN_FILE_SIZE
);
496 g_object_unref (info
);
499 ins
= g_file_read (child
, NULL
, &error
);
500 g_assert (ins
!= NULL
);
501 g_assert_no_error (error
);
503 buffer
= g_malloc (PATTERN_FILE_SIZE
);
506 while (total_read
< PATTERN_FILE_SIZE
)
510 g_input_stream_read (G_INPUT_STREAM (ins
), buffer
+ total_read
,
511 PATTERN_FILE_SIZE
, NULL
, &error
);
512 g_assert_no_error (error
);
514 log (" read %"G_GSSIZE_FORMAT
" bytes, total = %"G_GSSIZE_FORMAT
" of %d.\n",
515 read
, total_read
, PATTERN_FILE_SIZE
);
517 g_assert_cmpint (total_read
, ==, PATTERN_FILE_SIZE
);
520 res
= g_input_stream_close (G_INPUT_STREAM (ins
), NULL
, &error
);
521 g_assert_no_error (error
);
522 g_assert_cmpint (res
, ==, TRUE
);
524 for (i
= 0; i
< PATTERN_FILE_SIZE
; i
++)
525 g_assert_cmpint (*(buffer
+ i
), ==, i
% 256);
527 g_object_unref (ins
);
528 g_object_unref (child
);
530 g_object_unref (root
);
534 traverse_recurse_dirs (GFile
* parent
, GFile
* root
)
538 GFileEnumerator
*enumerator
;
545 g_assert (root
!= NULL
);
549 g_file_enumerate_children (parent
, "*",
550 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
, NULL
,
552 g_assert (enumerator
!= NULL
);
553 g_assert_no_error (error
);
555 g_assert (g_file_enumerator_get_container (enumerator
) == parent
);
558 info
= g_file_enumerator_next_file (enumerator
, NULL
, &error
);
559 while ((info
) && (!error
))
561 descend
= g_file_enumerator_get_child (enumerator
, info
);
562 g_assert (descend
!= NULL
);
563 relative_path
= g_file_get_relative_path (root
, descend
);
564 g_assert (relative_path
!= NULL
);
567 for (i
= 0; i
< G_N_ELEMENTS (sample_struct
); i
++)
569 if (strcmp (sample_struct
[i
].filename
, relative_path
) == 0)
571 /* test the attributes again */
572 test_attributes (sample_struct
[i
], info
);
578 g_assert_cmpint (found
, ==, TRUE
);
580 log (" Found file %s, relative to root: %s\n",
581 g_file_info_get_display_name (info
), relative_path
);
583 if (g_file_info_get_file_type (info
) == G_FILE_TYPE_DIRECTORY
)
584 traverse_recurse_dirs (descend
, root
);
586 g_object_unref (descend
);
588 g_object_unref (info
);
589 g_free (relative_path
);
591 info
= g_file_enumerator_next_file (enumerator
, NULL
, &error
);
593 g_assert_no_error (error
);
596 res
= g_file_enumerator_close (enumerator
, NULL
, &error
);
597 g_assert_cmpint (res
, ==, TRUE
);
598 g_assert_no_error (error
);
599 g_assert (g_file_enumerator_is_closed (enumerator
));
601 g_object_unref (enumerator
);
605 test_traverse_structure (gconstpointer test_data
)
610 g_assert (test_data
!= NULL
);
611 log ("\n Traversing through the sample structure in '%s'...\n",
614 root
= g_file_new_for_commandline_arg ((char *) test_data
);
615 g_assert (root
!= NULL
);
616 res
= g_file_query_exists (root
, NULL
);
617 g_assert_cmpint (res
, ==, TRUE
);
619 traverse_recurse_dirs (root
, root
);
621 g_object_unref (root
);
628 test_enumerate (gconstpointer test_data
)
633 GFileEnumerator
*enumerator
;
636 struct StructureItem item
;
639 g_assert (test_data
!= NULL
);
640 log ("\n Test enumerate '%s'...\n", (char *) test_data
);
642 root
= g_file_new_for_commandline_arg ((char *) test_data
);
643 g_assert (root
!= NULL
);
644 res
= g_file_query_exists (root
, NULL
);
645 g_assert_cmpint (res
, ==, TRUE
);
648 for (i
= 0; i
< G_N_ELEMENTS (sample_struct
); i
++)
650 item
= sample_struct
[i
];
651 if ((!posix_compat
) && (item
.file_type
== G_FILE_TYPE_SYMBOLIC_LINK
))
654 if (((item
.extra_flags
& TEST_NOT_EXISTS
) == TEST_NOT_EXISTS
) ||
655 (((item
.extra_flags
& TEST_NO_ACCESS
) == TEST_NO_ACCESS
)
657 || ((item
.extra_flags
& TEST_ENUMERATE_FILE
) ==
658 TEST_ENUMERATE_FILE
))
660 log (" Testing file '%s'\n", item
.filename
);
661 child
= g_file_get_child (root
, item
.filename
);
662 g_assert (child
!= NULL
);
665 g_file_enumerate_children (child
, "*",
666 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
669 if ((item
.extra_flags
& TEST_NOT_EXISTS
) == TEST_NOT_EXISTS
)
671 g_assert (enumerator
== NULL
);
672 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_FOUND
);
674 if ((item
.extra_flags
& TEST_ENUMERATE_FILE
) == TEST_ENUMERATE_FILE
)
676 g_assert (enumerator
== NULL
);
677 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_DIRECTORY
);
679 if ((item
.extra_flags
& TEST_NO_ACCESS
) == TEST_NO_ACCESS
)
681 g_assert (enumerator
!= NULL
);
684 info
= g_file_enumerator_next_file (enumerator
, NULL
, &error
);
685 g_assert (info
== NULL
);
686 g_assert_no_error (error
);
687 /* no items should be found, no error should be logged */
691 g_error_free (error
);
696 res
= g_file_enumerator_close (enumerator
, NULL
, &error
);
697 g_assert_cmpint (res
, ==, TRUE
);
698 g_assert_no_error (error
);
700 g_object_unref (enumerator
);
702 g_object_unref (child
);
705 g_object_unref (root
);
709 do_copy_move (GFile
* root
, struct StructureItem item
, const char *target_dir
,
710 enum StructureExtraFlags extra_flags
)
712 GFile
*dst_dir
, *src_file
, *dst_file
;
716 log (" do_copy_move: '%s' --> '%s'\n", item
.filename
, target_dir
);
718 dst_dir
= g_file_get_child (root
, target_dir
);
719 g_assert (dst_dir
!= NULL
);
720 src_file
= g_file_get_child (root
, item
.filename
);
721 g_assert (src_file
!= NULL
);
722 dst_file
= g_file_get_child (dst_dir
, item
.filename
);
723 g_assert (dst_file
!= NULL
);
726 if ((item
.extra_flags
& TEST_COPY
) == TEST_COPY
)
728 g_file_copy (src_file
, dst_file
,
729 G_FILE_COPY_NOFOLLOW_SYMLINKS
|
731 TEST_OVERWRITE
) ? G_FILE_COPY_OVERWRITE
:
732 G_FILE_COPY_NONE
), NULL
, NULL
, NULL
, &error
);
735 g_file_move (src_file
, dst_file
, G_FILE_COPY_NOFOLLOW_SYMLINKS
, NULL
,
739 log (" res = %d, error code %d = %s\n", res
, error
->code
,
742 /* copying file/directory to itself (".") */
743 if (((item
.extra_flags
& TEST_NOT_EXISTS
) != TEST_NOT_EXISTS
) &&
744 (extra_flags
== TEST_ALREADY_EXISTS
))
746 g_assert_cmpint (res
, ==, FALSE
);
747 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_EXISTS
);
749 /* target file is a file, overwrite is not set */
750 else if (((item
.extra_flags
& TEST_NOT_EXISTS
) != TEST_NOT_EXISTS
) &&
751 (extra_flags
== TEST_TARGET_IS_FILE
))
753 g_assert_cmpint (res
, ==, FALSE
);
754 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_DIRECTORY
);
756 /* source file is directory */
757 else if ((item
.extra_flags
& TEST_COPY_ERROR_RECURSE
) ==
758 TEST_COPY_ERROR_RECURSE
)
760 g_assert_cmpint (res
, ==, FALSE
);
761 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_WOULD_RECURSE
);
763 /* source or target path doesn't exist */
764 else if (((item
.extra_flags
& TEST_NOT_EXISTS
) == TEST_NOT_EXISTS
) ||
765 (extra_flags
== TEST_NOT_EXISTS
))
767 g_assert_cmpint (res
, ==, FALSE
);
768 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_FOUND
);
770 /* source or target path permission denied */
771 else if (((item
.extra_flags
& TEST_NO_ACCESS
) == TEST_NO_ACCESS
) ||
772 (extra_flags
== TEST_NO_ACCESS
))
774 /* This works for root, see bug #552912 */
775 if (test_suite
&& getuid () == 0)
777 g_assert_cmpint (res
, ==, TRUE
);
778 g_assert_no_error (error
);
782 g_assert_cmpint (res
, ==, FALSE
);
783 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_PERMISSION_DENIED
);
786 /* no error should be found, all exceptions defined above */
789 g_assert_cmpint (res
, ==, TRUE
);
790 g_assert_no_error (error
);
794 g_error_free (error
);
797 g_object_unref (dst_dir
);
798 g_object_unref (src_file
);
799 g_object_unref (dst_file
);
803 test_copy_move (gconstpointer test_data
)
808 struct StructureItem item
;
812 g_assert (test_data
!= NULL
);
813 root
= g_file_new_for_commandline_arg ((char *) test_data
);
814 g_assert (root
!= NULL
);
815 res
= g_file_query_exists (root
, NULL
);
816 g_assert_cmpint (res
, ==, TRUE
);
819 for (i
= 0; i
< G_N_ELEMENTS (sample_struct
); i
++)
821 item
= sample_struct
[i
];
823 if ((!posix_compat
) && (item
.file_type
== G_FILE_TYPE_SYMBOLIC_LINK
))
826 if (((item
.extra_flags
& TEST_COPY
) == TEST_COPY
) ||
827 ((item
.extra_flags
& TEST_MOVE
) == TEST_MOVE
))
829 /* test copy/move to a directory, expecting no errors if source files exist */
830 do_copy_move (root
, item
, TEST_DIR_TARGET
, 0);
832 /* some files have been already moved so we can't count with them in the tests */
833 if ((item
.extra_flags
& TEST_COPY
) == TEST_COPY
)
835 /* test overwrite for flagged files */
836 if ((item
.extra_flags
& TEST_OVERWRITE
) == TEST_OVERWRITE
)
838 do_copy_move (root
, item
, TEST_DIR_TARGET
, TEST_OVERWRITE
);
840 /* source = target, should return G_IO_ERROR_EXISTS */
841 do_copy_move (root
, item
, ".", TEST_ALREADY_EXISTS
);
843 do_copy_move (root
, item
, TEST_TARGET_FILE
,
844 TEST_TARGET_IS_FILE
);
845 /* target path is invalid */
846 do_copy_move (root
, item
, TEST_NAME_NOT_EXISTS
,
849 /* tests on POSIX-compatible filesystems */
852 /* target directory is not accessible (no execute flag) */
853 do_copy_move (root
, item
, TEST_DIR_NO_ACCESS
,
855 /* target directory is readonly */
856 do_copy_move (root
, item
, TEST_DIR_NO_WRITE
,
862 g_object_unref (root
);
865 /* Test that G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT is TRUE for / and for another
866 * known mountpoint. The FALSE case is tested for many directories and files by
867 * test_initial_structure(), via test_attributes().
870 test_unix_is_mountpoint (gconstpointer data
)
872 const gchar
*path
= data
;
873 GFile
*file
= g_file_new_for_path (path
);
875 gboolean is_mountpoint
;
876 GError
*error
= NULL
;
878 info
= g_file_query_info (file
, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT
,
879 G_FILE_QUERY_INFO_NONE
, NULL
, &error
);
880 g_assert_no_error (error
);
881 g_assert_nonnull (info
);
884 g_file_info_get_attribute_boolean (info
,
885 G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT
);
886 g_assert_true (is_mountpoint
);
888 g_clear_object (&info
);
889 g_clear_object (&file
);
893 test_create (gconstpointer test_data
)
899 struct StructureItem item
;
900 GFileOutputStream
*os
;
902 g_assert (test_data
!= NULL
);
905 root
= g_file_new_for_commandline_arg ((char *) test_data
);
906 g_assert (root
!= NULL
);
907 res
= g_file_query_exists (root
, NULL
);
908 g_assert_cmpint (res
, ==, TRUE
);
910 for (i
= 0; i
< G_N_ELEMENTS (sample_struct
); i
++)
912 item
= sample_struct
[i
];
914 if (((item
.extra_flags
& TEST_CREATE
) == TEST_CREATE
) ||
915 ((item
.extra_flags
& TEST_REPLACE
) == TEST_REPLACE
) ||
916 ((item
.extra_flags
& TEST_APPEND
) == TEST_APPEND
))
918 log (" test_create: '%s'\n", item
.filename
);
920 child
= g_file_get_child (root
, item
.filename
);
921 g_assert (child
!= NULL
);
925 if ((item
.extra_flags
& TEST_CREATE
) == TEST_CREATE
)
926 os
= g_file_create (child
, item
.create_flags
, NULL
, &error
);
927 else if ((item
.extra_flags
& TEST_REPLACE
) == TEST_REPLACE
)
929 g_file_replace (child
, NULL
, TRUE
, item
.create_flags
, NULL
,
931 else if ((item
.extra_flags
& TEST_APPEND
) == TEST_APPEND
)
932 os
= g_file_append_to (child
, item
.create_flags
, NULL
, &error
);
936 log (" error code %d = %s\n", error
->code
, error
->message
);
938 if (((item
.extra_flags
& TEST_NOT_EXISTS
) == 0) &&
939 ((item
.extra_flags
& TEST_CREATE
) == TEST_CREATE
))
941 g_assert (os
== NULL
);
942 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_EXISTS
);
944 else if (item
.file_type
== G_FILE_TYPE_DIRECTORY
)
946 g_assert (os
== NULL
);
947 if ((item
.extra_flags
& TEST_CREATE
) == TEST_CREATE
)
948 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_EXISTS
);
950 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_IS_DIRECTORY
);
954 g_assert (os
!= NULL
);
955 g_assert_no_error (error
);
959 g_error_free (error
);
965 g_output_stream_close (G_OUTPUT_STREAM (os
), NULL
, &error
);
967 log (" g_output_stream_close: error %d = %s\n",
968 error
->code
, error
->message
);
969 g_assert_cmpint (res
, ==, TRUE
);
970 g_assert_no_error (error
);
973 g_object_unref (child
);
976 g_object_unref (root
);
980 test_open (gconstpointer test_data
)
986 struct StructureItem item
;
987 GFileInputStream
*input_stream
;
989 g_assert (test_data
!= NULL
);
992 root
= g_file_new_for_commandline_arg ((char *) test_data
);
993 g_assert (root
!= NULL
);
994 res
= g_file_query_exists (root
, NULL
);
995 g_assert_cmpint (res
, ==, TRUE
);
997 for (i
= 0; i
< G_N_ELEMENTS (sample_struct
); i
++)
999 item
= sample_struct
[i
];
1001 if ((!posix_compat
) && (item
.file_type
== G_FILE_TYPE_SYMBOLIC_LINK
))
1004 if ((item
.extra_flags
& TEST_OPEN
) == TEST_OPEN
)
1006 log (" test_open: '%s'\n", item
.filename
);
1008 child
= g_file_get_child (root
, item
.filename
);
1009 g_assert (child
!= NULL
);
1011 input_stream
= g_file_read (child
, NULL
, &error
);
1013 if (((item
.extra_flags
& TEST_NOT_EXISTS
) == TEST_NOT_EXISTS
) ||
1014 ((item
.extra_flags
& TEST_INVALID_SYMLINK
) ==
1015 TEST_INVALID_SYMLINK
))
1017 g_assert (input_stream
== NULL
);
1018 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_FOUND
);
1020 else if (item
.file_type
== G_FILE_TYPE_DIRECTORY
)
1022 g_assert (input_stream
== NULL
);
1023 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_IS_DIRECTORY
);
1027 g_assert (input_stream
!= NULL
);
1028 g_assert_no_error (error
);
1032 g_error_free (error
);
1038 g_input_stream_close (G_INPUT_STREAM (input_stream
), NULL
,
1040 g_assert_cmpint (res
, ==, TRUE
);
1041 g_assert_no_error (error
);
1042 g_object_unref (input_stream
);
1044 g_object_unref (child
);
1047 g_object_unref (root
);
1051 test_delete (gconstpointer test_data
)
1058 struct StructureItem item
;
1061 g_assert (test_data
!= NULL
);
1064 root
= g_file_new_for_commandline_arg ((char *) test_data
);
1065 g_assert (root
!= NULL
);
1066 res
= g_file_query_exists (root
, NULL
);
1067 g_assert_cmpint (res
, ==, TRUE
);
1069 for (i
= 0; i
< G_N_ELEMENTS (sample_struct
); i
++)
1071 item
= sample_struct
[i
];
1073 if ((!posix_compat
) && (item
.file_type
== G_FILE_TYPE_SYMBOLIC_LINK
))
1076 if (((item
.extra_flags
& TEST_DELETE_NORMAL
) == TEST_DELETE_NORMAL
) ||
1077 ((item
.extra_flags
& TEST_DELETE_TRASH
) == TEST_DELETE_TRASH
))
1079 child
= file_exists (root
, item
.filename
, &res
);
1080 g_assert (child
!= NULL
);
1081 /* we don't care about result here */
1083 path
= g_file_get_path (child
);
1084 log (" Deleting %s, path = %s\n", item
.filename
, path
);
1088 if ((item
.extra_flags
& TEST_DELETE_NORMAL
) == TEST_DELETE_NORMAL
)
1089 res
= g_file_delete (child
, NULL
, &error
);
1091 res
= g_file_trash (child
, NULL
, &error
);
1093 if ((item
.extra_flags
& TEST_DELETE_NON_EMPTY
) ==
1094 TEST_DELETE_NON_EMPTY
)
1096 g_assert_cmpint (res
, ==, FALSE
);
1097 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_EMPTY
);
1099 if ((item
.extra_flags
& TEST_DELETE_FAILURE
) == TEST_DELETE_FAILURE
)
1101 g_assert_cmpint (res
, ==, FALSE
);
1102 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_FOUND
);
1104 if ((item
.extra_flags
& TEST_NOT_EXISTS
) == TEST_NOT_EXISTS
)
1106 g_assert_cmpint (res
, ==, FALSE
);
1107 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_NOT_FOUND
);
1112 log (" result = %d, error = %s\n", res
, error
->message
);
1113 g_error_free (error
);
1116 g_object_unref (child
);
1119 g_object_unref (root
);
1123 test_make_directory_with_parents (gconstpointer test_data
)
1125 GFile
*root
, *child
, *grandchild
, *greatgrandchild
;
1127 GError
*error
= NULL
;
1129 g_assert (test_data
!= NULL
);
1131 root
= g_file_new_for_commandline_arg ((char *) test_data
);
1132 g_assert (root
!= NULL
);
1133 res
= g_file_query_exists (root
, NULL
);
1134 g_assert_cmpint (res
, ==, TRUE
);
1136 child
= g_file_get_child (root
, "a");
1137 grandchild
= g_file_get_child (child
, "b");
1138 greatgrandchild
= g_file_get_child (grandchild
, "c");
1140 /* Check that we can successfully make directory hierarchies of
1143 res
= g_file_make_directory_with_parents (child
, NULL
, &error
);
1144 g_assert_cmpint (res
, ==, TRUE
);
1145 g_assert_no_error (error
);
1146 res
= g_file_query_exists (child
, NULL
);
1147 g_assert_cmpint (res
, ==, TRUE
);
1149 g_file_delete (child
, NULL
, NULL
);
1151 res
= g_file_make_directory_with_parents (grandchild
, NULL
, &error
);
1152 g_assert_cmpint (res
, ==, TRUE
);
1153 g_assert_no_error (error
);
1154 res
= g_file_query_exists (grandchild
, NULL
);
1155 g_assert_cmpint (res
, ==, TRUE
);
1157 g_file_delete (grandchild
, NULL
, NULL
);
1158 g_file_delete (child
, NULL
, NULL
);
1160 res
= g_file_make_directory_with_parents (greatgrandchild
, NULL
, &error
);
1161 g_assert_cmpint (res
, ==, TRUE
);
1162 g_assert_no_error (error
);
1163 res
= g_file_query_exists (greatgrandchild
, NULL
);
1164 g_assert_cmpint (res
, ==, TRUE
);
1166 g_file_delete (greatgrandchild
, NULL
, NULL
);
1167 g_file_delete (grandchild
, NULL
, NULL
);
1168 g_file_delete (child
, NULL
, NULL
);
1170 /* Now test failure by trying to create a directory hierarchy
1171 * where a ancestor exists but is read-only
1174 /* No obvious way to do this on Windows */
1178 #ifndef G_PLATFORM_WIN32
1179 if (getuid() == 0) /* permissions are ignored for root */
1183 g_file_make_directory (child
, NULL
, NULL
);
1184 g_assert_cmpint (res
, ==, TRUE
);
1186 res
= g_file_set_attribute_uint32 (child
,
1187 G_FILE_ATTRIBUTE_UNIX_MODE
,
1188 S_IRUSR
+ S_IXUSR
, /* -r-x------ */
1189 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
,
1191 g_assert_cmpint (res
, ==, TRUE
);
1193 res
= g_file_make_directory_with_parents (grandchild
, NULL
, &error
);
1194 g_assert_cmpint (res
, ==, FALSE
);
1195 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_PERMISSION_DENIED
);
1196 g_clear_error (&error
);
1198 res
= g_file_make_directory_with_parents (greatgrandchild
, NULL
, &error
);
1199 g_assert_cmpint (res
, ==, FALSE
);
1200 g_assert_error (error
, G_IO_ERROR
, G_IO_ERROR_PERMISSION_DENIED
);
1201 g_clear_error (&error
);
1204 g_object_unref (greatgrandchild
);
1205 g_object_unref (grandchild
);
1206 g_object_unref (child
);
1207 g_object_unref (root
);
1212 cleanup_dir_recurse (GFile
*parent
, GFile
*root
)
1216 GFileEnumerator
*enumerator
;
1219 char *relative_path
;
1221 g_assert (root
!= NULL
);
1224 g_file_enumerate_children (parent
, "*",
1225 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
, NULL
,
1231 info
= g_file_enumerator_next_file (enumerator
, NULL
, &error
);
1232 while ((info
) && (!error
))
1234 descend
= g_file_enumerator_get_child (enumerator
, info
);
1235 g_assert (descend
!= NULL
);
1236 relative_path
= g_file_get_relative_path (root
, descend
);
1237 g_assert (relative_path
!= NULL
);
1238 g_free (relative_path
);
1240 log (" deleting '%s'\n", g_file_info_get_display_name (info
));
1242 if (g_file_info_get_file_type (info
) == G_FILE_TYPE_DIRECTORY
)
1243 cleanup_dir_recurse (descend
, root
);
1246 res
= g_file_delete (descend
, NULL
, &error
);
1247 g_assert_cmpint (res
, ==, TRUE
);
1249 g_object_unref (descend
);
1251 g_object_unref (info
);
1253 info
= g_file_enumerator_next_file (enumerator
, NULL
, &error
);
1255 g_assert_no_error (error
);
1258 res
= g_file_enumerator_close (enumerator
, NULL
, &error
);
1259 g_assert_cmpint (res
, ==, TRUE
);
1260 g_assert_no_error (error
);
1262 g_object_unref (enumerator
);
1266 prep_clean_structure (gconstpointer test_data
)
1270 g_assert (test_data
!= NULL
);
1271 log ("\n Cleaning target testing structure in '%s'...\n",
1272 (char *) test_data
);
1274 root
= g_file_new_for_commandline_arg ((char *) test_data
);
1275 g_assert (root
!= NULL
);
1277 cleanup_dir_recurse (root
, root
);
1279 g_file_delete (root
, NULL
, NULL
);
1281 g_object_unref (root
);
1285 main (int argc
, char *argv
[])
1287 static gboolean only_create_struct
;
1288 const char *target_path
;
1290 GOptionContext
*context
;
1292 static GOptionEntry cmd_entries
[] = {
1293 {"read-write", 'w', 0, G_OPTION_ARG_NONE
, &write_test
,
1294 "Perform write tests (incl. structure creation)", NULL
},
1295 {"create-struct", 'c', 0, G_OPTION_ARG_NONE
, &only_create_struct
,
1296 "Only create testing structure (no tests)", NULL
},
1297 {"verbose", 'v', 0, G_OPTION_ARG_NONE
, &verbose
, "Be verbose", NULL
},
1298 {"posix", 'x', 0, G_OPTION_ARG_NONE
, &posix_compat
,
1299 "Test POSIX-specific features (unix permissions, symlinks)", NULL
},
1306 only_create_struct
= FALSE
;
1308 posix_compat
= FALSE
;
1310 /* strip all gtester-specific args */
1311 g_test_init (&argc
, &argv
, NULL
);
1313 /* no extra parameters specified, assume we're executed from glib test suite */
1319 only_create_struct
= FALSE
;
1320 target_path
= DEFAULT_TEST_DIR
;
1321 #ifdef G_PLATFORM_WIN32
1322 posix_compat
= FALSE
;
1324 posix_compat
= TRUE
;
1328 /* add trailing args */
1330 context
= g_option_context_new ("target_path");
1331 g_option_context_add_main_entries (context
, cmd_entries
, NULL
);
1332 if (!g_option_context_parse (context
, &argc
, &argv
, &error
))
1334 g_printerr ("option parsing failed: %s\n", error
->message
);
1335 return g_test_run ();
1338 /* remaining arg should is the target path; we don't care of the extra args here */
1340 target_path
= strdup (argv
[1]);
1344 g_printerr ("error: target path was not specified\n");
1345 g_printerr ("%s", g_option_context_get_help (context
, TRUE
, NULL
));
1346 return g_test_run ();
1349 g_option_context_free (context
);
1351 /* Write test - clean target directory first */
1352 /* this can be also considered as a test - enumerate + delete */
1353 if (write_test
|| only_create_struct
)
1354 g_test_add_data_func ("/live-g-file/prep_clean_structure", target_path
,
1355 prep_clean_structure
);
1357 /* Write test - create new testing structure */
1358 if (write_test
|| only_create_struct
)
1359 g_test_add_data_func ("/live-g-file/create_structure", target_path
,
1360 test_create_structure
);
1362 /* Read test - test the sample structure - expect defined attributes to be there */
1363 if (!only_create_struct
)
1364 g_test_add_data_func ("/live-g-file/test_initial_structure", target_path
,
1365 test_initial_structure
);
1367 /* Read test - test traverse the structure - no special file should appear */
1368 if (!only_create_struct
)
1369 g_test_add_data_func ("/live-g-file/test_traverse_structure", target_path
,
1370 test_traverse_structure
);
1372 /* Read test - enumerate */
1373 if (!only_create_struct
)
1374 g_test_add_data_func ("/live-g-file/test_enumerate", target_path
,
1377 /* Read test - open (g_file_read()) */
1378 if (!only_create_struct
)
1379 g_test_add_data_func ("/live-g-file/test_open", target_path
, test_open
);
1383 g_test_add_data_func ("/live-g-file/test_unix_is_mountpoint/sysroot",
1385 test_unix_is_mountpoint
);
1387 g_test_add_data_func ("/live-g-file/test_unix_is_mountpoint/proc",
1389 test_unix_is_mountpoint
);
1393 /* Write test - create */
1394 if (write_test
&& (!only_create_struct
))
1395 g_test_add_data_func ("/live-g-file/test_create", target_path
,
1398 /* Write test - copy, move */
1399 if (write_test
&& (!only_create_struct
))
1400 g_test_add_data_func ("/live-g-file/test_copy_move", target_path
,
1403 /* Write test - delete, trash */
1404 if (write_test
&& (!only_create_struct
))
1405 g_test_add_data_func ("/live-g-file/test_delete", target_path
,
1408 /* Write test - make_directory_with_parents */
1409 if (write_test
&& (!only_create_struct
))
1410 g_test_add_data_func ("/live-g-file/test_make_directory_with_parents", target_path
,
1411 test_make_directory_with_parents
);
1413 if (write_test
|| only_create_struct
)
1414 g_test_add_data_func ("/live-g-file/final_clean", target_path
,
1415 prep_clean_structure
);
1417 return g_test_run ();