blob: fd429c80a0873eb6f5acc9432af0e2a3357a4b1f [file] [log] [blame]
Roger Meierb3c84092014-09-01 21:53:40 +02001/*
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#include <glib-object.h>
21#include <inttypes.h>
22#include <signal.h>
23#include <stdio.h>
24#include <string.h>
25
26#include <sys/time.h>
27
28#include <thrift/c_glib/thrift.h>
29#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
30#include <thrift/c_glib/transport/thrift_buffered_transport.h>
31#include <thrift/c_glib/transport/thrift_framed_transport.h>
32#include <thrift/c_glib/transport/thrift_socket.h>
33#include <thrift/c_glib/transport/thrift_transport.h>
34
35#include "../gen-c_glib/t_test_thrift_test.h"
36
37/* Handle SIGPIPE signals (indicating the server has closed the
38 connection prematurely) by outputting an error message before
39 exiting. */
40static void
Roger Meier15df0762014-09-29 20:50:56 +020041sigpipe_handler (int signal_number)
42{
Roger Meierb3c84092014-09-01 21:53:40 +020043 THRIFT_UNUSED_VAR (signal_number);
44
45 /* Flush standard output to make sure the test results so far are
46 logged */
47 fflush (stdout);
48
49 fputs ("Broken pipe (server closed connection prematurely)\n", stderr);
50 fflush (stderr);
51
52 /* Re-raise the signal, this time invoking the default signal
53 handler, to terminate the program */
54 raise (SIGPIPE);
55}
56
57/* Compare two gint32 values. Used for sorting and finding integer
58 values within a GList. */
59static gint
Roger Meier15df0762014-09-29 20:50:56 +020060gint32_compare (gconstpointer a, gconstpointer b)
61{
Roger Meierb3c84092014-09-01 21:53:40 +020062 gint32 int32_a = *(gint32 *)a;
63 gint32 int32_b = *(gint32 *)b;
64 int result = 0;
65
66 if (int32_a < int32_b)
67 result = -1;
68 else if (int32_a > int32_b)
69 result = 1;
70
71 return result;
72}
73
74int
Roger Meier15df0762014-09-29 20:50:56 +020075main (int argc, char **argv)
76{
Roger Meierb3c84092014-09-01 21:53:40 +020077 static gchar *host = NULL;
78 static gint port = 9090;
79 static gchar *transport_option = NULL;
80 static gchar *protocol_option = NULL;
81 static gint num_tests = 1;
82
83 static
84 GOptionEntry option_entries[] ={
85 { "host", 0, 0, G_OPTION_ARG_STRING, &host,
86 "Host to connect (=localhost)", NULL },
87 { "port", 0, 0, G_OPTION_ARG_INT, &port,
88 "Port number to connect (=9090)", NULL },
89 { "transport", 0, 0, G_OPTION_ARG_STRING, &transport_option,
90 "Transport: buffered, framed (=buffered)", NULL },
91 { "protocol", 0, 0, G_OPTION_ARG_STRING, &protocol_option,
92 "Protocol: binary (=binary)", NULL },
93 { "testloops", 'n', 0, G_OPTION_ARG_INT, &num_tests,
94 "Number of tests (=1)", NULL },
95 { NULL }
96 };
97
98 struct sigaction sigpipe_action;
99
100 GType transport_type = THRIFT_TYPE_BUFFERED_TRANSPORT;
101 gchar *transport_name = "buffered";
102 GType protocol_type = THRIFT_TYPE_BINARY_PROTOCOL;
103 gchar *protocol_name = "binary";
104
105 ThriftSocket *socket;
106 ThriftTransport *transport;
107 ThriftProtocol *protocol;
108
109 TTestThriftTestIf *test_client;
110
111 struct timeval time_start, time_stop, time_elapsed;
112 guint64 time_elapsed_usec, time_total_usec = 0;
113 guint64 time_min_usec = G_MAXUINT64, time_max_usec = 0, time_avg_usec;
114
115 GOptionContext *option_context;
116 gboolean options_valid = TRUE;
117 int test_num = 0;
118 int fail_count = 0;
119 GError *error = NULL;
120
Roger Meier15df0762014-09-29 20:50:56 +0200121#if (!GLIB_CHECK_VERSION (2, 36, 0))
122 g_type_init ();
123#endif
124
Roger Meierb3c84092014-09-01 21:53:40 +0200125 /* Configure and parse our command-line options */
126 option_context = g_option_context_new (NULL);
127 g_option_context_add_main_entries (option_context,
128 option_entries,
129 NULL);
Roger Meier15df0762014-09-29 20:50:56 +0200130 if (!g_option_context_parse (option_context,
131 &argc,
132 &argv,
133 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200134 fprintf (stderr, "%s\n", error->message);
135 return 255;
136 }
137 g_option_context_free (option_context);
138
139 /* Set remaining default values for unspecified options */
140 if (host == NULL)
141 host = g_strdup ("localhost");
142
143 /* Validate the parsed options */
144 if (protocol_option != NULL &&
145 strncmp (protocol_option, "binary", 7) != 0) {
146 fprintf (stderr, "Unknown protocol type %s\n", protocol_option);
147 options_valid = FALSE;
148 }
149
150 if (transport_option != NULL) {
151 if (strncmp (transport_option, "framed", 7) == 0) {
152 transport_type = THRIFT_TYPE_FRAMED_TRANSPORT;
153 transport_name = "framed";
154 }
155 else if (strncmp (transport_option, "buffered", 9) != 0) {
156 fprintf (stderr, "Unknown transport type %s\n", transport_option);
157 options_valid = FALSE;
158 }
159 }
160
Roger Meier15df0762014-09-29 20:50:56 +0200161 if (!options_valid)
Roger Meierb3c84092014-09-01 21:53:40 +0200162 return 254;
163
164 printf ("Connecting (%s/%s) to: %s:%d\n",
165 transport_name,
166 protocol_name,
167 host,
168 port);
169
170 /* Install our SIGPIPE handler, which outputs an error message to
171 standard error before exiting so testers can know what
172 happened */
173 memset (&sigpipe_action, 0, sizeof (sigpipe_action));
174 sigpipe_action.sa_handler = sigpipe_handler;
175 sigpipe_action.sa_flags = SA_RESETHAND;
176 sigaction (SIGPIPE, &sigpipe_action, NULL);
177
178 /* Establish all our connection objects */
179 socket = g_object_new (THRIFT_TYPE_SOCKET,
180 "hostname", host,
181 "port", port,
182 NULL);
183 transport = g_object_new (transport_type,
184 "transport", socket,
185 NULL);
186 protocol = g_object_new (protocol_type,
187 "transport", transport,
188 NULL);
189 test_client = g_object_new (T_TEST_TYPE_THRIFT_TEST_CLIENT,
190 "input_protocol", protocol,
191 "output_protocol", protocol,
192 NULL);
193
194 /* Execute the actual tests */
195 for (test_num = 0; test_num < num_tests; ++test_num) {
Roger Meier15df0762014-09-29 20:50:56 +0200196 if (thrift_transport_open (transport, &error)) {
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900197 gchar *string = NULL;
198 gboolean boolean = 0;
199 gint8 byte = 0;
200 gint32 int32 = 0;
201 gint64 int64 = 0;
202 gdouble dub = 0;
Roger Meierb3c84092014-09-01 21:53:40 +0200203
204 gint byte_thing, i32_thing, inner_byte_thing, inner_i32_thing;
205 gint64 i64_thing, inner_i64_thing;
206
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900207 TTestXtruct *xtruct_out, *xtruct_out2, *xtruct_in, *inner_xtruct_in;
Roger Meierb3c84092014-09-01 21:53:40 +0200208 TTestXtruct2 *xtruct2_out, *xtruct2_in;
209
210 GHashTable *map_out, *map_in, *inner_map_in;
211 GHashTable *set_out, *set_in;
212 gpointer key, value;
213 gint32 *i32_key_ptr, *i32_value_ptr;
214 GHashTableIter hash_table_iter, inner_hash_table_iter;
215 GList *keys_out, *keys_in, *keys_elem;
216
217 GArray *list_out, *list_in;
218
219 TTestNumberz numberz;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900220 TTestNumberz numberz2;
Roger Meierb3c84092014-09-01 21:53:40 +0200221
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900222 TTestUserId user_id, *user_id_ptr, *user_id_ptr2;
Roger Meierb3c84092014-09-01 21:53:40 +0200223
224 TTestInsanity *insanity_out, *insanity_in;
225 GHashTable *user_map;
226 GHashTableIter user_map_iter;
227 GPtrArray *xtructs;
228
229 TTestXception *xception = NULL;
230 TTestXception2 *xception2 = NULL;
231
232 gboolean oneway_result;
233 struct timeval oneway_start, oneway_end, oneway_elapsed;
234 gint oneway_elapsed_usec;
235
236 gboolean first;
237 gint32 i, j;
238
239 printf ("Test #%d, connect %s:%d\n", test_num + 1, host, port);
240 gettimeofday (&time_start, NULL);
241
242 /* These test routines have been ported from the C++ test
243 client, care being taken to ensure their output remains as
244 close as possible to the original to facilitate diffs.
245
246 For simplicity comments have been omitted, but every routine
247 has the same basic structure:
248
249 - Create and populate data structures as necessary.
250
251 - Format and output (to the console) a representation of the
252 outgoing data.
253
254 - Issue the remote method call to the server.
255
256 - Format and output a representation of the returned data.
257
258 - Verify the returned data matches what was expected.
259
260 - Deallocate any created data structures.
261
262 Note the recognized values and expected behaviour of each
263 remote method are described in ThriftTest.thrift, which
264 you'll find in the top-level "test" folder. */
265
266 /**
267 * VOID TEST
268 */
269 printf ("testVoid()");
Roger Meier15df0762014-09-29 20:50:56 +0200270 if (t_test_thrift_test_if_test_void (test_client, &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200271 printf (" = void\n");
272 }
273 else {
274 printf ("%s\n", error->message);
275 g_error_free (error);
276 error = NULL;
277
278 fail_count++;
279 }
280
281 /**
282 * STRING TEST
283 */
284 printf ("testString(\"Test\")");
285 if (t_test_thrift_test_if_test_string (test_client,
286 &string,
287 "Test",
Roger Meier15df0762014-09-29 20:50:56 +0200288 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200289 printf (" = \"%s\"\n", string);
290 if (strncmp (string, "Test", 5) != 0)
291 fail_count++;
292
293 g_free (string);
294 string = NULL;
295 }
296 else {
297 printf ("%s\n", error->message);
298 g_error_free (error);
299 error = NULL;
300
301 fail_count++;
302 }
303
304 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900305 * BOOL TEST
306 */
307 printf ("testByte(true)");
308 if (t_test_thrift_test_if_test_bool (test_client,
309 &boolean,
310 1,
311 &error)) {
312 printf (" = %s\n", boolean ? "true" : "false");
313 if (boolean != 1)
314 fail_count++;
315 }
316 else {
317 printf ("%s\n", error->message);
318 g_error_free (error);
319 error = NULL;
320
321 fail_count++;
322 }
323 printf ("testByte(false)");
324 if (t_test_thrift_test_if_test_bool (test_client,
325 &boolean,
326 0,
327 &error)) {
328 printf (" = %s\n", boolean ? "true" : "false");
329 if (boolean != 0)
330 fail_count++;
331 }
332 else {
333 printf ("%s\n", error->message);
334 g_error_free (error);
335 error = NULL;
336
337 fail_count++;
338 }
339
340 /**
Roger Meierb3c84092014-09-01 21:53:40 +0200341 * BYTE TEST
342 */
343 printf ("testByte(1)");
344 if (t_test_thrift_test_if_test_byte (test_client,
345 &byte,
346 1,
Roger Meier15df0762014-09-29 20:50:56 +0200347 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200348 printf (" = %d\n", byte);
349 if (byte != 1)
350 fail_count++;
351 }
352 else {
353 printf ("%s\n", error->message);
354 g_error_free (error);
355 error = NULL;
356
357 fail_count++;
358 }
359
360 /**
361 * I32 TEST
362 */
363 printf ("testI32(-1)");
364 if (t_test_thrift_test_if_test_i32 (test_client,
365 &int32,
366 -1,
Roger Meier15df0762014-09-29 20:50:56 +0200367 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200368 printf (" = %d\n", int32);
369 if (int32 != -1)
370 fail_count++;
371 }
372 else {
373 printf ("%s\n", error->message);
374 g_error_free (error);
375 error = NULL;
376
377 fail_count++;
378 }
379
380 /**
381 * I64 TEST
382 */
383 printf ("testI64(-34359738368)");
384 if (t_test_thrift_test_if_test_i64 (test_client,
385 &int64,
386 (gint64)-34359738368,
Roger Meier15df0762014-09-29 20:50:56 +0200387 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200388 printf (" = %" PRId64 "\n", int64);
389 if (int64 != (gint64)-34359738368)
390 fail_count++;
391 }
392 else {
393 printf ("%s\n", error->message);
394 g_error_free (error);
395 error = NULL;
396
397 fail_count++;
398 }
399
400 /**
401 * DOUBLE TEST
402 */
403 printf("testDouble(-5.2098523)");
404 if (t_test_thrift_test_if_test_double (test_client,
405 &dub,
406 -5.2098523,
Roger Meier15df0762014-09-29 20:50:56 +0200407 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200408 printf (" = %f\n", dub);
409 if ((dub - (-5.2098523)) > 0.001)
410 fail_count++;
411 }
412 else {
413 printf ("%s\n", error->message);
414 g_error_free (error);
415 error = NULL;
416
417 fail_count++;
418 }
419
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100420 // TODO: add testBinary()
421
Roger Meierb3c84092014-09-01 21:53:40 +0200422 /**
423 * STRUCT TEST
424 */
425 printf ("testStruct({\"Zero\", 1, -3, -5})");
426 xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT,
427 "string_thing", "Zero",
428 "byte_thing", 1,
429 "i32_thing", -3,
430 "i64_thing", -5LL,
431 NULL);
432 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
433
434 if (t_test_thrift_test_if_test_struct (test_client,
435 &xtruct_in,
436 xtruct_out,
Roger Meier15df0762014-09-29 20:50:56 +0200437 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200438 g_object_get (xtruct_in,
439 "string_thing", &string,
440 "byte_thing", &byte_thing,
441 "i32_thing", &i32_thing,
442 "i64_thing", &i64_thing,
443 NULL);
444
445 printf (" = {\"%s\", %d, %d, %" PRId64 "}\n",
446 string,
447 byte_thing,
448 i32_thing,
449 i64_thing);
450 if ((string == NULL || strncmp (string, "Zero", 5) != 0) ||
451 byte_thing != 1 ||
452 i32_thing != -3 ||
453 i64_thing != (gint64)-5)
454 fail_count++;
455 }
456 else {
457 printf ("%s\n", error->message);
458 g_error_free (error);
459 error = NULL;
460
461 fail_count++;
462 }
463 g_object_unref (xtruct_in);
464
465 /**
466 * NESTED STRUCT TEST
467 */
468 printf ("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
469 xtruct2_out = g_object_new (T_TEST_TYPE_XTRUCT2,
470 "byte_thing", 1,
471 "struct_thing", xtruct_out,
472 "i32_thing", 5,
473 NULL);
474 xtruct2_in = g_object_new (T_TEST_TYPE_XTRUCT2, NULL);
475
476 if (t_test_thrift_test_if_test_nest (test_client,
477 &xtruct2_in,
478 xtruct2_out,
Roger Meier15df0762014-09-29 20:50:56 +0200479 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200480 g_object_get (xtruct2_in,
481 "byte_thing", &byte_thing,
482 "struct_thing", &xtruct_in,
483 "i32_thing", &i32_thing,
484 NULL);
485 g_object_get (xtruct_in,
486 "string_thing", &string,
487 "byte_thing", &inner_byte_thing,
488 "i32_thing", &inner_i32_thing,
489 "i64_thing", &inner_i64_thing,
490 NULL);
491
492 printf (" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
493 byte_thing,
494 string,
495 inner_byte_thing,
496 inner_i32_thing,
497 inner_i64_thing,
498 i32_thing);
499 if (byte_thing != 1 ||
500 (string == NULL || strncmp (string, "Zero", 5) != 0) ||
501 inner_byte_thing != 1 ||
502 inner_i32_thing != -3 ||
503 inner_i64_thing != (gint64)-5 ||
504 i32_thing != 5)
505 fail_count++;
506 }
507 else {
508 printf ("%s\n", error->message);
509 g_error_free (error);
510 error = NULL;
511
512 fail_count++;
513 }
514
515 g_object_unref (xtruct_in);
516 g_object_unref (xtruct2_in);
517 g_object_unref (xtruct2_out);
518 g_object_unref (xtruct_out);
519
520 /**
521 * MAP TEST
522 */
523 map_out = g_hash_table_new_full (g_int_hash,
524 g_int_equal,
525 g_free,
526 g_free);
527 for (i = 0; i < 5; ++i) {
528 i32_key_ptr = g_malloc (sizeof *i32_key_ptr);
529 i32_value_ptr = g_malloc (sizeof *i32_value_ptr);
530
531 *i32_key_ptr = i;
532 *i32_value_ptr = i - 10;
533
534 g_hash_table_insert (map_out, i32_key_ptr, i32_value_ptr);
535 }
536 printf ("testMap({");
537 first = TRUE;
538 g_hash_table_iter_init (&hash_table_iter, map_out);
539 while (g_hash_table_iter_next (&hash_table_iter,
540 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200541 &value)) {
542 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200543 first = FALSE;
544 else
545 printf (", ");
546
547 printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
548 }
549 printf ("})");
550
551 map_in = g_hash_table_new_full (g_int_hash,
552 g_int_equal,
553 g_free,
554 g_free);
555
556 if (t_test_thrift_test_if_test_map (test_client,
557 &map_in,
558 map_out,
Roger Meier15df0762014-09-29 20:50:56 +0200559 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200560 printf (" = {");
561 first = TRUE;
562 g_hash_table_iter_init (&hash_table_iter, map_in);
563 while (g_hash_table_iter_next (&hash_table_iter,
564 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200565 &value)) {
566 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200567 first = FALSE;
568 else
569 printf (", ");
570
571 printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
572 }
573 printf ("}\n");
574
575 if (g_hash_table_size (map_in) != g_hash_table_size (map_out))
576 fail_count++;
577 else {
578 g_hash_table_iter_init (&hash_table_iter, map_out);
579 while (g_hash_table_iter_next (&hash_table_iter,
580 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200581 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200582 gpointer in_value = g_hash_table_lookup (map_in, key);
583 if (in_value == NULL ||
584 *(gint32 *)in_value != *(gint32 *)value) {
585 fail_count++;
586 break;
587 }
588 }
589 }
590 }
591 else {
592 printf ("%s\n", error->message);
593 g_error_free (error);
594 error = NULL;
595
596 fail_count++;
597 }
598
599 g_hash_table_unref (map_in);
600 g_hash_table_unref (map_out);
601
602 /**
603 * STRING MAP TEST
604 */
605 map_out = g_hash_table_new_full (g_str_hash,
606 g_str_equal,
607 NULL,
608 NULL);
609 g_hash_table_insert (map_out, "a", "2");
610 g_hash_table_insert (map_out, "b", "blah");
611 g_hash_table_insert (map_out, "some", "thing");
612 printf ("testStringMap({");
613 first = TRUE;
614 g_hash_table_iter_init (&hash_table_iter, map_out);
615 while (g_hash_table_iter_next (&hash_table_iter,
616 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200617 &value)) {
618 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200619 first = FALSE;
620 else
621 printf (", ");
622
623 printf ("\"%s\" => \"%s\"", (gchar *)key, (gchar *)value);
624 }
625 printf (")}");
626
627 map_in = g_hash_table_new_full (g_str_hash,
628 g_str_equal,
629 g_free,
630 g_free);
631
632 if (t_test_thrift_test_if_test_string_map (test_client,
633 &map_in,
634 map_out,
Roger Meier15df0762014-09-29 20:50:56 +0200635 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200636 printf (" = {");
637 first = TRUE;
638 g_hash_table_iter_init (&hash_table_iter, map_in);
639 while (g_hash_table_iter_next (&hash_table_iter,
640 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200641 &value)) {
642 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200643 first = FALSE;
644 else
645 printf (", ");
646
647 printf ("\"%s\" => \"%s\"", (gchar *)key, (gchar *)value);
648 }
649 printf ("}\n");
650
651 if (g_hash_table_size (map_in) != g_hash_table_size (map_out))
652 fail_count++;
653 else {
654 g_hash_table_iter_init (&hash_table_iter, map_out);
655 while (g_hash_table_iter_next (&hash_table_iter,
656 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200657 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200658 gpointer in_value = g_hash_table_lookup (map_in, key);
659 if (in_value == NULL ||
660 strcmp ((gchar *)in_value, (gchar *)value) != 0) {
661 fail_count++;
662 break;
663 }
664 }
665 }
666 }
667 else {
668 printf ("%s\n", error->message);
669 g_error_free (error);
670 error = NULL;
671
672 fail_count++;
673 }
674
675 g_hash_table_unref (map_in);
676 g_hash_table_unref (map_out);
677
678 /**
679 * SET TEST
680 */
681 set_out = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
682 for (i = -2; i < 3; ++i) {
683 i32_key_ptr = g_malloc (sizeof *i32_key_ptr);
684 *i32_key_ptr = i;
685
686 g_hash_table_insert (set_out, i32_key_ptr, NULL);
687 }
688 printf ("testSet({");
689 first = TRUE;
690 keys_out = g_hash_table_get_keys (set_out);
691 keys_elem = keys_out;
692 while (keys_elem != NULL) {
Roger Meier15df0762014-09-29 20:50:56 +0200693 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200694 first = FALSE;
695 else
696 printf (", ");
697
698 printf ("%d", *(gint32 *)keys_elem->data);
699
700 keys_elem = keys_elem->next;
701 }
702 printf ("})");
703
704 set_in = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
705
706 if (t_test_thrift_test_if_test_set (test_client,
707 &set_in,
708 set_out,
Roger Meier15df0762014-09-29 20:50:56 +0200709 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200710 printf(" = {");
711 first = TRUE;
712 keys_in = g_hash_table_get_keys (set_in);
713 keys_elem = keys_in;
714 while (keys_elem != NULL) {
Roger Meier15df0762014-09-29 20:50:56 +0200715 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200716 first = FALSE;
717 else
718 printf (", ");
719
720 printf ("%d", *(gint32 *)keys_elem->data);
721
722 keys_elem = keys_elem->next;
723 }
724 printf ("}\n");
725
726 if (g_list_length (keys_in) != g_list_length (keys_out))
727 fail_count++;
728 else {
729 keys_elem = keys_out;
730 while (keys_elem != NULL) {
731 if (g_list_find_custom (keys_in,
732 keys_elem->data,
733 gint32_compare) == NULL) {
734 fail_count++;
735 break;
736 }
737
738 keys_elem = keys_elem->next;
739 }
740 }
741
742 g_list_free (keys_in);
743 }
744 else {
745 printf ("%s\n", error->message);
746 g_error_free (error);
747 error = NULL;
748
749 fail_count++;
750 }
751
752 g_hash_table_unref (set_in);
753 g_list_free (keys_out);
754 g_hash_table_unref (set_out);
755
756 /**
757 * LIST TEST
758 */
759 list_out = g_array_new (FALSE, TRUE, sizeof (gint32));
760 for (i = -2; i < 3; ++i) {
761 g_array_append_val (list_out, i);
762 }
763 printf ("testList({");
764 first = TRUE;
765 for (i = 0; i < (gint32)list_out->len; ++i) {
Roger Meier15df0762014-09-29 20:50:56 +0200766 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200767 first = FALSE;
768 else
769 printf (", ");
770
771 printf ("%d", g_array_index (list_out, gint32, i));
772 }
773 printf ("})");
774
775 list_in = g_array_new (FALSE, TRUE, sizeof (gint32));
776
777 if (t_test_thrift_test_if_test_list (test_client,
778 &list_in,
779 list_out,
Roger Meier15df0762014-09-29 20:50:56 +0200780 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200781 printf (" = {");
782 first = TRUE;
783 for (i = 0; i < (gint32)list_in->len; ++i) {
Roger Meier15df0762014-09-29 20:50:56 +0200784 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200785 first = FALSE;
786 else
787 printf (", ");
788
789 printf ("%d", g_array_index (list_in, gint32, i));
790 }
791 printf ("}\n");
792
793 if (list_in->len != list_out->len ||
794 memcmp (list_in->data,
795 list_out->data,
796 list_in->len * sizeof (gint32)) != 0)
797 fail_count++;
798 }
799 else {
800 printf ("%s\n", error->message);
801 g_error_free (error);
802 error = NULL;
803
804 fail_count++;
805 }
806
807 g_array_unref (list_in);
808 g_array_unref (list_out);
809
810 /**
811 * ENUM TEST
812 */
813 printf("testEnum(ONE)");
814 if (t_test_thrift_test_if_test_enum (test_client,
815 &numberz,
816 T_TEST_NUMBERZ_ONE,
Roger Meier15df0762014-09-29 20:50:56 +0200817 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200818 printf(" = %d\n", numberz);
819 if (numberz != T_TEST_NUMBERZ_ONE)
820 fail_count++;
821 }
822 else {
823 printf ("%s\n", error->message);
824 g_error_free (error);
825 error = NULL;
826
827 fail_count++;
828 }
829
830 printf("testEnum(TWO)");
831 if (t_test_thrift_test_if_test_enum (test_client,
832 &numberz,
833 T_TEST_NUMBERZ_TWO,
Roger Meier15df0762014-09-29 20:50:56 +0200834 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200835 printf(" = %d\n", numberz);
836 if (numberz != T_TEST_NUMBERZ_TWO)
837 fail_count++;
838 }
839 else {
840 printf ("%s\n", error->message);
841 g_error_free (error);
842 error = NULL;
843
844 fail_count++;
845 }
846
847 printf("testEnum(THREE)");
848 if (t_test_thrift_test_if_test_enum (test_client,
849 &numberz,
850 T_TEST_NUMBERZ_THREE,
Roger Meier15df0762014-09-29 20:50:56 +0200851 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200852 printf(" = %d\n", numberz);
853 if (numberz != T_TEST_NUMBERZ_THREE)
854 fail_count++;
855 }
856 else {
857 printf ("%s\n", error->message);
858 g_error_free (error);
859 error = NULL;
860
861 fail_count++;
862 }
863
864 printf("testEnum(FIVE)");
865 if (t_test_thrift_test_if_test_enum (test_client,
866 &numberz,
867 T_TEST_NUMBERZ_FIVE,
Roger Meier15df0762014-09-29 20:50:56 +0200868 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200869 printf(" = %d\n", numberz);
870 if (numberz != T_TEST_NUMBERZ_FIVE)
871 fail_count++;
872 }
873 else {
874 printf ("%s\n", error->message);
875 g_error_free (error);
876 error = NULL;
877
878 fail_count++;
879 }
880
881 printf("testEnum(EIGHT)");
882 if (t_test_thrift_test_if_test_enum (test_client,
883 &numberz,
884 T_TEST_NUMBERZ_EIGHT,
Roger Meier15df0762014-09-29 20:50:56 +0200885 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200886 printf(" = %d\n", numberz);
887 if (numberz != T_TEST_NUMBERZ_EIGHT)
888 fail_count++;
889 }
890 else {
891 printf ("%s\n", error->message);
892 g_error_free (error);
893 error = NULL;
894
895 fail_count++;
896 }
897
898 /**
899 * TYPEDEF TEST
900 */
901 printf ("testTypedef(309858235082523)");
902 if (t_test_thrift_test_if_test_typedef (test_client,
903 &user_id,
904 309858235082523LL,
Roger Meier15df0762014-09-29 20:50:56 +0200905 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200906 printf(" = %" PRId64 "\n", user_id);
907 if (user_id != 309858235082523LL)
908 fail_count++;
909 }
910 else {
911 printf ("%s\n", error->message);
912 g_error_free (error);
913 error = NULL;
914
915 fail_count++;
916 }
917
918 /**
919 * NESTED MAP TEST
920 */
921 printf ("testMapMap(1)");
922 map_in = g_hash_table_new_full (g_int_hash,
923 g_int_equal,
924 g_free,
925 (GDestroyNotify)g_hash_table_unref);
926 if (t_test_thrift_test_if_test_map_map (test_client,
927 &map_in,
928 1,
Roger Meier15df0762014-09-29 20:50:56 +0200929 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200930 g_hash_table_iter_init (&hash_table_iter, map_in);
931
932 printf (" = {");
933 while (g_hash_table_iter_next (&hash_table_iter,
934 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200935 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200936 printf ("%d => {", *(gint32 *)key);
937
938 g_hash_table_iter_init (&inner_hash_table_iter,
939 (GHashTable *)value);
940 while (g_hash_table_iter_next (&inner_hash_table_iter,
941 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200942 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200943 printf ("%d => %d, ", *(gint32 *)key, *(gint32 *)value);
944 }
945
946 printf ("}, ");
947 }
948 printf ("}\n");
949
950 if (g_hash_table_size (map_in) != 2)
951 fail_count++;
952 else {
953 gint32 inner_keys[] = {1, 2, 3, 4};
954 gint32 i32_key;
955
956 i32_key = -4;
957 inner_map_in = g_hash_table_lookup (map_in, &i32_key);
958 if (inner_map_in == NULL ||
959 g_hash_table_size (inner_map_in) != 4)
960 fail_count++;
961 else {
962 keys_in = g_hash_table_get_keys (inner_map_in);
963 keys_in = g_list_sort (keys_in, gint32_compare);
964
965 for (i = 0; i < 4; i++) {
966 keys_elem = g_list_nth (keys_in, 3 - i);
967
968 if (*(gint32 *)keys_elem->data != (-1 * inner_keys[i]) ||
969 *(gint32 *)g_hash_table_lookup (inner_map_in,
970 keys_elem->data) !=
971 (-1 * inner_keys[i])) {
972 fail_count++;
973 break;
974 }
975 }
976
977 g_list_free (keys_in);
978 }
979
980 i32_key = 4;
981 inner_map_in = g_hash_table_lookup (map_in, &i32_key);
982 if (inner_map_in == NULL ||
983 g_hash_table_size (inner_map_in) != 4)
984 fail_count++;
985 else {
986 keys_in = g_hash_table_get_keys (inner_map_in);
987 keys_in = g_list_sort (keys_in, gint32_compare);
988
989 for (i = 0; i < 4; i++) {
990 keys_elem = g_list_nth (keys_in, i);
991
992 if (*(gint32 *)keys_elem->data != inner_keys[i] ||
993 *(gint32 *)g_hash_table_lookup (inner_map_in,
994 keys_elem->data) !=
995 inner_keys[i]) {
996 fail_count++;
997 break;
998 }
999 }
1000
1001 g_list_free (keys_in);
1002 }
1003 }
1004 }
1005 else {
1006 printf ("%s\n", error->message);
1007 g_error_free (error);
1008 error = NULL;
1009
1010 fail_count++;
1011 }
1012
1013 g_hash_table_unref (map_in);
1014
1015 /**
1016 * INSANITY TEST
1017 */
1018 insanity_out = g_object_new (T_TEST_TYPE_INSANITY, NULL);
1019 g_object_get (insanity_out,
1020 "userMap", &user_map,
1021 "xtructs", &xtructs,
1022 NULL);
1023
1024 numberz = T_TEST_NUMBERZ_FIVE;
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +09001025 numberz2 = T_TEST_NUMBERZ_EIGHT;
Roger Meierb3c84092014-09-01 21:53:40 +02001026 user_id_ptr = g_malloc (sizeof *user_id_ptr);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +09001027 *user_id_ptr = 5;
1028 user_id_ptr2 = g_malloc (sizeof *user_id_ptr);
1029 *user_id_ptr2 = 8;
Roger Meierb3c84092014-09-01 21:53:40 +02001030 g_hash_table_insert (user_map, (gpointer)numberz, user_id_ptr);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +09001031 g_hash_table_insert (user_map, (gpointer)numberz2, user_id_ptr2);
Roger Meierb3c84092014-09-01 21:53:40 +02001032 g_hash_table_unref (user_map);
1033
1034 xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT,
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +09001035 "string_thing", "Hello2",
1036 "byte_thing", 2,
1037 "i32_thing", 2,
1038 "i64_thing", 2LL,
Roger Meierb3c84092014-09-01 21:53:40 +02001039 NULL);
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +09001040 xtruct_out2 = g_object_new (T_TEST_TYPE_XTRUCT,
1041 "string_thing", "Goodbye4",
1042 "byte_thing", 4,
1043 "i32_thing", 4,
1044 "i64_thing", 4LL,
1045 NULL);
1046 g_ptr_array_add (xtructs, xtruct_out2);
Roger Meierb3c84092014-09-01 21:53:40 +02001047 g_ptr_array_add (xtructs, xtruct_out);
1048 g_ptr_array_unref (xtructs);
1049
1050 map_in = g_hash_table_new_full (g_int64_hash,
1051 g_int64_equal,
1052 g_free,
1053 (GDestroyNotify)g_hash_table_unref);
1054
1055 printf("testInsanity()");
1056 if (t_test_thrift_test_if_test_insanity (test_client,
1057 &map_in,
1058 insanity_out,
Roger Meier15df0762014-09-29 20:50:56 +02001059 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001060 printf (" = {");
1061 g_hash_table_iter_init (&hash_table_iter, map_in);
1062 while (g_hash_table_iter_next (&hash_table_iter,
1063 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001064 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001065 printf ("%" PRId64 " => {", *(TTestUserId *)key);
1066
1067 g_hash_table_iter_init (&inner_hash_table_iter,
1068 (GHashTable *)value);
1069 while (g_hash_table_iter_next (&inner_hash_table_iter,
1070 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001071 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001072 printf ("%d => {", (TTestNumberz)key);
1073
1074 g_object_get ((TTestInsanity *)value,
1075 "userMap", &user_map,
1076 "xtructs", &xtructs,
1077 NULL);
1078
1079 printf ("{");
1080 g_hash_table_iter_init (&user_map_iter, user_map);
1081 while (g_hash_table_iter_next (&user_map_iter,
1082 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001083 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001084 printf ("%d => %" PRId64 ", ",
1085 (TTestNumberz)key,
1086 *(TTestUserId *)value);
1087 }
1088 printf ("}, ");
1089 g_hash_table_unref (user_map);
1090
1091 printf("{");
1092 for (i = 0; i < (gint32)xtructs->len; ++i) {
1093 xtruct_in = g_ptr_array_index (xtructs, i);
1094 g_object_get (xtruct_in,
1095 "string_thing", &string,
1096 "byte_thing", &byte_thing,
1097 "i32_thing", &i32_thing,
1098 "i64_thing", &i64_thing,
1099 NULL);
1100
1101 printf ("{\"%s\", %d, %d, %" PRId64 "}, ",
1102 string,
1103 byte_thing,
1104 i32_thing,
1105 i64_thing);
1106 }
1107 printf ("}");
1108 g_ptr_array_unref (xtructs);
1109
1110 printf ("}, ");
1111 }
1112 printf("}, ");
1113 }
1114 printf("}\n");
1115
1116 if (g_hash_table_size (map_in) != 2)
1117 fail_count++;
1118 else {
1119 TTestNumberz numberz_key_values[] = {
1120 T_TEST_NUMBERZ_TWO, T_TEST_NUMBERZ_THREE
1121 };
1122 gint user_map_values[] = { 5, 8 };
1123 TTestUserId user_id_key;
1124
1125 user_id_key = 1;
1126 inner_map_in = g_hash_table_lookup (map_in, &user_id_key);
1127 if (inner_map_in == NULL ||
1128 g_hash_table_size (inner_map_in) != 2)
1129 fail_count++;
1130 else {
1131 TTestNumberz numberz_key;
1132
1133 for (i = 0; i < 2; ++i) {
1134 numberz_key = numberz_key_values[i];
1135 insanity_in =
1136 g_hash_table_lookup (inner_map_in,
1137 (gconstpointer)numberz_key);
1138 if (insanity_in == NULL)
1139 fail_count++;
1140 else {
1141 g_object_get (insanity_in,
1142 "userMap", &user_map,
1143 "xtructs", &xtructs,
1144 NULL);
1145
1146 if (user_map == NULL)
1147 fail_count++;
1148 else {
1149 if (g_hash_table_size (user_map) != 2)
1150 fail_count++;
1151 else {
1152 for (j = 0; j < 2; ++j) {
1153 numberz_key = (TTestNumberz)user_map_values[j];
1154
1155 value =
1156 g_hash_table_lookup (user_map,
1157 (gconstpointer)numberz_key);
1158 if (value == NULL ||
1159 *(TTestUserId *)value != (TTestUserId)user_map_values[j])
1160 fail_count++;
1161 }
1162 }
1163
1164 g_hash_table_unref (user_map);
1165 }
1166
1167 if (xtructs == NULL)
1168 fail_count++;
1169 else {
1170 if (xtructs->len != 2)
1171 fail_count++;
1172 else {
1173 xtruct_in = g_ptr_array_index (xtructs, 0);
1174 g_object_get (xtruct_in,
1175 "string_thing", &string,
1176 "byte_thing", &byte_thing,
1177 "i32_thing", &i32_thing,
1178 "i64_thing", &i64_thing,
1179 NULL);
1180 if ((string == NULL ||
1181 strncmp (string, "Goodbye4", 9) != 0) ||
1182 byte_thing != 4 ||
1183 i32_thing != 4 ||
1184 i64_thing != 4)
1185 fail_count++;
1186
1187 if (string != NULL)
1188 g_free (string);
1189
1190 xtruct_in = g_ptr_array_index (xtructs, 1);
1191 g_object_get (xtruct_in,
1192 "string_thing", &string,
1193 "byte_thing", &byte_thing,
1194 "i32_thing", &i32_thing,
1195 "i64_thing", &i64_thing,
1196 NULL);
1197 if ((string == NULL ||
1198 strncmp (string, "Hello2", 7) != 0) ||
1199 byte_thing != 2 ||
1200 i32_thing != 2 ||
1201 i64_thing != 2)
1202 fail_count++;
1203
1204 if (string != NULL)
1205 g_free (string);
1206 }
1207
1208 g_ptr_array_unref (xtructs);
1209 }
1210 }
1211 }
1212 }
1213
1214 user_id_key = 2;
1215 inner_map_in = g_hash_table_lookup (map_in, &user_id_key);
1216 if (inner_map_in == NULL ||
1217 g_hash_table_size (inner_map_in) != 1)
1218 fail_count++;
1219 else {
1220 insanity_in =
1221 g_hash_table_lookup (inner_map_in,
1222 (gconstpointer)T_TEST_NUMBERZ_SIX);
1223 if (insanity_in == NULL)
1224 fail_count++;
1225 else {
1226 g_object_get (insanity_in,
1227 "userMap", &user_map,
1228 "xtructs", &xtructs,
1229 NULL);
1230
1231 if (user_map == NULL)
1232 fail_count++;
1233 else {
1234 if (g_hash_table_size (user_map) != 0)
1235 fail_count++;
1236
1237 g_hash_table_unref (user_map);
1238 }
1239
1240 if (xtructs == NULL)
1241 fail_count++;
1242 else {
1243 if (xtructs->len != 0)
1244 fail_count++;
1245
1246 g_ptr_array_unref (xtructs);
1247 }
1248 }
1249 }
1250 }
1251 }
1252 else {
1253 printf ("%s\n", error->message);
1254 g_error_free (error);
1255 error = NULL;
1256
1257 fail_count++;
1258 }
1259
1260 g_hash_table_unref (map_in);
1261 g_object_unref (insanity_out);
1262
1263 /* test exception */
1264 printf ("testClient.testException(\"Xception\") =>");
Roger Meier15df0762014-09-29 20:50:56 +02001265 if (!t_test_thrift_test_if_test_exception (test_client,
1266 "Xception",
1267 &xception,
1268 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001269 xception != NULL) {
1270 g_object_get (xception,
1271 "errorCode", &int32,
1272 "message", &string,
1273 NULL);
1274 printf (" {%u, \"%s\"}\n", int32, string);
1275 g_free (string);
1276
1277 g_object_unref (xception);
1278 xception = NULL;
1279
1280 g_error_free (error);
1281 error = NULL;
1282 }
1283 else {
1284 printf (" void\nFAILURE\n");
1285 fail_count++;
1286
1287 if (xception != NULL) {
1288 g_object_unref (xception);
1289 xception = NULL;
1290 }
1291
1292 if (error != NULL) {
1293 g_error_free (error);
1294 error = NULL;
1295 }
1296 }
1297
1298 printf ("testClient.testException(\"TException\") =>");
Roger Meier15df0762014-09-29 20:50:56 +02001299 if (!t_test_thrift_test_if_test_exception (test_client,
1300 "TException",
1301 &xception,
1302 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001303 xception == NULL &&
1304 error != NULL) {
1305 printf (" Caught TException\n");
1306
1307 g_error_free (error);
1308 error = NULL;
1309 }
1310 else {
1311 printf (" void\nFAILURE\n");
1312 fail_count++;
1313
1314 if (xception != NULL) {
1315 g_object_unref (xception);
1316 xception = NULL;
1317 }
1318
1319 if (error != NULL) {
1320 g_error_free (error);
1321 error = NULL;
1322 }
1323 }
1324
1325 printf ("testClient.testException(\"success\") =>");
1326 if (t_test_thrift_test_if_test_exception (test_client,
1327 "success",
1328 &xception,
Roger Meier15df0762014-09-29 20:50:56 +02001329 &error))
Roger Meierb3c84092014-09-01 21:53:40 +02001330 printf (" void\n");
1331 else {
1332 printf (" void\nFAILURE\n");
1333 fail_count++;
1334
1335 if (xception != NULL) {
1336 g_object_unref (xception);
1337 xception = NULL;
1338 }
1339
1340 g_error_free (error);
1341 error = NULL;
1342 }
1343
1344 g_assert (error == NULL);
1345
1346 /* test multi exception */
1347 printf ("testClient.testMultiException(\"Xception\", \"test 1\") =>");
1348 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier15df0762014-09-29 20:50:56 +02001349 if (!t_test_thrift_test_if_test_multi_exception (test_client,
1350 &xtruct_in,
1351 "Xception",
1352 "test 1",
1353 &xception,
1354 &xception2,
1355 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001356 xception != NULL &&
1357 xception2 == NULL) {
1358 g_object_get (xception,
1359 "errorCode", &int32,
1360 "message", &string,
1361 NULL);
1362 printf (" {%u, \"%s\"}\n", int32, string);
1363 g_free (string);
1364
1365 g_object_unref (xception);
1366 xception = NULL;
1367
1368 g_error_free (error);
1369 error = NULL;
1370 }
1371 else {
1372 printf (" result\nFAILURE\n");
1373 fail_count++;
1374
1375 if (xception != NULL) {
1376 g_object_unref (xception);
1377 xception = NULL;
1378 }
1379
1380 if (xception2 != NULL) {
1381 g_object_unref (xception2);
1382 xception = NULL;
1383 }
1384
1385 if (error != NULL) {
1386 g_error_free (error);
1387 error = NULL;
1388 }
1389 }
1390 g_object_unref (xtruct_in);
1391
1392 printf ("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
1393 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier15df0762014-09-29 20:50:56 +02001394 if (!t_test_thrift_test_if_test_multi_exception (test_client,
1395 &xtruct_in,
1396 "Xception2",
1397 "test 2",
1398 &xception,
1399 &xception2,
1400 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001401 xception == NULL &&
1402 xception2 != NULL) {
1403 g_object_get (xception2,
1404 "errorCode", &int32,
1405 "struct_thing", &inner_xtruct_in,
1406 NULL);
1407 g_object_get (inner_xtruct_in,
1408 "string_thing", &string,
1409 NULL);
1410 printf (" {%u, {\"%s\"}}\n", int32, string);
1411 g_free (string);
1412
1413 g_object_unref (inner_xtruct_in);
1414 inner_xtruct_in = NULL;
1415
1416 g_object_unref (xception2);
1417 xception2 = NULL;
1418
1419 g_error_free (error);
1420 error = NULL;
1421 }
1422 else {
1423 printf (" result\nFAILURE\n");
1424 fail_count++;
1425
1426 if (xception != NULL) {
1427 g_object_unref (xception);
1428 xception = NULL;
1429 }
1430
1431 if (xception2 != NULL) {
1432 g_object_unref (xception2);
1433 xception = NULL;
1434 }
1435
1436 if (error != NULL) {
1437 g_error_free (error);
1438 error = NULL;
1439 }
1440 }
1441 g_object_unref (xtruct_in);
1442
1443 printf ("testClient.testMultiException(\"success\", \"test 3\") =>");
1444 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
1445 if (t_test_thrift_test_if_test_multi_exception (test_client,
1446 &xtruct_in,
1447 "success",
1448 "test 3",
1449 &xception,
1450 &xception2,
Roger Meier15df0762014-09-29 20:50:56 +02001451 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001452 xception == NULL &&
1453 xception2 == NULL) {
1454 g_object_get (xtruct_in,
1455 "string_thing", &string,
1456 NULL);
1457 printf (" {{\"%s\"}}\n", string);
1458 g_free (string);
1459 }
1460 else {
1461 printf (" result\nFAILURE\n");
1462 fail_count++;
1463
1464 if (xception != NULL) {
1465 g_object_unref (xception);
1466 xception = NULL;
1467 }
1468
1469 if (xception2 != NULL) {
1470 g_object_unref (xception2);
1471 xception = NULL;
1472 }
1473
1474 if (error != NULL) {
1475 g_error_free (error);
1476 error = NULL;
1477 }
1478 }
1479 g_object_unref (xtruct_in);
1480
1481 /* test oneway void */
1482 printf ("testClient.testOneway(1) =>");
1483 gettimeofday (&oneway_start, NULL);
1484 oneway_result = t_test_thrift_test_if_test_oneway (test_client,
1485 1,
1486 &error);
1487 gettimeofday (&oneway_end, NULL);
1488 timersub (&oneway_end, &oneway_start, &oneway_elapsed);
1489 oneway_elapsed_usec =
1490 oneway_elapsed.tv_sec * 1000 * 1000 + oneway_elapsed.tv_usec;
1491
Roger Meier15df0762014-09-29 20:50:56 +02001492 if (oneway_result) {
Roger Meierb3c84092014-09-01 21:53:40 +02001493 if (oneway_elapsed_usec > 200 * 1000) {
1494 printf (" FAILURE - took %.2f ms\n",
1495 (double)oneway_elapsed_usec / 1000.0);
1496 fail_count++;
1497 }
1498 else
1499 printf (" success - took %.2f ms\n",
1500 (double)oneway_elapsed_usec / 1000.0);
1501 }
1502 else {
1503 printf ("%s\n", error->message);
1504 g_error_free (error);
1505 error = NULL;
1506
1507 fail_count++;
1508 }
1509
1510 /**
1511 * redo a simple test after the oneway to make sure we aren't "off by
1512 * one" -- if the server treated oneway void like normal void, this next
1513 * test will fail since it will get the void confirmation rather than
1514 * the correct result. In this circumstance, the client will receive the
1515 * error:
1516 *
1517 * application error: Wrong method name
1518 */
1519 /**
1520 * I32 TEST
1521 */
1522 printf ("re-test testI32(-1)");
1523 if (t_test_thrift_test_if_test_i32 (test_client,
1524 &int32,
1525 -1,
Roger Meier15df0762014-09-29 20:50:56 +02001526 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001527 printf (" = %d\n", int32);
1528 if (int32 != -1)
1529 fail_count++;
1530 }
1531 else {
1532 printf ("%s\n", error->message);
1533 g_error_free (error);
1534 error = NULL;
1535
1536 fail_count++;
1537 }
1538
1539 gettimeofday (&time_stop, NULL);
1540 timersub (&time_stop, &time_start, &time_elapsed);
1541 time_elapsed_usec =
1542 time_elapsed.tv_sec * 1000 * 1000 + time_elapsed.tv_usec;
1543
1544 printf("Total time: %" PRIu64 " us\n", time_elapsed_usec);
1545
1546 time_total_usec += time_elapsed_usec;
1547 if (time_elapsed_usec < time_min_usec)
1548 time_min_usec = time_elapsed_usec;
1549 if (time_elapsed_usec > time_max_usec)
1550 time_max_usec = time_elapsed_usec;
1551
1552 thrift_transport_close (transport, &error);
1553 }
1554 else {
1555 printf ("Connect failed: %s\n", error->message);
1556 g_error_free (error);
1557 error = NULL;
1558
1559 return 1;
1560 }
1561 }
1562
1563 /* All done---output statistics */
1564 puts ("\nAll tests done.");
1565
1566 time_avg_usec = time_total_usec / num_tests;
1567
1568 printf ("Min time: %" PRIu64 " us\n", time_min_usec);
1569 printf ("Max time: %" PRIu64 " us\n", time_max_usec);
1570 printf ("Avg time: %" PRIu64 " us\n", time_avg_usec);
1571
1572 g_object_unref (test_client);
1573 g_object_unref (protocol);
1574 g_object_unref (transport);
1575 g_free (host);
1576
1577 return fail_count;
1578}