From 6c4e020bb5ddcfa681e016f1a2f412c6f9b3d308 Mon Sep 17 00:00:00 2001 From: Jens Luedicke Date: Sat, 22 Jan 2011 22:21:49 +0100 Subject: [PATCH] Spit unit tests. --- unittest/{unittest.cpp => AttributesTest.cpp} | 11 ----- unittest/CMakeLists.txt | 10 +++-- unittest/String2typeTest.cpp | 41 +++++++++++++++++++ 3 files changed, 47 insertions(+), 15 deletions(-) rename unittest/{unittest.cpp => AttributesTest.cpp} (85%) create mode 100644 unittest/String2typeTest.cpp diff --git a/unittest/unittest.cpp b/unittest/AttributesTest.cpp similarity index 85% rename from unittest/unittest.cpp rename to unittest/AttributesTest.cpp index e93cdc9..49573eb 100644 --- a/unittest/unittest.cpp +++ b/unittest/AttributesTest.cpp @@ -37,17 +37,6 @@ struct test_fixture { test object; }; -BOOST_AUTO_TEST_SUITE(string2type_test) - -BOOST_AUTO_TEST_CASE( test1 ) -{ - int x = string2type::convert("42"); - - BOOST_CHECK( x == 42 ); -} - -BOOST_AUTO_TEST_SUITE_END() - BOOST_FIXTURE_TEST_SUITE( test_suite, test_fixture ) //____________________________________________________________________________// diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 3d04248..d52a424 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -2,8 +2,10 @@ cmake_minimum_required (VERSION 2.6) link_directories(${Boost_LIBRARY_DIRS}) -add_executable(unittest unittest.cpp) +add_executable(AttributesTest AttributesTest.cpp) +target_link_libraries(AttributesTest ${Boost_LIBRARIES}) +add_test(AttributesTest AttributesTest) -target_link_libraries(unittest ${Boost_LIBRARIES}) - -add_test(unittest unittest) +add_executable(String2typeTest String2typeTest.cpp) +target_link_libraries(String2typeTest ${Boost_LIBRARIES}) +add_test(String2typeTest String2typeTest) diff --git a/unittest/String2typeTest.cpp b/unittest/String2typeTest.cpp new file mode 100644 index 0000000..880870f --- /dev/null +++ b/unittest/String2typeTest.cpp @@ -0,0 +1,41 @@ +#include "string2type.hpp" + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE attributes_test + +#include + +#include +#include + +namespace string2type { + +template<> +int convert(const std::string &value) { + return boost::lexical_cast(value); +} + +template<> +double convert(const std::string &value) { + return boost::lexical_cast(value); +} + +} + +BOOST_AUTO_TEST_SUITE(string2type_test) + +BOOST_AUTO_TEST_CASE( test1 ) +{ + int x = string2type::convert("42"); + + BOOST_CHECK( x == 42 ); +} + +BOOST_AUTO_TEST_CASE( test2 ) +{ + double x = string2type::convert("3.14"); + + BOOST_CHECK( x >= 3.14 ); +} + +BOOST_AUTO_TEST_SUITE_END()