blob: e1737cde3deba4cdb6899b5fb0bc1925073edb9b [file] [log] [blame]
Roger Meierc1010922010-11-26 10:17:48 +00001/*
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 */
Roger Meier213a6642010-10-27 12:30:11 +000019
20/* test a C client with a C++ server */
21
22#include <signal.h>
23#include <sys/types.h>
24#include <sys/wait.h>
Roger Meier49ff8b12012-04-13 09:12:31 +000025#include <thrift/protocol/TBinaryProtocol.h>
26#include <thrift/protocol/TDebugProtocol.h>
27#include <thrift/server/TSimpleServer.h>
28#include <thrift/transport/TServerSocket.h>
Roger Meier213a6642010-10-27 12:30:11 +000029#include "ThriftTest.h"
30#include "ThriftTest_types.h"
31
32#include <iostream>
33
34using namespace std;
35using namespace boost;
36
37using namespace apache::thrift;
38using namespace apache::thrift::concurrency;
39using namespace apache::thrift::protocol;
40using namespace apache::thrift::transport;
41using namespace apache::thrift::server;
42
43using namespace thrift::test;
44
45#define TEST_PORT 9980
46
47// Extra functions required for ThriftTest_types to work
48namespace thrift { namespace test {
49
50bool Insanity::operator<(thrift::test::Insanity const& other) const {
51 using apache::thrift::ThriftDebugString;
52 return ThriftDebugString(*this) < ThriftDebugString(other);
53}
54
55}}
56
57class TestHandler : public ThriftTestIf {
58 public:
59 TestHandler() {}
60
61 void testVoid() {
62 printf("[C -> C++] testVoid()\n");
63 }
64
65 void testString(string& out, const string &thing) {
66 printf("[C -> C++] testString(\"%s\")\n", thing.c_str());
67 out = thing;
68 }
69
70 int8_t testByte(const int8_t thing) {
71 printf("[C -> C++] testByte(%d)\n", (int)thing);
72 return thing;
73 }
74 int32_t testI32(const int32_t thing) {
75 printf("[C -> C++] testI32(%d)\n", thing);
76 return thing;
77 }
78
79 int64_t testI64(const int64_t thing) {
Roger Meier79e971e2015-04-12 13:11:33 +020080 printf("[C -> C++] testI64(%ld)\n", thing);
Roger Meier213a6642010-10-27 12:30:11 +000081 return thing;
82 }
83
84 double testDouble(const double thing) {
85 printf("[C -> C++] testDouble(%lf)\n", thing);
86 return thing;
87 }
88
Jens Geyer8bcfdd92014-12-14 03:14:26 +010089 void testBinary(string& out, const string &thing) {
90 printf("[C -> C++] testBinary(\"%s\")\n", thing.c_str());
91 out = thing;
92 }
93
Roger Meier213a6642010-10-27 12:30:11 +000094 void testStruct(Xtruct& out, const Xtruct &thing) {
Roger Meier79e971e2015-04-12 13:11:33 +020095 printf("[C -> C++] testStruct({\"%s\", %d, %d, %ld})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
Roger Meier213a6642010-10-27 12:30:11 +000096 out = thing;
97 }
98
99 void testNest(Xtruct2& out, const Xtruct2& nest) {
100 const Xtruct &thing = nest.struct_thing;
Roger Meier79e971e2015-04-12 13:11:33 +0200101 printf("[C -> C++] testNest({%d, {\"%s\", %d, %d, %ld}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing);
Roger Meier213a6642010-10-27 12:30:11 +0000102 out = nest;
103 }
104
105 void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) {
106 printf("[C -> C++] testMap({");
107 map<int32_t, int32_t>::const_iterator m_iter;
108 bool first = true;
109 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
110 if (first) {
111 first = false;
112 } else {
113 printf(", ");
114 }
115 printf("%d => %d", m_iter->first, m_iter->second);
116 }
117 printf("})\n");
118 out = thing;
119 }
120
Roger Meiera1c416f2011-06-17 19:40:48 +0000121 void testStringMap(map<std::string, std::string> &out, const map<std::string, std::string> &thing) {
122 printf("[C -> C++] testStringMap({");
123 map<std::string, std::string>::const_iterator m_iter;
124 bool first = true;
125 for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
126 if (first) {
127 first = false;
128 } else {
129 printf(", ");
130 }
131 printf("\"%s\" => \"%s\"", (m_iter->first).c_str(), (m_iter->second).c_str());
132 }
133 printf("})\n");
134 out = thing;
135 }
136
137
Roger Meier213a6642010-10-27 12:30:11 +0000138 void testSet(set<int32_t> &out, const set<int32_t> &thing) {
139 printf("[C -> C++] testSet({");
140 set<int32_t>::const_iterator s_iter;
141 bool first = true;
142 for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
143 if (first) {
144 first = false;
145 } else {
146 printf(", ");
147 }
148 printf("%d", *s_iter);
149 }
150 printf("})\n");
151 out = thing;
152 }
153
154 void testList(vector<int32_t> &out, const vector<int32_t> &thing) {
155 printf("[C -> C++] testList({");
156 vector<int32_t>::const_iterator l_iter;
157 bool first = true;
158 for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
159 if (first) {
160 first = false;
161 } else { printf(", ");
162 }
163 printf("%d", *l_iter);
164 }
165 printf("})\n");
166 out = thing;
167 }
168
169 Numberz::type testEnum(const Numberz::type thing) {
170 printf("[C -> C++] testEnum(%d)\n", thing);
171 return thing;
172 }
173
174 UserId testTypedef(const UserId thing) {
Roger Meier79e971e2015-04-12 13:11:33 +0200175 printf("[C -> C++] testTypedef(%ld)\n", thing);
Roger Meier213a6642010-10-27 12:30:11 +0000176 return thing; }
177
178 void testMapMap(map<int32_t, map<int32_t,int32_t> > &mapmap, const int32_t hello) {
179 printf("[C -> C++] testMapMap(%d)\n", hello);
180
181 map<int32_t,int32_t> pos;
182 map<int32_t,int32_t> neg;
183 for (int i = 1; i < 5; i++) {
184 pos.insert(make_pair(i,i));
185 neg.insert(make_pair(-i,-i));
186 }
187
188 mapmap.insert(make_pair(4, pos));
189 mapmap.insert(make_pair(-4, neg));
190
191 }
192
193 void testInsanity(map<UserId, map<Numberz::type,Insanity> > &insane, const Insanity &argument) {
Simon South38e71552015-08-03 10:51:16 +0000194 THRIFT_UNUSED_VARIABLE (argument);
195
Roger Meier213a6642010-10-27 12:30:11 +0000196 printf("[C -> C++] testInsanity()\n");
197
198 Xtruct hello;
199 hello.string_thing = "Hello2";
200 hello.byte_thing = 2;
201 hello.i32_thing = 2;
202 hello.i64_thing = 2;
203
204 Xtruct goodbye;
205 goodbye.string_thing = "Goodbye4";
206 goodbye.byte_thing = 4;
207 goodbye.i32_thing = 4;
208 goodbye.i64_thing = 4;
209
210 Insanity crazy;
211 crazy.userMap.insert(make_pair(Numberz::EIGHT, 8));
212 crazy.xtructs.push_back(goodbye);
213
214 Insanity looney;
215 crazy.userMap.insert(make_pair(Numberz::FIVE, 5));
216 crazy.xtructs.push_back(hello);
217
218 map<Numberz::type, Insanity> first_map;
219 map<Numberz::type, Insanity> second_map;
220
221 first_map.insert(make_pair(Numberz::TWO, crazy));
222 first_map.insert(make_pair(Numberz::THREE, crazy));
223
224 second_map.insert(make_pair(Numberz::SIX, looney));
225
226 insane.insert(make_pair(1, first_map));
227 insane.insert(make_pair(2, second_map));
228
229 printf("return");
230 printf(" = {");
231 map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
232 for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
Roger Meier79e971e2015-04-12 13:11:33 +0200233 printf("%ld => {", i_iter->first);
Roger Meier213a6642010-10-27 12:30:11 +0000234 map<Numberz::type,Insanity>::const_iterator i2_iter;
235 for (i2_iter = i_iter->second.begin();
236 i2_iter != i_iter->second.end();
237 ++i2_iter) {
238 printf("%d => {", i2_iter->first);
239 map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
240 map<Numberz::type, UserId>::const_iterator um;
241 printf("{");
242 for (um = userMap.begin(); um != userMap.end(); ++um) {
Roger Meier79e971e2015-04-12 13:11:33 +0200243 printf("%d => %ld, ", um->first, um->second);
Roger Meier213a6642010-10-27 12:30:11 +0000244 }
245 printf("}, ");
246
247 vector<Xtruct> xtructs = i2_iter->second.xtructs;
248 vector<Xtruct>::const_iterator x;
249 printf("{");
250 for (x = xtructs.begin(); x != xtructs.end(); ++x) {
Roger Meier79e971e2015-04-12 13:11:33 +0200251 printf("{\"%s\", %d, %d, %ld}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing);
Roger Meier213a6642010-10-27 12:30:11 +0000252 }
253 printf("}");
254
255 printf("}, ");
256 }
257 printf("}, ");
258 }
259 printf("}\n");
260
261
262 }
263
264 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) {
Simon South38e71552015-08-03 10:51:16 +0000265 THRIFT_UNUSED_VARIABLE (arg3);
266 THRIFT_UNUSED_VARIABLE (arg4);
267 THRIFT_UNUSED_VARIABLE (arg5);
268
Roger Meier213a6642010-10-27 12:30:11 +0000269 printf("[C -> C++] testMulti()\n");
270
271 hello.string_thing = "Hello2";
272 hello.byte_thing = arg0;
273 hello.i32_thing = arg1;
274 hello.i64_thing = (int64_t)arg2;
275 }
276
277 void testException(const std::string &arg)
278 throw(Xception, apache::thrift::TException)
279 {
280 printf("[C -> C++] testException(%s)\n", arg.c_str());
281 if (arg.compare("Xception") == 0) {
282 Xception e;
283 e.errorCode = 1001;
284 e.message = arg;
285 throw e;
286 } else if (arg.compare("ApplicationException") == 0) {
287 apache::thrift::TException e;
288 throw e;
289 } else {
290 Xtruct result;
291 result.string_thing = arg;
292 return;
293 }
294 }
295
296 void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) {
297
298 printf("[C -> C++] testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
299
300 if (arg0.compare("Xception") == 0) {
301 Xception e;
302 e.errorCode = 1001;
303 e.message = "This is an Xception";
304 throw e;
305 } else if (arg0.compare("Xception2") == 0) {
306 Xception2 e;
307 e.errorCode = 2002;
308 e.struct_thing.string_thing = "This is an Xception2";
309 throw e;
310 } else {
311 result.string_thing = arg1;
312 return;
313 }
314 }
315
316 void testOneway(int sleepFor) {
317 printf("testOneway(%d): Sleeping...\n", sleepFor);
318 sleep(sleepFor);
319 printf("testOneway(%d): done sleeping!\n", sleepFor);
320 }
321};
322
323// C CLIENT
324extern "C" {
325
Jim King79c99112015-04-30 07:10:08 -0400326#undef THRIFT_SOCKET /* from lib/cpp */
327
Roger Meier213a6642010-10-27 12:30:11 +0000328#include "t_test_thrift_test.h"
329#include "t_test_thrift_test_types.h"
Roger Meiere3da7682013-01-11 11:41:53 +0100330#include <thrift/c_glib/transport/thrift_socket.h>
331#include <thrift/c_glib/protocol/thrift_protocol.h>
332#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
Roger Meier213a6642010-10-27 12:30:11 +0000333
334static void
335test_thrift_client (void)
336{
337 ThriftSocket *tsocket = NULL;
338 ThriftBinaryProtocol *protocol = NULL;
339 TTestThriftTestClient *client = NULL;
340 TTestThriftTestIf *iface = NULL;
341 GError *error = NULL;
342 gchar *string = NULL;
343 gint8 byte = 0;
344 gint16 i16 = 0;
345 gint32 i32 = 0, another_i32 = 56789;
346 gint64 i64 = 0;
347 double dbl = 0.0;
348 TTestXtruct *xtruct_in, *xtruct_out;
349 TTestXtruct2 *xtruct2_in, *xtruct2_out;
350 GHashTable *map_in = NULL, *map_out = NULL;
351 GHashTable *set_in = NULL, *set_out = NULL;
352 GArray *list_in = NULL, *list_out = NULL;
353 TTestNumberz enum_in, enum_out;
354 TTestUserId user_id_in, user_id_out;
355 GHashTable *insanity_in = NULL;
356 TTestXtruct *xtruct1, *xtruct2;
357 TTestInsanity *insanity_out = NULL;
358 TTestXtruct *multi_in = NULL;
359 GHashTable *multi_map_out = NULL;
360 TTestXception *xception = NULL;
361 TTestXception2 *xception2 = NULL;
362
Jens Geyer1c190272015-07-28 23:15:18 +0200363#if (!GLIB_CHECK_VERSION (2, 36, 0))
Roger Meier213a6642010-10-27 12:30:11 +0000364 // initialize gobject
365 g_type_init ();
Jens Geyer1c190272015-07-28 23:15:18 +0200366#endif
Roger Meier213a6642010-10-27 12:30:11 +0000367
368 // create a C client
369 tsocket = (ThriftSocket *) g_object_new (THRIFT_TYPE_SOCKET,
370 "hostname", "localhost",
371 "port", TEST_PORT, NULL);
372 protocol = (ThriftBinaryProtocol *) g_object_new (THRIFT_TYPE_BINARY_PROTOCOL,
373 "transport",
374 tsocket, NULL);
375 client = (TTestThriftTestClient *) g_object_new (T_TEST_TYPE_THRIFT_TEST_CLIENT, "input_protocol", protocol, "output_protocol", protocol, NULL);
376 iface = T_TEST_THRIFT_TEST_IF (client);
377
378 // open and send
379 thrift_transport_open (THRIFT_TRANSPORT(tsocket), NULL);
380
381 assert (t_test_thrift_test_client_test_void (iface, &error) == TRUE);
382 assert (error == NULL);
383
384 assert (t_test_thrift_test_client_test_string (iface, &string, "test123", &error) == TRUE);
385 assert (strcmp (string, "test123") == 0);
386 g_free (string);
387 assert (error == NULL);
388
389 assert (t_test_thrift_test_client_test_byte (iface, &byte, (gint8) 5, &error) == TRUE);
390 assert (byte == 5);
391 assert (error == NULL);
392
393 assert (t_test_thrift_test_client_test_i32 (iface, &i32, 123, &error) == TRUE);
394 assert (i32 == 123);
395 assert (error == NULL);
396
397 assert (t_test_thrift_test_client_test_i64 (iface, &i64, 12345, &error) == TRUE);
398 assert (i64 == 12345);
399 assert (error == NULL);
400
401 assert (t_test_thrift_test_client_test_double (iface, &dbl, 5.6, &error) == TRUE);
402 assert (dbl == 5.6);
403 assert (error == NULL);
404
405 xtruct_out = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, NULL);
406 xtruct_out->byte_thing = 1;
407 xtruct_out->__isset_byte_thing = TRUE;
408 xtruct_out->i32_thing = 15;
409 xtruct_out->__isset_i32_thing = TRUE;
410 xtruct_out->i64_thing = 151;
411 xtruct_out->__isset_i64_thing = TRUE;
412 xtruct_out->string_thing = g_strdup ("abc123");
413 xtruct_out->__isset_string_thing = TRUE;
Roger Meierc75797d2012-04-28 11:33:58 +0000414 xtruct_in = (TTestXtruct *) g_object_new(T_TEST_TYPE_XTRUCT, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000415 assert (t_test_thrift_test_client_test_struct (iface, &xtruct_in, xtruct_out, &error) == TRUE);
416 assert (error == NULL);
417
418 xtruct2_out = (TTestXtruct2 *) g_object_new (T_TEST_TYPE_XTRUCT2, NULL);
419 xtruct2_out->byte_thing = 1;
420 xtruct2_out->__isset_byte_thing = TRUE;
Roger Meierc75797d2012-04-28 11:33:58 +0000421 if (xtruct2_out->struct_thing != NULL)
422 g_object_unref(xtruct2_out->struct_thing);
Roger Meier213a6642010-10-27 12:30:11 +0000423 xtruct2_out->struct_thing = xtruct_out;
424 xtruct2_out->__isset_struct_thing = TRUE;
425 xtruct2_out->i32_thing = 123;
426 xtruct2_out->__isset_i32_thing = TRUE;
Roger Meierc75797d2012-04-28 11:33:58 +0000427 xtruct2_in = (TTestXtruct2 *) g_object_new (T_TEST_TYPE_XTRUCT2, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000428 assert (t_test_thrift_test_client_test_nest (iface, &xtruct2_in, xtruct2_out, &error) == TRUE);
429 assert (error == NULL);
430
431 g_object_unref (xtruct2_out);
432 g_object_unref (xtruct2_in);
Roger Meier213a6642010-10-27 12:30:11 +0000433 g_object_unref (xtruct_in);
434
435 map_out = g_hash_table_new (NULL, NULL);
436 map_in = g_hash_table_new (NULL, NULL); g_hash_table_insert (map_out, &i32, &i32);
437 assert (t_test_thrift_test_client_test_map (iface, &map_in, map_out, &error) == TRUE);
438 assert (error == NULL);
439 g_hash_table_destroy (map_out);
440 g_hash_table_destroy (map_in);
441
Roger Meiera1c416f2011-06-17 19:40:48 +0000442 map_out = g_hash_table_new (NULL, NULL);
443 map_in = g_hash_table_new (NULL, NULL);
444 g_hash_table_insert (map_out, g_strdup ("a"), g_strdup ("123"));
445 g_hash_table_insert (map_out, g_strdup ("a b"), g_strdup ("with spaces "));
446 g_hash_table_insert (map_out, g_strdup ("same"), g_strdup ("same"));
447 g_hash_table_insert (map_out, g_strdup ("0"), g_strdup ("numeric key"));
448 assert (t_test_thrift_test_client_test_string_map (iface, &map_in, map_out, &error) == TRUE);
449 assert (error == NULL);
450 g_hash_table_destroy (map_out);
451 g_hash_table_destroy (map_in);
452
Roger Meier213a6642010-10-27 12:30:11 +0000453 set_out = g_hash_table_new (NULL, NULL);
454 set_in = g_hash_table_new (NULL, NULL);
455 g_hash_table_insert (set_out, &i32, &i32);
456 assert (t_test_thrift_test_client_test_set (iface, &set_in, set_out, &error) == TRUE);
457 assert (error == NULL);
458 g_hash_table_destroy (set_out);
459 g_hash_table_destroy (set_in);
460
461 list_out = g_array_new(TRUE, TRUE, sizeof(gint32));
462 list_in = g_array_new(TRUE, TRUE, sizeof(gint32));
463 another_i32 = 456;
464 g_array_append_val (list_out, i32);
465 g_array_append_val (list_out, another_i32);
466 assert (t_test_thrift_test_client_test_list (iface, &list_in, list_out, &error) == TRUE);
467 assert (error == NULL);
468 g_array_free (list_out, TRUE);
469 g_array_free (list_in, TRUE);
470
471 enum_out = T_TEST_NUMBERZ_ONE;
472 assert (t_test_thrift_test_client_test_enum (iface, &enum_in, enum_out, &error) == TRUE);
473 assert (enum_in == enum_out);
474 assert (error == NULL);
475
476 user_id_out = 12345;
477 assert (t_test_thrift_test_client_test_typedef (iface, &user_id_in, user_id_out, &error) == TRUE);
478 assert (user_id_in == user_id_out);
479 assert (error == NULL);
480
481 map_in = g_hash_table_new (NULL, NULL);
482 assert (t_test_thrift_test_client_test_map_map (iface, &map_in, i32, &error) == TRUE);
483 assert (error == NULL);
484 g_hash_table_destroy (map_in);
485
486 // insanity
487 insanity_out = (TTestInsanity *) g_object_new (T_TEST_TYPE_INSANITY, NULL);
488 insanity_out->userMap = g_hash_table_new (NULL, NULL);
Roger Meier0cc6d3c2014-09-04 00:24:17 +0200489 g_hash_table_insert (insanity_out->userMap, GINT_TO_POINTER (enum_out), &user_id_out);
Roger Meier213a6642010-10-27 12:30:11 +0000490
491 xtruct1 = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, NULL);
492 xtruct1->byte_thing = 1;
493 xtruct1->__isset_byte_thing = TRUE;
494 xtruct1->i32_thing = 15;
495 xtruct1->__isset_i32_thing = TRUE;
496 xtruct1->i64_thing = 151;
497 xtruct1->__isset_i64_thing = TRUE;
498 xtruct1->string_thing = g_strdup ("abc123");
499 xtruct1->__isset_string_thing = TRUE;
500 xtruct2 = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, NULL);
501 xtruct2->byte_thing = 1;
502 xtruct2->__isset_byte_thing = TRUE;
503 xtruct2->i32_thing = 15;
504 xtruct2->__isset_i32_thing = TRUE;
505 xtruct2->i64_thing = 151;
506 xtruct2->__isset_i64_thing = TRUE;
507 xtruct2->string_thing = g_strdup ("abc123");
508 xtruct2->__isset_string_thing = TRUE;
509
Roger Meier213a6642010-10-27 12:30:11 +0000510 insanity_in = g_hash_table_new (NULL, NULL);
511 g_ptr_array_add (insanity_out->xtructs, xtruct1);
512 g_ptr_array_add (insanity_out->xtructs, xtruct2);
513 assert (t_test_thrift_test_client_test_insanity (iface, &insanity_in, insanity_out, &error) == TRUE);
514
515 g_hash_table_unref (insanity_in);
516 g_ptr_array_free (insanity_out->xtructs, TRUE);
Roger Meier213a6642010-10-27 12:30:11 +0000517
518 multi_map_out = g_hash_table_new (NULL, NULL);
519 string = g_strdup ("abc123");
520 g_hash_table_insert (multi_map_out, &i16, string);
Roger Meierc75797d2012-04-28 11:33:58 +0000521 multi_in = (TTestXtruct *) g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000522 assert (t_test_thrift_test_client_test_multi (iface, &multi_in, byte, i32, i64, multi_map_out, enum_out, user_id_out, &error) == TRUE);
523 assert (multi_in->i32_thing == i32);
524 assert (multi_in->i64_thing == i64);
525 g_object_unref (multi_in);
526 g_hash_table_unref (multi_map_out);
Roger Meierc75797d2012-04-28 11:33:58 +0000527 g_free (string);
Roger Meier213a6642010-10-27 12:30:11 +0000528
529 assert (t_test_thrift_test_client_test_exception (iface, "Xception", &xception, &error) == FALSE);
530 assert (xception->errorCode == 1001);
531 g_error_free (error);
532 error = NULL;
Roger Meierc75797d2012-04-28 11:33:58 +0000533 g_object_unref (xception);
534 xception = NULL;
Roger Meier213a6642010-10-27 12:30:11 +0000535
536 assert (t_test_thrift_test_client_test_exception (iface, "ApplicationException", &xception, &error) == FALSE);
537 g_error_free (error);
538 error = NULL;
Jens Geyer482da722015-07-28 23:46:02 +0200539 assert (xception == NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000540
541 assert (t_test_thrift_test_client_test_exception (iface, "Test", &xception, &error) == TRUE);
542 assert (error == NULL);
543
Roger Meierc75797d2012-04-28 11:33:58 +0000544 multi_in = (TTestXtruct*) g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000545 assert (t_test_thrift_test_client_test_multi_exception (iface, &multi_in, "Xception", NULL, &xception, &xception2, &error) == FALSE);
546 assert (xception->errorCode == 1001);
Roger Meierc75797d2012-04-28 11:33:58 +0000547 assert (xception2 == NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000548 g_error_free (error);
549 error = NULL;
550 g_object_unref (xception);
Roger Meierc75797d2012-04-28 11:33:58 +0000551 g_object_unref (multi_in);
Roger Meier213a6642010-10-27 12:30:11 +0000552 xception = NULL;
Roger Meierc75797d2012-04-28 11:33:58 +0000553 multi_in = NULL;
Roger Meier213a6642010-10-27 12:30:11 +0000554
Roger Meierc75797d2012-04-28 11:33:58 +0000555 multi_in = (TTestXtruct*) g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000556 assert (t_test_thrift_test_client_test_multi_exception (iface, &multi_in, "Xception2", NULL, &xception, &xception2, &error) == FALSE);
557 assert (xception2->errorCode == 2002);
Roger Meierc75797d2012-04-28 11:33:58 +0000558 assert (xception == NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000559 g_error_free (error);
560 error = NULL;
561 g_object_unref (xception2);
Roger Meierc75797d2012-04-28 11:33:58 +0000562 g_object_unref (multi_in);
Roger Meier213a6642010-10-27 12:30:11 +0000563 xception2 = NULL;
Roger Meierc75797d2012-04-28 11:33:58 +0000564 multi_in = NULL;
Roger Meier213a6642010-10-27 12:30:11 +0000565
Roger Meierc75797d2012-04-28 11:33:58 +0000566 multi_in = (TTestXtruct*) g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000567 assert (t_test_thrift_test_client_test_multi_exception (iface, &multi_in, NULL , NULL, &xception, &xception2, &error) == TRUE);
568 assert (error == NULL);
Roger Meierc75797d2012-04-28 11:33:58 +0000569 g_object_unref(multi_in);
570 multi_in = NULL;
Roger Meier213a6642010-10-27 12:30:11 +0000571
572 assert (t_test_thrift_test_client_test_oneway (iface, 1, &error) == TRUE);
573 assert (error == NULL);
574
575 /* sleep to let the oneway call go through */
576 sleep (5);
577
578 thrift_transport_close (THRIFT_TRANSPORT(tsocket), NULL);
579 g_object_unref (client);
580 g_object_unref (protocol);
581 g_object_unref (tsocket);
582}
583
584
585} /* extern "C" */
586
587
588static void
589bailout (int signum)
590{
Simon South38e71552015-08-03 10:51:16 +0000591 THRIFT_UNUSED_VARIABLE (signum);
592
Roger Meier213a6642010-10-27 12:30:11 +0000593 exit (1);
594}
595
596int
Simon South38e71552015-08-03 10:51:16 +0000597main (void)
Roger Meier213a6642010-10-27 12:30:11 +0000598{
599 int status;
600 int pid = fork ();
601 assert (pid >= 0);
602
603 if (pid == 0) /* child */
604 {
Marco Molteni83494252015-04-16 13:50:20 +0200605 boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
606 boost::shared_ptr<TestHandler> testHandler(new TestHandler());
607 boost::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
608 boost::shared_ptr<TServerSocket> serverSocket(new TServerSocket(TEST_PORT));
609 boost::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
Roger Meier213a6642010-10-27 12:30:11 +0000610 TSimpleServer simpleServer(testProcessor, serverSocket, transportFactory, protocolFactory);
611 signal (SIGALRM, bailout);
612 alarm (60);
613 simpleServer.serve();
614 } else {
615 sleep (1);
616 test_thrift_client ();
617 kill (pid, SIGINT);
Simon South38e71552015-08-03 10:51:16 +0000618 assert (wait (&status) == pid);
Roger Meier213a6642010-10-27 12:30:11 +0000619 }
620
621 return 0;
622}
623