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
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…
Add table
Add a link
Reference in a new issue