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 _i64tow_s with normal values and different radices, negative |
10 | ** values, as well as the highest and lowest values. |
11 | ** |
12 | ** |
13 | **============================================================*/ |
14 | |
15 | #include <palsuite.h> |
16 | |
17 | typedef struct |
18 | { |
19 | INT64 value; |
20 | int radix; |
21 | char *result; |
22 | } testCase; |
23 | |
24 | |
25 | int __cdecl main(int argc, char *argv[]) |
26 | { |
27 | WCHAR buffer[256]; |
28 | WCHAR *testStr; |
29 | WCHAR *ret; |
30 | int i; |
31 | testCase testCases[] = |
32 | { |
33 | {42, 10, "42" }, |
34 | {42, 2, "101010" }, |
35 | {29, 32, "t" }, |
36 | {-1, 10, "-1" }, |
37 | {-1, 8, "1777777777777777777777" }, |
38 | {-1, 32, "fvvvvvvvvvvvv" }, |
39 | {I64(0x7FFFFFFFFFFFFFFF), 10, "9223372036854775807" }, |
40 | {I64(0x8000000000000000), 10, "-9223372036854775808" }, |
41 | {0,2,"0" }, |
42 | {0,16,"0" }, |
43 | {3,16,"3" }, |
44 | {15,16,"f" }, |
45 | {16,16,"10" }, |
46 | |
47 | }; |
48 | |
49 | |
50 | if (0 != (PAL_Initialize(argc, argv))) |
51 | { |
52 | return FAIL; |
53 | } |
54 | |
55 | for (i=0; i<sizeof(testCases) / sizeof(testCase); i++) |
56 | { |
57 | errno_t err = _i64tow_s(testCases[i].value, buffer, sizeof(buffer) / sizeof(buffer[0]), testCases[i].radix); |
58 | |
59 | if(err != 0) |
60 | { |
61 | Fail("ERROR: _i64tow_s didn't return success, error code %d.\n" , err); |
62 | } |
63 | |
64 | testStr = convert(testCases[i].result); |
65 | if (wcscmp(testStr, buffer) != 0) |
66 | { |
67 | Fail("_i64tow_s did not give the correct string.\n" |
68 | "Expected %S, got %S\n" , testStr, buffer); |
69 | } |
70 | free(testStr); |
71 | } |
72 | |
73 | |
74 | PAL_Terminate(); |
75 | return PASS; |
76 | } |
77 | |