1# 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 20# Unit tests still require boost 21include(BoostMacros) 22REQUIRE_BOOST_HEADERS() 23set(BOOST_COMPONENTS filesystem thread unit_test_framework chrono) 24REQUIRE_BOOST_LIBRARIES(BOOST_COMPONENTS) 25 26include(ThriftMacros) 27 28# Make sure gen-cpp files can be included 29include_directories("${CMAKE_CURRENT_BINARY_DIR}") 30 31# Create the thrift C++ test library 32set(testgencpp_SOURCES 33 gen-cpp/AnnotationTest_types.cpp 34 gen-cpp/AnnotationTest_types.h 35 gen-cpp/DebugProtoTest_types.cpp 36 gen-cpp/DebugProtoTest_types.h 37 gen-cpp/EnumTest_types.cpp 38 gen-cpp/EnumTest_types.h 39 gen-cpp/OptionalRequiredTest_types.cpp 40 gen-cpp/OptionalRequiredTest_types.h 41 gen-cpp/Recursive_types.cpp 42 gen-cpp/Recursive_types.h 43 gen-cpp/ThriftTest_types.cpp 44 gen-cpp/ThriftTest_types.h 45 gen-cpp/OneWayTest_types.h 46 gen-cpp/OneWayService.cpp 47 gen-cpp/OneWayService.h 48 gen-cpp/TypedefTest_types.cpp 49 gen-cpp/TypedefTest_types.h 50 ThriftTest_extras.cpp 51 DebugProtoTest_extras.cpp 52) 53 54add_library(testgencpp STATIC ${testgencpp_SOURCES}) 55 56set(testgencpp_cob_SOURCES 57 gen-cpp/ChildService.cpp 58 gen-cpp/ChildService.h 59 gen-cpp/EmptyService.cpp 60 gen-cpp/EmptyService.h 61 gen-cpp/ParentService.cpp 62 gen-cpp/ParentService.h 63 gen-cpp/proc_types.cpp 64 gen-cpp/proc_types.h 65) 66add_library(testgencpp_cob STATIC ${testgencpp_cob_SOURCES}) 67 68add_executable(Benchmark Benchmark.cpp) 69target_link_libraries(Benchmark testgencpp) 70target_link_libraries(Benchmark thrift) 71add_test(NAME Benchmark COMMAND Benchmark) 72target_link_libraries(Benchmark testgencpp) 73 74set(UnitTest_SOURCES 75 UnitTestMain.cpp 76 OneWayHTTPTest.cpp 77 TMemoryBufferTest.cpp 78 TBufferBaseTest.cpp 79 Base64Test.cpp 80 ToStringTest.cpp 81 TypedefTest.cpp 82 TServerSocketTest.cpp 83 TServerTransportTest.cpp 84 ThrifttReadCheckTests.cpp 85) 86 87add_executable(UnitTests ${UnitTest_SOURCES}) 88target_link_libraries(UnitTests testgencpp ${Boost_LIBRARIES}) 89target_link_libraries(UnitTests thrift) 90add_test(NAME UnitTests COMMAND UnitTests) 91if(MSVC) 92 # Disable C4503: decorated name length exceeded, name was truncated 93 # 'insanity' results in very long decorated names 94 set_property( TARGET UnitTests APPEND_STRING PROPERTY COMPILE_FLAGS /wd4503 ) 95endif() 96 97 98set( TInterruptTest_SOURCES 99 TSocketInterruptTest.cpp 100 TSSLSocketInterruptTest.cpp 101) 102if (WIN32) 103 list(APPEND TInterruptTest_SOURCES 104 TPipeInterruptTest.cpp 105 ) 106endif() 107add_executable(TInterruptTest ${TInterruptTest_SOURCES}) 108target_link_libraries(TInterruptTest 109 testgencpp 110 ${Boost_LIBRARIES} 111) 112target_link_libraries(TInterruptTest thrift) 113if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT MINGW) 114 target_link_libraries(TInterruptTest -lrt) 115endif () 116add_test(NAME TInterruptTest COMMAND TInterruptTest -- "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys") 117 118add_executable(TServerIntegrationTest TServerIntegrationTest.cpp) 119target_link_libraries(TServerIntegrationTest 120 testgencpp_cob 121 ${Boost_LIBRARIES} 122) 123target_link_libraries(TServerIntegrationTest thrift) 124if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT MINGW) 125 target_link_libraries(TServerIntegrationTest -lrt) 126endif () 127add_test(NAME TServerIntegrationTest COMMAND TServerIntegrationTest) 128 129if(WITH_ZLIB) 130include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") 131add_executable(TransportTest TransportTest.cpp) 132target_link_libraries(TransportTest 133 testgencpp 134 ${Boost_LIBRARIES} 135 ${ZLIB_LIBRARIES} 136) 137target_link_libraries(TransportTest thrift) 138target_link_libraries(TransportTest thriftz) 139add_test(NAME TransportTest COMMAND TransportTest) 140 141add_executable(ZlibTest ZlibTest.cpp) 142target_link_libraries(ZlibTest 143 testgencpp 144 ${Boost_LIBRARIES} 145 ${ZLIB_LIBRARIES} 146) 147target_link_libraries(ZlibTest thrift) 148target_link_libraries(ZlibTest thriftz) 149add_test(NAME ZlibTest COMMAND ZlibTest) 150endif(WITH_ZLIB) 151 152add_executable(AnnotationTest AnnotationTest.cpp) 153target_link_libraries(AnnotationTest 154 testgencpp 155 ${Boost_LIBRARIES} 156) 157target_link_libraries(AnnotationTest thrift) 158add_test(NAME AnnotationTest COMMAND AnnotationTest) 159 160add_executable(EnumTest EnumTest.cpp) 161target_link_libraries(EnumTest 162 testgencpp 163 ${Boost_LIBRARIES} 164) 165target_link_libraries(EnumTest thrift) 166add_test(NAME EnumTest COMMAND EnumTest) 167 168if(HAVE_GETOPT_H) 169add_executable(TFileTransportTest TFileTransportTest.cpp) 170target_link_libraries(TFileTransportTest 171 testgencpp 172 ${Boost_LIBRARIES} 173) 174target_link_libraries(TFileTransportTest thrift) 175add_test(NAME TFileTransportTest COMMAND TFileTransportTest) 176endif() 177 178add_executable(TFDTransportTest TFDTransportTest.cpp) 179target_link_libraries(TFDTransportTest 180 ${Boost_LIBRARIES} 181) 182target_link_libraries(TFDTransportTest thrift) 183add_test(NAME TFDTransportTest COMMAND TFDTransportTest) 184 185add_executable(TPipedTransportTest TPipedTransportTest.cpp) 186target_link_libraries(TPipedTransportTest 187 ${Boost_LIBRARIES} 188) 189target_link_libraries(TPipedTransportTest thrift) 190add_test(NAME TPipedTransportTest COMMAND TPipedTransportTest) 191 192set(AllProtocolsTest_SOURCES 193 AllProtocolTests.cpp 194 AllProtocolTests.tcc 195 GenericHelpers.h 196) 197 198add_executable(AllProtocolsTest ${AllProtocolsTest_SOURCES}) 199target_link_libraries(AllProtocolsTest 200 testgencpp 201 ${Boost_LIBRARIES} 202) 203target_link_libraries(AllProtocolsTest thrift) 204add_test(NAME AllProtocolsTest COMMAND AllProtocolsTest) 205 206# The debug run-time in Windows asserts on isprint() with negative inputs 207if (NOT MSVC OR (MSVC AND CMAKE_BUILD_TYPE EQUAL "DEBUG")) 208 add_executable(DebugProtoTest DebugProtoTest.cpp) 209 target_link_libraries(DebugProtoTest 210 testgencpp 211 ${Boost_LIBRARIES} 212 ) 213 target_link_libraries(DebugProtoTest thrift) 214 add_test(NAME DebugProtoTest COMMAND DebugProtoTest) 215endif() 216 217add_executable(JSONProtoTest JSONProtoTest.cpp) 218target_link_libraries(JSONProtoTest 219 testgencpp 220 ${Boost_LIBRARIES} 221) 222target_link_libraries(JSONProtoTest thrift) 223add_test(NAME JSONProtoTest COMMAND JSONProtoTest) 224 225add_executable(OptionalRequiredTest OptionalRequiredTest.cpp) 226target_link_libraries(OptionalRequiredTest 227 testgencpp 228 ${Boost_LIBRARIES} 229) 230target_link_libraries(OptionalRequiredTest thrift) 231add_test(NAME OptionalRequiredTest COMMAND OptionalRequiredTest) 232 233add_executable(RecursiveTest RecursiveTest.cpp) 234target_link_libraries(RecursiveTest 235 testgencpp 236 ${Boost_LIBRARIES} 237) 238target_link_libraries(RecursiveTest thrift) 239add_test(NAME RecursiveTest COMMAND RecursiveTest) 240 241add_executable(SpecializationTest SpecializationTest.cpp) 242target_link_libraries(SpecializationTest 243 testgencpp 244 ${Boost_LIBRARIES} 245) 246target_link_libraries(SpecializationTest thrift) 247add_test(NAME SpecializationTest COMMAND SpecializationTest) 248 249set(concurrency_test_SOURCES 250 concurrency/Tests.cpp 251 concurrency/ThreadFactoryTests.h 252 concurrency/ThreadManagerTests.h 253 concurrency/TimerManagerTests.h 254) 255add_executable(concurrency_test ${concurrency_test_SOURCES}) 256target_link_libraries(concurrency_test thrift) 257add_test(NAME concurrency_test COMMAND concurrency_test) 258 259set(link_test_SOURCES 260 link/LinkTest.cpp 261 gen-cpp/ParentService.h 262 link/TemplatedService1.cpp 263 link/TemplatedService2.cpp 264) 265 266add_executable(link_test ${link_test_SOURCES}) 267target_link_libraries(link_test testgencpp_cob) 268target_link_libraries(link_test thrift) 269target_link_libraries(link_test testgencpp) 270add_test(NAME link_test COMMAND link_test) 271 272if(WITH_LIBEVENT) 273 set(processor_test_SOURCES 274 processor/ProcessorTest.cpp 275 processor/EventLog.cpp 276 processor/ServerThread.cpp 277 processor/EventLog.h 278 processor/Handlers.h 279 processor/ServerThread.h 280 ) 281 add_executable(processor_test ${processor_test_SOURCES}) 282 target_link_libraries(processor_test 283 testgencpp_cob 284 ${Boost_LIBRARIES} 285 ) 286 target_link_libraries(processor_test thriftnb) 287 add_test(NAME processor_test COMMAND processor_test) 288 289 set(TNonblockingServerTest_SOURCES TNonblockingServerTest.cpp) 290 add_executable(TNonblockingServerTest ${TNonblockingServerTest_SOURCES}) 291 include_directories(${LIBEVENT_INCLUDE_DIRS}) 292 target_link_libraries(TNonblockingServerTest 293 testgencpp_cob 294 ${Boost_LIBRARIES} 295 ) 296 target_link_libraries(TNonblockingServerTest thriftnb) 297 add_test(NAME TNonblockingServerTest COMMAND TNonblockingServerTest) 298 299 if(OPENSSL_FOUND AND WITH_OPENSSL) 300 set(TNonblockingSSLServerTest_SOURCES TNonblockingSSLServerTest.cpp) 301 add_executable(TNonblockingSSLServerTest ${TNonblockingSSLServerTest_SOURCES}) 302 include_directories(${LIBEVENT_INCLUDE_DIRS}) 303 target_link_libraries(TNonblockingSSLServerTest 304 testgencpp_cob 305 ${Boost_LIBRARIES} 306 ) 307 target_link_libraries(TNonblockingSSLServerTest thriftnb) 308 add_test(NAME TNonblockingSSLServerTest COMMAND TNonblockingSSLServerTest -- "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys") 309 endif(OPENSSL_FOUND AND WITH_OPENSSL) 310endif() 311 312if(OPENSSL_FOUND AND WITH_OPENSSL) 313add_executable(OpenSSLManualInitTest OpenSSLManualInitTest.cpp) 314target_link_libraries(OpenSSLManualInitTest 315 ${OPENSSL_LIBRARIES} 316 ${Boost_LIBRARIES} 317) 318target_link_libraries(OpenSSLManualInitTest thrift) 319add_test(NAME OpenSSLManualInitTest COMMAND OpenSSLManualInitTest) 320 321add_executable(SecurityTest SecurityTest.cpp) 322target_link_libraries(SecurityTest 323 testgencpp 324 ${Boost_LIBRARIES} 325) 326target_link_libraries(SecurityTest thrift) 327if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT MINGW) 328 target_link_libraries(SecurityTest -lrt) 329endif () 330add_test(NAME SecurityTest COMMAND SecurityTest -- "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys") 331 332add_executable(SecurityFromBufferTest SecurityFromBufferTest.cpp) 333target_link_libraries(SecurityFromBufferTest 334 testgencpp 335 ${Boost_LIBRARIES} 336) 337target_link_libraries(SecurityFromBufferTest thrift) 338if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT MINGW) 339 target_link_libraries(SecurityFromBufferTest -lrt) 340endif () 341add_test(NAME SecurityFromBufferTest COMMAND SecurityFromBufferTest -- "${CMAKE_CURRENT_SOURCE_DIR}/../../../test/keys") 342 343endif() 344 345if(WITH_QT5) 346 add_subdirectory(qt) 347endif() 348 349# 350# Common thrift code generation rules 351# 352 353add_custom_command(OUTPUT gen-cpp/AnnotationTest_constants.cpp 354 gen-cpp/AnnotationTest_constants.h 355 gen-cpp/AnnotationTest_types.cpp 356 gen-cpp/AnnotationTest_types.h 357 gen-cpp/foo_service.cpp 358 gen-cpp/foo_service.h 359 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/AnnotationTest.thrift 360) 361 362add_custom_command(OUTPUT gen-cpp/DebugProtoTest_types.cpp gen-cpp/DebugProtoTest_types.h gen-cpp/EmptyService.cpp gen-cpp/EmptyService.h 363 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/v0.16/DebugProtoTest.thrift 364) 365 366add_custom_command(OUTPUT gen-cpp/EnumTest_types.cpp gen-cpp/EnumTest_types.h 367 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/EnumTest.thrift 368) 369 370add_custom_command(OUTPUT gen-cpp/TypedefTest_types.cpp gen-cpp/TypedefTest_types.h 371 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/TypedefTest.thrift 372) 373 374add_custom_command(OUTPUT gen-cpp/OptionalRequiredTest_types.cpp gen-cpp/OptionalRequiredTest_types.h 375 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift 376) 377 378add_custom_command(OUTPUT gen-cpp/Recursive_types.cpp gen-cpp/Recursive_types.h 379 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/Recursive.thrift 380) 381 382add_custom_command(OUTPUT gen-cpp/Service.cpp gen-cpp/StressTest_types.cpp 383 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/StressTest.thrift 384) 385 386add_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 387 COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/v0.16/ThriftTest.thrift 388) 389 390add_custom_command(OUTPUT gen-cpp/OneWayService.cpp gen-cpp/OneWayTest_types.h gen-cpp/OneWayService.h 391 COMMAND ${THRIFT_COMPILER} --gen cpp ${CMAKE_CURRENT_SOURCE_DIR}/OneWayTest.thrift 392) 393 394add_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 395 COMMAND ${THRIFT_COMPILER} --gen cpp:templates,cob_style ${CMAKE_CURRENT_SOURCE_DIR}/processor/proc.thrift 396) 397