backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virkeyfiletest.c
blob427614916354f25e78f0d2c12a8a711afd7b866a
1 /*
2 * Copyright (C) 2011, 2012, 2014 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
19 #include <config.h>
21 #include <signal.h>
23 #include "testutils.h"
24 #include "virerror.h"
25 #include "viralloc.h"
26 #include "virlog.h"
28 #include "virkeyfile.h"
30 #define VIR_FROM_THIS VIR_FROM_RPC
32 VIR_LOG_INIT("tests.keyfiletest");
34 static int testParse(const void *args ATTRIBUTE_UNUSED)
36 static const char *cfg1 =
37 "# Some config\n"
38 "\n"
39 "# The first group\n"
40 "[Foo]\n"
41 "one=The first entry is here\n"
42 "two=The second entry\n"
43 " \n"
44 "three=The third entry\n"
45 "[Bar]\n"
46 "; Another comment\n"
47 "one=The first entry in second group";
48 virKeyFilePtr kf = virKeyFileNew();
49 int ret = -1;
51 if (virKeyFileLoadData(kf, "demo.conf", cfg1, strlen(cfg1)) < 0)
52 goto cleanup;
54 if (!virKeyFileHasGroup(kf, "Foo")) {
55 VIR_DEBUG("Missing group 'Foo'");
56 goto cleanup;
58 if (!virKeyFileHasValue(kf, "Foo", "one")) {
59 VIR_DEBUG("Missing Value 'Foo.one'");
60 goto cleanup;
62 if (!virKeyFileHasValue(kf, "Foo", "two")) {
63 VIR_DEBUG("Missing Value 'Foo.two'");
64 goto cleanup;
66 if (!virKeyFileHasValue(kf, "Foo", "three")) {
67 VIR_DEBUG("Missing Value 'Foo.three'");
68 goto cleanup;
70 if (STRNEQ(virKeyFileGetValueString(kf, "Foo", "one"),
71 "The first entry is here")) {
72 VIR_DEBUG("Wrong value for 'Foo.one'");
73 goto cleanup;
75 if (STRNEQ(virKeyFileGetValueString(kf, "Foo", "two"),
76 "The second entry")) {
77 VIR_DEBUG("Wrong value for 'Foo.one'");
78 goto cleanup;
80 if (STRNEQ(virKeyFileGetValueString(kf, "Foo", "three"),
81 "The third entry")) {
82 VIR_DEBUG("Wrong value for 'Foo.one'");
83 goto cleanup;
86 if (!virKeyFileHasGroup(kf, "Bar")) {
87 VIR_DEBUG("Missing group 'Bar'");
88 goto cleanup;
90 if (!virKeyFileHasValue(kf, "Bar", "one")) {
91 VIR_DEBUG("Missing Value 'Bar.one'");
92 goto cleanup;
94 if (STRNEQ(virKeyFileGetValueString(kf, "Bar", "one"),
95 "The first entry in second group")) {
96 VIR_DEBUG("Wrong value for 'Bar.one'");
97 goto cleanup;
100 ret = 0;
101 cleanup:
102 virKeyFileFree(kf);
103 return ret;
107 static int
108 mymain(void)
110 int ret = 0;
112 signal(SIGPIPE, SIG_IGN);
114 if (virTestRun("Test parse", testParse, NULL) < 0)
115 ret = -1;
117 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
120 VIR_TEST_MAIN(mymain)