[glib] Test that g_slice_set_config() works



commit bb5d90a76806788c26a6a3ed2c8453b35cb8c86e
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Oct 4 16:36:53 2011 -0400

    Test that g_slice_set_config() works
    
    For a while it didn't work, due to the ctor-based initialisation of
    gslice.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=660887

 glib/tests/.gitignore  |    1 +
 glib/tests/Makefile.am |    3 +++
 glib/tests/slice.c     |   28 ++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/.gitignore b/glib/tests/.gitignore
index 3cc7351..14e053e 100644
--- a/glib/tests/.gitignore
+++ b/glib/tests/.gitignore
@@ -45,6 +45,7 @@ rwlock
 scannerapi
 sequence
 shell
+slice
 slist
 sort
 strfuncs
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 80dd95b..96caa04 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -212,6 +212,9 @@ private_LDADD    = $(progs_ldadd)
 TEST_PROGS      += thread
 thread_LDADD     = $(progs_ldadd)
 
+TEST_PROGS      += slice
+slice_LDADD      = $(progs_ldadd)
+
 if OS_UNIX
 
 TEST_PROGS    += unix
diff --git a/glib/tests/slice.c b/glib/tests/slice.c
new file mode 100644
index 0000000..c1f81ab
--- /dev/null
+++ b/glib/tests/slice.c
@@ -0,0 +1,28 @@
+#include <glib.h>
+
+void
+test_slice_config (void)
+{
+  if (g_test_trap_fork (1000000, G_TEST_TRAP_SILENCE_STDERR))
+    g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE);
+
+  g_test_trap_assert_failed ();
+}
+
+int
+main (int argc, char **argv)
+{
+  /* have to do this before using gtester since it uses gslice */
+  gboolean was;
+
+  was = g_slice_get_config (G_SLICE_CONFIG_ALWAYS_MALLOC);
+  g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, !was);
+  g_assert_cmpint (g_slice_get_config (G_SLICE_CONFIG_ALWAYS_MALLOC), !=, was);
+  g_slice_set_config (G_SLICE_CONFIG_ALWAYS_MALLOC, was);
+
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/slice/config", test_slice_config);
+
+  return g_test_run ();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]