gio/tests: Some more fixes for installed tests
[platform/upstream/glib.git] / gio / tests / file.c
1 #include <string.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <gio/gio.h>
5 #include <gio/gfiledescriptorbased.h>
6 #ifdef G_OS_UNIX
7 #include <sys/stat.h>
8 #endif
9
10 static const gchar *datapath;
11
12 static void
13 test_basic (void)
14 {
15   GFile *file;
16   gchar *s;
17
18   file = g_file_new_for_path ("./some/directory/testfile");
19
20   s = g_file_get_basename (file);
21   g_assert_cmpstr (s, ==, "testfile");
22   g_free (s);
23
24   s = g_file_get_uri (file);
25   g_assert (g_str_has_prefix (s, "file://"));
26   g_assert (g_str_has_suffix (s, "/some/directory/testfile"));
27   g_free (s);
28
29   g_assert (g_file_has_uri_scheme (file, "file"));
30   s = g_file_get_uri_scheme (file);
31   g_assert_cmpstr (s, ==, "file");
32   g_free (s);
33
34   g_object_unref (file);
35 }
36
37 static void
38 test_parent (void)
39 {
40   GFile *file;
41   GFile *file2;
42   GFile *parent;
43   GFile *root;
44
45   file = g_file_new_for_path ("./some/directory/testfile");
46   file2 = g_file_new_for_path ("./some/directory");
47   root = g_file_new_for_path ("/");
48
49   g_assert (g_file_has_parent (file, file2));
50
51   parent = g_file_get_parent (file);
52   g_assert (g_file_equal (parent, file2));
53   g_object_unref (parent);
54
55   g_assert (g_file_get_parent (root) == NULL);
56
57   g_object_unref (file);
58   g_object_unref (file2);
59   g_object_unref (root);
60 }
61
62 static void
63 test_child (void)
64 {
65   GFile *file;
66   GFile *child;
67   GFile *child2;
68
69   file = g_file_new_for_path ("./some/directory");
70   child = g_file_get_child (file, "child");
71   g_assert (g_file_has_parent (child, file));
72
73   child2 = g_file_get_child_for_display_name (file, "child2", NULL);
74   g_assert (g_file_has_parent (child2, file));
75
76   g_object_unref (child);
77   g_object_unref (child2);
78   g_object_unref (file);
79 }
80
81 static void
82 test_type (void)
83 {
84   GFile *datapath_f;
85   GFile *file;
86   GFileType type;
87   GError *error = NULL;
88
89   datapath_f = g_file_new_for_path (datapath);
90
91   file = g_file_get_child (datapath_f, "g-icon.c");
92   type = g_file_query_file_type (file, 0, NULL);
93   g_assert_cmpint (type, ==, G_FILE_TYPE_REGULAR);
94   g_object_unref (file);
95
96   file = g_file_get_child (datapath_f, "schema-tests");
97   type = g_file_query_file_type (file, 0, NULL);
98   g_assert_cmpint (type, ==, G_FILE_TYPE_DIRECTORY);
99
100   g_file_read (file, NULL, &error);
101   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY);
102   g_error_free (error);
103   g_object_unref (file);
104
105   g_object_unref (datapath_f);
106 }
107
108
109 typedef struct
110 {
111   GFile *file;
112   GFileMonitor *monitor;
113   GOutputStream *ostream;
114   GInputStream *istream;
115   GMainLoop *loop;
116   gint buffersize;
117   gint monitor_created;
118   gint monitor_deleted;
119   gint monitor_changed;
120   gchar *monitor_path;
121   gint pos;
122   gchar *data;
123   gchar *buffer;
124   guint timeout;
125 } CreateDeleteData;
126
127 static void
128 monitor_changed (GFileMonitor      *monitor,
129                  GFile             *file,
130                  GFile             *other_file,
131                  GFileMonitorEvent  event_type,
132                  gpointer           user_data)
133 {
134   CreateDeleteData *data = user_data;
135   gchar *path;
136
137   path = g_file_get_path (file);
138   g_assert_cmpstr (data->monitor_path, ==, path);
139   g_free (path);
140
141   if (event_type == G_FILE_MONITOR_EVENT_CREATED)
142     data->monitor_created++;
143   if (event_type == G_FILE_MONITOR_EVENT_DELETED)
144     data->monitor_deleted++;
145   if (event_type == G_FILE_MONITOR_EVENT_CHANGED)
146     data->monitor_changed++;
147 }
148
149
150 static gboolean
151 quit_idle (gpointer user_data)
152 {
153   CreateDeleteData *data = user_data;
154
155   g_source_remove (data->timeout); 
156   g_main_loop_quit (data->loop);
157
158   return FALSE;
159 }
160
161 static void
162 iclosed_cb (GObject      *source,
163             GAsyncResult *res,
164             gpointer      user_data)
165 {
166   CreateDeleteData *data = user_data;
167   GError *error;
168   gboolean ret;
169
170   error = NULL;
171   ret = g_input_stream_close_finish (data->istream, res, &error);
172   g_assert_no_error (error);
173   g_assert (ret);
174
175   g_assert (g_input_stream_is_closed (data->istream));
176
177   ret = g_file_delete (data->file, NULL, &error);
178   g_assert (ret);
179   g_assert_no_error (error);
180
181   /* work around file monitor bug:
182    * inotify events are only processed every 1000 ms, regardless
183    * of the rate limit set on the file monitor
184    */
185   g_timeout_add (2000, quit_idle, data);
186 }
187
188 static void
189 read_cb (GObject      *source,
190          GAsyncResult *res,
191          gpointer      user_data)
192 {
193   CreateDeleteData *data = user_data;
194   GError *error;
195   gssize size;
196
197   error = NULL;
198   size = g_input_stream_read_finish (data->istream, res, &error);
199   g_assert_no_error (error);
200
201   data->pos += size;
202   if (data->pos < strlen (data->data))
203     {
204       g_input_stream_read_async (data->istream,
205                                  data->buffer + data->pos,
206                                  strlen (data->data) - data->pos,
207                                  0,
208                                  NULL,
209                                  read_cb,
210                                  data);
211     }
212   else
213     {
214       g_assert_cmpstr (data->buffer, ==, data->data);
215       g_assert (!g_input_stream_is_closed (data->istream));
216       g_input_stream_close_async (data->istream, 0, NULL, iclosed_cb, data);
217     }
218 }
219
220 static void
221 ipending_cb (GObject      *source,
222              GAsyncResult *res,
223              gpointer      user_data)
224 {
225   CreateDeleteData *data = user_data;
226   GError *error;
227
228   error = NULL;
229   g_input_stream_read_finish (data->istream, res, &error);
230   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PENDING);
231   g_error_free (error);
232 }
233
234 static void
235 skipped_cb (GObject      *source,
236             GAsyncResult *res,
237             gpointer      user_data)
238 {
239   CreateDeleteData *data = user_data;
240   GError *error;
241   gssize size;
242
243   error = NULL;
244   size = g_input_stream_skip_finish (data->istream, res, &error);
245   g_assert_no_error (error);
246   g_assert_cmpint (size, ==, data->pos);
247
248   g_input_stream_read_async (data->istream,
249                              data->buffer + data->pos,
250                              strlen (data->data) - data->pos,
251                              0,
252                              NULL,
253                              read_cb,
254                              data);
255   /* check that we get a pending error */
256   g_input_stream_read_async (data->istream,
257                              data->buffer + data->pos,
258                              strlen (data->data) - data->pos,
259                              0,
260                              NULL,
261                              ipending_cb,
262                              data);
263 }
264
265 static void
266 opened_cb (GObject      *source,
267            GAsyncResult *res,
268            gpointer      user_data)
269 {
270   GFileInputStream *base;
271   CreateDeleteData *data = user_data;
272   GError *error;
273
274   error = NULL;
275   base = g_file_read_finish (data->file, res, &error);
276   g_assert_no_error (error);
277
278   if (data->buffersize == 0)
279     data->istream = G_INPUT_STREAM (g_object_ref (base));
280   else
281     data->istream = g_buffered_input_stream_new_sized (G_INPUT_STREAM (base), data->buffersize);
282   g_object_unref (base);
283
284   data->buffer = g_new0 (gchar, strlen (data->data) + 1);
285
286   /* copy initial segment directly, then skip */
287   memcpy (data->buffer, data->data, 10);
288   data->pos = 10;
289
290   g_input_stream_skip_async (data->istream,
291                              10,
292                              0,
293                              NULL,
294                              skipped_cb,
295                              data);
296 }
297
298 static void
299 oclosed_cb (GObject      *source,
300             GAsyncResult *res,
301             gpointer      user_data)
302 {
303   CreateDeleteData *data = user_data;
304   GError *error;
305   gboolean ret;
306
307   error = NULL;
308   ret = g_output_stream_close_finish (data->ostream, res, &error);
309   g_assert_no_error (error);
310   g_assert (ret);
311   g_assert (g_output_stream_is_closed (data->ostream));
312
313   g_file_read_async (data->file, 0, NULL, opened_cb, data);
314 }
315
316 static void
317 written_cb (GObject      *source,
318             GAsyncResult *res,
319             gpointer      user_data)
320 {
321   CreateDeleteData *data = user_data;
322   gssize size;
323   GError *error;
324
325   error = NULL;
326   size = g_output_stream_write_finish (data->ostream, res, &error);
327   g_assert_no_error (error);
328
329   data->pos += size;
330   if (data->pos < strlen (data->data))
331     {
332       g_output_stream_write_async (data->ostream,
333                                    data->data + data->pos,
334                                    strlen (data->data) - data->pos,
335                                    0,
336                                    NULL,
337                                    written_cb,
338                                    data);
339     }
340   else
341     {
342       g_assert (!g_output_stream_is_closed (data->ostream));
343       g_output_stream_close_async (data->ostream, 0, NULL, oclosed_cb, data);
344     }
345 }
346
347 static void
348 opending_cb (GObject      *source,
349              GAsyncResult *res,
350              gpointer      user_data)
351 {
352   CreateDeleteData *data = user_data;
353   GError *error;
354
355   error = NULL;
356   g_output_stream_write_finish (data->ostream, res, &error);
357   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_PENDING);
358   g_error_free (error);
359 }
360
361 static void
362 created_cb (GObject      *source,
363             GAsyncResult *res,
364             gpointer      user_data)
365 {
366   GFileOutputStream *base;
367   CreateDeleteData *data = user_data;
368   GError *error;
369
370   error = NULL;
371   base = g_file_create_finish (G_FILE (source), res, &error);
372   g_assert_no_error (error);
373   g_assert (g_file_query_exists  (data->file, NULL));
374
375   if (data->buffersize == 0)
376     data->ostream = G_OUTPUT_STREAM (g_object_ref (base));
377   else
378     data->ostream = g_buffered_output_stream_new_sized (G_OUTPUT_STREAM (base), data->buffersize);
379   g_object_unref (base);
380
381   g_output_stream_write_async (data->ostream,
382                                data->data,
383                                strlen (data->data),
384                                0,
385                                NULL,
386                                written_cb,
387                                data);
388   /* check that we get a pending error */
389   g_output_stream_write_async (data->ostream,
390                                data->data,
391                                strlen (data->data),
392                                0,
393                                NULL,
394                                opending_cb,
395                                data);
396 }
397
398 static gboolean
399 stop_timeout (gpointer data)
400 {
401   g_assert_not_reached ();
402
403   return FALSE;
404 }
405
406 /*
407  * This test does a fully async create-write-read-delete.
408  * Callbackistan.
409  */
410 static void
411 test_create_delete (gconstpointer d)
412 {
413   GError *error;
414   CreateDeleteData *data;
415   GFileIOStream *iostream;
416
417   data = g_new0 (CreateDeleteData, 1);
418
419   data->buffersize = GPOINTER_TO_INT (d);
420   data->data = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789";
421   data->pos = 0;
422
423   data->file = g_file_new_tmp ("g_file_create_delete_XXXXXX",
424                                &iostream, NULL);
425   g_assert (data->file != NULL);
426   g_object_unref (iostream);
427
428   data->monitor_path = g_file_get_path (data->file);
429   remove (data->monitor_path);
430
431   g_assert (!g_file_query_exists  (data->file, NULL));
432
433   error = NULL;
434   data->monitor = g_file_monitor_file (data->file, 0, NULL, &error);
435   g_assert_no_error (error);
436
437   /* This test doesn't work with GPollFileMonitor, because it assumes
438    * that the monitor will notice a create immediately followed by a
439    * delete, rather than coalescing them into nothing.
440    */
441   if (!strcmp (G_OBJECT_TYPE_NAME (data->monitor), "GPollFileMonitor"))
442     {
443       g_print ("skipping test for this GFileMonitor implementation");
444       goto skip;
445     }
446
447   g_file_monitor_set_rate_limit (data->monitor, 100);
448
449   g_signal_connect (data->monitor, "changed", G_CALLBACK (monitor_changed), data);
450
451   data->loop = g_main_loop_new (NULL, FALSE);
452
453   data->timeout = g_timeout_add (5000, stop_timeout, NULL);
454
455   g_file_create_async (data->file, 0, 0, NULL, created_cb, data);
456
457   g_main_loop_run (data->loop);
458
459   g_assert_cmpint (data->monitor_created, ==, 1);
460   g_assert_cmpint (data->monitor_deleted, ==, 1);
461   g_assert_cmpint (data->monitor_changed, >, 0);
462
463   g_assert (!g_file_monitor_is_cancelled (data->monitor));
464   g_file_monitor_cancel (data->monitor);
465   g_assert (g_file_monitor_is_cancelled (data->monitor));
466
467   g_main_loop_unref (data->loop);
468   g_object_unref (data->ostream);
469   g_object_unref (data->istream);
470
471  skip:
472   g_object_unref (data->monitor);
473   g_object_unref (data->file);
474   free (data->monitor_path);
475   g_free (data->buffer);
476   g_free (data);
477 }
478
479 static const gchar *replace_data =
480     "/**\n"
481     " * g_file_replace_contents_async:\n"
482     " * @file: input #GFile.\n"
483     " * @contents: string of contents to replace the file with.\n"
484     " * @length: the length of @contents in bytes.\n"
485     " * @etag: (allow-none): a new <link linkend=\"gfile-etag\">entity tag</link> for the @file, or %NULL\n"
486     " * @make_backup: %TRUE if a backup should be created.\n"
487     " * @flags: a set of #GFileCreateFlags.\n"
488     " * @cancellable: optional #GCancellable object, %NULL to ignore.\n"
489     " * @callback: a #GAsyncReadyCallback to call when the request is satisfied\n"
490     " * @user_data: the data to pass to callback function\n"
491     " * \n"
492     " * Starts an asynchronous replacement of @file with the given \n"
493     " * @contents of @length bytes. @etag will replace the document's\n"
494     " * current entity tag.\n"
495     " * \n"
496     " * When this operation has completed, @callback will be called with\n"
497     " * @user_user data, and the operation can be finalized with \n"
498     " * g_file_replace_contents_finish().\n"
499     " * \n"
500     " * If @cancellable is not %NULL, then the operation can be cancelled by\n"
501     " * triggering the cancellable object from another thread. If the operation\n"
502     " * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. \n"
503     " * \n"
504     " * If @make_backup is %TRUE, this function will attempt to \n"
505     " * make a backup of @file.\n"
506     " **/\n";
507
508 typedef struct
509 {
510   GFile *file;
511   const gchar *data;
512   GMainLoop *loop;
513   gboolean again;
514 } ReplaceLoadData;
515
516 static void replaced_cb (GObject      *source,
517                          GAsyncResult *res,
518                          gpointer      user_data);
519
520 static void
521 loaded_cb (GObject      *source,
522            GAsyncResult *res,
523            gpointer      user_data)
524 {
525   ReplaceLoadData *data = user_data;
526   gboolean ret;
527   GError *error;
528   gchar *contents;
529   gsize length;
530
531   error = NULL;
532   ret = g_file_load_contents_finish (data->file, res, &contents, &length, NULL, &error);
533   g_assert (ret);
534   g_assert_no_error (error);
535   g_assert_cmpint (length, ==, strlen (data->data));
536   g_assert_cmpstr (contents, ==, data->data);
537
538   g_free (contents);
539
540   if (data->again)
541     {
542       data->again = FALSE;
543       data->data = "pi pa po";
544
545       g_file_replace_contents_async (data->file,
546                                      data->data,
547                                      strlen (data->data),
548                                      NULL,
549                                      FALSE,
550                                      0,
551                                      NULL,
552                                      replaced_cb,
553                                      data);
554     }
555   else
556     {
557        error = NULL;
558        ret = g_file_delete (data->file, NULL, &error);
559        g_assert_no_error (error);
560        g_assert (ret);
561        g_assert (!g_file_query_exists (data->file, NULL));
562
563        g_main_loop_quit (data->loop);
564     }
565 }
566
567 static void
568 replaced_cb (GObject      *source,
569              GAsyncResult *res,
570              gpointer      user_data)
571 {
572   ReplaceLoadData *data = user_data;
573   GError *error;
574
575   error = NULL;
576   g_file_replace_contents_finish (data->file, res, NULL, &error);
577   g_assert_no_error (error);
578
579   g_file_load_contents_async (data->file, NULL, loaded_cb, data);
580 }
581
582 static void
583 test_replace_load (void)
584 {
585   ReplaceLoadData *data;
586   gchar *path;
587   GFileIOStream *iostream;
588
589   data = g_new0 (ReplaceLoadData, 1);
590   data->again = TRUE;
591   data->data = replace_data;
592
593   data->file = g_file_new_tmp ("g_file_replace_load_XXXXXX",
594                                &iostream, NULL);
595   g_assert (data->file != NULL);
596   g_object_unref (iostream);
597
598   path = g_file_get_path (data->file);
599   remove (path);
600
601   g_assert (!g_file_query_exists (data->file, NULL));
602
603   data->loop = g_main_loop_new (NULL, FALSE);
604
605   g_file_replace_contents_async (data->file,
606                                  data->data,
607                                  strlen (data->data),
608                                  NULL,
609                                  FALSE,
610                                  0,
611                                  NULL,
612                                  replaced_cb,
613                                  data);
614
615   g_main_loop_run (data->loop);
616
617   g_main_loop_unref (data->loop);
618   g_object_unref (data->file);
619   g_free (data);
620   free (path);
621 }
622
623 static void
624 test_replace_cancel (void)
625 {
626   GFile *tmpdir, *file;
627   GFileOutputStream *ostream;
628   GFileEnumerator *fenum;
629   GFileInfo *info;
630   GCancellable *cancellable;
631   gchar *path;
632   gsize nwrote;
633   GError *error = NULL;
634
635   g_test_bug ("629301");
636
637   path = g_dir_make_tmp ("g_file_replace_cancel_XXXXXX", &error);
638   g_assert_no_error (error);
639   tmpdir = g_file_new_for_path (path);
640   g_free (path);
641
642   file = g_file_get_child (tmpdir, "file");
643   g_file_replace_contents (file,
644                            replace_data,
645                            strlen (replace_data),
646                            NULL, FALSE, 0, NULL,
647                            NULL, &error);
648   g_assert_no_error (error);
649
650   ostream = g_file_replace (file, NULL, TRUE, 0, NULL, &error);
651   g_assert_no_error (error);
652
653   g_output_stream_write_all (G_OUTPUT_STREAM (ostream),
654                              replace_data, strlen (replace_data),
655                              &nwrote, NULL, &error);
656   g_assert_no_error (error);
657   g_assert_cmpint (nwrote, ==, strlen (replace_data));
658
659   /* At this point there should be two files; the original and the
660    * temporary.
661    */
662   fenum = g_file_enumerate_children (tmpdir, NULL, 0, NULL, &error);
663   g_assert_no_error (error);
664
665   info = g_file_enumerator_next_file (fenum, NULL, &error);
666   g_assert_no_error (error);
667   g_assert (info != NULL);
668   g_object_unref (info);
669   info = g_file_enumerator_next_file (fenum, NULL, &error);
670   g_assert_no_error (error);
671   g_assert (info != NULL);
672   g_object_unref (info);
673
674   g_file_enumerator_close (fenum, NULL, &error);
675   g_assert_no_error (error);
676   g_object_unref (fenum);
677
678   /* Make sure the temporary gets deleted even if we cancel. */
679   cancellable = g_cancellable_new ();
680   g_cancellable_cancel (cancellable);
681   g_output_stream_close (G_OUTPUT_STREAM (ostream), cancellable, &error);
682   g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
683   g_clear_error (&error);
684
685   g_object_unref (cancellable);
686   g_object_unref (ostream);
687
688   g_file_delete (file, NULL, &error);
689   g_assert_no_error (error);
690   g_object_unref (file);
691
692   /* This will only succeed if the temp file was deleted. */
693   g_file_delete (tmpdir, NULL, &error);
694   g_assert_no_error (error);
695   g_object_unref (tmpdir);
696 }
697
698 static void
699 on_file_deleted (GObject      *object,
700                  GAsyncResult *result,
701                  gpointer      user_data)
702 {
703   GError *local_error = NULL;
704   GMainLoop *loop = user_data;
705
706   (void) g_file_delete_finish ((GFile*)object, result, &local_error);
707   g_assert_no_error (local_error);
708
709   g_main_loop_quit (loop);
710 }
711
712 static void
713 test_async_delete (void)
714 {
715   GFile *file;
716   GFileIOStream *iostream;
717   GError *local_error = NULL;
718   GError **error = &local_error;
719   GMainLoop *loop;
720
721   file = g_file_new_tmp ("g_file_delete_XXXXXX",
722                          &iostream, error);
723   g_assert_no_error (local_error);
724   g_object_unref (iostream);
725
726   g_assert (g_file_query_exists (file, NULL));
727
728   loop = g_main_loop_new (NULL, TRUE);
729
730   g_file_delete_async (file, G_PRIORITY_DEFAULT, NULL, on_file_deleted, loop);
731
732   g_main_loop_run (loop);
733
734   g_assert (!g_file_query_exists (file, NULL));
735
736   g_main_loop_unref (loop);
737   g_object_unref (file);
738 }
739
740 #ifdef G_OS_UNIX
741 static void
742 test_copy_preserve_mode (void)
743 {
744   GFile *tmpfile;
745   GFile *dest_tmpfile;
746   GFileInfo *dest_info;
747   GFileIOStream *iostream;
748   GError *local_error = NULL;
749   GError **error = &local_error;
750   guint32 romode = S_IFREG | 0600;
751   guint32 dest_mode;
752
753   tmpfile = g_file_new_tmp ("tmp-copy-preserve-modeXXXXXX",
754                             &iostream, error);
755   g_assert_no_error (local_error);
756   g_io_stream_close ((GIOStream*)iostream, NULL, error);
757   g_assert_no_error (local_error);
758   g_clear_object (&iostream);
759
760   g_file_set_attribute (tmpfile, G_FILE_ATTRIBUTE_UNIX_MODE, G_FILE_ATTRIBUTE_TYPE_UINT32,
761                         &romode, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
762                         NULL, error);
763   g_assert_no_error (local_error);
764
765   dest_tmpfile = g_file_new_tmp ("tmp-copy-preserve-modeXXXXXX",
766                                  &iostream, error);
767   g_assert_no_error (local_error);
768   g_io_stream_close ((GIOStream*)iostream, NULL, error);
769   g_assert_no_error (local_error);
770   g_clear_object (&iostream);
771
772   g_file_copy (tmpfile, dest_tmpfile, G_FILE_COPY_OVERWRITE | G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_ALL_METADATA,
773                NULL, NULL, NULL, error);
774   g_assert_no_error (local_error);
775
776   dest_info = g_file_query_info (dest_tmpfile, G_FILE_ATTRIBUTE_UNIX_MODE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
777                                  NULL, error);
778   g_assert_no_error (local_error);
779
780   dest_mode = g_file_info_get_attribute_uint32 (dest_info, G_FILE_ATTRIBUTE_UNIX_MODE);
781   
782   g_assert_cmpint (dest_mode, ==, romode);
783
784   (void) g_file_delete (tmpfile, NULL, NULL);
785   (void) g_file_delete (dest_tmpfile, NULL, NULL);
786   
787   g_clear_object (&tmpfile);
788   g_clear_object (&dest_tmpfile);
789   g_clear_object (&dest_info);
790 }
791 #endif
792
793 int
794 main (int argc, char *argv[])
795 {
796   if (g_getenv ("G_TEST_DATA"))
797     datapath = g_getenv ("G_TEST_DATA");
798   else
799     datapath = SRCDIR;
800
801   g_test_init (&argc, &argv, NULL);
802
803   g_test_bug_base ("http://bugzilla.gnome.org/");
804
805   g_test_add_func ("/file/basic", test_basic);
806   g_test_add_func ("/file/parent", test_parent);
807   g_test_add_func ("/file/child", test_child);
808   g_test_add_func ("/file/type", test_type);
809   g_test_add_data_func ("/file/async-create-delete/0", GINT_TO_POINTER (0), test_create_delete);
810   g_test_add_data_func ("/file/async-create-delete/1", GINT_TO_POINTER (1), test_create_delete);
811   g_test_add_data_func ("/file/async-create-delete/10", GINT_TO_POINTER (10), test_create_delete);
812   g_test_add_data_func ("/file/async-create-delete/25", GINT_TO_POINTER (25), test_create_delete);
813   g_test_add_data_func ("/file/async-create-delete/4096", GINT_TO_POINTER (4096), test_create_delete);
814   g_test_add_func ("/file/replace-load", test_replace_load);
815   g_test_add_func ("/file/replace-cancel", test_replace_cancel);
816   g_test_add_func ("/file/async-delete", test_async_delete);
817 #ifdef G_OS_UNIX
818   g_test_add_func ("/file/copy-preserve-mode", test_copy_preserve_mode);
819 #endif
820
821   return g_test_run ();
822 }