]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
qemumonitortestutils: Use VIR_DELETE_ELEMENT and VIR_APPEND_ELEMENT
authorPeter Krempa <pkrempa@redhat.com>
Thu, 18 Jul 2013 15:09:41 +0000 (17:09 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 31 Jul 2013 12:25:43 +0000 (14:25 +0200)
Simplify the code using the existing helpers instead of open coding the
same functionality.

tests/qemumonitortestutils.c

index ff90c5f524e0c18c57a2c05e73f31f6651d8211e..a3c54316e731ef9b4ecdbec216aeec444694e8d7 100644 (file)
@@ -133,17 +133,11 @@ qemuMonitorTestProcessCommandJSON(qemuMonitorTestPtr test,
                                         " { \"desc\": \"Unexpected command\", "
                                         "   \"class\": \"UnexpectedCommand\" } }");
     } else {
-        ret = qemuMonitorTestAddReponse(test,
-                                        test->items[0]->response);
+        ret = qemuMonitorTestAddReponse(test, test->items[0]->response);
         qemuMonitorTestItemFree(test->items[0]);
-        if (test->nitems == 1) {
-            VIR_FREE(test->items);
-            test->nitems = 0;
-        } else {
-            memmove(test->items,
-                    test->items + 1,
-                    sizeof(test->items[0]) * (test->nitems - 1));
-            VIR_SHRINK_N(test->items, test->nitems, 1);
+        if (VIR_DELETE_ELEMENT(test->items, 0, test->nitems) < 0) {
+            ret = -1;
+            goto cleanup;
         }
     }
 
@@ -175,17 +169,11 @@ qemuMonitorTestProcessCommandText(qemuMonitorTestPtr test,
         ret = qemuMonitorTestAddReponse(test,
                                         "unexpected command");
     } else {
-        ret = qemuMonitorTestAddReponse(test,
-                                        test->items[0]->response);
+        ret = qemuMonitorTestAddReponse(test, test->items[0]->response);
         qemuMonitorTestItemFree(test->items[0]);
-        if (test->nitems == 1) {
-            VIR_FREE(test->items);
-            test->nitems = 0;
-        } else {
-            memmove(test->items,
-                    test->items + 1,
-                    sizeof(test->items[0]) * (test->nitems - 1));
-            VIR_SHRINK_N(test->items, test->nitems, 1);
+        if (VIR_DELETE_ELEMENT(test->items, 0, test->nitems) < 0) {
+            ret = -1;
+            goto cleanup;
         }
     }
 
@@ -421,12 +409,10 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
         goto error;
 
     virMutexLock(&test->lock);
-    if (VIR_EXPAND_N(test->items, test->nitems, 1) < 0) {
+    if (VIR_APPEND_ELEMENT(test->items, test->nitems, item) < 0) {
         virMutexUnlock(&test->lock);
         goto error;
     }
-    test->items[test->nitems - 1] = item;
-
     virMutexUnlock(&test->lock);
 
     return 0;