1 #include <glib.h>
2
3 static void
test_dir_read(void)4 test_dir_read (void)
5 {
6 GDir *dir;
7 GError *error;
8 gchar *first;
9 const gchar *name;
10
11 error = NULL;
12 dir = g_dir_open (".", 0, &error);
13 g_assert_no_error (error);
14
15 first = NULL;
16 while ((name = g_dir_read_name (dir)) != NULL)
17 {
18 if (first == NULL)
19 first = g_strdup (name);
20 g_assert_cmpstr (name, !=, ".");
21 g_assert_cmpstr (name, !=, "..");
22 }
23
24 g_dir_rewind (dir);
25 g_assert_cmpstr (g_dir_read_name (dir), ==, first);
26
27 g_free (first);
28 g_dir_close (dir);
29 }
30
31 static void
test_dir_nonexisting(void)32 test_dir_nonexisting (void)
33 {
34 GDir *dir;
35 GError *error;
36
37 error = NULL;
38 dir = g_dir_open ("/pfrkstrf", 0, &error);
39 g_assert (dir == NULL);
40 g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
41 g_error_free (error);
42 }
43
44 int
main(int argc,char * argv[])45 main (int argc, char *argv[])
46 {
47 g_test_init (&argc, &argv, NULL);
48
49 g_test_add_func ("/dir/read", test_dir_read);
50 g_test_add_func ("/dir/nonexisting", test_dir_nonexisting);
51
52 return g_test_run ();
53 }
54