1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
/*=====================================================================
**
** Source: test19.c
**
** Purpose: Test #19 for the _vsnprintf function.
**
**
**===================================================================*/
#include <palsuite.h>
#include "../_vsnprintf.h"
/*
* Notes: memcmp is used, as is strlen.
*/
#define DOTEST(a,b,c,d,e) DoTest(a,b,(void*)c,d,e)
void DoArgumentPrecTest(char *formatstr, int precision, void *param,
char *paramstr, char *checkstr1, char *checkstr2)
{
char buf[256];
Testvsnprintf(buf,256,formatstr, precision, param);
if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 &&
memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0)
{
Fail("ERROR: failed to insert %s into \"%s\" with precision %d\n"
"Expected \"%s\" or \"%s\", got \"%s\".\n",
paramstr, formatstr, precision, checkstr1, checkstr2, buf);
}
}
void DoArgumentPrecDoubleTest(char *formatstr, int precision, double param,
char *checkstr1, char *checkstr2)
{
char buf[256];
Testvsnprintf(buf,256,formatstr, precision, param);
if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 &&
memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0)
{
Fail("ERROR: failed to insert %f into \"%s\" with precision %d\n"
"Expected \"%s\" or \"%s\", got \"%s\".\n",
param, formatstr, precision, checkstr1, checkstr2, buf);
}
}
int __cdecl main(int argc, char *argv[])
{
if (PAL_Initialize(argc, argv) != 0)
{
return(FAIL);
}
DoArgumentPrecTest("%.*s", 2, "bar", "bar", "ba", "ba");
DoArgumentPrecTest("%.*S", 2, convert("bar"), "bar", "ba", "ba");
DoArgumentPrecTest("%.*c", 0, (void*)'a', "a", "a", "a");
DoArgumentPrecTest("%.*c", 4, (void*)'a', "a", "a", "a");
DoArgumentPrecTest("%.*C", 0, (void*)'a', "a", "a", "a");
DoArgumentPrecTest("%.*C", 4, (void*)'a', "a", "a", "a");
DoArgumentPrecTest("%.*d", 1, (void*)42, "42", "42", "42");
DoArgumentPrecTest("%.*d", 3, (void*)42, "42", "042", "042");
DoArgumentPrecTest("%.*i", 1, (void*)42, "42", "42", "42");
DoArgumentPrecTest("%.*i", 3, (void*)42, "42", "042", "042");
DoArgumentPrecTest("%.*o", 1, (void*)42, "42", "52", "52");
DoArgumentPrecTest("%.*o", 3, (void*)42, "42", "052", "052");
DoArgumentPrecTest("%.*u", 1, (void*)42, "42", "42", "42");
DoArgumentPrecTest("%.*u", 3, (void*)42, "42", "042", "042");
DoArgumentPrecTest("%.*x", 1, (void*)0x42, "0x42", "42", "42");
DoArgumentPrecTest("%.*x", 3, (void*)0x42, "0x42", "042", "042");
DoArgumentPrecTest("%.*X", 1, (void*)0x42, "0x42", "42", "42");
DoArgumentPrecTest("%.*X", 3, (void*)0x42, "0x42", "042", "042");
DoArgumentPrecDoubleTest("%.*e", 1, 2.01, "2.0e+000", "2.0e+00");
DoArgumentPrecDoubleTest("%.*e", 3, 2.01, "2.010e+000", "2.010e+00");
DoArgumentPrecDoubleTest("%.*E", 1, 2.01, "2.0E+000", "2.0E+00");
DoArgumentPrecDoubleTest("%.*E", 3, 2.01, "2.010E+000", "2.010E+00");
DoArgumentPrecDoubleTest("%.*f", 1, 2.01, "2.0", "2.0");
DoArgumentPrecDoubleTest("%.*f", 3, 2.01, "2.010", "2.010");
DoArgumentPrecDoubleTest("%.*g", 1, 256.01, "3e+002", "3e+02");
DoArgumentPrecDoubleTest("%.*g", 3, 256.01, "256", "256");
DoArgumentPrecDoubleTest("%.*g", 4, 256.01, "256", "256");
DoArgumentPrecDoubleTest("%.*g", 6, 256.01, "256.01", "256.01");
DoArgumentPrecDoubleTest("%.*G", 1, 256.01, "3E+002", "3E+02");
DoArgumentPrecDoubleTest("%.*G", 3, 256.01, "256", "256");
DoArgumentPrecDoubleTest("%.*G", 4, 256.01, "256", "256");
DoArgumentPrecDoubleTest("%.*G", 6, 256.01, "256.01", "256.01");
PAL_Terminate();
return PASS;
}
|