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: test5.c
8**
9** Purpose: Test #5 for the wcstol function. Tests over and under flowing.
10**
11**
12**==========================================================================*/
13
14
15
16#include <palsuite.h>
17
18
19/*
20 * Notes: wcstol should depend on the current locale's LC_NUMERIC category,
21 * this is not currently tested.
22 */
23
24
25int __cdecl main(int argc, char *argv[])
26{
27 WCHAR overstr[] = {'2','1','4','7','4','8','3','6','4','8',0};
28 WCHAR understr[] = {'-','2','1','4','7','4','8','3','6','4','9',0};
29 WCHAR *end;
30 LONG l;
31
32 if (0 != PAL_Initialize(argc, argv))
33 {
34 return FAIL;
35 }
36
37
38 errno = 0;
39
40 l = wcstol(overstr, &end, 10);
41
42 if (l != LONG_MAX)
43 {
44 Fail("ERROR: Expected wcstol to return %u, got %u\n", LONG_MAX, l);
45 }
46 if (end != overstr + 10)
47 {
48 Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n",
49 overstr + 10, end);
50 }
51 if (errno != ERANGE)
52 {
53 Fail("ERROR: wcstol did not set errno to ERANGE (%d)\n", errno);
54 }
55
56
57 errno = 0;
58 l = wcstol(understr, &end, 10);
59
60 if (l != LONG_MIN)
61 {
62 Fail("ERROR: Expected wcstol to return %u, got %u\n", LONG_MIN, l);
63 }
64 if (end != understr + 11)
65 {
66 Fail("ERROR: Expected wcstol to give an end value of %p, got %p\n",
67 understr + 11, end);
68 }
69 if (errno != ERANGE)
70 {
71 Fail("ERROR: wcstol did not set errno to ERANGE (%d)\n", errno);
72 }
73
74 PAL_Terminate();
75 return PASS;
76}
77