File: tst-strtod3.c

package info (click to toggle)
glibc 2.19-12
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 202,524 kB
  • ctags: 140,467
  • sloc: ansic: 969,237; asm: 241,206; sh: 10,046; makefile: 8,467; cpp: 3,595; perl: 2,077; pascal: 1,839; awk: 1,704; yacc: 317; sed: 73
file content (55 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (46)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static const struct
{
  const char *in;
  const char *out;
  double expected;
} tests[] =
  {
    { "000,,,e1", ",,,e1", 0.0 },
    { "000e1", "", 0.0 },
    { "000,1e1", ",1e1", 0.0 }
  };
#define NTESTS (sizeof (tests) / sizeof (tests[0]))


static int
do_test (void)
{
  if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL)
    {
      puts ("could not set locale");
      return 1;
    }

  int status = 0;

  for (int i = 0; i < NTESTS; ++i)
    {
      char *ep;
      double r = __strtod_internal (tests[i].in, &ep, 1);

      if (strcmp (ep, tests[i].out) != 0)
	{
	  printf ("%d: got rest string \"%s\", expected \"%s\"\n",
		  i, ep, tests[i].out);
	  status = 1;
	}

      if (r != tests[i].expected)
	{
	  printf ("%d: got wrong results %g, expected %g\n",
		  i, r, tests[i].expected);
	  status = 1;
	}
    }

  return status;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"