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: test12.c
8**
9** Purpose: Tests the (lowercase) hexadecimal specifier (%x).
10** This test is modeled after the fprintf series.
11**
12**
13**==========================================================================*/
14
15#include <palsuite.h>
16#include "../fprintf.h"
17
18/*
19 * Depends on memcmp, strlen, fopen, fseek and fgets.
20 */
21
22int __cdecl main(int argc, char *argv[])
23{
24 int neg = -42;
25 int pos = 0x1234ab;
26 INT64 l = I64(0x1234567887654321);
27
28 if (PAL_Initialize(argc, argv) != 0)
29 return(FAIL);
30
31 DoNumTest("foo %x", pos, "foo 1234ab");
32 DoNumTest("foo %lx", pos, "foo 1234ab");
33 DoNumTest("foo %hx", pos, "foo 34ab");
34 DoNumTest("foo %Lx", pos, "foo 1234ab");
35 DoI64Test("foo %I64x", l, "0x1234567887654321",
36 "foo 1234567887654321", "foo 0x1234567887654321");
37 DoNumTest("foo %7x", pos, "foo 1234ab");
38 DoNumTest("foo %-7x", pos, "foo 1234ab ");
39 DoNumTest("foo %.1x", pos, "foo 1234ab");
40 DoNumTest("foo %.7x", pos, "foo 01234ab");
41 DoNumTest("foo %07x", pos, "foo 01234ab");
42 DoNumTest("foo %#x", pos, "foo 0x1234ab");
43 DoNumTest("foo %+x", pos, "foo 1234ab");
44 DoNumTest("foo % x", pos, "foo 1234ab");
45 DoNumTest("foo %+x", neg, "foo ffffffd6");
46 DoNumTest("foo % x", neg, "foo ffffffd6");
47
48 PAL_Terminate();
49 return PASS;
50}
51