CL
[glibc.git] / localedata / tst-sscanf.c
blob32c13285a9eeb96261f27c48098e234373ec5ca2
1 #include <stdio.h>
2 #include <locale.h>
3 #include <assert.h>
5 #define P0 "\xDB\xB0"
6 #define P1 "\xDB\xB1"
7 #define P2 "\xDB\xB2"
8 #define P3 "\xDB\xB3"
9 #define P4 "\xDB\xB4"
10 #define P5 "\xDB\xB5"
11 #define P6 "\xDB\xB6"
12 #define P7 "\xDB\xB7"
13 #define P8 "\xDB\xB8"
14 #define P9 "\xDB\xB9"
15 #define PD "\xd9\xab"
16 #define PT "\xd9\xac"
18 static int
19 check_sscanf (const char *s, const char *format, const float n)
21 float f;
23 if (sscanf (s, format, &f) != 1)
25 printf ("nothing found for \"%s\"\n", s);
26 return 1;
28 if (f != n)
30 printf ("got %f expected %f from \"%s\"\n", f, n, s);
31 return 1;
33 return 0;
36 static int
37 do_test (void)
39 if (setlocale (LC_ALL, "fa_IR.UTF-8") == NULL)
41 puts ("cannot set fa_IR locale");
42 return 1;
45 int r = check_sscanf (P3 PD P1 P4, "%I8f", 3.14);
46 r |= check_sscanf (P3 PT P1 P4 P5, "%I'f", 3145);
47 r |= check_sscanf (P3 PD P1 P4 P1 P5 P9, "%If", 3.14159);
48 r |= check_sscanf ("-" P3 PD P1 P4 P1 P5, "%If", -3.1415);
49 r |= check_sscanf ("+" PD P1 P4 P1 P5, "%If", +.1415);
50 r |= check_sscanf (P3 PD P1 P4 P1 P5 "e+" P2, "%Ie", 3.1415e+2);
52 return r;
55 #define TEST_FUNCTION do_test ()
56 #include "../test-skeleton.c"