blob: 2c3ebc0fe911b4f9ff86050294e8a7ec43e67095 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <app/tests.h>
24#include <debug.h>
25
26void printf_tests(void)
27{
Travis Geiselbrechteb946052008-09-07 22:32:49 -070028 printf("printf tests\n");
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070029
Travis Geiselbrechteb946052008-09-07 22:32:49 -070030 printf("numbers:\n");
31 printf("int8: %hhd %hhd %hhd\n", -12, 0, 254);
32 printf("uint8: %hhu %hhu %hhu\n", -12, 0, 254);
33 printf("int16: %hd %hd %hd\n", -1234, 0, 1234);
34 printf("uint16:%hu %hu %hu\n", -1234, 0, 1234);
35 printf("int: %d %d %d\n", -12345678, 0, 12345678);
36 printf("uint: %u %u %u\n", -12345678, 0, 12345678);
37 printf("long: %ld %ld %ld\n", -12345678, 0, 12345678);
38 printf("ulong: %lu %lu %lu\n", -12345678, 0, 12345678);
39 printf("long: %D %D %D\n", -12345678, 0, 12345678);
40 printf("ulong: %U %U %U\n", -12345678, 0, 12345678);
41 printf("longlong: %lli %lli %lli\n", -12345678LL, 0LL, 12345678LL);
42 printf("ulonglong: %llu %llu %llu\n", -12345678LL, 0LL, 12345678LL);
43 printf("size_t: %zd %zd %zd\n", -12345678, 0, 12345678);
44 printf("usize_t: %zu %zu %zu\n", -12345678, 0, 12345678);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070045
Travis Geiselbrechteb946052008-09-07 22:32:49 -070046 printf("hex:\n");
47 printf("uint8: %hhx %hhx %hhx\n", -12, 0, 254);
48 printf("uint16:%hx %hx %hx\n", -1234, 0, 1234);
49 printf("uint: %x %x %x\n", -12345678, 0, 12345678);
50 printf("ulong: %lx %lx %lx\n", -12345678, 0, 12345678);
51 printf("ulong: %X %X %X\n", -12345678, 0, 12345678);
52 printf("ulonglong: %llx %llx %llx\n", -12345678LL, 0LL, 12345678LL);
53 printf("usize_t: %zx %zx %zx\n", -12345678, 0, 12345678);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070054
Travis Geiselbrechteb946052008-09-07 22:32:49 -070055 printf("alt/sign:\n");
56 printf("uint: %#x %#X\n", 0xabcdef, 0xabcdef);
57 printf("int: %+d %+d\n", 12345678, -12345678);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070058
Travis Geiselbrechteb946052008-09-07 22:32:49 -070059 printf("formatting\n");
60 printf("int: a%8da\n", 12345678);
61 printf("int: a%9da\n", 12345678);
62 printf("int: a%-9da\n", 12345678);
63 printf("int: a%10da\n", 12345678);
64 printf("int: a%-10da\n", 12345678);
65 printf("int: a%09da\n", 12345678);
66 printf("int: a%010da\n", 12345678);
67 printf("int: a%6da\n", 12345678);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070068
Travis Geiselbrechteb946052008-09-07 22:32:49 -070069 printf("a%1sa\n", "b");
70 printf("a%9sa\n", "b");
71 printf("a%-9sa\n", "b");
72 printf("a%5sa\n", "thisisatest");
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070073
74 int err;
75
Travis Geiselbrechteb946052008-09-07 22:32:49 -070076 err = printf("a");
77 printf(" returned %d\n", err);
78 err = printf("ab");
79 printf(" returned %d\n", err);
80 err = printf("abc");
81 printf(" returned %d\n", err);
82 err = printf("abcd");
83 printf(" returned %d\n", err);
84 err = printf("abcde");
85 printf(" returned %d\n", err);
86 err = printf("abcdef");
87 printf(" returned %d\n", err);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070088}
89
90