mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
(libT) #5249 'error parsing json in some locales': add unit tests to test for this bug.
This commit is contained in:
parent
1d63fc7d22
commit
887850a636
2 changed files with 34 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
#include <string.h> /* strlen () */
|
||||
|
||||
#include <locale.h> /* setlocale() */
|
||||
|
||||
#define __LIBTRANSMISSION_VARIANT_MODULE___
|
||||
#include "transmission.h"
|
||||
#include "utils.h" /* tr_free */
|
||||
|
@ -221,12 +223,36 @@ test_unescape (void)
|
|||
int
|
||||
main (void)
|
||||
{
|
||||
const testFunc tests[] = { test_elements,
|
||||
test_utf8,
|
||||
test1,
|
||||
test2,
|
||||
test3,
|
||||
test_unescape };
|
||||
int i;
|
||||
int n;
|
||||
int rv;
|
||||
char lc_numeric[128];
|
||||
const char * comma_locales[] = { "da_DK.UTF-8", "fr_FR.UTF-8", "ru_RU.UTF-8"};
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -806,7 +806,7 @@ tr_variantWalk (const tr_variant * v,
|
|||
|
||||
/* always use a '.' decimal point s.t. locale-hopping doesn't bite us */
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue