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 atol function. |
10 | ** Check to ensure that the different ints (normal, |
11 | ** negative, decimal,exponent), all work as expected with |
12 | ** this function. |
13 | ** |
14 | ** |
15 | **===================================================================*/ |
16 | |
17 | #include <palsuite.h> |
18 | |
19 | struct testCase |
20 | { |
21 | LONG LongValue; |
22 | char avalue[20]; |
23 | }; |
24 | |
25 | int __cdecl main(int argc, char **argv) |
26 | { |
27 | |
28 | LONG result=0; |
29 | int i=0; |
30 | |
31 | struct testCase testCases[] = |
32 | { |
33 | {1234, "1234" }, |
34 | {-1234, "-1234" }, |
35 | {1234, "1234.44" }, |
36 | {1234, "1234e-5" }, |
37 | {1234, "1234e+5" }, |
38 | {1234, "1234E5" }, |
39 | {1234, "1234.657e-8" }, |
40 | {1234, "1234d-5" }, |
41 | {1234, "1234d+5" }, |
42 | {1234, "1234D5" }, |
43 | {1234567, " 1234567e-8 foo" }, |
44 | {0, "aaa 32 test" } |
45 | }; |
46 | |
47 | /* |
48 | * Initialize the PAL and return FAIL if this fails |
49 | */ |
50 | if (0 != (PAL_Initialize(argc, argv))) |
51 | { |
52 | return FAIL; |
53 | } |
54 | |
55 | /* Loop through each case. Convert the string to a LONG |
56 | and then compare to ensure that it is the correct value. |
57 | */ |
58 | |
59 | for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) |
60 | { |
61 | /*Convert the string to a LONG.*/ |
62 | result = atol(testCases[i].avalue); |
63 | |
64 | if (testCases[i].LongValue != result) |
65 | { |
66 | Fail("ERROR: atol misinterpreted \"%s\" as %d instead of %d.\n" |
67 | , testCases[i].avalue, result, testCases[i].LongValue); |
68 | } |
69 | |
70 | } |
71 | |
72 | |
73 | PAL_Terminate(); |
74 | return PASS; |
75 | } |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |