From b782ebd53c818847266e6aeb57d3e6c01e9479ee Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 12 Apr 2017 13:54:55 +0100 Subject: [PATCH] Add unit test for lexical_cast (broken) --- .gitmodules | 3 +++ CMakeLists.txt | 6 +++++ lib/Catch | 1 + test/unit/CMakeLists.txt | 22 +++++++++++++++++ test/unit/lexical_cast_test.cpp | 43 +++++++++++++++++++++++++++++++++ test/unit/main.cpp | 19 +++++++++++++++ 6 files changed, 94 insertions(+) create mode 160000 lib/Catch create mode 100644 test/unit/CMakeLists.txt create mode 100644 test/unit/lexical_cast_test.cpp create mode 100644 test/unit/main.cpp diff --git a/.gitmodules b/.gitmodules index 1a4c488..20ce5e1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index d7610e7..390e65e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/lib/Catch b/lib/Catch new file mode 160000 index 0000000..ac369b7 --- /dev/null +++ b/lib/Catch @@ -0,0 +1 @@ +Subproject commit ac369b7b8362de7ccc9c3f46e4f0c59115ecadcc diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt new file mode 100644 index 0000000..98e12db --- /dev/null +++ b/test/unit/CMakeLists.txt @@ -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} +) diff --git a/test/unit/lexical_cast_test.cpp b/test/unit/lexical_cast_test.cpp new file mode 100644 index 0000000..a24370c --- /dev/null +++ b/test/unit/lexical_cast_test.cpp @@ -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 . + */ + +#include "catch.hpp" +#include "duckhandy/lexical_cast.hpp" +#include +#include + +TEST_CASE ("Check string to int conversions", "[s2i][lexical_cast]") { + using dhandy::lexical_cast; + + CHECK(lexical_cast(std::string("0")) == 0); + CHECK(lexical_cast(std::string("1")) == 1); + CHECK(lexical_cast(std::string("9")) == 9); + CHECK(lexical_cast(std::string("10")) == 10); + CHECK(lexical_cast(std::string("11")) == 11); + CHECK(lexical_cast(std::string("99")) == 99); + CHECK(lexical_cast(std::string("512")) == 512); + CHECK(lexical_cast(std::string("513")) == 513); + CHECK(lexical_cast(std::string("15000")) == 15000); + + CHECK(lexical_cast(std::string("-1")) == -1); + CHECK(lexical_cast(std::string("-2")) == -2); + CHECK(lexical_cast(std::string("-10")) == -10); + CHECK(lexical_cast(std::string("-100000")) == -100000); +} + +TEST_CASE ("Check int to string conversions", "[i2s][lexical_cast]") { +} diff --git a/test/unit/main.cpp b/test/unit/main.cpp new file mode 100644 index 0000000..d3bb9b6 --- /dev/null +++ b/test/unit/main.cpp @@ -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 . + */ + +#define CATCH_CONFIG_MAIN +#include "catch.hpp"