1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*=====================================================================
6**
7** Source: test1.c
8**
9** Purpose: Tests the PAL implementation of the strtod function.
10** Convert a number of strings to doubles. Ensure they
11** convert correctly.
12**
13**
14**===================================================================*/
15
16#include <palsuite.h>
17
18
19struct testCase
20{
21 double CorrectResult; /* The returned double value */
22 char ResultString[20]; /* The remainder string */
23 char string[20]; /* The test string */
24};
25
26
27int __cdecl main(int argc, char **argv)
28{
29
30 char * endptr;
31 double result;
32 int i;
33
34 struct testCase testCases[] =
35 {
36 {1234,"","1234"},
37 {-1234,"","-1234"},
38 {1234.44,"","1234.44"},
39 {1234e-5,"","1234e-5"},
40 {1234e+5,"","1234e+5"},
41 {12345E5,"","12345e5"},
42 {1234.657e-8,"","1234.657e-8"},
43 {1234567e-8,"foo","1234567e-8foo"},
44 {999,"foo","999 foo"},
45 {7,"foo"," 7foo"},
46 {0,"a7","a7"},
47 {-777777,"z zz","-777777z zz"}
48 };
49
50 /*
51 * Initialize the PAL
52 */
53 if (0 != PAL_Initialize(argc,argv))
54 {
55 return FAIL;
56 }
57
58 /* Loop through the structure to test each case */
59 for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++)
60 {
61 result = strtod(testCases[i].string,&endptr);
62
63 /* need to check the result and the endptr result */
64 if ((testCases[i].CorrectResult != result) &&
65 (strcmp(testCases[i].ResultString,endptr)!=0))
66 {
67 Fail("ERROR: strtod returned %f instead of %f and "
68 "\"%s\" instead of \"%s\" for the test of \"%s\"\n",
69 result,
70 testCases[i].CorrectResult,
71 endptr,
72 testCases[i].ResultString,
73 testCases[i].string);
74 }
75
76 }
77
78 PAL_Terminate();
79 return PASS;
80}
81
82
83
84
85
86
87
88
89
90
91
92
93
94