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: test5.c |
8 | ** |
9 | ** Purpose: Tests the count specifier (%n). |
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 | int __cdecl main(int argc, char *argv[]) |
23 | { |
24 | WCHAR *longStr; |
25 | char *longResult = |
26 | "really-long-string-that-just-keeps-going-on-and-on-and-on.." |
27 | "..................useless-filler.................................." |
28 | "..................useless-filler.................................." |
29 | "..................useless-filler.................................." |
30 | " bar" ; |
31 | |
32 | if (PAL_Initialize(argc, argv)) |
33 | { |
34 | return FAIL; |
35 | } |
36 | |
37 | longStr = |
38 | convert("really-long-string-that-just-keeps-going-on-and-on-and-on.." |
39 | "..................useless-filler.................................." |
40 | "..................useless-filler.................................." |
41 | "..................useless-filler.................................." |
42 | "%n bar" ); |
43 | DoCountTest(convert("foo %n bar" ), 4, "foo bar" ); |
44 | DoCountTest(longStr, 257, longResult); |
45 | DoCountTest(convert("fo%n bar" ), 2, "fo bar" ); |
46 | DoCountTest(convert("%n foo" ), 0, " foo" ); |
47 | DoCountTest(convert("foo %#n bar" ), 4, "foo bar" ); |
48 | DoCountTest(convert("foo % n bar" ), 4, "foo bar" ); |
49 | DoCountTest(convert("foo %+n bar" ), 4, "foo bar" ); |
50 | DoCountTest(convert("foo %-n bar" ), 4, "foo bar" ); |
51 | DoCountTest(convert("foo %0n bar" ), 4, "foo bar" ); |
52 | DoShortCountTest(convert("foo %hn bar" ), 4, "foo bar" ); |
53 | DoCountTest(convert("foo %ln bar" ), 4, "foo bar" ); |
54 | DoCountTest(convert("foo %Ln bar" ), 4, "foo bar" ); |
55 | DoCountTest(convert("foo %I64n bar" ), 4, "foo bar" ); |
56 | DoCountTest(convert("foo %20.3n bar" ), 4, "foo bar" ); |
57 | |
58 | PAL_Terminate(); |
59 | |
60 | free(longStr); |
61 | |
62 | return PASS; |
63 | } |
64 | |