mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
Allow G_OPTION_ARG_CALLBACK for G_OPTION_REMAINING. (#437297, Dave Benson)
2007-05-11 Matthias Clasen <mclasen@redhat.com> * glib/goption.c: Allow G_OPTION_ARG_CALLBACK for G_OPTION_REMAINING. (#437297, Dave Benson) * tests/option-test.c: Add a test for this. svn path=/trunk/; revision=5487
This commit is contained in:
committed by
Matthias Clasen
parent
ec11b71411
commit
8f88ba6ffa
@@ -788,6 +788,48 @@ callback_test_optional_8 (void)
|
||||
g_option_context_free (context);
|
||||
}
|
||||
|
||||
static GPtrArray *callback_remaining_args;
|
||||
static gboolean
|
||||
callback_remaining_test1_callback (const gchar *option_name, const gchar *value,
|
||||
gpointer data, GError **error)
|
||||
{
|
||||
g_ptr_array_add (callback_remaining_args, g_strdup (value));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
callback_remaining_test1 (void)
|
||||
{
|
||||
GOptionContext *context;
|
||||
gboolean retval;
|
||||
GError *error = NULL;
|
||||
gchar **argv;
|
||||
int argc;
|
||||
GOptionEntry entries [] =
|
||||
{ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_CALLBACK, callback_remaining_test1_callback, NULL, NULL },
|
||||
{ NULL } };
|
||||
|
||||
callback_remaining_args = g_ptr_array_new ();
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
|
||||
/* Now try parsing */
|
||||
argv = split_string ("program foo.txt blah.txt", &argc);
|
||||
|
||||
retval = g_option_context_parse (context, &argc, &argv, &error);
|
||||
g_assert (retval);
|
||||
|
||||
g_assert (callback_remaining_args->len == 2);
|
||||
g_assert (strcmp (callback_remaining_args->pdata[0], "foo.txt") == 0);
|
||||
g_assert (strcmp (callback_remaining_args->pdata[1], "blah.txt") == 0);
|
||||
|
||||
g_ptr_array_foreach (callback_remaining_args, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free (callback_remaining_args, TRUE);
|
||||
|
||||
g_strfreev (argv);
|
||||
g_option_context_free (context);
|
||||
}
|
||||
|
||||
void
|
||||
ignore_test1 (void)
|
||||
{
|
||||
@@ -1420,6 +1462,9 @@ main (int argc, char **argv)
|
||||
callback_test_optional_6 ();
|
||||
callback_test_optional_7 ();
|
||||
callback_test_optional_8 ();
|
||||
|
||||
/* Test callback with G_OPTION_REMAINING */
|
||||
callback_remaining_test1 ();
|
||||
|
||||
/* Test ignoring options */
|
||||
ignore_test1 ();
|
||||
|
Reference in New Issue
Block a user