diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2018-04-19 11:59:12 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2018-04-19 12:11:09 +0200 |
commit | bc4e9c7bcfd7d7b3f62b23e583ef216a05975e80 (patch) | |
tree | 6fdeea27d6b55e713554216b00b6922d3451a504 | |
parent | 5b36f06f49c88fb1921da18f54524081729cb4d5 (diff) | |
download | libnitrokey-bc4e9c7bcfd7d7b3f62b23e583ef216a05975e80.tar.gz libnitrokey-bc4e9c7bcfd7d7b3f62b23e583ef216a05975e80.tar.bz2 |
Fix compilation warnings for tests
Cleanup CMakeList a bit as well.
Fixes #97
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r-- | CMakeLists.txt | 44 | ||||
-rw-r--r-- | unittest/test1.cc (renamed from unittest/test.cc) | 0 | ||||
-rw-r--r-- | unittest/test_C_API.cpp | 2 | ||||
-rw-r--r-- | unittest/test_HOTP.cc | 2 | ||||
-rw-r--r-- | unittest/test_offline.cc | 2 |
5 files changed, 24 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 073e7fd..06fcfac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ set_target_properties(nitrokey PROPERTIES OPTION(ERROR_ON_WARNING "Stop compilation on warning found (not supported for MSVC)" OFF) if (NOT MSVC) - set(COMPILE_FLAGS "-Wall -Wno-unused-function -Wcast-qual -Woverloaded-virtual") + set(COMPILE_FLAGS "-Wall -Wno-unused-function -Wcast-qual -Woverloaded-virtual -Wsign-compare -Wformat -Wformat-security") IF(NOT APPLE) if (ERROR_ON_WARNING) set(COMPILE_FLAGS "${COMPILE_FLAGS} -Werror") @@ -167,34 +167,32 @@ ENDIF() IF(COMPILE_OFFLINE_TESTS) add_executable (test_offline unittest/test_offline.cc) target_link_libraries (test_offline ${EXTRA_LIBS} nitrokey catch) + SET_TARGET_PROPERTIES(test_offline PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} ) #run with 'make test' or 'ctest' include (CTest) add_test (runs test_offline) ENDIF() IF (COMPILE_TESTS) - #needs connected PRO device for success - #warning: it may delete data on the device - add_executable (test_C_API unittest/test_C_API.cpp) - target_link_libraries (test_C_API ${EXTRA_LIBS} nitrokey catch) - - add_executable (test2 unittest/test2.cc) - target_link_libraries (test2 ${EXTRA_LIBS} nitrokey catch) - - add_executable (test3 unittest/test3.cc) - target_link_libraries (test3 ${EXTRA_LIBS} nitrokey catch) - - add_executable (test_HOTP unittest/test_HOTP.cc) - target_link_libraries (test_HOTP ${EXTRA_LIBS} nitrokey catch) - - add_executable (test1 unittest/test.cc) - target_link_libraries (test1 ${EXTRA_LIBS} nitrokey catch) - - add_executable (test_issues unittest/test_issues.cc) - target_link_libraries (test_issues ${EXTRA_LIBS} nitrokey catch) - - add_executable (test_multiple_devices unittest/test_multiple_devices.cc) - target_link_libraries (test_multiple_devices ${EXTRA_LIBS} nitrokey catch) + #needs connected Pro/Storage devices for success + #WARNING: it may delete data on the device + + SET(TESTS + unittest/test_C_API.cpp + unittest/test2.cc + unittest/test3.cc + unittest/test_HOTP.cc + unittest/test1.cc + unittest/test_issues.cc + unittest/test_multiple_devices.cc + ) + + foreach(testsourcefile ${TESTS} ) + get_filename_component(testname ${testsourcefile} NAME_WE ) + add_executable(${testname} ${testsourcefile} ) + target_link_libraries(${testname} ${EXTRA_LIBS} nitrokey catch ) + SET_TARGET_PROPERTIES(${testname} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} ) + endforeach(testsourcefile) ENDIF() diff --git a/unittest/test.cc b/unittest/test1.cc index 51a2ef6..51a2ef6 100644 --- a/unittest/test.cc +++ b/unittest/test1.cc diff --git a/unittest/test_C_API.cpp b/unittest/test_C_API.cpp index 2d83ef4..acfadd2 100644 --- a/unittest/test_C_API.cpp +++ b/unittest/test_C_API.cpp @@ -74,7 +74,7 @@ TEST_CASE("multiple devices with ID", "[BASIC]") { int t; string = strndup(s, 4096); - free ( (void*) s); + free (static_cast<void*>(const_cast<char*>(s))); while ((token = strsep(&string, ";")) != nullptr){ if (strnlen(token, 4096) < 3) continue; diff --git a/unittest/test_HOTP.cc b/unittest/test_HOTP.cc index c13fb8e..b11cf25 100644 --- a/unittest/test_HOTP.cc +++ b/unittest/test_HOTP.cc @@ -38,7 +38,7 @@ void hexStringToByte(uint8_t data[], const char* hexString){ REQUIRE(strlen(hexString)%2==0); char buf[3]; buf[2] = '\0'; - for(int i=0; i<strlen(hexString); i++){ + for(size_t i=0; i<strlen(hexString); i++){ buf[i%2] = hexString[i]; if (i%2==1){ data[i/2] = strtoul(buf, NULL, 16) & 0xFF; diff --git a/unittest/test_offline.cc b/unittest/test_offline.cc index 3ef63d2..468849e 100644 --- a/unittest/test_offline.cc +++ b/unittest/test_offline.cc @@ -113,7 +113,7 @@ TEST_CASE("Test helper function - hex_string_to_byte", "[fast]") { REQUIRE_NOTHROW(v = hex_string_to_byte("00112233445566")); const uint8_t test_data[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; REQUIRE(v.size() == sizeof(test_data)); - for (int i = 0; i < v.size(); ++i) { + for (size_t i = 0; i < v.size(); ++i) { INFO("Position i: " << i); REQUIRE(v[i] == test_data[i]); } |