1 /*
2  * Copyright (C) Red Hat, Inc. 2019
3  *
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.
8  *
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.
13  *
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/>.
17  */
18 
19 #include <config.h>
20 
21 #include "testutils.h"
22 #include "storage_conf.h"
23 #include "storage_capabilities.h"
24 
25 
26 #define VIR_FROM_THIS VIR_FROM_NONE
27 
28 
29 struct test_virStoragePoolCapsFormatData {
30     const char *filename;
31     virCaps *driverCaps;
32 };
33 
34 static void
test_virCapabilitiesAddFullStoragePool(virCaps * caps)35 test_virCapabilitiesAddFullStoragePool(virCaps *caps)
36 {
37     size_t i;
38 
39     for (i = 0; i < VIR_STORAGE_POOL_LAST; i++)
40         virCapabilitiesAddStoragePool(caps, i);
41 }
42 
43 
44 static void
test_virCapabilitiesAddFSStoragePool(virCaps * caps)45 test_virCapabilitiesAddFSStoragePool(virCaps *caps)
46 {
47     virCapabilitiesAddStoragePool(caps, VIR_STORAGE_POOL_FS);
48 }
49 
50 
51 static int
test_virStoragePoolCapsFormat(const void * opaque)52 test_virStoragePoolCapsFormat(const void *opaque)
53 {
54     struct test_virStoragePoolCapsFormatData *data =
55         (struct test_virStoragePoolCapsFormatData *) opaque;
56     virCaps *driverCaps = data->driverCaps;
57     g_autoptr(virStoragePoolCaps) poolCaps = NULL;
58     g_autofree char *path = NULL;
59     g_autofree char *poolCapsXML = NULL;
60 
61 
62     if (!(poolCaps = virStoragePoolCapsNew(driverCaps)))
63         return -1;
64 
65     path = g_strdup_printf("%s/storagepoolcapsschemadata/poolcaps-%s.xml",
66                            abs_srcdir, data->filename);
67 
68     if (!(poolCapsXML = virStoragePoolCapsFormat(poolCaps)))
69         return -1;
70 
71     if (virTestCompareToFile(poolCapsXML, path) < 0)
72         return -1;
73 
74     return 0;
75 }
76 
77 
78 static int
mymain(void)79 mymain(void)
80 {
81     int ret = 0;
82     g_autoptr(virCaps) fullCaps = NULL;
83     g_autoptr(virCaps) fsCaps = NULL;
84 
85 #define DO_TEST(Filename, DriverCaps) \
86     do { \
87         struct test_virStoragePoolCapsFormatData data = \
88             {.filename = Filename, .driverCaps = DriverCaps }; \
89         if (virTestRun(Filename, test_virStoragePoolCapsFormat, &data) < 0) \
90             ret = -1; \
91     } while (0)
92 
93     if (!(fullCaps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)) ||
94         !(fsCaps = virCapabilitiesNew(VIR_ARCH_NONE, false, false))) {
95         return -1;
96     }
97 
98     test_virCapabilitiesAddFullStoragePool(fullCaps);
99     test_virCapabilitiesAddFSStoragePool(fsCaps);
100 
101     DO_TEST("full", fullCaps);
102     DO_TEST("fs", fsCaps);
103 
104     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
105 }
106 
107 VIR_TEST_MAIN(mymain)
108