#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include "glib.h"
+#include "glib-private.h"
#include <stdlib.h>
#include <string.h>
g_assert_cmpint (GUINT32_SWAP_LE_BE (a32), ==, b32);
- a64 = 0xaaaaaaaabbbbbbbb;
- b64 = 0xbbbbbbbbaaaaaaaa;
+ a64 = G_GUINT64_CONSTANT(0xaaaaaaaabbbbbbbb);
+ b64 = G_GUINT64_CONSTANT(0xbbbbbbbbaaaaaaaa);
g_assert_cmpint (GUINT64_SWAP_LE_BE (a64), ==, b64);
}
{
gchar *res;
+#ifdef G_OS_UNIX
res = g_find_program_in_path ("sh");
g_assert (res != NULL);
g_free (res);
res = g_find_program_in_path ("/bin/sh");
g_assert (res != NULL);
g_free (res);
+#else
+ /* There's not a lot we can search for that would reliably work both
+ * on real Windows and mingw.
+ */
+#endif
res = g_find_program_in_path ("this_program_does_not_exit");
g_assert (res == NULL);
res = g_parse_debug_string ("all", keys, G_N_ELEMENTS (keys));
g_assert_cmpint (res, ==, 7);
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ if (g_test_subprocess ())
{
res = g_parse_debug_string ("help", keys, G_N_ELEMENTS (keys));
g_assert_cmpint (res, ==, 0);
- exit (0);
+ return;
}
+ g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_passed ();
g_test_trap_assert_stderr ("*Supported debug values: key1 key2 key3 all help*");
}
}
static void
+test_codeset2 (void)
+{
+ if (g_test_subprocess ())
+ {
+ const gchar *c;
+ g_setenv ("CHARSET", "UTF-8", TRUE);
+ g_get_charset (&c);
+ g_assert_cmpstr (c, ==, "UTF-8");
+ return;
+ }
+ g_test_trap_subprocess (NULL, 0, 0);
+ g_test_trap_assert_passed ();
+}
+
+static void
test_basename (void)
{
const gchar *path = "/path/to/a/file/deep/down.sh";
}
static void
+test_username (void)
+{
+ const gchar *name;
+
+ name = g_get_user_name ();
+
+ g_assert (name != NULL);
+}
+
+static void
test_realname (void)
{
const gchar *name;
g_assert (name != NULL);
}
+#ifdef G_OS_UNIX
static void
test_xdg_dirs (void)
{
g_assert_cmpstr (s, ==, xdg);
- g_strfreev ((gchar **)dirs);
g_free (s);
}
+#endif
static void
test_special_dir (void)
g_assert_cmpstr (dir, ==, dir2);
}
+static void
+test_desktop_special_dir (void)
+{
+ const gchar *dir, *dir2;
+
+ dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
+ g_assert (dir != NULL);
+
+ g_reload_user_special_dirs_cache ();
+ dir2 = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
+ g_assert (dir2 != NULL);
+}
+
+static void
+test_clear_pointer (void)
+{
+ gpointer a;
+
+ a = g_malloc (5);
+ g_clear_pointer (&a, g_free);
+ g_assert (a == NULL);
+
+ a = g_malloc (5);
+ (g_clear_pointer) (&a, g_free);
+ g_assert (a == NULL);
+}
+
+static void
+test_misc_mem (void)
+{
+ gpointer a;
+
+ a = g_try_malloc (0);
+ g_assert (a == NULL);
+
+ a = g_try_malloc0 (0);
+ g_assert (a == NULL);
+
+ a = g_malloc (16);
+ a = g_try_realloc (a, 20);
+ a = g_try_realloc (a, 0);
+
+ g_assert (a == NULL);
+}
+
+static void
+test_nullify (void)
+{
+ gpointer p = &test_nullify;
+
+ g_assert (p != NULL);
+
+ g_nullify_pointer (&p);
+
+ g_assert (p == NULL);
+}
+
+static void
+atexit_func (void)
+{
+ g_print ("atexit called");
+}
+
+static void
+test_atexit (void)
+{
+ if (g_test_subprocess ())
+ {
+ g_atexit (atexit_func);
+ return;
+ }
+ g_test_trap_subprocess (NULL, 0, 0);
+ g_test_trap_assert_passed ();
+ g_test_trap_assert_stdout ("*atexit called*");
+}
+
+static void
+test_check_setuid (void)
+{
+ gboolean res;
+
+ res = GLIB_PRIVATE_CALL(g_check_setuid) ();
+ g_assert (!res);
+}
+
int
main (int argc,
char *argv[])
g_unsetenv ("TMP");
g_unsetenv ("TEMP");
+ /* g_test_init() only calls g_set_prgname() if g_get_prgname()
+ * returns %NULL, but g_get_prgname() on Windows never returns NULL.
+ * So we need to do this by hand to make test_appname() work on
+ * Windows.
+ */
+ g_set_prgname (argv[0]);
+
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugzilla.gnome.org/");
g_test_add_func ("/utils/find-program", test_find_program);
g_test_add_func ("/utils/debug", test_debug);
g_test_add_func ("/utils/codeset", test_codeset);
+ g_test_add_func ("/utils/codeset2", test_codeset2);
g_test_add_func ("/utils/basename", test_basename);
g_test_add_func ("/utils/gettext", test_gettext);
+ g_test_add_func ("/utils/username", test_username);
g_test_add_func ("/utils/realname", test_realname);
g_test_add_func ("/utils/hostname", test_hostname);
+#ifdef G_OS_UNIX
g_test_add_func ("/utils/xdgdirs", test_xdg_dirs);
+#endif
g_test_add_func ("/utils/specialdir", test_special_dir);
-
- return g_test_run();
+ g_test_add_func ("/utils/specialdir/desktop", test_desktop_special_dir);
+ g_test_add_func ("/utils/clear-pointer", test_clear_pointer);
+ g_test_add_func ("/utils/misc-mem", test_misc_mem);
+ g_test_add_func ("/utils/nullify", test_nullify);
+ g_test_add_func ("/utils/atexit", test_atexit);
+ g_test_add_func ("/utils/check-setuid", test_check_setuid);
+
+ return g_test_run ();
}