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