First public contribution.
1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. */
6 #include <glib_global.h>
7 #include "mrt2_glib2_test.h"
10 char *error_test2_string;
11 gboolean error_test3_boolean;
14 gchar *arg_test2_string;
15 gchar *arg_test3_filename;
17 gchar *callback_test1_string;
18 gboolean callback_test2_int;
20 gchar *callback_test_optional_string;
21 gboolean callback_test_optional_boolean;
23 gchar **array_test1_array;
25 gboolean ignore_test1_boolean;
26 gboolean ignore_test2_boolean;
27 gchar *ignore_test3_string;
30 split_string (const char *str, int *argc)
35 argv = g_strsplit (str, " ", 0);
37 for (len = 0; argv[len] != NULL; len++);
46 join_stringv (int argc, char **argv)
51 str = g_string_new (NULL);
53 for (i = 0; i < argc; i++)
55 g_string_append (str, argv[i]);
58 g_string_append_c (str, ' ');
61 return g_string_free (str, FALSE);
64 /* Performs a shallow copy */
66 copy_stringv (char **argv, int argc)
68 return g_memdup (argv, sizeof (char *) * (argc + 1));
73 error_test1_pre_parse (GOptionContext *context,
78 g_assert (error_test1_int == 0x12345678);
84 error_test1_post_parse (GOptionContext *context,
89 g_assert (error_test1_int == 20);
91 /* Set an error in the post hook */
92 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "");
100 GOptionContext *context;
102 GError *error = NULL;
105 GOptionGroup *main_group;
107 GOptionEntry entries [] =
108 { { "test", 0, 0, G_OPTION_ARG_INT, &error_test1_int, NULL, NULL },
112 GOptionEntry entries [2];
114 entries[0].long_name = "test";
115 entries[0].short_name = 0;
116 entries[0].flags = 0;
117 entries[0].arg = G_OPTION_ARG_INT;
118 entries[0].arg_data = (gpointer)&error_test1_int;
119 entries[0].description = NULL;
120 entries[0].arg_description = NULL;
122 entries[1].long_name = NULL;
123 entries[1].short_name = 0;
124 entries[1].arg_data = NULL;
125 entries[1].description = NULL;
126 entries[1].arg_description = NULL;
129 context = g_option_context_new (NULL);
130 g_option_context_add_main_entries (context, entries, NULL);
132 /* Set pre and post parse hooks */
133 main_group = g_option_context_get_main_group (context);
134 g_option_group_set_parse_hooks (main_group,
135 error_test1_pre_parse, error_test1_post_parse);
137 /* Now try parsing */
138 argv = split_string ("program --test 20", &argc);
140 retval = g_option_context_parse (context, &argc, &argv, &error);
141 g_assert (retval == FALSE);
143 /* On failure, values should be reset */
144 g_assert (error_test1_int == 0x12345678);
147 g_option_context_free (context);
152 error_test2_pre_parse (GOptionContext *context,
157 g_assert (strcmp (error_test2_string, "foo") == 0);
163 error_test2_post_parse (GOptionContext *context,
168 g_assert (strcmp (error_test2_string, "bar") == 0);
170 /* Set an error in the post hook */
171 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "");
179 GOptionContext *context;
181 GError *error = NULL;
184 GOptionGroup *main_group;
186 GOptionEntry entries [] =
187 { { "test", 0, 0, G_OPTION_ARG_STRING, &error_test2_string, NULL, NULL },
190 GOptionEntry entries [2];
192 entries[0].long_name = "test";
193 entries[0].short_name = 0;
194 entries[0].flags = 0;
195 entries[0].arg = G_OPTION_ARG_STRING;
196 entries[0].arg_data = (gpointer)&error_test2_string;
197 entries[0].description = NULL;
198 entries[0].arg_description = NULL;
200 entries[1].long_name = NULL;
201 entries[1].short_name = 0;
202 entries[1].arg_data = NULL;
203 entries[1].description = NULL;
204 entries[1].arg_description = NULL;
208 context = g_option_context_new (NULL);
209 g_option_context_add_main_entries (context, entries, NULL);
211 /* Set pre and post parse hooks */
212 main_group = g_option_context_get_main_group (context);
213 g_option_group_set_parse_hooks (main_group,
214 error_test2_pre_parse, error_test2_post_parse);
216 /* Now try parsing */
217 argv = split_string ("program --test bar", &argc);
218 retval = g_option_context_parse (context, &argc, &argv, &error);
220 g_error_free (error);
221 g_assert (retval == FALSE);
223 g_assert (strcmp (error_test2_string, "foo") == 0);
226 g_option_context_free (context);
230 error_test3_pre_parse (GOptionContext *context,
235 g_assert (!error_test3_boolean);
241 error_test3_post_parse (GOptionContext *context,
246 g_assert (error_test3_boolean);
248 /* Set an error in the post hook */
249 g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "");
257 GOptionContext *context;
259 GError *error = NULL;
262 GOptionGroup *main_group;
265 GOptionEntry entries [] =
266 { { "test", 0, 0, G_OPTION_ARG_NONE, &error_test3_boolean, NULL, NULL },
269 GOptionEntry entries [2];
271 entries[0].long_name = "test";
272 entries[0].short_name = 0;
273 entries[0].flags = 0;
274 entries[0].arg = G_OPTION_ARG_NONE;
275 entries[0].arg_data = (gpointer)&error_test3_boolean;
276 entries[0].description = NULL;
277 entries[0].arg_description = NULL;
279 entries[1].long_name = NULL;
280 entries[1].short_name = 0;
281 entries[1].arg_data = NULL;
282 entries[1].description = NULL;
283 entries[1].arg_description = NULL;
287 context = g_option_context_new (NULL);
288 g_option_context_add_main_entries (context, entries, NULL);
290 /* Set pre and post parse hooks */
291 main_group = g_option_context_get_main_group (context);
292 g_option_group_set_parse_hooks (main_group,
293 error_test3_pre_parse, error_test3_post_parse);
295 /* Now try parsing */
296 argv = split_string ("program --test", &argc);
297 retval = g_option_context_parse (context, &argc, &argv, &error);
299 g_error_free (error);
300 g_assert (retval == FALSE);
302 g_assert (!error_test3_boolean);
305 g_option_context_free (context);
311 GOptionContext *context;
313 GError *error = NULL;
317 GOptionEntry entries [] =
318 { { "test", 0, 0, G_OPTION_ARG_INT, &arg_test1_int, NULL, NULL },
321 GOptionEntry entries [2];
323 entries[0].long_name = "test";
324 entries[0].short_name = 0;
325 entries[0].flags = 0;
326 entries[0].arg = G_OPTION_ARG_INT;
327 entries[0].arg_data = (gpointer)&arg_test1_int;
328 entries[0].description = NULL;
329 entries[0].arg_description = NULL;
331 entries[1].long_name = NULL;
332 entries[1].short_name = 0;
333 entries[1].arg_data = NULL;
334 entries[1].description = NULL;
335 entries[1].arg_description = NULL;
338 context = g_option_context_new (NULL);
339 g_option_context_add_main_entries (context, entries, NULL);
341 /* Now try parsing */
342 argv = split_string ("program --test 20 --test 30", &argc);
344 retval = g_option_context_parse (context, &argc, &argv, &error);
347 /* Last arg specified is the one that should be stored */
348 g_assert (arg_test1_int == 30);
351 g_option_context_free (context);
357 GOptionContext *context;
359 GError *error = NULL;
363 GOptionEntry entries [] =
364 { { "test", 0, 0, G_OPTION_ARG_STRING, &arg_test2_string, NULL, NULL },
367 GOptionEntry entries [2];
369 entries[0].long_name = "test";
370 entries[0].short_name = 0;
371 entries[0].flags = 0;
372 entries[0].arg = G_OPTION_ARG_STRING;
373 entries[0].arg_data = (gpointer)&arg_test2_string;
374 entries[0].description = NULL;
375 entries[0].arg_description = NULL;
377 entries[1].long_name = NULL;
378 entries[1].short_name = 0;
379 entries[1].arg_data = NULL;
380 entries[1].description = NULL;
381 entries[1].arg_description = NULL;
384 context = g_option_context_new (NULL);
385 g_option_context_add_main_entries (context, entries, NULL);
387 /* Now try parsing */
388 argv = split_string ("program --test foo --test bar", &argc);
390 retval = g_option_context_parse (context, &argc, &argv, &error);
393 /* Last arg specified is the one that should be stored */
394 g_assert (strcmp (arg_test2_string, "bar") == 0);
396 g_free (arg_test2_string);
399 g_option_context_free (context);
405 GOptionContext *context;
407 GError *error = NULL;
411 GOptionEntry entries [] =
412 { { "test", 0, 0, G_OPTION_ARG_FILENAME, &arg_test3_filename, NULL, NULL },
415 GOptionEntry entries [2];
417 entries[0].long_name = "test";
418 entries[0].short_name = 0;
419 entries[0].flags = 0;
420 entries[0].arg = G_OPTION_ARG_FILENAME;
421 entries[0].arg_data = (gpointer)&arg_test3_filename;
422 entries[0].description = NULL;
423 entries[0].arg_description = NULL;
425 entries[1].long_name = NULL;
426 entries[1].short_name = 0;
427 entries[1].arg_data = NULL;
428 entries[1].description = NULL;
429 entries[1].arg_description = NULL;
432 context = g_option_context_new (NULL);
433 g_option_context_add_main_entries (context, entries, NULL);
435 /* Now try parsing */
436 argv = split_string ("program --test foo.txt", &argc);
438 retval = g_option_context_parse (context, &argc, &argv, &error);
441 /* Last arg specified is the one that should be stored */
442 g_assert (strcmp (arg_test3_filename, "foo.txt") == 0);
444 g_free (arg_test3_filename);
447 g_option_context_free (context);
451 callback_parse1 (const gchar *option_name, const gchar *value,
452 gpointer data, GError **error)
454 callback_test1_string = g_strdup (value);
459 callback_test1 (void)
461 GOptionContext *context;
463 GError *error = NULL;
467 GOptionEntry entries [] =
468 { { "test", 0, 0, G_OPTION_ARG_CALLBACK, callback_parse1, NULL, NULL },
471 GOptionEntry entries [2];
473 entries[0].long_name = "test";
474 entries[0].short_name = 0;
475 entries[0].flags = 0;
476 entries[0].arg = G_OPTION_ARG_CALLBACK;
477 entries[0].arg_data = (gpointer)callback_parse1;
478 entries[0].description = NULL;
479 entries[0].arg_description = NULL;
481 entries[1].long_name = NULL;
482 entries[1].short_name = 0;
483 entries[1].arg_data = NULL;
484 entries[1].description = NULL;
485 entries[1].arg_description = NULL;
488 context = g_option_context_new (NULL);
489 g_option_context_add_main_entries (context, entries, NULL);
491 /* Now try parsing */
492 argv = split_string ("program --test foo.txt", &argc);
494 retval = g_option_context_parse (context, &argc, &argv, &error);
497 g_assert (strcmp (callback_test1_string, "foo.txt") == 0);
499 g_free (callback_test1_string);
502 g_option_context_free (context);
506 callback_parse2 (const gchar *option_name, const gchar *value,
507 gpointer data, GError **error)
509 callback_test2_int++;
514 callback_test2 (void)
516 GOptionContext *context;
518 GError *error = NULL;
523 GOptionEntry entries [] =
524 { { "test", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, callback_parse2, NULL, NULL },
527 GOptionEntry entries [2];
529 entries[0].long_name = "test";
530 entries[0].short_name = 0;
531 entries[0].flags = G_OPTION_FLAG_NO_ARG;
532 entries[0].arg = G_OPTION_ARG_CALLBACK;
533 entries[0].arg_data = (gpointer)callback_parse2;
534 entries[0].description = NULL;
535 entries[0].arg_description = NULL;
537 entries[1].long_name = NULL;
538 entries[1].short_name = 0;
539 entries[1].arg_data = NULL;
540 entries[1].description = NULL;
541 entries[1].arg_description = NULL;
544 context = g_option_context_new (NULL);
545 g_option_context_add_main_entries (context, entries, NULL);
547 /* Now try parsing */
548 argv = split_string ("program --test --test", &argc);
550 retval = g_option_context_parse (context, &argc, &argv, &error);
553 g_assert (callback_test2_int == 2);
556 g_option_context_free (context);
560 callback_parse_optional (const gchar *option_name, const gchar *value,
561 gpointer data, GError **error)
563 callback_test_optional_boolean = TRUE;
565 callback_test_optional_string = g_strdup (value);
567 callback_test_optional_string = NULL;
572 callback_test_optional_1 (void)
574 GOptionContext *context;
576 GError *error = NULL;
580 GOptionEntry entries [] =
581 { { "test", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
582 callback_parse_optional, NULL, NULL },
585 GOptionEntry entries [2];
587 entries[0].long_name = "test";
588 entries[0].short_name = 0;
589 entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
590 entries[0].arg = G_OPTION_ARG_CALLBACK;
591 entries[0].arg_data = (gpointer)callback_parse_optional;
592 entries[0].description = NULL;
593 entries[0].arg_description = NULL;
595 entries[1].long_name = NULL;
596 entries[1].short_name = 0;
597 entries[1].arg_data = NULL;
598 entries[1].description = NULL;
599 entries[1].arg_description = NULL;
602 context = g_option_context_new (NULL);
603 g_option_context_add_main_entries (context, entries, NULL);
605 /* Now try parsing */
606 argv = split_string ("program --test foo.txt", &argc);
608 retval = g_option_context_parse (context, &argc, &argv, &error);
611 g_assert (strcmp (callback_test_optional_string, "foo.txt") == 0);
613 g_assert (callback_test_optional_boolean);
615 g_free (callback_test_optional_string);
618 g_option_context_free (context);
622 callback_test_optional_2 (void)
624 GOptionContext *context;
626 GError *error = NULL;
630 GOptionEntry entries [] =
631 { { "test", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
632 callback_parse_optional, NULL, NULL },
635 GOptionEntry entries [2];
637 entries[0].long_name = "test";
638 entries[0].short_name = 0;
639 entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
640 entries[0].arg = G_OPTION_ARG_CALLBACK;
641 entries[0].arg_data = (gpointer)callback_parse_optional;
642 entries[0].description = NULL;
643 entries[0].arg_description = NULL;
645 entries[1].long_name = NULL;
646 entries[1].short_name = 0;
647 entries[1].arg_data = NULL;
648 entries[1].description = NULL;
649 entries[1].arg_description = NULL;
652 context = g_option_context_new (NULL);
653 g_option_context_add_main_entries (context, entries, NULL);
655 /* Now try parsing */
656 argv = split_string ("program --test", &argc);
658 retval = g_option_context_parse (context, &argc, &argv, &error);
661 g_assert (callback_test_optional_string == NULL);
663 g_assert (callback_test_optional_boolean);
665 g_free (callback_test_optional_string);
668 g_option_context_free (context);
672 callback_test_optional_3 (void)
674 GOptionContext *context;
676 GError *error = NULL;
680 GOptionEntry entries [] =
681 { { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
682 callback_parse_optional, NULL, NULL },
685 GOptionEntry entries [2];
687 entries[0].long_name = "test";
688 entries[0].short_name = 't';
689 entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
690 entries[0].arg = G_OPTION_ARG_CALLBACK;
691 entries[0].arg_data = (gpointer)callback_parse_optional;
692 entries[0].description = NULL;
693 entries[0].arg_description = NULL;
695 entries[1].long_name = NULL;
696 entries[1].short_name = 0;
697 entries[1].arg_data = NULL;
698 entries[1].description = NULL;
699 entries[1].arg_description = NULL;
702 context = g_option_context_new (NULL);
703 g_option_context_add_main_entries (context, entries, NULL);
705 /* Now try parsing */
706 argv = split_string ("program -t foo.txt", &argc);
708 retval = g_option_context_parse (context, &argc, &argv, &error);
711 g_assert (strcmp (callback_test_optional_string, "foo.txt") == 0);
713 g_assert (callback_test_optional_boolean);
715 g_free (callback_test_optional_string);
718 g_option_context_free (context);
723 callback_test_optional_4 (void)
725 GOptionContext *context;
727 GError *error = NULL;
731 GOptionEntry entries [] =
732 { { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
733 callback_parse_optional, NULL, NULL },
736 GOptionEntry entries [2];
738 entries[0].long_name = "test";
739 entries[0].short_name = 't';
740 entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
741 entries[0].arg = G_OPTION_ARG_CALLBACK;
742 entries[0].arg_data = (gpointer)callback_parse_optional;
743 entries[0].description = NULL;
744 entries[0].arg_description = NULL;
746 entries[1].long_name = NULL;
747 entries[1].short_name = 0;
748 entries[1].arg_data = NULL;
749 entries[1].description = NULL;
750 entries[1].arg_description = NULL;
753 context = g_option_context_new (NULL);
754 g_option_context_add_main_entries (context, entries, NULL);
756 /* Now try parsing */
757 argv = split_string ("program -t", &argc);
759 retval = g_option_context_parse (context, &argc, &argv, &error);
762 g_assert (callback_test_optional_string == NULL);
764 g_assert (callback_test_optional_boolean);
766 g_free (callback_test_optional_string);
769 g_option_context_free (context);
773 callback_test_optional_5 (void)
775 GOptionContext *context;
778 GError *error = NULL;
782 GOptionEntry entries [] =
783 { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, NULL },
784 { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
785 callback_parse_optional, NULL, NULL },
788 GOptionEntry entries [3];
790 entries[0].long_name = "dummy";
791 entries[0].short_name = 'd';
792 entries[0].flags = 0;
793 entries[0].arg = G_OPTION_ARG_NONE;
794 entries[0].arg_data = (gpointer)&dummy;
795 entries[0].description = NULL;
797 entries[1].long_name = "test";
798 entries[1].short_name = 't';
799 entries[1].flags = G_OPTION_FLAG_OPTIONAL_ARG;
800 entries[1].arg = G_OPTION_ARG_CALLBACK;
801 entries[1].arg_data = (gpointer)callback_parse_optional;
802 entries[1].description = NULL;
803 entries[1].arg_description = NULL;
806 entries[2].long_name = NULL;
807 entries[2].short_name = 0;
808 entries[2].arg_data = NULL;
809 entries[2].description = NULL;
810 entries[2].arg_description = NULL;
813 context = g_option_context_new (NULL);
814 g_option_context_add_main_entries (context, entries, NULL);
816 /* Now try parsing */
817 argv = split_string ("program --test --dummy", &argc);
819 retval = g_option_context_parse (context, &argc, &argv, &error);
822 g_assert (callback_test_optional_string == NULL);
824 g_assert (callback_test_optional_boolean);
826 g_free (callback_test_optional_string);
829 g_option_context_free (context);
833 callback_test_optional_6 (void)
835 GOptionContext *context;
838 GError *error = NULL;
842 GOptionEntry entries [] =
843 { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, NULL },
844 { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
845 callback_parse_optional, NULL, NULL },
848 GOptionEntry entries [3];
850 entries[0].long_name = "dummy";
851 entries[0].short_name = 'd';
852 entries[0].flags = 0;
853 entries[0].arg = G_OPTION_ARG_NONE;
854 entries[0].arg_data = (gpointer)&dummy;
855 entries[0].description = NULL;
857 entries[1].long_name = "test";
858 entries[1].short_name = 't';
859 entries[1].flags = G_OPTION_FLAG_OPTIONAL_ARG;
860 entries[1].arg = G_OPTION_ARG_CALLBACK;
861 entries[1].arg_data = (gpointer)callback_parse_optional;
862 entries[1].description = NULL;
863 entries[1].arg_description = NULL;
866 entries[2].long_name = NULL;
867 entries[2].short_name = 0;
868 entries[2].arg_data = NULL;
869 entries[2].description = NULL;
870 entries[2].arg_description = NULL;
874 context = g_option_context_new (NULL);
875 g_option_context_add_main_entries (context, entries, NULL);
877 /* Now try parsing */
878 argv = split_string ("program -t -d", &argc);
880 retval = g_option_context_parse (context, &argc, &argv, &error);
883 g_assert (callback_test_optional_string == NULL);
885 g_assert (callback_test_optional_boolean);
887 g_free (callback_test_optional_string);
890 g_option_context_free (context);
894 callback_test_optional_7 (void)
896 GOptionContext *context;
899 GError *error = NULL;
903 GOptionEntry entries [] =
904 { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, NULL },
905 { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
906 callback_parse_optional, NULL, NULL },
909 GOptionEntry entries [3];
911 entries[0].long_name = "dummy";
912 entries[0].short_name = 'd';
913 entries[0].flags = 0;
914 entries[0].arg = G_OPTION_ARG_NONE;
915 entries[0].arg_data = (gpointer)&dummy;
916 entries[0].description = NULL;
918 entries[1].long_name = "test";
919 entries[1].short_name = 't';
920 entries[1].flags = G_OPTION_FLAG_OPTIONAL_ARG;
921 entries[1].arg = G_OPTION_ARG_CALLBACK;
922 entries[1].arg_data = (gpointer)callback_parse_optional;
923 entries[1].description = NULL;
924 entries[1].arg_description = NULL;
927 entries[2].long_name = NULL;
928 entries[2].short_name = 0;
929 entries[2].arg_data = NULL;
930 entries[2].description = NULL;
931 entries[2].arg_description = NULL;
935 context = g_option_context_new (NULL);
936 g_option_context_add_main_entries (context, entries, NULL);
938 /* Now try parsing */
939 argv = split_string ("program -td", &argc);
941 retval = g_option_context_parse (context, &argc, &argv, &error);
944 g_assert (callback_test_optional_string == NULL);
946 g_assert (callback_test_optional_boolean);
948 g_free (callback_test_optional_string);
951 g_option_context_free (context);
955 callback_test_optional_8 (void)
957 GOptionContext *context;
960 GError *error = NULL;
964 GOptionEntry entries [] =
965 { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, NULL },
966 { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK,
967 callback_parse_optional, NULL, NULL },
970 GOptionEntry entries [3];
972 entries[0].long_name = "dummy";
973 entries[0].short_name = 'd';
974 entries[0].flags = 0;
975 entries[0].arg = G_OPTION_ARG_NONE;
976 entries[0].arg_data = (gpointer)&dummy;
977 entries[0].description = NULL;
979 entries[1].long_name = "test";
980 entries[1].short_name = 't';
981 entries[1].flags = G_OPTION_FLAG_OPTIONAL_ARG;
982 entries[1].arg = G_OPTION_ARG_CALLBACK;
983 entries[1].arg_data = (gpointer)callback_parse_optional;
984 entries[1].description = NULL;
985 entries[1].arg_description = NULL;
988 entries[2].long_name = NULL;
989 entries[2].short_name = 0;
990 entries[2].arg_data = NULL;
991 entries[2].description = NULL;
992 entries[2].arg_description = NULL;
995 context = g_option_context_new (NULL);
996 g_option_context_add_main_entries (context, entries, NULL);
998 /* Now try parsing */
999 argv = split_string ("program -dt foo.txt", &argc);
1001 retval = g_option_context_parse (context, &argc, &argv, &error);
1004 g_assert (callback_test_optional_string);
1006 g_assert (callback_test_optional_boolean);
1008 g_free (callback_test_optional_string);
1011 g_option_context_free (context);
1017 GOptionContext *context;
1019 GError *error = NULL;
1020 gchar **argv, **argv_copy;
1024 GOptionEntry entries [] =
1025 { { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1028 GOptionEntry entries [2];
1030 entries[0].long_name = "test";
1031 entries[0].short_name = 0;
1032 entries[0].flags = 0;
1033 entries[0].arg = G_OPTION_ARG_NONE;
1034 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1035 entries[0].description = NULL;
1036 entries[0].arg_description = NULL;
1038 entries[1].long_name = NULL;
1039 entries[1].short_name = 0;
1040 entries[1].arg_data = NULL;
1041 entries[1].description = NULL;
1042 entries[1].arg_description = NULL;
1045 context = g_option_context_new (NULL);
1046 g_option_context_set_ignore_unknown_options (context, TRUE);
1047 g_option_context_add_main_entries (context, entries, NULL);
1049 /* Now try parsing */
1050 argv = split_string ("program --test --hello", &argc);
1051 argv_copy = copy_stringv (argv, argc);
1053 retval = g_option_context_parse (context, &argc, &argv, &error);
1057 arg = join_stringv (argc, argv);
1058 g_assert (strcmp (arg, "program --hello") == 0);
1061 g_strfreev (argv_copy);
1063 g_option_context_free (context);
1069 GOptionContext *context;
1071 GError *error = NULL;
1076 GOptionEntry entries [] =
1077 { { "test", 't', 0, G_OPTION_ARG_NONE, &ignore_test2_boolean, NULL, NULL },
1080 GOptionEntry entries [2];
1082 entries[0].long_name = "test";
1083 entries[0].short_name = 't';
1084 entries[0].flags = 0;
1085 entries[0].arg = G_OPTION_ARG_NONE;
1086 entries[0].arg_data = (gpointer)&ignore_test2_boolean;
1087 entries[0].description = NULL;
1088 entries[0].arg_description = NULL;
1090 entries[1].long_name = NULL;
1091 entries[1].short_name = 0;
1092 entries[1].arg_data = NULL;
1093 entries[1].description = NULL;
1094 entries[1].arg_description = NULL;
1097 context = g_option_context_new (NULL);
1098 g_option_context_set_ignore_unknown_options (context, TRUE);
1099 g_option_context_add_main_entries (context, entries, NULL);
1101 /* Now try parsing */
1102 argv = split_string ("program -test", &argc);
1104 retval = g_option_context_parse (context, &argc, &argv, &error);
1108 arg = join_stringv (argc, argv);
1109 g_assert (strcmp (arg, "program -es") == 0);
1113 g_option_context_free (context);
1119 GOptionContext *context;
1121 GError *error = NULL;
1122 gchar **argv, **argv_copy;
1126 GOptionEntry entries [] =
1127 { { "test", 0, 0, G_OPTION_ARG_STRING, &ignore_test3_string, NULL, NULL },
1130 GOptionEntry entries [2];
1132 entries[0].long_name = "test";
1133 entries[0].short_name = 0;
1134 entries[0].flags = 0;
1135 entries[0].arg = G_OPTION_ARG_STRING;
1136 entries[0].arg_data = (gpointer)&ignore_test3_string;
1137 entries[0].description = NULL;
1138 entries[0].arg_description = NULL;
1140 entries[1].long_name = NULL;
1141 entries[1].short_name = 0;
1142 entries[1].arg_data = NULL;
1143 entries[1].description = NULL;
1144 entries[1].arg_description = NULL;
1147 context = g_option_context_new (NULL);
1148 g_option_context_set_ignore_unknown_options (context, TRUE);
1149 g_option_context_add_main_entries (context, entries, NULL);
1151 /* Now try parsing */
1152 argv = split_string ("program --test foo --hello", &argc);
1153 argv_copy = copy_stringv (argv, argc);
1155 retval = g_option_context_parse (context, &argc, &argv, &error);
1159 arg = join_stringv (argc, argv);
1160 g_assert (strcmp (arg, "program --hello") == 0);
1162 g_assert (strcmp (ignore_test3_string, "foo") == 0);
1163 g_free (ignore_test3_string);
1166 g_strfreev (argv_copy);
1168 g_option_context_free (context);
1174 GOptionContext *context;
1176 GError *error = NULL;
1180 GOptionEntry entries [] =
1181 { { "test", 0, 0, G_OPTION_ARG_STRING_ARRAY, &array_test1_array, NULL, NULL },
1184 GOptionEntry entries [2];
1186 entries[0].long_name = "test";
1187 entries[0].short_name = 0;
1188 entries[0].flags = 0;
1189 entries[0].arg = G_OPTION_ARG_STRING_ARRAY;
1190 entries[0].arg_data = (gpointer)&array_test1_array;
1191 entries[0].description = NULL;
1192 entries[0].arg_description = NULL;
1194 entries[1].long_name = NULL;
1195 entries[1].short_name = 0;
1196 entries[1].arg_data = NULL;
1197 entries[1].description = NULL;
1198 entries[1].arg_description = NULL;
1201 context = g_option_context_new (NULL);
1202 g_option_context_add_main_entries (context, entries, NULL);
1204 /* Now try parsing */
1205 argv = split_string ("program --test foo --test bar", &argc);
1207 retval = g_option_context_parse (context, &argc, &argv, &error);
1211 g_assert (strcmp (array_test1_array[0], "foo") == 0);
1212 g_assert (strcmp (array_test1_array[1], "bar") == 0);
1213 g_assert (array_test1_array[2] == NULL);
1215 g_strfreev (array_test1_array);
1218 g_option_context_free (context);
1224 GOptionContext *context;
1227 GOptionEntry entries1 [] =
1228 { { "test1", 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, NULL },
1230 GOptionEntry entries2 [] =
1231 { { "test2", 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, NULL },
1234 GOptionEntry entries1 [2];
1235 GOptionEntry entries2 [2];
1237 entries1[0].long_name = "test1";
1238 entries1[0].short_name = 0;
1239 entries1[0].flags = 0;
1240 entries1[0].arg = G_OPTION_ARG_STRING_ARRAY;
1241 entries1[0].arg_data = NULL;
1242 entries1[0].description = NULL;
1243 entries1[0].arg_description = NULL;
1245 entries1[1].long_name = NULL;
1246 entries1[1].short_name = 0;
1247 entries1[1].arg_data = NULL;
1248 entries1[1].description = NULL;
1249 entries1[1].arg_description = NULL;
1252 entries2[0].long_name = "test2";
1253 entries2[0].short_name = 0;
1254 entries2[0].flags = 0;
1255 entries2[0].arg = G_OPTION_ARG_STRING_ARRAY;
1256 entries2[0].arg_data = NULL;
1257 entries2[0].description = NULL;
1258 entries2[0].arg_description = NULL;
1260 entries2[1].long_name = NULL;
1261 entries2[1].short_name = 0;
1262 entries2[1].arg_data = NULL;
1263 entries2[1].description = NULL;
1264 entries2[1].arg_description = NULL;
1267 context = g_option_context_new (NULL);
1268 g_option_context_add_main_entries (context, entries1, NULL);
1269 g_option_context_add_main_entries (context, entries2, NULL);
1271 g_option_context_free (context);
1277 GOptionContext *context;
1278 GOptionEntry entries [] =
1281 g_set_prgname (NULL);
1283 context = g_option_context_new (NULL);
1285 g_option_context_add_main_entries (context, entries, NULL);
1287 g_option_context_parse (context, NULL, NULL, NULL);
1289 g_assert (strcmp (g_get_prgname (), "<unknown>") == 0);
1291 g_option_context_free (context);
1297 GOptionContext *context;
1299 context = g_option_context_new (NULL);
1300 g_option_context_parse (context, NULL, NULL, NULL);
1302 g_option_context_free (context);
1308 GOptionContext *context;
1315 context = g_option_context_new (NULL);
1316 g_option_context_parse (context, &argc, &argv, NULL);
1318 g_option_context_free (context);
1321 /* check that non-option arguments are left in argv by default */
1325 GOptionContext *context;
1327 GError *error = NULL;
1331 GOptionEntry entries [] = {
1332 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1336 GOptionEntry entries [2];
1338 entries[0].long_name = "test";
1339 entries[0].short_name = 0;
1340 entries[0].flags = 0;
1341 entries[0].arg = G_OPTION_ARG_NONE;
1342 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1343 entries[0].description = NULL;
1344 entries[0].arg_description = NULL;
1346 entries[1].long_name = NULL;
1347 entries[1].short_name = 0;
1348 entries[1].arg_data = NULL;
1349 entries[1].description = NULL;
1350 entries[1].arg_description = NULL;
1353 context = g_option_context_new (NULL);
1354 g_option_context_add_main_entries (context, entries, NULL);
1356 /* Now try parsing */
1357 argv = split_string ("program foo --test bar", &argc);
1359 retval = g_option_context_parse (context, &argc, &argv, &error);
1363 g_assert (ignore_test1_boolean);
1364 g_assert (strcmp (argv[0], "program") == 0);
1365 g_assert (strcmp (argv[1], "foo") == 0);
1366 g_assert (strcmp (argv[2], "bar") == 0);
1367 g_assert (argv[3] == NULL);
1370 g_option_context_free (context);
1373 /* check that -- works */
1377 GOptionContext *context;
1379 GError *error = NULL;
1383 GOptionEntry entries [] = {
1384 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1388 GOptionEntry entries [2];
1390 entries[0].long_name = "test";
1391 entries[0].short_name = 0;
1392 entries[0].flags = 0;
1393 entries[0].arg = G_OPTION_ARG_NONE;
1394 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1395 entries[0].description = NULL;
1396 entries[0].arg_description = NULL;
1398 entries[1].long_name = NULL;
1399 entries[1].short_name = 0;
1400 entries[1].arg_data = NULL;
1401 entries[1].description = NULL;
1402 entries[1].arg_description = NULL;
1405 context = g_option_context_new (NULL);
1406 g_option_context_add_main_entries (context, entries, NULL);
1408 /* Now try parsing */
1409 argv = split_string ("program foo --test -- -bar", &argc);
1411 retval = g_option_context_parse (context, &argc, &argv, &error);
1415 g_assert (ignore_test1_boolean);
1416 g_assert (strcmp (argv[0], "program") == 0);
1417 g_assert (strcmp (argv[1], "foo") == 0);
1418 g_assert (strcmp (argv[2], "--") == 0);
1419 g_assert (strcmp (argv[3], "-bar") == 0);
1420 g_assert (argv[4] == NULL);
1423 g_option_context_free (context);
1426 /* check that -- stripping works */
1430 GOptionContext *context;
1432 GError *error = NULL;
1436 GOptionEntry entries [] = {
1437 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1441 GOptionEntry entries [2];
1443 entries[0].long_name = "test";
1444 entries[0].short_name = 0;
1445 entries[0].flags = 0;
1446 entries[0].arg = G_OPTION_ARG_NONE;
1447 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1448 entries[0].description = NULL;
1449 entries[0].arg_description = NULL;
1451 entries[1].long_name = NULL;
1452 entries[1].short_name = 0;
1453 entries[1].arg_data = NULL;
1454 entries[1].description = NULL;
1455 entries[1].arg_description = NULL;
1458 context = g_option_context_new (NULL);
1459 g_option_context_add_main_entries (context, entries, NULL);
1461 /* Now try parsing */
1462 argv = split_string ("program foo --test -- bar", &argc);
1464 retval = g_option_context_parse (context, &argc, &argv, &error);
1468 g_assert (ignore_test1_boolean);
1469 g_assert (strcmp (argv[0], "program") == 0);
1470 g_assert (strcmp (argv[1], "foo") == 0);
1471 g_assert (strcmp (argv[2], "bar") == 0);
1472 g_assert (argv[3] == NULL);
1475 g_option_context_free (context);
1481 GOptionContext *context;
1483 GError *error = NULL;
1487 GOptionEntry entries [] = {
1488 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1492 GOptionEntry entries [2];
1494 entries[0].long_name = "test";
1495 entries[0].short_name = 0;
1496 entries[0].flags = 0;
1497 entries[0].arg = G_OPTION_ARG_NONE;
1498 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1499 entries[0].description = NULL;
1500 entries[0].arg_description = NULL;
1502 entries[1].long_name = NULL;
1503 entries[1].short_name = 0;
1504 entries[1].arg_data = NULL;
1505 entries[1].description = NULL;
1506 entries[1].arg_description = NULL;
1509 context = g_option_context_new (NULL);
1510 g_option_context_set_ignore_unknown_options (context, TRUE);
1511 g_option_context_add_main_entries (context, entries, NULL);
1513 /* Now try parsing */
1514 argv = split_string ("program foo --test -bar --", &argc);
1516 retval = g_option_context_parse (context, &argc, &argv, &error);
1520 g_assert (ignore_test1_boolean);
1521 g_assert (strcmp (argv[0], "program") == 0);
1522 g_assert (strcmp (argv[1], "foo") == 0);
1523 g_assert (strcmp (argv[2], "-bar") == 0);
1524 g_assert (argv[3] == NULL);
1527 g_option_context_free (context);
1533 GOptionContext *context;
1535 GError *error = NULL;
1539 GOptionEntry entries [] = {
1540 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1544 GOptionEntry entries [2];
1546 entries[0].long_name = "test";
1547 entries[0].short_name = 0;
1548 entries[0].flags = 0;
1549 entries[0].arg = G_OPTION_ARG_NONE;
1550 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1551 entries[0].description = NULL;
1552 entries[0].arg_description = NULL;
1554 entries[1].long_name = NULL;
1555 entries[1].short_name = 0;
1556 entries[1].arg_data = NULL;
1557 entries[1].description = NULL;
1558 entries[1].arg_description = NULL;
1561 context = g_option_context_new (NULL);
1562 g_option_context_add_main_entries (context, entries, NULL);
1564 /* Now try parsing */
1565 argv = split_string ("program --test foo -- bar", &argc);
1567 retval = g_option_context_parse (context, &argc, &argv, &error);
1571 g_assert (ignore_test1_boolean);
1572 g_assert (strcmp (argv[0], "program") == 0);
1573 g_assert (strcmp (argv[1], "foo") == 0);
1574 g_assert (strcmp (argv[2], "bar") == 0);
1575 g_assert (argv[3] == NULL);
1578 g_option_context_free (context);
1584 GOptionContext *context;
1586 GError *error = NULL;
1590 GOptionEntry entries [] = {
1591 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1595 GOptionEntry entries [2];
1597 entries[0].long_name = "test";
1598 entries[0].short_name = 0;
1599 entries[0].flags = 0;
1600 entries[0].arg = G_OPTION_ARG_NONE;
1601 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1602 entries[0].description = NULL;
1603 entries[0].arg_description = NULL;
1605 entries[1].long_name = NULL;
1606 entries[1].short_name = 0;
1607 entries[1].arg_data = NULL;
1608 entries[1].description = NULL;
1609 entries[1].arg_description = NULL;
1612 context = g_option_context_new (NULL);
1613 g_option_context_add_main_entries (context, entries, NULL);
1615 /* Now try parsing */
1616 argv = split_string ("program --test -- -bar", &argc);
1618 retval = g_option_context_parse (context, &argc, &argv, &error);
1622 g_assert (ignore_test1_boolean);
1623 g_assert (strcmp (argv[0], "program") == 0);
1624 g_assert (strcmp (argv[1], "--") == 0);
1625 g_assert (strcmp (argv[2], "-bar") == 0);
1626 g_assert (argv[3] == NULL);
1629 g_option_context_free (context);
1633 /* check that G_OPTION_REMAINING collects non-option arguments */
1637 GOptionContext *context;
1639 GError *error = NULL;
1643 GOptionEntry entries [] = {
1644 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1645 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &array_test1_array, NULL, NULL },
1649 GOptionEntry entries [3];
1651 entries[0].long_name = "test";
1652 entries[0].short_name = 0;
1653 entries[0].flags = 0;
1654 entries[0].arg = G_OPTION_ARG_NONE;
1655 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1656 entries[0].description = NULL;
1657 entries[0].arg_description = NULL;
1660 entries[1].long_name = G_OPTION_REMAINING;
1661 entries[1].short_name = 0;
1662 entries[1].flags = 0;
1663 entries[1].arg = G_OPTION_ARG_STRING_ARRAY;
1664 entries[1].arg_data = (gpointer)&array_test1_array;
1665 entries[1].description = NULL;
1666 entries[1].arg_description = NULL;
1668 entries[2].long_name = NULL;
1669 entries[2].short_name = 0;
1670 entries[2].arg_data = NULL;
1671 entries[2].description = NULL;
1672 entries[2].arg_description = NULL;
1675 context = g_option_context_new (NULL);
1676 g_option_context_add_main_entries (context, entries, NULL);
1678 /* Now try parsing */
1679 argv = split_string ("program foo --test bar", &argc);
1681 retval = g_option_context_parse (context, &argc, &argv, &error);
1685 g_assert (ignore_test1_boolean);
1686 g_assert (strcmp (array_test1_array[0], "foo") == 0);
1687 g_assert (strcmp (array_test1_array[1], "bar") == 0);
1688 g_assert (array_test1_array[2] == NULL);
1690 g_strfreev (array_test1_array);
1693 g_option_context_free (context);
1697 /* check that G_OPTION_REMAINING and -- work together */
1701 GOptionContext *context;
1703 GError *error = NULL;
1707 GOptionEntry entries [] = {
1708 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1709 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &array_test1_array, NULL, NULL },
1713 GOptionEntry entries [3];
1715 entries[0].long_name = "test";
1716 entries[0].short_name = 0;
1717 entries[0].flags = 0;
1718 entries[0].arg = G_OPTION_ARG_NONE;
1719 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1720 entries[0].description = NULL;
1721 entries[0].arg_description = NULL;
1724 entries[1].long_name = G_OPTION_REMAINING;
1725 entries[1].short_name = 0;
1726 entries[1].flags = 0;
1727 entries[1].arg = G_OPTION_ARG_STRING_ARRAY;
1728 entries[1].arg_data = (gpointer)&array_test1_array;
1729 entries[1].description = NULL;
1730 entries[1].arg_description = NULL;
1732 entries[2].long_name = NULL;
1733 entries[2].short_name = 0;
1734 entries[2].arg_data = NULL;
1735 entries[2].description = NULL;
1736 entries[2].arg_description = NULL;
1739 context = g_option_context_new (NULL);
1740 g_option_context_add_main_entries (context, entries, NULL);
1742 /* Now try parsing */
1743 argv = split_string ("program foo --test -- -bar", &argc);
1745 retval = g_option_context_parse (context, &argc, &argv, &error);
1749 g_assert (ignore_test1_boolean);
1750 g_assert (strcmp (array_test1_array[0], "foo") == 0);
1751 g_assert (strcmp (array_test1_array[1], "-bar") == 0);
1752 g_assert (array_test1_array[2] == NULL);
1754 g_strfreev (array_test1_array);
1757 g_option_context_free (context);
1760 /* test that G_OPTION_REMAINING works with G_OPTION_ARG_FILENAME_ARRAY */
1764 GOptionContext *context;
1766 GError *error = NULL;
1771 GOptionEntry entries [] = {
1772 { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
1773 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &array_test1_array, NULL, NULL },
1777 GOptionEntry entries [3];
1779 entries[0].long_name = "test";
1780 entries[0].short_name = 0;
1781 entries[0].flags = 0;
1782 entries[0].arg = G_OPTION_ARG_NONE;
1783 entries[0].arg_data = (gpointer)&ignore_test1_boolean;
1784 entries[0].description = NULL;
1785 entries[0].arg_description = NULL;
1788 entries[1].long_name = G_OPTION_REMAINING;
1789 entries[1].short_name = 0;
1790 entries[1].flags = 0;
1791 entries[1].arg = G_OPTION_ARG_FILENAME_ARRAY;
1792 entries[1].arg_data = (gpointer)&array_test1_array;
1793 entries[1].description = NULL;
1794 entries[1].arg_description = NULL;
1796 entries[2].long_name = NULL;
1797 entries[2].short_name = 0;
1798 entries[2].arg_data = NULL;
1799 entries[2].description = NULL;
1800 entries[2].arg_description = NULL;
1803 context = g_option_context_new (NULL);
1804 g_option_context_add_main_entries (context, entries, NULL);
1806 /* Now try parsing */
1807 argv = split_string ("program foo --test bar", &argc);
1809 retval = g_option_context_parse (context, &argc, &argv, &error);
1813 g_assert (ignore_test1_boolean);
1814 g_assert (strcmp (array_test1_array[0], "foo") == 0);
1815 g_assert (strcmp (array_test1_array[1], "bar") == 0);
1816 g_assert (array_test1_array[2] == NULL);
1818 g_strfreev (array_test1_array);
1821 g_option_context_free (context);
1825 unknown_short_test (void)
1827 GOptionContext *context;
1829 GError *error = NULL;
1833 GOptionEntry entries [] = { { NULL } };
1835 GOptionEntry entries [1];
1837 entries[0].long_name = NULL;
1838 entries[0].short_name = 0;
1839 entries[0].arg_data = NULL;
1840 entries[0].description = NULL;
1841 entries[0].arg_description = NULL;
1844 context = g_option_context_new (NULL);
1845 g_option_context_add_main_entries (context, entries, NULL);
1847 /* Now try parsing */
1848 argv = split_string ("program -0", &argc);
1850 retval = g_option_context_parse (context, &argc, &argv, &error);
1854 g_option_context_free (context);
1857 /* test that lone dashes are treated as non-options */
1858 void lonely_dash_test (void)
1860 GOptionContext *context;
1862 GError *error = NULL;
1866 context = g_option_context_new (NULL);
1868 /* Now try parsing */
1869 argv = split_string ("program -", &argc);
1871 retval = g_option_context_parse (context, &argc, &argv, &error);
1875 g_assert (argv[1] && strcmp (argv[1], "-") == 0);
1878 g_option_context_free (context);
1882 missing_arg_test (void)
1884 GOptionContext *context;
1886 GError *error = NULL;
1891 GOptionEntry entries [] =
1892 { { "test", 't', 0, G_OPTION_ARG_STRING, &arg, NULL, NULL },
1895 GOptionEntry entries [2];
1897 entries[0].long_name = "test";
1898 entries[0].short_name = 't';
1899 entries[0].flags = 0;
1900 entries[0].arg = G_OPTION_ARG_STRING;
1901 entries[0].arg_data = (gpointer)&arg;
1902 entries[0].description = NULL;
1903 entries[0].arg_description = NULL;
1905 entries[1].long_name = NULL;
1906 entries[1].short_name = 0;
1907 entries[1].arg_data = NULL;
1908 entries[1].description = NULL;
1909 entries[1].arg_description = NULL;
1912 context = g_option_context_new (NULL);
1913 g_option_context_add_main_entries (context, entries, NULL);
1915 /* Now try parsing */
1916 argv = split_string ("program --test", &argc);
1918 retval = g_option_context_parse (context, &argc, &argv, &error);
1919 g_assert (retval == FALSE);
1920 g_clear_error (&error);
1924 /* Try parsing again */
1925 argv = split_string ("program --t", &argc);
1927 retval = g_option_context_parse (context, &argc, &argv, &error);
1928 g_assert (retval == FALSE);
1931 g_option_context_free (context);
1935 main (int argc, char **argv)
1938 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
1939 g_set_print_handler(mrtPrintHandler);
1941 /* Test that restoration on failure works */
1942 error_test1_int = 0x12345678;
1944 error_test2_string = "foo";
1946 error_test3_boolean = FALSE;
1949 /* Test that special argument parsing works */
1954 /* Test string arrays */
1957 /* Test callback args */
1961 /* Test optional arg flag for callback */
1962 callback_test_optional_1 ();
1963 callback_test_optional_2 ();
1964 callback_test_optional_3 ();
1965 callback_test_optional_4 ();
1966 callback_test_optional_5 ();
1967 callback_test_optional_6 ();
1968 callback_test_optional_7 ();
1969 callback_test_optional_8 ();
1971 /* Test ignoring options */
1978 /* Test parsing empty args */
1983 /* Test handling of rest args */
1994 /* test for bug 166609 */
1995 unknown_short_test ();
1997 /* test for bug 168008 */
1998 lonely_dash_test ();
2000 /* test for bug 305576 */
2001 missing_arg_test ();
2004 testResultXml("option-test");
2005 #endif /* EMULATOR */