e46a4fceeca0d37937c73eac3070c429a055c5f2
[platform/upstream/cmocka.git] / example / CMakeLists.txt
1 project(cmocka-examples C)
2
3 include_directories(
4     ${CMAKE_BINARY_DIR}
5     ${CMAKE_CURRENT_SOURCE_DIR}
6     ${CMOCKA_PUBLIC_INCLUDE_DIRS}
7 )
8
9 set_source_files_properties(
10     calculator.c
11     allocate_module.c
12     assert_module.c
13     PROPERTIES
14         COMPILE_DEFINITIONS UNIT_TESTING=1)
15
16 if (WIN32)
17     set(DLL_PATH_ENV "${CMOCKA_DLL_PATH};$ENV{PATH}")
18
19     #
20     # IMPORTANT NOTE: The set_tests_properties(), below, internally
21     # stores its name/value pairs with a semicolon delimiter.
22     # because of this we must protect the semicolons in the path
23     #
24     string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}")
25 endif (WIN32)
26
27
28 ### The most simple test
29 add_executable(simple_test simple_test.c)
30 target_link_libraries(simple_test ${CMOCKA_SHARED_LIBRARY})
31
32 add_test(simple_test ${CMAKE_CURRENT_BINARY_DIR}/simple_test)
33 if (WIN32)
34     set_tests_properties(simple_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
35 endif (WIN32)
36
37 ### Calulator test
38 if (NOT WIN32)
39     add_executable(calculator_test calculator.c calculator_test.c)
40     target_link_libraries(calculator_test ${CMOCKA_SHARED_LIBRARY})
41
42     add_test(calculator_test ${CMAKE_CURRENT_BINARY_DIR}/calculator_test)
43 endif (NOT WIN32)
44
45 # FIXME These tests fail on Windows when run with ctest but look correct excuted manually.
46 if (NOT WIN32)
47 ### Allocate module test
48 add_executable(allocate_module_test allocate_module.c allocate_module_test.c)
49 target_link_libraries(allocate_module_test ${CMOCKA_SHARED_LIBRARY})
50
51 # This is a test that should detect leaks and overflows and will fail for that
52 add_test(allocate_module_test ${CMAKE_CURRENT_BINARY_DIR}/allocate_module_test)
53 if (WIN32)
54     set_tests_properties(allocate_module_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
55 endif (WIN32)
56 set_tests_properties(
57     allocate_module_test
58         PROPERTIES
59             WILL_FAIL 1
60 )
61
62 ### Assert macro test
63 add_executable(assert_macro_test assert_macro.c assert_macro_test.c)
64 target_link_libraries(assert_macro_test ${CMOCKA_SHARED_LIBRARY})
65
66 add_test(assert_macro_test ${CMAKE_CURRENT_BINARY_DIR}/assert_macro_test)
67 set_tests_properties(
68     assert_macro_test
69         PROPERTIES
70         WILL_FAIL 1
71 )
72 if (WIN32)
73     set_tests_properties(assert_macro_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
74 endif (WIN32)
75
76 ### Assert module test
77 add_executable(assert_module_test assert_module.c assert_module_test.c)
78 target_link_libraries(assert_module_test ${CMOCKA_SHARED_LIBRARY})
79
80 add_test(assert_module_test ${CMAKE_CURRENT_BINARY_DIR}/assert_module_test)
81 set_tests_properties(
82     assert_module_test
83         PROPERTIES
84         WILL_FAIL 1
85 )
86 if (WIN32)
87     set_tests_properties(assert_module_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
88 endif (WIN32)
89 endif (NOT WIN32) # FIXME FAIL
90
91 ### Customer database test
92 add_executable(customer_database_test customer_database.c customer_database_test.c)
93 target_link_libraries(customer_database_test ${CMOCKA_SHARED_LIBRARY})
94
95 add_test(customer_database_test ${CMAKE_CURRENT_BINARY_DIR}/customer_database_test)
96 if (WIN32)
97     set_tests_properties(customer_database_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
98 endif (WIN32)
99
100 ### Key Value Test
101 add_executable(key_value_test key_value.c key_value_test.c)
102 target_link_libraries(key_value_test ${CMOCKA_SHARED_LIBRARY})
103
104 add_test(key_value_test ${CMAKE_CURRENT_BINARY_DIR}/key_value_test)
105 if (WIN32)
106     set_tests_properties(key_value_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
107 endif (WIN32)
108
109 ### Product database test
110 add_executable(product_database_test product_database.c product_database_test.c)
111 target_link_libraries(product_database_test ${CMOCKA_SHARED_LIBRARY})
112
113 add_test(product_database_test ${CMAKE_CURRENT_BINARY_DIR}/product_database_test)
114 set_tests_properties(
115     product_database_test
116         PROPERTIES
117         PASS_REGULAR_EXPRESSION
118         "\\[  FAILED  \\] 2 test"
119 )
120 if (WIN32)
121     set_tests_properties(product_database_test PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}")
122 endif (WIN32)
123
124 # TODO Execute "$CMAKE_LINKER --help" and check for --wrap
125 if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)" AND NOT APPLE)
126     add_subdirectory(chef_wrap)
127 endif()