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: Call labs on a series of values -- negative, positive, zero,
10** and the largest negative value of a LONG. Ensure that they are all
11** changed properly to their absoulte value.
12**
13**
14**===================================================================*/
15
16#include <palsuite.h>
17
18struct testCase
19{
20 LONG LongValue;
21 LONG AbsoluteLongValue;
22};
23
24int __cdecl main(int argc, char **argv)
25{
26
27 LONG result=0;
28 int i=0;
29
30 struct testCase testCases[] =
31 {
32 {1234, 1234},
33 {-1234, 1234},
34 {0, 0},
35 {-2147483647, 2147483647}, /* Max value to abs */
36 {2147483647, 2147483647}
37 };
38
39 if (0 != (PAL_Initialize(argc, argv)))
40 {
41 return FAIL;
42 }
43
44 /* Loop through each case. Call labs on each LONG and ensure that
45 the resulting value is correct.
46 */
47
48 for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++)
49 {
50 /* Absolute value on a LONG */
51 result = labs(testCases[i].LongValue);
52
53 if (testCases[i].AbsoluteLongValue != result)
54 {
55 Fail("ERROR: labs took the absoulte value of '%d' to be '%d' "
56 "instead of %d.\n",
57 testCases[i].LongValue,
58 result,
59 testCases[i].AbsoluteLongValue);
60 }
61 }
62
63 PAL_Terminate();
64 return PASS;
65}
66