diff --git a/tests/Makefile.am b/tests/Makefile.am
index 760f600bf2..72f0420bab 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -369,6 +369,7 @@ test_programs += storagevolxml2argvtest
test_programs += storagepoolxml2argvtest
test_programs += virstorageutiltest
test_programs += storagepoolxml2xmltest
+test_programs += storagepoolcapstest
endif WITH_STORAGE
if WITH_STORAGE_FS
@@ -936,11 +937,16 @@ storagepoolxml2xmltest_LDADD = $(LDADDS) \
../src/libvirt_driver_storage_impl.la \
$(GNULIB_LIBS)
+storagepoolcapstest_SOURCES = \
+ storagepoolcapstest.c testutils.h testutils.c
+storagepoolcapstest_LDADD = $(LDADDS)
+
else ! WITH_STORAGE
EXTRA_DIST += storagevolxml2argvtest.c
EXTRA_DIST += virstorageutiltest.c
EXTRA_DIST += storagepoolxml2argvtest.c
EXTRA_DIST += storagepoolxml2xmltest.c
+EXTRA_DIST += storagepoolcapstest.c
endif ! WITH_STORAGE
storagevolxml2xmltest_SOURCES = \
diff --git a/tests/storagepoolcapsschemadata/poolcaps-fs.xml b/tests/storagepoolcapsschemadata/poolcaps-fs.xml
new file mode 100644
index 0000000000..0e15af0607
--- /dev/null
+++ b/tests/storagepoolcapsschemadata/poolcaps-fs.xml
@@ -0,0 +1,268 @@
+
+
+
+
+
+ none
+ raw
+ dir
+ bochs
+ cloop
+ dmg
+ iso
+ vpc
+ vdi
+ fat
+ vhd
+ ploop
+ cow
+ qcow
+ qcow2
+ qed
+ vmdk
+
+
+
+
+
+
+
+ auto
+ ext2
+ ext3
+ ext4
+ ufs
+ iso9660
+ udf
+ gfs
+ gfs2
+ vfat
+ hfs+
+ xfs
+ ocfs2
+
+
+ device
+
+
+
+
+
+ none
+ raw
+ dir
+ bochs
+ cloop
+ dmg
+ iso
+ vpc
+ vdi
+ fat
+ vhd
+ ploop
+ cow
+ qcow
+ qcow2
+ qed
+ vmdk
+
+
+
+
+
+
+
+ auto
+ nfs
+ glusterfs
+ cifs
+
+
+ host
+ dir
+
+
+
+
+
+ none
+ raw
+ dir
+ bochs
+ cloop
+ dmg
+ iso
+ vpc
+ vdi
+ fat
+ vhd
+ ploop
+ cow
+ qcow
+ qcow2
+ qed
+ vmdk
+
+
+
+
+
+
+
+ unknown
+ lvm2
+
+
+ device
+ name
+
+
+
+
+
+
+
+ unknown
+ dos
+ dvh
+ gpt
+ mac
+ bsd
+ pc98
+ sun
+ lvm2
+
+
+ device
+
+
+
+
+
+ none
+ linux
+ fat16
+ fat32
+ linux-swap
+ linux-lvm
+ linux-raid
+ extended
+
+
+
+
+
+
+ host
+ device
+ initiator
+
+
+
+
+
+
+ host
+ device
+ initiator
+ network
+
+
+
+
+
+
+ adapter
+
+
+
+
+
+
+
+
+ host
+ name
+ network
+
+
+
+
+
+
+ host
+ name
+ network
+
+
+
+
+
+
+ host
+ dir
+ name
+ network
+
+
+
+
+
+ none
+ raw
+ dir
+ bochs
+ cloop
+ dmg
+ iso
+ vpc
+ vdi
+ fat
+ vhd
+ ploop
+ cow
+ qcow
+ qcow2
+ qed
+ vmdk
+
+
+
+
+
+
+ device
+ name
+
+
+
+
+
+
+ name
+
+
+
+
+
+ none
+ raw
+ dir
+ bochs
+ cloop
+ dmg
+ iso
+ vpc
+ vdi
+ fat
+ vhd
+ ploop
+ cow
+ qcow
+ qcow2
+ qed
+ vmdk
+
+
+
+
diff --git a/tests/storagepoolcapstest.c b/tests/storagepoolcapstest.c
new file mode 100644
index 0000000000..d31f50c957
--- /dev/null
+++ b/tests/storagepoolcapstest.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) Red Hat, Inc. 2019
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * .
+ */
+
+#include
+
+#include "testutils.h"
+#include "storage_conf.h"
+#include "storage_capabilities.h"
+
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+
+struct test_virStoragePoolCapsFormatData {
+ const char *filename;
+ virCapsPtr driverCaps;
+};
+
+static void
+test_virCapabilitiesAddFullStoragePool(virCapsPtr caps)
+{
+ size_t i;
+
+ for (i = 0; i < VIR_STORAGE_POOL_LAST; i++)
+ virCapabilitiesAddStoragePool(caps, i);
+}
+
+
+static void
+test_virCapabilitiesAddFSStoragePool(virCapsPtr caps)
+{
+ virCapabilitiesAddStoragePool(caps, VIR_STORAGE_POOL_FS);
+}
+
+
+static int
+test_virStoragePoolCapsFormat(const void *opaque)
+{
+ struct test_virStoragePoolCapsFormatData *data =
+ (struct test_virStoragePoolCapsFormatData *) opaque;
+ virCapsPtr driverCaps = data->driverCaps;
+ virStoragePoolCapsPtr poolCaps = NULL;
+ int ret = -1;
+ VIR_AUTOFREE(char *) path = NULL;
+ VIR_AUTOFREE(char *) poolCapsFromFile = NULL;
+ VIR_AUTOFREE(char *) poolCapsXML = NULL;
+
+
+ if (!(poolCaps = virStoragePoolCapsNew(driverCaps)))
+ goto cleanup;
+
+ if (virAsprintf(&path, "%s/storagepoolcapsschemadata/poolcaps-%s.xml",
+ abs_srcdir, data->filename) < 0)
+ goto cleanup;
+
+ if (virFileReadAll(path, 8192, &poolCapsFromFile) < 0)
+ goto cleanup;
+
+ if (!(poolCapsXML = virStoragePoolCapsFormat(poolCaps)))
+ goto cleanup;
+
+ if (STRNEQ(poolCapsFromFile, poolCapsXML)) {
+ virTestDifference(stderr, poolCapsFromFile, poolCapsXML);
+ goto cleanup;
+ }
+
+ ret = 0;
+
+ cleanup:
+ virObjectUnref(poolCaps);
+ return ret;
+}
+
+
+static int
+mymain(void)
+{
+ int ret = -1;
+ virCapsPtr fullCaps = NULL;
+ virCapsPtr fsCaps = NULL;
+
+#define DO_TEST(Filename, DriverCaps) \
+ do { \
+ struct test_virStoragePoolCapsFormatData data = \
+ {.filename = Filename, .driverCaps = DriverCaps }; \
+ if (virTestRun(Filename, test_virStoragePoolCapsFormat, &data) < 0) \
+ goto cleanup; \
+ } while (0)
+
+ if (!(fullCaps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)) ||
+ !(fsCaps = virCapabilitiesNew(VIR_ARCH_NONE, false, false)))
+ goto cleanup;
+
+ test_virCapabilitiesAddFullStoragePool(fullCaps);
+ test_virCapabilitiesAddFSStoragePool(fsCaps);
+
+ DO_TEST("full", fullCaps);
+ DO_TEST("fs", fsCaps);
+
+ ret = 0;
+
+ cleanup:
+ virObjectUnref(fullCaps);
+ virObjectUnref(fsCaps);
+
+ return ret;
+}
+
+VIR_TEST_MAIN(mymain)