Selaa lähdekoodia

Closes #9 CppUTest harness added to project, first dummy test included

CapXilinx 12 vuotta sitten
vanhempi
sitoutus
39fad608eb

+ 8 - 0
buildsupport/OpENer_Tests.cmake

@@ -0,0 +1,8 @@
+#######################################
+# Adds test includes                  #
+#######################################
+macro( add_test_includes )
+  set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include ${CPPUTEST_HOME}/include/CppUTest/MemoryLeakDetectorNewMacros.h" )
+  set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${CPPUTEST_HOME}/include/CppUTest/MemoryLeakDetectorMallocMacros.h" )
+  include_directories( ${CPPUTEST_HOME}/include )
+endmacro( add_test_includes )

+ 17 - 0
src/CMakeLists.txt

@@ -55,8 +55,25 @@ if(OpENer_TRACES)
   
 endif(OpENer_TRACES)
 
+#######################################
+# Test switch                         #
+#######################################
+set( OpENer_TESTS OFF CACHE BOOL "Enable tests to be built" )
+if( OpENer_TESTS )
+  enable_language( CXX )
+  set( CPPUTEST_HOME "" CACHE PATH "Path to CppUTest directory" )
+  INCLUDE( ${OpENer_BUILDSUPPORT_DIR}/OpENer_Tests.cmake )
+  add_subdirectory(tests)
+endif( OpENer_TESTS )
+
+#######################################
+# OpENer C flags                      #
+#######################################
 set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w -Wall" )
 
+####################################################
+# Internal cache holding the available CIP objects #
+####################################################
 set( OpENer_ADD_CIP_OBJECTS "" CACHE INTERNAL STRING )
 
 #######################################

+ 12 - 0
src/tests/CMakeLists.txt

@@ -0,0 +1,12 @@
+#######################################
+# Add test subdirectories             #
+#######################################
+
+add_test_includes()
+
+add_subdirectory( utils )
+add_executable( OpENer_Tests main.cpp )
+
+set( CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${CPPUTEST_HOME}/lib )
+
+target_link_libraries( OpENer_Tests CppUTest CppUTestExt UtilsTest )

+ 12 - 0
src/tests/main.cpp

@@ -0,0 +1,12 @@
+#include "CppUTest/CommandLineTestRunner.h"
+
+IMPORT_TEST_GROUP(MTRandomTests);
+
+int main(int argc, char** argv)
+{
+  /* These checks are here to make sure assertions outside test runs don't crash */
+  CHECK(true);
+  LONGS_EQUAL(1, 1);
+
+  return CommandLineTestRunner::RunAllTests(argc, argv);
+}

+ 3 - 0
src/tests/utils/CMakeLists.txt

@@ -0,0 +1,3 @@
+set( UtilsTestSrc MTRandomTests.cpp )
+
+add_library( UtilsTest ${UtilsTestSrc} )

+ 11 - 0
src/tests/utils/MTRandomTests.cpp

@@ -0,0 +1,11 @@
+#include <CppUTest/TestHarness.h>
+
+TEST_GROUP(MTRandomTests)
+{
+};
+
+TEST(MTRandomTests, SeedTest)
+{
+  FAIL("Fail me!");
+}
+