]>
Commit | Line | Data |
---|---|---|
12d4f965 VS |
1 | /* |
2 | * GRUB -- GRand Unified Bootloader | |
3 | * Copyright (C) 2011 Free Software Foundation, Inc. | |
4 | * | |
5 | * GRUB is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * GRUB is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with GRUB. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #include <stdio.h> | |
20 | #include <string.h> | |
21 | #include <grub/test.h> | |
22 | #include <grub/misc.h> | |
23 | ||
1c4afb60 VS |
24 | #define MSG "printf test failed" |
25 | ||
12d4f965 VS |
26 | static void |
27 | printf_test (void) | |
28 | { | |
29 | char real[512]; | |
30 | char expected[512]; | |
31 | grub_snprintf (real, sizeof (real), "%d %d %d", 1, 2, 3); | |
32 | snprintf (expected, sizeof (expected), "%d %d %d", 1, 2, 3); | |
1c4afb60 | 33 | grub_test_assert (strcmp (real, expected) == 0, MSG); |
12d4f965 VS |
34 | grub_snprintf (real, sizeof (real), "%3$d %2$d %1$d", 1, 2, 3); |
35 | snprintf (expected, sizeof (expected), "%3$d %2$d %1$d", 1, 2, 3); | |
1c4afb60 | 36 | grub_test_assert (strcmp (real, expected) == 0, MSG); |
12d4f965 VS |
37 | grub_snprintf (real, sizeof (real), "%d %lld %d", 1, 2LL, 3); |
38 | snprintf (expected, sizeof (expected), "%d %lld %d", 1, 2LL, 3); | |
1c4afb60 | 39 | grub_test_assert (strcmp (real, expected) == 0, MSG); |
12d4f965 VS |
40 | grub_snprintf (real, sizeof (real), "%3$d %2$lld %1$d", 1, 2LL, 3); |
41 | snprintf (expected, sizeof (expected), "%3$d %2$lld %1$d", 1, 2LL, 3); | |
1c4afb60 | 42 | grub_test_assert (strcmp (real, expected) == 0, MSG); |
12d4f965 VS |
43 | } |
44 | ||
45 | GRUB_UNIT_TEST ("printf_unit_test", printf_test); |