Misc test additions
[platform/upstream/glib.git] / gio / tests / file.c
1 #include <gio/gio.h>
2
3 static void
4 test_basic (void)
5 {
6   GFile *file;
7   gchar *s;
8
9   file = g_file_new_for_path ("./some/directory/testfile");
10
11   s = g_file_get_basename (file);
12   g_assert_cmpstr (s, ==, "testfile");
13   g_free (s);
14
15   s = g_file_get_uri (file);
16   g_assert (g_str_has_prefix (s, "file://"));
17   g_assert (g_str_has_suffix (s, "/some/directory/testfile"));
18   g_free (s);
19
20   g_assert (g_file_has_uri_scheme (file, "file"));
21   s = g_file_get_uri_scheme (file);
22   g_assert_cmpstr (s, ==, "file");
23   g_free (s);
24
25   g_object_unref (file);
26 }
27
28 static void
29 test_parent (void)
30 {
31   GFile *file;
32   GFile *file2;
33   GFile *parent;
34   GFile *root;
35
36   file = g_file_new_for_path ("./some/directory/testfile");
37   file2 = g_file_new_for_path ("./some/directory");
38   root = g_file_new_for_path ("/");
39
40   g_assert (g_file_has_parent (file, file2));
41
42   parent = g_file_get_parent (file);
43   g_assert (g_file_equal (parent, file2));
44   g_object_unref (parent);
45
46   g_assert (g_file_get_parent (root) == NULL);
47
48   g_object_unref (file);
49   g_object_unref (file2);
50   g_object_unref (root);
51 }
52
53 int
54 main (int argc, char *argv[])
55 {
56   g_type_init ();
57
58   g_test_init (&argc, &argv, NULL);
59
60   g_test_add_func ("/file/basic", test_basic);
61   g_test_add_func ("/file/parent", test_parent);
62
63   return g_test_run ();
64 }