mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-08 22:15:21 +00:00
qemumonitortestutils: Use VIR_DELETE_ELEMENT and VIR_APPEND_ELEMENT
Simplify the code using the existing helpers instead of open coding the same functionality.
This commit is contained in:
parent
d24dbdd0a2
commit
65f3f9dd78
@ -133,17 +133,11 @@ qemuMonitorTestProcessCommandJSON(qemuMonitorTestPtr test,
|
|||||||
" { \"desc\": \"Unexpected command\", "
|
" { \"desc\": \"Unexpected command\", "
|
||||||
" \"class\": \"UnexpectedCommand\" } }");
|
" \"class\": \"UnexpectedCommand\" } }");
|
||||||
} else {
|
} else {
|
||||||
ret = qemuMonitorTestAddReponse(test,
|
ret = qemuMonitorTestAddReponse(test, test->items[0]->response);
|
||||||
test->items[0]->response);
|
|
||||||
qemuMonitorTestItemFree(test->items[0]);
|
qemuMonitorTestItemFree(test->items[0]);
|
||||||
if (test->nitems == 1) {
|
if (VIR_DELETE_ELEMENT(test->items, 0, test->nitems) < 0) {
|
||||||
VIR_FREE(test->items);
|
ret = -1;
|
||||||
test->nitems = 0;
|
goto cleanup;
|
||||||
} else {
|
|
||||||
memmove(test->items,
|
|
||||||
test->items + 1,
|
|
||||||
sizeof(test->items[0]) * (test->nitems - 1));
|
|
||||||
VIR_SHRINK_N(test->items, test->nitems, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,17 +169,11 @@ qemuMonitorTestProcessCommandText(qemuMonitorTestPtr test,
|
|||||||
ret = qemuMonitorTestAddReponse(test,
|
ret = qemuMonitorTestAddReponse(test,
|
||||||
"unexpected command");
|
"unexpected command");
|
||||||
} else {
|
} else {
|
||||||
ret = qemuMonitorTestAddReponse(test,
|
ret = qemuMonitorTestAddReponse(test, test->items[0]->response);
|
||||||
test->items[0]->response);
|
|
||||||
qemuMonitorTestItemFree(test->items[0]);
|
qemuMonitorTestItemFree(test->items[0]);
|
||||||
if (test->nitems == 1) {
|
if (VIR_DELETE_ELEMENT(test->items, 0, test->nitems) < 0) {
|
||||||
VIR_FREE(test->items);
|
ret = -1;
|
||||||
test->nitems = 0;
|
goto cleanup;
|
||||||
} else {
|
|
||||||
memmove(test->items,
|
|
||||||
test->items + 1,
|
|
||||||
sizeof(test->items[0]) * (test->nitems - 1));
|
|
||||||
VIR_SHRINK_N(test->items, test->nitems, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,12 +409,10 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
virMutexLock(&test->lock);
|
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);
|
virMutexUnlock(&test->lock);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
test->items[test->nitems - 1] = item;
|
|
||||||
|
|
||||||
virMutexUnlock(&test->lock);
|
virMutexUnlock(&test->lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user