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
21set(TEST_PREFIX "c_glib")
22
23# Make sure gen-cpp and gen-c_glib files can be included
24include_directories("${CMAKE_CURRENT_BINARY_DIR}")
25
26# Create the thrift C test library
27set(testgenc_SOURCES
28    gen-c_glib/t_test_debug_proto_test_types.c
29    gen-c_glib/t_test_enum_test_types.c
30    gen-c_glib/t_test_enum_test_service.c
31    gen-c_glib/t_test_empty_service.c
32    gen-c_glib/t_test_inherited.c
33    gen-c_glib/t_test_optional_required_test_types.c
34    gen-c_glib/t_test_reverse_order_service.c
35    gen-c_glib/t_test_second_service.c
36    gen-c_glib/t_test_service_for_exception_with_a_map.c
37    gen-c_glib/t_test_srv.c
38    gen-c_glib/t_test_thrift_test.c
39    gen-c_glib/t_test_thrift_test_types.c
40    gen-c_glib/t_test_debug_proto_test_types.h
41    gen-c_glib/t_test_enum_test_types.h
42    gen-c_glib/t_test_enum_test_service.h
43    gen-c_glib/t_test_empty_service.h
44    gen-c_glib/t_test_inherited.h
45    gen-c_glib/t_test_optional_required_test_types.h
46    gen-c_glib/t_test_reverse_order_service.h
47    gen-c_glib/t_test_second_service.h
48    gen-c_glib/t_test_service_for_exception_with_a_map.h
49    gen-c_glib/t_test_srv.h
50    gen-c_glib/t_test_thrift_test.h
51    gen-c_glib/t_test_thrift_test_types.h
52)
53
54add_library(testgenc STATIC ${testgenc_SOURCES})
55target_link_libraries(testgenc thrift_c_glib)
56
57
58add_executable(testserialization testserialization.c)
59target_link_libraries(testserialization testgenc)
60target_link_libraries(testserialization thrift_c_glib)
61add_test(NAME testserialization COMMAND testserialization)
62
63add_executable(testapplicationexception testapplicationexception.c)
64target_link_libraries(testapplicationexception thrift_c_glib)
65add_test(NAME testapplicationexception COMMAND testapplicationexception)
66
67add_executable(testtransportsocket testtransportsocket.c)
68target_link_libraries(testtransportsocket thrift_c_glib)
69add_test(NAME testtransportsocket COMMAND testtransportsocket)
70
71add_executable(testbinaryprotocol testbinaryprotocol.c)
72target_link_libraries(testbinaryprotocol thrift_c_glib)
73add_test(NAME testbinaryprotocol COMMAND testbinaryprotocol)
74
75add_executable(testcompactprotocol testcompactprotocol.c)
76target_link_libraries(testcompactprotocol thrift_c_glib)
77add_test(NAME testcompactprotocol COMMAND testcompactprotocol)
78
79add_executable(testbufferedtransport testbufferedtransport.c)
80target_link_libraries(testbufferedtransport thrift_c_glib)
81add_test(NAME testbufferedtransport COMMAND testbufferedtransport)
82
83add_executable(testframedtransport testframedtransport.c)
84target_link_libraries(testframedtransport thrift_c_glib)
85add_test(NAME testframedtransport COMMAND testframedtransport)
86
87add_executable(testfdtransport testfdtransport.c)
88target_link_libraries(testfdtransport thrift_c_glib)
89add_test(NAME testfdtransport COMMAND testfdtransport)
90
91add_executable(testmemorybuffer testmemorybuffer.c)
92target_link_libraries(testmemorybuffer thrift_c_glib)
93add_test(NAME testmemorybuffer COMMAND testmemorybuffer)
94
95add_executable(testsimpleserver testsimpleserver.c)
96target_link_libraries(testsimpleserver thrift_c_glib)
97add_test(NAME testsimpleserver COMMAND testsimpleserver)
98
99add_executable(testdebugproto testdebugproto.c)
100target_link_libraries(testdebugproto testgenc)
101add_test(NAME testdebugproto COMMAND testdebugproto)
102
103add_executable(testoptionalrequired testoptionalrequired.c)
104target_link_libraries(testoptionalrequired testgenc)
105add_test(NAME testoptionalrequired COMMAND testoptionalrequired)
106
107add_executable(testthriftbinaryreadcheck testthriftbinaryreadcheck.c)
108target_link_libraries(testthriftbinaryreadcheck testgenc)
109add_test(NAME testthriftbinaryreadcheck COMMAND testthriftbinaryreadcheck)
110
111add_executable(testthriftbufferedreadcheck testthriftbufferedreadcheck.c)
112target_link_libraries(testthriftbufferedreadcheck testgenc)
113add_test(NAME testthriftbufferedreadcheck COMMAND testthriftbufferedreadcheck)
114
115add_executable(testthriftcompactreadcheck testthriftcompactreadcheck.c)
116target_link_libraries(testthriftcompactreadcheck testgenc)
117add_test(NAME testthriftcompactreadcheck COMMAND testthriftcompactreadcheck)
118
119add_executable(testthriftframedreadcheck testthriftframedreadcheck.c)
120target_link_libraries(testthriftframedreadcheck testgenc)
121add_test(NAME testthriftframedreadcheck COMMAND testthriftframedreadcheck)
122
123add_executable(testthriftfdreadcheck testthriftfdreadcheck.c)
124target_link_libraries(testthriftfdreadcheck testgenc)
125add_test(NAME testthriftfdreadcheck COMMAND testthriftfdreadcheck)
126
127add_executable(testthriftmemorybufferreadcheck testthriftmemorybufferreadcheck.c)
128target_link_libraries(testthriftmemorybufferreadcheck testgenc)
129add_test(NAME testthriftmemorybufferreadcheck COMMAND testthriftmemorybufferreadcheck)
130
131if(WITH_ZLIB)
132  include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}")
133  add_executable(testzlibtransport testzlibtransport.c)
134  target_link_libraries(testzlibtransport testgenc ${ZLIB_LIBRARIES})
135  target_link_libraries(testzlibtransport thrift_c_glib_zlib)
136  add_test(NAME testzlibtransport COMMAND testzlibtransport)
137endif(WITH_ZLIB)
138
139include_directories("${PROJECT_SOURCE_DIR}/test/c_glib/src" "${CMAKE_CURRENT_BINARY_DIR}/gen-c_glib")
140
141add_executable(testthrifttest testthrifttest.c
142    ${PROJECT_SOURCE_DIR}/test/c_glib/src/thrift_test_handler.c
143    ${PROJECT_SOURCE_DIR}/test/c_glib/src/thrift_test_handler.h
144    ${PROJECT_SOURCE_DIR}/test/c_glib/src/thrift_second_service_handler.c
145    ${PROJECT_SOURCE_DIR}/test/c_glib/src/thrift_second_service_handler.h
146    gen-c_glib/t_test_thrift_test_types.h)
147target_link_libraries(testthrifttest testgenc)
148add_test(NAME testthrifttest COMMAND testthrifttest)
149
150
151if(BUILD_CPP)
152    include_directories("${PROJECT_SOURCE_DIR}/lib/cpp/src")
153
154    # Create the thrift C++ test library
155    set(testgenc_cpp_SOURCES
156        gen-cpp/ThriftTest.cpp
157        gen-cpp/ThriftTest_constants.cpp
158        gen-cpp/ThriftTest_types.cpp
159        gen-cpp/ThriftTest.h
160        gen-cpp/ThriftTest_constants.h
161        gen-cpp/ThriftTest_types.h
162    )
163
164    add_library(testgenc_cpp STATIC ${testgenc_cpp_SOURCES})
165    target_link_libraries(testgenc_cpp thrift)
166
167    #HACK: testthrifttestclient.cpp includes ThriftTest.h without gen-*/ prefixes
168    # so we include it here
169    include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-cpp" "${CMAKE_CURRENT_BINARY_DIR}/gen-c_glib")
170
171    add_executable(testthrifttestclient testthrifttestclient.cpp)
172    target_link_libraries(testthrifttestclient testgenc testgenc_cpp ${ZLIB_LIBRARIES})
173    add_test(NAME testthrifttestclient COMMAND testthrifttestclient)
174
175 if(WITH_ZLIB)
176    add_executable(testthrifttestzlibclient testthrifttestzlibclient.cpp)
177    target_link_libraries(testthrifttestzlibclient testgenc testgenc_cpp thriftz thrift_c_glib_zlib ${ZLIB_LIBRARIES})
178    add_test(NAME testthrifttestzlibclient COMMAND testthrifttestzlibclient)
179endif(WITH_ZLIB)
180
181endif(BUILD_CPP)
182
183#
184# Common thrift code generation rules
185#
186
187add_custom_command(OUTPUT
188    gen-c_glib/t_test_debug_proto_test_types.c
189    gen-c_glib/t_test_debug_proto_test_types.h
190    gen-c_glib/t_test_empty_service.c
191    gen-c_glib/t_test_empty_service.h
192    gen-c_glib/t_test_inherited.c
193    gen-c_glib/t_test_inherited.h
194    gen-c_glib/t_test_reverse_order_service.c
195    gen-c_glib/t_test_reverse_order_service.h
196    gen-c_glib/t_test_service_for_exception_with_a_map.c
197    gen-c_glib/t_test_service_for_exception_with_a_map.h
198    gen-c_glib/t_test_srv.c
199    gen-c_glib/t_test_srv.h
200    COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/v0.16/DebugProtoTest.thrift
201)
202
203add_custom_command(OUTPUT
204    gen-c_glib/t_test_enum_test_types.c
205    gen-c_glib/t_test_enum_test_types.h
206    gen-c_glib/t_test_enum_test_service.c
207    gen-c_glib/t_test_enum_test_service.h
208    COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/EnumTest.thrift
209)
210
211add_custom_command(OUTPUT
212    gen-c_glib/t_test_optional_required_test_types.c
213    gen-c_glib/t_test_optional_required_test_types.h
214    COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/OptionalRequiredTest.thrift
215)
216
217add_custom_command(OUTPUT
218    gen-c_glib/t_test_second_service.c
219    gen-c_glib/t_test_thrift_test.c
220    gen-c_glib/t_test_thrift_test_types.c
221    gen-c_glib/t_test_second_service.h
222    gen-c_glib/t_test_thrift_test.h
223    gen-c_glib/t_test_thrift_test_types.h
224    COMMAND ${THRIFT_COMPILER} --gen c_glib ${PROJECT_SOURCE_DIR}/test/v0.16/ThriftTest.thrift
225)
226
227add_custom_command(OUTPUT
228    gen-cpp/ThriftTest.cpp
229    gen-cpp/ThriftTest_constants.cpp
230    gen-cpp/ThriftTest_types.cpp
231    gen-cpp/ThriftTest.h
232    gen-cpp/ThriftTest_constants.h
233    gen-cpp/ThriftTest_types.h
234    COMMAND ${THRIFT_COMPILER} --gen cpp ${PROJECT_SOURCE_DIR}/test/v0.16/ThriftTest.thrift
235)
236
237# TODO: Add memory checks using ctest_memcheck or similar
238