1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

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

This commit is contained in:
Jordan Lee 2013-01-24 16:04:09 +00:00
parent 1d63fc7d22
commit 887850a636
2 changed files with 34 additions and 8 deletions

View file

@ -1,5 +1,7 @@
#include <string.h> /* strlen () */ #include <string.h> /* strlen () */
#include <locale.h> /* setlocale() */
#define __LIBTRANSMISSION_VARIANT_MODULE___ #define __LIBTRANSMISSION_VARIANT_MODULE___
#include "transmission.h" #include "transmission.h"
#include "utils.h" /* tr_free */ #include "utils.h" /* tr_free */
@ -221,12 +223,36 @@ test_unescape (void)
int int
main (void) main (void)
{ {
const testFunc tests[] = { test_elements, int i;
test_utf8, int n;
test1, int rv;
test2, char lc_numeric[128];
test3, const char * comma_locales[] = { "da_DK.UTF-8", "fr_FR.UTF-8", "ru_RU.UTF-8"};
test_unescape };
return runTests (tests, NUM_TESTS (tests)); const testFunc tests[] = { test_elements,
test_utf8,
test1,
test2,
test3,
test_unescape };
/* run the tests in a locale with a decimal point of '.' */
tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
setlocale (LC_NUMERIC, "C");
if ((rv = runTests (tests, NUM_TESTS (tests))))
return rv;
/* run the tests in a locale with a decimal point of ',' */
n = sizeof(comma_locales) / sizeof(comma_locales[0]);
for (i=0; i<n; ++i)
if (setlocale (LC_NUMERIC, comma_locales[i]) != NULL)
break;
if (i==n)
fprintf (stderr, "WARNING: unable to run locale-specific json tests.\n");
else if ((rv = runTests (tests, NUM_TESTS(tests))))
return rv;
setlocale (LC_NUMERIC, lc_numeric);
/* success */
return 0;
} }

View file

@ -806,7 +806,7 @@ tr_variantWalk (const tr_variant * v,
/* always use a '.' decimal point s.t. locale-hopping doesn't bite us */ /* always use a '.' decimal point s.t. locale-hopping doesn't bite us */
tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric)); tr_strlcpy (lc_numeric, setlocale (LC_NUMERIC, NULL), sizeof (lc_numeric));
setlocale (LC_NUMERIC, "POSIX"); setlocale (LC_NUMERIC, "C");
nodeConstruct (&stack[stackSize++], v, sort_dicts); nodeConstruct (&stack[stackSize++], v, sort_dicts);