Back to index

glibc  2.9
tst-strtod4.c
Go to the documentation of this file.
00001 #include <locale.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 
00006 #define NBSP "\xc2\xa0"
00007 
00008 static const struct
00009 {
00010   const char *in;
00011   const char *out;
00012   double expected;
00013 } tests[] =
00014   {
00015     { "000"NBSP"000"NBSP"000", "", 0.0 },
00016     { "1"NBSP"000"NBSP"000,5x", "x", 1000000.5 }
00017   };
00018 #define NTESTS (sizeof (tests) / sizeof (tests[0]))
00019 
00020 
00021 static int
00022 do_test (void)
00023 {
00024   if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL)
00025     {
00026       puts ("could not set locale");
00027       return 1;
00028     }
00029 
00030   int status = 0;
00031 
00032   for (int i = 0; i < NTESTS; ++i)
00033     {
00034       char *ep;
00035       double r = __strtod_internal (tests[i].in, &ep, 1);
00036 
00037       if (strcmp (ep, tests[i].out) != 0)
00038        {
00039          printf ("%d: got rest string \"%s\", expected \"%s\"\n",
00040                 i, ep, tests[i].out);
00041          status = 1;
00042        }
00043 
00044       if (r != tests[i].expected)
00045        {
00046          printf ("%d: got wrong results %g, expected %g\n",
00047                 i, r, tests[i].expected);
00048          status = 1;
00049        }
00050     }
00051 
00052   return status;
00053 }
00054 
00055 #define TEST_FUNCTION do_test ()
00056 #include "../test-skeleton.c"