mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-17 23:37:14 +02:00
added string_utils and strcpy_safe
This commit is contained in:
@ -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
|
||||
|
34
tests/src/test-string_utils.cpp
Normal file
34
tests/src/test-string_utils.cpp
Normal 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');
|
||||
}
|
Reference in New Issue
Block a user