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 the variable length precision argument.
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
22
23
24int __cdecl main(int argc, char *argv[])
25{
26 int n = -1;
27
28 if (PAL_Initialize(argc, argv) != 0)
29 {
30 return(FAIL);
31 }
32
33 DoArgumentPrecTest(convert("%.*s"), 2, (void*)convert("bar"), "bar", "ba", "ba");
34 DoArgumentPrecTest(convert("%.*S"), 2, (void*)"bar", "bar", "ba", "ba");
35 DoArgumentPrecTest(convert("foo %.*n"), 3, (void*)&n, "pointer to int", "foo ",
36 "foo ");
37 if (n != 4)
38 {
39 Fail("ERROR: Expected count parameter to resolve to %d, got %X\n",
40 4, n);
41 }
42
43 DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", "a", "a");
44 DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", "a", "a");
45 DoArgumentPrecTest(convert("%.*C"), 0, (void*)'a', "a", "a", "a");
46 DoArgumentPrecTest(convert("%.*C"), 4, (void*)'a', "a", "a", "a");
47 DoArgumentPrecTest(convert("%.*d"), 1, (void*)42, "42", "42", "42");
48 DoArgumentPrecTest(convert("%.*d"), 3, (void*)42, "42", "042", "042");
49 DoArgumentPrecTest(convert("%.*i"), 1, (void*)42, "42", "42", "42");
50 DoArgumentPrecTest(convert("%.*i"), 3, (void*)42, "42", "042", "042");
51 DoArgumentPrecTest(convert("%.*o"), 1, (void*)42, "42", "52", "52");
52 DoArgumentPrecTest(convert("%.*o"), 3, (void*)42, "42", "052", "052");
53 DoArgumentPrecTest(convert("%.*u"), 1, (void*)42, "42", "42", "42");
54 DoArgumentPrecTest(convert("%.*u"), 3, (void*)42, "42", "042", "042");
55 DoArgumentPrecTest(convert("%.*x"), 1, (void*)0x42, "0x42", "42", "42");
56 DoArgumentPrecTest(convert("%.*x"), 3, (void*)0x42, "0x42", "042", "042");
57 DoArgumentPrecTest(convert("%.*X"), 1, (void*)0x42, "0x42", "42", "42");
58 DoArgumentPrecTest(convert("%.*X"), 3, (void*)0x42, "0x42", "042", "042");
59
60
61 DoArgumentPrecDoubleTest(convert("%.*e"), 1, 2.01, "2.0e+000", "2.0e+00");
62 DoArgumentPrecDoubleTest(convert("%.*e"), 3, 2.01, "2.010e+000",
63 "2.010e+00");
64 DoArgumentPrecDoubleTest(convert("%.*E"), 1, 2.01, "2.0E+000", "2.0E+00");
65 DoArgumentPrecDoubleTest(convert("%.*E"), 3, 2.01, "2.010E+000",
66 "2.010E+00");
67 DoArgumentPrecDoubleTest(convert("%.*f"), 1, 2.01, "2.0", "2.0");
68 DoArgumentPrecDoubleTest(convert("%.*f"), 3, 2.01, "2.010", "2.010");
69 DoArgumentPrecDoubleTest(convert("%.*g"), 1, 256.01, "3e+002", "3e+02");
70 DoArgumentPrecDoubleTest(convert("%.*g"), 3, 256.01, "256", "256");
71 DoArgumentPrecDoubleTest(convert("%.*g"), 4, 256.01, "256", "256");
72 DoArgumentPrecDoubleTest(convert("%.*g"), 6, 256.01, "256.01", "256.01");
73 DoArgumentPrecDoubleTest(convert("%.*G"), 1, 256.01, "3E+002", "3E+02");
74 DoArgumentPrecDoubleTest(convert("%.*G"), 3, 256.01, "256", "256");
75 DoArgumentPrecDoubleTest(convert("%.*G"), 4, 256.01, "256", "256");
76 DoArgumentPrecDoubleTest(convert("%.*G"), 6, 256.01, "256.01", "256.01");
77
78 PAL_Terminate();
79
80 return PASS;
81}
82