Changeset 13860


Ignore:
Timestamp:
Jan 24, 2013, 4:04:09 PM (8 years ago)
Author:
jordan
Message:

(libT) #5249 'error parsing json in some locales': add unit tests to test for this bug.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/json-test.c

    r13683 r13860  
    11#include <string.h> /* strlen () */
     2
     3#include <locale.h> /* setlocale() */
    24
    35#define __LIBTRANSMISSION_VARIANT_MODULE___
     
    222224main (void)
    223225{
    224     const testFunc tests[] = { test_elements,
    225                                test_utf8,
    226                                test1,
    227                                test2,
    228                                test3,
    229                                test_unescape };
    230 
    231     return runTests (tests, NUM_TESTS (tests));
    232 }
     226  int i;
     227  int n;
     228  int rv;
     229  char lc_numeric[128];
     230  const char * comma_locales[] = { "da_DK.UTF-8", "fr_FR.UTF-8", "ru_RU.UTF-8"};
     231
     232  const testFunc tests[] = { test_elements,
     233                             test_utf8,
     234                             test1,
     235                             test2,
     236                             test3,
     237                             test_unescape };
     238
     239  /* run the tests in a locale with a decimal point of '.' */
     240  tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
     241  setlocale (LC_NUMERIC, "C");
     242  if ((rv = runTests (tests, NUM_TESTS (tests))))
     243    return rv;
     244
     245  /* run the tests in a locale with a decimal point of ',' */
     246  n = sizeof(comma_locales) / sizeof(comma_locales[0]);
     247  for (i=0; i<n; ++i)
     248    if (setlocale (LC_NUMERIC, comma_locales[i]) != NULL)
     249      break;
     250  if (i==n)
     251    fprintf (stderr, "WARNING: unable to run locale-specific json tests.\n");
     252  else if ((rv = runTests (tests, NUM_TESTS(tests))))
     253    return rv;
     254  setlocale (LC_NUMERIC, lc_numeric);
     255
     256  /* success */
     257  return 0;
     258}
  • trunk/libtransmission/variant.c

    r13712 r13860  
    807807  /* always use a '.' decimal point s.t. locale-hopping doesn't bite us */
    808808  tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
    809   setlocale (LC_NUMERIC, "POSIX");
     809  setlocale (LC_NUMERIC, "C");
    810810
    811811  nodeConstruct (&stack[stackSize++], v, sort_dicts);
Note: See TracChangeset for help on using the changeset viewer.