Rev 3424 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3424 | Rev 4377 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2005 Josef Cejka |
2 | * Copyright (c) 2005 Josef Cejka |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <print.h> |
29 | #include <print.h> |
30 | #include <test.h> |
30 | #include <test.h> |
31 | 31 | ||
32 | #define BUFFER_SIZE 32 |
- | |
33 | - | ||
34 | char * test_print1(bool quiet) |
32 | char *test_print1(void) |
35 | { |
33 | { |
36 | if (!quiet) { |
- | |
37 | int retval; |
- | |
38 | unative_t nat = 0x12345678u; |
- | |
39 | - | ||
40 | char buffer[BUFFER_SIZE]; |
- | |
41 | - | ||
42 | printf(" text 10.8s %*.*s \n", 5, 3, "text"); |
34 | TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n"); |
43 | printf(" very long text 10.8s %10.8s \n", "very long text"); |
- | |
44 | printf(" text 8.10s %8.10s \n", "text"); |
35 | TPRINTF("Expected output: \" tex\"\n"); |
45 | printf(" very long text 8.10s %8.10s \n", "very long text"); |
36 | TPRINTF("Real output: \"%*.*s\"\n\n", 5, 3, "text"); |
46 | 37 | ||
47 | printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n", 'a', 'b', 'c', 'd', 'e'); |
- | |
48 | printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n", 1, 1, 1, 1, 1); |
38 | TPRINTF("Testing printf(\"%%10.8s\", \"very long text\"):\n"); |
49 | printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n", -1, -1, -1, -1, -1); |
39 | TPRINTF("Expected output: \" very lon\"\n"); |
50 | printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n", 17, 17, 17, 17, 17); |
- | |
51 | - | ||
52 | printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#" PRIxn "'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" ); |
- | |
53 | - | ||
54 | printf(" Print to NULL '%s'\n", NULL); |
40 | TPRINTF("Real output: \"%10.8s\"\n\n", "very long text"); |
55 | 41 | ||
56 | retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); |
42 | TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n"); |
57 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
43 | TPRINTF("Expected output: \"text\"\n"); |
58 | - | ||
59 | retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); |
- | |
60 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
44 | TPRINTF("Real output: \"%8.10s\"\n\n", "text"); |
61 | 45 | ||
62 | printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
46 | TPRINTF("Testing printf(\"%%8.10s\", \"very long text\"):\n"); |
63 | retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text"); |
47 | TPRINTF("Expected output: \"very long \"\n"); |
64 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
48 | TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); |
65 | 49 | ||
66 | printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
50 | TPRINTF("Testing printf(\"%%s\", NULL):\n"); |
67 | retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE); |
51 | TPRINTF("Expected output: \"(NULL)\"\n"); |
68 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
52 | TPRINTF("Real output: \"%s\"\n\n", NULL); |
69 | } |
- | |
70 | 53 | ||
71 | return NULL; |
54 | return NULL; |
72 | } |
55 | } |
73 | 56 |