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 wcstod with a number of sample strings. |
10 | ** |
11 | ** |
12 | **===================================================================*/ |
13 | |
14 | #include <palsuite.h> |
15 | |
16 | struct testCase |
17 | { |
18 | double CorrectResult; |
19 | char string[20]; |
20 | int stopChar; |
21 | }; |
22 | |
23 | struct testCase testCases[] = |
24 | { |
25 | {1234,"1234" , 4}, |
26 | {-1234,"-1234" , 5}, |
27 | {1234.44,"1234.44" , 7}, |
28 | {1234e-5,"1234e-5" , 7}, |
29 | {1234e+5,"1234e+5" , 7}, |
30 | {1234E5,"1234E5" , 6}, |
31 | {1234.657e-8, "1234.657e-8" , 11}, |
32 | {0, "1e-800" , 6}, |
33 | {0, "-1e-800" , 7}, |
34 | {1234567e-8, " 1234567e-8 foo" , 13}, |
35 | {0, " foo 32 bar" , 0}, |
36 | }; |
37 | |
38 | int __cdecl main(int argc, char **argv) |
39 | { |
40 | WCHAR *wideStr; |
41 | WCHAR *endptr; |
42 | double result; |
43 | int i; |
44 | |
45 | if (PAL_Initialize(argc,argv)) |
46 | { |
47 | return FAIL; |
48 | } |
49 | |
50 | for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) |
51 | { |
52 | wideStr = convert(testCases[i].string); |
53 | result = wcstod(wideStr, &endptr); |
54 | |
55 | if (testCases[i].CorrectResult != result) |
56 | { |
57 | free(wideStr); |
58 | Fail("ERROR: wcstod misinterpreted \"%s\" as %g instead of " |
59 | "%g.\n" , |
60 | testCases[i].string, |
61 | result, |
62 | testCases[i].CorrectResult); |
63 | } |
64 | |
65 | if (endptr != wideStr + testCases[i].stopChar) |
66 | { |
67 | free(wideStr); |
68 | Fail("ERROR: wcstod stopped scanning \"%s\" at %p, " |
69 | "instead of %p!\n" , testCases[i].string, endptr, |
70 | wideStr + testCases[i].stopChar); |
71 | } |
72 | |
73 | free(wideStr); |
74 | } |
75 | |
76 | |
77 | PAL_Terminate(); |
78 | return PASS; |
79 | } |
80 | |