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