[glib] Improve option context test coverage
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Improve option context test coverage
- Date: Fri, 30 Jul 2010 23:59:24 +0000 (UTC)
commit 9100828185316503e2da366a8e0de8e361944301
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jul 30 15:35:47 2010 -0400
Improve option context test coverage
glib/tests/option-context.c | 65 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/option-context.c b/glib/tests/option-context.c
index d00171f..a1e6b8a 100644
--- a/glib/tests/option-context.c
+++ b/glib/tests/option-context.c
@@ -1747,6 +1747,69 @@ test_basic (void)
g_option_context_free (context);
}
+static void
+test_main_group (void)
+{
+ GOptionContext *context;
+ GOptionGroup *group;
+
+ context = g_option_context_new (NULL);
+ g_assert (g_option_context_get_main_group (context) == NULL);
+ group = g_option_group_new ("name", "description", "hlep", NULL, NULL);
+ g_option_context_add_group (context, group);
+ g_assert (g_option_context_get_main_group (context) == NULL);
+ group = g_option_group_new ("name", "description", "hlep", NULL, NULL);
+ g_option_context_set_main_group (context, group);
+ g_assert (g_option_context_get_main_group (context) == group);
+
+ g_option_context_free (context);
+}
+
+static gboolean error_func_called = FALSE;
+
+static void
+error_func (GOptionContext *context,
+ GOptionGroup *group,
+ gpointer data,
+ GError **error)
+{
+ g_assert_cmpint (GPOINTER_TO_INT(data), ==, 1234);
+ error_func_called = TRUE;
+}
+
+static void
+test_error_hook (void)
+{
+ GOptionContext *context;
+ gchar *arg = NULL;
+ GOptionEntry entries [] =
+ { { "test", 't', 0, G_OPTION_ARG_STRING, &arg, NULL, NULL },
+ { NULL } };
+ GOptionGroup *group;
+ gchar **argv;
+ gint argc;
+ gboolean retval;
+ GError *error = NULL;
+
+ context = g_option_context_new (NULL);
+ group = g_option_group_new ("name", "description", "hlep", GINT_TO_POINTER(1234), NULL);
+ g_option_group_add_entries (group, entries);
+ g_option_context_set_main_group (context, group);
+ g_option_group_set_error_hook (g_option_context_get_main_group (context),
+ error_func);
+
+ argv = split_string ("program --test", &argc);
+
+ retval = g_option_context_parse (context, &argc, &argv, &error);
+ g_assert (retval == FALSE);
+ g_clear_error (&error);
+
+ g_assert (error_func_called);
+
+ g_strfreev (argv);
+ g_option_context_free (context);
+}
+
int
main (int argc,
char *argv[])
@@ -1757,6 +1820,8 @@ main (int argc,
g_test_add_func ("/option/basic", test_basic);
g_test_add_func ("/option/group/captions", group_captions);
+ g_test_add_func ("/option/group/main", test_main_group);
+ g_test_add_func ("/option/group/error-hook", test_error_hook);
/* Test that restoration on failure works */
g_test_add_func ("/option/restoration/int", error_test1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]