os/ossrv/glib/tsrc/BC/tests/option-test.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/glib/tsrc/BC/tests/option-test.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2007 @@
     1.4 +/* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. */
     1.5 +#include <glib.h>
     1.6 +#include <string.h>
     1.7 +
     1.8 +#ifdef SYMBIAN
     1.9 +#include <glib_global.h>
    1.10 +#include "mrt2_glib2_test.h"
    1.11 +#endif /*SYMBIAN*/
    1.12 +int error_test1_int;
    1.13 +char *error_test2_string;
    1.14 +gboolean error_test3_boolean;
    1.15 +
    1.16 +int arg_test1_int;
    1.17 +gchar *arg_test2_string;
    1.18 +gchar *arg_test3_filename;
    1.19 +
    1.20 +gchar *callback_test1_string;
    1.21 +gboolean callback_test2_int;
    1.22 +
    1.23 +gchar *callback_test_optional_string;
    1.24 +gboolean callback_test_optional_boolean;
    1.25 +
    1.26 +gchar **array_test1_array;
    1.27 +
    1.28 +gboolean ignore_test1_boolean;
    1.29 +gboolean ignore_test2_boolean;
    1.30 +gchar *ignore_test3_string;
    1.31 +
    1.32 +gchar **
    1.33 +split_string (const char *str, int *argc)
    1.34 +{
    1.35 +  gchar **argv;
    1.36 +  int len;
    1.37 +  
    1.38 +  argv = g_strsplit (str, " ", 0);
    1.39 +
    1.40 +  for (len = 0; argv[len] != NULL; len++);
    1.41 +
    1.42 +  if (argc)
    1.43 +    *argc = len;
    1.44 +    
    1.45 +  return argv;
    1.46 +}
    1.47 +
    1.48 +gchar *
    1.49 +join_stringv (int argc, char **argv)
    1.50 +{
    1.51 +  int i;
    1.52 +  GString *str;
    1.53 +
    1.54 +  str = g_string_new (NULL);
    1.55 +
    1.56 +  for (i = 0; i < argc; i++)
    1.57 +    {
    1.58 +      g_string_append (str, argv[i]);
    1.59 +
    1.60 +      if (i < argc - 1)
    1.61 +	g_string_append_c (str, ' ');
    1.62 +    }
    1.63 +
    1.64 +  return g_string_free (str, FALSE);
    1.65 +}
    1.66 +
    1.67 +/* Performs a shallow copy */
    1.68 +char **
    1.69 +copy_stringv (char **argv, int argc)
    1.70 +{
    1.71 +  return g_memdup (argv, sizeof (char *) * (argc + 1));
    1.72 +}
    1.73 +
    1.74 +
    1.75 +static gboolean
    1.76 +error_test1_pre_parse (GOptionContext *context,
    1.77 +		       GOptionGroup   *group,
    1.78 +		       gpointer	       data,
    1.79 +		       GError        **error)
    1.80 +{
    1.81 +  g_assert (error_test1_int == 0x12345678);
    1.82 +
    1.83 +  return TRUE;
    1.84 +}
    1.85 +
    1.86 +static gboolean
    1.87 +error_test1_post_parse (GOptionContext *context,
    1.88 +			GOptionGroup   *group,
    1.89 +			gpointer	  data,
    1.90 +			GError        **error)
    1.91 +{
    1.92 +  g_assert (error_test1_int == 20);
    1.93 +
    1.94 +  /* Set an error in the post hook */
    1.95 +  g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "");
    1.96 +
    1.97 +  return FALSE;
    1.98 +}
    1.99 +
   1.100 +void
   1.101 +error_test1 (void)
   1.102 +{
   1.103 +  GOptionContext *context;
   1.104 +  gboolean retval;
   1.105 +  GError *error = NULL;
   1.106 +  gchar **argv;
   1.107 +  int argc;
   1.108 +  GOptionGroup *main_group;
   1.109 +#ifndef SYMBIAN
   1.110 +  GOptionEntry entries [] =
   1.111 +    { { "test", 0, 0, G_OPTION_ARG_INT, &error_test1_int, NULL, NULL },
   1.112 +      { NULL } };
   1.113 +#else    
   1.114 +
   1.115 +  GOptionEntry entries [2];
   1.116 + 
   1.117 +  entries[0].long_name = "test";
   1.118 +  entries[0].short_name = 0;
   1.119 +  entries[0].flags = 0;
   1.120 +  entries[0].arg = G_OPTION_ARG_INT;
   1.121 +  entries[0].arg_data = (gpointer)&error_test1_int;
   1.122 +  entries[0].description =  NULL;
   1.123 +  entries[0].arg_description = NULL;
   1.124 +      
   1.125 +  entries[1].long_name = NULL;
   1.126 +  entries[1].short_name = 0;
   1.127 +  entries[1].arg_data = NULL;
   1.128 +  entries[1].description =  NULL;
   1.129 +  entries[1].arg_description = NULL;
   1.130 +#endif
   1.131 +  
   1.132 +  context = g_option_context_new (NULL);
   1.133 +  g_option_context_add_main_entries (context, entries, NULL);
   1.134 +
   1.135 +  /* Set pre and post parse hooks */
   1.136 +  main_group = g_option_context_get_main_group (context);
   1.137 +  g_option_group_set_parse_hooks (main_group,
   1.138 +				  error_test1_pre_parse, error_test1_post_parse);
   1.139 +  
   1.140 +  /* Now try parsing */
   1.141 +  argv = split_string ("program --test 20", &argc);
   1.142 +
   1.143 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.144 +  g_assert (retval == FALSE);
   1.145 +
   1.146 +  /* On failure, values should be reset */
   1.147 +  g_assert (error_test1_int == 0x12345678);
   1.148 +  
   1.149 +  g_strfreev (argv);
   1.150 +  g_option_context_free (context);
   1.151 +  
   1.152 +}
   1.153 +
   1.154 +static gboolean
   1.155 +error_test2_pre_parse (GOptionContext *context,
   1.156 +		       GOptionGroup   *group,
   1.157 +		       gpointer	  data,
   1.158 +		       GError        **error)
   1.159 +{
   1.160 +  g_assert (strcmp (error_test2_string, "foo") == 0);
   1.161 +
   1.162 +  return TRUE;
   1.163 +}
   1.164 +
   1.165 +static gboolean
   1.166 +error_test2_post_parse (GOptionContext *context,
   1.167 +			GOptionGroup   *group,
   1.168 +			gpointer	  data,
   1.169 +			GError        **error)
   1.170 +{
   1.171 +  g_assert (strcmp (error_test2_string, "bar") == 0);
   1.172 +
   1.173 +  /* Set an error in the post hook */
   1.174 +  g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "");
   1.175 +
   1.176 +  return FALSE;
   1.177 +}
   1.178 +
   1.179 +void
   1.180 +error_test2 (void)
   1.181 +{
   1.182 +  GOptionContext *context;
   1.183 +  gboolean retval;
   1.184 +  GError *error = NULL;
   1.185 +  gchar **argv;
   1.186 +  int argc;
   1.187 +  GOptionGroup *main_group;
   1.188 +#ifndef SYMBIAN
   1.189 +  GOptionEntry entries [] =
   1.190 +    { { "test", 0, 0, G_OPTION_ARG_STRING, &error_test2_string, NULL, NULL },
   1.191 +      { NULL } };
   1.192 +#else      
   1.193 +  GOptionEntry entries [2];
   1.194 +  
   1.195 +  entries[0].long_name = "test";
   1.196 +  entries[0].short_name = 0;
   1.197 +  entries[0].flags = 0;
   1.198 +  entries[0].arg = G_OPTION_ARG_STRING;
   1.199 +  entries[0].arg_data = (gpointer)&error_test2_string;
   1.200 +  entries[0].description =  NULL;
   1.201 +  entries[0].arg_description = NULL;
   1.202 +      
   1.203 +  entries[1].long_name = NULL;
   1.204 +  entries[1].short_name = 0;
   1.205 +  entries[1].arg_data = NULL;
   1.206 +  entries[1].description =  NULL;
   1.207 +  entries[1].arg_description = NULL;
   1.208 +#endif  
   1.209 +
   1.210 +
   1.211 +  context = g_option_context_new (NULL);
   1.212 +  g_option_context_add_main_entries (context, entries, NULL);
   1.213 +
   1.214 +  /* Set pre and post parse hooks */
   1.215 +  main_group = g_option_context_get_main_group (context);
   1.216 +  g_option_group_set_parse_hooks (main_group,
   1.217 +				  error_test2_pre_parse, error_test2_post_parse);
   1.218 +  
   1.219 +  /* Now try parsing */
   1.220 +  argv = split_string ("program --test bar", &argc);
   1.221 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.222 +
   1.223 +  g_error_free (error);
   1.224 +  g_assert (retval == FALSE);
   1.225 +
   1.226 +  g_assert (strcmp (error_test2_string, "foo") == 0);
   1.227 +  
   1.228 +  g_strfreev (argv);
   1.229 +  g_option_context_free (context);
   1.230 +}
   1.231 +
   1.232 +static gboolean
   1.233 +error_test3_pre_parse (GOptionContext *context,
   1.234 +		       GOptionGroup   *group,
   1.235 +		       gpointer	  data,
   1.236 +		       GError        **error)
   1.237 +{
   1.238 +  g_assert (!error_test3_boolean);
   1.239 +
   1.240 +  return TRUE;
   1.241 +}
   1.242 +
   1.243 +static gboolean
   1.244 +error_test3_post_parse (GOptionContext *context,
   1.245 +			GOptionGroup   *group,
   1.246 +			gpointer	  data,
   1.247 +			GError        **error)
   1.248 +{
   1.249 +  g_assert (error_test3_boolean);
   1.250 +
   1.251 +  /* Set an error in the post hook */
   1.252 +  g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "");
   1.253 +
   1.254 +  return FALSE;
   1.255 +}
   1.256 +
   1.257 +void
   1.258 +error_test3 (void)
   1.259 +{
   1.260 +  GOptionContext *context;
   1.261 +  gboolean retval;
   1.262 +  GError *error = NULL;
   1.263 +  gchar **argv;
   1.264 +  int argc;
   1.265 +  GOptionGroup *main_group;
   1.266 + 
   1.267 +#ifndef SYMBIAN 
   1.268 +  GOptionEntry entries [] =
   1.269 +    { { "test", 0, 0, G_OPTION_ARG_NONE, &error_test3_boolean, NULL, NULL },
   1.270 +      { NULL } };
   1.271 +#else      
   1.272 +  GOptionEntry entries [2];
   1.273 +  
   1.274 +  entries[0].long_name = "test";
   1.275 +  entries[0].short_name = 0;
   1.276 +  entries[0].flags = 0;
   1.277 +  entries[0].arg = G_OPTION_ARG_NONE;
   1.278 +  entries[0].arg_data = (gpointer)&error_test3_boolean;
   1.279 +  entries[0].description =  NULL;
   1.280 +  entries[0].arg_description = NULL;
   1.281 +      
   1.282 +  entries[1].long_name = NULL;
   1.283 +  entries[1].short_name = 0;
   1.284 +  entries[1].arg_data = NULL;
   1.285 +  entries[1].description =  NULL;
   1.286 +  entries[1].arg_description = NULL;
   1.287 +#endif
   1.288 +      
   1.289 +
   1.290 +  context = g_option_context_new (NULL);
   1.291 +  g_option_context_add_main_entries (context, entries, NULL);
   1.292 +
   1.293 +  /* Set pre and post parse hooks */
   1.294 +  main_group = g_option_context_get_main_group (context);
   1.295 +  g_option_group_set_parse_hooks (main_group,
   1.296 +				  error_test3_pre_parse, error_test3_post_parse);
   1.297 +  
   1.298 +  /* Now try parsing */
   1.299 +  argv = split_string ("program --test", &argc);
   1.300 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.301 +
   1.302 +  g_error_free (error);
   1.303 +  g_assert (retval == FALSE);
   1.304 +
   1.305 +  g_assert (!error_test3_boolean);
   1.306 +  
   1.307 +  g_strfreev (argv);
   1.308 +  g_option_context_free (context);
   1.309 +}
   1.310 +
   1.311 +void
   1.312 +arg_test1 (void)
   1.313 +{
   1.314 +  GOptionContext *context;
   1.315 +  gboolean retval;
   1.316 +  GError *error = NULL;
   1.317 +  gchar **argv;
   1.318 +  int argc;
   1.319 +#ifndef SYMBIAN 
   1.320 +  GOptionEntry entries [] =
   1.321 +    { { "test", 0, 0, G_OPTION_ARG_INT, &arg_test1_int, NULL, NULL },
   1.322 +      { NULL } };
   1.323 +#else      
   1.324 +  GOptionEntry entries [2];
   1.325 +  
   1.326 +  entries[0].long_name = "test";
   1.327 +  entries[0].short_name = 0;
   1.328 +  entries[0].flags = 0;
   1.329 +  entries[0].arg = G_OPTION_ARG_INT;
   1.330 +  entries[0].arg_data = (gpointer)&arg_test1_int;
   1.331 +  entries[0].description =  NULL;
   1.332 +  entries[0].arg_description = NULL;
   1.333 +      
   1.334 +  entries[1].long_name = NULL;
   1.335 +  entries[1].short_name = 0;
   1.336 +  entries[1].arg_data = NULL;
   1.337 +  entries[1].description =  NULL;
   1.338 +  entries[1].arg_description = NULL;
   1.339 +#endif      
   1.340 +
   1.341 +  context = g_option_context_new (NULL);
   1.342 +  g_option_context_add_main_entries (context, entries, NULL);
   1.343 +
   1.344 +  /* Now try parsing */
   1.345 +  argv = split_string ("program --test 20 --test 30", &argc);
   1.346 +
   1.347 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.348 +  g_assert (retval);
   1.349 +
   1.350 +  /* Last arg specified is the one that should be stored */
   1.351 +  g_assert (arg_test1_int == 30);
   1.352 +
   1.353 +  g_strfreev (argv);
   1.354 +  g_option_context_free (context);
   1.355 +}
   1.356 +
   1.357 +void
   1.358 +arg_test2 (void)
   1.359 +{
   1.360 +  GOptionContext *context;
   1.361 +  gboolean retval;
   1.362 +  GError *error = NULL;
   1.363 +  gchar **argv;
   1.364 +  int argc;
   1.365 +#ifndef SYMBIAN  
   1.366 +  GOptionEntry entries [] =
   1.367 +    { { "test", 0, 0, G_OPTION_ARG_STRING, &arg_test2_string, NULL, NULL },
   1.368 +      { NULL } };
   1.369 +#else      
   1.370 +  GOptionEntry entries [2];
   1.371 +  
   1.372 +  entries[0].long_name = "test";
   1.373 +  entries[0].short_name = 0;
   1.374 +  entries[0].flags = 0;
   1.375 +  entries[0].arg = G_OPTION_ARG_STRING;
   1.376 +  entries[0].arg_data = (gpointer)&arg_test2_string;
   1.377 +  entries[0].description =  NULL;
   1.378 +  entries[0].arg_description = NULL;
   1.379 +      
   1.380 +  entries[1].long_name = NULL;
   1.381 +  entries[1].short_name = 0;
   1.382 +  entries[1].arg_data = NULL;
   1.383 +  entries[1].description =  NULL;
   1.384 +  entries[1].arg_description = NULL;
   1.385 +#endif      
   1.386 +  
   1.387 +  context = g_option_context_new (NULL);
   1.388 +  g_option_context_add_main_entries (context, entries, NULL);
   1.389 +
   1.390 +  /* Now try parsing */
   1.391 +  argv = split_string ("program --test foo --test bar", &argc);
   1.392 +  
   1.393 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.394 +  g_assert (retval);
   1.395 +
   1.396 +  /* Last arg specified is the one that should be stored */
   1.397 +  g_assert (strcmp (arg_test2_string, "bar") == 0);
   1.398 +
   1.399 +  g_free (arg_test2_string);
   1.400 +  
   1.401 +  g_strfreev (argv);
   1.402 +  g_option_context_free (context);
   1.403 +}
   1.404 +
   1.405 +void
   1.406 +arg_test3 (void)
   1.407 +{
   1.408 +  GOptionContext *context;
   1.409 +  gboolean retval;
   1.410 +  GError *error = NULL;
   1.411 +  gchar **argv;
   1.412 +  int argc;
   1.413 +#ifndef SYMBIAN  
   1.414 +  GOptionEntry entries [] =
   1.415 +    { { "test", 0, 0, G_OPTION_ARG_FILENAME, &arg_test3_filename, NULL, NULL },
   1.416 +      { NULL } };
   1.417 +#else      
   1.418 +  GOptionEntry entries [2];
   1.419 +  
   1.420 +  entries[0].long_name = "test";
   1.421 +  entries[0].short_name = 0;
   1.422 +  entries[0].flags = 0;
   1.423 +  entries[0].arg = G_OPTION_ARG_FILENAME;
   1.424 +  entries[0].arg_data = (gpointer)&arg_test3_filename;
   1.425 +  entries[0].description =  NULL;
   1.426 +  entries[0].arg_description = NULL;
   1.427 +      
   1.428 +  entries[1].long_name = NULL;
   1.429 +  entries[1].short_name = 0;
   1.430 +  entries[1].arg_data = NULL;
   1.431 +  entries[1].description =  NULL;
   1.432 +  entries[1].arg_description = NULL;
   1.433 +#endif      
   1.434 +  
   1.435 +  context = g_option_context_new (NULL);
   1.436 +  g_option_context_add_main_entries (context, entries, NULL);
   1.437 +
   1.438 +  /* Now try parsing */
   1.439 +  argv = split_string ("program --test foo.txt", &argc);
   1.440 +  
   1.441 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.442 +  g_assert (retval);
   1.443 +
   1.444 +  /* Last arg specified is the one that should be stored */
   1.445 +  g_assert (strcmp (arg_test3_filename, "foo.txt") == 0);
   1.446 +
   1.447 +  g_free (arg_test3_filename);
   1.448 +  
   1.449 +  g_strfreev (argv);
   1.450 +  g_option_context_free (context);
   1.451 +}
   1.452 +
   1.453 +static gboolean
   1.454 +callback_parse1 (const gchar *option_name, const gchar *value,
   1.455 +		 gpointer data, GError **error)
   1.456 +{
   1.457 +	callback_test1_string = g_strdup (value);
   1.458 +	return TRUE;
   1.459 +}
   1.460 +
   1.461 +void
   1.462 +callback_test1 (void)
   1.463 +{
   1.464 +  GOptionContext *context;
   1.465 +  gboolean retval;
   1.466 +  GError *error = NULL;
   1.467 +  gchar **argv;
   1.468 +  int argc;
   1.469 +#ifndef SYMBIAN  
   1.470 +  GOptionEntry entries [] =
   1.471 +    { { "test", 0, 0, G_OPTION_ARG_CALLBACK, callback_parse1, NULL, NULL },
   1.472 +      { NULL } };
   1.473 +#else 
   1.474 +  GOptionEntry entries [2];
   1.475 +  
   1.476 +  entries[0].long_name = "test";
   1.477 +  entries[0].short_name = 0;
   1.478 +  entries[0].flags = 0;
   1.479 +  entries[0].arg = G_OPTION_ARG_CALLBACK;
   1.480 +  entries[0].arg_data = (gpointer)callback_parse1;
   1.481 +  entries[0].description =  NULL;
   1.482 +  entries[0].arg_description = NULL;
   1.483 +      
   1.484 +  entries[1].long_name = NULL;
   1.485 +  entries[1].short_name = 0;
   1.486 +  entries[1].arg_data = NULL;
   1.487 +  entries[1].description =  NULL;
   1.488 +  entries[1].arg_description = NULL;
   1.489 +#endif
   1.490 +
   1.491 +  context = g_option_context_new (NULL);
   1.492 +  g_option_context_add_main_entries (context, entries, NULL);
   1.493 +
   1.494 +  /* Now try parsing */
   1.495 +  argv = split_string ("program --test foo.txt", &argc);
   1.496 +  
   1.497 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.498 +  g_assert (retval);
   1.499 +
   1.500 +  g_assert (strcmp (callback_test1_string, "foo.txt") == 0);
   1.501 +
   1.502 +  g_free (callback_test1_string);
   1.503 +  
   1.504 +  g_strfreev (argv);
   1.505 +  g_option_context_free (context);
   1.506 +}
   1.507 +
   1.508 +static gboolean
   1.509 +callback_parse2 (const gchar *option_name, const gchar *value,
   1.510 +		 gpointer data, GError **error)
   1.511 +{
   1.512 +	callback_test2_int++;
   1.513 +	return TRUE;
   1.514 +}
   1.515 +
   1.516 +void
   1.517 +callback_test2 (void)
   1.518 +{
   1.519 +  GOptionContext *context;
   1.520 +  gboolean retval;
   1.521 +  GError *error = NULL;
   1.522 +  gchar **argv;
   1.523 +  int argc;
   1.524 + 
   1.525 +#ifndef SYMBIAN 
   1.526 +  GOptionEntry entries [] =
   1.527 +    { { "test", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, callback_parse2, NULL, NULL },
   1.528 +      { NULL } };
   1.529 +#else      
   1.530 +  GOptionEntry entries [2];
   1.531 +  
   1.532 +  entries[0].long_name = "test";
   1.533 +  entries[0].short_name = 0;
   1.534 +  entries[0].flags = G_OPTION_FLAG_NO_ARG;
   1.535 +  entries[0].arg = G_OPTION_ARG_CALLBACK;
   1.536 +  entries[0].arg_data = (gpointer)callback_parse2;
   1.537 +  entries[0].description =  NULL;
   1.538 +  entries[0].arg_description = NULL;
   1.539 +      
   1.540 +  entries[1].long_name = NULL;
   1.541 +  entries[1].short_name = 0;
   1.542 +  entries[1].arg_data = NULL;
   1.543 +  entries[1].description =  NULL;
   1.544 +  entries[1].arg_description = NULL;
   1.545 +#endif      
   1.546 +  
   1.547 +  context = g_option_context_new (NULL);
   1.548 +  g_option_context_add_main_entries (context, entries, NULL);
   1.549 +
   1.550 +  /* Now try parsing */
   1.551 +  argv = split_string ("program --test --test", &argc);
   1.552 +  
   1.553 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.554 +  g_assert (retval);
   1.555 +
   1.556 +  g_assert (callback_test2_int == 2);
   1.557 +  
   1.558 +  g_strfreev (argv);
   1.559 +  g_option_context_free (context);
   1.560 +}
   1.561 +
   1.562 +static gboolean
   1.563 +callback_parse_optional (const gchar *option_name, const gchar *value,
   1.564 +		 gpointer data, GError **error)
   1.565 +{
   1.566 +	callback_test_optional_boolean = TRUE;
   1.567 +	if (value)
   1.568 +		callback_test_optional_string = g_strdup (value);
   1.569 +	else
   1.570 +		callback_test_optional_string = NULL;
   1.571 +	return TRUE;
   1.572 +}
   1.573 +
   1.574 +void
   1.575 +callback_test_optional_1 (void)
   1.576 +{
   1.577 +  GOptionContext *context;
   1.578 +  gboolean retval;
   1.579 +  GError *error = NULL;
   1.580 +  gchar **argv;
   1.581 +  int argc;
   1.582 +#ifndef SYMBIAN
   1.583 +  GOptionEntry entries [] =
   1.584 +    { { "test", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
   1.585 +	callback_parse_optional, NULL, NULL },
   1.586 +      { NULL } };
   1.587 +#else      
   1.588 +  GOptionEntry entries [2];
   1.589 +  
   1.590 +  entries[0].long_name = "test";
   1.591 +  entries[0].short_name = 0;
   1.592 +  entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
   1.593 +  entries[0].arg = G_OPTION_ARG_CALLBACK;
   1.594 +  entries[0].arg_data = (gpointer)callback_parse_optional;
   1.595 +  entries[0].description =  NULL;
   1.596 +  entries[0].arg_description = NULL;
   1.597 +      
   1.598 +  entries[1].long_name = NULL;
   1.599 +  entries[1].short_name = 0;
   1.600 +  entries[1].arg_data = NULL;
   1.601 +  entries[1].description =  NULL;
   1.602 +  entries[1].arg_description = NULL;
   1.603 +#endif      
   1.604 +  
   1.605 +  context = g_option_context_new (NULL);
   1.606 +  g_option_context_add_main_entries (context, entries, NULL);
   1.607 +
   1.608 +  /* Now try parsing */
   1.609 +  argv = split_string ("program --test foo.txt", &argc);
   1.610 +  
   1.611 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.612 +  g_assert (retval);
   1.613 +
   1.614 +  g_assert (strcmp (callback_test_optional_string, "foo.txt") == 0);
   1.615 +  
   1.616 +  g_assert (callback_test_optional_boolean);
   1.617 +
   1.618 +  g_free (callback_test_optional_string);
   1.619 +  
   1.620 +  g_strfreev (argv);
   1.621 +  g_option_context_free (context);
   1.622 +}
   1.623 +
   1.624 +void
   1.625 +callback_test_optional_2 (void)
   1.626 +{
   1.627 +  GOptionContext *context;
   1.628 +  gboolean retval;
   1.629 +  GError *error = NULL;
   1.630 +  gchar **argv;
   1.631 +  int argc;
   1.632 +#ifndef SYMBIAN  
   1.633 +  GOptionEntry entries [] =
   1.634 +    { { "test", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
   1.635 +	callback_parse_optional, NULL, NULL },
   1.636 +      { NULL } };
   1.637 +#else      
   1.638 +  GOptionEntry entries [2];
   1.639 +  
   1.640 +  entries[0].long_name = "test";
   1.641 +  entries[0].short_name = 0;
   1.642 +  entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
   1.643 +  entries[0].arg = G_OPTION_ARG_CALLBACK;
   1.644 +  entries[0].arg_data = (gpointer)callback_parse_optional;
   1.645 +  entries[0].description =  NULL;
   1.646 +  entries[0].arg_description = NULL;
   1.647 +      
   1.648 +  entries[1].long_name = NULL;
   1.649 +  entries[1].short_name = 0;
   1.650 +  entries[1].arg_data = NULL;
   1.651 +  entries[1].description =  NULL;
   1.652 +  entries[1].arg_description = NULL;
   1.653 +#endif      
   1.654 +  
   1.655 +  context = g_option_context_new (NULL);
   1.656 +  g_option_context_add_main_entries (context, entries, NULL);
   1.657 +
   1.658 +  /* Now try parsing */
   1.659 +  argv = split_string ("program --test", &argc);
   1.660 +  
   1.661 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.662 +  g_assert (retval);
   1.663 +
   1.664 +  g_assert (callback_test_optional_string == NULL);
   1.665 +  
   1.666 +  g_assert (callback_test_optional_boolean);
   1.667 +
   1.668 +  g_free (callback_test_optional_string);
   1.669 +  
   1.670 +  g_strfreev (argv);
   1.671 +  g_option_context_free (context);
   1.672 +}
   1.673 +
   1.674 +void
   1.675 +callback_test_optional_3 (void)
   1.676 +{
   1.677 +  GOptionContext *context;
   1.678 +  gboolean retval;
   1.679 +  GError *error = NULL;
   1.680 +  gchar **argv;
   1.681 +  int argc;
   1.682 +#ifndef SYMBIAN  
   1.683 +  GOptionEntry entries [] =
   1.684 +    { { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
   1.685 +	callback_parse_optional, NULL, NULL },
   1.686 +      { NULL } };
   1.687 +#else      
   1.688 +  GOptionEntry entries [2];
   1.689 +  
   1.690 +  entries[0].long_name = "test";
   1.691 +  entries[0].short_name = 't';
   1.692 +  entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
   1.693 +  entries[0].arg = G_OPTION_ARG_CALLBACK;
   1.694 +  entries[0].arg_data = (gpointer)callback_parse_optional;
   1.695 +  entries[0].description =  NULL;
   1.696 +  entries[0].arg_description = NULL;
   1.697 +      
   1.698 +  entries[1].long_name = NULL;
   1.699 +  entries[1].short_name = 0;
   1.700 +  entries[1].arg_data = NULL;
   1.701 +  entries[1].description =  NULL;
   1.702 +  entries[1].arg_description = NULL;
   1.703 +#endif      
   1.704 +  
   1.705 +  context = g_option_context_new (NULL);
   1.706 +  g_option_context_add_main_entries (context, entries, NULL);
   1.707 +
   1.708 +  /* Now try parsing */
   1.709 +  argv = split_string ("program -t foo.txt", &argc);
   1.710 +  
   1.711 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.712 +  g_assert (retval);
   1.713 +
   1.714 +  g_assert (strcmp (callback_test_optional_string, "foo.txt") == 0);
   1.715 +  
   1.716 +  g_assert (callback_test_optional_boolean);
   1.717 +
   1.718 +  g_free (callback_test_optional_string);
   1.719 +  
   1.720 +  g_strfreev (argv);
   1.721 +  g_option_context_free (context);
   1.722 +}
   1.723 +
   1.724 +
   1.725 +void
   1.726 +callback_test_optional_4 (void)
   1.727 +{
   1.728 +  GOptionContext *context;
   1.729 +  gboolean retval;
   1.730 +  GError *error = NULL;
   1.731 +  gchar **argv;
   1.732 +  int argc;
   1.733 +#ifndef SYMBIAN  
   1.734 +  GOptionEntry entries [] =
   1.735 +    { { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
   1.736 +	callback_parse_optional, NULL, NULL },
   1.737 +      { NULL } };
   1.738 +#else      
   1.739 +  GOptionEntry entries [2];
   1.740 +  
   1.741 +  entries[0].long_name = "test";
   1.742 +  entries[0].short_name = 't';
   1.743 +  entries[0].flags = G_OPTION_FLAG_OPTIONAL_ARG;
   1.744 +  entries[0].arg = G_OPTION_ARG_CALLBACK;
   1.745 +  entries[0].arg_data = (gpointer)callback_parse_optional;
   1.746 +  entries[0].description =  NULL;
   1.747 +  entries[0].arg_description = NULL;
   1.748 +      
   1.749 +  entries[1].long_name = NULL;
   1.750 +  entries[1].short_name = 0;
   1.751 +  entries[1].arg_data = NULL;
   1.752 +  entries[1].description =  NULL;
   1.753 +  entries[1].arg_description = NULL;
   1.754 +#endif      
   1.755 +  
   1.756 +  context = g_option_context_new (NULL);
   1.757 +  g_option_context_add_main_entries (context, entries, NULL);
   1.758 +
   1.759 +  /* Now try parsing */
   1.760 +  argv = split_string ("program -t", &argc);
   1.761 +  
   1.762 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.763 +  g_assert (retval);
   1.764 +
   1.765 +  g_assert (callback_test_optional_string == NULL);
   1.766 +  
   1.767 +  g_assert (callback_test_optional_boolean);
   1.768 +
   1.769 +  g_free (callback_test_optional_string);
   1.770 +  
   1.771 +  g_strfreev (argv);
   1.772 +  g_option_context_free (context);
   1.773 +}
   1.774 +
   1.775 +void
   1.776 +callback_test_optional_5 (void)
   1.777 +{
   1.778 +  GOptionContext *context;
   1.779 +  gboolean dummy;
   1.780 +  gboolean retval;
   1.781 +  GError *error = NULL;
   1.782 +  gchar **argv;
   1.783 +  int argc;
   1.784 +#ifndef SYMBIAN  
   1.785 +  GOptionEntry entries [] =
   1.786 +    { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, NULL },
   1.787 +      { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
   1.788 +	callback_parse_optional, NULL, NULL },
   1.789 +      { NULL } };
   1.790 +#else
   1.791 +  GOptionEntry entries [3];
   1.792 +  
   1.793 +  entries[0].long_name = "dummy";
   1.794 +  entries[0].short_name = 'd';
   1.795 +  entries[0].flags = 0;
   1.796 +  entries[0].arg = G_OPTION_ARG_NONE;
   1.797 +  entries[0].arg_data = (gpointer)&dummy;
   1.798 +  entries[0].description =  NULL;
   1.799 +    
   1.800 +  entries[1].long_name = "test";
   1.801 +  entries[1].short_name = 't';
   1.802 +  entries[1].flags = G_OPTION_FLAG_OPTIONAL_ARG;
   1.803 +  entries[1].arg = G_OPTION_ARG_CALLBACK;
   1.804 +  entries[1].arg_data = (gpointer)callback_parse_optional;
   1.805 +  entries[1].description =  NULL;
   1.806 +  entries[1].arg_description = NULL;
   1.807 +  
   1.808 +      
   1.809 +  entries[2].long_name = NULL;
   1.810 +  entries[2].short_name = 0;
   1.811 +  entries[2].arg_data = NULL;
   1.812 +  entries[2].description =  NULL;
   1.813 +  entries[2].arg_description = NULL;
   1.814 +#endif      
   1.815 +  
   1.816 +  context = g_option_context_new (NULL);
   1.817 +  g_option_context_add_main_entries (context, entries, NULL);
   1.818 +
   1.819 +  /* Now try parsing */
   1.820 +  argv = split_string ("program --test --dummy", &argc);
   1.821 +  
   1.822 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.823 +  g_assert (retval);
   1.824 +
   1.825 +  g_assert (callback_test_optional_string == NULL);
   1.826 +  
   1.827 +  g_assert (callback_test_optional_boolean);
   1.828 +
   1.829 +  g_free (callback_test_optional_string);
   1.830 +  
   1.831 +  g_strfreev (argv);
   1.832 +  g_option_context_free (context);
   1.833 +}
   1.834 +
   1.835 +void
   1.836 +callback_test_optional_6 (void)
   1.837 +{
   1.838 +  GOptionContext *context;
   1.839 +  gboolean dummy;
   1.840 +  gboolean retval;
   1.841 +  GError *error = NULL;
   1.842 +  gchar **argv;
   1.843 +  int argc;
   1.844 +#ifndef SYMBIAN  
   1.845 +  GOptionEntry entries [] =
   1.846 +    { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, NULL },
   1.847 +      { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
   1.848 +	callback_parse_optional, NULL, NULL },
   1.849 +      { NULL } };
   1.850 +#else           
   1.851 +  GOptionEntry entries [3];
   1.852 +  
   1.853 +  entries[0].long_name = "dummy";
   1.854 +  entries[0].short_name = 'd';
   1.855 +  entries[0].flags = 0;
   1.856 +  entries[0].arg = G_OPTION_ARG_NONE;
   1.857 +  entries[0].arg_data = (gpointer)&dummy;
   1.858 +  entries[0].description =  NULL;
   1.859 +    
   1.860 +  entries[1].long_name = "test";
   1.861 +  entries[1].short_name = 't';
   1.862 +  entries[1].flags = G_OPTION_FLAG_OPTIONAL_ARG;
   1.863 +  entries[1].arg = G_OPTION_ARG_CALLBACK;
   1.864 +  entries[1].arg_data = (gpointer)callback_parse_optional;
   1.865 +  entries[1].description =  NULL;
   1.866 +  entries[1].arg_description = NULL;
   1.867 +  
   1.868 +      
   1.869 +  entries[2].long_name = NULL;
   1.870 +  entries[2].short_name = 0;
   1.871 +  entries[2].arg_data = NULL;
   1.872 +  entries[2].description =  NULL;
   1.873 +  entries[2].arg_description = NULL;
   1.874 +#endif      
   1.875 +      
   1.876 +  
   1.877 +  context = g_option_context_new (NULL);
   1.878 +  g_option_context_add_main_entries (context, entries, NULL);
   1.879 +
   1.880 +  /* Now try parsing */
   1.881 +  argv = split_string ("program -t -d", &argc);
   1.882 +  
   1.883 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.884 +  g_assert (retval);
   1.885 +
   1.886 +  g_assert (callback_test_optional_string == NULL);
   1.887 +  
   1.888 +  g_assert (callback_test_optional_boolean);
   1.889 +
   1.890 +  g_free (callback_test_optional_string);
   1.891 +  
   1.892 +  g_strfreev (argv);
   1.893 +  g_option_context_free (context);
   1.894 +}
   1.895 +
   1.896 +void
   1.897 +callback_test_optional_7 (void)
   1.898 +{
   1.899 +  GOptionContext *context;
   1.900 +  gboolean dummy;
   1.901 +  gboolean retval;
   1.902 +  GError *error = NULL;
   1.903 +  gchar **argv;
   1.904 +  int argc;
   1.905 +#ifndef SYMBIAN  
   1.906 +  GOptionEntry entries [] =
   1.907 +    { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, NULL },
   1.908 +      { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
   1.909 +	callback_parse_optional, NULL, NULL },
   1.910 +      { NULL } };
   1.911 +#else      
   1.912 +   GOptionEntry entries [3];
   1.913 +  
   1.914 +  entries[0].long_name = "dummy";
   1.915 +  entries[0].short_name = 'd';
   1.916 +  entries[0].flags = 0;
   1.917 +  entries[0].arg = G_OPTION_ARG_NONE;
   1.918 +  entries[0].arg_data = (gpointer)&dummy;
   1.919 +  entries[0].description =  NULL;
   1.920 +    
   1.921 +  entries[1].long_name = "test";
   1.922 +  entries[1].short_name = 't';
   1.923 +  entries[1].flags = G_OPTION_FLAG_OPTIONAL_ARG;
   1.924 +  entries[1].arg = G_OPTION_ARG_CALLBACK;
   1.925 +  entries[1].arg_data = (gpointer)callback_parse_optional;
   1.926 +  entries[1].description =  NULL;
   1.927 +  entries[1].arg_description = NULL;
   1.928 +  
   1.929 +      
   1.930 +  entries[2].long_name = NULL;
   1.931 +  entries[2].short_name = 0;
   1.932 +  entries[2].arg_data = NULL;
   1.933 +  entries[2].description =  NULL;
   1.934 +  entries[2].arg_description = NULL;
   1.935 +#endif     
   1.936 +     
   1.937 +  
   1.938 +  context = g_option_context_new (NULL);
   1.939 +  g_option_context_add_main_entries (context, entries, NULL);
   1.940 +
   1.941 +  /* Now try parsing */
   1.942 +  argv = split_string ("program -td", &argc);
   1.943 +  
   1.944 +  retval = g_option_context_parse (context, &argc, &argv, &error);
   1.945 +  g_assert (retval);
   1.946 +
   1.947 +  g_assert (callback_test_optional_string == NULL);
   1.948 +  
   1.949 +  g_assert (callback_test_optional_boolean);
   1.950 +
   1.951 +  g_free (callback_test_optional_string);
   1.952 +  
   1.953 +  g_strfreev (argv);
   1.954 +  g_option_context_free (context);
   1.955 +}
   1.956 +
   1.957 +void
   1.958 +callback_test_optional_8 (void)
   1.959 +{
   1.960 +  GOptionContext *context;
   1.961 +  gboolean dummy;
   1.962 +  gboolean retval;
   1.963 +  GError *error = NULL;
   1.964 +  gchar **argv;
   1.965 +  int argc;
   1.966 +#ifndef SYMBIAN  
   1.967 +  GOptionEntry entries [] =
   1.968 +    { { "dummy", 'd', 0, G_OPTION_ARG_NONE, &dummy, NULL },
   1.969 +      { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, 
   1.970 +	callback_parse_optional, NULL, NULL },
   1.971 +      { NULL } };
   1.972 +#else      
   1.973 +   GOptionEntry entries [3];
   1.974 +  
   1.975 +  entries[0].long_name = "dummy";
   1.976 +  entries[0].short_name = 'd';
   1.977 +  entries[0].flags = 0;
   1.978 +  entries[0].arg = G_OPTION_ARG_NONE;
   1.979 +  entries[0].arg_data = (gpointer)&dummy;
   1.980 +  entries[0].description =  NULL;
   1.981 +    
   1.982 +  entries[1].long_name = "test";
   1.983 +  entries[1].short_name = 't';
   1.984 +  entries[1].flags = G_OPTION_FLAG_OPTIONAL_ARG;
   1.985 +  entries[1].arg = G_OPTION_ARG_CALLBACK;
   1.986 +  entries[1].arg_data = (gpointer)callback_parse_optional;
   1.987 +  entries[1].description =  NULL;
   1.988 +  entries[1].arg_description = NULL;
   1.989 +  
   1.990 +      
   1.991 +  entries[2].long_name = NULL;
   1.992 +  entries[2].short_name = 0;
   1.993 +  entries[2].arg_data = NULL;
   1.994 +  entries[2].description =  NULL;
   1.995 +  entries[2].arg_description = NULL;
   1.996 +#endif      
   1.997 +  
   1.998 +  context = g_option_context_new (NULL);
   1.999 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1000 +
  1.1001 +  /* Now try parsing */
  1.1002 +  argv = split_string ("program -dt foo.txt", &argc);
  1.1003 +  
  1.1004 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1005 +  g_assert (retval);
  1.1006 +
  1.1007 +  g_assert (callback_test_optional_string);
  1.1008 +  
  1.1009 +  g_assert (callback_test_optional_boolean);
  1.1010 +
  1.1011 +  g_free (callback_test_optional_string);
  1.1012 +  
  1.1013 +  g_strfreev (argv);
  1.1014 +  g_option_context_free (context);
  1.1015 +}
  1.1016 +
  1.1017 +void
  1.1018 +ignore_test1 (void)
  1.1019 +{
  1.1020 +  GOptionContext *context;
  1.1021 +  gboolean retval;
  1.1022 +  GError *error = NULL;
  1.1023 +  gchar **argv, **argv_copy;
  1.1024 +  int argc;
  1.1025 +  gchar *arg;
  1.1026 +#ifndef SYMBIAN  
  1.1027 +  GOptionEntry entries [] =
  1.1028 +    { { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1029 +      { NULL } };
  1.1030 +#else          
  1.1031 +  GOptionEntry entries [2];
  1.1032 +  
  1.1033 +  entries[0].long_name = "test";
  1.1034 +  entries[0].short_name = 0;
  1.1035 +  entries[0].flags = 0;
  1.1036 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1037 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1038 +  entries[0].description =  NULL;
  1.1039 +  entries[0].arg_description = NULL;
  1.1040 +      
  1.1041 +  entries[1].long_name = NULL;
  1.1042 +  entries[1].short_name = 0;
  1.1043 +  entries[1].arg_data = NULL;
  1.1044 +  entries[1].description =  NULL;
  1.1045 +  entries[1].arg_description = NULL;
  1.1046 +#endif      
  1.1047 +
  1.1048 +  context = g_option_context_new (NULL);
  1.1049 +  g_option_context_set_ignore_unknown_options (context, TRUE);
  1.1050 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1051 +
  1.1052 +  /* Now try parsing */
  1.1053 +  argv = split_string ("program --test --hello", &argc);
  1.1054 +  argv_copy = copy_stringv (argv, argc);
  1.1055 +  
  1.1056 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1057 +  g_assert (retval);
  1.1058 +
  1.1059 +  /* Check array */
  1.1060 +  arg = join_stringv (argc, argv);
  1.1061 +  g_assert (strcmp (arg, "program --hello") == 0);
  1.1062 +
  1.1063 +  g_free (arg);
  1.1064 +  g_strfreev (argv_copy);
  1.1065 +  g_free (argv);
  1.1066 +  g_option_context_free (context);
  1.1067 +}
  1.1068 +
  1.1069 +void
  1.1070 +ignore_test2 (void)
  1.1071 +{
  1.1072 +  GOptionContext *context;
  1.1073 +  gboolean retval;
  1.1074 +  GError *error = NULL;
  1.1075 +  gchar **argv;
  1.1076 +  int argc;
  1.1077 +  gchar *arg;
  1.1078 +#ifndef SYMBIAN  
  1.1079 +  GOptionEntry entries [] =
  1.1080 +    { { "test", 't', 0, G_OPTION_ARG_NONE, &ignore_test2_boolean, NULL, NULL },
  1.1081 +      { NULL } };
  1.1082 +#else      
  1.1083 +  GOptionEntry entries [2];
  1.1084 +  
  1.1085 +  entries[0].long_name = "test";
  1.1086 +  entries[0].short_name = 't';
  1.1087 +  entries[0].flags = 0;
  1.1088 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1089 +  entries[0].arg_data = (gpointer)&ignore_test2_boolean;
  1.1090 +  entries[0].description =  NULL;
  1.1091 +  entries[0].arg_description = NULL;
  1.1092 +      
  1.1093 +  entries[1].long_name = NULL;
  1.1094 +  entries[1].short_name = 0;
  1.1095 +  entries[1].arg_data = NULL;
  1.1096 +  entries[1].description =  NULL;
  1.1097 +  entries[1].arg_description = NULL;
  1.1098 +#endif      
  1.1099 +
  1.1100 +  context = g_option_context_new (NULL);
  1.1101 +  g_option_context_set_ignore_unknown_options (context, TRUE);
  1.1102 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1103 +
  1.1104 +  /* Now try parsing */
  1.1105 +  argv = split_string ("program -test", &argc);
  1.1106 +  
  1.1107 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1108 +  g_assert (retval);
  1.1109 +
  1.1110 +  /* Check array */
  1.1111 +  arg = join_stringv (argc, argv);
  1.1112 +  g_assert (strcmp (arg, "program -es") == 0);
  1.1113 +
  1.1114 +  g_free (arg);
  1.1115 +  g_strfreev (argv);
  1.1116 +  g_option_context_free (context);
  1.1117 +}
  1.1118 +
  1.1119 +void
  1.1120 +ignore_test3 (void)
  1.1121 +{
  1.1122 +  GOptionContext *context;
  1.1123 +  gboolean retval;
  1.1124 +  GError *error = NULL;
  1.1125 +  gchar **argv, **argv_copy;
  1.1126 +  int argc;
  1.1127 +  gchar *arg;
  1.1128 +#ifndef SYMBAIN  
  1.1129 +  GOptionEntry entries [] =
  1.1130 +    { { "test", 0, 0, G_OPTION_ARG_STRING, &ignore_test3_string, NULL, NULL },
  1.1131 +      { NULL } };
  1.1132 +#else      
  1.1133 +  GOptionEntry entries [2];
  1.1134 +  
  1.1135 +  entries[0].long_name = "test";
  1.1136 +  entries[0].short_name = 0;
  1.1137 +  entries[0].flags = 0;
  1.1138 +  entries[0].arg = G_OPTION_ARG_STRING;
  1.1139 +  entries[0].arg_data = (gpointer)&ignore_test3_string;
  1.1140 +  entries[0].description =  NULL;
  1.1141 +  entries[0].arg_description = NULL;
  1.1142 +      
  1.1143 +  entries[1].long_name = NULL;
  1.1144 +  entries[1].short_name = 0;
  1.1145 +  entries[1].arg_data = NULL;
  1.1146 +  entries[1].description =  NULL;
  1.1147 +  entries[1].arg_description = NULL;
  1.1148 +#endif      
  1.1149 +
  1.1150 +  context = g_option_context_new (NULL);
  1.1151 +  g_option_context_set_ignore_unknown_options (context, TRUE);
  1.1152 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1153 +
  1.1154 +  /* Now try parsing */
  1.1155 +  argv = split_string ("program --test foo --hello", &argc);
  1.1156 +  argv_copy = copy_stringv (argv, argc);
  1.1157 +  
  1.1158 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1159 +  g_assert (retval);
  1.1160 +
  1.1161 +  /* Check array */
  1.1162 +  arg = join_stringv (argc, argv);
  1.1163 +  g_assert (strcmp (arg, "program --hello") == 0);
  1.1164 +
  1.1165 +  g_assert (strcmp (ignore_test3_string, "foo") == 0);
  1.1166 +  g_free (ignore_test3_string);
  1.1167 +
  1.1168 +  g_free (arg);
  1.1169 +  g_strfreev (argv_copy);
  1.1170 +  g_free (argv);
  1.1171 +  g_option_context_free (context);
  1.1172 +}
  1.1173 +
  1.1174 +void
  1.1175 +array_test1 (void)
  1.1176 +{
  1.1177 +  GOptionContext *context;
  1.1178 +  gboolean retval;
  1.1179 +  GError *error = NULL;
  1.1180 +  gchar **argv;
  1.1181 +  int argc;
  1.1182 +#ifndef SYMBIAN  
  1.1183 +  GOptionEntry entries [] =
  1.1184 +    { { "test", 0, 0, G_OPTION_ARG_STRING_ARRAY, &array_test1_array, NULL, NULL },
  1.1185 +      { NULL } };
  1.1186 +#else     
  1.1187 +  GOptionEntry entries [2];
  1.1188 +  
  1.1189 +  entries[0].long_name = "test";
  1.1190 +  entries[0].short_name = 0;
  1.1191 +  entries[0].flags = 0;
  1.1192 +  entries[0].arg = G_OPTION_ARG_STRING_ARRAY;
  1.1193 +  entries[0].arg_data = (gpointer)&array_test1_array;
  1.1194 +  entries[0].description =  NULL;
  1.1195 +  entries[0].arg_description = NULL;
  1.1196 +      
  1.1197 +  entries[1].long_name = NULL;
  1.1198 +  entries[1].short_name = 0;
  1.1199 +  entries[1].arg_data = NULL;
  1.1200 +  entries[1].description =  NULL;
  1.1201 +  entries[1].arg_description = NULL;
  1.1202 +#endif      
  1.1203 +        
  1.1204 +  context = g_option_context_new (NULL);
  1.1205 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1206 +
  1.1207 +  /* Now try parsing */
  1.1208 +  argv = split_string ("program --test foo --test bar", &argc);
  1.1209 +  
  1.1210 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1211 +  g_assert (retval);
  1.1212 +
  1.1213 +  /* Check array */
  1.1214 +  g_assert (strcmp (array_test1_array[0], "foo") == 0);
  1.1215 +  g_assert (strcmp (array_test1_array[1], "bar") == 0);
  1.1216 +  g_assert (array_test1_array[2] == NULL);
  1.1217 +
  1.1218 +  g_strfreev (array_test1_array);
  1.1219 +  
  1.1220 +  g_strfreev (argv);
  1.1221 +  g_option_context_free (context);
  1.1222 +}
  1.1223 +
  1.1224 +void
  1.1225 +add_test1 (void)
  1.1226 +{
  1.1227 +  GOptionContext *context;
  1.1228 +
  1.1229 +#ifndef SYMBIAN
  1.1230 +  GOptionEntry entries1 [] =
  1.1231 +    { { "test1", 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, NULL },
  1.1232 +      { NULL } };
  1.1233 +  GOptionEntry entries2 [] =
  1.1234 +    { { "test2", 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, NULL },
  1.1235 +      { NULL } };
  1.1236 +#else      
  1.1237 +  GOptionEntry entries1 [2];
  1.1238 +  GOptionEntry entries2 [2];
  1.1239 +  
  1.1240 +  entries1[0].long_name = "test1";
  1.1241 +  entries1[0].short_name = 0;
  1.1242 +  entries1[0].flags = 0;
  1.1243 +  entries1[0].arg = G_OPTION_ARG_STRING_ARRAY;
  1.1244 +  entries1[0].arg_data = NULL;
  1.1245 +  entries1[0].description =  NULL;
  1.1246 +  entries1[0].arg_description = NULL;
  1.1247 +      
  1.1248 +  entries1[1].long_name = NULL;
  1.1249 +  entries1[1].short_name = 0;
  1.1250 +  entries1[1].arg_data = NULL;
  1.1251 +  entries1[1].description =  NULL;
  1.1252 +  entries1[1].arg_description = NULL;
  1.1253 +      
  1.1254 +  
  1.1255 +  entries2[0].long_name = "test2";
  1.1256 +  entries2[0].short_name = 0;
  1.1257 +  entries2[0].flags = 0;
  1.1258 +  entries2[0].arg = G_OPTION_ARG_STRING_ARRAY;
  1.1259 +  entries2[0].arg_data = NULL;
  1.1260 +  entries2[0].description =  NULL;
  1.1261 +  entries2[0].arg_description = NULL;
  1.1262 +      
  1.1263 +  entries2[1].long_name = NULL;
  1.1264 +  entries2[1].short_name = 0;
  1.1265 +  entries2[1].arg_data = NULL;
  1.1266 +  entries2[1].description =  NULL;
  1.1267 +  entries2[1].arg_description = NULL;
  1.1268 +#endif
  1.1269 +
  1.1270 +  context = g_option_context_new (NULL);
  1.1271 +  g_option_context_add_main_entries (context, entries1, NULL);
  1.1272 +  g_option_context_add_main_entries (context, entries2, NULL);
  1.1273 +
  1.1274 +  g_option_context_free (context);
  1.1275 +}
  1.1276 +
  1.1277 +void
  1.1278 +empty_test1 (void)
  1.1279 +{
  1.1280 +  GOptionContext *context;
  1.1281 +  GOptionEntry entries [] =
  1.1282 +    { { NULL } };
  1.1283 +
  1.1284 +  g_set_prgname (NULL);
  1.1285 +
  1.1286 +  context = g_option_context_new (NULL);
  1.1287 +
  1.1288 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1289 +  
  1.1290 +  g_option_context_parse (context, NULL, NULL, NULL);
  1.1291 +
  1.1292 +  g_assert (strcmp (g_get_prgname (), "<unknown>") == 0);
  1.1293 +  
  1.1294 +  g_option_context_free (context);
  1.1295 +}
  1.1296 +
  1.1297 +void
  1.1298 +empty_test2 (void)
  1.1299 +{
  1.1300 +  GOptionContext *context;
  1.1301 +
  1.1302 +  context = g_option_context_new (NULL);
  1.1303 +  g_option_context_parse (context, NULL, NULL, NULL);
  1.1304 +  
  1.1305 +  g_option_context_free (context);
  1.1306 +}
  1.1307 +
  1.1308 +void
  1.1309 +empty_test3 (void)
  1.1310 +{
  1.1311 +  GOptionContext *context;
  1.1312 +  gint argc;
  1.1313 +  gchar **argv;
  1.1314 +
  1.1315 +  argc = 0;
  1.1316 +  argv = NULL;
  1.1317 +
  1.1318 +  context = g_option_context_new (NULL);
  1.1319 +  g_option_context_parse (context, &argc, &argv, NULL);
  1.1320 +  
  1.1321 +  g_option_context_free (context);
  1.1322 +}
  1.1323 +
  1.1324 +/* check that non-option arguments are left in argv by default */
  1.1325 +void
  1.1326 +rest_test1 (void)
  1.1327 +{
  1.1328 +  GOptionContext *context;
  1.1329 +  gboolean retval;
  1.1330 +  GError *error = NULL;
  1.1331 +  gchar **argv;
  1.1332 +  int argc;
  1.1333 +#ifndef SYMBIAN  
  1.1334 +  GOptionEntry entries [] = { 
  1.1335 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1336 +      { NULL } 
  1.1337 +  };
  1.1338 +#else  
  1.1339 +  GOptionEntry entries [2];
  1.1340 +  
  1.1341 +  entries[0].long_name = "test";
  1.1342 +  entries[0].short_name = 0;
  1.1343 +  entries[0].flags = 0;
  1.1344 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1345 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1346 +  entries[0].description =  NULL;
  1.1347 +  entries[0].arg_description = NULL;
  1.1348 +      
  1.1349 +  entries[1].long_name = NULL;
  1.1350 +  entries[1].short_name = 0;
  1.1351 +  entries[1].arg_data = NULL;
  1.1352 +  entries[1].description =  NULL;
  1.1353 +  entries[1].arg_description = NULL;
  1.1354 +#endif
  1.1355 +        
  1.1356 +  context = g_option_context_new (NULL);
  1.1357 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1358 +
  1.1359 +  /* Now try parsing */
  1.1360 +  argv = split_string ("program foo --test bar", &argc);
  1.1361 +  
  1.1362 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1363 +  g_assert (retval);
  1.1364 +
  1.1365 +  /* Check array */
  1.1366 +  g_assert (ignore_test1_boolean);
  1.1367 +  g_assert (strcmp (argv[0], "program") == 0);
  1.1368 +  g_assert (strcmp (argv[1], "foo") == 0);
  1.1369 +  g_assert (strcmp (argv[2], "bar") == 0);
  1.1370 +  g_assert (argv[3] == NULL);
  1.1371 +
  1.1372 +  g_strfreev (argv);
  1.1373 +  g_option_context_free (context);
  1.1374 +}
  1.1375 +
  1.1376 +/* check that -- works */
  1.1377 +void
  1.1378 +rest_test2 (void)
  1.1379 +{
  1.1380 +  GOptionContext *context;
  1.1381 +  gboolean retval;
  1.1382 +  GError *error = NULL;
  1.1383 +  gchar **argv;
  1.1384 +  int argc;
  1.1385 +#ifndef SYMBIAN  
  1.1386 +  GOptionEntry entries [] = { 
  1.1387 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1388 +      { NULL } 
  1.1389 +  };
  1.1390 +#else  
  1.1391 +  GOptionEntry entries [2];
  1.1392 +  
  1.1393 +  entries[0].long_name = "test";
  1.1394 +  entries[0].short_name = 0;
  1.1395 +  entries[0].flags = 0;
  1.1396 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1397 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1398 +  entries[0].description =  NULL;
  1.1399 +  entries[0].arg_description = NULL;
  1.1400 +      
  1.1401 +  entries[1].long_name = NULL;
  1.1402 +  entries[1].short_name = 0;
  1.1403 +  entries[1].arg_data = NULL;
  1.1404 +  entries[1].description =  NULL;
  1.1405 +  entries[1].arg_description = NULL;
  1.1406 +#endif
  1.1407 +        
  1.1408 +  context = g_option_context_new (NULL);
  1.1409 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1410 +
  1.1411 +  /* Now try parsing */
  1.1412 +  argv = split_string ("program foo --test -- -bar", &argc);
  1.1413 +  
  1.1414 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1415 +  g_assert (retval);
  1.1416 +
  1.1417 +  /* Check array */
  1.1418 +  g_assert (ignore_test1_boolean);
  1.1419 +  g_assert (strcmp (argv[0], "program") == 0);
  1.1420 +  g_assert (strcmp (argv[1], "foo") == 0);
  1.1421 +  g_assert (strcmp (argv[2], "--") == 0);
  1.1422 +  g_assert (strcmp (argv[3], "-bar") == 0);
  1.1423 +  g_assert (argv[4] == NULL);
  1.1424 +
  1.1425 +  g_strfreev (argv);
  1.1426 +  g_option_context_free (context);
  1.1427 +}
  1.1428 +
  1.1429 +/* check that -- stripping works */
  1.1430 +void
  1.1431 +rest_test2a (void)
  1.1432 +{
  1.1433 +  GOptionContext *context;
  1.1434 +  gboolean retval;
  1.1435 +  GError *error = NULL;
  1.1436 +  gchar **argv;
  1.1437 +  int argc;
  1.1438 +#ifndef SYMBIAN  
  1.1439 +  GOptionEntry entries [] = { 
  1.1440 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1441 +      { NULL } 
  1.1442 +  };
  1.1443 +#else 
  1.1444 +  GOptionEntry entries [2];
  1.1445 +  
  1.1446 +  entries[0].long_name = "test";
  1.1447 +  entries[0].short_name = 0;
  1.1448 +  entries[0].flags = 0;
  1.1449 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1450 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1451 +  entries[0].description =  NULL;
  1.1452 +  entries[0].arg_description = NULL;
  1.1453 +      
  1.1454 +  entries[1].long_name = NULL;
  1.1455 +  entries[1].short_name = 0;
  1.1456 +  entries[1].arg_data = NULL;
  1.1457 +  entries[1].description =  NULL;
  1.1458 +  entries[1].arg_description = NULL;
  1.1459 +#endif
  1.1460 +        
  1.1461 +  context = g_option_context_new (NULL);
  1.1462 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1463 +
  1.1464 +  /* Now try parsing */
  1.1465 +  argv = split_string ("program foo --test -- bar", &argc);
  1.1466 +  
  1.1467 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1468 +  g_assert (retval);
  1.1469 +
  1.1470 +  /* Check array */
  1.1471 +  g_assert (ignore_test1_boolean);
  1.1472 +  g_assert (strcmp (argv[0], "program") == 0);
  1.1473 +  g_assert (strcmp (argv[1], "foo") == 0);
  1.1474 +  g_assert (strcmp (argv[2], "bar") == 0);
  1.1475 +  g_assert (argv[3] == NULL);
  1.1476 +
  1.1477 +  g_strfreev (argv);
  1.1478 +  g_option_context_free (context);
  1.1479 +}
  1.1480 +
  1.1481 +void
  1.1482 +rest_test2b (void)
  1.1483 +{
  1.1484 +  GOptionContext *context;
  1.1485 +  gboolean retval;
  1.1486 +  GError *error = NULL;
  1.1487 +  gchar **argv;
  1.1488 +  int argc;
  1.1489 +#ifndef SYMBIAN  
  1.1490 +  GOptionEntry entries [] = { 
  1.1491 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1492 +      { NULL } 
  1.1493 +  };
  1.1494 +#else  
  1.1495 +  GOptionEntry entries [2];
  1.1496 +  
  1.1497 +  entries[0].long_name = "test";
  1.1498 +  entries[0].short_name = 0;
  1.1499 +  entries[0].flags = 0;
  1.1500 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1501 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1502 +  entries[0].description =  NULL;
  1.1503 +  entries[0].arg_description = NULL;
  1.1504 +      
  1.1505 +  entries[1].long_name = NULL;
  1.1506 +  entries[1].short_name = 0;
  1.1507 +  entries[1].arg_data = NULL;
  1.1508 +  entries[1].description =  NULL;
  1.1509 +  entries[1].arg_description = NULL;
  1.1510 +#endif
  1.1511 +        
  1.1512 +  context = g_option_context_new (NULL);
  1.1513 +  g_option_context_set_ignore_unknown_options (context, TRUE);
  1.1514 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1515 +
  1.1516 +  /* Now try parsing */
  1.1517 +  argv = split_string ("program foo --test -bar --", &argc);
  1.1518 +  
  1.1519 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1520 +  g_assert (retval);
  1.1521 +
  1.1522 +  /* Check array */
  1.1523 +  g_assert (ignore_test1_boolean);
  1.1524 +  g_assert (strcmp (argv[0], "program") == 0);
  1.1525 +  g_assert (strcmp (argv[1], "foo") == 0);
  1.1526 +  g_assert (strcmp (argv[2], "-bar") == 0);
  1.1527 +  g_assert (argv[3] == NULL);
  1.1528 +
  1.1529 +  g_strfreev (argv);
  1.1530 +  g_option_context_free (context);
  1.1531 +}
  1.1532 +
  1.1533 +void
  1.1534 +rest_test2c (void)
  1.1535 +{
  1.1536 +  GOptionContext *context;
  1.1537 +  gboolean retval;
  1.1538 +  GError *error = NULL;
  1.1539 +  gchar **argv;
  1.1540 +  int argc;
  1.1541 +#ifndef SYMBIAN  
  1.1542 +  GOptionEntry entries [] = { 
  1.1543 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1544 +      { NULL } 
  1.1545 +  };
  1.1546 +#else  
  1.1547 +  GOptionEntry entries [2];
  1.1548 +  
  1.1549 +  entries[0].long_name = "test";
  1.1550 +  entries[0].short_name = 0;
  1.1551 +  entries[0].flags = 0;
  1.1552 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1553 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1554 +  entries[0].description =  NULL;
  1.1555 +  entries[0].arg_description = NULL;
  1.1556 +      
  1.1557 +  entries[1].long_name = NULL;
  1.1558 +  entries[1].short_name = 0;
  1.1559 +  entries[1].arg_data = NULL;
  1.1560 +  entries[1].description =  NULL;
  1.1561 +  entries[1].arg_description = NULL;
  1.1562 +#endif
  1.1563 +        
  1.1564 +  context = g_option_context_new (NULL);
  1.1565 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1566 +
  1.1567 +  /* Now try parsing */
  1.1568 +  argv = split_string ("program --test foo -- bar", &argc);
  1.1569 +  
  1.1570 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1571 +  g_assert (retval);
  1.1572 +
  1.1573 +  /* Check array */
  1.1574 +  g_assert (ignore_test1_boolean);
  1.1575 +  g_assert (strcmp (argv[0], "program") == 0);
  1.1576 +  g_assert (strcmp (argv[1], "foo") == 0);
  1.1577 +  g_assert (strcmp (argv[2], "bar") == 0);
  1.1578 +  g_assert (argv[3] == NULL);
  1.1579 +
  1.1580 +  g_strfreev (argv);
  1.1581 +  g_option_context_free (context);
  1.1582 +}
  1.1583 +
  1.1584 +void
  1.1585 +rest_test2d (void)
  1.1586 +{
  1.1587 +  GOptionContext *context;
  1.1588 +  gboolean retval;
  1.1589 +  GError *error = NULL;
  1.1590 +  gchar **argv;
  1.1591 +  int argc;
  1.1592 +#ifndef SYMBIAN  
  1.1593 +  GOptionEntry entries [] = { 
  1.1594 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1595 +      { NULL } 
  1.1596 +  };
  1.1597 +#else  
  1.1598 +  GOptionEntry entries [2];
  1.1599 +  
  1.1600 +  entries[0].long_name = "test";
  1.1601 +  entries[0].short_name = 0;
  1.1602 +  entries[0].flags = 0;
  1.1603 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1604 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1605 +  entries[0].description =  NULL;
  1.1606 +  entries[0].arg_description = NULL;
  1.1607 +      
  1.1608 +  entries[1].long_name = NULL;
  1.1609 +  entries[1].short_name = 0;
  1.1610 +  entries[1].arg_data = NULL;
  1.1611 +  entries[1].description =  NULL;
  1.1612 +  entries[1].arg_description = NULL;
  1.1613 +#endif
  1.1614 +        
  1.1615 +  context = g_option_context_new (NULL);
  1.1616 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1617 +
  1.1618 +  /* Now try parsing */
  1.1619 +  argv = split_string ("program --test -- -bar", &argc);
  1.1620 +  
  1.1621 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1622 +  g_assert (retval);
  1.1623 +
  1.1624 +  /* Check array */
  1.1625 +  g_assert (ignore_test1_boolean);
  1.1626 +  g_assert (strcmp (argv[0], "program") == 0);
  1.1627 +  g_assert (strcmp (argv[1], "--") == 0);
  1.1628 +  g_assert (strcmp (argv[2], "-bar") == 0);
  1.1629 +  g_assert (argv[3] == NULL);
  1.1630 +
  1.1631 +  g_strfreev (argv);
  1.1632 +  g_option_context_free (context);
  1.1633 +}
  1.1634 +
  1.1635 +
  1.1636 +/* check that G_OPTION_REMAINING collects non-option arguments */
  1.1637 +void
  1.1638 +rest_test3 (void)
  1.1639 +{
  1.1640 +  GOptionContext *context;
  1.1641 +  gboolean retval;
  1.1642 +  GError *error = NULL;
  1.1643 +  gchar **argv;
  1.1644 +  int argc;
  1.1645 +#ifndef SYMBIAN  
  1.1646 +  GOptionEntry entries [] = { 
  1.1647 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1648 +      { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &array_test1_array, NULL, NULL },
  1.1649 +      { NULL } 
  1.1650 +  };
  1.1651 +#else  
  1.1652 +  GOptionEntry entries [3];
  1.1653 +  
  1.1654 +  entries[0].long_name = "test";
  1.1655 +  entries[0].short_name = 0;
  1.1656 +  entries[0].flags = 0;
  1.1657 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1658 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1659 +  entries[0].description =  NULL;
  1.1660 +  entries[0].arg_description = NULL;
  1.1661 +      
  1.1662 +      
  1.1663 +  entries[1].long_name = G_OPTION_REMAINING;
  1.1664 +  entries[1].short_name = 0;
  1.1665 +  entries[1].flags = 0;
  1.1666 +  entries[1].arg = G_OPTION_ARG_STRING_ARRAY;
  1.1667 +  entries[1].arg_data = (gpointer)&array_test1_array;
  1.1668 +  entries[1].description =  NULL;
  1.1669 +  entries[1].arg_description = NULL;
  1.1670 +
  1.1671 +  entries[2].long_name = NULL;
  1.1672 +  entries[2].short_name = 0;
  1.1673 +  entries[2].arg_data = NULL;
  1.1674 +  entries[2].description =  NULL;
  1.1675 +  entries[2].arg_description = NULL;
  1.1676 +#endif
  1.1677 +        
  1.1678 +  context = g_option_context_new (NULL);
  1.1679 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1680 +
  1.1681 +  /* Now try parsing */
  1.1682 +  argv = split_string ("program foo --test bar", &argc);
  1.1683 +  
  1.1684 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1685 +  g_assert (retval);
  1.1686 +
  1.1687 +  /* Check array */
  1.1688 +  g_assert (ignore_test1_boolean);
  1.1689 +  g_assert (strcmp (array_test1_array[0], "foo") == 0);
  1.1690 +  g_assert (strcmp (array_test1_array[1], "bar") == 0);
  1.1691 +  g_assert (array_test1_array[2] == NULL);
  1.1692 +
  1.1693 +  g_strfreev (array_test1_array);
  1.1694 +  
  1.1695 +  g_strfreev (argv);
  1.1696 +  g_option_context_free (context);
  1.1697 +}
  1.1698 +
  1.1699 +
  1.1700 +/* check that G_OPTION_REMAINING and -- work together */
  1.1701 +void
  1.1702 +rest_test4 (void)
  1.1703 +{
  1.1704 +  GOptionContext *context;
  1.1705 +  gboolean retval;
  1.1706 +  GError *error = NULL;
  1.1707 +  gchar **argv;
  1.1708 +  int argc;
  1.1709 +#ifndef SYMBIAN  
  1.1710 +  GOptionEntry entries [] = { 
  1.1711 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1712 +      { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &array_test1_array, NULL, NULL },
  1.1713 +      { NULL } 
  1.1714 +  };
  1.1715 +#else  
  1.1716 +  GOptionEntry entries [3];
  1.1717 +  
  1.1718 +  entries[0].long_name = "test";
  1.1719 +  entries[0].short_name = 0;
  1.1720 +  entries[0].flags = 0;
  1.1721 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1722 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1723 +  entries[0].description =  NULL;
  1.1724 +  entries[0].arg_description = NULL;
  1.1725 +      
  1.1726 +      
  1.1727 +  entries[1].long_name = G_OPTION_REMAINING;
  1.1728 +  entries[1].short_name = 0;
  1.1729 +  entries[1].flags = 0;
  1.1730 +  entries[1].arg = G_OPTION_ARG_STRING_ARRAY;
  1.1731 +  entries[1].arg_data = (gpointer)&array_test1_array;
  1.1732 +  entries[1].description =  NULL;
  1.1733 +  entries[1].arg_description = NULL;
  1.1734 +
  1.1735 +  entries[2].long_name = NULL;
  1.1736 +  entries[2].short_name = 0;
  1.1737 +  entries[2].arg_data = NULL;
  1.1738 +  entries[2].description =  NULL;
  1.1739 +  entries[2].arg_description = NULL;
  1.1740 +#endif
  1.1741 +        
  1.1742 +  context = g_option_context_new (NULL);
  1.1743 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1744 +
  1.1745 +  /* Now try parsing */
  1.1746 +  argv = split_string ("program foo --test -- -bar", &argc);
  1.1747 +  
  1.1748 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1749 +  g_assert (retval);
  1.1750 +
  1.1751 +  /* Check array */
  1.1752 +  g_assert (ignore_test1_boolean);
  1.1753 +  g_assert (strcmp (array_test1_array[0], "foo") == 0);
  1.1754 +  g_assert (strcmp (array_test1_array[1], "-bar") == 0);
  1.1755 +  g_assert (array_test1_array[2] == NULL);
  1.1756 +
  1.1757 +  g_strfreev (array_test1_array);
  1.1758 +  
  1.1759 +  g_strfreev (argv);
  1.1760 +  g_option_context_free (context);
  1.1761 +}
  1.1762 +
  1.1763 +/* test that G_OPTION_REMAINING works with G_OPTION_ARG_FILENAME_ARRAY */
  1.1764 +void
  1.1765 +rest_test5 (void)
  1.1766 +{
  1.1767 +  GOptionContext *context;
  1.1768 +  gboolean retval;
  1.1769 +  GError *error = NULL;
  1.1770 +  gchar **argv;
  1.1771 +  int argc;
  1.1772 +  
  1.1773 +#ifndef SYMBIAN  
  1.1774 +  GOptionEntry entries [] = { 
  1.1775 +      { "test", 0, 0, G_OPTION_ARG_NONE, &ignore_test1_boolean, NULL, NULL },
  1.1776 +      { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &array_test1_array, NULL, NULL },
  1.1777 +      { NULL } 
  1.1778 +  };
  1.1779 +#else  
  1.1780 +  GOptionEntry entries [3];
  1.1781 +  
  1.1782 +  entries[0].long_name = "test";
  1.1783 +  entries[0].short_name = 0;
  1.1784 +  entries[0].flags = 0;
  1.1785 +  entries[0].arg = G_OPTION_ARG_NONE;
  1.1786 +  entries[0].arg_data = (gpointer)&ignore_test1_boolean;
  1.1787 +  entries[0].description =  NULL;
  1.1788 +  entries[0].arg_description = NULL;
  1.1789 +      
  1.1790 +      
  1.1791 +  entries[1].long_name = G_OPTION_REMAINING;
  1.1792 +  entries[1].short_name = 0;
  1.1793 +  entries[1].flags = 0;
  1.1794 +  entries[1].arg = G_OPTION_ARG_FILENAME_ARRAY;
  1.1795 +  entries[1].arg_data = (gpointer)&array_test1_array;
  1.1796 +  entries[1].description =  NULL;
  1.1797 +  entries[1].arg_description = NULL;
  1.1798 +
  1.1799 +  entries[2].long_name = NULL;
  1.1800 +  entries[2].short_name = 0;
  1.1801 +  entries[2].arg_data = NULL;
  1.1802 +  entries[2].description =  NULL;
  1.1803 +  entries[2].arg_description = NULL;
  1.1804 +#endif
  1.1805 +        
  1.1806 +  context = g_option_context_new (NULL);
  1.1807 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1808 +
  1.1809 +  /* Now try parsing */
  1.1810 +  argv = split_string ("program foo --test bar", &argc);
  1.1811 +  
  1.1812 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1813 +  g_assert (retval);
  1.1814 +
  1.1815 +  /* Check array */
  1.1816 +  g_assert (ignore_test1_boolean);
  1.1817 +  g_assert (strcmp (array_test1_array[0], "foo") == 0);
  1.1818 +  g_assert (strcmp (array_test1_array[1], "bar") == 0);
  1.1819 +  g_assert (array_test1_array[2] == NULL);
  1.1820 +
  1.1821 +  g_strfreev (array_test1_array);
  1.1822 +  
  1.1823 +  g_strfreev (argv);
  1.1824 +  g_option_context_free (context);
  1.1825 +}
  1.1826 +
  1.1827 +void
  1.1828 +unknown_short_test (void)
  1.1829 +{
  1.1830 +  GOptionContext *context;
  1.1831 +  gboolean retval;
  1.1832 +  GError *error = NULL;
  1.1833 +  gchar **argv;
  1.1834 +  int argc;
  1.1835 +#ifndef SYMBIAN  
  1.1836 +  GOptionEntry entries [] = { { NULL } };
  1.1837 +#else
  1.1838 +  GOptionEntry entries [1];
  1.1839 +
  1.1840 +  entries[0].long_name = NULL;
  1.1841 +  entries[0].short_name = 0;
  1.1842 +  entries[0].arg_data = NULL;
  1.1843 +  entries[0].description =  NULL;
  1.1844 +  entries[0].arg_description = NULL;
  1.1845 +#endif
  1.1846 +
  1.1847 +  context = g_option_context_new (NULL);
  1.1848 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1849 +
  1.1850 +  /* Now try parsing */
  1.1851 +  argv = split_string ("program -0", &argc);
  1.1852 +
  1.1853 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1854 +  g_assert (!retval);
  1.1855 +
  1.1856 +  g_strfreev (argv);
  1.1857 +  g_option_context_free (context);
  1.1858 +}
  1.1859 +
  1.1860 +/* test that lone dashes are treated as non-options */
  1.1861 +void lonely_dash_test (void)
  1.1862 +{
  1.1863 +  GOptionContext *context;
  1.1864 +  gboolean retval;
  1.1865 +  GError *error = NULL;
  1.1866 +  gchar **argv;
  1.1867 +  int argc;
  1.1868 +
  1.1869 +  context = g_option_context_new (NULL);
  1.1870 +
  1.1871 +  /* Now try parsing */
  1.1872 +  argv = split_string ("program -", &argc);
  1.1873 +
  1.1874 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1875 +
  1.1876 +  g_assert (retval);
  1.1877 +
  1.1878 +  g_assert (argv[1] && strcmp (argv[1], "-") == 0);
  1.1879 +
  1.1880 +  g_strfreev (argv);
  1.1881 +  g_option_context_free (context);
  1.1882 +}
  1.1883 +
  1.1884 +void
  1.1885 +missing_arg_test (void)
  1.1886 +{
  1.1887 +  GOptionContext *context;
  1.1888 +  gboolean retval;
  1.1889 +  GError *error = NULL;
  1.1890 +  gchar **argv;
  1.1891 +  int argc;
  1.1892 +  gchar *arg = NULL;
  1.1893 +#ifndef SYMBIAN  
  1.1894 +  GOptionEntry entries [] =
  1.1895 +    { { "test", 't', 0, G_OPTION_ARG_STRING, &arg, NULL, NULL },
  1.1896 +      { NULL } };
  1.1897 +#else      
  1.1898 +  GOptionEntry entries [2];
  1.1899 +  
  1.1900 +  entries[0].long_name = "test";
  1.1901 +  entries[0].short_name = 't';
  1.1902 +  entries[0].flags = 0;
  1.1903 +  entries[0].arg = G_OPTION_ARG_STRING;
  1.1904 +  entries[0].arg_data = (gpointer)&arg;
  1.1905 +  entries[0].description =  NULL;
  1.1906 +  entries[0].arg_description = NULL;
  1.1907 +      
  1.1908 +  entries[1].long_name = NULL;
  1.1909 +  entries[1].short_name = 0;
  1.1910 +  entries[1].arg_data = NULL;
  1.1911 +  entries[1].description =  NULL;
  1.1912 +  entries[1].arg_description = NULL;
  1.1913 +#endif
  1.1914 +
  1.1915 +  context = g_option_context_new (NULL);
  1.1916 +  g_option_context_add_main_entries (context, entries, NULL);
  1.1917 +
  1.1918 +  /* Now try parsing */
  1.1919 +  argv = split_string ("program --test", &argc);
  1.1920 +
  1.1921 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1922 +  g_assert (retval == FALSE);
  1.1923 +  g_clear_error (&error);
  1.1924 +
  1.1925 +  g_strfreev (argv);
  1.1926 +
  1.1927 +  /* Try parsing again */
  1.1928 +  argv = split_string ("program --t", &argc);
  1.1929 +
  1.1930 +  retval = g_option_context_parse (context, &argc, &argv, &error);
  1.1931 +  g_assert (retval == FALSE);
  1.1932 +
  1.1933 +  g_strfreev (argv);
  1.1934 +  g_option_context_free (context);
  1.1935 +}
  1.1936 +
  1.1937 +int
  1.1938 +main (int argc, char **argv)
  1.1939 +{
  1.1940 +  #ifdef SYMBIAN
  1.1941 +  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);
  1.1942 +  g_set_print_handler(mrtPrintHandler);
  1.1943 +  #endif /*SYMBIAN*/
  1.1944 +  /* Test that restoration on failure works */
  1.1945 +  error_test1_int = 0x12345678;
  1.1946 +  error_test1 ();
  1.1947 +  error_test2_string = "foo";
  1.1948 +  error_test2 ();
  1.1949 +  error_test3_boolean = FALSE;
  1.1950 +  error_test3 ();
  1.1951 +  
  1.1952 +  /* Test that special argument parsing works */
  1.1953 +  arg_test1 ();
  1.1954 +  arg_test2 ();
  1.1955 +  arg_test3 ();
  1.1956 +
  1.1957 +  /* Test string arrays */
  1.1958 +  array_test1 ();
  1.1959 +
  1.1960 +  /* Test callback args */
  1.1961 +  callback_test1 ();
  1.1962 +  callback_test2 ();
  1.1963 +
  1.1964 +  /* Test optional arg flag for callback */
  1.1965 +  callback_test_optional_1 ();
  1.1966 +  callback_test_optional_2 ();
  1.1967 +  callback_test_optional_3 ();
  1.1968 +  callback_test_optional_4 ();
  1.1969 +  callback_test_optional_5 ();
  1.1970 +  callback_test_optional_6 ();
  1.1971 +  callback_test_optional_7 ();
  1.1972 +  callback_test_optional_8 ();
  1.1973 +  
  1.1974 +  /* Test ignoring options */
  1.1975 +  ignore_test1 ();
  1.1976 +  ignore_test2 ();
  1.1977 +  ignore_test3 ();
  1.1978 +
  1.1979 +  add_test1 ();
  1.1980 +
  1.1981 +  /* Test parsing empty args */
  1.1982 +  empty_test1 ();
  1.1983 +  empty_test2 ();
  1.1984 +  empty_test3 ();
  1.1985 +
  1.1986 +  /* Test handling of rest args */
  1.1987 +  rest_test1 ();
  1.1988 +  rest_test2 ();
  1.1989 +  rest_test2a ();
  1.1990 +  rest_test2b ();
  1.1991 +  rest_test2c ();
  1.1992 +  rest_test2d ();
  1.1993 +  rest_test3 ();
  1.1994 +  rest_test4 ();
  1.1995 +  rest_test5 ();
  1.1996 +
  1.1997 +  /* test for bug 166609 */
  1.1998 +  unknown_short_test ();
  1.1999 +
  1.2000 +  /* test for bug 168008 */
  1.2001 +  lonely_dash_test ();
  1.2002 +
  1.2003 +  /* test for bug 305576 */
  1.2004 +  missing_arg_test ();
  1.2005 +
  1.2006 +#ifdef SYMBIAN
  1.2007 +  testResultXml("option-test");
  1.2008 +#endif /* EMULATOR */
  1.2009 +  return 0;
  1.2010 +}