1#include <glib.h>
2
3static void
4test_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 (path: ".", flags: 0, error: &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 (str: 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 (mem: first);
28 g_dir_close (dir);
29}
30
31static void
32test_dir_nonexisting (void)
33{
34 GDir *dir;
35 GError *error;
36
37 error = NULL;
38 dir = g_dir_open (path: "/pfrkstrf", flags: 0, error: &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
44int
45main (int argc, char *argv[])
46{
47 g_test_init (argc: &argc, argv: &argv, NULL);
48
49 g_test_add_func (testpath: "/dir/read", test_func: test_dir_read);
50 g_test_add_func (testpath: "/dir/nonexisting", test_func: test_dir_nonexisting);
51
52 return g_test_run ();
53}
54

source code of gtk/subprojects/glib/glib/tests/dir.c