blob: 5c4b931570d389028ce3701994053334d747ac60 [file] [log] [blame]
zeshuai007037753e2020-11-30 11:16:10 +08001/*
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/* test a C client with a C++ server (that makes sense...) */
21
22#include <signal.h>
23#include <sys/types.h>
24#include <sys/wait.h>
25#include <thrift/protocol/TBinaryProtocol.h>
26#include <thrift/protocol/TDebugProtocol.h>
27#include <thrift/server/TSimpleServer.h>
28#include <memory>
29#include <thrift/transport/TServerSocket.h>
30#include <thrift/transport/TZlibTransport.h>
31#include "ThriftTest.h"
32#include "ThriftTest_types.h"
33
34#include <iostream>
35#include <map>
36#include <set>
37#include <string>
38#include <vector>
39
40using namespace apache::thrift;
41using namespace apache::thrift::concurrency;
42using namespace apache::thrift::protocol;
43using namespace apache::thrift::server;
44using namespace apache::thrift::transport;
45
46using namespace thrift::test;
47
48using std::cout;
49using std::endl;
50using std::fixed;
51using std::make_pair;
52using std::map;
53using std::set;
54using std::string;
55using std::vector;
56
57#define TEST_PORT 9980
58
59// Extra functions required for ThriftTest_types to work
60namespace thrift { namespace test {
61
62bool Insanity::operator<(thrift::test::Insanity const& other) const {
63 using apache::thrift::ThriftDebugString;
64 return ThriftDebugString(*this) < ThriftDebugString(other);
65}
66
67}}
68
69class TestHandler : public ThriftTestIf {
70 public:
71 TestHandler() = default;
72
73 void testVoid() override {
74 cout << "[C -> C++] testVoid()" << endl;
75 }
76
77 void testString(string& out, const string &thing) override {
78 cout << "[C -> C++] testString(\"" << thing << "\")" << endl;
79 out = thing;
80 }
81
82 bool testBool(const bool thing) override {
83 cout << "[C -> C++] testBool(" << (thing ? "true" : "false") << ")" << endl;
84 return thing;
85 }
86 int8_t testByte(const int8_t thing) override {
87 cout << "[C -> C++] testByte(" << (int)thing << ")" << endl;
88 return thing;
89 }
90 int32_t testI32(const int32_t thing) override {
91 cout << "[C -> C++] testI32(" << thing << ")" << endl;
92 return thing;
93 }
94
95 int64_t testI64(const int64_t thing) override {
96 cout << "[C -> C++] testI64(" << thing << ")" << endl;
97 return thing;
98 }
99
100 double testDouble(const double thing) override {
101 cout.precision(6);
102 cout << "[C -> C++] testDouble(" << fixed << thing << ")" << endl;
103 return thing;
104 }
105
106 void testBinary(string& out, const string &thing) override {
107 cout << "[C -> C++] testBinary(\"" << thing << "\")" << endl;
108 out = thing;
109 }
110
111 void testStruct(Xtruct& out, const Xtruct &thing) override {
112 cout << "[C -> C++] testStruct({\"" << thing.string_thing << "\", " << (int)thing.byte_thing << ", " << thing.i32_thing << ", " << thing.i64_thing << "})" << endl;
113 out = thing;
114 }
115
116 void testNest(Xtruct2& out, const Xtruct2& nest) override {
117 const Xtruct &thing = nest.struct_thing;
118 cout << "[C -> C++] testNest({" << (int)nest.byte_thing << ", {\"" << thing.string_thing << "\", " << (int)thing.byte_thing << ", " << thing.i32_thing << ", " << thing.i64_thing << "}, " << nest.i32_thing << "})" << endl;
119 out = nest;
120 }
121
122 void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) override {
123 cout << "[C -> C++] testMap({";
124 map<int32_t, int32_t>::const_iterator m_iter;
125 bool first = true;
126 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
127 if (first) {
128 first = false;
129 } else {
130 cout << ", ";
131 }
132 cout << m_iter->first << " => " << m_iter->second;
133 }
134 cout << "})" << endl;
135 out = thing;
136 }
137
138 void testStringMap(map<std::string, std::string> &out, const map<std::string, std::string> &thing) override {
139 cout << "[C -> C++] testStringMap({";
140 map<std::string, std::string>::const_iterator m_iter;
141 bool first = true;
142 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
143 if (first) {
144 first = false;
145 } else {
146 cout << ", ";
147 }
148 cout << "\"" << m_iter->first << "\" => \"" << m_iter->second << "\"";
149 }
150 cout << "})" << endl;
151 out = thing;
152 }
153
154
155 void testSet(set<int32_t> &out, const set<int32_t> &thing) override {
156 cout << "[C -> C++] testSet({";
157 set<int32_t>::const_iterator s_iter;
158 bool first = true;
159 for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
160 if (first) {
161 first = false;
162 } else {
163 cout << ", ";
164 }
165 cout << *s_iter;
166 }
167 cout << "})" << endl;
168 out = thing;
169 }
170
171 void testList(vector<int32_t> &out, const vector<int32_t> &thing) override {
172 cout << "[C -> C++] testList({";
173 vector<int32_t>::const_iterator l_iter;
174 bool first = true;
175 for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
176 if (first) {
177 first = false;
178 } else {
179 cout << ", ";
180 }
181 cout << *l_iter;
182 }
183 cout << "})" << endl;
184 out = thing;
185 }
186
187 Numberz::type testEnum(const Numberz::type thing) override {
188 cout << "[C -> C++] testEnum(" << thing << ")" << endl;
189 return thing;
190 }
191
192 UserId testTypedef(const UserId thing) override {
193 cout << "[C -> C++] testTypedef(" << thing << ")" << endl;
194 return thing; }
195
196 void testMapMap(map<int32_t, map<int32_t,int32_t> > &mapmap, const int32_t hello) override {
197 cout << "[C -> C++] testMapMap(" << hello << ")" << endl;
198
199 map<int32_t,int32_t> pos;
200 map<int32_t,int32_t> neg;
201 for (int i = 1; i < 5; i++) {
202 pos.insert(make_pair(i,i));
203 neg.insert(make_pair(-i,-i));
204 }
205
206 mapmap.insert(make_pair(4, pos));
207 mapmap.insert(make_pair(-4, neg));
208
209 }
210
211 void testInsanity(map<UserId, map<Numberz::type,Insanity> > &insane, const Insanity &argument) override {
212 THRIFT_UNUSED_VARIABLE (argument);
213
214 cout << "[C -> C++] testInsanity()" << endl;
215
216 Xtruct hello;
217 hello.string_thing = "Hello2";
218 hello.byte_thing = 2;
219 hello.i32_thing = 2;
220 hello.i64_thing = 2;
221
222 Xtruct goodbye;
223 goodbye.string_thing = "Goodbye4";
224 goodbye.byte_thing = 4;
225 goodbye.i32_thing = 4;
226 goodbye.i64_thing = 4;
227
228 Insanity crazy;
229 crazy.userMap.insert(make_pair(Numberz::EIGHT, 8));
230 crazy.xtructs.push_back(goodbye);
231
232 Insanity looney;
233 crazy.userMap.insert(make_pair(Numberz::FIVE, 5));
234 crazy.xtructs.push_back(hello);
235
236 map<Numberz::type, Insanity> first_map;
237 map<Numberz::type, Insanity> second_map;
238
239 first_map.insert(make_pair(Numberz::TWO, crazy));
240 first_map.insert(make_pair(Numberz::THREE, crazy));
241
242 second_map.insert(make_pair(Numberz::SIX, looney));
243
244 insane.insert(make_pair(1, first_map));
245 insane.insert(make_pair(2, second_map));
246
247 cout << "return = {";
248 map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
249 for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
250 cout << i_iter->first << " => {";
251 map<Numberz::type,Insanity>::const_iterator i2_iter;
252 for (i2_iter = i_iter->second.begin();
253 i2_iter != i_iter->second.end();
254 ++i2_iter) {
255 cout << i2_iter->first << " => {";
256 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
257 map<Numberz::type, UserId>::const_iterator um;
258 cout << "{";
259 for (um = userMap.begin(); um != userMap.end(); ++um) {
260 cout << um->first << " => " << um->second << ", ";
261 }
262 cout << "}, ";
263
264 vector<Xtruct> xtructs = i2_iter->second.xtructs;
265 vector<Xtruct>::const_iterator x;
266 cout << "{";
267 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
268 cout << "{\"" << x->string_thing << "\", " << (int)x->byte_thing << ", " << x->i32_thing << ", " << x->i64_thing << "}, ";
269 }
270 cout << "}";
271
272 cout << "}, ";
273 }
274 cout << "}, ";
275 }
276 cout << "}" << endl;
277
278
279 }
280
281 void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> &arg3, const Numberz::type arg4, const UserId arg5) override {
282 THRIFT_UNUSED_VARIABLE (arg3);
283 THRIFT_UNUSED_VARIABLE (arg4);
284 THRIFT_UNUSED_VARIABLE (arg5);
285
286 cout << "[C -> C++] testMulti()" << endl;
287
288 hello.string_thing = "Hello2";
289 hello.byte_thing = arg0;
290 hello.i32_thing = arg1;
291 hello.i64_thing = (int64_t)arg2;
292 }
293
294 void testException(const std::string &arg)
295 throw(Xception, apache::thrift::TException) override
296 {
297 cout << "[C -> C++] testException(" << arg << ")" << endl;
298 if (arg.compare("Xception") == 0) {
299 Xception e;
300 e.errorCode = 1001;
301 e.message = arg;
302 throw e;
303 } else if (arg.compare("ApplicationException") == 0) {
304 apache::thrift::TException e;
305 throw e;
306 } else {
307 Xtruct result;
308 result.string_thing = arg;
309 return;
310 }
311 }
312
313 void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) override {
314
315 cout << "[C -> C++] testMultiException(" << arg0 << ", " << arg1 << ")" << endl;
316
317 if (arg0.compare("Xception") == 0) {
318 Xception e;
319 e.errorCode = 1001;
320 e.message = "This is an Xception";
321 throw e;
322 } else if (arg0.compare("Xception2") == 0) {
323 Xception2 e;
324 e.errorCode = 2002;
325 e.struct_thing.string_thing = "This is an Xception2";
326 throw e;
327 } else {
328 result.string_thing = arg1;
329 return;
330 }
331 }
332
333 void testOneway(int sleepFor) override {
334 cout << "testOneway(" << sleepFor << "): Sleeping..." << endl;
335 sleep(sleepFor);
336 cout << "testOneway(" << sleepFor << "): done sleeping!" << endl;
337 }
338};
339
340// C CLIENT
341extern "C" {
342
343#undef THRIFT_SOCKET /* from lib/cpp */
344
345#include "t_test_thrift_test.h"
346#include "t_test_thrift_test_types.h"
347#include <thrift/c_glib/transport/thrift_socket.h>
348#include <thrift/c_glib/transport/thrift_zlib_transport.h>
349#include <thrift/c_glib/protocol/thrift_protocol.h>
350#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
351
352static void
353test_thrift_client (void)
354{
355 ThriftSocket *tsocket = nullptr;
356 ThriftBinaryProtocol *protocol = nullptr;
357 ThriftZlibTransport *transport = nullptr;
358 TTestThriftTestClient *client = nullptr;
359 TTestThriftTestIf *iface = nullptr;
360 GError *error = nullptr;
361 gchar *string = nullptr;
362 gint8 byte = 0;
363 gint16 i16 = 0;
364 gint32 i32 = 0, another_i32 = 56789;
365 gint64 i64 = 0;
366 double dbl = 0.0;
367 TTestXtruct *xtruct_in, *xtruct_out;
368 TTestXtruct2 *xtruct2_in, *xtruct2_out;
369 GHashTable *map_in = nullptr, *map_out = nullptr;
370 GHashTable *set_in = nullptr, *set_out = nullptr;
371 GArray *list_in = nullptr, *list_out = nullptr;
372 TTestNumberz enum_in, enum_out;
373 TTestUserId user_id_in, user_id_out;
374 GHashTable *insanity_in = nullptr;
375 TTestXtruct *xtruct1, *xtruct2;
376 TTestInsanity *insanity_out = nullptr;
377 TTestXtruct *multi_in = nullptr;
378 GHashTable *multi_map_out = nullptr;
379 TTestXception *xception = nullptr;
380 TTestXception2 *xception2 = nullptr;
381
382#if (!GLIB_CHECK_VERSION (2, 36, 0))
383 // initialize gobject
384 g_type_init ();
385#endif
386
387 // create a C client
388 tsocket = (ThriftSocket *) g_object_new (THRIFT_TYPE_SOCKET,
389 "hostname", "localhost",
390 "port", TEST_PORT, nullptr);
391 transport = (ThriftZlibTransport *) g_object_new (THRIFT_TYPE_ZLIB_TRANSPORT,
392 "transport", tsocket, nullptr);
393 protocol = (ThriftBinaryProtocol *) g_object_new (THRIFT_TYPE_BINARY_PROTOCOL,
394 "transport",
395 transport, nullptr);
396 client = (TTestThriftTestClient *) g_object_new (T_TEST_TYPE_THRIFT_TEST_CLIENT, "input_protocol", protocol, "output_protocol", protocol, nullptr);
397 iface = T_TEST_THRIFT_TEST_IF (client);
398
399 // open and send
400 thrift_transport_open (THRIFT_TRANSPORT(transport), nullptr);
401
402 assert (t_test_thrift_test_client_test_void (iface, &error) == TRUE);
403 assert (error == nullptr);
404
405 assert (t_test_thrift_test_client_test_string (iface, &string, "test123", &error) == TRUE);
406 assert (strcmp (string, "test123") == 0);
407 g_free (string);
408 assert (error == nullptr);
409
410 assert (t_test_thrift_test_client_test_byte (iface, &byte, (gint8) 5, &error) == TRUE);
411 assert (byte == 5);
412 assert (error == nullptr);
413
414 assert (t_test_thrift_test_client_test_i32 (iface, &i32, 123, &error) == TRUE);
415 assert (i32 == 123);
416 assert (error == nullptr);
417
418 assert (t_test_thrift_test_client_test_i64 (iface, &i64, 12345, &error) == TRUE);
419 assert (i64 == 12345);
420 assert (error == nullptr);
421
422 assert (t_test_thrift_test_client_test_double (iface, &dbl, 5.6, &error) == TRUE);
423 assert (dbl == 5.6);
424 assert (error == nullptr);
425
426 xtruct_out = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, nullptr);
427 xtruct_out->byte_thing = 1;
428 xtruct_out->__isset_byte_thing = TRUE;
429 xtruct_out->i32_thing = 15;
430 xtruct_out->__isset_i32_thing = TRUE;
431 xtruct_out->i64_thing = 151;
432 xtruct_out->__isset_i64_thing = TRUE;
433 xtruct_out->string_thing = g_strdup ("abc123");
434 xtruct_out->__isset_string_thing = TRUE;
435 xtruct_in = (TTestXtruct *) g_object_new(T_TEST_TYPE_XTRUCT, nullptr);
436 assert (t_test_thrift_test_client_test_struct (iface, &xtruct_in, xtruct_out, &error) == TRUE);
437 assert (error == nullptr);
438
439 xtruct2_out = (TTestXtruct2 *) g_object_new (T_TEST_TYPE_XTRUCT2, nullptr);
440 xtruct2_out->byte_thing = 1;
441 xtruct2_out->__isset_byte_thing = TRUE;
442 if (xtruct2_out->struct_thing != nullptr)
443 g_object_unref(xtruct2_out->struct_thing);
444 xtruct2_out->struct_thing = xtruct_out;
445 xtruct2_out->__isset_struct_thing = TRUE;
446 xtruct2_out->i32_thing = 123;
447 xtruct2_out->__isset_i32_thing = TRUE;
448 xtruct2_in = (TTestXtruct2 *) g_object_new (T_TEST_TYPE_XTRUCT2, nullptr);
449 assert (t_test_thrift_test_client_test_nest (iface, &xtruct2_in, xtruct2_out, &error) == TRUE);
450 assert (error == nullptr);
451
452 g_object_unref (xtruct2_out);
453 g_object_unref (xtruct2_in);
454 g_object_unref (xtruct_in);
455
456 map_out = g_hash_table_new (nullptr, nullptr);
457 map_in = g_hash_table_new (nullptr, nullptr); g_hash_table_insert (map_out, &i32, &i32);
458 assert (t_test_thrift_test_client_test_map (iface, &map_in, map_out, &error) == TRUE);
459 assert (error == nullptr);
460 g_hash_table_destroy (map_out);
461 g_hash_table_destroy (map_in);
462
463 map_out = g_hash_table_new (nullptr, nullptr);
464 map_in = g_hash_table_new (nullptr, nullptr);
465 g_hash_table_insert (map_out, g_strdup ("a"), g_strdup ("123"));
466 g_hash_table_insert (map_out, g_strdup ("a b"), g_strdup ("with spaces "));
467 g_hash_table_insert (map_out, g_strdup ("same"), g_strdup ("same"));
468 g_hash_table_insert (map_out, g_strdup ("0"), g_strdup ("numeric key"));
469 assert (t_test_thrift_test_client_test_string_map (iface, &map_in, map_out, &error) == TRUE);
470 assert (error == nullptr);
471 g_hash_table_destroy (map_out);
472 g_hash_table_destroy (map_in);
473
474 set_out = g_hash_table_new (nullptr, nullptr);
475 set_in = g_hash_table_new (nullptr, nullptr);
476 g_hash_table_insert (set_out, &i32, &i32);
477 assert (t_test_thrift_test_client_test_set (iface, &set_in, set_out, &error) == TRUE);
478 assert (error == nullptr);
479 g_hash_table_destroy (set_out);
480 g_hash_table_destroy (set_in);
481
482 list_out = g_array_new(TRUE, TRUE, sizeof(gint32));
483 list_in = g_array_new(TRUE, TRUE, sizeof(gint32));
484 another_i32 = 456;
485 g_array_append_val (list_out, i32);
486 g_array_append_val (list_out, another_i32);
487 assert (t_test_thrift_test_client_test_list (iface, &list_in, list_out, &error) == TRUE);
488 assert (error == nullptr);
489 g_array_free (list_out, TRUE);
490 g_array_free (list_in, TRUE);
491
492 enum_out = T_TEST_NUMBERZ_ONE;
493 assert (t_test_thrift_test_client_test_enum (iface, &enum_in, enum_out, &error) == TRUE);
494 assert (enum_in == enum_out);
495 assert (error == nullptr);
496
497 user_id_out = 12345;
498 assert (t_test_thrift_test_client_test_typedef (iface, &user_id_in, user_id_out, &error) == TRUE);
499 assert (user_id_in == user_id_out);
500 assert (error == nullptr);
501
502 map_in = g_hash_table_new (nullptr, nullptr);
503 assert (t_test_thrift_test_client_test_map_map (iface, &map_in, i32, &error) == TRUE);
504 assert (error == nullptr);
505 g_hash_table_destroy (map_in);
506
507 // insanity
508 insanity_out = (TTestInsanity *) g_object_new (T_TEST_TYPE_INSANITY, nullptr);
509 insanity_out->userMap = g_hash_table_new (nullptr, nullptr);
510 g_hash_table_insert (insanity_out->userMap, GINT_TO_POINTER (enum_out), &user_id_out);
511
512 xtruct1 = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, nullptr);
513 xtruct1->byte_thing = 1;
514 xtruct1->__isset_byte_thing = TRUE;
515 xtruct1->i32_thing = 15;
516 xtruct1->__isset_i32_thing = TRUE;
517 xtruct1->i64_thing = 151;
518 xtruct1->__isset_i64_thing = TRUE;
519 xtruct1->string_thing = g_strdup ("abc123");
520 xtruct1->__isset_string_thing = TRUE;
521 xtruct2 = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, nullptr);
522 xtruct2->byte_thing = 1;
523 xtruct2->__isset_byte_thing = TRUE;
524 xtruct2->i32_thing = 15;
525 xtruct2->__isset_i32_thing = TRUE;
526 xtruct2->i64_thing = 151;
527 xtruct2->__isset_i64_thing = TRUE;
528 xtruct2->string_thing = g_strdup ("abc123");
529 xtruct2->__isset_string_thing = TRUE;
530
531 insanity_in = g_hash_table_new (nullptr, nullptr);
532 g_ptr_array_add (insanity_out->xtructs, xtruct1);
533 g_ptr_array_add (insanity_out->xtructs, xtruct2);
534 assert (t_test_thrift_test_client_test_insanity (iface, &insanity_in, insanity_out, &error) == TRUE);
535
536 g_hash_table_unref (insanity_in);
537 g_ptr_array_free (insanity_out->xtructs, TRUE);
538
539 multi_map_out = g_hash_table_new (nullptr, nullptr);
540 string = g_strdup ("abc123");
541 g_hash_table_insert (multi_map_out, &i16, string);
542 multi_in = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, nullptr);
543 assert (t_test_thrift_test_client_test_multi (iface, &multi_in, byte, i32, i64, multi_map_out, enum_out, user_id_out, &error) == TRUE);
544 assert (multi_in->i32_thing == i32);
545 assert (multi_in->i64_thing == i64);
546 g_object_unref (multi_in);
547 g_hash_table_unref (multi_map_out);
548 g_free (string);
549
550 assert (t_test_thrift_test_client_test_exception (iface, "Xception", &xception, &error) == FALSE);
551 assert (xception->errorCode == 1001);
552 g_error_free (error);
553 error = nullptr;
554 g_object_unref (xception);
555 xception = nullptr;
556
557 assert (t_test_thrift_test_client_test_exception (iface, "ApplicationException", &xception, &error) == FALSE);
558 g_error_free (error);
559 error = nullptr;
560 assert (xception == nullptr);
561
562 assert (t_test_thrift_test_client_test_exception (iface, "Test", &xception, &error) == TRUE);
563 assert (error == nullptr);
564
565 multi_in = (TTestXtruct*) g_object_new (T_TEST_TYPE_XTRUCT, nullptr);
566 assert (t_test_thrift_test_client_test_multi_exception (iface, &multi_in, "Xception", nullptr, &xception, &xception2, &error) == FALSE);
567 assert (xception->errorCode == 1001);
568 assert (xception2 == nullptr);
569 g_error_free (error);
570 error = nullptr;
571 g_object_unref (xception);
572 g_object_unref (multi_in);
573 xception = nullptr;
574 multi_in = nullptr;
575
576 multi_in = (TTestXtruct*) g_object_new (T_TEST_TYPE_XTRUCT, nullptr);
577 assert (t_test_thrift_test_client_test_multi_exception (iface, &multi_in, "Xception2", nullptr, &xception, &xception2, &error) == FALSE);
578 assert (xception2->errorCode == 2002);
579 assert (xception == nullptr);
580 g_error_free (error);
581 error = nullptr;
582 g_object_unref (xception2);
583 g_object_unref (multi_in);
584 xception2 = nullptr;
585 multi_in = nullptr;
586
587 multi_in = (TTestXtruct*) g_object_new (T_TEST_TYPE_XTRUCT, nullptr);
588 assert (t_test_thrift_test_client_test_multi_exception (iface, &multi_in, nullptr , nullptr, &xception, &xception2, &error) == TRUE);
589 assert (error == nullptr);
590 g_object_unref(multi_in);
591 multi_in = nullptr;
592
593 assert (t_test_thrift_test_client_test_oneway (iface, 1, &error) == TRUE);
594 assert (error == nullptr);
595
596 /* sleep to let the oneway call go through */
597 sleep (5);
598
599 thrift_transport_close (THRIFT_TRANSPORT(tsocket), nullptr);
600 g_object_unref (client);
601 g_object_unref (protocol);
602 g_object_unref (tsocket);
603}
604
605
606} /* extern "C" */
607
608
609static void
610bailout (int signum)
611{
612 THRIFT_UNUSED_VARIABLE (signum);
613
614 exit (1);
615}
616
617int
618main (void)
619{
620 int status;
621 int pid = fork ();
622 assert (pid >= 0);
623
624 if (pid == 0) /* child */
625 {
626 std::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
627 std::shared_ptr<TestHandler> testHandler(new TestHandler());
628 std::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
629 std::shared_ptr<TServerSocket> serverSocket(new TServerSocket(TEST_PORT));
630 std::shared_ptr<TZlibTransportFactory> transportFactory(new TZlibTransportFactory());
631 //std::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
632 TSimpleServer simpleServer(testProcessor, serverSocket, transportFactory, protocolFactory);
633 signal (SIGALRM, bailout);
634 alarm (60);
635 simpleServer.serve();
636 } else {
637 sleep (1);
638 test_thrift_client ();
639 kill (pid, SIGINT);
640 assert (wait (&status) == pid);
641 }
642
643 return 0;
644}
645