Imported Upstream version 1.2.4
[archive/platform/upstream/libvirt.git] / tests / storagepoolxml2xmltest.c
1 #include <config.h>
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <string.h>
7
8 #include <sys/types.h>
9 #include <fcntl.h>
10
11 #include "internal.h"
12 #include "testutils.h"
13 #include "storage_conf.h"
14 #include "testutilsqemu.h"
15 #include "virstring.h"
16
17 #define VIR_FROM_THIS VIR_FROM_NONE
18
19 static int
20 testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
21 {
22     char *inXmlData = NULL;
23     char *outXmlData = NULL;
24     char *actual = NULL;
25     int ret = -1;
26     virStoragePoolDefPtr dev = NULL;
27
28     if (virtTestLoadFile(inxml, &inXmlData) < 0)
29         goto fail;
30     if (virtTestLoadFile(outxml, &outXmlData) < 0)
31         goto fail;
32
33     if (!(dev = virStoragePoolDefParseString(inXmlData)))
34         goto fail;
35
36     if (!(actual = virStoragePoolDefFormat(dev)))
37         goto fail;
38
39     if (STRNEQ(outXmlData, actual)) {
40         virtTestDifference(stderr, outXmlData, actual);
41         goto fail;
42     }
43
44     ret = 0;
45
46  fail:
47     VIR_FREE(inXmlData);
48     VIR_FREE(outXmlData);
49     VIR_FREE(actual);
50     virStoragePoolDefFree(dev);
51     return ret;
52 }
53
54 static int
55 testCompareXMLToXMLHelper(const void *data)
56 {
57     int result = -1;
58     char *inxml = NULL;
59     char *outxml = NULL;
60
61     if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml",
62                     abs_srcdir, (const char*)data) < 0 ||
63         virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml",
64                     abs_srcdir, (const char*)data) < 0) {
65         goto cleanup;
66     }
67
68     result = testCompareXMLToXMLFiles(inxml, outxml);
69
70  cleanup:
71     VIR_FREE(inxml);
72     VIR_FREE(outxml);
73
74     return result;
75 }
76
77 static int
78 mymain(void)
79 {
80     int ret = 0;
81
82 #define DO_TEST(name)                                           \
83     if (virtTestRun("Storage Pool XML-2-XML " name,             \
84                     testCompareXMLToXMLHelper, (name)) < 0)     \
85         ret = -1
86
87     DO_TEST("pool-dir");
88     DO_TEST("pool-dir-naming");
89     DO_TEST("pool-fs");
90     DO_TEST("pool-logical");
91     DO_TEST("pool-logical-nopath");
92     DO_TEST("pool-logical-create");
93     DO_TEST("pool-disk");
94     DO_TEST("pool-iscsi");
95     DO_TEST("pool-iscsi-auth");
96     DO_TEST("pool-netfs");
97     DO_TEST("pool-netfs-gluster");
98     DO_TEST("pool-scsi");
99     DO_TEST("pool-scsi-type-scsi-host");
100     DO_TEST("pool-scsi-type-fc-host");
101     DO_TEST("pool-mpath");
102     DO_TEST("pool-iscsi-multiiqn");
103     DO_TEST("pool-iscsi-vendor-product");
104     DO_TEST("pool-sheepdog");
105     DO_TEST("pool-gluster");
106     DO_TEST("pool-gluster-sub");
107
108     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
109 }
110
111 VIRT_TEST_MAIN(mymain)