Test: split test cases in N binaries.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sat, 21 Jan 2012 10:23:34 +0000 (08:23 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sat, 21 Jan 2012 10:23:34 +0000 (08:23 -0200)
Each test in its own binary:
- Allow linking of mock objects without conflicts with the original definition,
  which is linked in another executable;
- Provide list of tests and hints on which test failed, instead of a bloated
  binary, which gives no hint about.

12 files changed:
test/CMakeLists.test_hoststatusanalyzer.txt [new file with mode: 0644]
test/CMakeLists.test_icmpv4header.txt [new file with mode: 0644]
test/CMakeLists.test_icmpv6header.txt [new file with mode: 0644]
test/CMakeLists.test_ipv4header.txt [new file with mode: 0644]
test/CMakeLists.test_ipv6header.txt [new file with mode: 0644]
test/CMakeLists.test_messagepayload.txt [new file with mode: 0644]
test/CMakeLists.txt
test/test_hoststatusanalyzer.cpp
test/test_icmpv4header.cpp
test/test_icmpv6header.cpp
test/test_ipv4header.cpp
test/test_ipv6header.cpp

diff --git a/test/CMakeLists.test_hoststatusanalyzer.txt b/test/CMakeLists.test_hoststatusanalyzer.txt
new file mode 100644 (file)
index 0000000..5ac0172
--- /dev/null
@@ -0,0 +1,16 @@
+# compiler: creates the binaries
+add_executable(test_hoststatusanalyzer
+    test_hoststatusanalyzer.cpp
+    mock_linkstatusanalyzer.cpp
+    ${CMAKE_SOURCE_DIR}/src/host/hoststatusanalyzer.cpp
+)
+
+# linker: link the program against the libraries
+target_link_libraries(
+    test_hoststatusanalyzer
+    ${I2NCOMMON_LIBRARIES}
+    ${Boost_LIBRARIES}
+)
+
+# cmake: invocation via "make test"
+add_test(test_hoststatusanalyzer test_hoststatusanalyzer)
diff --git a/test/CMakeLists.test_icmpv4header.txt b/test/CMakeLists.test_icmpv4header.txt
new file mode 100644 (file)
index 0000000..1e3cde4
--- /dev/null
@@ -0,0 +1,21 @@
+# compiler: creates the binaries
+add_executable(test_icmpv4header
+    test_icmpv4header.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpv4header.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpmessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpdestinationunreachablemessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpechoreplymessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpechorequestmessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpgenericmessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
+)
+
+# linker: link the program against the libraries
+target_link_libraries(
+    test_icmpv4header
+    ${I2NCOMMON_LIBRARIES}
+    ${Boost_LIBRARIES}
+)
+
+# cmake: invocation via "make test"
+add_test(test_icmpv4header test_icmpv4header)
diff --git a/test/CMakeLists.test_icmpv6header.txt b/test/CMakeLists.test_icmpv6header.txt
new file mode 100644 (file)
index 0000000..53e309c
--- /dev/null
@@ -0,0 +1,21 @@
+# compiler: creates the binaries
+add_executable(test_icmpv6header
+    test_icmpv6header.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpv6header.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpmessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpdestinationunreachablemessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpechoreplymessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpechorequestmessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/icmp/icmpgenericmessage.cpp
+    ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
+)
+
+# linker: link the program against the libraries
+target_link_libraries(
+    test_icmpv6header
+    ${I2NCOMMON_LIBRARIES}
+    ${Boost_LIBRARIES}
+)
+
+# cmake: invocation via "make test"
+add_test(test_icmpv6header test_icmpv6header)
diff --git a/test/CMakeLists.test_ipv4header.txt b/test/CMakeLists.test_ipv4header.txt
new file mode 100644 (file)
index 0000000..d97cdd6
--- /dev/null
@@ -0,0 +1,16 @@
+# compiler: creates the binaries
+add_executable(test_ipv4header
+    test_ipv4header.cpp
+    ${CMAKE_SOURCE_DIR}/src/ip/ipv4header.cpp
+    ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
+)
+
+# linker: link the program against the libraries
+target_link_libraries(
+    test_ipv4header
+    ${I2NCOMMON_LIBRARIES}
+    ${Boost_LIBRARIES}
+)
+
+# cmake: invocation via "make test"
+add_test(test_ipv4header test_ipv4header)
diff --git a/test/CMakeLists.test_ipv6header.txt b/test/CMakeLists.test_ipv6header.txt
new file mode 100644 (file)
index 0000000..4f308bd
--- /dev/null
@@ -0,0 +1,16 @@
+# compiler: creates the binaries
+add_executable(test_ipv6header
+    test_ipv6header.cpp
+    ${CMAKE_SOURCE_DIR}/src/ip/ipv6header.cpp
+    ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
+)
+
+# linker: link the program against the libraries
+target_link_libraries(
+    test_ipv6header
+    ${I2NCOMMON_LIBRARIES}
+    ${Boost_LIBRARIES}
+)
+
+# cmake: invocation via "make test"
+add_test(test_ipv6header test_ipv6header)
diff --git a/test/CMakeLists.test_messagepayload.txt b/test/CMakeLists.test_messagepayload.txt
new file mode 100644 (file)
index 0000000..fa555a7
--- /dev/null
@@ -0,0 +1,15 @@
+# compiler: creates the binaries
+add_executable(test_messagepayload
+    test_messagepayload.cpp
+    ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
+)
+
+# linker: link the program against the libraries
+target_link_libraries(
+    test_messagepayload
+    ${I2NCOMMON_LIBRARIES}
+    ${Boost_LIBRARIES}
+)
+
+# cmake: invocation via "make test"
+add_test(test_messagepayload test_messagepayload)
index c1a392a..131855c 100644 (file)
@@ -20,49 +20,23 @@ 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 from test cases
-set(TESTS_SOURCES
-    test_messagepayload.cpp
-    test_hoststatusanalyzer.cpp
-    test_ipv4header.cpp
-    test_ipv6header.cpp
-    test_icmpv4header.cpp
-    test_icmpv6header.cpp
-)
-
-# compiler: source code from mock objects
-set(MOCK_SOURCES
-    mock_linkstatusanalyzer.cpp
-)
-
-# compiler: source code to be tested
-set(SOURCES
-    ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
-    ${CMAKE_SOURCE_DIR}/src/host/hoststatusanalyzer.cpp
-    ${CMAKE_SOURCE_DIR}/src/ip/ipv4header.cpp
-    ${CMAKE_SOURCE_DIR}/src/ip/ipv6header.cpp
-    ${CMAKE_SOURCE_DIR}/src/icmp/icmpv4header.cpp
-    ${CMAKE_SOURCE_DIR}/src/icmp/icmpv6header.cpp
-    ${CMAKE_SOURCE_DIR}/src/icmp/icmpmessage.cpp
-    ${CMAKE_SOURCE_DIR}/src/icmp/icmpdestinationunreachablemessage.cpp
-    ${CMAKE_SOURCE_DIR}/src/icmp/icmpechoreplymessage.cpp
-    ${CMAKE_SOURCE_DIR}/src/icmp/icmpechorequestmessage.cpp
-    ${CMAKE_SOURCE_DIR}/src/icmp/icmpgenericmessage.cpp
-)
+# cmake: enable ctest
+enable_testing()
 
-# compiler: creates the binary
-add_executable(test_${TARGET} ${SOURCES} ${MOCK_SOURCES} ${TESTS_SOURCES})
+# cmake: inclusion of each test case cmake file
+include(CMakeLists.test_messagepayload.txt)
+include(CMakeLists.test_hoststatusanalyzer.txt)
+include(CMakeLists.test_ipv4header.txt)
+include(CMakeLists.test_ipv6header.txt)
+include(CMakeLists.test_icmpv4header.txt)
+include(CMakeLists.test_icmpv6header.txt)
 
 # 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_LIBRARIES}
+add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS
+    test_messagepayload
+    test_hoststatusanalyzer
+    test_ipv4header
+    test_ipv6header
+    test_icmpv4header
+    test_icmpv6header
 )
index d795998..2e2d788 100644 (file)
@@ -18,8 +18,8 @@ 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
-#define BOOST_TEST_MESSAGE usage
 
 #include <streambuf>
 
@@ -153,5 +153,3 @@ BOOST_AUTO_TEST_CASE( fail_percentage_80 )
 }
 
 BOOST_AUTO_TEST_SUITE_END()
-
-
index 4fe3940..5a3af8a 100644 (file)
@@ -18,6 +18,7 @@ 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 <streambuf>
index c0415b6..df24a28 100644 (file)
@@ -18,6 +18,7 @@ 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 <streambuf>
index 9931d65..fda1f3b 100644 (file)
@@ -18,6 +18,7 @@ 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 <streambuf>
index 5e8a030..c6053c7 100644 (file)
@@ -18,6 +18,7 @@ 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 <streambuf>