1 /* Test the %m, %#m printf specifiers via asprintf.
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
20 #include <libc-diag.h>
22 #include <support/check.h>
23 #include <support/support.h>
25 /* GCC does not yet know about the %#m specifier. */
26 DIAG_PUSH_NEEDS_COMMENT
;
27 DIAG_IGNORE_NEEDS_COMMENT (11, "-Wformat=");
35 TEST_COMPARE (sprintf (buf
, "%m"), 16);
36 TEST_COMPARE_STRING (buf
, "Invalid argument");
39 TEST_COMPARE (sprintf (buf
, "%#m"), 6);
40 TEST_COMPARE_STRING (buf
, "EINVAL");
43 TEST_COMPARE (sprintf (buf
, "%m"), 7);
44 TEST_COMPARE_STRING (buf
, "Success");
47 TEST_COMPARE (sprintf (buf
, "%#m"), 1);
48 TEST_COMPARE_STRING (buf
, "0");
52 TEST_COMPARE (sprintf (buf
, "%m"), 39);
53 TEST_COMPARE_STRING (buf
, "Error in unknown error system: FFFFFFFF");
55 TEST_COMPARE (sprintf (buf
, "%m"), 16);
56 TEST_COMPARE_STRING (buf
, "Unknown error -1");
60 TEST_COMPARE (sprintf (buf
, "%#m"), 2);
61 TEST_COMPARE_STRING (buf
, "-1");
65 TEST_COMPARE (sprintf (buf
, "%m"), 42);
66 TEST_COMPARE_STRING (buf
, "(system kern) error with unknown subsystem");
68 TEST_COMPARE (sprintf (buf
, "%m"), 21);
69 TEST_COMPARE_STRING (buf
, "Unknown error 1002003");
73 TEST_COMPARE (sprintf (buf
, "%#m"), 7);
74 TEST_COMPARE_STRING (buf
, "1002003");
77 TEST_COMPARE (sprintf (buf
, "%20m"), 20);
78 TEST_COMPARE_STRING (buf
, " Invalid argument");
81 TEST_COMPARE (sprintf (buf
, "%#20m"), 20);
82 TEST_COMPARE_STRING (buf
, " EINVAL");
85 TEST_COMPARE (sprintf (buf
, "%-20m"), 20);
86 TEST_COMPARE_STRING (buf
, "Invalid argument ");
89 TEST_COMPARE (sprintf (buf
, "%-#20m"), 20);
90 TEST_COMPARE_STRING (buf
, "EINVAL ");
93 TEST_COMPARE (sprintf (buf
, "%-20m"), 20);
94 TEST_COMPARE_STRING (buf
, "Success ");
97 TEST_COMPARE (sprintf (buf
, "%-#20m"), 20);
98 TEST_COMPARE_STRING (buf
, "0 ");
103 #include <support/test-driver.c>