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