void thrift_simple_server_serve (ThriftServer *server) { g_return_if_fail (THRIFT_IS_SIMPLE_SERVER (server)); ThriftTransport *t = NULL; ThriftTransport *input_transport = NULL, *output_transport = NULL; ThriftProtocol *input_protocol = NULL, *output_protocol = NULL; ThriftSimpleServer *tss = THRIFT_SIMPLE_SERVER(server); THRIFT_SERVER_TRANSPORT_GET_CLASS (server->server_transport) ->listen (server->server_transport, NULL); tss->running = TRUE; while (tss->running == TRUE) { t = thrift_server_transport_accept (server->server_transport, NULL); input_transport = THRIFT_TRANSPORT_FACTORY_GET_CLASS (server->input_transport_factory) ->get_transport (server->input_transport_factory, t); output_transport = THRIFT_TRANSPORT_FACTORY_GET_CLASS (server->output_transport_factory) ->get_transport (server->output_transport_factory, t); input_protocol = THRIFT_PROTOCOL_FACTORY_GET_CLASS (server->input_protocol_factory) ->get_protocol (server->input_protocol_factory, t); output_protocol = THRIFT_PROTOCOL_FACTORY_GET_CLASS (server->output_protocol_factory) ->get_protocol (server->output_protocol_factory, t); while (THRIFT_PROCESSOR_GET_CLASS (server->processor) ->process (server->processor, input_protocol, output_protocol)) { // TODO: implement transport peek () } // TODO: handle exceptions THRIFT_TRANSPORT_GET_CLASS (input_transport)->close (input_transport, NULL); THRIFT_TRANSPORT_GET_CLASS (output_transport)->close (output_transport, NULL); } // attempt to shutdown THRIFT_SERVER_TRANSPORT_GET_CLASS (server->server_transport) ->close (server->server_transport, NULL); }
static void thrift_socket_server_open (const int port, int times) { ThriftServerTransport *transport = NULL; ThriftTransport *client = NULL; int i; ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL); transport = THRIFT_SERVER_TRANSPORT (tsocket); thrift_server_transport_listen (transport, NULL); for(i=0;i<times;i++){ client = thrift_server_transport_accept (transport, NULL); g_assert (client != NULL); thrift_socket_close (client, NULL); g_object_unref (client); } g_object_unref (tsocket); }
static void thrift_server (const int port) { int bytes = 0; ThriftServerTransport *transport = NULL; ThriftTransport *client = NULL; guchar buf[10]; /* a buffer */ guchar match[10] = TEST_DATA; ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL); transport = THRIFT_SERVER_TRANSPORT (tsocket); thrift_server_transport_listen (transport, NULL); /* wrap the client in a BufferedTransport */ client = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT, "transport", thrift_server_transport_accept (transport, NULL), "r_buf_size", 5, NULL); assert (client != NULL); /* read 10 bytes */ bytes = thrift_buffered_transport_read (client, buf, 10, NULL); assert (bytes == 10); /* make sure we've read 10 bytes */ assert ( memcmp (buf, match, 10) == 0 ); /* make sure what we got matches */ /* read 1 byte */ bytes = thrift_buffered_transport_read (client, buf, 1, NULL); bytes = thrift_buffered_transport_read (client, buf, 6, NULL); bytes = thrift_buffered_transport_read (client, buf, 2, NULL); bytes = thrift_buffered_transport_read (client, buf, 1, NULL); thrift_buffered_transport_read_end (client, NULL); thrift_buffered_transport_close (client, NULL); g_object_unref (client); g_object_unref (tsocket); }
static void thrift_server_complex_types (const int port) { ThriftServerTransport *transport = NULL; ThriftTransport *client = NULL; ThriftBinaryProtocol *tbp = NULL; ThriftProtocol *protocol = NULL; gchar *struct_name = NULL; gchar *field_name = NULL; gchar *message_name = NULL; ThriftType element_type, key_type, value_type, field_type; ThriftMessageType message_type; gint8 value = 0; gint16 field_id = 0; guint32 size = 0; gint32 seqid = 0; gint32 version = 0; ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL); transport = THRIFT_SERVER_TRANSPORT (tsocket); thrift_server_transport_listen (transport, NULL); client = thrift_server_transport_accept (transport, NULL); assert (client != NULL); tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport", client, NULL); protocol = THRIFT_PROTOCOL (tbp); thrift_binary_protocol_read_struct_begin (protocol, &struct_name, NULL); thrift_binary_protocol_read_struct_end (protocol, NULL); thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL); thrift_binary_protocol_read_field_end (protocol, NULL); /* test first read error on a field */ transport_read_error = 1; assert (thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == -1); transport_read_error = 0; /* test 2nd write failure */ thrift_binary_protocol_read_byte (protocol, &value, NULL); /* test 2nd read failure on a field */ transport_read_count = 0; transport_read_error_at = 1; assert (thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == -1); transport_read_error_at = -1; /* test field stop */ thrift_binary_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL); thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL); thrift_binary_protocol_read_map_end (protocol, NULL); /* test read failure on a map */ transport_read_count = 0; transport_read_error_at = 0; assert (thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL) == -1); transport_read_error_at = -1; /* test 2nd read failure on a map */ transport_read_count = 0; transport_read_error_at = 1; assert (thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL) == -1); transport_read_error_at = -1; /* test 3rd read failure on a map */ transport_read_count = 0; transport_read_error_at = 2; assert (thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL) == -1); transport_read_error_at = -1; /* test 2nd write failure */ thrift_binary_protocol_read_byte (protocol, &value, NULL); /* test 3rd write failure */ thrift_binary_protocol_read_byte (protocol, &value, NULL); thrift_binary_protocol_read_byte (protocol, &value, NULL); /* test negative map size */ assert (thrift_binary_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL) == -1); /* test list operations */ thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL); thrift_binary_protocol_read_list_end (protocol, NULL); /* test read failure */ transport_read_error = 1; assert (thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL) == -1); transport_read_error = 0; /* test 2nd read failure */ transport_read_count = 0; transport_read_error_at = 1; thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL); transport_read_error_at = -1; /* test negative list size failure */ thrift_binary_protocol_read_list_begin (protocol, &element_type, &size, NULL); /* test 2nd write failure */ thrift_binary_protocol_read_byte (protocol, &value, NULL); /* test set operations */ thrift_binary_protocol_read_set_begin (protocol, &element_type, &size, NULL); thrift_binary_protocol_read_set_end (protocol, NULL); /* broken read */ transport_read_error = 1; assert (thrift_binary_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); transport_read_error = 0; /* invalid protocol version */ assert (thrift_binary_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); /* sz > 0 */ assert (thrift_binary_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) > 0); /* read a valid message */ assert (thrift_binary_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) > 0); g_free (message_name); /* broken 2nd read on a message */ transport_read_count = 0; transport_read_error_at = 1; assert (thrift_binary_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); transport_read_error_at = -1; /* broken 3rd read on a message */ transport_read_count = 0; transport_read_error_at = 3; /* read_string does two reads */ assert (thrift_binary_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); g_free (message_name); transport_read_error_at = -1; /* read a valid message */ assert (thrift_binary_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) > 0); g_free (message_name); assert (thrift_binary_protocol_read_message_end (protocol, NULL) == 0); /* handle 2nd write failure on a message */ thrift_binary_protocol_read_i32 (protocol, &version, NULL); /* handle 2nd write failure on a message */ thrift_binary_protocol_read_i32 (protocol, &version, NULL); thrift_binary_protocol_read_string (protocol, &message_name, NULL); g_object_unref (client); /* TODO: investigate g_object_unref (tbp); */ g_object_unref (tsocket); }
static void thrift_server_primitives (const int port) { ThriftServerTransport *transport = NULL; ThriftTransport *client = NULL; ThriftBinaryProtocol *tbp = NULL; ThriftProtocol *protocol = NULL; gboolean value_boolean = FALSE; gint8 value_byte = 0; gint16 value_16 = 0; gint32 value_32 = 0; gint64 value_64 = 0; gdouble value_double = 0; gchar *string = NULL; gpointer binary = NULL; guint32 len = 0; void *comparator = (void *) TEST_STRING; ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL); transport = THRIFT_SERVER_TRANSPORT (tsocket); thrift_server_transport_listen (transport, NULL); client = thrift_server_transport_accept (transport, NULL); assert (client != NULL); tbp = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport", client, NULL); protocol = THRIFT_PROTOCOL (tbp); assert (thrift_binary_protocol_read_bool (protocol, &value_boolean, NULL) > 0); assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) > 0); assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) > 0); assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) > 0); assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) > 0); assert (thrift_binary_protocol_read_double (protocol, &value_double, NULL) > 0); assert (thrift_binary_protocol_read_string (protocol, &string, NULL) > 0); assert (thrift_binary_protocol_read_binary (protocol, &binary, &len, NULL) > 0); assert (value_boolean == TEST_BOOL); assert (value_byte = TEST_BYTE); assert (value_16 = TEST_I16); assert (value_32 = TEST_I32); assert (value_64 = TEST_I64); assert (value_double = TEST_DOUBLE); assert (strcmp (TEST_STRING, string) == 0); assert (memcmp (comparator, binary, len) == 0); g_free (string); g_free (binary); thrift_binary_protocol_read_binary (protocol, &binary, &len, NULL); g_free (binary); transport_read_count = 0; transport_read_error_at = 0; assert (thrift_binary_protocol_read_binary (protocol, &binary, &len, NULL) == -1); transport_read_error_at = -1; transport_read_count = 0; transport_read_error_at = 1; assert (thrift_binary_protocol_read_binary (protocol, &binary, &len, NULL) == -1); transport_read_error_at = -1; transport_read_error = 1; assert (thrift_binary_protocol_read_bool (protocol, &value_boolean, NULL) == -1); assert (thrift_binary_protocol_read_byte (protocol, &value_byte, NULL) == -1); assert (thrift_binary_protocol_read_i16 (protocol, &value_16, NULL) == -1); assert (thrift_binary_protocol_read_i32 (protocol, &value_32, NULL) == -1); assert (thrift_binary_protocol_read_i64 (protocol, &value_64, NULL) == -1); assert (thrift_binary_protocol_read_double (protocol, &value_double, NULL) == -1); transport_read_error = 0; /* test partial write failure */ thrift_protocol_read_i32 (protocol, &value_32, NULL); thrift_transport_read_end (client, NULL); thrift_transport_close (client, NULL); g_object_unref (tbp); g_object_unref (client); g_object_unref (tsocket); }
/* test reading from the transport after the peer has unexpectedly closed the connection */ static void test_read_after_peer_close(void) { int status; pid_t pid; int port = 51199; GError *err = NULL; pid = fork (); g_assert (pid >= 0); if (pid == 0) { ThriftServerTransport *server_transport = NULL; ThriftTransport *client_transport = NULL; /* child listens */ server_transport = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL); g_assert (server_transport != NULL); thrift_server_transport_listen (server_transport, &err); g_assert (err == NULL); /* wrap the client transport in a ThriftFramedTransport */ client_transport = g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT, "transport", thrift_server_transport_accept (server_transport, &err), "r_buf_size", 0, NULL); g_assert (err == NULL); g_assert (client_transport != NULL); /* close the connection immediately after the client connects */ thrift_transport_close (client_transport, NULL); g_object_unref (client_transport); g_object_unref (server_transport); exit (0); } else { ThriftSocket *tsocket = NULL; ThriftTransport *transport = NULL; guchar buf[10]; /* a buffer */ /* parent connects, wait a bit for the socket to be created */ sleep (1); tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost", "port", port, NULL); transport = g_object_new (THRIFT_TYPE_FRAMED_TRANSPORT, "transport", THRIFT_TRANSPORT (tsocket), "w_buf_size", 0, NULL); g_assert (thrift_transport_open (transport, NULL) == TRUE); g_assert (thrift_transport_is_open (transport)); /* attempting to read from the transport after the peer has closed the connection fails gracefully without generating a critical warning or segmentation fault */ thrift_transport_read (transport, buf, 10, &err); g_assert (err != NULL); g_error_free (err); err = NULL; thrift_transport_read_end (transport, &err); g_assert (err == NULL); thrift_transport_close (transport, &err); g_assert (err == NULL); g_object_unref (transport); g_object_unref (tsocket); g_assert (wait (&status) == pid); g_assert (status == 0); } }
static void test_write_fail(void) { int status; pid_t pid; ThriftSocket *tsocket = NULL; ThriftTransport *transport = NULL; int port = 51198; guchar buf[10] = TEST_DATA; /* a buffer */ /* SIGPIPE when send to disconnected socket */ signal(SIGPIPE, SIG_IGN); pid = fork (); assert ( pid >= 0 ); if ( pid == 0 ) { /* child listens */ ThriftServerTransport *transport = NULL; ThriftTransport *client = NULL; ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL); transport = THRIFT_SERVER_TRANSPORT (tsocket); thrift_server_transport_listen (transport, NULL); /* wrap the client in a BufferedTransport */ client = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT, "transport", thrift_server_transport_accept (transport, NULL), "r_buf_size", 5, NULL); assert (client != NULL); /* just close socket */ thrift_buffered_transport_close (client, NULL); g_object_unref (client); g_object_unref (tsocket); exit (0); } else { /* parent connects, wait a bit for the socket to be created */ sleep (1); tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost", "port", port, NULL); transport = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT, "transport", THRIFT_TRANSPORT (tsocket), "w_buf_size", 4, NULL); assert (thrift_buffered_transport_open (transport, NULL) == TRUE); assert (thrift_buffered_transport_is_open (transport)); /* recognize disconnection */ sleep(1); assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == TRUE); assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == FALSE); /* write and overflow buffer */ assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == FALSE); /* write 1 and flush */ assert (thrift_buffered_transport_write (transport, buf, 1, NULL) == TRUE); assert (thrift_buffered_transport_flush (transport, NULL) == FALSE); thrift_buffered_transport_close (transport, NULL); g_object_unref (transport); g_object_unref (tsocket); assert ( wait (&status) == pid ); assert ( status == 0 ); } }
static void thrift_server_complex_types (const int port) { ThriftServerTransport *transport = NULL; ThriftTransport *client = NULL; ThriftCompactProtocol *tc = NULL; ThriftProtocol *protocol = NULL; gchar *struct_name = NULL; gchar *field_name = NULL; gchar *message_name = NULL; ThriftType element_type, key_type, value_type, field_type; ThriftMessageType message_type; gboolean value_boolean = ! TEST_BOOL; gint8 value = 0; gint16 field_id = 0; guint32 size = 0; gint32 seqid = 0; gint8 version_and_type = 0; gint8 protocol_id = 0; ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, "port", port, NULL); transport = THRIFT_SERVER_TRANSPORT (tsocket); thrift_server_transport_listen (transport, NULL); client = thrift_server_transport_accept (transport, NULL); assert (client != NULL); tc = g_object_new (THRIFT_TYPE_COMPACT_PROTOCOL, "transport", client, NULL); protocol = THRIFT_PROTOCOL (tc); /* test struct operations */ thrift_compact_protocol_read_struct_begin (protocol, &struct_name, NULL); thrift_compact_protocol_read_struct_end (protocol, NULL); /* test field state w.r.t. deltas */ field_id = 0; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 1); field_id = 0; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 16); field_id = 0; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 17); field_id = 0; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); assert (field_id == 15); field_id = 0; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 30); field_id = 0; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); assert (field_id == 46); field_id = 0; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 47); field_id = 0; /* test field operations */ thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL); thrift_compact_protocol_read_field_end (protocol, NULL); /* test field state w.r.t. structs */ assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); assert (field_id == 1); field_id = 0; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 16); field_id = 0; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_struct_begin (protocol, &struct_name, NULL) == 0); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); assert (field_id == 17); field_id = 0; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_struct_begin (protocol, &struct_name, NULL) == 0); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); assert (field_id == 18); field_id = 0; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 19); field_id = 0; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_struct_end (protocol, NULL) == 0); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 18); field_id = 0; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 25); field_id = 0; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_struct_end (protocol, NULL) == 0); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_id == 17); field_id = 0; thrift_compact_protocol_read_field_end (protocol, NULL); /* test field state w.r.t. bools */ /* deltas */ /* non-bool field -> bool field -> non-bool field */ assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_type == T_BOOL); assert (thrift_compact_protocol_read_bool (protocol, &value_boolean, NULL) == 0); assert (value_boolean == TEST_BOOL); value_boolean = ! TEST_BOOL; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); thrift_compact_protocol_read_field_end (protocol, NULL); /* bool -> bool field -> bool */ assert (thrift_compact_protocol_read_bool (protocol, &value_boolean, NULL) > 0); assert (value_boolean == TEST_BOOL); value_boolean = ! TEST_BOOL; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == 1); assert (field_type == T_BOOL); assert (thrift_compact_protocol_read_bool (protocol, &value_boolean, NULL) == 0); assert (value_boolean == TEST_BOOL); value_boolean = ! TEST_BOOL; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_bool (protocol, &value_boolean, NULL) > 0); assert (value_boolean == TEST_BOOL); value_boolean = ! TEST_BOOL; /* no deltas */ /* non-bool field -> bool field -> non-bool field */ assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); assert (field_type == T_BOOL); assert (thrift_compact_protocol_read_bool (protocol, &value_boolean, NULL) == 0); assert (value_boolean == TEST_BOOL); value_boolean = ! TEST_BOOL; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); thrift_compact_protocol_read_field_end (protocol, NULL); /* bool -> bool field -> bool */ assert (thrift_compact_protocol_read_bool (protocol, &value_boolean, NULL) > 0); assert (value_boolean == TEST_BOOL); value_boolean = ! TEST_BOOL; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) > 1); assert (field_type == T_BOOL); assert (thrift_compact_protocol_read_bool (protocol, &value_boolean, NULL) == 0); assert (value_boolean == TEST_BOOL); value_boolean = ! TEST_BOOL; thrift_compact_protocol_read_field_end (protocol, NULL); assert (thrift_compact_protocol_read_bool (protocol, &value_boolean, NULL) > 0); assert (value_boolean == TEST_BOOL); value_boolean = ! TEST_BOOL; /* test first read error on a field */ transport_read_error = 1; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == -1); transport_read_error = 0; /* test 2nd write failure */ thrift_compact_protocol_read_byte (protocol, &value, NULL); /* test 2nd read failure on a field */ transport_read_count = 0; transport_read_error_at = 1; assert (thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL) == -1); transport_read_error_at = -1; /* test field stop */ thrift_compact_protocol_read_field_begin (protocol, &field_name, &field_type, &field_id, NULL); /* test map operations */ thrift_compact_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL); thrift_compact_protocol_read_map_end (protocol, NULL); /* test 1st read failure on a map */ transport_read_count = 0; transport_read_error_at = 0; assert (thrift_compact_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL) == -1); transport_read_error_at = -1; /* test 2nd read failure on a map */ transport_read_count = 0; transport_read_error_at = 1; assert (thrift_compact_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL) == -1); transport_read_error_at = -1; /* test 1st write failure on map---nothing to do on our side */ /* test 2nd write failure */ thrift_compact_protocol_read_byte (protocol, &value, NULL); /* test negative map size */ assert (thrift_compact_protocol_read_map_begin (protocol, &key_type, &value_type, &size, NULL) == -1); /* test list operations */ thrift_compact_protocol_read_list_begin (protocol, &element_type, &size, NULL); thrift_compact_protocol_read_list_end (protocol, NULL); /* test small list 1st read failure */ transport_read_error = 1; assert (thrift_compact_protocol_read_list_begin (protocol, &element_type, &size, NULL) == -1); transport_read_error = 0; /* test big list 1st read failure */ transport_read_error = 1; assert (thrift_compact_protocol_read_list_begin (protocol, &element_type, &size, NULL) == -1); transport_read_error = 0; /* test big list 2nd read failure */ transport_read_count = 0; transport_read_error_at = 1; thrift_compact_protocol_read_list_begin (protocol, &element_type, &size, NULL); transport_read_error_at = -1; /* test negative list size failure */ thrift_compact_protocol_read_list_begin (protocol, &element_type, &size, NULL); /* test small list 1st write failure---nothing to do on our end */ /* test big list 1st write failure---nothing to do on our end */ /* test big list 2nd write failure */ thrift_compact_protocol_read_byte (protocol, &value, NULL); /* test set operations */ thrift_compact_protocol_read_set_begin (protocol, &element_type, &size, NULL); thrift_compact_protocol_read_set_end (protocol, NULL); /* broken read */ transport_read_error = 1; assert (thrift_compact_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); transport_read_error = 0; /* invalid protocol */ assert (thrift_compact_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); /* invalid version */ assert (thrift_compact_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); /* read a valid message */ assert (thrift_compact_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) > 0); g_free (message_name); /* broken 2nd read on a message */ transport_read_count = 0; transport_read_error_at = 1; assert (thrift_compact_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); transport_read_error_at = -1; /* broken 3rd read on a message */ transport_read_count = 0; transport_read_error_at = 2; assert (thrift_compact_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); transport_read_error_at = -1; /* broken 4th read on a message */ transport_read_count = 0; transport_read_error_at = 3; assert (thrift_compact_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) == -1); transport_read_error_at = -1; /* read a valid message */ assert (thrift_compact_protocol_read_message_begin (protocol, &message_name, &message_type, &seqid, NULL) > 0); g_free (message_name); assert (thrift_compact_protocol_read_message_end (protocol, NULL) == 0); /* handle 2nd write failure on a message */ thrift_compact_protocol_read_byte (protocol, &protocol_id, NULL); /* handle 3rd write failure on a message */ thrift_compact_protocol_read_byte (protocol, &protocol_id, NULL); thrift_compact_protocol_read_byte (protocol, &version_and_type, NULL); /* handle 4th write failure on a message */ thrift_compact_protocol_read_byte (protocol, &protocol_id, NULL); thrift_compact_protocol_read_byte (protocol, &version_and_type, NULL); thrift_compact_protocol_read_varint32 (tc, &seqid, NULL); g_object_unref (client); g_object_unref (tsocket); }