added string_utils and strcpy_safe

This commit is contained in:
Erik Frojdh
2018-12-19 15:44:21 +01:00
parent 89d9204e1c
commit 1ca8bf204a
7 changed files with 74 additions and 10 deletions

View File

@ -16,7 +16,9 @@ if(USE_TESTS)
set(LOCAL_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(TEST_SOURCES
${LOCAL_TEST_DIR}/test-container_utils.cpp
${LOCAL_TEST_DIR}/test-string_utils.cpp
${LOCAL_TEST_DIR}/test-MySocketTCP.cpp
#${LOCAL_TEST_DIR}/test-multiDetector.cpp
${LOCAL_TEST_DIR}/test.cpp
# PARENT_SCOPE

View File

@ -0,0 +1,34 @@
#include "MySocketTCP.h"
#include "catch.hpp"
// #include "multiSlsDetector.h"
#include "logger.h"
#include <iostream>
#include <vector>
#include "string_utils.h"
#define VERBOSE
TEST_CASE("copy a string") {
char src[10] = "hej";
REQUIRE(src[3]=='\0');
char dst[20];
sls::strcpy_safe(dst, src);
REQUIRE(dst[0]=='h');
REQUIRE(dst[1]=='e');
REQUIRE(dst[2]=='j');
REQUIRE(dst[3]=='\0');
}
TEST_CASE("copy a long string"){
auto src = "some very very long sting that does not fit";
char dst[3];
sls::strcpy_safe(dst, src);
REQUIRE(dst[0]=='s');
REQUIRE(dst[1]=='o');
REQUIRE(dst[3]=='\0');
}