2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; If not, see
14 * <http://www.gnu.org/licenses/>.
19 #include "testutils.h"
21 #define LIBVIRT_VIRERRORPRIV_H_ALLOW
22 #include "virerrorpriv.h"
23 #undef LIBVIRT_VIRERRORPRIV_H_ALLOW
26 virErrorTestMsgFormatInfoOne(const char *msg
)
35 for (next
= (char *)msg
; (next
= strchr(next
, '%')); next
++) {
36 if (!STRPREFIX(next
+ 1, "1$s")) {
37 VIR_TEST_VERBOSE("\nerror message '%s' contains disallowed printf modifiers", msg
);
41 VIR_TEST_VERBOSE("\nerror message '%s' contains multiple %%s modifiers", msg
);
50 VIR_TEST_VERBOSE("\nerror message '%s' does not contain correct %%s modifiers", msg
);
59 virErrorTestMsgs(const void *opaque G_GNUC_UNUSED
)
61 const char *err_noinfo
;
66 for (i
= 1; i
< VIR_ERR_NUMBER_LAST
; i
++) {
67 err_noinfo
= virErrorMsg(i
, NULL
);
68 err_info
= virErrorMsg(i
, "");
71 VIR_TEST_VERBOSE("\nmissing string without info for error id %zu", i
);
76 VIR_TEST_VERBOSE("\nmissing string with info for error id %zu", i
);
80 if (err_noinfo
&& strchr(err_noinfo
, '%')) {
81 VIR_TEST_VERBOSE("\nerror message id %zu contains formatting characters: '%s'",
86 if (err_info
&& virErrorTestMsgFormatInfoOne(err_info
) < 0)
99 if (virTestRun("error message strings ", virErrorTestMsgs
, NULL
) < 0)
102 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
105 VIR_TEST_MAIN(mymain
)