mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
tests: Use virTestCompareToString() more
Instead of using: if (STRNEQ(a, b)) { virTestDifference(stderr, a, b); ... } we can use: if (virTestCompareToString(a, b) < ) { ... } Generated by the following spatch: @@ expression a, b; @@ - if (STRNEQ(a, b)) { + if (virTestCompareToString(a, b) < 0) { ... - virTestDifference(stderr, a, b); ... } and its variations (STRNEQ_NULLABLE() instead of STRNEQ(), then in some cases variables passed to STRNEQ() are in reversed order when compared to virTestCompareToString()). However, coccinelle failed to recognize the pattern in testNWFilterEBIPTablesAllTeardown() so I had to fix it manually. Also, I manually fixed testFormat() in tests/sockettest.c as I didn't bother writing another spatch rule just for that. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
parent
1fffd1605d
commit
a156b69c35
@ -436,8 +436,7 @@ static int test13(const void *unused G_GNUC_UNUSED)
|
||||
|
||||
g_clear_pointer(&cmd, virCommandFree);
|
||||
|
||||
if (STRNEQ(outactual, outexpect)) {
|
||||
virTestDifference(stderr, outexpect, outactual);
|
||||
if (virTestCompareToString(outexpect, outactual) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -497,16 +496,13 @@ static int test14(const void *unused G_GNUC_UNUSED)
|
||||
if (!jointactual)
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(outactual, outexpect)) {
|
||||
virTestDifference(stderr, outexpect, outactual);
|
||||
if (virTestCompareToString(outexpect, outactual) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (STRNEQ(erractual, errexpect)) {
|
||||
virTestDifference(stderr, errexpect, erractual);
|
||||
if (virTestCompareToString(errexpect, erractual) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (STRNEQ(jointactual, jointexpect)) {
|
||||
virTestDifference(stderr, jointexpect, jointactual);
|
||||
if (virTestCompareToString(jointexpect, jointactual) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -569,8 +565,7 @@ static int test16(const void *unused G_GNUC_UNUSED)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ(outactual, outexpect)) {
|
||||
virTestDifference(stderr, outexpect, outactual);
|
||||
if (virTestCompareToString(outexpect, outactual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -774,13 +769,11 @@ static int test21(const void *unused G_GNUC_UNUSED)
|
||||
if (virTestGetVerbose())
|
||||
printf("STDOUT:%s\nSTDERR:%s\n", NULLSTR(outbuf), NULLSTR(errbuf));
|
||||
|
||||
if (STRNEQ_NULLABLE(outbuf, outbufExpected)) {
|
||||
virTestDifference(stderr, outbufExpected, outbuf);
|
||||
if (virTestCompareToString(outbufExpected, outbuf) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(errbuf, errbufExpected)) {
|
||||
virTestDifference(stderr, errbufExpected, errbuf);
|
||||
if (virTestCompareToString(errbufExpected, errbuf) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1016,8 +1009,7 @@ static int test26(const void *unused G_GNUC_UNUSED)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ(outactual, outexpect)) {
|
||||
virTestDifference(stderr, outexpect, outactual);
|
||||
if (virTestCompareToString(outexpect, outactual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1086,12 +1078,10 @@ static int test27(const void *unused G_GNUC_UNUSED)
|
||||
if (!outactual || !erractual)
|
||||
return -1;
|
||||
|
||||
if (STRNEQ(outactual, outexpect)) {
|
||||
virTestDifference(stderr, outexpect, outactual);
|
||||
if (virTestCompareToString(outexpect, outactual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (STRNEQ(erractual, errexpect)) {
|
||||
virTestDifference(stderr, errexpect, erractual);
|
||||
if (virTestCompareToString(errexpect, erractual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1225,8 +1215,7 @@ test29(const void *unused G_GNUC_UNUSED)
|
||||
}
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(outactual, outexpect)) {
|
||||
virTestDifference(stderr, outexpect, outactual);
|
||||
if (virTestCompareToString(outexpect, outactual) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -50,19 +50,15 @@ testParseDatastorePath(const void *data G_GNUC_UNUSED)
|
||||
if (paths[i].result < 0)
|
||||
continue;
|
||||
|
||||
if (STRNEQ(paths[i].datastoreName, datastoreName)) {
|
||||
virTestDifference(stderr, paths[i].datastoreName, datastoreName);
|
||||
if (virTestCompareToString(paths[i].datastoreName, datastoreName) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ(paths[i].directoryName, directoryName)) {
|
||||
virTestDifference(stderr, paths[i].directoryName, directoryName);
|
||||
if (virTestCompareToString(paths[i].directoryName, directoryName) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ(paths[i].directoryAndFileName, directoryAndFileName)) {
|
||||
virTestDifference(stderr, paths[i].directoryAndFileName,
|
||||
directoryAndFileName);
|
||||
if (virTestCompareToString(paths[i].directoryAndFileName, directoryAndFileName) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -107,8 +107,7 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferContentAndReset(&buf);
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, expected)) {
|
||||
virTestDifference(stderr, expected, actual);
|
||||
if (virTestCompareToString(actual, expected) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -169,8 +168,7 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferContentAndReset(&buf);
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, expected)) {
|
||||
virTestDifference(stderr, expected, actual);
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -209,8 +207,7 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferContentAndReset(&buf);
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, expected)) {
|
||||
virTestDifference(stderr, expected, actual);
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -234,8 +231,7 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferContentAndReset(&buf);
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, expected)) {
|
||||
virTestDifference(stderr, expected, actual);
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -297,8 +293,7 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferContentAndReset(&buf);
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, expected)) {
|
||||
virTestDifference(stderr, expected, actual);
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -378,8 +373,7 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferContentAndReset(&buf);
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, expected)) {
|
||||
virTestDifference(stderr, expected, actual);
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -442,8 +436,7 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferContentAndReset(&buf);
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, expected)) {
|
||||
virTestDifference(stderr, expected, actual);
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,7 @@ testReadConfigParam(const void *data G_GNUC_UNUSED)
|
||||
if (configParams[i].ret != 1)
|
||||
continue;
|
||||
|
||||
if (STRNEQ(configParams[i].value, value)) {
|
||||
virTestDifference(stderr, configParams[i].value, value);
|
||||
if (virTestCompareToString(configParams[i].value, value) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -114,8 +113,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (STRNEQ(expected, actual)) {
|
||||
virTestDifference(stderr, expected, actual);
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -48,8 +48,7 @@ static int testFormat(virSocketAddr *addr, const char *addrstr, bool pass)
|
||||
if (!newaddrstr)
|
||||
return pass ? -1 : 0;
|
||||
|
||||
if (STRNEQ(newaddrstr, addrstr)) {
|
||||
virTestDifference(stderr, addrstr, newaddrstr);
|
||||
if (virTestCompareToString(newaddrstr, addrstr) < 0) {
|
||||
return pass ? -1 : 0;
|
||||
} else {
|
||||
return pass ? 0 : -1;
|
||||
|
@ -47,8 +47,7 @@ testIndexToDiskName(const void *data G_GNUC_UNUSED)
|
||||
|
||||
diskName = virIndexToDiskName(i, "sd");
|
||||
|
||||
if (STRNEQ(diskNames[i], diskName)) {
|
||||
virTestDifference(stderr, diskNames[i], diskName);
|
||||
if (virTestCompareToString(diskNames[i], diskName) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +69,7 @@ testCompareXMLtoXMLFiles(const char *xml)
|
||||
if (!(xmlData = testFilterXML(xmlData)))
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(actual, xmlData)) {
|
||||
virTestDifference(stderr, xmlData, actual);
|
||||
if (virTestCompareToString(xmlData, actual) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED)
|
||||
virBufferAddChar(buf, '\n');
|
||||
|
||||
result = virBufferContentAndReset(buf);
|
||||
if (STRNEQ_NULLABLE(result, expected)) {
|
||||
virTestDifference(stderr, expected, result);
|
||||
if (virTestCompareToString(expected, result) < 0) {
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
@ -122,8 +121,7 @@ static int testBufTrim(const void *data G_GNUC_UNUSED)
|
||||
virBufferTrim(buf, ",,");
|
||||
|
||||
result = virBufferContentAndReset(buf);
|
||||
if (STRNEQ_NULLABLE(result, expected)) {
|
||||
virTestDifference(stderr, expected, result);
|
||||
if (virTestCompareToString(expected, result) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -145,8 +143,7 @@ testBufTrimChars(const void *opaque)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, data->expect)) {
|
||||
virTestDifference(stderr, data->expect, actual);
|
||||
if (virTestCompareToString(data->expect, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -250,8 +247,7 @@ static int testBufAddBuffer(const void *data G_GNUC_UNUSED)
|
||||
}
|
||||
|
||||
result = virBufferContentAndReset(&buf1);
|
||||
if (STRNEQ_NULLABLE(result, expected)) {
|
||||
virTestDifference(stderr, expected, result);
|
||||
if (virTestCompareToString(expected, result) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -276,8 +272,7 @@ testBufAddStr(const void *opaque)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, data->expect)) {
|
||||
virTestDifference(stderr, data->expect, actual);
|
||||
if (virTestCompareToString(data->expect, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -303,8 +298,7 @@ testBufEscapeStr(const void *opaque)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, data->expect)) {
|
||||
virTestDifference(stderr, data->expect, actual);
|
||||
if (virTestCompareToString(data->expect, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -326,8 +320,7 @@ testBufEscapeRegex(const void *opaque)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(actual, data->expect)) {
|
||||
virTestDifference(stderr, data->expect, actual);
|
||||
if (virTestCompareToString(data->expect, actual) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,8 @@ testFirewallSingleGroup(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -136,9 +135,8 @@ testFirewallRemoveRule(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -190,9 +188,8 @@ testFirewallManyGroups(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -265,9 +262,8 @@ testFirewallIgnoreFailGroup(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -318,9 +314,8 @@ testFirewallIgnoreFailRule(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -365,9 +360,8 @@ testFirewallNoRollback(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -431,9 +425,8 @@ testFirewallSingleRollback(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -500,9 +493,8 @@ testFirewallManyRollback(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -599,9 +591,8 @@ testFirewallChainedRollback(const void *opaque G_GNUC_UNUSED)
|
||||
|
||||
actual = virBufferCurrentContent(&cmdbuf);
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -763,9 +754,8 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(expected, actual)) {
|
||||
if (virTestCompareToString(expected, actual) < 0) {
|
||||
fprintf(stderr, "Unexpected command execution\n");
|
||||
virTestDifference(stderr, expected, actual);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -93,8 +93,7 @@ testJSONFromString(const void *data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ(expectstr, formatted)) {
|
||||
virTestDifference(stderr, expectstr, formatted);
|
||||
if (virTestCompareToString(expectstr, formatted) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -424,8 +423,7 @@ testJSONEscapeObj(const void *data G_GNUC_UNUSED)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ(parsednestedstr, neststr)) {
|
||||
virTestDifference(stderr, neststr, parsednestedstr);
|
||||
if (virTestCompareToString(neststr, parsednestedstr) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,7 @@ checkOutput(virBuffer *buf, const char *exp_cmd)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (STRNEQ(exp_cmd, actual_cmd)) {
|
||||
virTestDifference(stderr, exp_cmd, actual_cmd);
|
||||
if (virTestCompareToString(exp_cmd, actual_cmd) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,7 @@ testVirNetDevBandwidthSet(const void *data)
|
||||
* Maybe that's expected, actually. */
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(exp_cmd, actual_cmd)) {
|
||||
virTestDifference(stderr, exp_cmd, actual_cmd);
|
||||
if (virTestCompareToString(exp_cmd, actual_cmd) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -175,8 +175,7 @@ testVirNetDevOpenvswitchInterfaceSetQos(const void *data)
|
||||
* Maybe that's expected, actually. */
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(info->exp_cmd, actual_cmd)) {
|
||||
virTestDifference(stderr, info->exp_cmd, actual_cmd);
|
||||
if (virTestCompareToString(info->exp_cmd, actual_cmd) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -204,8 +203,7 @@ testVirNetDevOpenvswitchInterfaceClearQos(const void *data)
|
||||
* Maybe that's expected, actually. */
|
||||
}
|
||||
|
||||
if (STRNEQ_NULLABLE(info->exp_cmd, actual_cmd)) {
|
||||
virTestDifference(stderr, info->exp_cmd, actual_cmd);
|
||||
if (virTestCompareToString(info->exp_cmd, actual_cmd) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -488,8 +488,7 @@ static int testSocketSSH(const void *opaque)
|
||||
}
|
||||
buf[rv] = '\0';
|
||||
|
||||
if (STRNEQ(buf, data->expectOut)) {
|
||||
virTestDifference(stderr, data->expectOut, buf);
|
||||
if (virTestCompareToString(data->expectOut, buf) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -134,8 +134,7 @@ testCompareOutputLit(const char *expectData,
|
||||
if (filter && testFilterLine(actualData, filter) < 0)
|
||||
return -1;
|
||||
|
||||
if (STRNEQ(expectData, actualData)) {
|
||||
virTestDifference(stderr, expectData, actualData);
|
||||
if (virTestCompareToString(expectData, actualData) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user