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: Tests the pointer specifier (%p).
10** This test is modeled after the sprintf series.
11**
12**
13**==========================================================================*/
14
15#include <palsuite.h>
16#include "../fwprintf.h"
17
18/*
19 * Depends on memcmp, strlen, fopen, fseek and fgets.
20 */
21
22int __cdecl main(int argc, char *argv[])
23{
24 void *ptr = (void*) 0x123456;
25 INT64 lptr = I64(0x1234567887654321);
26
27 if (PAL_Initialize(argc, argv) != 0)
28 {
29 return(FAIL);
30 }
31
32/*
33** Run only on 64 bit platforms
34*/
35#if defined(BIT64)
36 Trace("Testing for 64 Bit Platforms \n");
37 DoPointerTest(convert("%p"), NULL, "NULL", "0000000000000000", "0x0");
38 DoPointerTest(convert("%p"), ptr, "pointer to 0x123456", "0000000000123456",
39 "0x123456");
40 DoPointerTest(convert("%17p"), ptr, "pointer to 0x123456", " 0000000000123456",
41 " 0x123456");
42 DoPointerTest(convert("%17p"), ptr, "pointer to 0x123456", " 0000000000123456",
43 "0x0123456");
44 DoPointerTest(convert("%-17p"), ptr, "pointer to 0x123456", "0000000000123456 ",
45 "0x123456 ");
46 DoPointerTest(convert("%+p"), ptr, "pointer to 0x123456", "0000000000123456",
47 "0x123456");
48 DoPointerTest(convert("%#p"), ptr, "pointer to 0x123456", "0X0000000000123456",
49 "0x123456");
50 DoPointerTest(convert("%lp"), ptr, "pointer to 0x123456", "00123456",
51 "0x123456");
52 DoPointerTest(convert("%hp"), ptr, "pointer to 0x123456", "00003456",
53 "0x3456");
54 DoPointerTest(convert("%Lp"), ptr, "pointer to 0x123456", "00123456",
55 "0x123456");
56 DoI64Test(convert("%I64p"), lptr, "pointer to 0x1234567887654321",
57 "1234567887654321", "0x1234567887654321");
58#else
59 Trace("Testing for Non 64 Bit Platforms \n");
60 DoPointerTest(convert("%p"), NULL, "NULL", "00000000", "0x0");
61 DoPointerTest(convert("%p"), ptr, "pointer to 0x123456", "00123456",
62 "0x123456");
63 DoPointerTest(convert("%9p"), ptr, "pointer to 0x123456", " 00123456",
64 " 0x123456");
65 DoPointerTest(convert("%09p"), ptr, "pointer to 0x123456", " 00123456",
66 "0x0123456");
67 DoPointerTest(convert("%-9p"), ptr, "pointer to 0x123456", "00123456 ",
68 "0x123456 ");
69 DoPointerTest(convert("%+p"), ptr, "pointer to 0x123456", "00123456",
70 "0x123456");
71 DoPointerTest(convert("%#p"), ptr, "pointer to 0x123456", "0X00123456",
72 "0x123456");
73 DoPointerTest(convert("%lp"), ptr, "pointer to 0x123456", "00123456",
74 "0x123456");
75 DoPointerTest(convert("%hp"), ptr, "pointer to 0x123456", "00003456",
76 "0x3456");
77 DoPointerTest(convert("%Lp"), ptr, "pointer to 0x123456", "00123456",
78 "0x123456");
79 DoI64Test(convert("%I64p"), lptr, "pointer to 0x1234567887654321",
80 "1234567887654321", "0x1234567887654321");
81#endif
82
83 PAL_Terminate();
84 return PASS;
85}
86