blob: dba2daf13af0f35db1fa16c2a0503b6d3cea04a9 [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)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200197 gchar *string = NULL;
198 gint8 byte = 0;
199 gint32 int32 = 0;
200 gint64 int64 = 0;
201 gdouble dub = 0;
202
203 gint byte_thing, i32_thing, inner_byte_thing, inner_i32_thing;
204 gint64 i64_thing, inner_i64_thing;
205
206 TTestXtruct *xtruct_out, *xtruct_in, *inner_xtruct_in;
207 TTestXtruct2 *xtruct2_out, *xtruct2_in;
208
209 GHashTable *map_out, *map_in, *inner_map_in;
210 GHashTable *set_out, *set_in;
211 gpointer key, value;
212 gint32 *i32_key_ptr, *i32_value_ptr;
213 GHashTableIter hash_table_iter, inner_hash_table_iter;
214 GList *keys_out, *keys_in, *keys_elem;
215
216 GArray *list_out, *list_in;
217
218 TTestNumberz numberz;
219
220 TTestUserId user_id, *user_id_ptr;
221
222 TTestInsanity *insanity_out, *insanity_in;
223 GHashTable *user_map;
224 GHashTableIter user_map_iter;
225 GPtrArray *xtructs;
226
227 TTestXception *xception = NULL;
228 TTestXception2 *xception2 = NULL;
229
230 gboolean oneway_result;
231 struct timeval oneway_start, oneway_end, oneway_elapsed;
232 gint oneway_elapsed_usec;
233
234 gboolean first;
235 gint32 i, j;
236
237 printf ("Test #%d, connect %s:%d\n", test_num + 1, host, port);
238 gettimeofday (&time_start, NULL);
239
240 /* These test routines have been ported from the C++ test
241 client, care being taken to ensure their output remains as
242 close as possible to the original to facilitate diffs.
243
244 For simplicity comments have been omitted, but every routine
245 has the same basic structure:
246
247 - Create and populate data structures as necessary.
248
249 - Format and output (to the console) a representation of the
250 outgoing data.
251
252 - Issue the remote method call to the server.
253
254 - Format and output a representation of the returned data.
255
256 - Verify the returned data matches what was expected.
257
258 - Deallocate any created data structures.
259
260 Note the recognized values and expected behaviour of each
261 remote method are described in ThriftTest.thrift, which
262 you'll find in the top-level "test" folder. */
263
264 /**
265 * VOID TEST
266 */
267 printf ("testVoid()");
Roger Meier15df0762014-09-29 20:50:56 +0200268 if (t_test_thrift_test_if_test_void (test_client, &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200269 printf (" = void\n");
270 }
271 else {
272 printf ("%s\n", error->message);
273 g_error_free (error);
274 error = NULL;
275
276 fail_count++;
277 }
278
279 /**
280 * STRING TEST
281 */
282 printf ("testString(\"Test\")");
283 if (t_test_thrift_test_if_test_string (test_client,
284 &string,
285 "Test",
Roger Meier15df0762014-09-29 20:50:56 +0200286 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200287 printf (" = \"%s\"\n", string);
288 if (strncmp (string, "Test", 5) != 0)
289 fail_count++;
290
291 g_free (string);
292 string = NULL;
293 }
294 else {
295 printf ("%s\n", error->message);
296 g_error_free (error);
297 error = NULL;
298
299 fail_count++;
300 }
301
302 /**
303 * BYTE TEST
304 */
305 printf ("testByte(1)");
306 if (t_test_thrift_test_if_test_byte (test_client,
307 &byte,
308 1,
Roger Meier15df0762014-09-29 20:50:56 +0200309 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200310 printf (" = %d\n", byte);
311 if (byte != 1)
312 fail_count++;
313 }
314 else {
315 printf ("%s\n", error->message);
316 g_error_free (error);
317 error = NULL;
318
319 fail_count++;
320 }
321
322 /**
323 * I32 TEST
324 */
325 printf ("testI32(-1)");
326 if (t_test_thrift_test_if_test_i32 (test_client,
327 &int32,
328 -1,
Roger Meier15df0762014-09-29 20:50:56 +0200329 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200330 printf (" = %d\n", int32);
331 if (int32 != -1)
332 fail_count++;
333 }
334 else {
335 printf ("%s\n", error->message);
336 g_error_free (error);
337 error = NULL;
338
339 fail_count++;
340 }
341
342 /**
343 * I64 TEST
344 */
345 printf ("testI64(-34359738368)");
346 if (t_test_thrift_test_if_test_i64 (test_client,
347 &int64,
348 (gint64)-34359738368,
Roger Meier15df0762014-09-29 20:50:56 +0200349 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200350 printf (" = %" PRId64 "\n", int64);
351 if (int64 != (gint64)-34359738368)
352 fail_count++;
353 }
354 else {
355 printf ("%s\n", error->message);
356 g_error_free (error);
357 error = NULL;
358
359 fail_count++;
360 }
361
362 /**
363 * DOUBLE TEST
364 */
365 printf("testDouble(-5.2098523)");
366 if (t_test_thrift_test_if_test_double (test_client,
367 &dub,
368 -5.2098523,
Roger Meier15df0762014-09-29 20:50:56 +0200369 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200370 printf (" = %f\n", dub);
371 if ((dub - (-5.2098523)) > 0.001)
372 fail_count++;
373 }
374 else {
375 printf ("%s\n", error->message);
376 g_error_free (error);
377 error = NULL;
378
379 fail_count++;
380 }
381
Jens Geyer8bcfdd92014-12-14 03:14:26 +0100382 // TODO: add testBinary()
383
Roger Meierb3c84092014-09-01 21:53:40 +0200384 /**
385 * STRUCT TEST
386 */
387 printf ("testStruct({\"Zero\", 1, -3, -5})");
388 xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT,
389 "string_thing", "Zero",
390 "byte_thing", 1,
391 "i32_thing", -3,
392 "i64_thing", -5LL,
393 NULL);
394 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
395
396 if (t_test_thrift_test_if_test_struct (test_client,
397 &xtruct_in,
398 xtruct_out,
Roger Meier15df0762014-09-29 20:50:56 +0200399 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200400 g_object_get (xtruct_in,
401 "string_thing", &string,
402 "byte_thing", &byte_thing,
403 "i32_thing", &i32_thing,
404 "i64_thing", &i64_thing,
405 NULL);
406
407 printf (" = {\"%s\", %d, %d, %" PRId64 "}\n",
408 string,
409 byte_thing,
410 i32_thing,
411 i64_thing);
412 if ((string == NULL || strncmp (string, "Zero", 5) != 0) ||
413 byte_thing != 1 ||
414 i32_thing != -3 ||
415 i64_thing != (gint64)-5)
416 fail_count++;
417 }
418 else {
419 printf ("%s\n", error->message);
420 g_error_free (error);
421 error = NULL;
422
423 fail_count++;
424 }
425 g_object_unref (xtruct_in);
426
427 /**
428 * NESTED STRUCT TEST
429 */
430 printf ("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
431 xtruct2_out = g_object_new (T_TEST_TYPE_XTRUCT2,
432 "byte_thing", 1,
433 "struct_thing", xtruct_out,
434 "i32_thing", 5,
435 NULL);
436 xtruct2_in = g_object_new (T_TEST_TYPE_XTRUCT2, NULL);
437
438 if (t_test_thrift_test_if_test_nest (test_client,
439 &xtruct2_in,
440 xtruct2_out,
Roger Meier15df0762014-09-29 20:50:56 +0200441 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200442 g_object_get (xtruct2_in,
443 "byte_thing", &byte_thing,
444 "struct_thing", &xtruct_in,
445 "i32_thing", &i32_thing,
446 NULL);
447 g_object_get (xtruct_in,
448 "string_thing", &string,
449 "byte_thing", &inner_byte_thing,
450 "i32_thing", &inner_i32_thing,
451 "i64_thing", &inner_i64_thing,
452 NULL);
453
454 printf (" = {%d, {\"%s\", %d, %d, %" PRId64 "}, %d}\n",
455 byte_thing,
456 string,
457 inner_byte_thing,
458 inner_i32_thing,
459 inner_i64_thing,
460 i32_thing);
461 if (byte_thing != 1 ||
462 (string == NULL || strncmp (string, "Zero", 5) != 0) ||
463 inner_byte_thing != 1 ||
464 inner_i32_thing != -3 ||
465 inner_i64_thing != (gint64)-5 ||
466 i32_thing != 5)
467 fail_count++;
468 }
469 else {
470 printf ("%s\n", error->message);
471 g_error_free (error);
472 error = NULL;
473
474 fail_count++;
475 }
476
477 g_object_unref (xtruct_in);
478 g_object_unref (xtruct2_in);
479 g_object_unref (xtruct2_out);
480 g_object_unref (xtruct_out);
481
482 /**
483 * MAP TEST
484 */
485 map_out = g_hash_table_new_full (g_int_hash,
486 g_int_equal,
487 g_free,
488 g_free);
489 for (i = 0; i < 5; ++i) {
490 i32_key_ptr = g_malloc (sizeof *i32_key_ptr);
491 i32_value_ptr = g_malloc (sizeof *i32_value_ptr);
492
493 *i32_key_ptr = i;
494 *i32_value_ptr = i - 10;
495
496 g_hash_table_insert (map_out, i32_key_ptr, i32_value_ptr);
497 }
498 printf ("testMap({");
499 first = TRUE;
500 g_hash_table_iter_init (&hash_table_iter, map_out);
501 while (g_hash_table_iter_next (&hash_table_iter,
502 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200503 &value)) {
504 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200505 first = FALSE;
506 else
507 printf (", ");
508
509 printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
510 }
511 printf ("})");
512
513 map_in = g_hash_table_new_full (g_int_hash,
514 g_int_equal,
515 g_free,
516 g_free);
517
518 if (t_test_thrift_test_if_test_map (test_client,
519 &map_in,
520 map_out,
Roger Meier15df0762014-09-29 20:50:56 +0200521 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200522 printf (" = {");
523 first = TRUE;
524 g_hash_table_iter_init (&hash_table_iter, map_in);
525 while (g_hash_table_iter_next (&hash_table_iter,
526 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200527 &value)) {
528 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200529 first = FALSE;
530 else
531 printf (", ");
532
533 printf ("%d => %d", *(gint32 *)key, *(gint32 *)value);
534 }
535 printf ("}\n");
536
537 if (g_hash_table_size (map_in) != g_hash_table_size (map_out))
538 fail_count++;
539 else {
540 g_hash_table_iter_init (&hash_table_iter, map_out);
541 while (g_hash_table_iter_next (&hash_table_iter,
542 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200543 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200544 gpointer in_value = g_hash_table_lookup (map_in, key);
545 if (in_value == NULL ||
546 *(gint32 *)in_value != *(gint32 *)value) {
547 fail_count++;
548 break;
549 }
550 }
551 }
552 }
553 else {
554 printf ("%s\n", error->message);
555 g_error_free (error);
556 error = NULL;
557
558 fail_count++;
559 }
560
561 g_hash_table_unref (map_in);
562 g_hash_table_unref (map_out);
563
564 /**
565 * STRING MAP TEST
566 */
567 map_out = g_hash_table_new_full (g_str_hash,
568 g_str_equal,
569 NULL,
570 NULL);
571 g_hash_table_insert (map_out, "a", "2");
572 g_hash_table_insert (map_out, "b", "blah");
573 g_hash_table_insert (map_out, "some", "thing");
574 printf ("testStringMap({");
575 first = TRUE;
576 g_hash_table_iter_init (&hash_table_iter, map_out);
577 while (g_hash_table_iter_next (&hash_table_iter,
578 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200579 &value)) {
580 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200581 first = FALSE;
582 else
583 printf (", ");
584
585 printf ("\"%s\" => \"%s\"", (gchar *)key, (gchar *)value);
586 }
587 printf (")}");
588
589 map_in = g_hash_table_new_full (g_str_hash,
590 g_str_equal,
591 g_free,
592 g_free);
593
594 if (t_test_thrift_test_if_test_string_map (test_client,
595 &map_in,
596 map_out,
Roger Meier15df0762014-09-29 20:50:56 +0200597 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200598 printf (" = {");
599 first = TRUE;
600 g_hash_table_iter_init (&hash_table_iter, map_in);
601 while (g_hash_table_iter_next (&hash_table_iter,
602 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200603 &value)) {
604 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200605 first = FALSE;
606 else
607 printf (", ");
608
609 printf ("\"%s\" => \"%s\"", (gchar *)key, (gchar *)value);
610 }
611 printf ("}\n");
612
613 if (g_hash_table_size (map_in) != g_hash_table_size (map_out))
614 fail_count++;
615 else {
616 g_hash_table_iter_init (&hash_table_iter, map_out);
617 while (g_hash_table_iter_next (&hash_table_iter,
618 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200619 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200620 gpointer in_value = g_hash_table_lookup (map_in, key);
621 if (in_value == NULL ||
622 strcmp ((gchar *)in_value, (gchar *)value) != 0) {
623 fail_count++;
624 break;
625 }
626 }
627 }
628 }
629 else {
630 printf ("%s\n", error->message);
631 g_error_free (error);
632 error = NULL;
633
634 fail_count++;
635 }
636
637 g_hash_table_unref (map_in);
638 g_hash_table_unref (map_out);
639
640 /**
641 * SET TEST
642 */
643 set_out = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
644 for (i = -2; i < 3; ++i) {
645 i32_key_ptr = g_malloc (sizeof *i32_key_ptr);
646 *i32_key_ptr = i;
647
648 g_hash_table_insert (set_out, i32_key_ptr, NULL);
649 }
650 printf ("testSet({");
651 first = TRUE;
652 keys_out = g_hash_table_get_keys (set_out);
653 keys_elem = keys_out;
654 while (keys_elem != NULL) {
Roger Meier15df0762014-09-29 20:50:56 +0200655 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200656 first = FALSE;
657 else
658 printf (", ");
659
660 printf ("%d", *(gint32 *)keys_elem->data);
661
662 keys_elem = keys_elem->next;
663 }
664 printf ("})");
665
666 set_in = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
667
668 if (t_test_thrift_test_if_test_set (test_client,
669 &set_in,
670 set_out,
Roger Meier15df0762014-09-29 20:50:56 +0200671 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200672 printf(" = {");
673 first = TRUE;
674 keys_in = g_hash_table_get_keys (set_in);
675 keys_elem = keys_in;
676 while (keys_elem != NULL) {
Roger Meier15df0762014-09-29 20:50:56 +0200677 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200678 first = FALSE;
679 else
680 printf (", ");
681
682 printf ("%d", *(gint32 *)keys_elem->data);
683
684 keys_elem = keys_elem->next;
685 }
686 printf ("}\n");
687
688 if (g_list_length (keys_in) != g_list_length (keys_out))
689 fail_count++;
690 else {
691 keys_elem = keys_out;
692 while (keys_elem != NULL) {
693 if (g_list_find_custom (keys_in,
694 keys_elem->data,
695 gint32_compare) == NULL) {
696 fail_count++;
697 break;
698 }
699
700 keys_elem = keys_elem->next;
701 }
702 }
703
704 g_list_free (keys_in);
705 }
706 else {
707 printf ("%s\n", error->message);
708 g_error_free (error);
709 error = NULL;
710
711 fail_count++;
712 }
713
714 g_hash_table_unref (set_in);
715 g_list_free (keys_out);
716 g_hash_table_unref (set_out);
717
718 /**
719 * LIST TEST
720 */
721 list_out = g_array_new (FALSE, TRUE, sizeof (gint32));
722 for (i = -2; i < 3; ++i) {
723 g_array_append_val (list_out, i);
724 }
725 printf ("testList({");
726 first = TRUE;
727 for (i = 0; i < (gint32)list_out->len; ++i) {
Roger Meier15df0762014-09-29 20:50:56 +0200728 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200729 first = FALSE;
730 else
731 printf (", ");
732
733 printf ("%d", g_array_index (list_out, gint32, i));
734 }
735 printf ("})");
736
737 list_in = g_array_new (FALSE, TRUE, sizeof (gint32));
738
739 if (t_test_thrift_test_if_test_list (test_client,
740 &list_in,
741 list_out,
Roger Meier15df0762014-09-29 20:50:56 +0200742 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200743 printf (" = {");
744 first = TRUE;
745 for (i = 0; i < (gint32)list_in->len; ++i) {
Roger Meier15df0762014-09-29 20:50:56 +0200746 if (first)
Roger Meierb3c84092014-09-01 21:53:40 +0200747 first = FALSE;
748 else
749 printf (", ");
750
751 printf ("%d", g_array_index (list_in, gint32, i));
752 }
753 printf ("}\n");
754
755 if (list_in->len != list_out->len ||
756 memcmp (list_in->data,
757 list_out->data,
758 list_in->len * sizeof (gint32)) != 0)
759 fail_count++;
760 }
761 else {
762 printf ("%s\n", error->message);
763 g_error_free (error);
764 error = NULL;
765
766 fail_count++;
767 }
768
769 g_array_unref (list_in);
770 g_array_unref (list_out);
771
772 /**
773 * ENUM TEST
774 */
775 printf("testEnum(ONE)");
776 if (t_test_thrift_test_if_test_enum (test_client,
777 &numberz,
778 T_TEST_NUMBERZ_ONE,
Roger Meier15df0762014-09-29 20:50:56 +0200779 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200780 printf(" = %d\n", numberz);
781 if (numberz != T_TEST_NUMBERZ_ONE)
782 fail_count++;
783 }
784 else {
785 printf ("%s\n", error->message);
786 g_error_free (error);
787 error = NULL;
788
789 fail_count++;
790 }
791
792 printf("testEnum(TWO)");
793 if (t_test_thrift_test_if_test_enum (test_client,
794 &numberz,
795 T_TEST_NUMBERZ_TWO,
Roger Meier15df0762014-09-29 20:50:56 +0200796 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200797 printf(" = %d\n", numberz);
798 if (numberz != T_TEST_NUMBERZ_TWO)
799 fail_count++;
800 }
801 else {
802 printf ("%s\n", error->message);
803 g_error_free (error);
804 error = NULL;
805
806 fail_count++;
807 }
808
809 printf("testEnum(THREE)");
810 if (t_test_thrift_test_if_test_enum (test_client,
811 &numberz,
812 T_TEST_NUMBERZ_THREE,
Roger Meier15df0762014-09-29 20:50:56 +0200813 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200814 printf(" = %d\n", numberz);
815 if (numberz != T_TEST_NUMBERZ_THREE)
816 fail_count++;
817 }
818 else {
819 printf ("%s\n", error->message);
820 g_error_free (error);
821 error = NULL;
822
823 fail_count++;
824 }
825
826 printf("testEnum(FIVE)");
827 if (t_test_thrift_test_if_test_enum (test_client,
828 &numberz,
829 T_TEST_NUMBERZ_FIVE,
Roger Meier15df0762014-09-29 20:50:56 +0200830 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200831 printf(" = %d\n", numberz);
832 if (numberz != T_TEST_NUMBERZ_FIVE)
833 fail_count++;
834 }
835 else {
836 printf ("%s\n", error->message);
837 g_error_free (error);
838 error = NULL;
839
840 fail_count++;
841 }
842
843 printf("testEnum(EIGHT)");
844 if (t_test_thrift_test_if_test_enum (test_client,
845 &numberz,
846 T_TEST_NUMBERZ_EIGHT,
Roger Meier15df0762014-09-29 20:50:56 +0200847 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200848 printf(" = %d\n", numberz);
849 if (numberz != T_TEST_NUMBERZ_EIGHT)
850 fail_count++;
851 }
852 else {
853 printf ("%s\n", error->message);
854 g_error_free (error);
855 error = NULL;
856
857 fail_count++;
858 }
859
860 /**
861 * TYPEDEF TEST
862 */
863 printf ("testTypedef(309858235082523)");
864 if (t_test_thrift_test_if_test_typedef (test_client,
865 &user_id,
866 309858235082523LL,
Roger Meier15df0762014-09-29 20:50:56 +0200867 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200868 printf(" = %" PRId64 "\n", user_id);
869 if (user_id != 309858235082523LL)
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 /**
881 * NESTED MAP TEST
882 */
883 printf ("testMapMap(1)");
884 map_in = g_hash_table_new_full (g_int_hash,
885 g_int_equal,
886 g_free,
887 (GDestroyNotify)g_hash_table_unref);
888 if (t_test_thrift_test_if_test_map_map (test_client,
889 &map_in,
890 1,
Roger Meier15df0762014-09-29 20:50:56 +0200891 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200892 g_hash_table_iter_init (&hash_table_iter, map_in);
893
894 printf (" = {");
895 while (g_hash_table_iter_next (&hash_table_iter,
896 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200897 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200898 printf ("%d => {", *(gint32 *)key);
899
900 g_hash_table_iter_init (&inner_hash_table_iter,
901 (GHashTable *)value);
902 while (g_hash_table_iter_next (&inner_hash_table_iter,
903 &key,
Roger Meier15df0762014-09-29 20:50:56 +0200904 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +0200905 printf ("%d => %d, ", *(gint32 *)key, *(gint32 *)value);
906 }
907
908 printf ("}, ");
909 }
910 printf ("}\n");
911
912 if (g_hash_table_size (map_in) != 2)
913 fail_count++;
914 else {
915 gint32 inner_keys[] = {1, 2, 3, 4};
916 gint32 i32_key;
917
918 i32_key = -4;
919 inner_map_in = g_hash_table_lookup (map_in, &i32_key);
920 if (inner_map_in == NULL ||
921 g_hash_table_size (inner_map_in) != 4)
922 fail_count++;
923 else {
924 keys_in = g_hash_table_get_keys (inner_map_in);
925 keys_in = g_list_sort (keys_in, gint32_compare);
926
927 for (i = 0; i < 4; i++) {
928 keys_elem = g_list_nth (keys_in, 3 - i);
929
930 if (*(gint32 *)keys_elem->data != (-1 * inner_keys[i]) ||
931 *(gint32 *)g_hash_table_lookup (inner_map_in,
932 keys_elem->data) !=
933 (-1 * inner_keys[i])) {
934 fail_count++;
935 break;
936 }
937 }
938
939 g_list_free (keys_in);
940 }
941
942 i32_key = 4;
943 inner_map_in = g_hash_table_lookup (map_in, &i32_key);
944 if (inner_map_in == NULL ||
945 g_hash_table_size (inner_map_in) != 4)
946 fail_count++;
947 else {
948 keys_in = g_hash_table_get_keys (inner_map_in);
949 keys_in = g_list_sort (keys_in, gint32_compare);
950
951 for (i = 0; i < 4; i++) {
952 keys_elem = g_list_nth (keys_in, i);
953
954 if (*(gint32 *)keys_elem->data != inner_keys[i] ||
955 *(gint32 *)g_hash_table_lookup (inner_map_in,
956 keys_elem->data) !=
957 inner_keys[i]) {
958 fail_count++;
959 break;
960 }
961 }
962
963 g_list_free (keys_in);
964 }
965 }
966 }
967 else {
968 printf ("%s\n", error->message);
969 g_error_free (error);
970 error = NULL;
971
972 fail_count++;
973 }
974
975 g_hash_table_unref (map_in);
976
977 /**
978 * INSANITY TEST
979 */
980 insanity_out = g_object_new (T_TEST_TYPE_INSANITY, NULL);
981 g_object_get (insanity_out,
982 "userMap", &user_map,
983 "xtructs", &xtructs,
984 NULL);
985
986 numberz = T_TEST_NUMBERZ_FIVE;
987 user_id_ptr = g_malloc (sizeof *user_id_ptr);
988 *user_id_ptr = 5000;
989 g_hash_table_insert (user_map, (gpointer)numberz, user_id_ptr);
990 g_hash_table_unref (user_map);
991
992 xtruct_out = g_object_new (T_TEST_TYPE_XTRUCT,
993 "string_thing", "Truck",
994 "byte_thing", 8,
995 "i32_thing", 8,
Roger Meier15df0762014-09-29 20:50:56 +0200996 "i64_thing", 8LL,
Roger Meierb3c84092014-09-01 21:53:40 +0200997 NULL);
998 g_ptr_array_add (xtructs, xtruct_out);
999 g_ptr_array_unref (xtructs);
1000
1001 map_in = g_hash_table_new_full (g_int64_hash,
1002 g_int64_equal,
1003 g_free,
1004 (GDestroyNotify)g_hash_table_unref);
1005
1006 printf("testInsanity()");
1007 if (t_test_thrift_test_if_test_insanity (test_client,
1008 &map_in,
1009 insanity_out,
Roger Meier15df0762014-09-29 20:50:56 +02001010 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001011 printf (" = {");
1012 g_hash_table_iter_init (&hash_table_iter, map_in);
1013 while (g_hash_table_iter_next (&hash_table_iter,
1014 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001015 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001016 printf ("%" PRId64 " => {", *(TTestUserId *)key);
1017
1018 g_hash_table_iter_init (&inner_hash_table_iter,
1019 (GHashTable *)value);
1020 while (g_hash_table_iter_next (&inner_hash_table_iter,
1021 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001022 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001023 printf ("%d => {", (TTestNumberz)key);
1024
1025 g_object_get ((TTestInsanity *)value,
1026 "userMap", &user_map,
1027 "xtructs", &xtructs,
1028 NULL);
1029
1030 printf ("{");
1031 g_hash_table_iter_init (&user_map_iter, user_map);
1032 while (g_hash_table_iter_next (&user_map_iter,
1033 &key,
Roger Meier15df0762014-09-29 20:50:56 +02001034 &value)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001035 printf ("%d => %" PRId64 ", ",
1036 (TTestNumberz)key,
1037 *(TTestUserId *)value);
1038 }
1039 printf ("}, ");
1040 g_hash_table_unref (user_map);
1041
1042 printf("{");
1043 for (i = 0; i < (gint32)xtructs->len; ++i) {
1044 xtruct_in = g_ptr_array_index (xtructs, i);
1045 g_object_get (xtruct_in,
1046 "string_thing", &string,
1047 "byte_thing", &byte_thing,
1048 "i32_thing", &i32_thing,
1049 "i64_thing", &i64_thing,
1050 NULL);
1051
1052 printf ("{\"%s\", %d, %d, %" PRId64 "}, ",
1053 string,
1054 byte_thing,
1055 i32_thing,
1056 i64_thing);
1057 }
1058 printf ("}");
1059 g_ptr_array_unref (xtructs);
1060
1061 printf ("}, ");
1062 }
1063 printf("}, ");
1064 }
1065 printf("}\n");
1066
1067 if (g_hash_table_size (map_in) != 2)
1068 fail_count++;
1069 else {
1070 TTestNumberz numberz_key_values[] = {
1071 T_TEST_NUMBERZ_TWO, T_TEST_NUMBERZ_THREE
1072 };
1073 gint user_map_values[] = { 5, 8 };
1074 TTestUserId user_id_key;
1075
1076 user_id_key = 1;
1077 inner_map_in = g_hash_table_lookup (map_in, &user_id_key);
1078 if (inner_map_in == NULL ||
1079 g_hash_table_size (inner_map_in) != 2)
1080 fail_count++;
1081 else {
1082 TTestNumberz numberz_key;
1083
1084 for (i = 0; i < 2; ++i) {
1085 numberz_key = numberz_key_values[i];
1086 insanity_in =
1087 g_hash_table_lookup (inner_map_in,
1088 (gconstpointer)numberz_key);
1089 if (insanity_in == NULL)
1090 fail_count++;
1091 else {
1092 g_object_get (insanity_in,
1093 "userMap", &user_map,
1094 "xtructs", &xtructs,
1095 NULL);
1096
1097 if (user_map == NULL)
1098 fail_count++;
1099 else {
1100 if (g_hash_table_size (user_map) != 2)
1101 fail_count++;
1102 else {
1103 for (j = 0; j < 2; ++j) {
1104 numberz_key = (TTestNumberz)user_map_values[j];
1105
1106 value =
1107 g_hash_table_lookup (user_map,
1108 (gconstpointer)numberz_key);
1109 if (value == NULL ||
1110 *(TTestUserId *)value != (TTestUserId)user_map_values[j])
1111 fail_count++;
1112 }
1113 }
1114
1115 g_hash_table_unref (user_map);
1116 }
1117
1118 if (xtructs == NULL)
1119 fail_count++;
1120 else {
1121 if (xtructs->len != 2)
1122 fail_count++;
1123 else {
1124 xtruct_in = g_ptr_array_index (xtructs, 0);
1125 g_object_get (xtruct_in,
1126 "string_thing", &string,
1127 "byte_thing", &byte_thing,
1128 "i32_thing", &i32_thing,
1129 "i64_thing", &i64_thing,
1130 NULL);
1131 if ((string == NULL ||
1132 strncmp (string, "Goodbye4", 9) != 0) ||
1133 byte_thing != 4 ||
1134 i32_thing != 4 ||
1135 i64_thing != 4)
1136 fail_count++;
1137
1138 if (string != NULL)
1139 g_free (string);
1140
1141 xtruct_in = g_ptr_array_index (xtructs, 1);
1142 g_object_get (xtruct_in,
1143 "string_thing", &string,
1144 "byte_thing", &byte_thing,
1145 "i32_thing", &i32_thing,
1146 "i64_thing", &i64_thing,
1147 NULL);
1148 if ((string == NULL ||
1149 strncmp (string, "Hello2", 7) != 0) ||
1150 byte_thing != 2 ||
1151 i32_thing != 2 ||
1152 i64_thing != 2)
1153 fail_count++;
1154
1155 if (string != NULL)
1156 g_free (string);
1157 }
1158
1159 g_ptr_array_unref (xtructs);
1160 }
1161 }
1162 }
1163 }
1164
1165 user_id_key = 2;
1166 inner_map_in = g_hash_table_lookup (map_in, &user_id_key);
1167 if (inner_map_in == NULL ||
1168 g_hash_table_size (inner_map_in) != 1)
1169 fail_count++;
1170 else {
1171 insanity_in =
1172 g_hash_table_lookup (inner_map_in,
1173 (gconstpointer)T_TEST_NUMBERZ_SIX);
1174 if (insanity_in == NULL)
1175 fail_count++;
1176 else {
1177 g_object_get (insanity_in,
1178 "userMap", &user_map,
1179 "xtructs", &xtructs,
1180 NULL);
1181
1182 if (user_map == NULL)
1183 fail_count++;
1184 else {
1185 if (g_hash_table_size (user_map) != 0)
1186 fail_count++;
1187
1188 g_hash_table_unref (user_map);
1189 }
1190
1191 if (xtructs == NULL)
1192 fail_count++;
1193 else {
1194 if (xtructs->len != 0)
1195 fail_count++;
1196
1197 g_ptr_array_unref (xtructs);
1198 }
1199 }
1200 }
1201 }
1202 }
1203 else {
1204 printf ("%s\n", error->message);
1205 g_error_free (error);
1206 error = NULL;
1207
1208 fail_count++;
1209 }
1210
1211 g_hash_table_unref (map_in);
1212 g_object_unref (insanity_out);
1213
1214 /* test exception */
1215 printf ("testClient.testException(\"Xception\") =>");
Roger Meier15df0762014-09-29 20:50:56 +02001216 if (!t_test_thrift_test_if_test_exception (test_client,
1217 "Xception",
1218 &xception,
1219 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001220 xception != NULL) {
1221 g_object_get (xception,
1222 "errorCode", &int32,
1223 "message", &string,
1224 NULL);
1225 printf (" {%u, \"%s\"}\n", int32, string);
1226 g_free (string);
1227
1228 g_object_unref (xception);
1229 xception = NULL;
1230
1231 g_error_free (error);
1232 error = NULL;
1233 }
1234 else {
1235 printf (" void\nFAILURE\n");
1236 fail_count++;
1237
1238 if (xception != NULL) {
1239 g_object_unref (xception);
1240 xception = NULL;
1241 }
1242
1243 if (error != NULL) {
1244 g_error_free (error);
1245 error = NULL;
1246 }
1247 }
1248
1249 printf ("testClient.testException(\"TException\") =>");
Roger Meier15df0762014-09-29 20:50:56 +02001250 if (!t_test_thrift_test_if_test_exception (test_client,
1251 "TException",
1252 &xception,
1253 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001254 xception == NULL &&
1255 error != NULL) {
1256 printf (" Caught TException\n");
1257
1258 g_error_free (error);
1259 error = NULL;
1260 }
1261 else {
1262 printf (" void\nFAILURE\n");
1263 fail_count++;
1264
1265 if (xception != NULL) {
1266 g_object_unref (xception);
1267 xception = NULL;
1268 }
1269
1270 if (error != NULL) {
1271 g_error_free (error);
1272 error = NULL;
1273 }
1274 }
1275
1276 printf ("testClient.testException(\"success\") =>");
1277 if (t_test_thrift_test_if_test_exception (test_client,
1278 "success",
1279 &xception,
Roger Meier15df0762014-09-29 20:50:56 +02001280 &error))
Roger Meierb3c84092014-09-01 21:53:40 +02001281 printf (" void\n");
1282 else {
1283 printf (" void\nFAILURE\n");
1284 fail_count++;
1285
1286 if (xception != NULL) {
1287 g_object_unref (xception);
1288 xception = NULL;
1289 }
1290
1291 g_error_free (error);
1292 error = NULL;
1293 }
1294
1295 g_assert (error == NULL);
1296
1297 /* test multi exception */
1298 printf ("testClient.testMultiException(\"Xception\", \"test 1\") =>");
1299 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier15df0762014-09-29 20:50:56 +02001300 if (!t_test_thrift_test_if_test_multi_exception (test_client,
1301 &xtruct_in,
1302 "Xception",
1303 "test 1",
1304 &xception,
1305 &xception2,
1306 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001307 xception != NULL &&
1308 xception2 == NULL) {
1309 g_object_get (xception,
1310 "errorCode", &int32,
1311 "message", &string,
1312 NULL);
1313 printf (" {%u, \"%s\"}\n", int32, string);
1314 g_free (string);
1315
1316 g_object_unref (xception);
1317 xception = NULL;
1318
1319 g_error_free (error);
1320 error = NULL;
1321 }
1322 else {
1323 printf (" result\nFAILURE\n");
1324 fail_count++;
1325
1326 if (xception != NULL) {
1327 g_object_unref (xception);
1328 xception = NULL;
1329 }
1330
1331 if (xception2 != NULL) {
1332 g_object_unref (xception2);
1333 xception = NULL;
1334 }
1335
1336 if (error != NULL) {
1337 g_error_free (error);
1338 error = NULL;
1339 }
1340 }
1341 g_object_unref (xtruct_in);
1342
1343 printf ("testClient.testMultiException(\"Xception2\", \"test 2\") =>");
1344 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
Roger Meier15df0762014-09-29 20:50:56 +02001345 if (!t_test_thrift_test_if_test_multi_exception (test_client,
1346 &xtruct_in,
1347 "Xception2",
1348 "test 2",
1349 &xception,
1350 &xception2,
1351 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001352 xception == NULL &&
1353 xception2 != NULL) {
1354 g_object_get (xception2,
1355 "errorCode", &int32,
1356 "struct_thing", &inner_xtruct_in,
1357 NULL);
1358 g_object_get (inner_xtruct_in,
1359 "string_thing", &string,
1360 NULL);
1361 printf (" {%u, {\"%s\"}}\n", int32, string);
1362 g_free (string);
1363
1364 g_object_unref (inner_xtruct_in);
1365 inner_xtruct_in = NULL;
1366
1367 g_object_unref (xception2);
1368 xception2 = NULL;
1369
1370 g_error_free (error);
1371 error = NULL;
1372 }
1373 else {
1374 printf (" result\nFAILURE\n");
1375 fail_count++;
1376
1377 if (xception != NULL) {
1378 g_object_unref (xception);
1379 xception = NULL;
1380 }
1381
1382 if (xception2 != NULL) {
1383 g_object_unref (xception2);
1384 xception = NULL;
1385 }
1386
1387 if (error != NULL) {
1388 g_error_free (error);
1389 error = NULL;
1390 }
1391 }
1392 g_object_unref (xtruct_in);
1393
1394 printf ("testClient.testMultiException(\"success\", \"test 3\") =>");
1395 xtruct_in = g_object_new (T_TEST_TYPE_XTRUCT, NULL);
1396 if (t_test_thrift_test_if_test_multi_exception (test_client,
1397 &xtruct_in,
1398 "success",
1399 "test 3",
1400 &xception,
1401 &xception2,
Roger Meier15df0762014-09-29 20:50:56 +02001402 &error) &&
Roger Meierb3c84092014-09-01 21:53:40 +02001403 xception == NULL &&
1404 xception2 == NULL) {
1405 g_object_get (xtruct_in,
1406 "string_thing", &string,
1407 NULL);
1408 printf (" {{\"%s\"}}\n", string);
1409 g_free (string);
1410 }
1411 else {
1412 printf (" result\nFAILURE\n");
1413 fail_count++;
1414
1415 if (xception != NULL) {
1416 g_object_unref (xception);
1417 xception = NULL;
1418 }
1419
1420 if (xception2 != NULL) {
1421 g_object_unref (xception2);
1422 xception = NULL;
1423 }
1424
1425 if (error != NULL) {
1426 g_error_free (error);
1427 error = NULL;
1428 }
1429 }
1430 g_object_unref (xtruct_in);
1431
1432 /* test oneway void */
1433 printf ("testClient.testOneway(1) =>");
1434 gettimeofday (&oneway_start, NULL);
1435 oneway_result = t_test_thrift_test_if_test_oneway (test_client,
1436 1,
1437 &error);
1438 gettimeofday (&oneway_end, NULL);
1439 timersub (&oneway_end, &oneway_start, &oneway_elapsed);
1440 oneway_elapsed_usec =
1441 oneway_elapsed.tv_sec * 1000 * 1000 + oneway_elapsed.tv_usec;
1442
Roger Meier15df0762014-09-29 20:50:56 +02001443 if (oneway_result) {
Roger Meierb3c84092014-09-01 21:53:40 +02001444 if (oneway_elapsed_usec > 200 * 1000) {
1445 printf (" FAILURE - took %.2f ms\n",
1446 (double)oneway_elapsed_usec / 1000.0);
1447 fail_count++;
1448 }
1449 else
1450 printf (" success - took %.2f ms\n",
1451 (double)oneway_elapsed_usec / 1000.0);
1452 }
1453 else {
1454 printf ("%s\n", error->message);
1455 g_error_free (error);
1456 error = NULL;
1457
1458 fail_count++;
1459 }
1460
1461 /**
1462 * redo a simple test after the oneway to make sure we aren't "off by
1463 * one" -- if the server treated oneway void like normal void, this next
1464 * test will fail since it will get the void confirmation rather than
1465 * the correct result. In this circumstance, the client will receive the
1466 * error:
1467 *
1468 * application error: Wrong method name
1469 */
1470 /**
1471 * I32 TEST
1472 */
1473 printf ("re-test testI32(-1)");
1474 if (t_test_thrift_test_if_test_i32 (test_client,
1475 &int32,
1476 -1,
Roger Meier15df0762014-09-29 20:50:56 +02001477 &error)) {
Roger Meierb3c84092014-09-01 21:53:40 +02001478 printf (" = %d\n", int32);
1479 if (int32 != -1)
1480 fail_count++;
1481 }
1482 else {
1483 printf ("%s\n", error->message);
1484 g_error_free (error);
1485 error = NULL;
1486
1487 fail_count++;
1488 }
1489
1490 gettimeofday (&time_stop, NULL);
1491 timersub (&time_stop, &time_start, &time_elapsed);
1492 time_elapsed_usec =
1493 time_elapsed.tv_sec * 1000 * 1000 + time_elapsed.tv_usec;
1494
1495 printf("Total time: %" PRIu64 " us\n", time_elapsed_usec);
1496
1497 time_total_usec += time_elapsed_usec;
1498 if (time_elapsed_usec < time_min_usec)
1499 time_min_usec = time_elapsed_usec;
1500 if (time_elapsed_usec > time_max_usec)
1501 time_max_usec = time_elapsed_usec;
1502
1503 thrift_transport_close (transport, &error);
1504 }
1505 else {
1506 printf ("Connect failed: %s\n", error->message);
1507 g_error_free (error);
1508 error = NULL;
1509
1510 return 1;
1511 }
1512 }
1513
1514 /* All done---output statistics */
1515 puts ("\nAll tests done.");
1516
1517 time_avg_usec = time_total_usec / num_tests;
1518
1519 printf ("Min time: %" PRIu64 " us\n", time_min_usec);
1520 printf ("Max time: %" PRIu64 " us\n", time_max_usec);
1521 printf ("Avg time: %" PRIu64 " us\n", time_avg_usec);
1522
1523 g_object_unref (test_client);
1524 g_object_unref (protocol);
1525 g_object_unref (transport);
1526 g_free (host);
1527
1528 return fail_count;
1529}