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 vswprintf function.
10**
11**
12**===================================================================*/
13
14#include <palsuite.h>
15#include "../vswprintf.h"
16
17/* memcmp is used to verify the results, so this test is dependent on it. */
18/* ditto with wcslen */
19static void DoPointerTest(WCHAR *formatstr, void* param, WCHAR* paramstr,
20 WCHAR *checkstr1)
21{
22 WCHAR buf[256] = { 0 };
23
24 testvswp(buf, _countof(buf), formatstr, param);
25 if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0)
26
27 {
28 Fail("ERROR: failed to insert pointer to %#p into \"%s\"\n"
29 "Expected \"%s\" got \"%s\".\n",
30 paramstr,
31 convertC(formatstr),
32 convertC(checkstr1),
33 convertC(buf));
34 }
35}
36
37static void DoI64DoubleTest(WCHAR *formatstr, INT64 value, WCHAR *valuestr,
38 WCHAR *checkstr1)
39{
40 WCHAR buf[256] = { 0 };
41
42 testvswp(buf, _countof(buf), formatstr, value);
43 if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0)
44 {
45 Fail("ERROR: failed to insert %s into \"%s\"\n"
46 "Expected \"%s\", got \"%s\".\n",
47 value,
48 convertC(formatstr),
49 convertC(checkstr1),
50 convertC(buf));
51 }
52}
53
54int __cdecl main(int argc, char *argv[])
55{
56 void *ptr = (void*) 0x123456;
57 INT64 lptr = I64(0x1234567887654321);
58
59 if (PAL_Initialize(argc, argv) != 0)
60 return(FAIL);
61
62/*
63** Run only on 64 bit platforms
64*/
65#if defined(BIT64)
66 Trace("Testing for 64 Bit Platforms \n");
67 DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("0000000000000000"));
68 DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"),
69 convert("0000000000123456"));
70 DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"),
71 convert(" 0000000000123456"));
72 DoPointerTest(convert("%17p"), ptr, convert("pointer to 0x123456"),
73 convert(" 0000000000123456"));
74 DoPointerTest(convert("%-17p"), ptr, convert("pointer to 0x123456"),
75 convert("0000000000123456 "));
76 DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"),
77 convert("0000000000123456"));
78 DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"),
79 convert("0X0000000000123456"));
80 DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"),
81 convert("00123456"));
82 DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"),
83 convert("00003456"));
84 DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"),
85 convert("00123456"));
86 DoI64DoubleTest(convert("%I64p"), lptr,
87 convert("pointer to 0x1234567887654321"), convert("1234567887654321"));
88
89#else
90 Trace("Testing for Non 64 Bit Platforms \n");
91 DoPointerTest(convert("%p"), NULL, convert("NULL"), convert("00000000"));
92 DoPointerTest(convert("%p"), ptr, convert("pointer to 0x123456"),
93 convert("00123456"));
94 DoPointerTest(convert("%9p"), ptr, convert("pointer to 0x123456"),
95 convert(" 00123456"));
96 DoPointerTest(convert("%09p"), ptr, convert("pointer to 0x123456"),
97 convert(" 00123456"));
98 DoPointerTest(convert("%-9p"), ptr, convert("pointer to 0x123456"),
99 convert("00123456 "));
100 DoPointerTest(convert("%+p"), ptr, convert("pointer to 0x123456"),
101 convert("00123456"));
102 DoPointerTest(convert("%#p"), ptr, convert("pointer to 0x123456"),
103 convert("0X00123456"));
104 DoPointerTest(convert("%lp"), ptr, convert("pointer to 0x123456"),
105 convert("00123456"));
106 DoPointerTest(convert("%hp"), ptr, convert("pointer to 0x123456"),
107 convert("00003456"));
108 DoPointerTest(convert("%Lp"), ptr, convert("pointer to 0x123456"),
109 convert("00123456"));
110 DoI64DoubleTest(convert("%I64p"), lptr,
111 convert("pointer to 0x1234567887654321"), convert("1234567887654321"));
112
113#endif
114
115 PAL_Terminate();
116 return PASS;
117}
118
119