backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virerrortest.c
blobb49d1a91354f7e63383944af477986d4199ead38
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 for (next = (char *)msg; (next = strchr(next, '%')); next++) {
33 if (next[1] != 's') {
34 VIR_TEST_VERBOSE("\nerror message '%s' contains disallowed printf modifiers\n", msg);
35 ret = -1;
36 } else {
37 if (found) {
38 VIR_TEST_VERBOSE("\nerror message '%s' contains multiple %%s modifiers\n", msg);
39 ret = -1;
40 } else {
41 found = true;
46 if (!found) {
47 VIR_TEST_VERBOSE("\nerror message '%s' does not contain any %%s modifiers\n", msg);
48 ret = -1;
51 return ret;
55 static int
56 virErrorTestMsgs(const void *opaque ATTRIBUTE_UNUSED)
58 const char *err_noinfo;
59 const char *err_info;
60 size_t i;
61 int ret = 0;
63 for (i = 1; i < VIR_ERR_NUMBER_LAST; i++) {
64 err_noinfo = virErrorMsg(i, NULL);
65 err_info = virErrorMsg(i, "");
67 if (!err_noinfo) {
68 VIR_TEST_VERBOSE("\nmissing string without info for error id %zu\n", i);
69 ret = -1;
72 if (!err_info) {
73 VIR_TEST_VERBOSE("\nmissing string with info for error id %zu\n", i);
74 ret = -1;
77 if (err_noinfo && strchr(err_noinfo, '%')) {
78 VIR_TEST_VERBOSE("\nerror message id %zu contains formatting characters: '%s'\n",
79 i, err_noinfo);
80 ret = -1;
83 if (err_info && virErrorTestMsgFormatInfoOne(err_info) < 0)
84 ret = -1;
87 return ret;
91 static int
92 mymain(void)
94 int ret = 0;
96 if (virTestRun("error message strings ", virErrorTestMsgs, NULL) < 0)
97 ret = -1;
99 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
102 VIR_TEST_MAIN(mymain)