core, click, tap-bridge: Fix clang-tidy readability-string-compare warnings

This commit is contained in:
Eduardo Almeida
2022-10-17 18:29:08 +01:00
parent 60e6e9cd25
commit 219d958ee4
3 changed files with 36 additions and 35 deletions

View File

@@ -28,6 +28,7 @@
#include "ns3/test.h"
#include <click/simclick.h>
#include <string>
using namespace ns3;
@@ -133,30 +134,30 @@ ClickIpMacAddressFromNameTest::DoRun()
char* buf = new char[255];
simclick_sim_command(click->m_simNode, SIMCLICK_IPADDR_FROM_NAME, "eth0", buf, 255);
NS_TEST_EXPECT_MSG_EQ(strcmp(buf, "10.1.1.1"), 0, "eth0 has IP 10.1.1.1");
NS_TEST_EXPECT_MSG_EQ(std::string(buf), "10.1.1.1", "eth0 has IP 10.1.1.1");
simclick_sim_command(click->m_simNode, SIMCLICK_MACADDR_FROM_NAME, "eth0", buf, 255);
NS_TEST_EXPECT_MSG_EQ(strcmp(buf, "00:00:00:00:00:01"),
0,
NS_TEST_EXPECT_MSG_EQ(std::string(buf),
"00:00:00:00:00:01",
"eth0 has Mac Address 00:00:00:00:00:01");
simclick_sim_command(click->m_simNode, SIMCLICK_IPADDR_FROM_NAME, "eth1", buf, 255);
NS_TEST_EXPECT_MSG_EQ(strcmp(buf, "10.1.1.2"), 0, "eth1 has IP 10.1.1.2");
NS_TEST_EXPECT_MSG_EQ(std::string(buf), "10.1.1.2", "eth1 has IP 10.1.1.2");
simclick_sim_command(click->m_simNode, SIMCLICK_MACADDR_FROM_NAME, "eth1", buf, 255);
NS_TEST_EXPECT_MSG_EQ(strcmp(buf, "00:00:00:00:00:02"),
0,
NS_TEST_EXPECT_MSG_EQ(std::string(buf),
"00:00:00:00:00:02",
"eth0 has Mac Address 00:00:00:00:00:02");
// Not sure how to test the below case, because the Ipv4ClickRouting code is to ASSERT for such
// inputs simclick_sim_command (click->m_simNode, SIMCLICK_IPADDR_FROM_NAME, "eth2", buf, 255);
// NS_TEST_EXPECT_MSG_EQ (buf, NULL, "No eth2");
// NS_TEST_EXPECT_MSG_EQ (buf, nullptr, "No eth2");
simclick_sim_command(click->m_simNode, SIMCLICK_IPADDR_FROM_NAME, "tap0", buf, 255);
NS_TEST_EXPECT_MSG_EQ(strcmp(buf, "127.0.0.1"), 0, "tun0 has IP 127.0.0.1");
NS_TEST_EXPECT_MSG_EQ(std::string(buf), "127.0.0.1", "tun0 has IP 127.0.0.1");
simclick_sim_command(click->m_simNode, SIMCLICK_MACADDR_FROM_NAME, "tap0", buf, 255);
NS_TEST_EXPECT_MSG_EQ(strcmp(buf, "00:00:00:00:00:00"), 0, "tun0 has IP 127.0.0.1");
NS_TEST_EXPECT_MSG_EQ(std::string(buf), "00:00:00:00:00:00", "tun0 has IP 127.0.0.1");
delete[] buf;
}
@@ -191,7 +192,7 @@ ClickTrivialTest::DoRun()
char* buf = new char[255];
ret = simclick_sim_command(click->m_simNode, SIMCLICK_GET_NODE_NAME, buf, 255);
NS_TEST_EXPECT_MSG_EQ(strcmp(buf, "myNode"), 0, "Node name is Node");
NS_TEST_EXPECT_MSG_EQ(std::string(buf), "myNode", "Node name is Node");
ret = simclick_sim_command(click->m_simNode, SIMCLICK_IF_READY, 0);
NS_TEST_EXPECT_MSG_EQ(ret, 1, "tap0 is ready");

View File

@@ -907,76 +907,76 @@ TestRunnerImpl::Run(int argc, char* argv[])
while (*argi != nullptr)
{
char* arg = *argi;
std::string arg = *argi;
if (strcmp(arg, "--assert-on-failure") == 0)
if (arg == "--assert-on-failure")
{
m_assertOnFailure = true;
}
else if (strcmp(arg, "--stop-on-failure") == 0)
else if (arg == "--stop-on-failure")
{
m_continueOnFailure = false;
}
else if (strcmp(arg, "--verbose") == 0)
else if (arg == "--verbose")
{
m_verbose = true;
}
else if (strcmp(arg, "--print-temp-dir") == 0)
else if (arg == "--print-temp-dir")
{
printTempDir = true;
}
else if (strcmp(arg, "--update-data") == 0)
else if (arg == "--update-data")
{
m_updateData = true;
}
else if (strcmp(arg, "--help") == 0)
else if (arg == "--help")
{
PrintHelp(progname);
return 0;
}
else if (strcmp(arg, "--print-test-name-list") == 0 || strcmp(arg, "--list") == 0)
else if (arg == "--print-test-name-list" || arg == "--list")
{
printTestNameList = true;
}
else if (strcmp(arg, "--print-test-types") == 0)
else if (arg == "--print-test-types")
{
printTestTypeAndName = true;
}
else if (strcmp(arg, "--print-test-type-list") == 0)
else if (arg == "--print-test-type-list")
{
printTestTypeList = true;
}
else if (strcmp(arg, "--append") == 0)
else if (arg == "--append")
{
append = true;
}
else if (strcmp(arg, "--xml") == 0)
else if (arg == "--xml")
{
xml = true;
}
else if (strncmp(arg, "--test-type=", strlen("--test-type=")) == 0)
else if (arg.find("--test-type=") != std::string::npos)
{
testTypeString = arg + strlen("--test-type=");
testTypeString = arg.substr(arg.find_first_of('=') + 1);
}
else if (strncmp(arg, "--test-name=", strlen("--test-name=")) == 0)
else if (arg.find("--test-name=") != std::string::npos)
{
testName = arg + strlen("--test-name=");
testName = arg.substr(arg.find_first_of('=') + 1);
}
else if (strncmp(arg, "--suite=", strlen("--suite=")) == 0)
else if (arg.find("--suite=") != std::string::npos)
{
testName = arg + strlen("--suite=");
testName = arg.substr(arg.find_first_of('=') + 1);
}
else if (strncmp(arg, "--tempdir=", strlen("--tempdir=")) == 0)
else if (arg.find("--tempdir=") != std::string::npos)
{
m_tempDir = arg + strlen("--tempdir=");
m_tempDir = arg.substr(arg.find_first_of('=') + 1);
}
else if (strncmp(arg, "--out=", strlen("--out=")) == 0)
else if (arg.find("--out=") != std::string::npos)
{
out = arg + strlen("--out=");
out = arg.substr(arg.find_first_of('=') + 1);
}
else if (strncmp(arg, "--fullness=", strlen("--fullness=")) == 0)
else if (arg.find("--fullness=") != std::string::npos)
{
fullness = arg + strlen("--fullness=");
fullness = arg.substr(arg.find_first_of('=') + 1);
// Set the maximum test length allowed.
if (fullness == "QUICK")

View File

@@ -316,7 +316,7 @@ CreateTap(const char* dev,
// configured a network tap that we are just going to use. So don't mess
// up his hard work by changing anything, just return the tap fd.
//
if (strcmp(mode, "2") == 0 || strcmp(mode, "3") == 0)
if (std::string(mode) == "2" || std::string(mode) == "3")
{
LOG("Returning precreated tap ");
return tap;