summaryrefslogtreecommitdiff
path: root/src/test/CMakeLists.txt
blob: dc3db6b547b7281278074e84370fdf72d25befe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
include_directories(
  ${CMAKE_BINARY_DIR}
  ${CMAKE_SOURCE_DIR}/src
  ${CMAKE_BINARY_DIR}/src
  ${CMAKE_SOURCE_DIR}/src/libical
  ${CMAKE_BINARY_DIR}/src/libical
  ${CMAKE_SOURCE_DIR}/src/libicalss
)

if(ICU_FOUND)
  include_directories(${ICU_INCLUDE_DIRS})
endif()

if(BDB_FOUND)
  include_directories(${BDB_INCLUDE_DIR})
endif()

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})

set(TEST_DATADIR "\"${CMAKE_SOURCE_DIR}/test-data\"")
add_definitions(-DTEST_DATADIR=${TEST_DATADIR} -DTEST_ZONEDIR="${CMAKE_SOURCE_DIR}/zoneinfo")

macro(setprops _name)
  if(UNIX)
    set_tests_properties(${_name} PROPERTIES
      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
    )
  endif()
  if(WIN32)
    set(tpath "${CMAKE_BINARY_DIR}/bin;%PATH%")
    if(ICU_FOUND)
      set(tpath "${ICU_BINARY_DIR};${tpath}")
    endif()
    set_tests_properties(${_name} PROPERTIES
      ENVIRONMENT "PATH=${tpath}"
      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
    )
  endif()
  if(CYGWIN OR MSYS)
    set_tests_properties(${_name} PROPERTIES
      ENVIRONMENT "PATH=${EXECUTABLE_OUTPUT_PATH}:${CMAKE_BINARY_DIR}/lib:$ENV{PATH}"
      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
    )
  endif()
endmacro()

#macro to build (but do not create a test)
macro(buildme _name _srcs)
  add_executable(${_name} ${_srcs})
  add_dependencies(${_name} ical icalss icalvcal)
  if(NOT SHARED_ONLY)
    add_dependencies(${_name} ical-static icalss-static icalvcal-static)
  endif()
  target_link_libraries(${_name} ical icalss icalvcal)

  if(WITH_CXX_BINDINGS)
    add_dependencies(${_name} ical_cxx icalss_cxx)
    if(NOT SHARED_ONLY)
      add_dependencies(${_name} ical_cxx-static icalss_cxx-static)
    endif()
    target_link_libraries(${_name} ical_cxx icalss_cxx)
  endif()

  target_link_libraries(${_name} ${CMAKE_THREAD_LIBS_INIT})
  if(ICU_FOUND)
    target_link_libraries(${_name} ${ICU_LIBRARIES})
  endif()
  if(BDB_FOUND)
    target_link_libraries(${_name} ${BDB_LIBRARY})
  endif()
endmacro()

macro(testme _name _srcs)
  buildme(${_name} "${_srcs}")
  add_test(NAME ${_name} COMMAND ${_name})
  setprops(${_name})
endmacro()

########## libical-glib tests #########
if(ICAL_GLIB AND HAVE_INTROSPECTION)
  add_subdirectory(libical-glib)
endif()

########### next target ###############

set(copycluster_SRCS copycluster.c)
buildme(copycluster "${copycluster_SRCS}")

########### next target ###############

set(regression_SRCS
  regression.c
  regression.h
  regression-component.c
  regression-classify.c
  regression-utils.c
  regression-recur.c
  regression-storage.c
)
if(WITH_CXX_BINDINGS)
  list(APPEND regression_SRCS regression-cxx.cpp)
endif()
testme(regression "${regression_SRCS}")

########### next target ###############

set(parser_SRCS icaltestparser.c)
buildme(parser "${parser_SRCS}")

file(GLOB TEST_FILES ${CMAKE_SOURCE_DIR}/test-data/*.ics)
foreach(TEST_FILE ${TEST_FILES})
  get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE)
  add_test(NAME parser-${TEST_NAME} COMMAND parser ${TEST_FILE})
  setprops(parser-${TEST_NAME})
endforeach()

########### next target ###############

if(NOT WIN32 AND NOT ANDROID)
  #stow is very Unix specific
  set(stow_SRCS stow.c)
  buildme(stow "${stow_SRCS}")
endif()

########### next target ###############

set(recur_SRCS recur.c)
testme(recur "${recur_SRCS}")

########### next target ###############

if(HAVE_GETOPT) #getopt is required
  set(icalrecur_test_SRCS icalrecur_test.c)
  buildme(icalrecur_test "${icalrecur_test_SRCS}")
endif()

########### next target ###############
if(CMAKE_USE_PTHREADS_INIT)
  set(icaltm_test_SRCS icaltm_test.c)
  testme(icaltm_test "${icaltm_test_SRCS}")
endif()

########### next target ###############

if(HAVE_GETOPT) #getopt is required
  set(testmime_SRCS testmime.c)
  testme(testmime "${testmime_SRCS}")
endif()

########### next target ###############

set(testvcal_SRCS testvcal.c)
testme(testvcal "${testvcal_SRCS}")

########### next target ###############

set(process_SRCS process.c)
testme(process "${process_SRCS}")

########### next target ###############

if(NOT USE_BUILTIN_TZDATA AND NOT CYGWIN) #seeing >15% error rate on Cygwin. why?
  set(timezones_SRCS timezones.c)
  testme(timezones "${timezones_SRCS}")
endif()

########### next target ###############

set(builtin_timezones_SRCS builtin_timezones.c)
testme(builtin_timezones "${builtin_timezones_SRCS}")

########### next target ###############

#cmake v3.14 compare_files can ignore line endings => needed on Windows
set(CMAKE_COMPARE_FILES_IGNORE_EOL FALSE)
if(NOT ${CMAKE_VERSION} VERSION_LESS 3.14)
  set(CMAKE_COMPARE_FILES_IGNORE_EOL TRUE)
endif()
if(NOT WIN32 OR CMAKE_COMPARE_FILES_IGNORE_EOL)
  if(NOT CYGWIN AND NOT USE_32BIT_TIME_T) #ignore_eol doesn't work on Cygwin. tests for years greater than 2037 will fail
    set(icalrecurtest_SRCS icalrecur_test.c)
    add_executable(icalrecurtest ${icalrecurtest_SRCS})
    target_link_libraries(icalrecurtest ical icalss icalvcal)
    set(test_cmd "${CMAKE_BINARY_DIR}/src/test/icalrecurtest${CMAKE_EXECUTABLE_SUFFIX}")

    if(ICU_FOUND)
      #test rscale capable rrules
      set(test_args "-r")
      if(HAVE_ICU_DANGI)
        set(reference_data "icalrecur_withicu_dangi_test.out")
      else()
        set(reference_data "icalrecur_withicu_test.out")
      endif()
      add_test(NAME icalrecurtest-r
        COMMAND ${CMAKE_COMMAND}
        -D test_cmd=${test_cmd}
        -D test_args:string=${test_args}
        -D output_blessed=${CMAKE_SOURCE_DIR}/src/test/${reference_data}
        -D output_test=${CMAKE_BINARY_DIR}/bin/test.out
        -P ${CMAKE_SOURCE_DIR}/cmake/run_test.cmake
      )
      setprops(icalrecurtest-r)
    endif()

    #test non-rscale rrules
    set(test_args "")
    set(reference_data "icalrecur_test.out")
    add_test(NAME icalrecurtest
      COMMAND ${CMAKE_COMMAND}
      -D test_cmd=${test_cmd}
      -D test_args:string=${test_args}
      -D output_blessed=${CMAKE_SOURCE_DIR}/src/test/${reference_data}
      -D output_test=${CMAKE_BINARY_DIR}/bin/test.out
      -P ${CMAKE_SOURCE_DIR}/cmake/run_test.cmake
    )
    setprops(icalrecurtest)
  endif()
endif()