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 vprintf function. Tests the pointer
10** specifier (%p).
11**
12**
13**==========================================================================*/
14
15
16
17#include <palsuite.h>
18#include "../vprintf.h"
19
20
21
22
23int __cdecl main(int argc, char *argv[])
24{
25 void *ptr = (void*) 0x123456;
26 INT64 lptr = I64(0x1234567887654321);
27
28 if (PAL_Initialize(argc, argv))
29 {
30 return FAIL;
31 }
32/*
33** Run only on 64 bit platforms
34*/
35#if defined(BIT64)
36 Trace("Testing for 64 Bit Platforms \n");
37 DoPointerTest("%p", NULL, "NULL", "0000000000000000");
38 DoPointerTest("%p", ptr, "pointer to 0x123456", "0000000000123456");
39 DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456");
40 DoPointerTest("%17p", ptr, "pointer to 0x123456", " 0000000000123456");
41 DoPointerTest("%-17p", ptr, "pointer to 0x123456", "0000000000123456 ");
42 DoPointerTest("%+p", ptr, "pointer to 0x123456", "0000000000123456");
43 DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X0000000000123456");
44 DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456");
45 DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456");
46 DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456");
47 DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321",
48 "1234567887654321");
49
50#else
51 Trace("Testing for Non 64 Bit Platforms \n");
52 DoPointerTest("%p", NULL, "NULL", "00000000");
53 DoPointerTest("%p", ptr, "pointer to 0x123456", "00123456");
54 DoPointerTest("%9p", ptr, "pointer to 0x123456", " 00123456");
55 DoPointerTest("%09p", ptr, "pointer to 0x123456", " 00123456");
56 DoPointerTest("%-9p", ptr, "pointer to 0x123456", "00123456 ");
57 DoPointerTest("%+p", ptr, "pointer to 0x123456", "00123456");
58 DoPointerTest("%#p", ptr, "pointer to 0x123456", "0X00123456");
59 DoPointerTest("%lp", ptr, "pointer to 0x123456", "00123456");
60 DoPointerTest("%hp", ptr, "pointer to 0x123456", "00003456");
61 DoPointerTest("%Lp", ptr, "pointer to 0x123456", "00123456");
62 DoI64Test("%I64p", lptr, "pointer to 0x1234567887654321",
63 "1234567887654321");
64
65#endif
66
67 PAL_Terminate();
68 return PASS;
69}
70
71