Back to index

glibc  2.9
tst-strtod3.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 static const struct
00007 {
00008   const char *in;
00009   const char *out;
00010   double expected;
00011 } tests[] =
00012   {
00013     { "000,,,e1", ",,,e1", 0.0 },
00014     { "000e1", "", 0.0 },
00015     { "000,1e1", ",1e1", 0.0 }
00016   };
00017 #define NTESTS (sizeof (tests) / sizeof (tests[0]))
00018 
00019 
00020 static int
00021 do_test (void)
00022 {
00023   if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL)
00024     {
00025       puts ("could not set locale");
00026       return 1;
00027     }
00028 
00029   int status = 0;
00030 
00031   for (int i = 0; i < NTESTS; ++i)
00032     {
00033       char *ep;
00034       double r = __strtod_internal (tests[i].in, &ep, 1);
00035 
00036       if (strcmp (ep, tests[i].out) != 0)
00037        {
00038          printf ("%d: got rest string \"%s\", expected \"%s\"\n",
00039                 i, ep, tests[i].out);
00040          status = 1;
00041        }
00042 
00043       if (r != tests[i].expected)
00044        {
00045          printf ("%d: got wrong results %g, expected %g\n",
00046                 i, r, tests[i].expected);
00047          status = 1;
00048        }
00049     }
00050 
00051   return status;
00052 }
00053 
00054 #define TEST_FUNCTION do_test ()
00055 #include "../test-skeleton.c"