mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Set arg_data on filenames. (Discovered by Mats-Ola Persson).
2004-10-03 Anders Carlsson <andersca@gnome.org> * glib/goption.c: (parse_arg): Set arg_data on filenames. (Discovered by Mats-Ola Persson). * tests/option-test.c: (arg_test3), (ignore_test3), (main): Add test for filename args.
This commit is contained in:
parent
7b752f10b6
commit
a515025dee
@ -1,3 +1,11 @@
|
||||
2004-10-03 Anders Carlsson <andersca@gnome.org>
|
||||
|
||||
* glib/goption.c: (parse_arg):
|
||||
Set arg_data on filenames. (Discovered by Mats-Ola Persson).
|
||||
|
||||
* tests/option-test.c: (arg_test3), (ignore_test3), (main):
|
||||
Add test for filename args.
|
||||
|
||||
2004-10-01 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* glib/goption.c (g_option_context_parse): Use
|
||||
|
@ -1,3 +1,11 @@
|
||||
2004-10-03 Anders Carlsson <andersca@gnome.org>
|
||||
|
||||
* glib/goption.c: (parse_arg):
|
||||
Set arg_data on filenames. (Discovered by Mats-Ola Persson).
|
||||
|
||||
* tests/option-test.c: (arg_test3), (ignore_test3), (main):
|
||||
Add test for filename args.
|
||||
|
||||
2004-10-01 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* glib/goption.c (g_option_context_parse): Use
|
||||
|
@ -1,3 +1,11 @@
|
||||
2004-10-03 Anders Carlsson <andersca@gnome.org>
|
||||
|
||||
* glib/goption.c: (parse_arg):
|
||||
Set arg_data on filenames. (Discovered by Mats-Ola Persson).
|
||||
|
||||
* tests/option-test.c: (arg_test3), (ignore_test3), (main):
|
||||
Add test for filename args.
|
||||
|
||||
2004-10-01 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* glib/goption.c (g_option_context_parse): Use
|
||||
|
@ -1,3 +1,11 @@
|
||||
2004-10-03 Anders Carlsson <andersca@gnome.org>
|
||||
|
||||
* glib/goption.c: (parse_arg):
|
||||
Set arg_data on filenames. (Discovered by Mats-Ola Persson).
|
||||
|
||||
* tests/option-test.c: (arg_test3), (ignore_test3), (main):
|
||||
Add test for filename args.
|
||||
|
||||
2004-10-01 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* glib/goption.c (g_option_context_parse): Use
|
||||
|
@ -1,3 +1,11 @@
|
||||
2004-10-03 Anders Carlsson <andersca@gnome.org>
|
||||
|
||||
* glib/goption.c: (parse_arg):
|
||||
Set arg_data on filenames. (Discovered by Mats-Ola Persson).
|
||||
|
||||
* tests/option-test.c: (arg_test3), (ignore_test3), (main):
|
||||
Add test for filename args.
|
||||
|
||||
2004-10-01 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* glib/goption.c (g_option_context_parse): Use
|
||||
|
@ -542,6 +542,7 @@ parse_arg (GOptionContext *context,
|
||||
change->prev.str = *(gchar **)entry->arg_data;
|
||||
change->allocated.str = data;
|
||||
|
||||
*(gchar **)entry->arg_data = data;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ gboolean error_test3_boolean;
|
||||
|
||||
int arg_test1_int;
|
||||
gchar *arg_test2_string;
|
||||
gchar *arg_test3_filename;
|
||||
|
||||
gchar **array_test1_array;
|
||||
|
||||
@ -294,6 +295,36 @@ arg_test2 (void)
|
||||
g_option_context_free (context);
|
||||
}
|
||||
|
||||
void
|
||||
arg_test3 (void)
|
||||
{
|
||||
GOptionContext *context;
|
||||
gboolean retval;
|
||||
GError *error = NULL;
|
||||
gchar **argv;
|
||||
int argc;
|
||||
GOptionEntry entries [] =
|
||||
{ { "test", 0, 0, G_OPTION_ARG_FILENAME, &arg_test3_filename, NULL, NULL },
|
||||
{ NULL } };
|
||||
|
||||
context = g_option_context_new (NULL);
|
||||
g_option_context_add_main_entries (context, entries, NULL);
|
||||
|
||||
/* Now try parsing */
|
||||
argv = split_string ("program --test foo.txt", &argc);
|
||||
|
||||
retval = g_option_context_parse (context, &argc, &argv, &error);
|
||||
g_assert (retval);
|
||||
|
||||
/* Last arg specified is the one that should be stored */
|
||||
g_assert (strcmp (arg_test3_filename, "foo.txt") == 0);
|
||||
|
||||
g_free (arg_test3_filename);
|
||||
|
||||
g_strfreev (argv);
|
||||
g_option_context_free (context);
|
||||
}
|
||||
|
||||
void
|
||||
ignore_test1 (void)
|
||||
{
|
||||
@ -391,24 +422,6 @@ ignore_test3 (void)
|
||||
g_assert (strcmp (ignore_test3_string, "foo") == 0);
|
||||
g_free (ignore_test3_string);
|
||||
|
||||
g_free (arg);
|
||||
g_strfreev (argv_copy);
|
||||
g_free (argv);
|
||||
|
||||
/* Try again */
|
||||
argv = split_string ("program --test=foo --hello", &argc);
|
||||
argv_copy = copy_stringv (argv, argc);
|
||||
|
||||
retval = g_option_context_parse (context, &argc, &argv, &error);
|
||||
g_assert (retval);
|
||||
|
||||
/* Check array */
|
||||
arg = join_stringv (argc, argv);
|
||||
g_assert (strcmp (arg, "program --hello") == 0);
|
||||
|
||||
g_assert (strcmp (ignore_test3_string, "foo") == 0);
|
||||
g_free (ignore_test3_string);
|
||||
|
||||
g_free (arg);
|
||||
g_strfreev (argv_copy);
|
||||
g_free (argv);
|
||||
@ -509,6 +522,7 @@ main (int argc, char **argv)
|
||||
/* Test that special argument parsing works */
|
||||
arg_test1 ();
|
||||
arg_test2 ();
|
||||
arg_test3 ();
|
||||
|
||||
/* Test string arrays */
|
||||
array_test1 ();
|
||||
|
Loading…
Reference in New Issue
Block a user