[Orxonox-commit 4349] r9020 - in code/branches/testing: cmake test

landauf at orxonox.net landauf at orxonox.net
Sat Feb 25 20:13:19 CET 2012


Author: landauf
Date: 2012-02-25 20:13:19 +0100 (Sat, 25 Feb 2012)
New Revision: 9020

Added:
   code/branches/testing/test/BoostTest.cc
Modified:
   code/branches/testing/cmake/LibraryConfig.cmake
   code/branches/testing/test/CMakeLists.txt
Log:
sample tests with boost test

Modified: code/branches/testing/cmake/LibraryConfig.cmake
===================================================================
--- code/branches/testing/cmake/LibraryConfig.cmake	2012-02-23 19:52:57 UTC (rev 9019)
+++ code/branches/testing/cmake/LibraryConfig.cmake	2012-02-25 19:13:19 UTC (rev 9020)
@@ -161,6 +161,9 @@
 SET(Boost_ADDITIONAL_VERSIONS 1.40 1.40.0 1.41 1.41.0 1.42 1.42.0 1.43 1.43.0
                               1.44 1.44.0 1.45 1.45.0 1.46 1.46.0 1.46.1)
 IF(NOT TARDIS)
+  # optional
+  FIND_PACKAGE(Boost 1.40 COMPONENTS unit_test_framework)
+  # required
   FIND_PACKAGE(Boost 1.40 REQUIRED thread filesystem system date_time)
 ENDIF()
 # No auto linking, so this option is useless anyway

Added: code/branches/testing/test/BoostTest.cc
===================================================================
--- code/branches/testing/test/BoostTest.cc	                        (rev 0)
+++ code/branches/testing/test/BoostTest.cc	2012-02-25 19:13:19 UTC (rev 9020)
@@ -0,0 +1,23 @@
+#include <boost/test/minimal.hpp>
+
+//____________________________________________________________________________//
+
+int add( int i, int j ) { return i+j; }
+
+//____________________________________________________________________________//
+
+int test_main( int, char *[] )             // note the name!
+{
+    // six ways to detect and report the same error:
+    BOOST_CHECK( add( 2,2 ) == 4 );        // #1 continues on error
+    BOOST_REQUIRE( add( 2,2 ) == 4 );      // #2 throws on error
+    if( add( 2,2 ) != 4 )
+        BOOST_ERROR( "Ouch..." );          // #3 continues on error
+    if( add( 2,2 ) != 4 )
+        BOOST_FAIL( "Ouch..." );           // #4 throws on error
+    if( add( 2,2 ) != 4 ) throw "Oops..."; // #5 throws on error
+
+    return add( 2, 2 ) == 4 ? 0 : 1;       // #6 returns error code
+}
+
+//____________________________________________________________________________//

Modified: code/branches/testing/test/CMakeLists.txt
===================================================================
--- code/branches/testing/test/CMakeLists.txt	2012-02-23 19:52:57 UTC (rev 9019)
+++ code/branches/testing/test/CMakeLists.txt	2012-02-25 19:13:19 UTC (rev 9020)
@@ -1,9 +1,22 @@
 ENABLE_TESTING()
 
+ADD_CUSTOM_TARGET(test COMMAND ${CMAKE_CTEST_COMMAND})
+
 ADD_EXECUTABLE(sample_test EXCLUDE_FROM_ALL SampleTest.cc)
-ADD_TEST(test1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sample_test)
-ADD_TEST(test2 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sample_test)
-ADD_TEST(test3 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sample_test)
+ADD_DEPENDENCIES(test sample_test)
 
-ADD_CUSTOM_TARGET(test COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS sample_test)
-#ADD_DEPENDENCIES(test sample_test)
+ADD_TEST(test1a ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sample_test)
+ADD_TEST(test1b ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sample_test)
+ADD_TEST(test1c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sample_test)
+
+
+IF(Boost_UNIT_TEST_FRAMEWORK_FOUND)
+  INCLUDE_DIRECTORIES(
+    ${Boost_INCLUDE_DIRS}
+  )
+  ADD_EXECUTABLE(boost_test EXCLUDE_FROM_ALL BoostTest.cc)
+  TARGET_LINK_LIBRARIES(boost_test ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+  ADD_DEPENDENCIES(test boost_test)
+
+  ADD_TEST(test2 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/boost_test)
+ENDIF()




More information about the Orxonox-commit mailing list