2 #include "../common/dconf-paths.h"
3 #include <glib/gstdio.h>
11 #include "../shm/dconf-shm.h"
15 test_mkdir_fail (void)
19 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR
))
24 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
);
26 evil
= g_build_filename (g_get_user_runtime_dir (), "dconf", NULL
);
27 fd
= open (evil
, O_WRONLY
| O_CREAT
, 0600);
30 shm
= dconf_shm_open ("foo");
31 g_assert (shm
== NULL
);
38 g_test_trap_assert_passed ();
39 g_test_trap_assert_stderr ("*unable to create directory*");
43 test_close_null (void)
45 dconf_shm_close (NULL
);
49 test_open_and_flag (void)
53 shm
= dconf_shm_open ("foo");
54 g_assert (shm
!= NULL
);
55 g_assert (!dconf_shm_is_flagged (shm
));
56 dconf_shm_flag ("foo");
57 g_assert (dconf_shm_is_flagged (shm
));
58 dconf_shm_close (shm
);
62 test_invalid_name (void)
64 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR
))
68 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
);
70 shm
= dconf_shm_open ("foo/bar");
71 g_assert (shm
== NULL
);
72 g_assert (dconf_shm_is_flagged (shm
));
75 g_test_trap_assert_passed ();
76 g_test_trap_assert_stderr ("*unable to create*foo/bar*");
80 test_flag_nonexistent (void)
82 dconf_shm_flag ("does-not-exist");
85 static gboolean should_fail_pwrite
;
88 pwrite (int fd
, const void *buf
, size_t count
, off_t offset
)
90 static ssize_t (* real_pwrite
) (int, const void *, size_t, off_t
);
93 real_pwrite
= dlsym (RTLD_NEXT
, "pwrite");
95 if (should_fail_pwrite
)
101 return (* real_pwrite
) (fd
, buf
, count
, offset
);
105 test_out_of_space_open (void)
107 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR
))
111 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
);
112 should_fail_pwrite
= TRUE
;
114 shm
= dconf_shm_open ("foo");
115 g_assert (shm
== NULL
);
116 g_assert (dconf_shm_is_flagged (shm
));
119 g_test_trap_assert_passed ();
120 g_test_trap_assert_stderr ("*failed to allocate*foo*");
124 test_out_of_space_flag (void)
126 if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR
))
128 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
);
129 should_fail_pwrite
= TRUE
;
131 dconf_shm_flag ("foo");
134 g_test_trap_assert_passed ();
138 main (int argc
, char **argv
)
143 temp
= dconf_test_create_tmpdir ();
145 g_setenv ("XDG_RUNTIME_DIR", temp
, TRUE
);
146 /* This currently works, but it is possible that one day GLib will
147 * read the XDG_RUNTIME_DIR variable (and cache its value) as a
148 * side-effect of the dconf_test_create_tmpdir() call above.
150 * This assert will quickly uncover the problem in that case...
152 g_assert_cmpstr (g_get_user_runtime_dir (), ==, temp
);
154 g_test_init (&argc
, &argv
, NULL
);
156 g_test_add_func ("/shm/mkdir-fail", test_mkdir_fail
);
157 g_test_add_func ("/shm/close-null", test_close_null
);
158 g_test_add_func ("/shm/open-and-flag", test_open_and_flag
);
159 g_test_add_func ("/shm/invalid-name", test_invalid_name
);
160 g_test_add_func ("/shm/flag-nonexistent", test_flag_nonexistent
);
161 g_test_add_func ("/shm/out-of-space-open", test_out_of_space_open
);
162 g_test_add_func ("/shm/out-of-space-flag", test_out_of_space_flag
);
164 status
= g_test_run ();
166 dconf_test_remove_tmpdir (temp
);