blob: 8587fa8278021deeed4e7f4dc753c547078e3e3d [file] [log] [blame]
Pascal Bachd5f87e12014-12-12 15:59:17 +01001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
Pascal Bachd5f87e12014-12-12 15:59:17 +010020# Find required packages
21set(Boost_USE_STATIC_LIBS ON) # Force the use of static boost test framework
Ben Craig1684c422015-04-24 08:52:44 -050022find_package(Boost 1.53.0 REQUIRED COMPONENTS chrono system thread unit_test_framework)
Nobuaki Sukegawac444fb52015-01-02 23:16:55 +090023include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
Pascal Bachd5f87e12014-12-12 15:59:17 +010024
25#Make sure gen-cpp files can be included
26include_directories("${CMAKE_CURRENT_BINARY_DIR}")
27
28# Create the thrift C++ test library
29set(testgencpp_SOURCES
30 gen-cpp/DebugProtoTest_types.cpp
31 gen-cpp/DebugProtoTest_types.h
32 gen-cpp/EnumTest_types.cpp
33 gen-cpp/EnumTest_types.h
34 gen-cpp/OptionalRequiredTest_types.cpp
35 gen-cpp/OptionalRequiredTest_types.h
36 gen-cpp/Recursive_types.cpp
37 gen-cpp/Recursive_types.h
38 gen-cpp/ThriftTest_types.cpp
39 gen-cpp/ThriftTest_types.h
40 gen-cpp/TypedefTest_types.cpp
41 gen-cpp/TypedefTest_types.h
42 ThriftTest_extras.cpp
43 DebugProtoTest_extras.cpp
44)
45
46add_library(testgencpp STATIC ${testgencpp_SOURCES})
Pascal Bachd5f87e12014-12-12 15:59:17 +010047
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +090048set(testgencpp_cob_SOURCES
Pascal Bachd5f87e12014-12-12 15:59:17 +010049 gen-cpp/ChildService.cpp
50 gen-cpp/ChildService.h
Ben Craig1684c422015-04-24 08:52:44 -050051 gen-cpp/EmptyService.cpp
52 gen-cpp/EmptyService.h
Pascal Bachd5f87e12014-12-12 15:59:17 +010053 gen-cpp/ParentService.cpp
54 gen-cpp/ParentService.h
55 gen-cpp/proc_types.cpp
56 gen-cpp/proc_types.h
57)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +090058add_library(testgencpp_cob STATIC ${testgencpp_cob_SOURCES})
Pascal Bachd5f87e12014-12-12 15:59:17 +010059
60
61add_executable(Benchmark Benchmark.cpp)
62target_link_libraries(Benchmark testgencpp)
Jim King9de9b1f2015-04-30 16:03:34 -040063LINK_AGAINST_THRIFT_LIBRARY(Benchmark thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +010064add_test(NAME Benchmark COMMAND Benchmark)
65
66set(UnitTest_SOURCES
67 UnitTestMain.cpp
68 TMemoryBufferTest.cpp
69 TBufferBaseTest.cpp
70 Base64Test.cpp
71 ToStringTest.cpp
72 TypedefTest.cpp
Roger Meier3815e0b2015-04-04 16:26:30 +020073 TServerSocketTest.cpp
Ben Craig1684c422015-04-24 08:52:44 -050074 TServerTransportTest.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +010075)
76
Roger Meiera6b66332015-05-15 15:21:50 +020077if(NOT WITH_BOOSTTHREADS AND NOT WITH_STDTHREADS AND NOT MSVC)
Pascal Bachd5f87e12014-12-12 15:59:17 +010078 list(APPEND UnitTest_SOURCES RWMutexStarveTest.cpp)
79endif()
80
81add_executable(UnitTests ${UnitTest_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -040082target_link_libraries(UnitTests testgencpp ${Boost_LIBRARIES})
83LINK_AGAINST_THRIFT_LIBRARY(UnitTests thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +010084add_test(NAME UnitTests COMMAND UnitTests)
85
Ben Craig1684c422015-04-24 08:52:44 -050086add_executable(TSocketInterruptTest TSocketInterruptTest.cpp)
87target_link_libraries(TSocketInterruptTest
88 testgencpp
89 ${Boost_LIBRARIES}
Ben Craig1684c422015-04-24 08:52:44 -050090)
Jim King9de9b1f2015-04-30 16:03:34 -040091LINK_AGAINST_THRIFT_LIBRARY(TSocketInterruptTest thrift)
Thomas Bartelmess9e78ed82015-05-01 13:57:44 -040092if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Ben Craig1684c422015-04-24 08:52:44 -050093target_link_libraries(TSocketInterruptTest -lrt)
94endif ()
95add_test(NAME TSocketInterruptTest COMMAND TSocketInterruptTest)
96
97add_executable(TServerIntegrationTest TServerIntegrationTest.cpp)
98target_link_libraries(TServerIntegrationTest
99 testgencpp_cob
100 ${Boost_LIBRARIES}
101)
Jim King9de9b1f2015-04-30 16:03:34 -0400102LINK_AGAINST_THRIFT_LIBRARY(TServerIntegrationTest thrift)
Thomas Bartelmess9e78ed82015-05-01 13:57:44 -0400103if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Ben Craig1684c422015-04-24 08:52:44 -0500104target_link_libraries(TServerIntegrationTest -lrt)
105endif ()
106add_test(NAME TServerIntegrationTest COMMAND TServerIntegrationTest)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100107
108if(WITH_ZLIB)
109add_executable(TransportTest TransportTest.cpp)
110target_link_libraries(TransportTest
111 testgencpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100112 ${Boost_LIBRARIES}
113 ${ZLIB_LIBRARIES}
114)
Jim King9de9b1f2015-04-30 16:03:34 -0400115LINK_AGAINST_THRIFT_LIBRARY(TransportTest thrift)
116LINK_AGAINST_THRIFT_LIBRARY(TransportTest thriftz)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100117add_test(NAME TransportTest COMMAND TransportTest)
118
119add_executable(ZlibTest ZlibTest.cpp)
120target_link_libraries(ZlibTest
121 testgencpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100122 ${Boost_LIBRARIES}
123 ${ZLIB_LIBRARIES}
124)
Jim King9de9b1f2015-04-30 16:03:34 -0400125LINK_AGAINST_THRIFT_LIBRARY(ZlibTest thrift)
126LINK_AGAINST_THRIFT_LIBRARY(ZlibTest thriftz)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100127add_test(NAME ZlibTest COMMAND ZlibTest)
128endif(WITH_ZLIB)
129
130
131add_executable(EnumTest EnumTest.cpp)
132target_link_libraries(EnumTest
133 testgencpp
134 ${Boost_LIBRARIES}
135)
Jim King9de9b1f2015-04-30 16:03:34 -0400136LINK_AGAINST_THRIFT_LIBRARY(EnumTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100137add_test(NAME EnumTest COMMAND EnumTest)
138
Jim King9de9b1f2015-04-30 16:03:34 -0400139if(HAVE_GETOPT_H)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100140add_executable(TFileTransportTest TFileTransportTest.cpp)
141target_link_libraries(TFileTransportTest
142 testgencpp
143 ${Boost_LIBRARIES}
144)
Jim King9de9b1f2015-04-30 16:03:34 -0400145LINK_AGAINST_THRIFT_LIBRARY(TFileTransportTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100146add_test(NAME TFileTransportTest COMMAND TFileTransportTest)
Jim King9de9b1f2015-04-30 16:03:34 -0400147endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100148
149add_executable(TFDTransportTest TFDTransportTest.cpp)
Jim King9de9b1f2015-04-30 16:03:34 -0400150LINK_AGAINST_THRIFT_LIBRARY(TFDTransportTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100151add_test(NAME TFDTransportTest COMMAND TFDTransportTest)
152
153add_executable(TPipedTransportTest TPipedTransportTest.cpp)
Jim King9de9b1f2015-04-30 16:03:34 -0400154LINK_AGAINST_THRIFT_LIBRARY(TPipedTransportTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100155add_test(NAME TPipedTransportTest COMMAND TPipedTransportTest)
156
157set(AllProtocolsTest_SOURCES
158 AllProtocolTests.cpp
159 AllProtocolTests.tcc
160 GenericHelpers
161 )
162
163add_executable(AllProtocolsTest ${AllProtocolsTest_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400164target_link_libraries(AllProtocolsTest testgencpp)
165LINK_AGAINST_THRIFT_LIBRARY(AllProtocolsTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100166add_test(NAME AllProtocolsTest COMMAND AllProtocolsTest)
167
Jim King9de9b1f2015-04-30 16:03:34 -0400168# The debug run-time in Windows asserts on isprint() with negative inputs
169if (NOT MSVC OR (MSVC AND CMAKE_BUILD_TYPE EQUAL "DEBUG"))
Pascal Bachd5f87e12014-12-12 15:59:17 +0100170add_executable(DebugProtoTest DebugProtoTest.cpp)
Jim King9de9b1f2015-04-30 16:03:34 -0400171target_link_libraries(DebugProtoTest testgencpp)
172LINK_AGAINST_THRIFT_LIBRARY(DebugProtoTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100173add_test(NAME DebugProtoTest COMMAND DebugProtoTest)
Jim King9de9b1f2015-04-30 16:03:34 -0400174endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100175
176add_executable(JSONProtoTest JSONProtoTest.cpp)
Jim King9de9b1f2015-04-30 16:03:34 -0400177target_link_libraries(JSONProtoTest testgencpp)
178LINK_AGAINST_THRIFT_LIBRARY(JSONProtoTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100179add_test(NAME JSONProtoTest COMMAND JSONProtoTest)
180
181add_executable(OptionalRequiredTest OptionalRequiredTest.cpp)
Jim King9de9b1f2015-04-30 16:03:34 -0400182target_link_libraries(OptionalRequiredTest testgencpp)
183LINK_AGAINST_THRIFT_LIBRARY(OptionalRequiredTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100184add_test(NAME OptionalRequiredTest COMMAND OptionalRequiredTest)
185
186add_executable(RecursiveTest RecursiveTest.cpp)
Jim King9de9b1f2015-04-30 16:03:34 -0400187target_link_libraries(RecursiveTest testgencpp)
188LINK_AGAINST_THRIFT_LIBRARY(RecursiveTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100189add_test(NAME RecursiveTest COMMAND RecursiveTest)
190
191add_executable(SpecializationTest SpecializationTest.cpp)
Jim King9de9b1f2015-04-30 16:03:34 -0400192target_link_libraries(SpecializationTest testgencpp)
193LINK_AGAINST_THRIFT_LIBRARY(SpecializationTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100194add_test(NAME SpecializationTest COMMAND SpecializationTest)
195
196set(concurrency_test_SOURCES
197 concurrency/Tests.cpp
198 concurrency/ThreadFactoryTests.h
199 concurrency/ThreadManagerTests.h
200 concurrency/TimerManagerTests.h
201)
202add_executable(concurrency_test ${concurrency_test_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400203LINK_AGAINST_THRIFT_LIBRARY(concurrency_test thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100204add_test(NAME concurrency_test COMMAND concurrency_test)
205
206set(link_test_SOURCES
207 link/LinkTest.cpp
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900208 gen-cpp/ParentService.h
Pascal Bachd5f87e12014-12-12 15:59:17 +0100209 link/TemplatedService1.cpp
210 link/TemplatedService2.cpp
Pascal Bachd5f87e12014-12-12 15:59:17 +0100211)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900212
Pascal Bachd5f87e12014-12-12 15:59:17 +0100213add_executable(link_test ${link_test_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400214target_link_libraries(link_test testgencpp_cob)
215LINK_AGAINST_THRIFT_LIBRARY(link_test thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100216add_test(NAME link_test COMMAND link_test)
217
218if(WITH_LIBEVENT)
219set(processor_test_SOURCES
220 processor/ProcessorTest.cpp
221 processor/EventLog.cpp
222 processor/ServerThread.cpp
223 processor/EventLog.h
224 processor/Handlers.h
225 processor/ServerThread.h
226)
227add_executable(processor_test ${processor_test_SOURCES})
228target_link_libraries(processor_test
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900229 testgencpp_cob
Pascal Bachd5f87e12014-12-12 15:59:17 +0100230 ${Boost_LIBRARIES}
231)
Jim King9de9b1f2015-04-30 16:03:34 -0400232LINK_AGAINST_THRIFT_LIBRARY(processor_test thrift)
233LINK_AGAINST_THRIFT_LIBRARY(processor_test thriftnb)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100234add_test(NAME processor_test COMMAND processor_test)
Nobuaki Sukegawa8016af82015-01-02 23:14:22 +0900235
236set(TNonblockingServerTest_SOURCES TNonblockingServerTest.cpp)
237add_executable(TNonblockingServerTest ${TNonblockingServerTest_SOURCES})
238include_directories(${LIBEVENT_INCLUDE_DIRS})
239target_link_libraries(TNonblockingServerTest
240 testgencpp_cob
Nobuaki Sukegawa8016af82015-01-02 23:14:22 +0900241 ${LIBEVENT_LIBRARIES}
242 ${Boost_LIBRARIES}
243)
Jim King9de9b1f2015-04-30 16:03:34 -0400244LINK_AGAINST_THRIFT_LIBRARY(TNonblockingServerTest thrift)
245LINK_AGAINST_THRIFT_LIBRARY(TNonblockingServerTest thriftnb)
Nobuaki Sukegawa8016af82015-01-02 23:14:22 +0900246add_test(NAME TNonblockingServerTest COMMAND TNonblockingServerTest)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100247endif()
248
249if(OPENSSL_FOUND AND WITH_OPENSSL)
250add_executable(OpenSSLManualInitTest OpenSSLManualInitTest.cpp)
251target_link_libraries(OpenSSLManualInitTest
Pascal Bachd5f87e12014-12-12 15:59:17 +0100252 ${OPENSSL_LIBRARIES}
253 ${Boost_LIBRARIES}
254)
Jim King9de9b1f2015-04-30 16:03:34 -0400255LINK_AGAINST_THRIFT_LIBRARY(OpenSSLManualInitTest thrift)
Pascal Bachd5f87e12014-12-12 15:59:17 +0100256add_test(NAME OpenSSLManualInitTest COMMAND OpenSSLManualInitTest)
257endif()
258
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900259if(WITH_QT4)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900260set(CMAKE_AUTOMOC ON)
261find_package(Qt4 REQUIRED COMPONENTS QtTest)
262set(TQTcpServerTest_SOURCES
263 qt/TQTcpServerTest.cpp
264)
265add_executable(TQTcpServerTest ${TQTcpServerTest_SOURCES})
Jim King9de9b1f2015-04-30 16:03:34 -0400266target_link_libraries(TQTcpServerTest testgencpp_cob thriftqt Qt4::QtTest)
267LINK_AGAINST_THRIFT_LIBRARY(TQTcpServerTest thrift)
Nobuaki Sukegawa6304a532014-12-18 01:30:58 +0900268add_test(NAME TQTcpServerTest COMMAND TQTcpServerTest)
269endif()
270
Nobuaki Sukegawa66228772014-12-07 21:45:33 +0900271if(WITH_QT5)
272add_subdirectory(qt)
273endif()
274
Pascal Bachd5f87e12014-12-12 15:59:17 +0100275#
276# Common thrift code generation rules
277#
278
279
Ben Craig1684c422015-04-24 08:52:44 -0500280add_custom_command(OUTPUT gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h gen-cpp/EmptyService.cpp gen-cpp/EmptyService.h
Pascal Bachd5f87e12014-12-12 15:59:17 +0100281 COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
282)
283
284add_custom_command(OUTPUT gen-cpp/EnumTest_types.cpp gen-cpp/EnumTest_types.h
285 COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/EnumTest.thrift
286)
287
288add_custom_command(OUTPUT gen-cpp/TypedefTest_types.cpp gen-cpp/TypedefTest_types.h
289 COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/TypedefTest.thrift
290)
291
292add_custom_command(OUTPUT gen-cpp/OptionalRequiredTest_types.cpp gen-cpp/OptionalRequiredTest_types.h
293 COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
294)
295
296add_custom_command(OUTPUT gen-cpp/Recursive_types.cpp gen-cpp/Recursive_types.h
297 COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/Recursive.thrift
298)
299
300add_custom_command(OUTPUT gen-cpp/Service.cpp gen-cpp/StressTest_types.cpp
301 COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/StressTest.thrift
302)
303
304add_custom_command(OUTPUT gen-cpp/SecondService.cpp gen-cpp/ThriftTest_constants.cpp gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_types.h
305 COMMAND thrift-compiler --gen cpp:dense ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
306)
307
308add_custom_command(OUTPUT gen-cpp/ChildService.cpp gen-cpp/ChildService.h gen-cpp/ParentService.cpp gen-cpp/ParentService.h gen-cpp/proc_types.cpp gen-cpp/proc_types.h
309 COMMAND thrift-compiler --gen cpp:templates,cob_style ${CMAKE_CURRENT_SOURCE_DIR}/processor/proc.thrift
310)