blob: c6de3858785af1cc06625116e47b94cd44c71cdf [file] [log] [blame]
Roger Meierc1010922010-11-26 10:17:48 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
Roger Meier213a6642010-10-27 12:30:11 +000020#include <unistd.h>
21#include <stdlib.h>
22#include <stdio.h>
23#include <assert.h>
24#include <netdb.h>
25#include <string.h>
Jens Geyer1c190272015-07-28 23:15:18 +020026#include <sys/wait.h>
Roger Meier213a6642010-10-27 12:30:11 +000027
Roger Meiere3da7682013-01-11 11:41:53 +010028#include <thrift/c_glib/protocol/thrift_protocol.h>
29#include <thrift/c_glib/transport/thrift_socket.h>
30#include <thrift/c_glib/transport/thrift_server_socket.h>
Roger Meier213a6642010-10-27 12:30:11 +000031
32#define TEST_BOOL TRUE
33#define TEST_BYTE 123
34#define TEST_I16 12345
35#define TEST_I32 1234567890
36#define TEST_I64 123456789012345LL
37#define TEST_DOUBLE 1234567890.123
38#define TEST_STRING "this is a test string 1234567890!@#$%^&*()"
39#define TEST_PORT 51199
40
41static int transport_read_count = 0;
42static int transport_read_error = 0;
43static int transport_read_error_at = -1;
44gint32
45my_thrift_transport_read (ThriftTransport *transport, gpointer buf,
46 guint32 len, GError **error)
47{
48 if (transport_read_count != transport_read_error_at
49 && transport_read_error == 0)
50 {
51 transport_read_count++;
52 return thrift_transport_read (transport, buf, len, error);
53 }
54 return -1;
55}
56
57static int transport_write_count = 0;
58static int transport_write_error = 0;
59static int transport_write_error_at = -1;
60gboolean
61my_thrift_transport_write (ThriftTransport *transport, const gpointer buf,
62 const guint32 len, GError **error)
63{
64 if (transport_write_count != transport_write_error_at
65 && transport_write_error == 0)
66 {
67 transport_write_count++;
68 return thrift_transport_write (transport, buf, len, error);
69 }
70 return FALSE;
71}
72
73#define thrift_transport_read my_thrift_transport_read
74#define thrift_transport_write my_thrift_transport_write
Roger Meiere3da7682013-01-11 11:41:53 +010075#include "../src/thrift/c_glib/protocol/thrift_binary_protocol.c"
Roger Meier213a6642010-10-27 12:30:11 +000076#undef thrift_transport_read
77#undef thrift_transport_write
78
79static void thrift_server_primitives (const int port);
80static void thrift_server_complex_types (const int port);
81
82static void
83test_create_and_destroy(void)
84{
85 GObject *object = NULL;
86
87 /* create an object and then destroy it */
88 object = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, NULL);
89 assert (object != NULL);
90 g_object_unref (object);
91}
92
93static void
94test_initialize(void)
95{
96 ThriftSocket *tsocket = NULL;
97 ThriftBinaryProtocol *protocol = NULL;
98 ThriftSocket *temp = NULL;
99
100 /* create a ThriftTransport */
101 tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
102 "port", 51188, NULL);
103 assert (tsocket != NULL);
104 /* create a ThriftBinaryProtocol using the Transport */
105 protocol = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
106 tsocket, NULL);
107 assert (protocol != NULL);
108 /* fetch the properties */
109 g_object_get (G_OBJECT(protocol), "transport", &temp, NULL);
110 g_object_unref (temp);
111
112 /* clean up memory */
113 g_object_unref (protocol);
114 g_object_unref (tsocket);
115}
116
117static void
118test_read_and_write_primitives(void)
119{
120 int status;
121 pid_t pid;
122 ThriftSocket *tsocket = NULL;
123 ThriftTransport *transport = NULL;
124 ThriftBinaryProtocol *tb = NULL;
125 ThriftProtocol *protocol = NULL;
126 gpointer binary = (gpointer *) TEST_STRING;
127 guint32 len = strlen (TEST_STRING);
128 int port = TEST_PORT;
129
130 /* fork a server from the client */
131 pid = fork ();
132 assert (pid >= 0);
133
134 if (pid == 0)
135 {
136 /* child listens */
137 thrift_server_primitives (port);
138 exit (0);
139 } else {
140 /* parent. wait a bit for the socket to be created. */
141 sleep (1);
142
143 /* create a ThriftSocket */
144 tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
145 "port", port, NULL);
146 transport = THRIFT_TRANSPORT (tsocket);
147 thrift_transport_open (transport, NULL);
148 assert (thrift_transport_is_open (transport));
149
150 /* create a ThriftBinaryTransport */
151 tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
152 tsocket, NULL);
153 protocol = THRIFT_PROTOCOL (tb);
154 assert (protocol != NULL);
155
156 /* write a bunch of primitives */
157 assert (thrift_binary_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
158 assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, NULL) > 0);
159 assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) > 0);
160 assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) > 0);
161 assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) > 0);
162 assert (thrift_binary_protocol_write_double (protocol,
163 TEST_DOUBLE, NULL) > 0);
164 assert (thrift_binary_protocol_write_string (protocol,
165 TEST_STRING, NULL) > 0);
166 assert (thrift_binary_protocol_write_binary (protocol, binary,
167 len, NULL) > 0);
168 assert (thrift_binary_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
169 assert (thrift_binary_protocol_write_binary (protocol, binary,
170 len, NULL) > 0);
171
172 /* test write errors */
173 transport_write_error = 1;
174 assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE,
175 NULL) == -1);
176 assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) == -1);
177 assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) == -1);
178 assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) == -1);
179 assert (thrift_binary_protocol_write_double (protocol, TEST_DOUBLE,
180 NULL) == -1);
181 assert (thrift_binary_protocol_write_binary (protocol, binary, len,
182 NULL) == -1);
183 transport_write_error = 0;
184
185 /* test binary partial failure */
186 transport_write_count = 0;
187 transport_write_error_at = 1;
188 assert (thrift_binary_protocol_write_binary (protocol, binary,
189 len, NULL) == -1);
190 transport_write_error_at = -1;
191
192 /* clean up */
193 thrift_transport_close (transport, NULL);
194 g_object_unref (tsocket);
195 g_object_unref (protocol);
196 assert (wait (&status) == pid);
197 assert (status == 0);
198 }
199}
200
201static void
202test_read_and_write_complex_types (void)
203{
204 int status;
205 pid_t pid;
206 ThriftSocket *tsocket = NULL;
207 ThriftTransport *transport = NULL;
208 ThriftBinaryProtocol *tb = NULL;
209 ThriftProtocol *protocol = NULL;
210 int port = TEST_PORT;
211
212 /* fork a server from the client */
213 pid = fork ();
214 assert (pid >= 0);
215
216 if (pid == 0)
217 {
218 /* child listens */
219 thrift_server_complex_types (port);
220 exit (0);
221 } else {
222 /* parent. wait a bit for the socket to be created. */
223 sleep (1);
224
225 /* create a ThriftSocket */
226 tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
227 "port", port, NULL);
228 transport = THRIFT_TRANSPORT (tsocket);
229 thrift_transport_open (transport, NULL);
230 assert (thrift_transport_is_open (transport));
231
232 /* create a ThriftBinaryTransport */
233 tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
234 tsocket, NULL);
235 protocol = THRIFT_PROTOCOL (tb);
236 assert (protocol != NULL);
237
238 /* test structures */
239 assert (thrift_binary_protocol_write_struct_begin (protocol,
240 NULL, NULL) == 0);
241 assert (thrift_binary_protocol_write_struct_end (protocol, NULL) == 0);
242
243 assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
244 1, NULL) > 0);
245 assert (thrift_binary_protocol_write_field_end (protocol, NULL) == 0);
246
247 /* test write error */
248 transport_write_error = 1;
249 assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
250 1, NULL) == -1);
251 transport_write_error = 0;
252
253 /* test 2nd write error */
254 transport_write_count = 0;
255 transport_write_error_at = 1;
256 assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
257 1, NULL) == -1);
258 transport_write_error_at = -1;
259
260 /* test 2nd read failure on a field */
261 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
262
263 /* test write_field_stop */
264 assert (thrift_binary_protocol_write_field_stop (protocol, NULL) > 0);
265
266 /* write a map */
267 assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
268 1, NULL) > 0);
269 assert (thrift_binary_protocol_write_map_end (protocol, NULL) == 0);
270
271 /* test 2nd read failure on a map */
272 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
273
274 /* test 3rd read failure on a map */
275 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
276 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
277
278 /* test 1st write failure on a map */
279 transport_write_error = 1;
280 assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
281 1, NULL) == -1);
282 transport_write_error = 0;
283
284 /* test 2nd write failure on a map */
285 transport_write_count = 0;
286 transport_write_error_at = 1;
287 assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
288 1, NULL) == -1);
289 transport_write_error_at = -1;
290
291 /* test 3rd write failure on a map */
292 transport_write_count = 0;
293 transport_write_error_at = 2;
294 assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
295 1, NULL) == -1);
296 transport_write_error_at = -1;
297
298 /* test negative map size */
299 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
300 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
301 thrift_binary_protocol_write_i32 (protocol, -10, NULL);
302
303 /* test list operations */
304 assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
305 1, NULL) > 0);
306 assert (thrift_binary_protocol_write_list_end (protocol, NULL) == 0);
307
308 /* test 2nd read failure on a list */
309 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
310
311 /* test negative list size */
312 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
313 thrift_binary_protocol_write_i32 (protocol, -10, NULL);
314
315 /* test first write error on a list */
316 transport_write_error = 1;
317 assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
318 1, NULL) == -1);
319 transport_write_error = 0;
320
321 /* test 2nd write error on a list */
322 transport_write_count = 0;
323 transport_write_error_at = 1;
324 assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
325 1, NULL) == -1);
326 transport_write_error_at = -1;
327
328 /* test set operation s*/
329 assert (thrift_binary_protocol_write_set_begin (protocol, T_VOID,
330 1, NULL) > 0);
331 assert (thrift_binary_protocol_write_set_end (protocol, NULL) == 0);
332
333 /* invalid version */
334 assert (thrift_binary_protocol_write_i32 (protocol, -1, NULL) > 0);
335
336 /* sz > 0 for a message */
337 assert (thrift_binary_protocol_write_i32 (protocol, 1, NULL) > 0);
338
339 /* send a valid message */
340 thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
341 thrift_binary_protocol_write_string (protocol, "test", NULL);
342 thrift_binary_protocol_write_i32 (protocol, 1, NULL);
343
344 /* broken 2nd read */
345 thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
346
347 /* send a broken 3rd read */
348 thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
349 thrift_binary_protocol_write_string (protocol, "test", NULL);
350
351 /* send a valid message */
352 assert (thrift_binary_protocol_write_message_begin (protocol, "test",
353 T_CALL, 1, NULL) > 0);
354
355 assert (thrift_binary_protocol_write_message_end (protocol, NULL) == 0);
356
357 /* send broken writes */
358 transport_write_error = 1;
359 assert (thrift_binary_protocol_write_message_begin (protocol, "test",
360 T_CALL, 1, NULL) == -1);
361 transport_write_error = 0;
362
363 transport_write_count = 0;
364 transport_write_error_at = 2;
365 assert (thrift_binary_protocol_write_message_begin (protocol, "test",
366 T_CALL, 1, NULL) == -1);
367 transport_write_error_at = -1;
368
369 transport_write_count = 0;
370 transport_write_error_at = 3;
371 assert (thrift_binary_protocol_write_message_begin (protocol, "test",
372 T_CALL, 1, NULL) == -1);
373 transport_write_error_at = -1;
374
375 /* clean up */
376 thrift_transport_close (transport, NULL);
377 g_object_unref (tsocket);
378 g_object_unref (protocol);
379 assert (wait (&status) == pid);
380 assert (status == 0);
381 }
382}
383
384
385static void
386thrift_server_primitives (const int port)
387{
388 ThriftServerTransport *transport = NULL;
389 ThriftTransport *client = NULL;
390 ThriftBinaryProtocol *tbp = NULL;
391 ThriftProtocol *protocol = NULL;
392 gboolean value_boolean = FALSE;
393 gint8 value_byte = 0;
394 gint16 value_16 = 0;
395 gint32 value_32 = 0;
396 gint64 value_64 = 0;
397 gdouble value_double = 0;
398 gchar *string = NULL;
399 gpointer binary = NULL;
400 guint32 len = 0;
401 void *comparator = (void *) TEST_STRING;
402
403 ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
404 "port", port, NULL);
405 transport = THRIFT_SERVER_TRANSPORT (tsocket);
406 thrift_server_transport_listen (transport, NULL);
407 client = thrift_server_transport_accept (transport, NULL);
408 assert (client != NULL);
409
410 tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
411 client, NULL);
412 protocol = THRIFT_PROTOCOL (tbp);
413
414 assert (thrift_binary_protocol_read_bool (protocol,
415 &value_boolean, NULL) > 0);
416 assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) > 0);
417 assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) > 0);
418 assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) > 0);
419 assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) > 0);
420 assert (thrift_binary_protocol_read_double (protocol,
421 &value_double, NULL) > 0);
422 assert (thrift_binary_protocol_read_string (protocol, &string, NULL) > 0);
423 assert (thrift_binary_protocol_read_binary (protocol, &binary,
424 &len, NULL) > 0);
425
426 assert (value_boolean == TEST_BOOL);
427 assert (value_byte = TEST_BYTE);
428 assert (value_16 = TEST_I16);
429 assert (value_32 = TEST_I32);
430 assert (value_64 = TEST_I64);
431 assert (value_double = TEST_DOUBLE);
432 assert (strcmp (TEST_STRING, string) == 0);
433 assert (memcmp (comparator, binary, len) == 0);
434
435 g_free (string);
436 g_free (binary);
437
438 thrift_binary_protocol_read_binary (protocol, &binary, &len, NULL);
439 g_free (binary);
440
441 transport_read_count = 0;
442 transport_read_error_at = 0;
443 assert (thrift_binary_protocol_read_binary (protocol, &binary,
444 &len, NULL) == -1);
445 transport_read_error_at = -1;
446
447 transport_read_count = 0;
448 transport_read_error_at = 1;
449 assert (thrift_binary_protocol_read_binary (protocol, &binary,
450 &len, NULL) == -1);
451 transport_read_error_at = -1;
452
453 transport_read_error = 1;
454 assert (thrift_binary_protocol_read_bool (protocol,
455 &value_boolean, NULL) == -1);
456 assert (thrift_binary_protocol_read_byte (protocol,
457 &value_byte, NULL) == -1);
458 assert (thrift_binary_protocol_read_i16 (protocol,
459 &value_16, NULL) == -1);
460 assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) == -1);
461 assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) == -1);
462 assert (thrift_binary_protocol_read_double (protocol,
463 &value_double, NULL) == -1);
464 transport_read_error = 0;
465
466 /* test partial write failure */
467 thrift_protocol_read_i32 (protocol, &value_32, NULL);
468
469 thrift_transport_read_end (client, NULL);
470 thrift_transport_close (client, NULL);
471
472 g_object_unref (tbp);
473 g_object_unref (client);
474 g_object_unref (tsocket);
475}
476
477static void
478thrift_server_complex_types (const int port)
479{
480 ThriftServerTransport *transport = NULL;
481 ThriftTransport *client = NULL;
482 ThriftBinaryProtocol *tbp = NULL;
483 ThriftProtocol *protocol = NULL;
484 gchar *struct_name = NULL;
485 gchar *field_name = NULL;
486 gchar *message_name = NULL;
487 ThriftType element_type, key_type, value_type, field_type;
488 ThriftMessageType message_type;
489 gint8 value = 0;
490 gint16 field_id = 0;
491 guint32 size = 0;
492 gint32 seqid = 0;
493 gint32 version = 0;
494
495 ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
496 "port", port, NULL);
497 transport = THRIFT_SERVER_TRANSPORT (tsocket);
498 thrift_server_transport_listen (transport, NULL);
499 client = thrift_server_transport_accept (transport, NULL);
500 assert (client != NULL);
501
502 tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
503 client, NULL);
504 protocol = THRIFT_PROTOCOL (tbp);
505
506 thrift_binary_protocol_read_struct_begin (protocol, &struct_name, NULL);
507 thrift_binary_protocol_read_struct_end (protocol, NULL);
508
509 thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type,
510 &field_id, NULL);
511 thrift_binary_protocol_read_field_end (protocol, NULL);
512
513 /* test first read error on a field */
514 transport_read_error = 1;
515 assert (thrift_binary_protocol_read_field_begin (protocol,
516 &field_name, &field_type,
517 &field_id, NULL) == -1);
518 transport_read_error = 0;
519
520 /* test 2nd write failure */
521 thrift_binary_protocol_read_byte (protocol, &value, NULL);
522
523 /* test 2nd read failure on a field */
524 transport_read_count = 0;
525 transport_read_error_at = 1;
526 assert (thrift_binary_protocol_read_field_begin (protocol,
527 &field_name, &field_type,
528 &field_id, NULL) == -1);
529 transport_read_error_at = -1;
530
531 /* test field stop */
532 thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type,
533 &field_id, NULL);
534
535 thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type,
536 &size, NULL);
537 thrift_binary_protocol_read_map_end (protocol, NULL);
538
539 /* test read failure on a map */
540 transport_read_count = 0;
541 transport_read_error_at = 0;
542 assert (thrift_binary_protocol_read_map_begin (protocol,
543 &key_type, &value_type,
544 &size, NULL) == -1);
545 transport_read_error_at = -1;
546
547 /* test 2nd read failure on a map */
548 transport_read_count = 0;
549 transport_read_error_at = 1;
550 assert (thrift_binary_protocol_read_map_begin (protocol,
551 &key_type, &value_type,
552 &size, NULL) == -1);
553 transport_read_error_at = -1;
554
555 /* test 3rd read failure on a map */
556 transport_read_count = 0;
557 transport_read_error_at = 2;
558 assert (thrift_binary_protocol_read_map_begin (protocol,
559 &key_type, &value_type,
560 &size, NULL) == -1);
561 transport_read_error_at = -1;
562
563 /* test 2nd write failure */
564 thrift_binary_protocol_read_byte (protocol, &value, NULL);
565
566 /* test 3rd write failure */
567 thrift_binary_protocol_read_byte (protocol, &value, NULL);
568 thrift_binary_protocol_read_byte (protocol, &value, NULL);
569
570 /* test negative map size */
571 assert (thrift_binary_protocol_read_map_begin (protocol,
572 &key_type, &value_type,
573 &size, NULL) == -1);
574
575 /* test list operations */
576 thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
577 thrift_binary_protocol_read_list_end (protocol, NULL);
578
579 /* test read failure */
580 transport_read_error = 1;
581 assert (thrift_binary_protocol_read_list_begin (protocol, &element_type,
582 &size, NULL) == -1);
583 transport_read_error = 0;
584
585 /* test 2nd read failure */
586 transport_read_count = 0;
587 transport_read_error_at = 1;
588 thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
589 transport_read_error_at = -1;
590
591 /* test negative list size failure */
592 thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
593
594 /* test 2nd write failure */
595 thrift_binary_protocol_read_byte (protocol, &value, NULL);
596
597 /* test set operations */
598 thrift_binary_protocol_read_set_begin (protocol, &element_type, &size, NULL);
599 thrift_binary_protocol_read_set_end (protocol, NULL);
600
601 /* broken read */
602 transport_read_error = 1;
603 assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
604 &message_type, &seqid,
605 NULL) == -1);
606 transport_read_error = 0;
607
608 /* invalid protocol version */
609 assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
610 &message_type, &seqid,
611 NULL) == -1);
612
613 /* sz > 0 */
614 assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
615 &message_type, &seqid,
616 NULL) > 0);
617
618 /* read a valid message */
619 assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
620 &message_type, &seqid,
621 NULL) > 0);
622 g_free (message_name);
623
624 /* broken 2nd read on a message */
625 transport_read_count = 0;
626 transport_read_error_at = 1;
627 assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
628 &message_type, &seqid,
629 NULL) == -1);
630 transport_read_error_at = -1;
631
632 /* broken 3rd read on a message */
633 transport_read_count = 0;
634 transport_read_error_at = 3; /* read_string does two reads */
635 assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
636 &message_type, &seqid,
637 NULL) == -1);
638 g_free (message_name);
639 transport_read_error_at = -1;
640
641 /* read a valid message */
642 assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
643 &message_type, &seqid,
644 NULL) > 0);
645 g_free (message_name);
646
647 assert (thrift_binary_protocol_read_message_end (protocol, NULL) == 0);
648
649 /* handle 2nd write failure on a message */
650 thrift_binary_protocol_read_i32 (protocol, &version, NULL);
651
652 /* handle 2nd write failure on a message */
653 thrift_binary_protocol_read_i32 (protocol, &version, NULL);
654 thrift_binary_protocol_read_string (protocol, &message_name, NULL);
655
656 g_object_unref (client);
657 // TODO: investigate g_object_unref (tbp);
658 g_object_unref (tsocket);
659}
660
661int
Roger Meierc1010922010-11-26 10:17:48 +0000662main(int argc, char *argv[])
Roger Meier213a6642010-10-27 12:30:11 +0000663{
Jens Geyer1c190272015-07-28 23:15:18 +0200664#if (!GLIB_CHECK_VERSION (2, 36, 0))
Roger Meierc1010922010-11-26 10:17:48 +0000665 g_type_init();
Jens Geyer1c190272015-07-28 23:15:18 +0200666#endif
667
Roger Meierc1010922010-11-26 10:17:48 +0000668 g_test_init (&argc, &argv, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000669
Roger Meierc2cc61a2010-11-30 19:53:29 +0000670 g_test_add_func ("/testbinaryprotocol/CreateAndDestroy", test_create_and_destroy);
671 g_test_add_func ("/testbinaryprotocol/Initialize", test_initialize);
672 g_test_add_func ("/testbinaryprotocol/ReadAndWritePrimitives", test_read_and_write_primitives);
673 g_test_add_func ("/testbinaryprotocol/ReadAndWriteComplexTypes", test_read_and_write_complex_types);
Roger Meierc1010922010-11-26 10:17:48 +0000674
675 return g_test_run ();
Roger Meier213a6642010-10-27 12:30:11 +0000676}