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