Bring aboard test framework.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 3 Jan 2012 02:19:51 +0000 (00:19 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 3 Jan 2012 02:19:51 +0000 (00:19 -0200)
CMakeLists.txt
test/CMakeLists.txt [new file with mode: 0644]
test/test_messagepayload.cpp [new file with mode: 0644]

index 190b8b3..a913e9d 100644 (file)
@@ -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 (file)
index 0000000..d8b3415
--- /dev/null
@@ -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 (file)
index 0000000..d30bf7d
--- /dev/null
@@ -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 <boost/test/unit_test.hpp>
+
+#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()