[PATCH 2/2] Add a test for virUSBDeviceList functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Most of them are already tested in a limited way
by testing virUSBDeviceFind.
---
 tests/virusbtest.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/tests/virusbtest.c b/tests/virusbtest.c
index f9104bf..74b9a5e 100644
--- a/tests/virusbtest.c
+++ b/tests/virusbtest.c
@@ -204,6 +204,78 @@ cleanup:
 
 
 static int
+testUSBList(const void *opaque ATTRIBUTE_UNUSED)
+{
+    virUSBDeviceListPtr list = NULL;
+    virUSBDeviceListPtr devlist = NULL;
+    virUSBDevicePtr dev = NULL;
+    int ret = -1;
+    size_t i, ndevs;
+
+    if (!(list = virUSBDeviceListNew()))
+        goto cleanup;
+
+    if (virUSBDeviceFindByVendor(0x1d6b, 0x0002, NULL, true, &devlist) < 0)
+        goto cleanup;
+
+    ndevs = virUSBDeviceListCount(devlist);
+    for (i = 0; i < ndevs; i++) {
+        dev = virUSBDeviceListGet(devlist, 0);
+        dev = virUSBDeviceListSteal(devlist, dev);
+
+        if (virUSBDeviceListAdd(list, dev) < 0)
+            goto cleanup;
+        dev = NULL;
+    }
+
+    virObjectUnref(devlist);
+    devlist = NULL;
+
+    if (virUSBDeviceFindByVendor(0x18d1, 0x4e22, NULL, true, &devlist) < 0)
+        goto cleanup;
+
+    ndevs = virUSBDeviceListCount(devlist);
+    for (i = 0; i < ndevs; i++) {
+        dev = virUSBDeviceListGet(devlist, 0);
+        dev = virUSBDeviceListSteal(devlist, dev);
+
+        if (virUSBDeviceListAdd(list, dev) < 0)
+            goto cleanup;
+        dev = NULL;
+    }
+
+    if (virUSBDeviceFind(0x18d1, 0x4e22, 1, 20, NULL, true, &dev) < 0)
+        goto cleanup;
+
+    if (!virUSBDeviceListFind(list, dev)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Device '%s' not in list when it should be",
+                       virUSBDeviceGetName(dev));
+        goto cleanup;
+    }
+
+    virUSBDeviceListDel(list, dev);
+    dev = NULL;
+
+    if (virUSBDeviceListCount(list) != 5) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Wrong device count %zu expected %d",
+                       virUSBDeviceListCount(list),
+                       5);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    virObjectUnref(list);
+    virObjectUnref(devlist);
+    virUSBDeviceFree(dev);
+    return ret;
+}
+
+
+static int
 mymain(void)
 {
     int rv = 0;
@@ -251,6 +323,9 @@ mymain(void)
     DO_TEST_FIND_BY_VENDOR_FAIL("Bogus vendor and product", 0xf00d, 0xbeef);
     DO_TEST_FIND_BY_VENDOR_FAIL("Valid vendor", 0x1d6b, 0xbeef);
 
+    if (virtTestRun("USB List test", testUSBList, NULL) < 0)
+        rv = -1;
+
     if (rv < 0)
         return EXIT_FAILURE;
     return EXIT_SUCCESS;
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]