This commit is contained in:
Erik Frojdh
2019-04-02 17:00:00 +02:00
parent 45fd35b243
commit 24f28f14f4
5 changed files with 53 additions and 149 deletions

View File

@ -7,19 +7,7 @@
#include "string_utils.h"
using namespace sls;
TEST_CASE("Convert mac address") {
std::vector<uint64_t> vec_addr{346856806822, 346856806852, 262027939863028};
std::vector<std::string> vec_ans{"00:50:c2:46:d9:a6", "00:50:c2:46:d9:c4", "ee:50:22:46:d9:f4"};
for (int i = 0; i != vec_addr.size(); ++i) {
auto mac = vec_addr[i];
auto answer = vec_ans[i];
std::string string_addr = MacAddrToString(mac);
CHECK(string_addr == answer);
CHECK(MacStringToUint(string_addr) == mac);
}
}
TEST_CASE("Convert mac address using classes") {
@ -38,19 +26,6 @@ TEST_CASE("Convert mac address using classes") {
}
}
TEST_CASE("Convert IP") {
std::vector<uint32_t> vec_addr{4073554305, 2747957633, 2697625985};
std::vector<std::string> vec_ans{"129.129.205.242", "129.129.202.163", "129.129.202.160"};
for (int i = 0; i != vec_addr.size(); ++i) {
auto ip = vec_addr[i];
auto answer = vec_ans[i];
auto string_addr = IpToString(ip);
CHECK(string_addr == answer);
CHECK(IpStringToUint(string_addr.c_str()) == ip);
}
}
TEST_CASE("Convert IP using classes ") {
std::vector<uint32_t> vec_addr{4073554305, 2747957633, 2697625985};
@ -70,19 +45,7 @@ TEST_CASE("Convert IP using classes ") {
}
}
TEST_CASE("IP not valid") {
CHECK(IpStringToUint("hej") == 0);
CHECK(IpStringToUint("mpc2408") == 0);
}
TEST_CASE("Convert ip to hex") {
std::vector<std::string> ipstrings{"74.125.43.99", "129.129.202.217"};
std::vector<std::string> vec_ans{"4a7d2b63", "8181cad9"};
for (int i = 0; i != ipstrings.size(); ++i) {
uint32_t ip = IpStringToUint(ipstrings[i].c_str());
CHECK(IpToHexString(ip) == vec_ans[i]);
}
}
// TEST_CASE("Lookup ip")
TEST_CASE("Strange input gives 0"){
CHECK(IpAddr("hej")== 0);
CHECK(MacAddr("hej")== 0);
}

View File

@ -1,6 +1,5 @@
#include "MySocketTCP.h"
#include "catch.hpp"
// #include "multiSlsDetector.h"
#include "logger.h"
#include <iostream>
#include <vector>
@ -23,6 +22,9 @@ TEST_CASE("copy a string") {
}
#ifdef NDEBUG
//This test can only run in release since we assert on the length of the string
TEST_CASE("copy a long string"){
auto src = "some very very long sting that does not fit";
char dst[3];
@ -32,7 +34,7 @@ TEST_CASE("copy a long string"){
REQUIRE(dst[2]=='\0');
}
#endif
TEST_CASE("Concat") {
std::vector<std::string> v{"one", "one", "one"};
std::vector<std::string> v2{"one", "one", "one"};