blob: b1fe0657cd8754c807a56684cac456cbf5660b34 [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
207 TTestXtruct *xtruct_out, *xtruct_in, *inner_xtruct_in;
208 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;
220
221 TTestUserId user_id, *user_id_ptr;
222
223 TTestInsanity *insanity_out, *insanity_in;
224 GHashTable *user_map;
225 GHashTableIter user_map_iter;
226 GPtrArray *xtructs;
227
228 TTestXception *xception = NULL;
229 TTestXception2 *xception2 = NULL;
230
231 gboolean oneway_result;
232 struct timeval oneway_start, oneway_end, oneway_elapsed;
233 gint oneway_elapsed_usec;
234
235 gboolean first;
236 gint32 i, j;
237
238 printf ("Test #%d, connect %s:%d\n", test_num + 1, host, port);
239 gettimeofday (&time_start, NULL);
240
241 /* These test routines have been ported from the C++ test
242 client, care being taken to ensure their output remains as
243 close as possible to the original to facilitate diffs.
244
245 For simplicity comments have been omitted, but every routine
246 has the same basic structure:
247
248 - Create and populate data structures as necessary.
249
250 - Format and output (to the console) a representation of the
251 outgoing data.
252
253 - Issue the remote method call to the server.
254
255 - Format and output a representation of the returned data.
256
257 - Verify the returned data matches what was expected.
258
259 - Deallocate any created data structures.
260
261 Note the recognized values and expected behaviour of each
262 remote method are described in ThriftTest.thrift, which
263 you'll find in the top-level "test" folder. */
264
265 /**
266 * VOID TEST
267 */
268 printf ("testVoid()");
Roger Meier15df0762014-09-29 20:50:56 +0200269 if (t_test_thrift_test_if_test_void (test_client, &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200270 printf (" = void\n");
271 }
272 else {
273 printf ("%s\n", error->message);
274 g_error_free (error);
275 error = NULL;
276
277 fail_count++;
278 }
279
280 /**
281 * STRING TEST
282 */
283 printf ("testString(\"Test\")");
284 if (t_test_thrift_test_if_test_string (test_client,
285 &string,
286 "Test",
Roger Meier15df0762014-09-29 20:50:56 +0200287 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200288 printf (" = \"%s\"\n", string);
289 if (strncmp (string, "Test", 5) != 0)
290 fail_count++;
291
292 g_free (string);
293 string = NULL;
294 }
295 else {
296 printf ("%s\n", error->message);
297 g_error_free (error);
298 error = NULL;
299
300 fail_count++;
301 }
302
303 /**
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900304 * BOOL TEST
305 */
306 printf ("testByte(true)");
307 if (t_test_thrift_test_if_test_bool (test_client,
308 &boolean,
309 1,
310 &error)) {
311 printf (" = %s\n", boolean ? "true" : "false");
312 if (boolean != 1)
313 fail_count++;
314 }
315 else {
316 printf ("%s\n", error->message);
317 g_error_free (error);
318 error = NULL;
319
320 fail_count++;
321 }
322 printf ("testByte(false)");
323 if (t_test_thrift_test_if_test_bool (test_client,
324 &boolean,
325 0,
326 &error)) {
327 printf (" = %s\n", boolean ? "true" : "false");
328 if (boolean != 0)
329 fail_count++;
330 }
331 else {
332 printf ("%s\n", error->message);
333 g_error_free (error);
334 error = NULL;
335
336 fail_count++;
337 }
338
339 /**
Roger Meierb3c84092014-09-01 21:53:40 +0200340 * BYTE TEST
341 */
342 printf ("testByte(1)");
343 if (t_test_thrift_test_if_test_byte (test_client,
344 &byte,
345 1,
Roger Meier15df0762014-09-29 20:50:56 +0200346 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200347 printf (" = %d\n", byte);
348 if (byte != 1)
349 fail_count++;
350 }
351 else {
352 printf ("%s\n", error->message);
353 g_error_free (error);
354 error = NULL;
355
356 fail_count++;
357 }
358
359 /**
360 * I32 TEST
361 */
362 printf ("testI32(-1)");
363 if (t_test_thrift_test_if_test_i32 (test_client,
364 &int32,
365 -1,
Roger Meier15df0762014-09-29 20:50:56 +0200366 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200367 printf (" = %d\n", int32);
368 if (int32 != -1)
369 fail_count++;
370 }
371 else {
372 printf ("%s\n", error->message);
373 g_error_free (error);
374 error = NULL;
375
376 fail_count++;
377 }
378
379 /**
380 * I64 TEST
381 */
382 printf ("testI64(-34359738368)");
383 if (t_test_thrift_test_if_test_i64 (test_client,
384 &int64,
385 (gint64)-34359738368,
Roger Meier15df0762014-09-29 20:50:56 +0200386 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200387 printf (" = %" PRId64 "\n", int64);
388 if (int64 != (gint64)-34359738368)
389 fail_count++;
390 }
391 else {
392 printf ("%s\n", error->message);
393 g_error_free (error);
394 error = NULL;
395
396 fail_count++;
397 }
398
399 /**
400 * DOUBLE TEST
401 */
402 printf("testDouble(-5.2098523)");
403 if (t_test_thrift_test_if_test_double (test_client,
404 &dub,
405 -5.2098523,
Roger Meier15df0762014-09-29 20:50:56 +0200406 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200407 printf (" = %f\n", dub);
408 if ((dub - (-5.2098523)) > 0.001)
409 fail_count++;
410 }
411 else {
412 printf ("%s\n", error->message);
413 g_error_free (error);
414 error = NULL;
415
416 fail_count++;
417 }
418
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100419 // TODO: add testBinary()
420
Roger Meierb3c84092014-09-01 21:53:40 +0200421 /**
422 * STRUCT TEST
423 */
424 printf ("testStruct({\"Zero\", 1, -3, -5})");
425 xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT,
426 "string_thing", "Zero",
427 "byte_thing", 1,
428 "i32_thing", -3,
429 "i64_thing", -5LL,
430 NULL);
431 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
432
433 if (t_test_thrift_test_if_test_struct (test_client,
434 &xtruct_in,
435 xtruct_out,
Roger Meier15df0762014-09-29 20:50:56 +0200436 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200437 g_object_get (xtruct_in,
438 "string_thing", &string,
439 "byte_thing", &byte_thing,
440 "i32_thing", &i32_thing,
441 "i64_thing", &i64_thing,
442 NULL);
443
444 printf (" = {\"%s\", %d, %d, %" PRId64 "}\n",
445 string,
446 byte_thing,
447 i32_thing,
448 i64_thing);
449 if ((string == NULL || strncmp (string, "Zero", 5) != 0) ||
450 byte_thing != 1 ||
451 i32_thing != -3 ||
452 i64_thing != (gint64)-5)
453 fail_count++;
454 }
455 else {
456 printf ("%s\n", error->message);
457 g_error_free (error);
458 error = NULL;
459
460 fail_count++;
461 }
462 g_object_unref (xtruct_in);
463
464 /**
465 * NESTED STRUCT TEST
466 */
467 printf ("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
468 xtruct2_out = g_object_new (T_TEST_TYPE_XTRUCT2,
469 "byte_thing", 1,
470 "struct_thing", xtruct_out,
471 "i32_thing", 5,
472 NULL);
473 xtruct2_in = g_object_new (T_TEST_TYPE_XTRUCT2, NULL);
474
475 if (t_test_thrift_test_if_test_nest (test_client,
476 &xtruct2_in,
477 xtruct2_out,
Roger Meier15df0762014-09-29 20:50:56 +0200478 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200479 g_object_get (xtruct2_in,
480 "byte_thing", &byte_thing,
481 "struct_thing", &xtruct_in,
482 "i32_thing", &i32_thing,
483 NULL);
484 g_object_get (xtruct_in,
485 "string_thing", &string,
486 "byte_thing", &inner_byte_thing,
487 "i32_thing", &inner_i32_thing,
488 "i64_thing", &inner_i64_thing,
489 NULL);
490
491 printf (" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
492 byte_thing,
493 string,
494 inner_byte_thing,
495 inner_i32_thing,
496 inner_i64_thing,
497 i32_thing);
498 if (byte_thing != 1 ||
499 (string == NULL || strncmp (string, "Zero", 5) != 0) ||
500 inner_byte_thing != 1 ||
501 inner_i32_thing != -3 ||
502 inner_i64_thing != (gint64)-5 ||
503 i32_thing != 5)
504 fail_count++;
505 }
506 else {
507 printf ("%s\n", error->message);
508 g_error_free (error);
509 error = NULL;
510
511 fail_count++;
512 }
513
514 g_object_unref (xtruct_in);
515 g_object_unref (xtruct2_in);
516 g_object_unref (xtruct2_out);
517 g_object_unref (xtruct_out);
518
519 /**
520 * MAP TEST
521 */
522 map_out = g_hash_table_new_full (g_int_hash,
523 g_int_equal,
524 g_free,
525 g_free);
526 for (i = 0; i < 5; ++i) {
527 i32_key_ptr = g_malloc (sizeof *i32_key_ptr);
528 i32_value_ptr = g_malloc (sizeof *i32_value_ptr);
529
530 *i32_key_ptr = i;
531 *i32_value_ptr = i - 10;
532
533 g_hash_table_insert (map_out, i32_key_ptr, i32_value_ptr);
534 }
535 printf ("testMap({");
536 first = TRUE;
537 g_hash_table_iter_init (&hash_table_iter, map_out);
538 while (g_hash_table_iter_next (&hash_table_iter,
539 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200540 &value)) {
541 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200542 first = FALSE;
543 else
544 printf (", ");
545
546 printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
547 }
548 printf ("})");
549
550 map_in = g_hash_table_new_full (g_int_hash,
551 g_int_equal,
552 g_free,
553 g_free);
554
555 if (t_test_thrift_test_if_test_map (test_client,
556 &map_in,
557 map_out,
Roger Meier15df0762014-09-29 20:50:56 +0200558 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200559 printf (" = {");
560 first = TRUE;
561 g_hash_table_iter_init (&hash_table_iter, map_in);
562 while (g_hash_table_iter_next (&hash_table_iter,
563 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200564 &value)) {
565 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200566 first = FALSE;
567 else
568 printf (", ");
569
570 printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
571 }
572 printf ("}\n");
573
574 if (g_hash_table_size (map_in) != g_hash_table_size (map_out))
575 fail_count++;
576 else {
577 g_hash_table_iter_init (&hash_table_iter, map_out);
578 while (g_hash_table_iter_next (&hash_table_iter,
579 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200580 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200581 gpointer in_value = g_hash_table_lookup (map_in, key);
582 if (in_value == NULL ||
583 *(gint32 *)in_value != *(gint32 *)value) {
584 fail_count++;
585 break;
586 }
587 }
588 }
589 }
590 else {
591 printf ("%s\n", error->message);
592 g_error_free (error);
593 error = NULL;
594
595 fail_count++;
596 }
597
598 g_hash_table_unref (map_in);
599 g_hash_table_unref (map_out);
600
601 /**
602 * STRING MAP TEST
603 */
604 map_out = g_hash_table_new_full (g_str_hash,
605 g_str_equal,
606 NULL,
607 NULL);
608 g_hash_table_insert (map_out, "a", "2");
609 g_hash_table_insert (map_out, "b", "blah");
610 g_hash_table_insert (map_out, "some", "thing");
611 printf ("testStringMap({");
612 first = TRUE;
613 g_hash_table_iter_init (&hash_table_iter, map_out);
614 while (g_hash_table_iter_next (&hash_table_iter,
615 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200616 &value)) {
617 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200618 first = FALSE;
619 else
620 printf (", ");
621
622 printf ("\"%s\" => \"%s\"", (gchar *)key, (gchar *)value);
623 }
624 printf (")}");
625
626 map_in = g_hash_table_new_full (g_str_hash,
627 g_str_equal,
628 g_free,
629 g_free);
630
631 if (t_test_thrift_test_if_test_string_map (test_client,
632 &map_in,
633 map_out,
Roger Meier15df0762014-09-29 20:50:56 +0200634 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200635 printf (" = {");
636 first = TRUE;
637 g_hash_table_iter_init (&hash_table_iter, map_in);
638 while (g_hash_table_iter_next (&hash_table_iter,
639 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200640 &value)) {
641 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200642 first = FALSE;
643 else
644 printf (", ");
645
646 printf ("\"%s\" => \"%s\"", (gchar *)key, (gchar *)value);
647 }
648 printf ("}\n");
649
650 if (g_hash_table_size (map_in) != g_hash_table_size (map_out))
651 fail_count++;
652 else {
653 g_hash_table_iter_init (&hash_table_iter, map_out);
654 while (g_hash_table_iter_next (&hash_table_iter,
655 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200656 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200657 gpointer in_value = g_hash_table_lookup (map_in, key);
658 if (in_value == NULL ||
659 strcmp ((gchar *)in_value, (gchar *)value) != 0) {
660 fail_count++;
661 break;
662 }
663 }
664 }
665 }
666 else {
667 printf ("%s\n", error->message);
668 g_error_free (error);
669 error = NULL;
670
671 fail_count++;
672 }
673
674 g_hash_table_unref (map_in);
675 g_hash_table_unref (map_out);
676
677 /**
678 * SET TEST
679 */
680 set_out = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
681 for (i = -2; i < 3; ++i) {
682 i32_key_ptr = g_malloc (sizeof *i32_key_ptr);
683 *i32_key_ptr = i;
684
685 g_hash_table_insert (set_out, i32_key_ptr, NULL);
686 }
687 printf ("testSet({");
688 first = TRUE;
689 keys_out = g_hash_table_get_keys (set_out);
690 keys_elem = keys_out;
691 while (keys_elem != NULL) {
Roger Meier15df0762014-09-29 20:50:56 +0200692 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200693 first = FALSE;
694 else
695 printf (", ");
696
697 printf ("%d", *(gint32 *)keys_elem->data);
698
699 keys_elem = keys_elem->next;
700 }
701 printf ("})");
702
703 set_in = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
704
705 if (t_test_thrift_test_if_test_set (test_client,
706 &set_in,
707 set_out,
Roger Meier15df0762014-09-29 20:50:56 +0200708 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200709 printf(" = {");
710 first = TRUE;
711 keys_in = g_hash_table_get_keys (set_in);
712 keys_elem = keys_in;
713 while (keys_elem != NULL) {
Roger Meier15df0762014-09-29 20:50:56 +0200714 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200715 first = FALSE;
716 else
717 printf (", ");
718
719 printf ("%d", *(gint32 *)keys_elem->data);
720
721 keys_elem = keys_elem->next;
722 }
723 printf ("}\n");
724
725 if (g_list_length (keys_in) != g_list_length (keys_out))
726 fail_count++;
727 else {
728 keys_elem = keys_out;
729 while (keys_elem != NULL) {
730 if (g_list_find_custom (keys_in,
731 keys_elem->data,
732 gint32_compare) == NULL) {
733 fail_count++;
734 break;
735 }
736
737 keys_elem = keys_elem->next;
738 }
739 }
740
741 g_list_free (keys_in);
742 }
743 else {
744 printf ("%s\n", error->message);
745 g_error_free (error);
746 error = NULL;
747
748 fail_count++;
749 }
750
751 g_hash_table_unref (set_in);
752 g_list_free (keys_out);
753 g_hash_table_unref (set_out);
754
755 /**
756 * LIST TEST
757 */
758 list_out = g_array_new (FALSE, TRUE, sizeof (gint32));
759 for (i = -2; i < 3; ++i) {
760 g_array_append_val (list_out, i);
761 }
762 printf ("testList({");
763 first = TRUE;
764 for (i = 0; i < (gint32)list_out->len; ++i) {
Roger Meier15df0762014-09-29 20:50:56 +0200765 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200766 first = FALSE;
767 else
768 printf (", ");
769
770 printf ("%d", g_array_index (list_out, gint32, i));
771 }
772 printf ("})");
773
774 list_in = g_array_new (FALSE, TRUE, sizeof (gint32));
775
776 if (t_test_thrift_test_if_test_list (test_client,
777 &list_in,
778 list_out,
Roger Meier15df0762014-09-29 20:50:56 +0200779 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200780 printf (" = {");
781 first = TRUE;
782 for (i = 0; i < (gint32)list_in->len; ++i) {
Roger Meier15df0762014-09-29 20:50:56 +0200783 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200784 first = FALSE;
785 else
786 printf (", ");
787
788 printf ("%d", g_array_index (list_in, gint32, i));
789 }
790 printf ("}\n");
791
792 if (list_in->len != list_out->len ||
793 memcmp (list_in->data,
794 list_out->data,
795 list_in->len * sizeof (gint32)) != 0)
796 fail_count++;
797 }
798 else {
799 printf ("%s\n", error->message);
800 g_error_free (error);
801 error = NULL;
802
803 fail_count++;
804 }
805
806 g_array_unref (list_in);
807 g_array_unref (list_out);
808
809 /**
810 * ENUM TEST
811 */
812 printf("testEnum(ONE)");
813 if (t_test_thrift_test_if_test_enum (test_client,
814 &numberz,
815 T_TEST_NUMBERZ_ONE,
Roger Meier15df0762014-09-29 20:50:56 +0200816 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200817 printf(" = %d\n", numberz);
818 if (numberz != T_TEST_NUMBERZ_ONE)
819 fail_count++;
820 }
821 else {
822 printf ("%s\n", error->message);
823 g_error_free (error);
824 error = NULL;
825
826 fail_count++;
827 }
828
829 printf("testEnum(TWO)");
830 if (t_test_thrift_test_if_test_enum (test_client,
831 &numberz,
832 T_TEST_NUMBERZ_TWO,
Roger Meier15df0762014-09-29 20:50:56 +0200833 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200834 printf(" = %d\n", numberz);
835 if (numberz != T_TEST_NUMBERZ_TWO)
836 fail_count++;
837 }
838 else {
839 printf ("%s\n", error->message);
840 g_error_free (error);
841 error = NULL;
842
843 fail_count++;
844 }
845
846 printf("testEnum(THREE)");
847 if (t_test_thrift_test_if_test_enum (test_client,
848 &numberz,
849 T_TEST_NUMBERZ_THREE,
Roger Meier15df0762014-09-29 20:50:56 +0200850 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200851 printf(" = %d\n", numberz);
852 if (numberz != T_TEST_NUMBERZ_THREE)
853 fail_count++;
854 }
855 else {
856 printf ("%s\n", error->message);
857 g_error_free (error);
858 error = NULL;
859
860 fail_count++;
861 }
862
863 printf("testEnum(FIVE)");
864 if (t_test_thrift_test_if_test_enum (test_client,
865 &numberz,
866 T_TEST_NUMBERZ_FIVE,
Roger Meier15df0762014-09-29 20:50:56 +0200867 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200868 printf(" = %d\n", numberz);
869 if (numberz != T_TEST_NUMBERZ_FIVE)
870 fail_count++;
871 }
872 else {
873 printf ("%s\n", error->message);
874 g_error_free (error);
875 error = NULL;
876
877 fail_count++;
878 }
879
880 printf("testEnum(EIGHT)");
881 if (t_test_thrift_test_if_test_enum (test_client,
882 &numberz,
883 T_TEST_NUMBERZ_EIGHT,
Roger Meier15df0762014-09-29 20:50:56 +0200884 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200885 printf(" = %d\n", numberz);
886 if (numberz != T_TEST_NUMBERZ_EIGHT)
887 fail_count++;
888 }
889 else {
890 printf ("%s\n", error->message);
891 g_error_free (error);
892 error = NULL;
893
894 fail_count++;
895 }
896
897 /**
898 * TYPEDEF TEST
899 */
900 printf ("testTypedef(309858235082523)");
901 if (t_test_thrift_test_if_test_typedef (test_client,
902 &user_id,
903 309858235082523LL,
Roger Meier15df0762014-09-29 20:50:56 +0200904 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200905 printf(" = %" PRId64 "\n", user_id);
906 if (user_id != 309858235082523LL)
907 fail_count++;
908 }
909 else {
910 printf ("%s\n", error->message);
911 g_error_free (error);
912 error = NULL;
913
914 fail_count++;
915 }
916
917 /**
918 * NESTED MAP TEST
919 */
920 printf ("testMapMap(1)");
921 map_in = g_hash_table_new_full (g_int_hash,
922 g_int_equal,
923 g_free,
924 (GDestroyNotify)g_hash_table_unref);
925 if (t_test_thrift_test_if_test_map_map (test_client,
926 &map_in,
927 1,
Roger Meier15df0762014-09-29 20:50:56 +0200928 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200929 g_hash_table_iter_init (&hash_table_iter, map_in);
930
931 printf (" = {");
932 while (g_hash_table_iter_next (&hash_table_iter,
933 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200934 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200935 printf ("%d => {", *(gint32 *)key);
936
937 g_hash_table_iter_init (&inner_hash_table_iter,
938 (GHashTable *)value);
939 while (g_hash_table_iter_next (&inner_hash_table_iter,
940 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200941 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200942 printf ("%d => %d, ", *(gint32 *)key, *(gint32 *)value);
943 }
944
945 printf ("}, ");
946 }
947 printf ("}\n");
948
949 if (g_hash_table_size (map_in) != 2)
950 fail_count++;
951 else {
952 gint32 inner_keys[] = {1, 2, 3, 4};
953 gint32 i32_key;
954
955 i32_key = -4;
956 inner_map_in = g_hash_table_lookup (map_in, &i32_key);
957 if (inner_map_in == NULL ||
958 g_hash_table_size (inner_map_in) != 4)
959 fail_count++;
960 else {
961 keys_in = g_hash_table_get_keys (inner_map_in);
962 keys_in = g_list_sort (keys_in, gint32_compare);
963
964 for (i = 0; i < 4; i++) {
965 keys_elem = g_list_nth (keys_in, 3 - i);
966
967 if (*(gint32 *)keys_elem->data != (-1 * inner_keys[i]) ||
968 *(gint32 *)g_hash_table_lookup (inner_map_in,
969 keys_elem->data) !=
970 (-1 * inner_keys[i])) {
971 fail_count++;
972 break;
973 }
974 }
975
976 g_list_free (keys_in);
977 }
978
979 i32_key = 4;
980 inner_map_in = g_hash_table_lookup (map_in, &i32_key);
981 if (inner_map_in == NULL ||
982 g_hash_table_size (inner_map_in) != 4)
983 fail_count++;
984 else {
985 keys_in = g_hash_table_get_keys (inner_map_in);
986 keys_in = g_list_sort (keys_in, gint32_compare);
987
988 for (i = 0; i < 4; i++) {
989 keys_elem = g_list_nth (keys_in, i);
990
991 if (*(gint32 *)keys_elem->data != inner_keys[i] ||
992 *(gint32 *)g_hash_table_lookup (inner_map_in,
993 keys_elem->data) !=
994 inner_keys[i]) {
995 fail_count++;
996 break;
997 }
998 }
999
1000 g_list_free (keys_in);
1001 }
1002 }
1003 }
1004 else {
1005 printf ("%s\n", error->message);
1006 g_error_free (error);
1007 error = NULL;
1008
1009 fail_count++;
1010 }
1011
1012 g_hash_table_unref (map_in);
1013
1014 /**
1015 * INSANITY TEST
1016 */
1017 insanity_out = g_object_new (T_TEST_TYPE_INSANITY, NULL);
1018 g_object_get (insanity_out,
1019 "userMap", &user_map,
1020 "xtructs", &xtructs,
1021 NULL);
1022
1023 numberz = T_TEST_NUMBERZ_FIVE;
1024 user_id_ptr = g_malloc (sizeof *user_id_ptr);
1025 *user_id_ptr = 5000;
1026 g_hash_table_insert (user_map, (gpointer)numberz, user_id_ptr);
1027 g_hash_table_unref (user_map);
1028
1029 xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT,
1030 "string_thing", "Truck",
1031 "byte_thing", 8,
1032 "i32_thing", 8,
Roger Meier15df0762014-09-29 20:50:56 +02001033 "i64_thing", 8LL,
Roger Meierb3c84092014-09-01 21:53:40 +02001034 NULL);
1035 g_ptr_array_add (xtructs, xtruct_out);
1036 g_ptr_array_unref (xtructs);
1037
1038 map_in = g_hash_table_new_full (g_int64_hash,
1039 g_int64_equal,
1040 g_free,
1041 (GDestroyNotify)g_hash_table_unref);
1042
1043 printf("testInsanity()");
1044 if (t_test_thrift_test_if_test_insanity (test_client,
1045 &map_in,
1046 insanity_out,
Roger Meier15df0762014-09-29 20:50:56 +02001047 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001048 printf (" = {");
1049 g_hash_table_iter_init (&hash_table_iter, map_in);
1050 while (g_hash_table_iter_next (&hash_table_iter,
1051 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001052 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001053 printf ("%" PRId64 " => {", *(TTestUserId *)key);
1054
1055 g_hash_table_iter_init (&inner_hash_table_iter,
1056 (GHashTable *)value);
1057 while (g_hash_table_iter_next (&inner_hash_table_iter,
1058 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001059 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001060 printf ("%d => {", (TTestNumberz)key);
1061
1062 g_object_get ((TTestInsanity *)value,
1063 "userMap", &user_map,
1064 "xtructs", &xtructs,
1065 NULL);
1066
1067 printf ("{");
1068 g_hash_table_iter_init (&user_map_iter, user_map);
1069 while (g_hash_table_iter_next (&user_map_iter,
1070 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001071 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001072 printf ("%d => %" PRId64 ", ",
1073 (TTestNumberz)key,
1074 *(TTestUserId *)value);
1075 }
1076 printf ("}, ");
1077 g_hash_table_unref (user_map);
1078
1079 printf("{");
1080 for (i = 0; i < (gint32)xtructs->len; ++i) {
1081 xtruct_in = g_ptr_array_index (xtructs, i);
1082 g_object_get (xtruct_in,
1083 "string_thing", &string,
1084 "byte_thing", &byte_thing,
1085 "i32_thing", &i32_thing,
1086 "i64_thing", &i64_thing,
1087 NULL);
1088
1089 printf ("{\"%s\", %d, %d, %" PRId64 "}, ",
1090 string,
1091 byte_thing,
1092 i32_thing,
1093 i64_thing);
1094 }
1095 printf ("}");
1096 g_ptr_array_unref (xtructs);
1097
1098 printf ("}, ");
1099 }
1100 printf("}, ");
1101 }
1102 printf("}\n");
1103
1104 if (g_hash_table_size (map_in) != 2)
1105 fail_count++;
1106 else {
1107 TTestNumberz numberz_key_values[] = {
1108 T_TEST_NUMBERZ_TWO, T_TEST_NUMBERZ_THREE
1109 };
1110 gint user_map_values[] = { 5, 8 };
1111 TTestUserId user_id_key;
1112
1113 user_id_key = 1;
1114 inner_map_in = g_hash_table_lookup (map_in, &user_id_key);
1115 if (inner_map_in == NULL ||
1116 g_hash_table_size (inner_map_in) != 2)
1117 fail_count++;
1118 else {
1119 TTestNumberz numberz_key;
1120
1121 for (i = 0; i < 2; ++i) {
1122 numberz_key = numberz_key_values[i];
1123 insanity_in =
1124 g_hash_table_lookup (inner_map_in,
1125 (gconstpointer)numberz_key);
1126 if (insanity_in == NULL)
1127 fail_count++;
1128 else {
1129 g_object_get (insanity_in,
1130 "userMap", &user_map,
1131 "xtructs", &xtructs,
1132 NULL);
1133
1134 if (user_map == NULL)
1135 fail_count++;
1136 else {
1137 if (g_hash_table_size (user_map) != 2)
1138 fail_count++;
1139 else {
1140 for (j = 0; j < 2; ++j) {
1141 numberz_key = (TTestNumberz)user_map_values[j];
1142
1143 value =
1144 g_hash_table_lookup (user_map,
1145 (gconstpointer)numberz_key);
1146 if (value == NULL ||
1147 *(TTestUserId *)value != (TTestUserId)user_map_values[j])
1148 fail_count++;
1149 }
1150 }
1151
1152 g_hash_table_unref (user_map);
1153 }
1154
1155 if (xtructs == NULL)
1156 fail_count++;
1157 else {
1158 if (xtructs->len != 2)
1159 fail_count++;
1160 else {
1161 xtruct_in = g_ptr_array_index (xtructs, 0);
1162 g_object_get (xtruct_in,
1163 "string_thing", &string,
1164 "byte_thing", &byte_thing,
1165 "i32_thing", &i32_thing,
1166 "i64_thing", &i64_thing,
1167 NULL);
1168 if ((string == NULL ||
1169 strncmp (string, "Goodbye4", 9) != 0) ||
1170 byte_thing != 4 ||
1171 i32_thing != 4 ||
1172 i64_thing != 4)
1173 fail_count++;
1174
1175 if (string != NULL)
1176 g_free (string);
1177
1178 xtruct_in = g_ptr_array_index (xtructs, 1);
1179 g_object_get (xtruct_in,
1180 "string_thing", &string,
1181 "byte_thing", &byte_thing,
1182 "i32_thing", &i32_thing,
1183 "i64_thing", &i64_thing,
1184 NULL);
1185 if ((string == NULL ||
1186 strncmp (string, "Hello2", 7) != 0) ||
1187 byte_thing != 2 ||
1188 i32_thing != 2 ||
1189 i64_thing != 2)
1190 fail_count++;
1191
1192 if (string != NULL)
1193 g_free (string);
1194 }
1195
1196 g_ptr_array_unref (xtructs);
1197 }
1198 }
1199 }
1200 }
1201
1202 user_id_key = 2;
1203 inner_map_in = g_hash_table_lookup (map_in, &user_id_key);
1204 if (inner_map_in == NULL ||
1205 g_hash_table_size (inner_map_in) != 1)
1206 fail_count++;
1207 else {
1208 insanity_in =
1209 g_hash_table_lookup (inner_map_in,
1210 (gconstpointer)T_TEST_NUMBERZ_SIX);
1211 if (insanity_in == NULL)
1212 fail_count++;
1213 else {
1214 g_object_get (insanity_in,
1215 "userMap", &user_map,
1216 "xtructs", &xtructs,
1217 NULL);
1218
1219 if (user_map == NULL)
1220 fail_count++;
1221 else {
1222 if (g_hash_table_size (user_map) != 0)
1223 fail_count++;
1224
1225 g_hash_table_unref (user_map);
1226 }
1227
1228 if (xtructs == NULL)
1229 fail_count++;
1230 else {
1231 if (xtructs->len != 0)
1232 fail_count++;
1233
1234 g_ptr_array_unref (xtructs);
1235 }
1236 }
1237 }
1238 }
1239 }
1240 else {
1241 printf ("%s\n", error->message);
1242 g_error_free (error);
1243 error = NULL;
1244
1245 fail_count++;
1246 }
1247
1248 g_hash_table_unref (map_in);
1249 g_object_unref (insanity_out);
1250
1251 /* test exception */
1252 printf ("testClient.testException(\"Xception\") =>");
Roger Meier15df0762014-09-29 20:50:56 +02001253 if (!t_test_thrift_test_if_test_exception (test_client,
1254 "Xception",
1255 &xception,
1256 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001257 xception != NULL) {
1258 g_object_get (xception,
1259 "errorCode", &int32,
1260 "message", &string,
1261 NULL);
1262 printf (" {%u, \"%s\"}\n", int32, string);
1263 g_free (string);
1264
1265 g_object_unref (xception);
1266 xception = NULL;
1267
1268 g_error_free (error);
1269 error = NULL;
1270 }
1271 else {
1272 printf (" void\nFAILURE\n");
1273 fail_count++;
1274
1275 if (xception != NULL) {
1276 g_object_unref (xception);
1277 xception = NULL;
1278 }
1279
1280 if (error != NULL) {
1281 g_error_free (error);
1282 error = NULL;
1283 }
1284 }
1285
1286 printf ("testClient.testException(\"TException\") =>");
Roger Meier15df0762014-09-29 20:50:56 +02001287 if (!t_test_thrift_test_if_test_exception (test_client,
1288 "TException",
1289 &xception,
1290 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001291 xception == NULL &&
1292 error != NULL) {
1293 printf (" Caught TException\n");
1294
1295 g_error_free (error);
1296 error = NULL;
1297 }
1298 else {
1299 printf (" void\nFAILURE\n");
1300 fail_count++;
1301
1302 if (xception != NULL) {
1303 g_object_unref (xception);
1304 xception = NULL;
1305 }
1306
1307 if (error != NULL) {
1308 g_error_free (error);
1309 error = NULL;
1310 }
1311 }
1312
1313 printf ("testClient.testException(\"success\") =>");
1314 if (t_test_thrift_test_if_test_exception (test_client,
1315 "success",
1316 &xception,
Roger Meier15df0762014-09-29 20:50:56 +02001317 &error))
Roger Meierb3c84092014-09-01 21:53:40 +02001318 printf (" void\n");
1319 else {
1320 printf (" void\nFAILURE\n");
1321 fail_count++;
1322
1323 if (xception != NULL) {
1324 g_object_unref (xception);
1325 xception = NULL;
1326 }
1327
1328 g_error_free (error);
1329 error = NULL;
1330 }
1331
1332 g_assert (error == NULL);
1333
1334 /* test multi exception */
1335 printf ("testClient.testMultiException(\"Xception\", \"test 1\") =>");
1336 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier15df0762014-09-29 20:50:56 +02001337 if (!t_test_thrift_test_if_test_multi_exception (test_client,
1338 &xtruct_in,
1339 "Xception",
1340 "test 1",
1341 &xception,
1342 &xception2,
1343 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001344 xception != NULL &&
1345 xception2 == NULL) {
1346 g_object_get (xception,
1347 "errorCode", &int32,
1348 "message", &string,
1349 NULL);
1350 printf (" {%u, \"%s\"}\n", int32, string);
1351 g_free (string);
1352
1353 g_object_unref (xception);
1354 xception = NULL;
1355
1356 g_error_free (error);
1357 error = NULL;
1358 }
1359 else {
1360 printf (" result\nFAILURE\n");
1361 fail_count++;
1362
1363 if (xception != NULL) {
1364 g_object_unref (xception);
1365 xception = NULL;
1366 }
1367
1368 if (xception2 != NULL) {
1369 g_object_unref (xception2);
1370 xception = NULL;
1371 }
1372
1373 if (error != NULL) {
1374 g_error_free (error);
1375 error = NULL;
1376 }
1377 }
1378 g_object_unref (xtruct_in);
1379
1380 printf ("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
1381 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier15df0762014-09-29 20:50:56 +02001382 if (!t_test_thrift_test_if_test_multi_exception (test_client,
1383 &xtruct_in,
1384 "Xception2",
1385 "test 2",
1386 &xception,
1387 &xception2,
1388 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001389 xception == NULL &&
1390 xception2 != NULL) {
1391 g_object_get (xception2,
1392 "errorCode", &int32,
1393 "struct_thing", &inner_xtruct_in,
1394 NULL);
1395 g_object_get (inner_xtruct_in,
1396 "string_thing", &string,
1397 NULL);
1398 printf (" {%u, {\"%s\"}}\n", int32, string);
1399 g_free (string);
1400
1401 g_object_unref (inner_xtruct_in);
1402 inner_xtruct_in = NULL;
1403
1404 g_object_unref (xception2);
1405 xception2 = NULL;
1406
1407 g_error_free (error);
1408 error = NULL;
1409 }
1410 else {
1411 printf (" result\nFAILURE\n");
1412 fail_count++;
1413
1414 if (xception != NULL) {
1415 g_object_unref (xception);
1416 xception = NULL;
1417 }
1418
1419 if (xception2 != NULL) {
1420 g_object_unref (xception2);
1421 xception = NULL;
1422 }
1423
1424 if (error != NULL) {
1425 g_error_free (error);
1426 error = NULL;
1427 }
1428 }
1429 g_object_unref (xtruct_in);
1430
1431 printf ("testClient.testMultiException(\"success\", \"test 3\") =>");
1432 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
1433 if (t_test_thrift_test_if_test_multi_exception (test_client,
1434 &xtruct_in,
1435 "success",
1436 "test 3",
1437 &xception,
1438 &xception2,
Roger Meier15df0762014-09-29 20:50:56 +02001439 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001440 xception == NULL &&
1441 xception2 == NULL) {
1442 g_object_get (xtruct_in,
1443 "string_thing", &string,
1444 NULL);
1445 printf (" {{\"%s\"}}\n", string);
1446 g_free (string);
1447 }
1448 else {
1449 printf (" result\nFAILURE\n");
1450 fail_count++;
1451
1452 if (xception != NULL) {
1453 g_object_unref (xception);
1454 xception = NULL;
1455 }
1456
1457 if (xception2 != NULL) {
1458 g_object_unref (xception2);
1459 xception = NULL;
1460 }
1461
1462 if (error != NULL) {
1463 g_error_free (error);
1464 error = NULL;
1465 }
1466 }
1467 g_object_unref (xtruct_in);
1468
1469 /* test oneway void */
1470 printf ("testClient.testOneway(1) =>");
1471 gettimeofday (&oneway_start, NULL);
1472 oneway_result = t_test_thrift_test_if_test_oneway (test_client,
1473 1,
1474 &error);
1475 gettimeofday (&oneway_end, NULL);
1476 timersub (&oneway_end, &oneway_start, &oneway_elapsed);
1477 oneway_elapsed_usec =
1478 oneway_elapsed.tv_sec * 1000 * 1000 + oneway_elapsed.tv_usec;
1479
Roger Meier15df0762014-09-29 20:50:56 +02001480 if (oneway_result) {
Roger Meierb3c84092014-09-01 21:53:40 +02001481 if (oneway_elapsed_usec > 200 * 1000) {
1482 printf (" FAILURE - took %.2f ms\n",
1483 (double)oneway_elapsed_usec / 1000.0);
1484 fail_count++;
1485 }
1486 else
1487 printf (" success - took %.2f ms\n",
1488 (double)oneway_elapsed_usec / 1000.0);
1489 }
1490 else {
1491 printf ("%s\n", error->message);
1492 g_error_free (error);
1493 error = NULL;
1494
1495 fail_count++;
1496 }
1497
1498 /**
1499 * redo a simple test after the oneway to make sure we aren't "off by
1500 * one" -- if the server treated oneway void like normal void, this next
1501 * test will fail since it will get the void confirmation rather than
1502 * the correct result. In this circumstance, the client will receive the
1503 * error:
1504 *
1505 * application error: Wrong method name
1506 */
1507 /**
1508 * I32 TEST
1509 */
1510 printf ("re-test testI32(-1)");
1511 if (t_test_thrift_test_if_test_i32 (test_client,
1512 &int32,
1513 -1,
Roger Meier15df0762014-09-29 20:50:56 +02001514 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001515 printf (" = %d\n", int32);
1516 if (int32 != -1)
1517 fail_count++;
1518 }
1519 else {
1520 printf ("%s\n", error->message);
1521 g_error_free (error);
1522 error = NULL;
1523
1524 fail_count++;
1525 }
1526
1527 gettimeofday (&time_stop, NULL);
1528 timersub (&time_stop, &time_start, &time_elapsed);
1529 time_elapsed_usec =
1530 time_elapsed.tv_sec * 1000 * 1000 + time_elapsed.tv_usec;
1531
1532 printf("Total time: %" PRIu64 " us\n", time_elapsed_usec);
1533
1534 time_total_usec += time_elapsed_usec;
1535 if (time_elapsed_usec < time_min_usec)
1536 time_min_usec = time_elapsed_usec;
1537 if (time_elapsed_usec > time_max_usec)
1538 time_max_usec = time_elapsed_usec;
1539
1540 thrift_transport_close (transport, &error);
1541 }
1542 else {
1543 printf ("Connect failed: %s\n", error->message);
1544 g_error_free (error);
1545 error = NULL;
1546
1547 return 1;
1548 }
1549 }
1550
1551 /* All done---output statistics */
1552 puts ("\nAll tests done.");
1553
1554 time_avg_usec = time_total_usec / num_tests;
1555
1556 printf ("Min time: %" PRIu64 " us\n", time_min_usec);
1557 printf ("Max time: %" PRIu64 " us\n", time_max_usec);
1558 printf ("Avg time: %" PRIu64 " us\n", time_avg_usec);
1559
1560 g_object_unref (test_client);
1561 g_object_unref (protocol);
1562 g_object_unref (transport);
1563 g_free (host);
1564
1565 return fail_count;
1566}