backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virnetworkportxml2xmltest.c
blobbb0ae8a8d5cd74e4ebfb8ba2f36c857a3e123e35
1 /*
2 * virnetworkportxml2xmltest.c: network port XML processing test suite
4 * Copyright (C) 2018 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include <config.h>
23 #include <unistd.h>
25 #include <sys/types.h>
26 #include <fcntl.h>
28 #include "internal.h"
29 #include "testutils.h"
30 #include "virnetworkportdef.h"
31 #include "virstring.h"
33 #define VIR_FROM_THIS VIR_FROM_NONE
36 static int
37 testCompareXMLToXMLFiles(const char *expected)
39 char *actual = NULL;
40 int ret = -1;
41 virNetworkPortDefPtr dev = NULL;
43 if (!(dev = virNetworkPortDefParseFile(expected)))
44 goto cleanup;
46 if (!(actual = virNetworkPortDefFormat(dev)))
47 goto cleanup;
49 if (virTestCompareToFile(actual, expected) < 0)
50 goto cleanup;
52 ret = 0;
53 cleanup:
54 VIR_FREE(actual);
55 virNetworkPortDefFree(dev);
56 return ret;
59 struct testInfo {
60 const char *name;
63 static int
64 testCompareXMLToXMLHelper(const void *data)
66 const struct testInfo *info = data;
67 int ret = -1;
68 char *xml = NULL;
70 if (virAsprintf(&xml, "%s/virnetworkportxml2xmldata/%s.xml",
71 abs_srcdir, info->name) < 0)
72 goto cleanup;
74 ret = testCompareXMLToXMLFiles(xml);
76 cleanup:
77 VIR_FREE(xml);
79 return ret;
82 static int
83 mymain(void)
85 int ret = 0;
87 #define DO_TEST(name) \
88 do { \
89 const struct testInfo info = {name}; \
90 if (virTestRun("virnetworkportdeftest " name, \
91 testCompareXMLToXMLHelper, &info) < 0) \
92 ret = -1; \
93 } while (0)
95 DO_TEST("plug-none");
96 DO_TEST("plug-bridge");
97 DO_TEST("plug-bridge-mactbl");
98 DO_TEST("plug-direct");
99 DO_TEST("plug-hostdev-pci");
101 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
104 VIR_TEST_MAIN(mymain)