mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-02 04:15:46 +00:00
virbitmaptest: Turn 'TEST_MAP' macro into a helper function
The function will also be reusable in other places of the code by making the size check optional. For now only test12* is refactored since it used TEST_MAP directly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
7a1bc02be9
commit
0128fe1411
@ -26,6 +26,31 @@
|
|||||||
|
|
||||||
#include "virbitmap.h"
|
#include "virbitmap.h"
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
checkBitmap(virBitmapPtr map,
|
||||||
|
const char *expect,
|
||||||
|
ssize_t expectedSize)
|
||||||
|
{
|
||||||
|
g_autofree char *actual = virBitmapFormat(map);
|
||||||
|
|
||||||
|
if (expectedSize != -1 &&
|
||||||
|
virBitmapSize(map) != expectedSize) {
|
||||||
|
fprintf(stderr, "\n expected bitmap size: '%zd' actual size: "
|
||||||
|
"'%zu'\n", expectedSize, virBitmapSize(map));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (STRNEQ_NULLABLE(expect, actual)) {
|
||||||
|
fprintf(stderr, "\n expected bitmap contents '%s' actual contents "\
|
||||||
|
"'%s'\n", NULLSTR(expect), NULLSTR(actual));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test1(const void *data G_GNUC_UNUSED)
|
test1(const void *data G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
@ -630,25 +655,6 @@ test11(const void *opaque)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_MAP(sz, expect) \
|
|
||||||
do { \
|
|
||||||
char *actual; \
|
|
||||||
if (virBitmapSize(map) != sz) { \
|
|
||||||
fprintf(stderr, "\n expected bitmap size: '%d' actual size: " \
|
|
||||||
"'%zu'\n", sz, virBitmapSize(map)); \
|
|
||||||
goto cleanup; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
actual = virBitmapFormat(map); \
|
|
||||||
\
|
|
||||||
if (STRNEQ_NULLABLE(expect, actual)) { \
|
|
||||||
fprintf(stderr, "\n expected bitmap contents '%s' actual contents "\
|
|
||||||
"'%s'\n", NULLSTR(expect), NULLSTR(actual)); \
|
|
||||||
VIR_FREE(actual); \
|
|
||||||
goto cleanup; \
|
|
||||||
} \
|
|
||||||
VIR_FREE(actual); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/* test self-expanding bitmap APIs */
|
/* test self-expanding bitmap APIs */
|
||||||
static int
|
static int
|
||||||
@ -657,17 +663,20 @@ test12a(const void *opaque G_GNUC_UNUSED)
|
|||||||
virBitmapPtr map = virBitmapNewEmpty();
|
virBitmapPtr map = virBitmapNewEmpty();
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
TEST_MAP(0, "");
|
if (checkBitmap(map, "", 0) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (virBitmapSetBitExpand(map, 128) < 0)
|
if (virBitmapSetBitExpand(map, 128) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
TEST_MAP(129, "128");
|
if (checkBitmap(map, "128", 129) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (virBitmapClearBitExpand(map, 150) < 0)
|
if (virBitmapClearBitExpand(map, 150) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
TEST_MAP(151, "128");
|
if (checkBitmap(map, "128", 151) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
@ -686,13 +695,16 @@ test12b(const void *opaque G_GNUC_UNUSED)
|
|||||||
if (!(map = virBitmapParseUnlimited("34,1023")))
|
if (!(map = virBitmapParseUnlimited("34,1023")))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
TEST_MAP(1024, "34,1023");
|
if (checkBitmap(map, "34,1023", 1024) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
virBitmapShrink(map, 35);
|
virBitmapShrink(map, 35);
|
||||||
TEST_MAP(35, "34");
|
if (checkBitmap(map, "34", 35) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
virBitmapShrink(map, 34);
|
virBitmapShrink(map, 34);
|
||||||
TEST_MAP(34, "");
|
if (checkBitmap(map, "", 34) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
@ -729,7 +741,6 @@ test13(const void *opaque G_GNUC_UNUSED)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef TEST_MAP
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test14(const void *opaque)
|
test14(const void *opaque)
|
||||||
|
Loading…
Reference in New Issue
Block a user