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