]> git.zndr.dk Git - unittest.git/commitdiff
Initial commit
authorJannik ZANDER <jzander@grundfos.com>
Thu, 9 Feb 2017 21:19:44 +0000 (22:19 +0100)
committerJannik ZANDER <jzander@grundfos.com>
Thu, 9 Feb 2017 21:19:44 +0000 (22:19 +0100)
18 files changed:
.editorconfig [new file with mode: 0644]
.gitignore [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
README.md [new file with mode: 0644]
cmake/CMakeLists.txt.in [new file with mode: 0644]
cmake/FindAddUnitTest.cmake [new file with mode: 0644]
cmake/Findcppunit.cmake [new file with mode: 0644]
cmake/gtest.cmake [new file with mode: 0644]
folder1/Source/CMakeLists.txt [new file with mode: 0644]
folder1/Source/folder1.c [new file with mode: 0644]
folder1/Source/folder1.h [new file with mode: 0644]
folder1/Test/CMakeLists.txt [new file with mode: 0644]
folder1/Test/folder1_test.cpp [new file with mode: 0644]
folder2/Source/CMakeLists.txt [new file with mode: 0644]
folder2/Source/folder2.c [new file with mode: 0644]
folder2/Source/folder2.h [new file with mode: 0644]
folder2/Test/CMakeLists.txt [new file with mode: 0644]
folder2/Test/folder2_test.cpp [new file with mode: 0644]

diff --git a/.editorconfig b/.editorconfig
new file mode 100644 (file)
index 0000000..6cd80db
--- /dev/null
@@ -0,0 +1,16 @@
+; Top level editor config
+root = true
+; Always use Unix style new lines
+end_of_line = lf
+; New line ending on every file
+insert_final_newline = true
+; Trim whitespace
+trim_trailing_whitespace = true
+[*.py]
+; PEP8 defines 4 spaces for indentation
+indent_style = space
+indent_size = 4
+[*.md]
+; Markup file 2 spaces for indentation
+indent_style = space
+indent_size = 2
diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..72e8ffc
--- /dev/null
@@ -0,0 +1 @@
+*
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..45d8546
--- /dev/null
@@ -0,0 +1,16 @@
+cmake_minimum_required (VERSION 3.2)\r
+project(solution_test)\r
+\r
+set(USE_GTEST "yes")\r
+\r
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")\r
+find_package(AddUnitTest)\r
+\r
+# Add folder1\r
+add_subdirectory(folder1/Source)\r
+add_subdirectory(folder1/Test)\r
+\r
+# Add folder2\r
+add_subdirectory(folder2/Source)\r
+add_subdirectory(folder2/Test)\r
+\r
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..f38fe4a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,203 @@
+# Unit testing with CMake \r
+\r
+This is a framework for doing unit testing with CMake. \r
+\r
+Content\r
+* [Setup steps for Windows](#setup)\r
+* [Usage](#usage)\r
+* [Demo](#demo)\r
+\r
+<a name="setup"></a>\r
+## Setup steps for Windows \r
+* Install Visual Studio 2008\r
+* Install CMake \r
+  * Make sure executable is added to environmant path.\r
+* Install CPPUnit\r
+  * Make sure the environment variable CPPUNITDIR is pointing to your installation folder. \r
+  * Make sure CPPUnit is compiled with same compiler as is used to testing (MSVC 2008)\r
+\r
+Some additional notes\r
+* Visual Studio 2013 can also be used (or any other C++ compiler that is installed on your PC)\r
+* The framework support both CPPUnit testing framework and google testing framework\r
+* If google testing framework is selected it will be git cloned automatically if it is not found on your PC. This has the added advantages:\r
+  * Easy to swap between compilers since it is build automatically\r
+  * No installation of testing framework is required beforehand\r
+\r
+<a name="usage"></a>\r
+## Usage \r
+To setup testing you need to define a "unit" of code that shall be tested and a corresponding "unittest".\r
+\r
+Each "unit" of code has a name and the following properties:\r
+*  What source files should be included in this "unit"\r
+*  Which public interface or include path we need for this "unit"\r
+*  Which other "units" this "unit" depends on\r
+\r
+A "unittest" of code has the same kind of properties. \r
+\r
+Each user of a "unit" can be kept unaware of that\r
+* You decide to re-arrange your "unit" e.g split a .c file pair into two file pairs\r
+* You add/remove dependencies to other "units"\r
+\r
+Unit tests should only test the public interface of the "unit" and never access private parts\r
+\r
+To describe this for CMake a file called "CMakeLists.txt" should be created each folder that contain a "unit" of code. \r
+A function call to either "add_unit()" or "add_unittest()" is added to the file.\r
+\r
+Example of a "unit": \r
+\r
+    $ add_unit(TARGET folder1\r
+    $          SRCS   folder1.c\r
+    $          INCS   .)\r
+\r
+Example of another "unit" depending on the first "unit": \r
+\r
+    $ add_unit(TARGET folder2\r
+    $          SRCS   folder2.c\r
+    $          INCS   .\r
+    $          DEPS   folder1)\r
+\r
+Example of "unittest":\r
+\r
+    $ add_unittest(TARGET folder2_test\r
+    $              SRCS   folder2_test.cpp\r
+    $              INCS   .\r
+    $              DEPS   folder2)\r
+\r
+<a name="demo"></a>\r
+## Demo\r
+    $ mkdir build\r
+    $ cd build\r
+    $ cmake -GNinja ..\r
+    $ -- The C compiler identification is GNU 6.2.0\r
+    $ -- The CXX compiler identification is GNU 6.2.0\r
+    $ -- Check for working C compiler: C:/programs/msys64/mingw64/bin/cc.exe\r
+    $ -- Check for working C compiler: C:/programs/msys64/mingw64/bin/cc.exe -- works\r
+    $ -- Detecting C compiler ABI info\r
+    $ -- Detecting C compiler ABI info - done\r
+    $ -- Detecting C compile features\r
+    $ -- Detecting C compile features - done\r
+    $ -- Check for working CXX compiler: C:/programs/msys64/mingw64/bin/c++.exe\r
+    $ -- Check for working CXX compiler: C:/programs/msys64/mingw64/bin/c++.exe -- works\r
+    $ -- Detecting CXX compiler ABI info\r
+    $ -- Detecting CXX compiler ABI info - done\r
+    $ -- Detecting CXX compile features\r
+    $ -- Detecting CXX compile features - done\r
+    $ -- Could NOT find GTest (missing:  GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)\r
+    $ -- Found Git: C:/programs/msys64/usr/bin/git.exe (found version "2.9.0")\r
+    $ -- Configuring done\r
+    $ -- Generating done\r
+    $ -- Build files have been written to: C:/Projects/repos/jannikz/unittest_cmake/build/googletest-download\r
+    $ [1/9] Creating directories for 'googletest'\r
+    $ [2/9] Performing download step (git clone) for 'googletest'\r
+    $ Cloning into 'googletest-src'...\r
+    $ Already on 'master'\r
+    $ Your branch is up-to-date with 'origin/master'.\r
+    $ [3/9] No patch step for 'googletest'\r
+    $ [4/9] Performing update step for 'googletest'\r
+    $ Current branch master is up to date.\r
+    $ [5/9] No configure step for 'googletest'\r
+    $ [6/9] No build step for 'googletest'\r
+    $ [7/9] No install step for 'googletest'\r
+    $ [8/9] No test step for 'googletest'\r
+    $ [9/9] Completed 'googletest'\r
+    $ -- Found PythonInterp: C:/programs/msys64/mingw64/bin/python.exe (found version "2.7.11")\r
+    $ ===================================================\r
+    $ Component:\r
+    $   folder1:\r
+    $     Sources:\r
+    $       - folder1.c\r
+    $     Includes:\r
+    $       - .\r
+    $     Dependencies:\r
+    $     Definitions:\r
+    $ ===================================================\r
+    $ Component:\r
+    $   folder1_if:\r
+    $     Sources:\r
+    $     Includes:\r
+    $       - .\r
+    $     Dependencies:\r
+    $     Definitions:\r
+    $ ===================================================\r
+    $ UnitTest:\r
+    $   folder1_test:\r
+    $     Sources:\r
+    $       - folder1_test.cpp\r
+    $     Includes:\r
+    $       - .\r
+    $     Dependencies:\r
+    $       - folder1\r
+    $     Definitions:\r
+    $ ===================================================\r
+    $ Component:\r
+    $   folder2:\r
+    $     Sources:\r
+    $       - folder2.c\r
+    $     Includes:\r
+    $       - .\r
+    $     Dependencies:\r
+    $       - folder1\r
+    $     Definitions:\r
+    $ ===================================================\r
+    $ UnitTest:\r
+    $   folder2_test:\r
+    $     Sources:\r
+    $       - folder2_test.cpp\r
+    $     Includes:\r
+    $       - .\r
+    $     Dependencies:\r
+    $       - folder2\r
+    $     Definitions:\r
+    $ ===================================================\r
+    $ -- Configuring done\r
+    $ -- Generating done\r
+    $ -- Build files have been written to: C:/Projects/repos/jannikz/unittest_cmake/build\r
+    $ cmake --build .\r
+    $ [1/19] Building C object folder1/Source/CMakeFiles/folder1.dir/folder1.c.obj\r
+    $ [2/19] Linking C static library folder1\Source\libfolder1.a\r
+    $ [3/19] Building C object folder2/Source/CMakeFiles/folder2.dir/folder2.c.obj\r
+    $ [4/19] Linking C static library folder2\Source\libfolder2.a\r
+    $ [5/19] Building CXX object googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.obj\r
+    $ [6/19] Building CXX object googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.obj\r
+    $ [7/19] Building CXX object googletest-build/googlemock/CMakeFiles/gmock_main.dir/src/gmock-all.cc.obj\r
+    $ [8/19] Building CXX object googletest-build/googlemock/CMakeFiles/gmock.dir/__/googletest/src/gtest-all.cc.obj\r
+    $ [9/19] Building CXX object googletest-build/googlemock/CMakeFiles/gmock_main.dir/__/googletest/src/gtest-all.cc.obj\r
+    $ [10/19] Building CXX object googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj\r
+    $ [11/19] Linking CXX static library googletest-build\googlemock\gtest\libgtest.a\r
+    $ [12/19] Linking CXX static library googletest-build\googlemock\libgmock.a\r
+    $ [13/19] Linking CXX static library googletest-build\googlemock\libgmock_main.a\r
+    $ [14/19] Building CXX object googletest-build/googlemock/gtest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj\r
+    $ [15/19] Linking CXX static library googletest-build\googlemock\gtest\libgtest_main.a\r
+    $ [16/19] Building CXX object folder2/Test/CMakeFiles/folder2_test.dir/folder2_test.cpp.obj\r
+    $ [17/19] Building CXX object folder1/Test/CMakeFiles/folder1_test.dir/folder1_test.cpp.obj\r
+    $ [18/19] Linking CXX executable folder2\Test\folder2_test.exe\r
+    $ Running main() from gtest_main.cc\r
+    $ [==========] Running 1 test from 1 test case.\r
+    $ [----------] Global test environment set-up.\r
+    $ [----------] 1 test from function3_test\r
+    $ [ RUN      ] function3_test.compare3\r
+    $ [       OK ] function3_test.compare3 (0 ms)\r
+    $ [----------] 1 test from function3_test (0 ms total)\r
+    $ \r
+    $ [----------] Global test environment tear-down\r
+    $ [==========] 1 test from 1 test case ran. (0 ms total)\r
+    $ [  PASSED  ] 1 test.\r
+    $ [19/19] Linking CXX executable folder1\Test\folder1_test.exe\r
+    $ Running main() from gtest_main.cc\r
+    $ [==========] Running 2 tests from 2 test cases.\r
+    $ [----------] Global test environment set-up.\r
+    $ [----------] 1 test from function1_test\r
+    $ [ RUN      ] function1_test.compare1\r
+    $ [       OK ] function1_test.compare1 (0 ms)\r
+    $ [----------] 1 test from function1_test (0 ms total)\r
+    $ \r
+    $ [----------] 1 test from function2_test\r
+    $ [ RUN      ] function2_test.compare2\r
+    $ [       OK ] function2_test.compare2 (0 ms)\r
+    $ [----------] 1 test from function2_test (0 ms total)\r
+    $ \r
+    $ [----------] Global test environment tear-down\r
+    $ [==========] 2 tests from 2 test cases ran. (0 ms total)\r
+    $ [  PASSED  ] 2 tests.\r
+    \r
+\r
diff --git a/cmake/CMakeLists.txt.in b/cmake/CMakeLists.txt.in
new file mode 100644 (file)
index 0000000..73ea4a6
--- /dev/null
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.2) 
+
+project(googletest-download NONE)
+
+include(ExternalProject)
+ExternalProject_Add(googletest
+  GIT_REPOSITORY    https://github.com/google/googletest.git
+  GIT_TAG           master
+  SOURCE_DIR        "${CMAKE_BINARY_DIR}/googletest-src"
+  BINARY_DIR        "${CMAKE_BINARY_DIR}/googletest-build"
+  CONFIGURE_COMMAND ""
+  BUILD_COMMAND     ""
+  INSTALL_COMMAND   ""
+  TEST_COMMAND      ""
+)
+
diff --git a/cmake/FindAddUnitTest.cmake b/cmake/FindAddUnitTest.cmake
new file mode 100644 (file)
index 0000000..0a69117
--- /dev/null
@@ -0,0 +1,150 @@
+cmake_minimum_required (VERSION 3.2)\r
+\r
+enable_testing()\r
+set_property( GLOBAL PROPERTY USE_FOLDERS ON)\r
+\r
+################################\r
+# Add unit function \r
+################################\r
+function(add_unit)\r
+  cmake_parse_arguments(my "" "TARGET" "INCS;SRCS;DEPS;DEFS" ${ARGN})\r
+  print_target("Component" "${my_TARGET}" "${my_SRCS}" "${my_INCS}" "${my_DEPS}" "${my_DEFS}")\r
+  if ("${my_SRCS}" MATCHES ".*\\.(cpp|c)")\r
+    # Add public library\r
+    add_library(${my_TARGET} "${my_SRCS}")\r
+    foreach(inc ${my_INCS})\r
+      target_include_directories(${my_TARGET} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${inc}")\r
+    endforeach()\r
+    target_link_libraries(${my_TARGET} PUBLIC "${my_DEPS}")\r
+    target_compile_definitions(${my_TARGET} PUBLIC ${my_DEFS})\r
+    add_unitfolder(${my_TARGET} "${my_SRCS}")\r
+  else()\r
+    # Add interface library\r
+    add_library(${my_TARGET} INTERFACE)\r
+    foreach(inc ${my_INCS})\r
+      target_include_directories(${my_TARGET} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/${inc}")\r
+    endforeach()\r
+    target_link_libraries(${my_TARGET} INTERFACE "${my_DEPS}")\r
+    target_compile_definitions(${my_TARGET} INTERFACE ${my_DEFS})\r
+\r
+    # Add header files to IDE view (this has no effect on build)\r
+    foreach(src ${my_SRCS})\r
+      target_sources(${my_TARGET} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/${src}")\r
+    endforeach()\r
+  endif() \r
+endfunction()\r
+\r
+################################\r
+# Add unittest function \r
+################################\r
+function(add_unittest)\r
+  cmake_parse_arguments(my "" "TARGET" "INCS;SRCS;DEPS;DEFS" ${ARGN})\r
+  print_target("UnitTest" "${my_TARGET}" "${my_SRCS}" "${my_INCS}" "${my_DEPS}" "${my_DEFS}")\r
+\r
+  # Add test executable\r
+  add_executable(${my_TARGET} "${my_SRCS}")\r
+  foreach(inc ${my_INCS})\r
+    target_include_directories(${my_TARGET} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${inc}")\r
+  endforeach()\r
+  if (USE_GTEST)\r
+    if(GTEST_FOUND)\r
+      target_include_directories(${my_TARGET} PUBLIC "${GTEST_INCLUDE_DIRS}")\r
+      target_link_libraries(${my_TARGET} PUBLIC "${my_DEPS}" ${GTEST_BOTH_LIBRARIES})\r
+    else()\r
+      target_link_libraries(${my_TARGET} PUBLIC "${my_DEPS}" gtest gtest_main)\r
+    endif()\r
+    target_compile_definitions(${my_TARGET} PUBLIC ${my_DEFS} USE_GTEST)\r
+  else()\r
+    target_include_directories(${my_TARGET} PUBLIC "${CPPUNIT_INCLUDE_DIRS}")\r
+    target_link_libraries(${my_TARGET} PUBLIC "${my_DEPS}" ${CPPUNIT_LIBRARIES})\r
+    target_compile_definitions(${my_TARGET} PUBLIC ${my_DEFS})\r
+  endif()\r
+  # Add test to test suite\r
+  add_test(${my_TARGET} ${my_TARGET})\r
+  add_unitfolder(${my_TARGET} "${my_SRCS}")\r
+  # Run test after build\r
+  add_custom_command(TARGET ${my_TARGET} POST_BUILD COMMAND ${my_TARGET})\r
+endfunction()\r
+\r
+################################\r
+# Add add_unitfolder function (only for IDE)\r
+################################\r
+function(add_unitfolder mytarget mysrcs)\r
+  # source_group("" FILES "${mysrcs}")\r
+  string(REGEX REPLACE "_stub*$" "" myfolder ${mytarget})\r
+  string(REGEX REPLACE "_stubs*$" "" myfolder ${mytarget})\r
+  string(REGEX REPLACE "_test*$" "" myfolder ${myfolder})\r
+  string(REGEX REPLACE "_if*$"   "" myfolder ${myfolder})\r
+  string(TOUPPER ${myfolder} myfolder)\r
+  set_property(TARGET ${mytarget} PROPERTY FOLDER "${myfolder}")\r
+endfunction()\r
+\r
+################################\r
+# Print target function \r
+################################\r
+function(print_target type target srcs incs deps defs)\r
+  message("${type}:")\r
+  message("  ${target}:")\r
+  message("    Sources:")\r
+  foreach(src ${srcs})\r
+  message("      - ${src}")\r
+  endforeach()\r
+  message("    Includes:")\r
+  foreach(inc ${incs})\r
+  message("      - ${inc}")\r
+  endforeach()\r
+  message("    Dependencies:")\r
+  foreach(dep ${deps})\r
+  message("      - ${dep}")\r
+  endforeach()\r
+  message("    Definitions:")\r
+  foreach(def ${defs})\r
+  message("      - ${def}")\r
+  endforeach()\r
+  message("===================================================")\r
+endfunction()\r
+\r
+\r
+################################\r
+# Compiler options \r
+################################\r
+if(MSVC)\r
+  add_definitions(/FC /D_CRT_SECURE_NO_WARNINGS)\r
+endif()\r
+\r
+if(CMAKE_COMPILER_IS_GNUCXX)\r
+  add_definitions(-Wall -Wno-deprecated -pthread -D__PC__)\r
+endif()\r
+\r
+################################\r
+# Configure testing framework \r
+################################\r
+\r
+if(USE_GTEST)\r
+  if(NOT GTEST_ROOT)\r
+    if(NOT $ENV{GTEST_DIR} STREQUAL "")\r
+      set(GTEST_ROOT "$ENV{GTEST_DIR}")\r
+    else()\r
+      set(GTEST_ROOT "C:/googletest-release-1.7.0")\r
+    endif()\r
+  endif()\r
+\r
+  find_package(gtest)\r
+  if(NOT GTEST_FOUND)\r
+    # Add external google test project\r
+    find_package(git REQUIRED)\r
+    include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/gtest.cmake")\r
+  endif()\r
+else()\r
+  if(NOT CPPUNIT_ROOT_DIR)\r
+    if(NOT $ENV{CPPUNITDIR} STREQUAL "")\r
+      set(CPPUNIT_ROOT_DIR "$ENV{CPPUNITDIR}/lib")\r
+    else()\r
+      set(CPPUNIT_ROOT_DIR "C:/cppunit-1.12.1/lib")\r
+    endif()\r
+  endif()\r
+\r
+  find_package(cppunit REQUIRED)\r
+endif()\r
+\r
+message("===================================================")\r
diff --git a/cmake/Findcppunit.cmake b/cmake/Findcppunit.cmake
new file mode 100644 (file)
index 0000000..b83b67e
--- /dev/null
@@ -0,0 +1,76 @@
+# - try to find cppunit library
+#
+# Cache Variables: (probably not for direct use in your scripts)
+#  CPPUNIT_INCLUDE_DIR
+#  CPPUNIT_LIBRARY
+#
+# Non-cache variables you might use in your CMakeLists.txt:
+#  CPPUNIT_FOUND
+#  CPPUNIT_INCLUDE_DIRS
+#  CPPUNIT_LIBRARIES
+#
+# Requires these CMake modules:
+#  SelectLibraryConfigurations (included with CMake >= 2.8.0)
+#  FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
+#
+# Original Author:
+# 2009-2011 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2009-2011.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+set(CPPUNIT_ROOT_DIR
+       "${CPPUNIT_ROOT_DIR}"
+       CACHE
+       PATH
+       "Directory to search")
+
+find_library(CPPUNIT_LIBRARY_RELEASE
+       NAMES
+       cppunit
+       HINTS
+       "${CPPUNIT_ROOT_DIR}")
+
+find_library(CPPUNIT_LIBRARY_DEBUG
+       NAMES
+       cppunitd
+       HINTS
+       "${CPPUNIT_ROOT_DIR}")
+
+include(SelectLibraryConfigurations)
+select_library_configurations(CPPUNIT)
+
+# Might want to look close to the library first for the includes.
+get_filename_component(_libdir "${CPPUNIT_LIBRARY_RELEASE}" PATH)
+
+find_path(CPPUNIT_INCLUDE_DIR
+       NAMES
+       cppunit/TestCase.h
+       HINTS
+       "${_libdir}/.."
+       PATHS
+       "${CPPUNIT_ROOT_DIR}"
+       PATH_SUFFIXES
+       include/)
+
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(cppunit
+       DEFAULT_MSG
+       CPPUNIT_LIBRARY
+       CPPUNIT_INCLUDE_DIR)
+
+if(CPPUNIT_FOUND)
+       set(CPPUNIT_LIBRARIES ${CPPUNIT_LIBRARY} ${CMAKE_DL_LIBS})
+       set(CPPUNIT_INCLUDE_DIRS "${CPPUNIT_INCLUDE_DIR}")
+       mark_as_advanced(CPPUNIT_ROOT_DIR)
+endif()
+
+mark_as_advanced(CPPUNIT_INCLUDE_DIR
+       CPPUNIT_LIBRARY_RELEASE
+       CPPUNIT_LIBRARY_DEBUG)
+
diff --git a/cmake/gtest.cmake b/cmake/gtest.cmake
new file mode 100644 (file)
index 0000000..5c92fde
--- /dev/null
@@ -0,0 +1,34 @@
+cmake_minimum_required (VERSION 3.2)
+
+find_path (my_PATH NAMES CMakeLists.txt.in HINTS ${CMAKE_MODULE_PATH})
+
+# Download and unpack googletest at configure time
+configure_file("${my_PATH}/CMakeLists.txt.in" googletest-download/CMakeLists.txt)
+execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
+  RESULT_VARIABLE result
+  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
+if(result)
+  message(FATAL_ERROR "CMake step for googletest failed: ${result}")
+endif()
+execute_process(COMMAND ${CMAKE_COMMAND} --build .
+  RESULT_VARIABLE result
+  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
+if(result)
+  message(FATAL_ERROR "Build step for googletest failed: ${result}")
+endif()
+
+# Prevent overriding the parent project's compiler/linker
+# settings on Windows
+set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+
+# Add googletest directly to our build. This defines
+# the gtest and gtest_main targets.
+add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
+                 ${CMAKE_BINARY_DIR}/googletest-build)
+
+# The gtest/gtest_main targets carry header search path
+# dependencies automatically when using CMake 2.8.11 or
+# later. Otherwise we have to add them here ourselves.
+if (CMAKE_VERSION VERSION_LESS 2.8.11)
+  include_directories("${gtest_SOURCE_DIR}/include")
+endif()
diff --git a/folder1/Source/CMakeLists.txt b/folder1/Source/CMakeLists.txt
new file mode 100644 (file)
index 0000000..624047b
--- /dev/null
@@ -0,0 +1,7 @@
+add_unit(TARGET folder1 
+         SRCS   folder1.c
+         INCS   .)
+
+add_unit(TARGET folder1_if
+         INCS   .)
+
diff --git a/folder1/Source/folder1.c b/folder1/Source/folder1.c
new file mode 100644 (file)
index 0000000..36066c0
--- /dev/null
@@ -0,0 +1,11 @@
+#include "folder1.h"\r
+\r
+int function1()\r
+{\r
+  return 1;\r
+}\r
+\r
+int function2()\r
+{\r
+  return 2;\r
+}
\ No newline at end of file
diff --git a/folder1/Source/folder1.h b/folder1/Source/folder1.h
new file mode 100644 (file)
index 0000000..ae3e5bd
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef FOLDER1_H\r
+#define FOLDER1_H\r
+\r
+int function1();\r
+int function2();\r
+\r
+#endif // FOLDER1_H
\ No newline at end of file
diff --git a/folder1/Test/CMakeLists.txt b/folder1/Test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d5572c6
--- /dev/null
@@ -0,0 +1,4 @@
+add_unittest(TARGET folder1_test
+             SRCS   folder1_test.cpp
+             INCS   . 
+             DEPS   folder1)
diff --git a/folder1/Test/folder1_test.cpp b/folder1/Test/folder1_test.cpp
new file mode 100644 (file)
index 0000000..68d7673
--- /dev/null
@@ -0,0 +1,15 @@
+#include "gtest/gtest.h"\r
+extern "C" {\r
+#include "folder1.h"\r
+}\r
+\r
+TEST(function1_test, compare1)\r
+{\r
+  ASSERT_EQ(function1(), 1) << "Values are equal function1 == 1";\r
+}\r
+\r
+TEST(function2_test, compare2)\r
+{\r
+  ASSERT_EQ(function2(), 2) << "Values are equal function2 == 2";\r
+}\r
+\r
diff --git a/folder2/Source/CMakeLists.txt b/folder2/Source/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b509ca4
--- /dev/null
@@ -0,0 +1,5 @@
+add_unit(TARGET folder2 
+         SRCS   folder2.c
+         INCS   . 
+         DEPS   folder1)
+
diff --git a/folder2/Source/folder2.c b/folder2/Source/folder2.c
new file mode 100644 (file)
index 0000000..2d27b97
--- /dev/null
@@ -0,0 +1,8 @@
+#include "folder1.h"\r
+#include "folder2.h"\r
+\r
+\r
+int function3()\r
+{\r
+  return function1()+function2();\r
+}\r
diff --git a/folder2/Source/folder2.h b/folder2/Source/folder2.h
new file mode 100644 (file)
index 0000000..b03ea51
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef FOLDER2_H\r
+#define FOLDER2_H\r
+\r
+int function3();\r
+\r
+#endif // FOLDER2_H
\ No newline at end of file
diff --git a/folder2/Test/CMakeLists.txt b/folder2/Test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a03731c
--- /dev/null
@@ -0,0 +1,5 @@
+add_unittest(TARGET folder2_test
+             SRCS   folder2_test.cpp
+             INCS   . 
+             DEPS   folder2)
+
diff --git a/folder2/Test/folder2_test.cpp b/folder2/Test/folder2_test.cpp
new file mode 100644 (file)
index 0000000..6e0d942
--- /dev/null
@@ -0,0 +1,9 @@
+#include "gtest/gtest.h"\r
+extern "C" {\r
+#include "folder2.h"\r
+}\r
+\r
+TEST(function3_test, compare3)\r
+{\r
+  ASSERT_EQ(function3(), 3) << "Values are equal function3 == 3";\r
+}\r