docs: Reword virDomainGetEmulatorPinInfo description
[libvirt.git] / tests / virerrortest.c
blobc1b1a2ba657e81bfdd581c86dee6722cef73b042
1 /*
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/>.
17 #include <config.h>
19 #include "testutils.h"
21 #define LIBVIRT_VIRERRORPRIV_H_ALLOW
22 #include "virerrorpriv.h"
23 #undef LIBVIRT_VIRERRORPRIV_H_ALLOW
25 static int
26 virErrorTestMsgFormatInfoOne(const char *msg)
28 bool found = false;
29 char *next;
30 int ret = 0;
32 if (STREQ(msg, "%s"))
33 return 0;
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);
38 ret = -1;
39 } else {
40 if (found) {
41 VIR_TEST_VERBOSE("\nerror message '%s' contains multiple %%s modifiers", msg);
42 ret = -1;
43 } else {
44 found = true;
49 if (!found) {
50 VIR_TEST_VERBOSE("\nerror message '%s' does not contain correct %%s modifiers", msg);
51 ret = -1;
54 return ret;
58 static int
59 virErrorTestMsgs(const void *opaque G_GNUC_UNUSED)
61 const char *err_noinfo;
62 const char *err_info;
63 size_t i;
64 int ret = 0;
66 for (i = 1; i < VIR_ERR_NUMBER_LAST; i++) {
67 err_noinfo = virErrorMsg(i, NULL);
68 err_info = virErrorMsg(i, "");
70 if (!err_noinfo) {
71 VIR_TEST_VERBOSE("\nmissing string without info for error id %zu", i);
72 ret = -1;
75 if (!err_info) {
76 VIR_TEST_VERBOSE("\nmissing string with info for error id %zu", i);
77 ret = -1;
80 if (err_noinfo && strchr(err_noinfo, '%')) {
81 VIR_TEST_VERBOSE("\nerror message id %zu contains formatting characters: '%s'",
82 i, err_noinfo);
83 ret = -1;
86 if (err_info && virErrorTestMsgFormatInfoOne(err_info) < 0)
87 ret = -1;
90 return ret;
94 static int
95 mymain(void)
97 int ret = 0;
99 if (virTestRun("error message strings ", virErrorTestMsgs, NULL) < 0)
100 ret = -1;
102 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
105 VIR_TEST_MAIN(mymain)