3 #include "../common/dconf-paths.h"
4 #include <glib/gstdio.h>
12 #include "../shm/dconf-shm.h"
16 test_mkdir_fail (void)
20 if (g_test_subprocess ())
25 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
);
27 evil
= g_build_filename (g_get_user_runtime_dir (), "dconf", NULL
);
28 fd
= open (evil
, O_WRONLY
| O_CREAT
, 0600);
31 shm
= dconf_shm_open ("foo");
32 g_assert (shm
== NULL
);
40 g_test_trap_subprocess (NULL
, 0, 0);
41 g_test_trap_assert_passed ();
42 g_test_trap_assert_stderr ("*unable to create directory*");
46 test_close_null (void)
48 dconf_shm_close (NULL
);
52 test_open_and_flag (void)
56 shm
= dconf_shm_open ("foo");
57 g_assert (shm
!= NULL
);
58 g_assert (!dconf_shm_is_flagged (shm
));
59 dconf_shm_flag ("foo");
60 g_assert (dconf_shm_is_flagged (shm
));
61 dconf_shm_close (shm
);
65 test_invalid_name (void)
67 if (g_test_subprocess ())
71 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
);
73 shm
= dconf_shm_open ("foo/bar");
74 g_assert (shm
== NULL
);
75 g_assert (dconf_shm_is_flagged (shm
));
79 g_test_trap_subprocess (NULL
, 0, 0);
80 g_test_trap_assert_passed ();
81 g_test_trap_assert_stderr ("*unable to create*foo/bar*");
85 test_flag_nonexistent (void)
87 dconf_shm_flag ("does-not-exist");
90 static gboolean should_fail_pwrite
;
93 pwrite (int fd
, const void *buf
, size_t count
, off_t offset
)
95 static ssize_t (* real_pwrite
) (int, const void *, size_t, off_t
);
98 real_pwrite
= dlsym (RTLD_NEXT
, "pwrite");
100 if (should_fail_pwrite
)
106 return (* real_pwrite
) (fd
, buf
, count
, offset
);
110 test_out_of_space_open (void)
112 if (g_test_subprocess ())
116 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
);
117 should_fail_pwrite
= TRUE
;
119 shm
= dconf_shm_open ("foo");
120 g_assert (shm
== NULL
);
121 g_assert (dconf_shm_is_flagged (shm
));
125 g_test_trap_subprocess (NULL
, 0, 0);
126 g_test_trap_assert_passed ();
127 g_test_trap_assert_stderr ("*failed to allocate*foo*");
131 test_out_of_space_flag (void)
133 if (g_test_subprocess ())
135 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
);
136 should_fail_pwrite
= TRUE
;
138 dconf_shm_flag ("foo");
142 g_test_trap_subprocess (NULL
, 0, 0);
143 g_test_trap_assert_passed ();
147 main (int argc
, char **argv
)
152 temp
= dconf_test_create_tmpdir ();
154 g_setenv ("XDG_RUNTIME_DIR", temp
, TRUE
);
155 /* This currently works, but it is possible that one day GLib will
156 * read the XDG_RUNTIME_DIR variable (and cache its value) as a
157 * side-effect of the dconf_test_create_tmpdir() call above.
159 * This assert will quickly uncover the problem in that case...
161 g_assert_cmpstr (g_get_user_runtime_dir (), ==, temp
);
163 g_test_init (&argc
, &argv
, NULL
);
165 g_test_add_func ("/shm/mkdir-fail", test_mkdir_fail
);
166 g_test_add_func ("/shm/close-null", test_close_null
);
167 g_test_add_func ("/shm/open-and-flag", test_open_and_flag
);
168 g_test_add_func ("/shm/invalid-name", test_invalid_name
);
169 g_test_add_func ("/shm/flag-nonexistent", test_flag_nonexistent
);
170 g_test_add_func ("/shm/out-of-space-open", test_out_of_space_open
);
171 g_test_add_func ("/shm/out-of-space-flag", test_out_of_space_flag
);
173 status
= g_test_run ();
175 dconf_test_remove_tmpdir (temp
);