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/>.
23 #include "testutils.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
=
41 "one=The first entry is here\n"
42 "two=The second entry\n"
44 "three=The third entry\n"
47 "one=The first entry in second group";
48 virKeyFilePtr kf
= virKeyFileNew();
51 if (virKeyFileLoadData(kf
, "demo.conf", cfg1
, strlen(cfg1
)) < 0)
54 if (!virKeyFileHasGroup(kf
, "Foo")) {
55 VIR_DEBUG("Missing group 'Foo'");
58 if (!virKeyFileHasValue(kf
, "Foo", "one")) {
59 VIR_DEBUG("Missing Value 'Foo.one'");
62 if (!virKeyFileHasValue(kf
, "Foo", "two")) {
63 VIR_DEBUG("Missing Value 'Foo.two'");
66 if (!virKeyFileHasValue(kf
, "Foo", "three")) {
67 VIR_DEBUG("Missing Value 'Foo.three'");
70 if (STRNEQ(virKeyFileGetValueString(kf
, "Foo", "one"),
71 "The first entry is here")) {
72 VIR_DEBUG("Wrong value for 'Foo.one'");
75 if (STRNEQ(virKeyFileGetValueString(kf
, "Foo", "two"),
76 "The second entry")) {
77 VIR_DEBUG("Wrong value for 'Foo.one'");
80 if (STRNEQ(virKeyFileGetValueString(kf
, "Foo", "three"),
82 VIR_DEBUG("Wrong value for 'Foo.one'");
86 if (!virKeyFileHasGroup(kf
, "Bar")) {
87 VIR_DEBUG("Missing group 'Bar'");
90 if (!virKeyFileHasValue(kf
, "Bar", "one")) {
91 VIR_DEBUG("Missing Value 'Bar.one'");
94 if (STRNEQ(virKeyFileGetValueString(kf
, "Bar", "one"),
95 "The first entry in second group")) {
96 VIR_DEBUG("Wrong value for 'Bar.one'");
112 signal(SIGPIPE
, SIG_IGN
);
114 if (virTestRun("Test parse", testParse
, NULL
) < 0)
117 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
120 VIR_TEST_MAIN(mymain
)