Added unittest (requires Boost unit test framework).
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project (libsettable)
|
||||
|
||||
find_package(Boost)
|
||||
find_package(Boost 1.42 COMPONENTS system unit_test_framework)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/src
|
||||
${Boost_INCLUDE_DIRS})
|
||||
|
||||
add_subdirectory(examples)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_subdirectory(unittest)
|
||||
|
||||
9
unittest/CMakeLists.txt
Normal file
9
unittest/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
|
||||
link_directories(${Boost_LIBRARY_DIRS})
|
||||
|
||||
add_executable(unittest unittest.cpp)
|
||||
|
||||
target_link_libraries(unittest ${Boost_LIBRARIES})
|
||||
|
||||
add_test(unittest unittest)
|
||||
70
unittest/unittest.cpp
Normal file
70
unittest/unittest.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "attributes.hpp"
|
||||
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE attributes_test
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace string2type {
|
||||
|
||||
template<>
|
||||
int convert<int>(const std::string &value) {
|
||||
return boost::lexical_cast<int>(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct test : attributes {
|
||||
test() : x(0) {
|
||||
REGISTER_ATTRIBUTE(int, x);
|
||||
}
|
||||
|
||||
int x;
|
||||
};
|
||||
|
||||
struct test_fixture {
|
||||
test_fixture() : object() {
|
||||
BOOST_TEST_MESSAGE( "setup fixture" );
|
||||
}
|
||||
|
||||
~test_fixture() {
|
||||
BOOST_TEST_MESSAGE( "teardown fixture" );
|
||||
}
|
||||
|
||||
test object;
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(string2type_test)
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test1 )
|
||||
{
|
||||
int x = string2type::convert<int>("42");
|
||||
|
||||
BOOST_CHECK( x == 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE( test_suite, test_fixture )
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test2 )
|
||||
{
|
||||
BOOST_CHECK( object.x == 0 );
|
||||
|
||||
object.set_attribute("x", "42");
|
||||
|
||||
BOOST_CHECK( object.x == 42 );
|
||||
|
||||
object.set_attribute("x", "0");
|
||||
|
||||
BOOST_CHECK( object.x == 0 );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
Reference in New Issue
Block a user