From a691312d8794d5516402bb6bb0d3e90c40ba188b Mon Sep 17 00:00:00 2001 From: Carmelo Amoroso Date: Wed, 9 Jul 2008 15:05:36 +0000 Subject: Added several tests for locale support (8 bit and multibyte UTF-8) Basically all tests have been taken from glibc. For testing multibyte encoding EUC_JP parts have been commented out and added new section for UTF-8 that is the only multibyte codeset currently supported on uCLibc. Some tests are still failing due to unsupported/missing features, other have been fixed. Signed-off-by: Filippo Arcidiacono Signed-off-by: Carmelo Amoroso --- test/locale/tst-sscanf.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/locale/tst-sscanf.c (limited to 'test/locale/tst-sscanf.c') diff --git a/test/locale/tst-sscanf.c b/test/locale/tst-sscanf.c new file mode 100644 index 000000000..32c13285a --- /dev/null +++ b/test/locale/tst-sscanf.c @@ -0,0 +1,56 @@ +#include +#include +#include + +#define P0 "\xDB\xB0" +#define P1 "\xDB\xB1" +#define P2 "\xDB\xB2" +#define P3 "\xDB\xB3" +#define P4 "\xDB\xB4" +#define P5 "\xDB\xB5" +#define P6 "\xDB\xB6" +#define P7 "\xDB\xB7" +#define P8 "\xDB\xB8" +#define P9 "\xDB\xB9" +#define PD "\xd9\xab" +#define PT "\xd9\xac" + +static int +check_sscanf (const char *s, const char *format, const float n) +{ + float f; + + if (sscanf (s, format, &f) != 1) + { + printf ("nothing found for \"%s\"\n", s); + return 1; + } + if (f != n) + { + printf ("got %f expected %f from \"%s\"\n", f, n, s); + return 1; + } + return 0; +} + +static int +do_test (void) +{ + if (setlocale (LC_ALL, "fa_IR.UTF-8") == NULL) + { + puts ("cannot set fa_IR locale"); + return 1; + } + + int r = check_sscanf (P3 PD P1 P4, "%I8f", 3.14); + r |= check_sscanf (P3 PT P1 P4 P5, "%I'f", 3145); + r |= check_sscanf (P3 PD P1 P4 P1 P5 P9, "%If", 3.14159); + r |= check_sscanf ("-" P3 PD P1 P4 P1 P5, "%If", -3.1415); + r |= check_sscanf ("+" PD P1 P4 P1 P5, "%If", +.1415); + r |= check_sscanf (P3 PD P1 P4 P1 P5 "e+" P2, "%Ie", 3.1415e+2); + + return r; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" -- cgit v1.2.3