[glib/new-gsettings] More tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/new-gsettings] More tests
- Date: Wed, 14 Apr 2010 22:27:33 +0000 (UTC)
commit 0b1b1582b84d9e48cd5b181310f495844835747f
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Apr 14 17:35:31 2010 -0400
More tests
gio/tests/gsettings.c | 173 ++++++++++++++++++++++++++++++++++++++++
gio/tests/org.gtk.test.gschema | 46 +++++++++++
2 files changed, 219 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c
index cade882..e3ed67c 100644
--- a/gio/tests/gsettings.c
+++ b/gio/tests/gsettings.c
@@ -1,4 +1,6 @@
+#include <stdlib.h>
#include <gio.h>
+#include <gstdio.h>
static void
test_basic (void)
@@ -22,15 +24,186 @@ test_basic (void)
/* FIXME: currently, the integer write is not failing, so we get hte schema default here */
g_assert_cmpstr (str, ==, "goodbye world");
#endif
+ g_settings_set (settings, "greeting", "s", "this is the end");
+}
+
+static void
+test_unknown_key (void)
+{
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ {
+ GSettings *settings;
+ GVariant *value;
+
+ settings = g_settings_new ("org.gtk.test");
+ value = g_settings_get_value (settings, "no_such_key");
+ }
+ g_test_trap_assert_failed ();
+ g_test_trap_assert_stderr ("*CRITICAL*");
+}
+
+void
+test_no_schema (void)
+{
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ {
+ GSettings *settings;
+
+ settings = g_settings_new ("no.such.schema");
+ }
+
+ g_test_trap_assert_failed ();
+ g_test_trap_assert_stderr ("*Settings schema 'no.such.schema' is not installed*");
+}
+
+static void
+test_wrong_type (void)
+{
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ {
+ GSettings *settings;
+ gchar *str = NULL;
+
+ settings = g_settings_new ("org.gtk.test");
+
+ g_settings_get (settings, "greetings", "o", &str);
+ }
+ g_test_trap_assert_failed ();
+ g_test_trap_assert_stderr ("*CRITICAL*");
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
+ {
+ GSettings *settings;
+ gchar *str = NULL;
+
+ settings = g_settings_new ("org.gtk.test");
+
+ g_settings_set (settings, "greetings", "o", &str);
+ }
+ g_test_trap_assert_failed ();
+ g_test_trap_assert_stderr ("*CRITICAL*");
+}
+
+static void
+test_basic_types (void)
+{
+ GSettings *settings;
+ gboolean b;
+ guint8 byte;
+ gint16 i16;
+ guint16 u16;
+ gint32 i32;
+ guint32 u32;
+ gint64 i64;
+ guint64 u64;
+ gdouble d;
+ gchar *str;
+
+ settings = g_settings_new ("org.gtk.test.basic-types");
+
+ g_settings_get (settings, "test_boolean", "b", &b);
+ g_assert_cmpint (b, ==, 1);
+
+ g_settings_set (settings, "test_boolean", "b", 0);
+ g_settings_get (settings, "test_boolean", "b", &b);
+ g_assert_cmpint (b, ==, 0);
+
+ g_settings_get (settings, "test_byte", "y", &byte);
+ g_assert_cmpint (byte, ==, 25);
+
+ g_settings_set (settings, "test_byte", "y", G_MAXUINT8);
+ g_settings_get (settings, "test_byte", "y", &byte);
+ g_assert_cmpint (byte, ==, G_MAXUINT8);
+
+ g_settings_get (settings, "test_int16", "n", &i16);
+ g_assert_cmpint (i16, ==, -1234);
+
+ g_settings_set (settings, "test_int16", "n", G_MININT16);
+ g_settings_get (settings, "test_int16", "n", &i16);
+ g_assert_cmpint (i16, ==, G_MININT16);
+
+ g_settings_set (settings, "test_int16", "n", G_MAXINT16);
+ g_settings_get (settings, "test_int16", "n", &i16);
+ g_assert_cmpint (i16, ==, G_MAXINT16);
+
+ g_settings_get (settings, "test_uint16", "q", &u16);
+ g_assert_cmpuint (u16, ==, 1234);
+
+ g_settings_set (settings, "test_uint16", "q", G_MAXUINT16);
+ g_settings_get (settings, "test_uint16", "q", &u16);
+ g_assert_cmpuint (u16, ==, G_MAXUINT16);
+
+ g_settings_get (settings, "test_int32", "i", &i32);
+ g_assert_cmpint (i32, ==, -123456);
+
+ g_settings_set (settings, "test_int32", "i", G_MININT32);
+ g_settings_get (settings, "test_int32", "i", &i32);
+ g_assert_cmpint (i32, ==, G_MININT32);
+
+ g_settings_set (settings, "test_int32", "i", G_MAXINT32);
+ g_settings_get (settings, "test_int32", "i", &i32);
+ g_assert_cmpint (i32, ==, G_MAXINT32);
+
+ g_settings_get (settings, "test_uint32", "u", &u32);
+ g_assert_cmpuint (u32, ==, 123456);
+
+ g_settings_set (settings, "test_uint32", "u", G_MAXUINT32);
+ g_settings_get (settings, "test_uint32", "u", &u32);
+ g_assert_cmpuint (u32, ==, G_MAXUINT32);
+
+ g_settings_get (settings, "test_int64", "x", &i64);
+ g_assert_cmpuint (i64, ==, -123456789);
+
+ g_settings_set (settings, "test_int64", "x", G_MININT64);
+ g_settings_get (settings, "test_int64", "x", &i64);
+ g_assert_cmpuint (i64, ==, G_MININT64);
+
+ g_settings_set (settings, "test_int64", "x", G_MAXINT64);
+ g_settings_get (settings, "test_int64", "x", &i64);
+ g_assert_cmpuint (i64, ==, G_MAXINT64);
+
+ g_settings_get (settings, "test_uint64", "t", &u64);
+ g_assert_cmpuint (u64, ==, 123456789);
+
+ g_settings_set (settings, "test_uint64", "t", G_MAXUINT64);
+ g_settings_get (settings, "test_uint64", "t", &u64);
+ g_assert_cmpuint (u64, ==, G_MAXUINT64);
+
+ g_settings_get (settings, "test_double", "d", &d);
+ g_assert_cmpfloat (d, ==, 123.456);
+
+ g_settings_set (settings, "test_double", "d", G_MINDOUBLE);
+ g_settings_get (settings, "test_double", "d", &d);
+ g_assert_cmpfloat (d, ==, G_MINDOUBLE);
+
+ g_settings_set (settings, "test_double", "d", G_MAXDOUBLE);
+ g_settings_get (settings, "test_double", "d", &d);
+ g_assert_cmpfloat (d, ==, G_MAXDOUBLE);
+
+ g_settings_get (settings, "test_string", "s", &str);
+ g_assert_cmpstr (str, ==, "a string, it seems");
+
+ g_settings_get (settings, "test_objectpath", "o", &str);
+ g_assert_cmpstr (str, ==, "/a/object/path");
}
int
main (int argc, char *argv[])
{
+ g_setenv ("GSETTINGS_SCHEMA_DIR", ".", TRUE);
+ g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
+ g_setenv ("GSETTINGS_MEMORY_BACKEND_STORE", "./store", TRUE);
+
+ g_remove ("./store");
+
g_type_init ();
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/gsettings/basic", test_basic);
+ g_test_add_func ("/gsettings/no-schema", test_no_schema);
+ g_test_add_func ("/gsettings/unknown-key", test_unknown_key);
+ g_test_add_func ("/gsettings/wrong-type", test_wrong_type);
+ g_test_add_func ("/gsettings/basic-types", test_basic_types);
return g_test_run ();
}
diff --git a/gio/tests/org.gtk.test.gschema b/gio/tests/org.gtk.test.gschema
new file mode 100644
index 0000000..ecd88ad
--- /dev/null
+++ b/gio/tests/org.gtk.test.gschema
@@ -0,0 +1,46 @@
+<schemalist>
+ <schema id="org.gtk.test" path="/tests/" gettext-domain="test">
+ <key name="greeting" type="s">
+ <default l10n="true">"Hello, earthlings"</default>
+ <summary>A greeting</summary>
+ <description>
+ Greeting of the invading martians
+ </description>
+ </key>
+ </schema>
+ <schema id="org.gtk.test.basic-types" path="/tests/basic_types/" gettext-domain="test">
+ <key name="test_boolean" type="b">
+ <default>true</default>
+ </key>
+ <key name="test_byte" type="y">
+ <default>25</default>
+ </key>
+ <key name="test_int16" type="n">
+ <default>-1234</default>
+ </key>
+ <key name="test_uint16" type="q">
+ <default>1234</default>
+ </key>
+ <key name="test_int32" type="i">
+ <default>-123456</default>
+ </key>
+ <key name="test_uint32" type="u">
+ <default>123456</default>
+ </key>
+ <key name="test_int64" type="x">
+ <default>-123456789</default>
+ </key>
+ <key name="test_uint64" type="t">
+ <default>123456789</default>
+ </key>
+ <key name="test_double" type="d">
+ <default>123.456</default>
+ </key>
+ <key name="test_string" type="s">
+ <default>"a string, it seems"</default>
+ </key>
+ <key name="test_objectpath" type="o">
+ <default>"/a/object/path"</default>
+ </key>
+ </schema>
+</schemalist>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]