GVariant: fix a trivial typo in a comment
[platform/upstream/glib.git] / glib / tests / utils.c
index 9c89bde..2e4a63b 100644 (file)
@@ -24,6 +24,7 @@
 #define GLIB_DISABLE_DEPRECATION_WARNINGS
 
 #include "glib.h"
+#include "glib-private.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -225,8 +226,8 @@ test_swap (void)
 
   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);
 }
@@ -294,12 +295,13 @@ test_debug (void)
   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*");
 }
@@ -319,6 +321,21 @@ test_codeset (void)
 }
 
 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";
@@ -431,7 +448,6 @@ test_xdg_dirs (void)
 
   g_assert_cmpstr (s, ==, xdg);
 
-  g_strfreev ((gchar **)dirs);
   g_free (s);
 }
 #endif
@@ -505,6 +521,34 @@ test_nullify (void)
   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[])
@@ -536,6 +580,7 @@ main (int   argc,
   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);
@@ -549,6 +594,8 @@ main (int   argc,
   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 ();
 }