tests: delete tests for VIR_STR(N)DUP

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2019-10-25 00:12:49 +02:00
parent 93de3025b4
commit ca4c90b435

View File

@ -233,136 +233,6 @@ static int testRemove(const void *args)
}
static bool fail;
static const char *
testStrdupLookup1(size_t i)
{
switch (i) {
case 0:
return "hello";
case 1:
return NULL;
default:
fail = true;
return "oops";
}
}
static size_t
testStrdupLookup2(size_t i)
{
if (i)
fail = true;
return 5;
}
static int
testStrdup(const void *data G_GNUC_UNUSED)
{
char *array[] = { NULL, NULL };
size_t i = 0;
size_t j = 0;
size_t k = 0;
int ret = -1;
int value;
value = VIR_STRDUP(array[i++], testStrdupLookup1(j++));
if (value != 1) {
virFilePrintf(stderr, "unexpected strdup result %d, expected 1\n", value);
goto cleanup;
}
/* coverity[dead_error_begin] */
if (i != 1) {
virFilePrintf(stderr, "unexpected side effects i=%zu, expected 1\n", i);
goto cleanup;
}
/* coverity[dead_error_begin] */
if (j != 1) {
virFilePrintf(stderr, "unexpected side effects j=%zu, expected 1\n", j);
goto cleanup;
}
if (STRNEQ_NULLABLE(array[0], "hello") || array[1]) {
virFilePrintf(stderr, "incorrect array contents '%s' '%s'\n",
NULLSTR(array[0]), NULLSTR(array[1]));
goto cleanup;
}
value = VIR_STRNDUP(array[i++], testStrdupLookup1(j++),
testStrdupLookup2(k++));
if (value != 0) {
virFilePrintf(stderr, "unexpected strdup result %d, expected 0\n", value);
goto cleanup;
}
/* coverity[dead_error_begin] */
if (i != 2) {
virFilePrintf(stderr, "unexpected side effects i=%zu, expected 2\n", i);
goto cleanup;
}
/* coverity[dead_error_begin] */
if (j != 2) {
virFilePrintf(stderr, "unexpected side effects j=%zu, expected 2\n", j);
goto cleanup;
}
/* coverity[dead_error_begin] */
if (k != 1) {
virFilePrintf(stderr, "unexpected side effects k=%zu, expected 1\n", k);
goto cleanup;
}
if (STRNEQ_NULLABLE(array[0], "hello") || array[1]) {
virFilePrintf(stderr, "incorrect array contents '%s' '%s'\n",
NULLSTR(array[0]), NULLSTR(array[1]));
goto cleanup;
}
if (fail) {
virFilePrintf(stderr, "side effects failed\n");
goto cleanup;
}
ret = 0;
cleanup:
for (i = 0; i < G_N_ELEMENTS(array); i++)
VIR_FREE(array[i]);
return ret;
}
static int
testStrndupNegative(const void *opaque G_GNUC_UNUSED)
{
int ret = -1;
char *dst;
const char *src = "Hello world";
int value;
if ((value = VIR_STRNDUP(dst, src, 5)) != 1) {
fprintf(stderr, "unexpected virStrndup result %d, expected 1\n", value);
goto cleanup;
}
if (STRNEQ_NULLABLE(dst, "Hello")) {
fprintf(stderr, "unexpected content '%s'", dst);
goto cleanup;
}
VIR_FREE(dst);
if ((value = VIR_STRNDUP(dst, src, -1)) != 1) {
fprintf(stderr, "unexpected virStrndup result %d, expected 1\n", value);
goto cleanup;
}
if (STRNEQ_NULLABLE(dst, src)) {
fprintf(stderr, "unexpected content '%s'", dst);
goto cleanup;
}
ret = 0;
cleanup:
VIR_FREE(dst);
return ret;
}
static int
testStringSortCompare(const void *opaque G_GNUC_UNUSED)
{
@ -847,12 +717,6 @@ mymain(void)
const char *tokens8[] = { "gluster", "rdma", NULL };
TEST_SPLIT("gluster+rdma", "+", 2, tokens8);
if (virTestRun("strdup", testStrdup, NULL) < 0)
ret = -1;
if (virTestRun("strdup", testStrndupNegative, NULL) < 0)
ret = -1;
if (virTestRun("virStringSortCompare", testStringSortCompare, NULL) < 0)
ret = -1;