From 67016f61645a5a92be07920476c61087541877eb Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Tue, 3 Jan 2012 00:19:51 -0200 Subject: [PATCH] Bring aboard test framework. --- CMakeLists.txt | 7 ++- test/CMakeLists.txt | 41 ++++++++++++++++ test/test_messagepayload.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 test/CMakeLists.txt create mode 100644 test/test_messagepayload.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 190b8b3..a913e9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(pingcheck) set(VERSION 0.1) set(TARGET ${PROJECT_NAME}) -# CMake +# cmake: build options if("${CMAKE_BUILD_TYPE}" STREQUAL "") set(CMAKE_BUILD_TYPE Debug) endif("${CMAKE_BUILD_TYPE}" STREQUAL "") @@ -35,7 +35,10 @@ set(CPACK_SOURCE_IGNORE_FILES ) set(CPACK_SOURCE_PACKAGE_FILE_NAME "${TARGET}-${VERSION}") -# build the application in the source directory +# cmake: build the application in the source directory add_subdirectory(src) +# cmake: build the test cases +add_subdirectory(test) + include(CPack) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..d8b3415 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,41 @@ +# package: required boost libraries +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) +find_package(Boost 1.44 COMPONENTS unit_test_framework REQUIRED) +include_directories(${Boost_INCLUDE_DIRS}) +link_directories(${Boost_LIBRARY_DIRS}) + +# package: libi2ncommon +pkg_check_modules(I2NCOMMON REQUIRED libi2ncommon) +include_directories(${I2NCOMMON_INCLUDE_DIRS}) +link_directories(${I2NCOMMON_LIBRARY_DIRS}) + +# compiler: include directories where the source code is located +include_directories(${CMAKE_SOURCE_DIR}/src) + +# compiler: include directories where the source code is located +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) + +# compiler: source code files +set(SOURCES + test_messagepayload.cpp + ../src/host/messagepayload.cpp +) + +# compiler: creates the binary +add_executable(test_${TARGET} ${SOURCES}) + +# cmake: add a custom "make check" target which automatically builds the binary +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_${TARGET}) + +# cmake: invocation via "make test" +enable_testing() +add_test(test_${TARGET} test_${TARGET}) + +# linker: link the program against the libraries +target_link_libraries( + test_${TARGET} + ${I2NCOMMON_LIBRARIES} + ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES} +) diff --git a/test/test_messagepayload.cpp b/test/test_messagepayload.cpp new file mode 100644 index 0000000..d30bf7d --- /dev/null +++ b/test/test_messagepayload.cpp @@ -0,0 +1,106 @@ +/* +The software in this package is distributed under the GNU General +Public License version 2 (with a special exception described below). + +A copy of GNU General Public License (GPL) is included in this distribution, +in the file COPYING.GPL. + +As a special exception, if other files instantiate templates or use macros +or inline functions from this file, or you compile this file and link it +with other works to produce a work based on this file, this file +does not by itself cause the resulting work to be covered +by the GNU General Public License. + +However the source code for this file must still be made available +in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based +on this file might be covered by the GNU General Public License. +*/ + +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK +#include + +#include "host/messagepayload.h" + +BOOST_AUTO_TEST_SUITE( TestMessagePayload ) + +BOOST_AUTO_TEST_CASE( basic_assignment ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( array_subscript_const ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( array_subscript ) +{ + MessagePayload mp( 10 ); + mp[0] = 0xA0; + mp[1] = 0xA1; + mp[2] = 0xA2; + mp[3] = 0xA3; + mp[4] = 0xA4; + mp[5] = 0xA5; + mp[6] = 0xA6; + mp[7] = 0xA7; + mp[8] = 0xA8; + mp[9] = 0xA9; + + MessagePayload mp2( mp ); + BOOST_CHECK_EQUAL( mp2[0], 0xA0 ); + BOOST_CHECK_EQUAL( mp2[1], 0xA1 ); + BOOST_CHECK_EQUAL( mp2[2], 0xA2 ); + BOOST_CHECK_EQUAL( mp2[3], 0xA3 ); + BOOST_CHECK_EQUAL( mp2[4], 0xA4 ); + BOOST_CHECK_EQUAL( mp2[5], 0xA5 ); + BOOST_CHECK_EQUAL( mp2[6], 0xA6 ); + BOOST_CHECK_EQUAL( mp2[7], 0xA7 ); + BOOST_CHECK_EQUAL( mp2[8], 0xA8 ); + BOOST_CHECK_EQUAL( mp2[9], 0xA9 ); +} + +BOOST_AUTO_TEST_CASE( get ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( append ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( decode16 ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( encode16 ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( decode32 ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( encode32 ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( read ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_CASE( write ) +{ + BOOST_CHECK_EQUAL( 3, 3 ); +} + +BOOST_AUTO_TEST_SUITE_END() -- 1.7.1