[glib] Test an option handling corner-case
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Test an option handling corner-case
- Date: Thu, 5 Aug 2010 06:25:34 +0000 (UTC)
commit 008615f9999641158a89e3e6163b1580cac53dd0
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Aug 5 02:23:42 2010 -0400
Test an option handling corner-case
glib/tests/option-context.c | 59 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 58 insertions(+), 1 deletions(-)
---
diff --git a/glib/tests/option-context.c b/glib/tests/option-context.c
index a1e6b8a..ffb4d13 100644
--- a/glib/tests/option-context.c
+++ b/glib/tests/option-context.c
@@ -1708,7 +1708,7 @@ missing_arg_test (void)
g_strfreev (argv);
/* Try parsing again */
- argv = split_string ("program --t", &argc);
+ argv = split_string ("program -t", &argc);
retval = g_option_context_parse (context, &argc, &argv, &error);
g_assert (retval == FALSE);
@@ -1717,6 +1717,62 @@ missing_arg_test (void)
g_option_context_free (context);
}
+static gchar *test_arg;
+
+static gboolean cb (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ test_arg = g_strdup (value);
+ return TRUE;
+}
+
+void
+dash_arg_test (void)
+{
+ GOptionContext *context;
+ gboolean retval;
+ GError *error = NULL;
+ gchar **argv;
+ int argc;
+ gboolean argb = FALSE;
+ GOptionEntry entries [] =
+ { { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, cb, NULL, NULL },
+ { "three", '3', 0, G_OPTION_ARG_NONE, &argb, NULL, NULL },
+ { NULL } };
+
+ g_test_bug ("577638");
+
+ context = g_option_context_new (NULL);
+ g_option_context_add_main_entries (context, entries, NULL);
+
+ /* Now try parsing */
+ argv = split_string ("program --test=-3", &argc);
+
+ test_arg = NULL;
+ error = NULL;
+ retval = g_option_context_parse (context, &argc, &argv, &error);
+ g_assert (retval);
+ g_assert_no_error (error);
+ g_assert_cmpstr (test_arg, ==, "-3");
+
+ g_strfreev (argv);
+ g_free (test_arg);
+ test_arg = NULL;
+
+ /* Try parsing again */
+ argv = split_string ("program --test -3", &argc);
+
+ error = NULL;
+ retval = g_option_context_parse (context, &argc, &argv, &error);
+ g_assert_no_error (error);
+ g_assert (retval);
+ g_assert_cmpstr (test_arg, ==, NULL);
+
+ g_option_context_free (context);
+}
+
static void
test_basic (void)
{
@@ -1886,6 +1942,7 @@ main (int argc,
g_test_add_func ("/option/bug/unknown-short", unknown_short_test);
g_test_add_func ("/option/bug/lonely-dash", lonely_dash_test);
g_test_add_func ("/option/bug/missing-arg", missing_arg_test);
+ g_test_add_func ("/option/bug/dash-arg", dash_arg_test);
return g_test_run();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]