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: test19.c
8**
9** Purpose: Tests swprintf with argument specified precision
10**
11**
12**==========================================================================*/
13
14
15
16#include <palsuite.h>
17#include "../swprintf.h"
18
19/*
20 * Uses memcmp & wcslen
21 */
22
23int __cdecl main(int argc, char *argv[])
24{
25 int n = -1;
26
27 if (PAL_Initialize(argc, argv) != 0)
28 {
29 return FAIL;
30 }
31
32 DoArgumentPrecTest(convert("%.*s"), 2, (void*)convert("bar"), "bar",
33 convert("ba"), convert("ba"));
34 DoArgumentPrecTest(convert("%.*S"), 2, (void*)"bar", "bar", convert("ba"),
35 convert("ba"));
36 DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", convert("a"),
37 convert("a"));
38 DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", convert("a"),
39 convert("a"));
40 DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", convert("a"),
41 convert("a"));
42 DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", convert("a"),
43 convert("a"));
44 DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", convert("42"),
45 convert("42"));
46 DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", convert("042"),
47 convert("042"));
48 DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", convert("42"),
49 convert("42"));
50 DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", convert("042"),
51 convert("042"));
52 DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", convert("52"),
53 convert("52"));
54 DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", convert("052"),
55 convert("052"));
56 DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", convert("42"),
57 convert("42"));
58 DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", convert("042"),
59 convert("042"));
60 DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", convert("42"),
61 convert("42"));
62 DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", convert("042"),
63 convert("042"));
64 DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", convert("42"),
65 convert("42"));
66 DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", convert("042"),
67 convert("042"));
68
69
70 DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, convert("2.0e+000"),
71 convert("2.0e+000"));
72 DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, convert("2.010e+000"),
73 convert("2.010e+000"));
74 DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, convert("2.0E+000"),
75 convert("2.0E+000"));
76 DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, convert("2.010E+000"),
77 convert("2.010E+000"));
78 DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, convert("2.0"),
79 convert("2.0"));
80 DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, convert("2.010"),
81 convert("2.010"));
82 DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, convert("3e+002"),
83 convert("3e+002"));
84 DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, convert("256"),
85 convert("256"));
86 DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, convert("256"),
87 convert("256"));
88 DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, convert("256.01"),
89 convert("256.01"));
90 DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, convert("3E+002"),
91 convert("3E+002"));
92 DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, convert("256"),
93 convert("256"));
94 DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, convert("256"),
95 convert("256"));
96 DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, convert("256.01"),
97 convert("256.01"));
98
99 PAL_Terminate();
100 return PASS;
101}
102