os/ossrv/glib/tsrc/BC/tests/keyfile-test.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. */
sl@0
     2
#include <glib.h>
sl@0
     3
#include <locale.h>
sl@0
     4
#include <string.h>
sl@0
     5
#include <stdlib.h>
sl@0
     6
#include <stdio.h>
sl@0
     7
sl@0
     8
#ifdef SYMBIAN
sl@0
     9
#include "mrt2_glib2_test.h"
sl@0
    10
#endif /*SYMBIAN*/
sl@0
    11
sl@0
    12
sl@0
    13
static GKeyFile *
sl@0
    14
load_data (const gchar   *data, 
sl@0
    15
	   GKeyFileFlags  flags)
sl@0
    16
{
sl@0
    17
  GKeyFile *keyfile;
sl@0
    18
  GError *error = NULL;
sl@0
    19
sl@0
    20
  keyfile = g_key_file_new ();
sl@0
    21
  g_key_file_load_from_data (keyfile, data, -1, flags, &error);
sl@0
    22
  if (error)
sl@0
    23
    {
sl@0
    24
      g_print ("Could not load data: %s\n", error->message);
sl@0
    25
      
sl@0
    26
      g_assert(FALSE && "keyfile-test failed");
sl@0
    27
      
sl@0
    28
      #ifdef SYMBIAN
sl@0
    29
  	  testResultXml("keyfile-test");
sl@0
    30
  	  #endif /* EMULATOR */
sl@0
    31
  	  
sl@0
    32
      exit (1);
sl@0
    33
    }
sl@0
    34
  
sl@0
    35
  return keyfile;
sl@0
    36
}
sl@0
    37
sl@0
    38
static void
sl@0
    39
check_error (GError **error,
sl@0
    40
	     GQuark   domain,
sl@0
    41
	     gint     code)
sl@0
    42
{
sl@0
    43
  if (*error == NULL)
sl@0
    44
    {
sl@0
    45
      g_print ("Missing an error\n");
sl@0
    46
            
sl@0
    47
      g_assert(FALSE && "keyfile-test failed");
sl@0
    48
      
sl@0
    49
      #ifdef SYMBIAN
sl@0
    50
  	  testResultXml("keyfile-test");
sl@0
    51
  	  #endif /* EMULATOR */
sl@0
    52
  	  
sl@0
    53
      exit (1);
sl@0
    54
    }
sl@0
    55
  
sl@0
    56
  if ((*error)->domain != domain)
sl@0
    57
    {
sl@0
    58
      g_print ("Wrong error domain: got %s, expected %s\n",
sl@0
    59
	       g_quark_to_string ((*error)->domain),
sl@0
    60
	       g_quark_to_string (domain));      
sl@0
    61
sl@0
    62
      g_assert(FALSE && "keyfile-test failed");
sl@0
    63
      
sl@0
    64
      #ifdef SYMBIAN
sl@0
    65
  	  testResultXml("keyfile-test");
sl@0
    66
  	  #endif /* EMULATOR */ 	  
sl@0
    67
sl@0
    68
      exit (1);
sl@0
    69
    }
sl@0
    70
  
sl@0
    71
  if ((*error)->code != code)
sl@0
    72
    {
sl@0
    73
      g_print ("Wrong error code: got %d, expected %d\n",
sl@0
    74
	       (*error)->code, code);
sl@0
    75
	        
sl@0
    76
      g_assert(FALSE && "keyfile-test failed");
sl@0
    77
      
sl@0
    78
      #ifdef SYMBIAN
sl@0
    79
  	  testResultXml("keyfile-test");
sl@0
    80
  	  #endif /* EMULATOR */
sl@0
    81
  	  
sl@0
    82
      exit (1);
sl@0
    83
    }
sl@0
    84
sl@0
    85
  g_error_free (*error);
sl@0
    86
  *error = NULL;
sl@0
    87
}
sl@0
    88
sl@0
    89
static void 
sl@0
    90
check_no_error (GError **error)
sl@0
    91
{
sl@0
    92
  if (*error != NULL)
sl@0
    93
    {
sl@0
    94
      g_print ("Unexpected error: (%s, %d) %s\n",
sl@0
    95
	       g_quark_to_string ((*error)->domain),
sl@0
    96
	       (*error)->code, (*error)->message);	        
sl@0
    97
sl@0
    98
      g_assert(FALSE && "keyfile-test failed");
sl@0
    99
      
sl@0
   100
      #ifdef SYMBIAN
sl@0
   101
  	  testResultXml("keyfile-test");
sl@0
   102
  	  #endif /* EMULATOR */
sl@0
   103
  	  
sl@0
   104
      exit (1);
sl@0
   105
    }
sl@0
   106
}
sl@0
   107
sl@0
   108
static void
sl@0
   109
check_string_value (GKeyFile    *keyfile,
sl@0
   110
		    const gchar *group,
sl@0
   111
		    const gchar *key,
sl@0
   112
		    const gchar *expected) 
sl@0
   113
{
sl@0
   114
  GError *error = NULL;
sl@0
   115
  gchar *value;
sl@0
   116
sl@0
   117
  value = g_key_file_get_string (keyfile, group, key, &error);
sl@0
   118
  check_no_error (&error);
sl@0
   119
  g_assert (value != NULL);
sl@0
   120
sl@0
   121
  if (strcmp (value, expected) != 0)
sl@0
   122
    {
sl@0
   123
      g_print ("Group %s key %s: "
sl@0
   124
	       "expected string value '%s', actual value '%s'\n",
sl@0
   125
	       group, key, expected, value); 
sl@0
   126
	  	        
sl@0
   127
      g_assert(FALSE && "keyfile-test failed");
sl@0
   128
      
sl@0
   129
      #ifdef SYMBIAN
sl@0
   130
  	  testResultXml("keyfile-test");
sl@0
   131
  	  #endif /* EMULATOR */
sl@0
   132
  	      
sl@0
   133
      exit (1);
sl@0
   134
    }
sl@0
   135
sl@0
   136
  g_free (value);
sl@0
   137
}
sl@0
   138
sl@0
   139
static void
sl@0
   140
check_locale_string_value (GKeyFile    *keyfile,
sl@0
   141
			   const gchar *group,
sl@0
   142
			   const gchar *key,
sl@0
   143
			   const gchar *locale,
sl@0
   144
			   const gchar *expected) 
sl@0
   145
{
sl@0
   146
  GError *error = NULL;
sl@0
   147
  gchar *value;
sl@0
   148
sl@0
   149
  value = g_key_file_get_locale_string (keyfile, group, key, locale, &error);
sl@0
   150
  check_no_error (&error);
sl@0
   151
  g_assert (value != NULL);
sl@0
   152
sl@0
   153
  if (strcmp (value, expected) != 0)
sl@0
   154
    {
sl@0
   155
      g_print ("Group %s key %s locale %s: "
sl@0
   156
	       "expected string value '%s', actual value '%s'\n",
sl@0
   157
	       group, key, locale, expected, value);  
sl@0
   158
	       
sl@0
   159
	  	        
sl@0
   160
      g_assert(FALSE && "keyfile-test failed");
sl@0
   161
      
sl@0
   162
      #ifdef SYMBIAN
sl@0
   163
  	  testResultXml("keyfile-test");
sl@0
   164
  	  #endif /* EMULATOR */
sl@0
   165
  	     
sl@0
   166
      exit (1);
sl@0
   167
    }
sl@0
   168
sl@0
   169
  g_free (value);
sl@0
   170
}
sl@0
   171
sl@0
   172
static void
sl@0
   173
check_string_list_value (GKeyFile    *keyfile,
sl@0
   174
			 const gchar *group,
sl@0
   175
			 const gchar *key,
sl@0
   176
			 ...)
sl@0
   177
{
sl@0
   178
  gint i;
sl@0
   179
  gchar *v, **value;
sl@0
   180
  va_list args;
sl@0
   181
  gsize len;
sl@0
   182
  GError *error = NULL;
sl@0
   183
sl@0
   184
  value = g_key_file_get_string_list (keyfile, group, key, &len, &error);
sl@0
   185
  check_no_error (&error);
sl@0
   186
  g_assert (value != NULL);
sl@0
   187
  
sl@0
   188
  va_start (args, key);
sl@0
   189
  i = 0;
sl@0
   190
  v = va_arg (args, gchar*);
sl@0
   191
  while (v)
sl@0
   192
    {
sl@0
   193
      if (value[i] == NULL)
sl@0
   194
	{
sl@0
   195
	  g_print ("Group %s key %s: list too short (%d)\n", 
sl@0
   196
		   group, key, i);      
sl@0
   197
	  	        
sl@0
   198
      g_assert(FALSE && "keyfile-test failed");
sl@0
   199
      
sl@0
   200
      #ifdef SYMBIAN
sl@0
   201
  	  testResultXml("keyfile-test");
sl@0
   202
  	  #endif /* EMULATOR */
sl@0
   203
  	  
sl@0
   204
	  exit (1);
sl@0
   205
	}
sl@0
   206
      if (strcmp (v, value[i]) != 0)
sl@0
   207
	{
sl@0
   208
	  g_print ("Group %s key %s: mismatch at %d, expected %s, got %s\n", 
sl@0
   209
		   group, key, i, v, value[i]);      
sl@0
   210
		   
sl@0
   211
	  	        
sl@0
   212
      g_assert(FALSE && "keyfile-test failed");
sl@0
   213
      
sl@0
   214
      #ifdef SYMBIAN
sl@0
   215
  	  testResultXml("keyfile-test");
sl@0
   216
  	  #endif /* EMULATOR */
sl@0
   217
  	  
sl@0
   218
	  exit (1);
sl@0
   219
	}
sl@0
   220
sl@0
   221
      i++;
sl@0
   222
      v = va_arg (args, gchar*);
sl@0
   223
    }
sl@0
   224
sl@0
   225
  va_end (args);
sl@0
   226
  
sl@0
   227
  g_strfreev (value);
sl@0
   228
}
sl@0
   229
sl@0
   230
static void
sl@0
   231
check_integer_list_value (GKeyFile    *keyfile,
sl@0
   232
			  const gchar *group,
sl@0
   233
			  const gchar *key,
sl@0
   234
			  ...)
sl@0
   235
{
sl@0
   236
  gint i;
sl@0
   237
  gint v, *value;
sl@0
   238
  va_list args;
sl@0
   239
  gsize len;
sl@0
   240
  GError *error = NULL;
sl@0
   241
sl@0
   242
  value = g_key_file_get_integer_list (keyfile, group, key, &len, &error);
sl@0
   243
  check_no_error (&error);
sl@0
   244
  g_assert (value != NULL);
sl@0
   245
  
sl@0
   246
  va_start (args, key);
sl@0
   247
  i = 0;
sl@0
   248
  v = va_arg (args, gint);
sl@0
   249
  while (v != -100)
sl@0
   250
    {
sl@0
   251
      if (i == len)
sl@0
   252
	{
sl@0
   253
	  g_print ("Group %s key %s: list too short (%d)\n", 
sl@0
   254
		   group, key, i);      
sl@0
   255
	  	        
sl@0
   256
      g_assert(FALSE && "keyfile-test failed");
sl@0
   257
      
sl@0
   258
      #ifdef SYMBIAN
sl@0
   259
  	  testResultXml("keyfile-test");
sl@0
   260
  	  #endif /* EMULATOR */
sl@0
   261
  	  
sl@0
   262
	  exit (1);
sl@0
   263
	}
sl@0
   264
      if (value[i] != v)
sl@0
   265
	{
sl@0
   266
	  g_print ("Group %s key %s: mismatch at %d, expected %d, got %d\n", 
sl@0
   267
		   group, key, i, v, value[i]);      
sl@0
   268
	  	        
sl@0
   269
      g_assert(FALSE && "keyfile-test failed");
sl@0
   270
      
sl@0
   271
      #ifdef SYMBIAN
sl@0
   272
  	  testResultXml("keyfile-test");
sl@0
   273
  	  #endif /* EMULATOR */
sl@0
   274
  	  
sl@0
   275
	  exit (1);
sl@0
   276
	}
sl@0
   277
sl@0
   278
      i++;
sl@0
   279
      v = va_arg (args, gint);
sl@0
   280
    }
sl@0
   281
sl@0
   282
  va_end (args);
sl@0
   283
  
sl@0
   284
  g_free (value);
sl@0
   285
}
sl@0
   286
sl@0
   287
static void
sl@0
   288
check_boolean_list_value (GKeyFile    *keyfile,
sl@0
   289
			  const gchar *group,
sl@0
   290
			  const gchar *key,
sl@0
   291
			  ...)
sl@0
   292
{
sl@0
   293
  gint i;
sl@0
   294
  gboolean v, *value;
sl@0
   295
  va_list args;
sl@0
   296
  gsize len;
sl@0
   297
  GError *error = NULL;
sl@0
   298
sl@0
   299
  value = g_key_file_get_boolean_list (keyfile, group, key, &len, &error);
sl@0
   300
  check_no_error (&error);
sl@0
   301
  g_assert (value != NULL);
sl@0
   302
  
sl@0
   303
  va_start (args, key);
sl@0
   304
  i = 0;
sl@0
   305
  v = va_arg (args, gboolean);
sl@0
   306
  while (v != -100)
sl@0
   307
    {
sl@0
   308
      if (i == len)
sl@0
   309
	{
sl@0
   310
	  g_print ("Group %s key %s: list too short (%d)\n", 
sl@0
   311
		   group, key, i);      
sl@0
   312
	  	        
sl@0
   313
      g_assert(FALSE && "keyfile-test failed");
sl@0
   314
      
sl@0
   315
      #ifdef SYMBIAN
sl@0
   316
  	  testResultXml("keyfile-test");
sl@0
   317
  	  #endif /* EMULATOR */
sl@0
   318
  	  
sl@0
   319
	  exit (1);
sl@0
   320
	}
sl@0
   321
      if (value[i] != v)
sl@0
   322
	{
sl@0
   323
	  g_print ("Group %s key %s: mismatch at %d, expected %d, got %d\n", 
sl@0
   324
		   group, key, i, v, value[i]);      
sl@0
   325
	  	        
sl@0
   326
      g_assert(FALSE && "keyfile-test failed");
sl@0
   327
      
sl@0
   328
      #ifdef SYMBIAN
sl@0
   329
  	  testResultXml("keyfile-test");
sl@0
   330
  	  #endif /* EMULATOR */
sl@0
   331
  	  
sl@0
   332
	  exit (1);
sl@0
   333
	}
sl@0
   334
sl@0
   335
      i++;
sl@0
   336
      v = va_arg (args, gboolean);
sl@0
   337
    }
sl@0
   338
sl@0
   339
  va_end (args);
sl@0
   340
  
sl@0
   341
  g_free (value);
sl@0
   342
}
sl@0
   343
sl@0
   344
static void
sl@0
   345
check_boolean_value (GKeyFile    *keyfile,
sl@0
   346
		     const gchar *group,
sl@0
   347
		     const gchar *key,
sl@0
   348
		     gboolean     expected) 
sl@0
   349
{
sl@0
   350
  GError *error = NULL;
sl@0
   351
  gboolean value;
sl@0
   352
sl@0
   353
  value = g_key_file_get_boolean (keyfile, group, key, &error);
sl@0
   354
  check_no_error (&error);
sl@0
   355
sl@0
   356
  if (value != expected)
sl@0
   357
    {
sl@0
   358
      g_print ("Group %s key %s: "
sl@0
   359
	       "expected boolean value '%s', actual value '%s'\n",
sl@0
   360
	       group, key, 
sl@0
   361
	       expected ? "true" : "false", 
sl@0
   362
	       value ? "true" : "false");      
sl@0
   363
	  	        
sl@0
   364
      g_assert(FALSE && "keyfile-test failed");
sl@0
   365
      
sl@0
   366
      #ifdef SYMBIAN
sl@0
   367
  	  testResultXml("keyfile-test");
sl@0
   368
  	  #endif /* EMULATOR */
sl@0
   369
  	  
sl@0
   370
      exit (1);
sl@0
   371
    }
sl@0
   372
}
sl@0
   373
sl@0
   374
static void
sl@0
   375
check_integer_value (GKeyFile    *keyfile,
sl@0
   376
		     const gchar *group,
sl@0
   377
		     const gchar *key,
sl@0
   378
		     gint         expected) 
sl@0
   379
{
sl@0
   380
  GError *error = NULL;
sl@0
   381
  gint value;
sl@0
   382
sl@0
   383
  value = g_key_file_get_integer (keyfile, group, key, &error);
sl@0
   384
  check_no_error (&error);
sl@0
   385
sl@0
   386
  if (value != expected)
sl@0
   387
    {
sl@0
   388
      g_print ("Group %s key %s: "
sl@0
   389
	       "expected integer value %d, actual value %d\n",
sl@0
   390
	       group, key, expected, value);      
sl@0
   391
	  	        
sl@0
   392
      g_assert(FALSE && "keyfile-test failed");
sl@0
   393
      
sl@0
   394
      #ifdef SYMBIAN
sl@0
   395
  	  testResultXml("keyfile-test");
sl@0
   396
  	  #endif /* EMULATOR */
sl@0
   397
  	  
sl@0
   398
      exit (1);
sl@0
   399
    }
sl@0
   400
}
sl@0
   401
sl@0
   402
static void
sl@0
   403
check_name (const gchar *what,
sl@0
   404
	    const gchar *value,
sl@0
   405
	    const gchar *expected,
sl@0
   406
	    gint         position)
sl@0
   407
{
sl@0
   408
  if (!value || strcmp (expected, value) != 0)
sl@0
   409
    {
sl@0
   410
      g_print ("Wrong %s returned: got '%s' at %d, expected '%s'\n",
sl@0
   411
	       what, value, position, expected);
sl@0
   412
	  	        
sl@0
   413
      g_assert(FALSE && "keyfile-test failed");
sl@0
   414
      
sl@0
   415
      #ifdef SYMBIAN
sl@0
   416
  	  testResultXml("keyfile-test");
sl@0
   417
  	  #endif /* EMULATOR */
sl@0
   418
  	  
sl@0
   419
      exit (1);
sl@0
   420
    }
sl@0
   421
}
sl@0
   422
sl@0
   423
static void
sl@0
   424
check_length (const gchar *what,
sl@0
   425
	      gint         n_items,
sl@0
   426
	      gint         length,
sl@0
   427
	      gint         expected)
sl@0
   428
{
sl@0
   429
  if (n_items != length || length != expected)
sl@0
   430
    {
sl@0
   431
      g_print ("Wrong number of %s returned: got %d items, length %d, expected %d\n",
sl@0
   432
	       what, n_items, length, expected);
sl@0
   433
      	        
sl@0
   434
      g_assert(FALSE && "keyfile-test failed");
sl@0
   435
      
sl@0
   436
      #ifdef SYMBIAN
sl@0
   437
  	  testResultXml("keyfile-test");
sl@0
   438
  	  #endif /* EMULATOR */
sl@0
   439
  	  
sl@0
   440
      exit (1);
sl@0
   441
    }
sl@0
   442
}
sl@0
   443
sl@0
   444
sl@0
   445
/* check that both \n and \r\n are accepted as line ends,
sl@0
   446
 * and that stray \r are passed through
sl@0
   447
 */
sl@0
   448
static void
sl@0
   449
test_line_ends (void)
sl@0
   450
{
sl@0
   451
  GKeyFile *keyfile;
sl@0
   452
sl@0
   453
  const gchar *data = 
sl@0
   454
    "[group1]\n"
sl@0
   455
    "key1=value1\n"
sl@0
   456
    "key2=value2\r\n"
sl@0
   457
    "[group2]\r\n"
sl@0
   458
    "key3=value3\r\r\n"
sl@0
   459
    "key4=value4\n";
sl@0
   460
sl@0
   461
  keyfile = load_data (data, 0);
sl@0
   462
sl@0
   463
  check_string_value (keyfile, "group1", "key1", "value1");
sl@0
   464
  check_string_value (keyfile, "group1", "key2", "value2");
sl@0
   465
  check_string_value (keyfile, "group2", "key3", "value3\r");
sl@0
   466
  check_string_value (keyfile, "group2", "key4", "value4");
sl@0
   467
sl@0
   468
  g_key_file_free (keyfile);
sl@0
   469
}
sl@0
   470
sl@0
   471
/* check handling of whitespace 
sl@0
   472
 */
sl@0
   473
static void
sl@0
   474
test_whitespace (void)
sl@0
   475
{
sl@0
   476
  GKeyFile *keyfile;
sl@0
   477
sl@0
   478
  const gchar *data = 
sl@0
   479
    "[group1]\n"
sl@0
   480
    "key1 = value1\n"
sl@0
   481
    "key2\t=\tvalue2\n"
sl@0
   482
    " [ group2 ] \n"
sl@0
   483
    "key3  =  value3  \n"
sl@0
   484
    "key4  =  value \t4\n"
sl@0
   485
    "  key5  =  value5\n";
sl@0
   486
  
sl@0
   487
  keyfile = load_data (data, 0);
sl@0
   488
sl@0
   489
  check_string_value (keyfile, "group1", "key1", "value1");
sl@0
   490
  check_string_value (keyfile, "group1", "key2", "value2");
sl@0
   491
  check_string_value (keyfile, " group2 ", "key3", "value3  ");
sl@0
   492
  check_string_value (keyfile, " group2 ", "key4", "value \t4");
sl@0
   493
  check_string_value (keyfile, " group2 ", "key5", "value5");
sl@0
   494
sl@0
   495
  g_key_file_free (keyfile);
sl@0
   496
}
sl@0
   497
sl@0
   498
/* check handling of comments
sl@0
   499
 */
sl@0
   500
static void
sl@0
   501
test_comments (void)
sl@0
   502
{
sl@0
   503
  GKeyFile *keyfile;
sl@0
   504
  gchar **names;
sl@0
   505
  gsize len;
sl@0
   506
  GError *error = NULL;
sl@0
   507
  gchar *comment;
sl@0
   508
sl@0
   509
  const gchar *data = 
sl@0
   510
    "# top comment\n"
sl@0
   511
    "# top comment, continued\n"
sl@0
   512
    "[group1]\n"
sl@0
   513
    "key1 = value1\n"
sl@0
   514
    "# key comment\n"
sl@0
   515
    "# key comment, continued\n"
sl@0
   516
    "key2 = value2\n"
sl@0
   517
    "# line end check\r\n"
sl@0
   518
    "key3 = value3\n"
sl@0
   519
    "key4 = value4\n"
sl@0
   520
    "# group comment\n"
sl@0
   521
    "# group comment, continued\n"
sl@0
   522
    "[group2]\n";
sl@0
   523
sl@0
   524
  const gchar *top_comment= " top comment\n top comment, continued\n";
sl@0
   525
  const gchar *group_comment= " group comment\n group comment, continued\n";
sl@0
   526
  const gchar *key_comment= " key comment\n key comment, continued\n";
sl@0
   527
  
sl@0
   528
  keyfile = load_data (data, 0);
sl@0
   529
sl@0
   530
  check_string_value (keyfile, "group1", "key1", "value1");
sl@0
   531
  check_string_value (keyfile, "group1", "key2", "value2");
sl@0
   532
  check_string_value (keyfile, "group1", "key3", "value3");
sl@0
   533
  check_string_value (keyfile, "group1", "key4", "value4");
sl@0
   534
sl@0
   535
  names = g_key_file_get_keys (keyfile, "group1", &len, &error);
sl@0
   536
  check_no_error (&error);
sl@0
   537
sl@0
   538
  check_length ("keys", g_strv_length (names), len, 4);
sl@0
   539
  check_name ("key", names[0], "key1", 0);
sl@0
   540
  check_name ("key", names[1], "key2", 1);
sl@0
   541
  check_name ("key", names[2], "key3", 2);
sl@0
   542
  check_name ("key", names[3], "key4", 3);
sl@0
   543
sl@0
   544
  g_strfreev (names);
sl@0
   545
sl@0
   546
  g_key_file_free (keyfile);
sl@0
   547
sl@0
   548
  keyfile = load_data (data, G_KEY_FILE_KEEP_COMMENTS);
sl@0
   549
sl@0
   550
  names = g_key_file_get_keys (keyfile, "group1", &len, &error);
sl@0
   551
  check_no_error (&error);
sl@0
   552
sl@0
   553
  check_length ("keys", g_strv_length (names), len, 4);
sl@0
   554
  check_name ("key", names[0], "key1", 0);
sl@0
   555
  check_name ("key", names[1], "key2", 1);
sl@0
   556
  check_name ("key", names[2], "key3", 2);
sl@0
   557
  check_name ("key", names[3], "key4", 3);
sl@0
   558
sl@0
   559
  g_strfreev (names);
sl@0
   560
sl@0
   561
  comment = g_key_file_get_comment (keyfile, NULL, NULL, &error);
sl@0
   562
  check_no_error (&error);
sl@0
   563
  check_name ("top comment", comment, top_comment, 0);
sl@0
   564
  g_free (comment);
sl@0
   565
sl@0
   566
  comment = g_key_file_get_comment (keyfile, "group1", "key2", &error);
sl@0
   567
  check_no_error (&error);
sl@0
   568
  check_name ("key comment", comment, key_comment, 0);
sl@0
   569
  g_free (comment);
sl@0
   570
sl@0
   571
  comment = g_key_file_get_comment (keyfile, "group2", NULL, &error);
sl@0
   572
  check_no_error (&error);
sl@0
   573
  check_name ("group comment", comment, group_comment, 0);
sl@0
   574
  g_free (comment);
sl@0
   575
sl@0
   576
  g_key_file_free (keyfile);
sl@0
   577
}
sl@0
   578
sl@0
   579
sl@0
   580
/* check key and group listing */
sl@0
   581
static void
sl@0
   582
test_listing (void)
sl@0
   583
{
sl@0
   584
  GKeyFile *keyfile;
sl@0
   585
  gchar **names;
sl@0
   586
  gsize len;
sl@0
   587
  gchar *start;
sl@0
   588
  GError *error = NULL;
sl@0
   589
sl@0
   590
  const gchar *data = 
sl@0
   591
    "[group1]\n"
sl@0
   592
    "key1=value1\n"
sl@0
   593
    "key2=value2\n"
sl@0
   594
    "[group2]\n"
sl@0
   595
    "key3=value3\n"
sl@0
   596
    "key4=value4\n";
sl@0
   597
  
sl@0
   598
  keyfile = load_data (data, 0);
sl@0
   599
sl@0
   600
  names = g_key_file_get_groups (keyfile, &len);
sl@0
   601
  if (names == NULL)
sl@0
   602
    {
sl@0
   603
      g_print ("Error listing groups\n");
sl@0
   604
            	        
sl@0
   605
      g_assert(FALSE && "keyfile-test failed");
sl@0
   606
      
sl@0
   607
      #ifdef SYMBIAN
sl@0
   608
  	  testResultXml("keyfile-test");
sl@0
   609
  	  #endif /* EMULATOR */
sl@0
   610
  	  
sl@0
   611
      exit (1);
sl@0
   612
    }
sl@0
   613
sl@0
   614
  check_length ("groups", g_strv_length (names), len, 2);
sl@0
   615
  check_name ("group name", names[0], "group1", 0);
sl@0
   616
  check_name ("group name", names[1], "group2", 1);
sl@0
   617
  
sl@0
   618
  g_strfreev (names);
sl@0
   619
  
sl@0
   620
  names = g_key_file_get_keys (keyfile, "group1", &len, &error);
sl@0
   621
  check_no_error (&error);
sl@0
   622
sl@0
   623
  check_length ("keys", g_strv_length (names), len, 2);
sl@0
   624
  check_name ("key", names[0], "key1", 0);
sl@0
   625
  check_name ("key", names[1], "key2", 1);
sl@0
   626
sl@0
   627
  g_strfreev (names);
sl@0
   628
sl@0
   629
  names = g_key_file_get_keys (keyfile, "no-such-group", &len, &error);
sl@0
   630
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
sl@0
   631
sl@0
   632
  g_strfreev (names);
sl@0
   633
sl@0
   634
  if (!g_key_file_has_group (keyfile, "group1") ||
sl@0
   635
      !g_key_file_has_group (keyfile, "group2") ||
sl@0
   636
      g_key_file_has_group (keyfile, "group10") ||
sl@0
   637
      g_key_file_has_group (keyfile, "group2 "))      
sl@0
   638
    {
sl@0
   639
      g_print ("Group finding trouble\n");
sl@0
   640
      
sl@0
   641
      	        
sl@0
   642
      g_assert(FALSE && "keyfile-test failed");
sl@0
   643
      
sl@0
   644
      #ifdef SYMBIAN
sl@0
   645
  	  testResultXml("keyfile-test");
sl@0
   646
  	  #endif /* EMULATOR */
sl@0
   647
  	  
sl@0
   648
      exit (1);      
sl@0
   649
    }
sl@0
   650
sl@0
   651
  start = g_key_file_get_start_group (keyfile);
sl@0
   652
  if (!start || strcmp (start, "group1") != 0)
sl@0
   653
    {
sl@0
   654
      g_print ("Start group finding trouble\n");
sl@0
   655
      
sl@0
   656
      	        
sl@0
   657
      g_assert(FALSE && "keyfile-test failed");
sl@0
   658
      
sl@0
   659
      #ifdef SYMBIAN
sl@0
   660
  	  testResultXml("keyfile-test");
sl@0
   661
  	  #endif /* EMULATOR */
sl@0
   662
  	  
sl@0
   663
      exit (1);
sl@0
   664
    }
sl@0
   665
  g_free (start);
sl@0
   666
sl@0
   667
  if (!g_key_file_has_key (keyfile, "group1", "key1", &error) ||
sl@0
   668
      !g_key_file_has_key (keyfile, "group2", "key3", &error) ||
sl@0
   669
      g_key_file_has_key (keyfile, "group2", "no-such-key", &error))
sl@0
   670
    {
sl@0
   671
      g_print ("Key finding trouble\n");
sl@0
   672
      
sl@0
   673
      	        
sl@0
   674
      g_assert(FALSE && "keyfile-test failed");
sl@0
   675
      
sl@0
   676
      #ifdef SYMBIAN
sl@0
   677
  	  testResultXml("keyfile-test");
sl@0
   678
  	  #endif /* EMULATOR */
sl@0
   679
  	  
sl@0
   680
sl@0
   681
      exit (1);      
sl@0
   682
    }
sl@0
   683
  check_no_error (&error);
sl@0
   684
  
sl@0
   685
  g_key_file_has_key (keyfile, "no-such-group", "key", &error);
sl@0
   686
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
sl@0
   687
sl@0
   688
  g_key_file_free (keyfile);
sl@0
   689
}
sl@0
   690
sl@0
   691
/* check parsing of string values */
sl@0
   692
static void
sl@0
   693
test_string (void)
sl@0
   694
{
sl@0
   695
  GKeyFile *keyfile;
sl@0
   696
  GError *error = NULL;
sl@0
   697
  gchar *value;
sl@0
   698
sl@0
   699
  const gchar *data = 
sl@0
   700
    "[valid]\n"
sl@0
   701
    "key1=\\s\\n\\t\\r\\\\\n"
sl@0
   702
    "key2=\"quoted\"\n"
sl@0
   703
    "key3='quoted'\n"
sl@0
   704
    "key4=\xe2\x89\xa0\xe2\x89\xa0\n"
sl@0
   705
    "[invalid]\n"
sl@0
   706
    "key1=\\a\\b\\0800xff\n"
sl@0
   707
    "key2=blabla\\\n";
sl@0
   708
  
sl@0
   709
  keyfile = load_data (data, 0);
sl@0
   710
sl@0
   711
  check_string_value (keyfile, "valid", "key1", " \n\t\r\\");
sl@0
   712
  check_string_value (keyfile, "valid", "key2", "\"quoted\"");
sl@0
   713
  check_string_value (keyfile, "valid", "key3", "'quoted'");  
sl@0
   714
  check_string_value (keyfile, "valid", "key4", "\xe2\x89\xa0\xe2\x89\xa0");  
sl@0
   715
  
sl@0
   716
  value = g_key_file_get_string (keyfile, "invalid", "key1", &error);
sl@0
   717
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   718
  g_free (value);
sl@0
   719
sl@0
   720
  value = g_key_file_get_string (keyfile, "invalid", "key2", &error);
sl@0
   721
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   722
  g_free (value);
sl@0
   723
  
sl@0
   724
  g_key_file_free (keyfile);
sl@0
   725
}
sl@0
   726
sl@0
   727
/* check parsing of boolean values */
sl@0
   728
static void
sl@0
   729
test_boolean (void)
sl@0
   730
{
sl@0
   731
  GKeyFile *keyfile;
sl@0
   732
  GError *error = NULL;
sl@0
   733
sl@0
   734
  const gchar *data = 
sl@0
   735
    "[valid]\n"
sl@0
   736
    "key1=true\n"
sl@0
   737
    "key2=false\n"
sl@0
   738
    "key3=1\n"
sl@0
   739
    "key4=0\n"
sl@0
   740
    "[invalid]\n"
sl@0
   741
    "key1=t\n"
sl@0
   742
    "key2=f\n"
sl@0
   743
    "key3=yes\n"
sl@0
   744
    "key4=no\n";
sl@0
   745
  
sl@0
   746
  keyfile = load_data (data, 0);
sl@0
   747
sl@0
   748
  check_boolean_value (keyfile, "valid", "key1", TRUE);
sl@0
   749
  check_boolean_value (keyfile, "valid", "key2", FALSE);
sl@0
   750
  check_boolean_value (keyfile, "valid", "key3", TRUE);
sl@0
   751
  check_boolean_value (keyfile, "valid", "key4", FALSE);
sl@0
   752
sl@0
   753
  g_key_file_get_boolean (keyfile, "invalid", "key1", &error);
sl@0
   754
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   755
sl@0
   756
  g_key_file_get_boolean (keyfile, "invalid", "key2", &error);
sl@0
   757
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   758
sl@0
   759
  g_key_file_get_boolean (keyfile, "invalid", "key3", &error);
sl@0
   760
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   761
sl@0
   762
  g_key_file_get_boolean (keyfile, "invalid", "key4", &error);
sl@0
   763
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   764
sl@0
   765
  g_key_file_free (keyfile);
sl@0
   766
}
sl@0
   767
sl@0
   768
/* check parsing of integer values */
sl@0
   769
static void
sl@0
   770
test_integer (void)
sl@0
   771
{
sl@0
   772
  GKeyFile *keyfile;
sl@0
   773
  GError *error = NULL;
sl@0
   774
sl@0
   775
  const gchar *data = 
sl@0
   776
    "[valid]\n"
sl@0
   777
    "key1=0\n"
sl@0
   778
    "key2=1\n"
sl@0
   779
    "key3=-1\n"
sl@0
   780
    "key4=2324431\n"
sl@0
   781
    "key5=-2324431\n"
sl@0
   782
    "key6=000111\n"
sl@0
   783
    "[invalid]\n"
sl@0
   784
    "key1=0xffff\n"
sl@0
   785
    "key2=0.5\n"
sl@0
   786
    "key3=1e37\n"
sl@0
   787
    "key4=ten\n";
sl@0
   788
  
sl@0
   789
  keyfile = load_data (data, 0);
sl@0
   790
sl@0
   791
  check_integer_value (keyfile, "valid", "key1", 0);
sl@0
   792
  check_integer_value (keyfile, "valid", "key2", 1);
sl@0
   793
  check_integer_value (keyfile, "valid", "key3", -1);
sl@0
   794
  check_integer_value (keyfile, "valid", "key4", 2324431);
sl@0
   795
  check_integer_value (keyfile, "valid", "key5", -2324431);
sl@0
   796
  check_integer_value (keyfile, "valid", "key6", 111);
sl@0
   797
sl@0
   798
  g_key_file_get_integer (keyfile, "invalid", "key1", &error);
sl@0
   799
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   800
sl@0
   801
  g_key_file_get_integer (keyfile, "invalid", "key2", &error);
sl@0
   802
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   803
sl@0
   804
  g_key_file_get_integer (keyfile, "invalid", "key3", &error);
sl@0
   805
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   806
sl@0
   807
  g_key_file_get_integer (keyfile, "invalid", "key4", &error);
sl@0
   808
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
sl@0
   809
sl@0
   810
  g_key_file_free (keyfile);
sl@0
   811
}
sl@0
   812
sl@0
   813
/* check handling of translated strings */
sl@0
   814
static void
sl@0
   815
test_locale_string (void)
sl@0
   816
{
sl@0
   817
  GKeyFile *keyfile;
sl@0
   818
  GError *error = NULL;
sl@0
   819
  gchar *value;
sl@0
   820
sl@0
   821
  const gchar *data = 
sl@0
   822
    "[valid]\n"
sl@0
   823
    "key1=v1\n"
sl@0
   824
    "key1[de]=v1-de\n"
sl@0
   825
    "key1[de_DE]=v1-de_DE\n"
sl@0
   826
    "key1[de_DE.UTF8]=v1-de_DE.UTF8\n"
sl@0
   827
    "key1[fr]=v1-fr\n"
sl@0
   828
    "key1[en] =v1-en\n"
sl@0
   829
    "key1[sr@Latn]=v1-sr\n";
sl@0
   830
  
sl@0
   831
  keyfile = load_data (data, G_KEY_FILE_KEEP_TRANSLATIONS);
sl@0
   832
sl@0
   833
  check_locale_string_value (keyfile, "valid", "key1", "it", "v1");
sl@0
   834
  check_locale_string_value (keyfile, "valid", "key1", "de", "v1-de");
sl@0
   835
  check_locale_string_value (keyfile, "valid", "key1", "de_DE", "v1-de_DE");
sl@0
   836
  check_locale_string_value (keyfile, "valid", "key1", "de_DE.UTF8", "v1-de_DE.UTF8");
sl@0
   837
  check_locale_string_value (keyfile, "valid", "key1", "fr", "v1-fr");
sl@0
   838
  check_locale_string_value (keyfile, "valid", "key1", "fr_FR", "v1-fr");
sl@0
   839
  check_locale_string_value (keyfile, "valid", "key1", "en", "v1-en");
sl@0
   840
  check_locale_string_value (keyfile, "valid", "key1", "sr@Latn", "v1-sr");
sl@0
   841
  
sl@0
   842
  g_key_file_free (keyfile);
sl@0
   843
sl@0
   844
  /* now test that translations are thrown away */
sl@0
   845
sl@0
   846
  g_setenv ("LANGUAGE", "de", TRUE);
sl@0
   847
  setlocale (LC_ALL, "");
sl@0
   848
sl@0
   849
  keyfile = load_data (data, 0);
sl@0
   850
sl@0
   851
  check_locale_string_value (keyfile, "valid", "key1", "it", "v1");
sl@0
   852
  check_locale_string_value (keyfile, "valid", "key1", "de", "v1-de");
sl@0
   853
  check_locale_string_value (keyfile, "valid", "key1", "de_DE", "v1-de");
sl@0
   854
  check_locale_string_value (keyfile, "valid", "key1", "de_DE.UTF8", "v1-de");
sl@0
   855
  check_locale_string_value (keyfile, "valid", "key1", "fr", "v1");
sl@0
   856
  check_locale_string_value (keyfile, "valid", "key1", "fr_FR", "v1");
sl@0
   857
  check_locale_string_value (keyfile, "valid", "key1", "en", "v1");
sl@0
   858
sl@0
   859
  g_key_file_free (keyfile);  
sl@0
   860
}
sl@0
   861
sl@0
   862
static void
sl@0
   863
test_lists (void)
sl@0
   864
{
sl@0
   865
  GKeyFile *keyfile;
sl@0
   866
sl@0
   867
  const gchar *data = 
sl@0
   868
    "[valid]\n"
sl@0
   869
    "key1=v1;v2\n"
sl@0
   870
    "key2=v1;v2;\n"
sl@0
   871
    "key3=v1,v2\n"
sl@0
   872
    "key4=v1\\;v2\n"
sl@0
   873
    "key5=true;false\n"
sl@0
   874
    "key6=1;0;-1\n"
sl@0
   875
    "key7= 1 ; 0 ; -1 \n"
sl@0
   876
    "key8=v1\\,v2\n";
sl@0
   877
  
sl@0
   878
  keyfile = load_data (data, 0);
sl@0
   879
sl@0
   880
  check_string_list_value (keyfile, "valid", "key1", "v1", "v2", NULL);
sl@0
   881
  check_string_list_value (keyfile, "valid", "key2", "v1", "v2", NULL);
sl@0
   882
  check_string_list_value (keyfile, "valid", "key3", "v1,v2", NULL);
sl@0
   883
  check_string_list_value (keyfile, "valid", "key4", "v1;v2", NULL);
sl@0
   884
  check_boolean_list_value (keyfile, "valid", "key5", TRUE, FALSE, -100);
sl@0
   885
  check_integer_list_value (keyfile, "valid", "key6", 1, 0, -1, -100);
sl@0
   886
  /* maybe these should be valid */
sl@0
   887
  /* check_integer_list_value (keyfile, "valid", "key7", 1, 0, -1, -100);*/
sl@0
   888
  /* check_string_list_value (keyfile, "valid", "key8", "v1\\,v2", NULL);*/
sl@0
   889
sl@0
   890
  g_key_file_free (keyfile);  
sl@0
   891
sl@0
   892
  /* Now check an alternate separator */
sl@0
   893
sl@0
   894
  keyfile = load_data (data, 0);
sl@0
   895
  g_key_file_set_list_separator (keyfile, ',');
sl@0
   896
sl@0
   897
  check_string_list_value (keyfile, "valid", "key1", "v1;v2", NULL);
sl@0
   898
  check_string_list_value (keyfile, "valid", "key2", "v1;v2;", NULL);
sl@0
   899
  check_string_list_value (keyfile, "valid", "key3", "v1", "v2", NULL);
sl@0
   900
sl@0
   901
  g_key_file_free (keyfile);  
sl@0
   902
}
sl@0
   903
sl@0
   904
/* http://bugzilla.gnome.org/show_bug.cgi?id=165887 */
sl@0
   905
static void 
sl@0
   906
test_group_remove (void)
sl@0
   907
{
sl@0
   908
  GKeyFile *keyfile;
sl@0
   909
  gchar **names;
sl@0
   910
  gsize len;
sl@0
   911
  GError *error = NULL;
sl@0
   912
sl@0
   913
  const gchar *data = 
sl@0
   914
    "[group1]\n"
sl@0
   915
    "[group2]\n"
sl@0
   916
    "key1=bla\n"
sl@0
   917
    "key2=bla\n"
sl@0
   918
    "[group3]\n"
sl@0
   919
    "key1=bla\n"
sl@0
   920
    "key2=bla\n";
sl@0
   921
  
sl@0
   922
  keyfile = load_data (data, 0);
sl@0
   923
  
sl@0
   924
  names = g_key_file_get_groups (keyfile, &len);
sl@0
   925
  if (names == NULL)
sl@0
   926
    {
sl@0
   927
      g_print ("Error listing groups\n");
sl@0
   928
      	        
sl@0
   929
      g_assert(FALSE && "keyfile-test failed");
sl@0
   930
      
sl@0
   931
      #ifdef SYMBIAN
sl@0
   932
  	  testResultXml("keyfile-test");
sl@0
   933
  	  #endif /* EMULATOR */
sl@0
   934
  	  
sl@0
   935
      exit (1);
sl@0
   936
    }
sl@0
   937
sl@0
   938
  check_length ("groups", g_strv_length (names), len, 3);
sl@0
   939
  check_name ("group name", names[0], "group1", 0);
sl@0
   940
  check_name ("group name", names[1], "group2", 1);
sl@0
   941
  check_name ("group name", names[2], "group3", 2);
sl@0
   942
sl@0
   943
  g_key_file_remove_group (keyfile, "group1", &error);
sl@0
   944
  check_no_error (&error);
sl@0
   945
  
sl@0
   946
  g_strfreev (names);
sl@0
   947
sl@0
   948
  names = g_key_file_get_groups (keyfile, &len);
sl@0
   949
  if (names == NULL)
sl@0
   950
    {
sl@0
   951
      g_print ("Error listing groups\n");
sl@0
   952
      	        
sl@0
   953
      g_assert(FALSE && "keyfile-test failed");
sl@0
   954
      
sl@0
   955
      #ifdef SYMBIAN
sl@0
   956
  	  testResultXml("keyfile-test");
sl@0
   957
  	  #endif /* EMULATOR */
sl@0
   958
  	  
sl@0
   959
      exit (1);
sl@0
   960
    }
sl@0
   961
sl@0
   962
  check_length ("groups", g_strv_length (names), len, 2);
sl@0
   963
  check_name ("group name", names[0], "group2", 0);
sl@0
   964
  check_name ("group name", names[1], "group3", 1);
sl@0
   965
sl@0
   966
  g_key_file_remove_group (keyfile, "group2", &error);
sl@0
   967
  check_no_error (&error);
sl@0
   968
  
sl@0
   969
  g_strfreev (names);
sl@0
   970
sl@0
   971
  names = g_key_file_get_groups (keyfile, &len);
sl@0
   972
  if (names == NULL)
sl@0
   973
    {
sl@0
   974
      g_print ("Error listing groups\n");
sl@0
   975
      	        
sl@0
   976
      g_assert(FALSE && "keyfile-test failed");
sl@0
   977
      
sl@0
   978
      #ifdef SYMBIAN
sl@0
   979
  	  testResultXml("keyfile-test");
sl@0
   980
  	  #endif /* EMULATOR */
sl@0
   981
  	  
sl@0
   982
      exit (1);
sl@0
   983
    }
sl@0
   984
sl@0
   985
  check_length ("groups", g_strv_length (names), len, 1);
sl@0
   986
  check_name ("group name", names[0], "group3", 0);
sl@0
   987
sl@0
   988
  g_key_file_remove_group (keyfile, "no such group", &error);
sl@0
   989
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
sl@0
   990
sl@0
   991
  g_strfreev (names);
sl@0
   992
sl@0
   993
  g_key_file_free (keyfile);
sl@0
   994
}
sl@0
   995
sl@0
   996
/* http://bugzilla.gnome.org/show_bug.cgi?id=165980 */
sl@0
   997
static void 
sl@0
   998
test_key_remove (void)
sl@0
   999
{
sl@0
  1000
  GKeyFile *keyfile;
sl@0
  1001
  gchar *value;
sl@0
  1002
  GError *error = NULL;
sl@0
  1003
sl@0
  1004
  const gchar *data = 
sl@0
  1005
    "[group1]\n"
sl@0
  1006
    "key1=bla\n"
sl@0
  1007
    "key2=bla\n";
sl@0
  1008
  
sl@0
  1009
  keyfile = load_data (data, 0);
sl@0
  1010
  
sl@0
  1011
  check_string_value (keyfile, "group1", "key1", "bla");
sl@0
  1012
sl@0
  1013
  g_key_file_remove_key (keyfile, "group1", "key1", &error);
sl@0
  1014
  check_no_error (&error);
sl@0
  1015
sl@0
  1016
  value = g_key_file_get_string (keyfile, "group1", "key1", &error);
sl@0
  1017
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND);
sl@0
  1018
  g_free (value);
sl@0
  1019
  
sl@0
  1020
  g_key_file_remove_key (keyfile, "group1", "key1", &error);
sl@0
  1021
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND);
sl@0
  1022
sl@0
  1023
  g_key_file_remove_key (keyfile, "no such group", "key1", &error);
sl@0
  1024
  check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
sl@0
  1025
sl@0
  1026
  g_key_file_free (keyfile);
sl@0
  1027
}
sl@0
  1028
sl@0
  1029
/* http://bugzilla.gnome.org/show_bug.cgi?id=316309 */
sl@0
  1030
static void
sl@0
  1031
test_groups (void)
sl@0
  1032
{
sl@0
  1033
  GKeyFile *keyfile;
sl@0
  1034
sl@0
  1035
  const gchar *data = 
sl@0
  1036
    "[1]\n"
sl@0
  1037
    "key1=123\n"
sl@0
  1038
    "[2]\n"
sl@0
  1039
    "key2=123\n";
sl@0
  1040
  
sl@0
  1041
  keyfile = load_data (data, 0);
sl@0
  1042
sl@0
  1043
  check_string_value (keyfile, "1", "key1", "123");
sl@0
  1044
  check_string_value (keyfile, "2", "key2", "123");
sl@0
  1045
sl@0
  1046
  g_key_file_free (keyfile);  
sl@0
  1047
}
sl@0
  1048
sl@0
  1049
sl@0
  1050
int
sl@0
  1051
main (int argc, char *argv[])
sl@0
  1052
{
sl@0
  1053
  #ifdef SYMBIAN
sl@0
  1054
  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);
sl@0
  1055
  g_set_print_handler(mrtPrintHandler);
sl@0
  1056
  #endif /*SYMBIAN*/
sl@0
  1057
	  
sl@0
  1058
sl@0
  1059
  test_line_ends ();
sl@0
  1060
  test_whitespace ();
sl@0
  1061
  test_comments ();
sl@0
  1062
  test_listing ();
sl@0
  1063
  test_string ();
sl@0
  1064
  test_boolean ();
sl@0
  1065
  test_integer ();
sl@0
  1066
  test_locale_string ();
sl@0
  1067
  test_lists ();
sl@0
  1068
  test_group_remove ();
sl@0
  1069
  test_key_remove ();
sl@0
  1070
  test_groups ();
sl@0
  1071
  
sl@0
  1072
  #ifdef SYMBIAN
sl@0
  1073
  testResultXml("keyfile-test");
sl@0
  1074
  #endif /* EMULATOR */
sl@0
  1075
  	  
sl@0
  1076
  return 0;
sl@0
  1077
}