Add unit test for lexical_cast (broken)
This commit is contained in:
parent
9587e0e7a1
commit
b782ebd53c
6 changed files with 94 additions and 0 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
|||
[submodule "lib/sprout"]
|
||||
path = lib/sprout
|
||||
url = ../../bolero-MURAKAMI/Sprout.git
|
||||
[submodule "lib/Catch"]
|
||||
path = lib/Catch
|
||||
url = https://github.com/philsquared/Catch.git
|
||||
|
|
|
@ -3,6 +3,9 @@ project(duckhandy)
|
|||
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
|
||||
|
||||
include(shared_git_project)
|
||||
include(CTest)
|
||||
|
||||
set(DUCKHANDY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
|
||||
|
@ -23,3 +26,6 @@ target_include_directories(${PROJECT_NAME}
|
|||
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/lib/sprout
|
||||
)
|
||||
if (BUILD_TESTING)
|
||||
add_subdirectory(test/unit)
|
||||
endif()
|
||||
|
|
1
lib/Catch
Submodule
1
lib/Catch
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit ac369b7b8362de7ccc9c3f46e4f0c59115ecadcc
|
22
test/unit/CMakeLists.txt
Normal file
22
test/unit/CMakeLists.txt
Normal file
|
@ -0,0 +1,22 @@
|
|||
project(dhandy_unit_test CXX)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
lexical_cast_test.cpp
|
||||
)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE ${DUCKHANDY_SOURCE_DIR}/lib/Catch/single_include
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE duckhandy
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME DuckHandyTest
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${PROJECT_NAME}
|
||||
)
|
43
test/unit/lexical_cast_test.cpp
Normal file
43
test/unit/lexical_cast_test.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* Copyright 2017, Michele Santullo
|
||||
* This file is part of "duckhandy".
|
||||
*
|
||||
* "duckhandy" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "duckhandy" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "duckhandy". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "duckhandy/lexical_cast.hpp"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE ("Check string to int conversions", "[s2i][lexical_cast]") {
|
||||
using dhandy::lexical_cast;
|
||||
|
||||
CHECK(lexical_cast<uint16_t>(std::string("0")) == 0);
|
||||
CHECK(lexical_cast<uint16_t>(std::string("1")) == 1);
|
||||
CHECK(lexical_cast<uint16_t>(std::string("9")) == 9);
|
||||
CHECK(lexical_cast<uint16_t>(std::string("10")) == 10);
|
||||
CHECK(lexical_cast<uint16_t>(std::string("11")) == 11);
|
||||
CHECK(lexical_cast<uint16_t>(std::string("99")) == 99);
|
||||
CHECK(lexical_cast<uint16_t>(std::string("512")) == 512);
|
||||
CHECK(lexical_cast<uint16_t>(std::string("513")) == 513);
|
||||
CHECK(lexical_cast<uint16_t>(std::string("15000")) == 15000);
|
||||
|
||||
CHECK(lexical_cast<uint32_t>(std::string("-1")) == -1);
|
||||
CHECK(lexical_cast<uint32_t>(std::string("-2")) == -2);
|
||||
CHECK(lexical_cast<uint32_t>(std::string("-10")) == -10);
|
||||
CHECK(lexical_cast<uint32_t>(std::string("-100000")) == -100000);
|
||||
}
|
||||
|
||||
TEST_CASE ("Check int to string conversions", "[i2s][lexical_cast]") {
|
||||
}
|
19
test/unit/main.cpp
Normal file
19
test/unit/main.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* Copyright 2017, Michele Santullo
|
||||
* This file is part of "duckhandy".
|
||||
*
|
||||
* "duckhandy" is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* "duckhandy" is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with "duckhandy". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
Loading…
Reference in a new issue