blob: 14f4fb063913d74e9e4f6c2327c868878a5db81f [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
Simon South38e71552015-08-03 10:51:16 +000020/* Disable string-function optimizations when glibc is used, as these produce
21 compiler warnings about string length when a string function is used inside
James E. King, III43f4bf22017-10-28 12:54:02 -040022 a call to g_assert () */
Simon South38e71552015-08-03 10:51:16 +000023#ifdef __GLIBC__
Simon South56cf7792015-12-29 12:02:18 -050024#include <features.h>
Simon South38e71552015-08-03 10:51:16 +000025#define __NO_STRING_INLINES 1
26#endif
27
Roger Meier213a6642010-10-27 12:30:11 +000028#include <unistd.h>
29#include <stdlib.h>
30#include <stdio.h>
Roger Meier213a6642010-10-27 12:30:11 +000031#include <netdb.h>
32#include <string.h>
Jens Geyer1c190272015-07-28 23:15:18 +020033#include <sys/wait.h>
Roger Meier213a6642010-10-27 12:30:11 +000034
Roger Meiere3da7682013-01-11 11:41:53 +010035#include <thrift/c_glib/protocol/thrift_protocol.h>
36#include <thrift/c_glib/transport/thrift_socket.h>
37#include <thrift/c_glib/transport/thrift_server_socket.h>
Chandler May1ccd81b2016-02-11 08:25:25 -050038#include <thrift/c_glib/transport/thrift_framed_transport.h>
Roger Meier213a6642010-10-27 12:30:11 +000039
40#define TEST_BOOL TRUE
41#define TEST_BYTE 123
42#define TEST_I16 12345
43#define TEST_I32 1234567890
Simon Southbf8f7b42015-12-23 20:29:29 -050044#define TEST_I64 G_GINT64_CONSTANT (123456789012345)
Roger Meier213a6642010-10-27 12:30:11 +000045#define TEST_DOUBLE 1234567890.123
46#define TEST_STRING "this is a test string 1234567890!@#$%^&*()"
47#define TEST_PORT 51199
48
49static int transport_read_count = 0;
50static int transport_read_error = 0;
51static int transport_read_error_at = -1;
52gint32
Chandler May1ccd81b2016-02-11 08:25:25 -050053my_thrift_transport_read_all (ThriftTransport *transport, gpointer buf,
54 guint32 len, GError **error)
Roger Meier213a6642010-10-27 12:30:11 +000055{
56 if (transport_read_count != transport_read_error_at
57 && transport_read_error == 0)
58 {
59 transport_read_count++;
Chandler May1ccd81b2016-02-11 08:25:25 -050060 return thrift_transport_read_all (transport, buf, len, error);
Roger Meier213a6642010-10-27 12:30:11 +000061 }
62 return -1;
63}
64
65static int transport_write_count = 0;
66static int transport_write_error = 0;
67static int transport_write_error_at = -1;
68gboolean
69my_thrift_transport_write (ThriftTransport *transport, const gpointer buf,
70 const guint32 len, GError **error)
71{
72 if (transport_write_count != transport_write_error_at
73 && transport_write_error == 0)
74 {
75 transport_write_count++;
76 return thrift_transport_write (transport, buf, len, error);
77 }
78 return FALSE;
79}
80
Chandler May1ccd81b2016-02-11 08:25:25 -050081#define thrift_transport_read_all my_thrift_transport_read_all
Roger Meier213a6642010-10-27 12:30:11 +000082#define thrift_transport_write my_thrift_transport_write
Roger Meiere3da7682013-01-11 11:41:53 +010083#include "../src/thrift/c_glib/protocol/thrift_binary_protocol.c"
Chandler May1ccd81b2016-02-11 08:25:25 -050084#undef thrift_transport_read_all
Roger Meier213a6642010-10-27 12:30:11 +000085#undef thrift_transport_write
86
87static void thrift_server_primitives (const int port);
88static void thrift_server_complex_types (const int port);
Chandler May1ccd81b2016-02-11 08:25:25 -050089static void thrift_server_many_frames (const int port);
Roger Meier213a6642010-10-27 12:30:11 +000090
91static void
92test_create_and_destroy(void)
93{
94 GObject *object = NULL;
95
96 /* create an object and then destroy it */
97 object = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -040098 g_assert (object != NULL);
Roger Meier213a6642010-10-27 12:30:11 +000099 g_object_unref (object);
100}
101
102static void
103test_initialize(void)
104{
105 ThriftSocket *tsocket = NULL;
106 ThriftBinaryProtocol *protocol = NULL;
107 ThriftSocket *temp = NULL;
108
109 /* create a ThriftTransport */
110 tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
111 "port", 51188, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400112 g_assert (tsocket != NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000113 /* create a ThriftBinaryProtocol using the Transport */
114 protocol = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
115 tsocket, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400116 g_assert (protocol != NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000117 /* fetch the properties */
118 g_object_get (G_OBJECT(protocol), "transport", &temp, NULL);
119 g_object_unref (temp);
120
121 /* clean up memory */
122 g_object_unref (protocol);
123 g_object_unref (tsocket);
124}
125
126static void
127test_read_and_write_primitives(void)
128{
129 int status;
130 pid_t pid;
131 ThriftSocket *tsocket = NULL;
132 ThriftTransport *transport = NULL;
133 ThriftBinaryProtocol *tb = NULL;
134 ThriftProtocol *protocol = NULL;
135 gpointer binary = (gpointer *) TEST_STRING;
136 guint32 len = strlen (TEST_STRING);
137 int port = TEST_PORT;
138
139 /* fork a server from the client */
140 pid = fork ();
James E. King, III43f4bf22017-10-28 12:54:02 -0400141 g_assert (pid >= 0);
Roger Meier213a6642010-10-27 12:30:11 +0000142
143 if (pid == 0)
144 {
145 /* child listens */
146 thrift_server_primitives (port);
147 exit (0);
148 } else {
149 /* parent. wait a bit for the socket to be created. */
150 sleep (1);
151
152 /* create a ThriftSocket */
153 tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
154 "port", port, NULL);
155 transport = THRIFT_TRANSPORT (tsocket);
156 thrift_transport_open (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400157 g_assert (thrift_transport_is_open (transport));
Roger Meier213a6642010-10-27 12:30:11 +0000158
159 /* create a ThriftBinaryTransport */
160 tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
161 tsocket, NULL);
162 protocol = THRIFT_PROTOCOL (tb);
James E. King, III43f4bf22017-10-28 12:54:02 -0400163 g_assert (protocol != NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000164
165 /* write a bunch of primitives */
James E. King, III43f4bf22017-10-28 12:54:02 -0400166 g_assert (thrift_binary_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
167 g_assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, NULL) > 0);
168 g_assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) > 0);
169 g_assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) > 0);
170 g_assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) > 0);
171 g_assert (thrift_binary_protocol_write_double (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000172 TEST_DOUBLE, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400173 g_assert (thrift_binary_protocol_write_string (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000174 TEST_STRING, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400175 g_assert (thrift_binary_protocol_write_string (protocol, "", NULL) > 0);
176 g_assert (thrift_binary_protocol_write_binary (protocol, binary,
Roger Meier213a6642010-10-27 12:30:11 +0000177 len, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400178 g_assert (thrift_binary_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
179 g_assert (thrift_binary_protocol_write_binary (protocol, binary,
Roger Meier213a6642010-10-27 12:30:11 +0000180 len, NULL) > 0);
181
182 /* test write errors */
183 transport_write_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400184 g_assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE,
Roger Meier213a6642010-10-27 12:30:11 +0000185 NULL) == -1);
James E. King, III43f4bf22017-10-28 12:54:02 -0400186 g_assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) == -1);
187 g_assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) == -1);
188 g_assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) == -1);
189 g_assert (thrift_binary_protocol_write_double (protocol, TEST_DOUBLE,
Roger Meier213a6642010-10-27 12:30:11 +0000190 NULL) == -1);
James E. King, III43f4bf22017-10-28 12:54:02 -0400191 g_assert (thrift_binary_protocol_write_binary (protocol, binary, len,
Roger Meier213a6642010-10-27 12:30:11 +0000192 NULL) == -1);
193 transport_write_error = 0;
194
195 /* test binary partial failure */
196 transport_write_count = 0;
197 transport_write_error_at = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400198 g_assert (thrift_binary_protocol_write_binary (protocol, binary,
Roger Meier213a6642010-10-27 12:30:11 +0000199 len, NULL) == -1);
200 transport_write_error_at = -1;
201
202 /* clean up */
203 thrift_transport_close (transport, NULL);
204 g_object_unref (tsocket);
205 g_object_unref (protocol);
James E. King, III43f4bf22017-10-28 12:54:02 -0400206 g_assert (wait (&status) == pid);
207 g_assert (status == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000208 }
209}
210
211static void
212test_read_and_write_complex_types (void)
213{
214 int status;
215 pid_t pid;
216 ThriftSocket *tsocket = NULL;
217 ThriftTransport *transport = NULL;
218 ThriftBinaryProtocol *tb = NULL;
219 ThriftProtocol *protocol = NULL;
220 int port = TEST_PORT;
221
222 /* fork a server from the client */
223 pid = fork ();
James E. King, III43f4bf22017-10-28 12:54:02 -0400224 g_assert (pid >= 0);
Roger Meier213a6642010-10-27 12:30:11 +0000225
226 if (pid == 0)
227 {
228 /* child listens */
229 thrift_server_complex_types (port);
230 exit (0);
231 } else {
232 /* parent. wait a bit for the socket to be created. */
233 sleep (1);
234
235 /* create a ThriftSocket */
236 tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
237 "port", port, NULL);
238 transport = THRIFT_TRANSPORT (tsocket);
239 thrift_transport_open (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400240 g_assert (thrift_transport_is_open (transport));
Roger Meier213a6642010-10-27 12:30:11 +0000241
242 /* create a ThriftBinaryTransport */
243 tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
244 tsocket, NULL);
245 protocol = THRIFT_PROTOCOL (tb);
James E. King, III43f4bf22017-10-28 12:54:02 -0400246 g_assert (protocol != NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000247
248 /* test structures */
James E. King, III43f4bf22017-10-28 12:54:02 -0400249 g_assert (thrift_binary_protocol_write_struct_begin (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000250 NULL, NULL) == 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400251 g_assert (thrift_binary_protocol_write_struct_end (protocol, NULL) == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000252
James E. King, III43f4bf22017-10-28 12:54:02 -0400253 g_assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000254 1, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400255 g_assert (thrift_binary_protocol_write_field_end (protocol, NULL) == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000256
257 /* test write error */
258 transport_write_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400259 g_assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000260 1, NULL) == -1);
261 transport_write_error = 0;
262
263 /* test 2nd write error */
264 transport_write_count = 0;
265 transport_write_error_at = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400266 g_assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000267 1, NULL) == -1);
268 transport_write_error_at = -1;
269
270 /* test 2nd read failure on a field */
271 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
272
273 /* test write_field_stop */
James E. King, III43f4bf22017-10-28 12:54:02 -0400274 g_assert (thrift_binary_protocol_write_field_stop (protocol, NULL) > 0);
Roger Meier213a6642010-10-27 12:30:11 +0000275
276 /* write a map */
James E. King, III43f4bf22017-10-28 12:54:02 -0400277 g_assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000278 1, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400279 g_assert (thrift_binary_protocol_write_map_end (protocol, NULL) == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000280
281 /* test 2nd read failure on a map */
282 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
283
284 /* test 3rd read failure on a map */
285 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
286 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
287
288 /* test 1st write failure on a map */
289 transport_write_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400290 g_assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000291 1, NULL) == -1);
292 transport_write_error = 0;
293
294 /* test 2nd write failure on a map */
295 transport_write_count = 0;
296 transport_write_error_at = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400297 g_assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000298 1, NULL) == -1);
299 transport_write_error_at = -1;
300
301 /* test 3rd write failure on a map */
302 transport_write_count = 0;
303 transport_write_error_at = 2;
James E. King, III43f4bf22017-10-28 12:54:02 -0400304 g_assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000305 1, NULL) == -1);
306 transport_write_error_at = -1;
307
308 /* test negative map size */
309 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
310 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
311 thrift_binary_protocol_write_i32 (protocol, -10, NULL);
312
313 /* test list operations */
James E. King, III43f4bf22017-10-28 12:54:02 -0400314 g_assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000315 1, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400316 g_assert (thrift_binary_protocol_write_list_end (protocol, NULL) == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000317
318 /* test 2nd read failure on a list */
319 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
320
321 /* test negative list size */
322 thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
323 thrift_binary_protocol_write_i32 (protocol, -10, NULL);
324
325 /* test first write error on a list */
326 transport_write_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400327 g_assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000328 1, NULL) == -1);
329 transport_write_error = 0;
330
331 /* test 2nd write error on a list */
332 transport_write_count = 0;
333 transport_write_error_at = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400334 g_assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000335 1, NULL) == -1);
336 transport_write_error_at = -1;
337
338 /* test set operation s*/
James E. King, III43f4bf22017-10-28 12:54:02 -0400339 g_assert (thrift_binary_protocol_write_set_begin (protocol, T_VOID,
Roger Meier213a6642010-10-27 12:30:11 +0000340 1, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400341 g_assert (thrift_binary_protocol_write_set_end (protocol, NULL) == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000342
343 /* invalid version */
James E. King, III43f4bf22017-10-28 12:54:02 -0400344 g_assert (thrift_binary_protocol_write_i32 (protocol, -1, NULL) > 0);
Roger Meier213a6642010-10-27 12:30:11 +0000345
346 /* sz > 0 for a message */
James E. King, III43f4bf22017-10-28 12:54:02 -0400347 g_assert (thrift_binary_protocol_write_i32 (protocol, 1, NULL) > 0);
Roger Meier213a6642010-10-27 12:30:11 +0000348
349 /* send a valid message */
350 thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
351 thrift_binary_protocol_write_string (protocol, "test", NULL);
352 thrift_binary_protocol_write_i32 (protocol, 1, NULL);
353
354 /* broken 2nd read */
355 thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
356
357 /* send a broken 3rd read */
358 thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
359 thrift_binary_protocol_write_string (protocol, "test", NULL);
360
361 /* send a valid message */
James E. King, III43f4bf22017-10-28 12:54:02 -0400362 g_assert (thrift_binary_protocol_write_message_begin (protocol, "test",
Roger Meier213a6642010-10-27 12:30:11 +0000363 T_CALL, 1, NULL) > 0);
364
James E. King, III43f4bf22017-10-28 12:54:02 -0400365 g_assert (thrift_binary_protocol_write_message_end (protocol, NULL) == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000366
367 /* send broken writes */
368 transport_write_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400369 g_assert (thrift_binary_protocol_write_message_begin (protocol, "test",
Roger Meier213a6642010-10-27 12:30:11 +0000370 T_CALL, 1, NULL) == -1);
371 transport_write_error = 0;
372
373 transport_write_count = 0;
374 transport_write_error_at = 2;
James E. King, III43f4bf22017-10-28 12:54:02 -0400375 g_assert (thrift_binary_protocol_write_message_begin (protocol, "test",
Roger Meier213a6642010-10-27 12:30:11 +0000376 T_CALL, 1, NULL) == -1);
377 transport_write_error_at = -1;
378
379 transport_write_count = 0;
380 transport_write_error_at = 3;
James E. King, III43f4bf22017-10-28 12:54:02 -0400381 g_assert (thrift_binary_protocol_write_message_begin (protocol, "test",
Roger Meier213a6642010-10-27 12:30:11 +0000382 T_CALL, 1, NULL) == -1);
383 transport_write_error_at = -1;
384
385 /* clean up */
386 thrift_transport_close (transport, NULL);
387 g_object_unref (tsocket);
388 g_object_unref (protocol);
James E. King, III43f4bf22017-10-28 12:54:02 -0400389 g_assert (wait (&status) == pid);
390 g_assert (status == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000391 }
392}
393
Chandler May1ccd81b2016-02-11 08:25:25 -0500394static void
395test_read_and_write_many_frames (void)
396{
397 int status;
398 pid_t pid;
399 ThriftSocket *tsocket = NULL;
400 ThriftTransport *transport = NULL;
401 ThriftFramedTransport *ft = NULL;
402 ThriftBinaryProtocol *tb = NULL;
403 ThriftProtocol *protocol = NULL;
404 gpointer binary = (gpointer *) TEST_STRING;
405 const guint32 len = strlen (TEST_STRING);
406 int port = TEST_PORT;
407
408 /* fork a server from the client */
409 pid = fork ();
James E. King, III43f4bf22017-10-28 12:54:02 -0400410 g_assert (pid >= 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500411
412 if (pid == 0)
413 {
414 /* child listens */
415 thrift_server_many_frames (port);
416 exit (0);
417 } else {
418 /* parent. wait a bit for the socket to be created. */
419 sleep (1);
420
421 /* create a ThriftSocket */
422 tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
423 "port", port, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400424 g_assert (tsocket != NULL);
Chandler May1ccd81b2016-02-11 08:25:25 -0500425 transport = THRIFT_TRANSPORT (tsocket);
426
427 /* wrap in a framed transport */
428 ft = g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT, "transport", transport,
429 "w_buf_size", 1, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400430 g_assert (ft != NULL);
Chandler May1ccd81b2016-02-11 08:25:25 -0500431 transport = THRIFT_TRANSPORT (ft);
432
433 thrift_transport_open (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400434 g_assert (thrift_transport_is_open (transport));
Chandler May1ccd81b2016-02-11 08:25:25 -0500435
436 /* create a binary protocol */
437 tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
438 transport, NULL);
439 protocol = THRIFT_PROTOCOL (tb);
James E. King, III43f4bf22017-10-28 12:54:02 -0400440 g_assert (protocol != NULL);
Chandler May1ccd81b2016-02-11 08:25:25 -0500441
442 /* write a bunch of primitives */
James E. King, III43f4bf22017-10-28 12:54:02 -0400443 g_assert (thrift_binary_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500444 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400445 g_assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, NULL) > 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500446 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400447 g_assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) > 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500448 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400449 g_assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) > 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500450 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400451 g_assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) > 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500452 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400453 g_assert (thrift_binary_protocol_write_double (protocol,
Chandler May1ccd81b2016-02-11 08:25:25 -0500454 TEST_DOUBLE, NULL) > 0);
455 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400456 g_assert (thrift_binary_protocol_write_string (protocol,
Chandler May1ccd81b2016-02-11 08:25:25 -0500457 TEST_STRING, NULL) > 0);
458 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400459 g_assert (thrift_binary_protocol_write_string (protocol, "", NULL) > 0);
Simon South30a8b652016-12-22 06:29:17 -0500460 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400461 g_assert (thrift_binary_protocol_write_binary (protocol, binary,
Chandler May1ccd81b2016-02-11 08:25:25 -0500462 len, NULL) > 0);
463 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400464 g_assert (thrift_binary_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500465 thrift_transport_flush (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400466 g_assert (thrift_binary_protocol_write_binary (protocol, binary,
Chandler May1ccd81b2016-02-11 08:25:25 -0500467 len, NULL) > 0);
468 thrift_transport_flush (transport, NULL);
469
470 /* clean up */
471 thrift_transport_write_end (transport, NULL);
472 thrift_transport_close (transport, NULL);
473 g_object_unref (ft);
474 g_object_unref (tsocket);
475 g_object_unref (tb);
James E. King, III43f4bf22017-10-28 12:54:02 -0400476 g_assert (wait (&status) == pid);
477 g_assert (status == 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500478 }
479}
480
Roger Meier213a6642010-10-27 12:30:11 +0000481
482static void
483thrift_server_primitives (const int port)
484{
485 ThriftServerTransport *transport = NULL;
486 ThriftTransport *client = NULL;
487 ThriftBinaryProtocol *tbp = NULL;
488 ThriftProtocol *protocol = NULL;
489 gboolean value_boolean = FALSE;
490 gint8 value_byte = 0;
491 gint16 value_16 = 0;
492 gint32 value_32 = 0;
493 gint64 value_64 = 0;
494 gdouble value_double = 0;
495 gchar *string = NULL;
Simon South30a8b652016-12-22 06:29:17 -0500496 gchar *empty_string = NULL;
Roger Meier213a6642010-10-27 12:30:11 +0000497 gpointer binary = NULL;
498 guint32 len = 0;
499 void *comparator = (void *) TEST_STRING;
500
501 ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
502 "port", port, NULL);
503 transport = THRIFT_SERVER_TRANSPORT (tsocket);
504 thrift_server_transport_listen (transport, NULL);
505 client = thrift_server_transport_accept (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400506 g_assert (client != NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000507
508 tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
509 client, NULL);
510 protocol = THRIFT_PROTOCOL (tbp);
511
James E. King, III43f4bf22017-10-28 12:54:02 -0400512 g_assert (thrift_binary_protocol_read_bool (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000513 &value_boolean, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400514 g_assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) > 0);
515 g_assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) > 0);
516 g_assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) > 0);
517 g_assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) > 0);
518 g_assert (thrift_binary_protocol_read_double (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000519 &value_double, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400520 g_assert (thrift_binary_protocol_read_string (protocol, &string, NULL) > 0);
521 g_assert (thrift_binary_protocol_read_string (protocol, &empty_string,
Simon South30a8b652016-12-22 06:29:17 -0500522 NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400523 g_assert (thrift_binary_protocol_read_binary (protocol, &binary,
Roger Meier213a6642010-10-27 12:30:11 +0000524 &len, NULL) > 0);
525
James E. King, III43f4bf22017-10-28 12:54:02 -0400526 g_assert (value_boolean == TEST_BOOL);
527 g_assert (value_byte == TEST_BYTE);
528 g_assert (value_16 == TEST_I16);
529 g_assert (value_32 == TEST_I32);
530 g_assert (value_64 == TEST_I64);
531 g_assert (value_double == TEST_DOUBLE);
532 g_assert (strcmp (TEST_STRING, string) == 0);
533 g_assert (strcmp ("", empty_string) == 0);
534 g_assert (memcmp (comparator, binary, len) == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000535
536 g_free (string);
Simon South30a8b652016-12-22 06:29:17 -0500537 g_free (empty_string);
Roger Meier213a6642010-10-27 12:30:11 +0000538 g_free (binary);
539
James E. King, III43f4bf22017-10-28 12:54:02 -0400540 g_assert (thrift_binary_protocol_read_binary (protocol, &binary,
Simon South30a8b652016-12-22 06:29:17 -0500541 &len, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400542 g_assert (binary == NULL);
543 g_assert (len == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000544 g_free (binary);
545
546 transport_read_count = 0;
547 transport_read_error_at = 0;
James E. King, III43f4bf22017-10-28 12:54:02 -0400548 g_assert (thrift_binary_protocol_read_binary (protocol, &binary,
Roger Meier213a6642010-10-27 12:30:11 +0000549 &len, NULL) == -1);
550 transport_read_error_at = -1;
551
552 transport_read_count = 0;
553 transport_read_error_at = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400554 g_assert (thrift_binary_protocol_read_binary (protocol, &binary,
Roger Meier213a6642010-10-27 12:30:11 +0000555 &len, NULL) == -1);
556 transport_read_error_at = -1;
557
558 transport_read_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400559 g_assert (thrift_binary_protocol_read_bool (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000560 &value_boolean, NULL) == -1);
James E. King, III43f4bf22017-10-28 12:54:02 -0400561 g_assert (thrift_binary_protocol_read_byte (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000562 &value_byte, NULL) == -1);
James E. King, III43f4bf22017-10-28 12:54:02 -0400563 g_assert (thrift_binary_protocol_read_i16 (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000564 &value_16, NULL) == -1);
James E. King, III43f4bf22017-10-28 12:54:02 -0400565 g_assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) == -1);
566 g_assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) == -1);
567 g_assert (thrift_binary_protocol_read_double (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000568 &value_double, NULL) == -1);
569 transport_read_error = 0;
570
571 /* test partial write failure */
572 thrift_protocol_read_i32 (protocol, &value_32, NULL);
573
574 thrift_transport_read_end (client, NULL);
575 thrift_transport_close (client, NULL);
576
577 g_object_unref (tbp);
578 g_object_unref (client);
579 g_object_unref (tsocket);
580}
581
582static void
583thrift_server_complex_types (const int port)
584{
585 ThriftServerTransport *transport = NULL;
586 ThriftTransport *client = NULL;
587 ThriftBinaryProtocol *tbp = NULL;
588 ThriftProtocol *protocol = NULL;
589 gchar *struct_name = NULL;
590 gchar *field_name = NULL;
591 gchar *message_name = NULL;
592 ThriftType element_type, key_type, value_type, field_type;
593 ThriftMessageType message_type;
594 gint8 value = 0;
595 gint16 field_id = 0;
596 guint32 size = 0;
597 gint32 seqid = 0;
598 gint32 version = 0;
599
600 ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
601 "port", port, NULL);
602 transport = THRIFT_SERVER_TRANSPORT (tsocket);
603 thrift_server_transport_listen (transport, NULL);
604 client = thrift_server_transport_accept (transport, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400605 g_assert (client != NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000606
607 tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
608 client, NULL);
609 protocol = THRIFT_PROTOCOL (tbp);
610
611 thrift_binary_protocol_read_struct_begin (protocol, &struct_name, NULL);
612 thrift_binary_protocol_read_struct_end (protocol, NULL);
613
614 thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type,
615 &field_id, NULL);
616 thrift_binary_protocol_read_field_end (protocol, NULL);
617
618 /* test first read error on a field */
619 transport_read_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400620 g_assert (thrift_binary_protocol_read_field_begin (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000621 &field_name, &field_type,
622 &field_id, NULL) == -1);
623 transport_read_error = 0;
624
625 /* test 2nd write failure */
626 thrift_binary_protocol_read_byte (protocol, &value, NULL);
627
628 /* test 2nd read failure on a field */
629 transport_read_count = 0;
630 transport_read_error_at = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400631 g_assert (thrift_binary_protocol_read_field_begin (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000632 &field_name, &field_type,
633 &field_id, NULL) == -1);
634 transport_read_error_at = -1;
635
636 /* test field stop */
637 thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type,
638 &field_id, NULL);
639
640 thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type,
641 &size, NULL);
642 thrift_binary_protocol_read_map_end (protocol, NULL);
643
644 /* test read failure on a map */
645 transport_read_count = 0;
646 transport_read_error_at = 0;
James E. King, III43f4bf22017-10-28 12:54:02 -0400647 g_assert (thrift_binary_protocol_read_map_begin (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000648 &key_type, &value_type,
649 &size, NULL) == -1);
650 transport_read_error_at = -1;
651
652 /* test 2nd read failure on a map */
653 transport_read_count = 0;
654 transport_read_error_at = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400655 g_assert (thrift_binary_protocol_read_map_begin (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000656 &key_type, &value_type,
657 &size, NULL) == -1);
658 transport_read_error_at = -1;
659
660 /* test 3rd read failure on a map */
661 transport_read_count = 0;
662 transport_read_error_at = 2;
James E. King, III43f4bf22017-10-28 12:54:02 -0400663 g_assert (thrift_binary_protocol_read_map_begin (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000664 &key_type, &value_type,
665 &size, NULL) == -1);
666 transport_read_error_at = -1;
667
668 /* test 2nd write failure */
669 thrift_binary_protocol_read_byte (protocol, &value, NULL);
670
671 /* test 3rd write failure */
672 thrift_binary_protocol_read_byte (protocol, &value, NULL);
673 thrift_binary_protocol_read_byte (protocol, &value, NULL);
674
675 /* test negative map size */
James E. King, III43f4bf22017-10-28 12:54:02 -0400676 g_assert (thrift_binary_protocol_read_map_begin (protocol,
Roger Meier213a6642010-10-27 12:30:11 +0000677 &key_type, &value_type,
678 &size, NULL) == -1);
679
680 /* test list operations */
681 thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
682 thrift_binary_protocol_read_list_end (protocol, NULL);
683
684 /* test read failure */
685 transport_read_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400686 g_assert (thrift_binary_protocol_read_list_begin (protocol, &element_type,
Roger Meier213a6642010-10-27 12:30:11 +0000687 &size, NULL) == -1);
688 transport_read_error = 0;
689
690 /* test 2nd read failure */
691 transport_read_count = 0;
692 transport_read_error_at = 1;
693 thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
694 transport_read_error_at = -1;
695
696 /* test negative list size failure */
697 thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL);
698
699 /* test 2nd write failure */
700 thrift_binary_protocol_read_byte (protocol, &value, NULL);
701
702 /* test set operations */
703 thrift_binary_protocol_read_set_begin (protocol, &element_type, &size, NULL);
704 thrift_binary_protocol_read_set_end (protocol, NULL);
705
706 /* broken read */
707 transport_read_error = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400708 g_assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
Roger Meier213a6642010-10-27 12:30:11 +0000709 &message_type, &seqid,
710 NULL) == -1);
711 transport_read_error = 0;
712
713 /* invalid protocol version */
James E. King, III43f4bf22017-10-28 12:54:02 -0400714 g_assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
Roger Meier213a6642010-10-27 12:30:11 +0000715 &message_type, &seqid,
716 NULL) == -1);
717
718 /* sz > 0 */
James E. King, III43f4bf22017-10-28 12:54:02 -0400719 g_assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
Roger Meier213a6642010-10-27 12:30:11 +0000720 &message_type, &seqid,
721 NULL) > 0);
722
723 /* read a valid message */
James E. King, III43f4bf22017-10-28 12:54:02 -0400724 g_assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
Roger Meier213a6642010-10-27 12:30:11 +0000725 &message_type, &seqid,
726 NULL) > 0);
727 g_free (message_name);
728
729 /* broken 2nd read on a message */
730 transport_read_count = 0;
731 transport_read_error_at = 1;
James E. King, III43f4bf22017-10-28 12:54:02 -0400732 g_assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
Roger Meier213a6642010-10-27 12:30:11 +0000733 &message_type, &seqid,
734 NULL) == -1);
735 transport_read_error_at = -1;
736
737 /* broken 3rd read on a message */
738 transport_read_count = 0;
739 transport_read_error_at = 3; /* read_string does two reads */
James E. King, III43f4bf22017-10-28 12:54:02 -0400740 g_assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
Roger Meier213a6642010-10-27 12:30:11 +0000741 &message_type, &seqid,
742 NULL) == -1);
743 g_free (message_name);
744 transport_read_error_at = -1;
745
746 /* read a valid message */
James E. King, III43f4bf22017-10-28 12:54:02 -0400747 g_assert (thrift_binary_protocol_read_message_begin (protocol, &message_name,
Roger Meier213a6642010-10-27 12:30:11 +0000748 &message_type, &seqid,
749 NULL) > 0);
750 g_free (message_name);
751
James E. King, III43f4bf22017-10-28 12:54:02 -0400752 g_assert (thrift_binary_protocol_read_message_end (protocol, NULL) == 0);
Roger Meier213a6642010-10-27 12:30:11 +0000753
754 /* handle 2nd write failure on a message */
755 thrift_binary_protocol_read_i32 (protocol, &version, NULL);
756
757 /* handle 2nd write failure on a message */
758 thrift_binary_protocol_read_i32 (protocol, &version, NULL);
759 thrift_binary_protocol_read_string (protocol, &message_name, NULL);
760
761 g_object_unref (client);
Simon South38e71552015-08-03 10:51:16 +0000762 /* TODO: investigate g_object_unref (tbp); */
Roger Meier213a6642010-10-27 12:30:11 +0000763 g_object_unref (tsocket);
764}
765
Chandler May1ccd81b2016-02-11 08:25:25 -0500766static void
767thrift_server_many_frames (const int port)
768{
769 ThriftServerTransport *transport = NULL;
770 ThriftTransport *client = NULL;
771 ThriftBinaryProtocol *tbp = NULL;
772 ThriftProtocol *protocol = NULL;
773 ThriftServerSocket *tsocket = NULL;
774 gboolean value_boolean = FALSE;
775 gint8 value_byte = 0;
776 gint16 value_16 = 0;
777 gint32 value_32 = 0;
778 gint64 value_64 = 0;
779 gdouble value_double = 0;
780 gchar *string = NULL;
Simon South30a8b652016-12-22 06:29:17 -0500781 gchar *empty_string = NULL;
Chandler May1ccd81b2016-02-11 08:25:25 -0500782 gpointer binary = NULL;
783 guint32 len = 0;
784 void *comparator = (void *) TEST_STRING;
785
786 tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL);
787 transport = THRIFT_SERVER_TRANSPORT (tsocket);
788 thrift_server_transport_listen (transport, NULL);
789
790 /* wrap the client in a framed transport */
791 client = g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT, "transport",
792 thrift_server_transport_accept (transport, NULL),
793 "r_buf_size", 1, NULL);
James E. King, III43f4bf22017-10-28 12:54:02 -0400794 g_assert (client != NULL);
Chandler May1ccd81b2016-02-11 08:25:25 -0500795
796 tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
797 client, NULL);
798 protocol = THRIFT_PROTOCOL (tbp);
799
James E. King, III43f4bf22017-10-28 12:54:02 -0400800 g_assert (thrift_binary_protocol_read_bool (protocol,
Chandler May1ccd81b2016-02-11 08:25:25 -0500801 &value_boolean, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400802 g_assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) > 0);
803 g_assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) > 0);
804 g_assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) > 0);
805 g_assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) > 0);
806 g_assert (thrift_binary_protocol_read_double (protocol,
Chandler May1ccd81b2016-02-11 08:25:25 -0500807 &value_double, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400808 g_assert (thrift_binary_protocol_read_string (protocol, &string, NULL) > 0);
809 g_assert (thrift_binary_protocol_read_string (protocol, &empty_string,
Simon South30a8b652016-12-22 06:29:17 -0500810 NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400811 g_assert (thrift_binary_protocol_read_binary (protocol, &binary,
Chandler May1ccd81b2016-02-11 08:25:25 -0500812 &len, NULL) > 0);
813
James E. King, III43f4bf22017-10-28 12:54:02 -0400814 g_assert (value_boolean == TEST_BOOL);
815 g_assert (value_byte == TEST_BYTE);
816 g_assert (value_16 == TEST_I16);
817 g_assert (value_32 == TEST_I32);
818 g_assert (value_64 == TEST_I64);
819 g_assert (value_double == TEST_DOUBLE);
820 g_assert (strcmp (TEST_STRING, string) == 0);
821 g_assert (strcmp ("", empty_string) == 0);
822 g_assert (memcmp (comparator, binary, len) == 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500823
824 g_free (string);
Simon South30a8b652016-12-22 06:29:17 -0500825 g_free (empty_string);
826 g_free (binary);
827
James E. King, III43f4bf22017-10-28 12:54:02 -0400828 g_assert (thrift_binary_protocol_read_binary (protocol, &binary,
Simon South30a8b652016-12-22 06:29:17 -0500829 &len, NULL) > 0);
James E. King, III43f4bf22017-10-28 12:54:02 -0400830 g_assert (binary == NULL);
831 g_assert (len == 0);
Chandler May1ccd81b2016-02-11 08:25:25 -0500832 g_free (binary);
833
834 thrift_transport_read_end (client, NULL);
835 thrift_transport_close (client, NULL);
836
837 g_object_unref (tbp);
838 g_object_unref (client);
839 g_object_unref (tsocket);
840}
841
Roger Meier213a6642010-10-27 12:30:11 +0000842int
Roger Meierc1010922010-11-26 10:17:48 +0000843main(int argc, char *argv[])
Roger Meier213a6642010-10-27 12:30:11 +0000844{
Jens Geyer1c190272015-07-28 23:15:18 +0200845#if (!GLIB_CHECK_VERSION (2, 36, 0))
Roger Meierc1010922010-11-26 10:17:48 +0000846 g_type_init();
Jens Geyer1c190272015-07-28 23:15:18 +0200847#endif
848
Roger Meierc1010922010-11-26 10:17:48 +0000849 g_test_init (&argc, &argv, NULL);
Roger Meier213a6642010-10-27 12:30:11 +0000850
Roger Meierc2cc61a2010-11-30 19:53:29 +0000851 g_test_add_func ("/testbinaryprotocol/CreateAndDestroy", test_create_and_destroy);
852 g_test_add_func ("/testbinaryprotocol/Initialize", test_initialize);
853 g_test_add_func ("/testbinaryprotocol/ReadAndWritePrimitives", test_read_and_write_primitives);
854 g_test_add_func ("/testbinaryprotocol/ReadAndWriteComplexTypes", test_read_and_write_complex_types);
Chandler May1ccd81b2016-02-11 08:25:25 -0500855 g_test_add_func ("/testbinaryprotocol/ReadAndWriteManyFrames",
856 test_read_and_write_many_frames);
Roger Meierc1010922010-11-26 10:17:48 +0000857
858 return g_test_run ();
Roger Meier213a6642010-10-27 12:30:11 +0000859}