示例#1
0
int main(int argc, char **argv) {
#else
int log(){
#endif /* NOMAIN */

    g_type_init();

    ThriftTransport *transport = NULL;
    ThriftSocket *tsocket = NULL;
    ThriftBinaryProtocol *protocol = NULL;
    scribeClient *client = NULL;
    scribeIf *iface = NULL;

    ResultCode result;
    LogEntry *log = NULL;
    GPtrArray * messages = NULL;

    GError *error = NULL;

    tsocket = g_object_new(THRIFT_TYPE_SOCKET, "hostname", "localhost",
        "port", 1463, NULL);
    transport = g_object_new(THRIFT_TYPE_FRAMED_TRANSPORT, "transport",
        THRIFT_TRANSPORT(tsocket), NULL);
    protocol = g_object_new(THRIFT_TYPE_BINARY_PROTOCOL, "transport",
        THRIFT_TRANSPORT(transport), NULL);
    client = g_object_new(TYPE_SCRIBE_CLIENT,
        "input_protocol", THRIFT_PROTOCOL(protocol),
        "output_protocol", THRIFT_PROTOCOL(protocol), NULL);
    iface = SCRIBE_IF(client);

    thrift_transport_open(THRIFT_TRANSPORT(tsocket), NULL);

    messages = g_ptr_array_new();

    log = g_object_new(TYPE_LOG_ENTRY, NULL);
    log->category = "TEST";
    log->message = "This is a test message\n\0";

    g_ptr_array_add(messages, log);
    scribe_client_log(iface, &result, messages, &error);
    return 0;

}
示例#2
0
static void
thrift_protocol_dispose (GObject *gobject)
{
  ThriftProtocol *self = THRIFT_PROTOCOL (gobject);

  g_clear_object(&self->transport);

  /* Always chain up to the parent class; there is no need to check if
   * the parent class implements the dispose() virtual function: it is
   * always guaranteed to do so
   */
  G_OBJECT_CLASS (thrift_protocol_parent_class)->dispose(gobject);
}
示例#3
0
void
thrift_protocol_get_property (GObject *object, guint property_id,
                              GValue *value, GParamSpec *pspec)
{
  ThriftProtocol *protocol = THRIFT_PROTOCOL (object);

  THRIFT_UNUSED_VAR (pspec);

  switch (property_id)
  {
    case PROP_THRIFT_PROTOCOL_TRANSPORT:
      g_value_set_object (value, protocol->transport);
      break;
  }
}
示例#4
0
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);
}
示例#5
0
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);
}
示例#6
0
static void
test_read_and_write_complex_types (void)
{
  int status;
  pid_t pid;
  ThriftSocket *tsocket = NULL;
  ThriftTransport *transport = NULL;
  ThriftBinaryProtocol *tb = NULL;
  ThriftProtocol *protocol = NULL;
  int port = TEST_PORT;

  /* fork a server from the client */
  pid = fork ();
  assert (pid >= 0);

  if (pid == 0)
  {
    /* child listens */
    thrift_server_complex_types (port);
    exit (0);
  } else {
    /* parent.  wait a bit for the socket to be created. */
    sleep (1);

    /* create a ThriftSocket */
    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
                            "port", port, NULL);
    transport = THRIFT_TRANSPORT (tsocket);
    thrift_transport_open (transport, NULL);
    assert (thrift_transport_is_open (transport));

    /* create a ThriftBinaryTransport */
    tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
                       tsocket, NULL);
    protocol = THRIFT_PROTOCOL (tb);
    assert (protocol != NULL);

    /* test structures */
    assert (thrift_binary_protocol_write_struct_begin (protocol, 
                                                       NULL, NULL) == 0);
    assert (thrift_binary_protocol_write_struct_end (protocol, NULL) == 0);

    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
                                                      1, NULL) > 0);
    assert (thrift_binary_protocol_write_field_end (protocol, NULL) == 0);

    /* test write error */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID, 
                                                      1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write error */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_binary_protocol_write_field_begin (protocol, "test", T_VOID,
                                                      1, NULL) == -1);
    transport_write_error_at = -1;

    /* test 2nd read failure on a field */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);

    /* test write_field_stop */
    assert (thrift_binary_protocol_write_field_stop (protocol, NULL) > 0);

    /* write a map */
    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
                                                    1, NULL) > 0);
    assert (thrift_binary_protocol_write_map_end (protocol, NULL) == 0);

    /* test 2nd read failure on a map */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);

    /* test 3rd read failure on a map */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);

    /* test 1st write failure on a map */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
                                                    1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write failure on a map */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
                                                    1, NULL) == -1);
    transport_write_error_at = -1;

    /* test 3rd write failure on a map */
    transport_write_count = 0;
    transport_write_error_at = 2;
    assert (thrift_binary_protocol_write_map_begin (protocol, T_VOID, T_VOID,
                                                    1, NULL) == -1);
    transport_write_error_at = -1;

    /* test negative map size */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
    thrift_binary_protocol_write_i32 (protocol, -10, NULL);

    /* test list operations */
    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
                                                     1, NULL) > 0);
    assert (thrift_binary_protocol_write_list_end (protocol, NULL) == 0);

    /* test 2nd read failure on a list */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);

    /* test negative list size */
    thrift_binary_protocol_write_byte (protocol, T_VOID, NULL);
    thrift_binary_protocol_write_i32 (protocol, -10, NULL);

    /* test first write error on a list */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
                                                     1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write error on a list */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_binary_protocol_write_list_begin (protocol, T_VOID,
                                                     1, NULL) == -1);
    transport_write_error_at = -1;

    /* test set operation s*/
    assert (thrift_binary_protocol_write_set_begin (protocol, T_VOID,
                                                    1, NULL) > 0);
    assert (thrift_binary_protocol_write_set_end (protocol, NULL) == 0);

    /* invalid version */
    assert (thrift_binary_protocol_write_i32 (protocol, -1, NULL) > 0);

    /* sz > 0 for a message */
    assert (thrift_binary_protocol_write_i32 (protocol, 1, NULL) > 0);

    /* send a valid message */
    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
    thrift_binary_protocol_write_string (protocol, "test", NULL);
    thrift_binary_protocol_write_i32 (protocol, 1, NULL);

    /* broken 2nd read */
    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);

    /* send a broken 3rd read */
    thrift_binary_protocol_write_i32 (protocol, 0x80010000, NULL);
    thrift_binary_protocol_write_string (protocol, "test", NULL);

    /* send a valid message */
    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) > 0);

    assert (thrift_binary_protocol_write_message_end (protocol, NULL) == 0);

    /* send broken writes */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error = 0;

    transport_write_count = 0;
    transport_write_error_at = 2;
    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    transport_write_count = 0;
    transport_write_error_at = 3;
    assert (thrift_binary_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    /* clean up */
    thrift_transport_close (transport, NULL);
    g_object_unref (tsocket);
    g_object_unref (protocol);
    assert (wait (&status) == pid);
    assert (status == 0);
  }
}
示例#7
0
static void
test_read_and_write_primitives(void)
{
  int status;
  pid_t pid;
  ThriftSocket *tsocket = NULL;
  ThriftTransport *transport = NULL;
  ThriftBinaryProtocol *tb = NULL;
  ThriftProtocol *protocol = NULL;
  gpointer binary = (gpointer *) TEST_STRING;
  guint32 len = strlen (TEST_STRING);
  int port = TEST_PORT;

  /* fork a server from the client */
  pid = fork ();
  assert (pid >= 0);

  if (pid == 0)
  {
    /* child listens */
    thrift_server_primitives (port);
    exit (0);
  } else {
    /* parent.  wait a bit for the socket to be created. */
    sleep (1);

    /* create a ThriftSocket */
    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
                            "port", port, NULL);
    transport = THRIFT_TRANSPORT (tsocket);
    thrift_transport_open (transport, NULL);
    assert (thrift_transport_is_open (transport));

    /* create a ThriftBinaryTransport */
    tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL, "transport",
                       tsocket, NULL);
    protocol = THRIFT_PROTOCOL (tb);
    assert (protocol != NULL);

    /* write a bunch of primitives */
    assert (thrift_binary_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
    assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, NULL) > 0);
    assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) > 0);
    assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) > 0);
    assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) > 0);
    assert (thrift_binary_protocol_write_double (protocol, 
                                                 TEST_DOUBLE, NULL) > 0);
    assert (thrift_binary_protocol_write_string (protocol,
                                                 TEST_STRING, NULL) > 0);
    assert (thrift_binary_protocol_write_binary (protocol, binary, 
                                                 len, NULL) > 0);
    assert (thrift_binary_protocol_write_binary (protocol, NULL, 0, NULL) > 0);
    assert (thrift_binary_protocol_write_binary (protocol, binary,
                                                 len, NULL) > 0);

    /* test write errors */
    transport_write_error = 1;
    assert (thrift_binary_protocol_write_byte (protocol, TEST_BYTE, 
                                               NULL) == -1);
    assert (thrift_binary_protocol_write_i16 (protocol, TEST_I16, NULL) == -1);
    assert (thrift_binary_protocol_write_i32 (protocol, TEST_I32, NULL) == -1);
    assert (thrift_binary_protocol_write_i64 (protocol, TEST_I64, NULL) == -1);
    assert (thrift_binary_protocol_write_double (protocol, TEST_DOUBLE,
                                                 NULL) == -1);
    assert (thrift_binary_protocol_write_binary (protocol, binary, len,
                                                 NULL) == -1);
    transport_write_error = 0;

    /* test binary partial failure */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_binary_protocol_write_binary (protocol, binary,
                                                 len, NULL) == -1);
    transport_write_error_at = -1;

    /* clean up */
    thrift_transport_close (transport, NULL);
    g_object_unref (tsocket);
    g_object_unref (protocol);
    assert (wait (&status) == pid);
    assert (status == 0);
  }
}
示例#8
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);
}
示例#9
0
static void
test_read_and_write_complex_types (void)
{
  int status;
  pid_t pid;
  ThriftSocket *tsocket = NULL;
  ThriftTransport *transport = NULL;
  ThriftCompactProtocol *tc = NULL;
  ThriftProtocol *protocol = NULL;
  int port = TEST_PORT;

  /* fork a server from the client */
  pid = fork ();
  assert (pid >= 0);

  if (pid == 0)
  {
    /* child listens */
    thrift_server_complex_types (port);
    exit (0);
  } else {
    /* parent.  wait a bit for the socket to be created. */
    sleep (1);

    /* create a ThriftSocket */
    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
                            "port", port, NULL);
    transport = THRIFT_TRANSPORT (tsocket);
    thrift_transport_open (transport, NULL);
    assert (thrift_transport_is_open (transport));

    /* create a ThriftCompactTransport */
    tc = g_object_new (THRIFT_TYPE_COMPACT_PROTOCOL, "transport",
                       tsocket, NULL);
    protocol = THRIFT_PROTOCOL (tc);
    assert (protocol != NULL);

    /* test structures */
    assert (thrift_compact_protocol_write_struct_begin (protocol,
                                                       NULL, NULL) == 0);
    assert (thrift_compact_protocol_write_struct_end (protocol, NULL) == 0);

    /* test field state w.r.t. deltas */

    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE, 1, NULL) == 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       16, NULL) == 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       17, NULL) == 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       15, NULL) > 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       30, NULL) == 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       46, NULL) > 1);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       47, NULL) == 1);

    /* test fields */
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);

    /* test field state w.r.t. structs */

    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       16, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);

    assert (thrift_compact_protocol_write_struct_begin (protocol,
                                                       NULL, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       17, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);

    assert (thrift_compact_protocol_write_struct_begin (protocol,
                                                       NULL, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       18, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       19, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_struct_end (protocol, NULL) == 0);

    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       18, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       25, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_struct_end (protocol, NULL) == 0);

    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       17, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);

    /* test field state w.r.t. bools */

    /* deltas */
    /* non-bool field -> bool field -> non-bool field */
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       18, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test", T_BOOL,
                                                       19, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL,
                                                NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       20, NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    /* bool -> bool field -> bool */
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test", T_BOOL,
                                                       21, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL,
                                                NULL) == 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);

    /* no deltas */
    /* non-bool field -> bool field -> non-bool field */
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test", T_BOOL,
                                                      1, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    /* bool -> bool field -> bool */
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);
    assert (thrift_compact_protocol_write_field_begin (protocol, "test", T_BOOL,
                                                      1, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 1);
    assert (thrift_compact_protocol_write_field_end (protocol, NULL) == 0);
    assert (thrift_compact_protocol_write_bool (protocol, TEST_BOOL, NULL) > 0);

    /* test write error */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write error */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_compact_protocol_write_field_begin (protocol, "test",
                                                       T_DOUBLE,
                                                       1, NULL) == -1);
    transport_write_error_at = -1;

    /* test 2nd read failure on a field */
    thrift_compact_protocol_write_byte (protocol, T_DOUBLE, NULL);

    /* test write_field_stop */
    assert (thrift_compact_protocol_write_field_stop (protocol, NULL) > 0);

    /* write a map */
    assert (thrift_compact_protocol_write_map_begin (protocol, T_DOUBLE,
                                                     T_DOUBLE,
                                                     1, NULL) > 0);
    assert (thrift_compact_protocol_write_map_end (protocol, NULL) == 0);

    /* test 1st read failure on map---nothing to do on our side */

    /* test 2nd read failure on a map */
    thrift_compact_protocol_write_byte (protocol, T_DOUBLE, NULL);

    /* test 1st write failure on a map */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_map_begin (protocol, T_DOUBLE,
                                                     T_DOUBLE,
                                                     1, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write failure on a map */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_compact_protocol_write_map_begin (protocol, T_DOUBLE,
                                                     T_DOUBLE,
                                                     1, NULL) == -1);
    transport_write_error_at = -1;

    /* test negative map size */
    thrift_compact_protocol_write_varint32 (tc, -10, NULL);
    thrift_compact_protocol_write_byte (protocol, T_DOUBLE, NULL);

    /* test list operations */
    assert (thrift_compact_protocol_write_list_begin (protocol, T_DOUBLE,
                                                     15, NULL) > 0);
    assert (thrift_compact_protocol_write_list_end (protocol, NULL) == 0);

    /* test 1st read failure on a small list---nothing to do on our end */

    /* test 1st read failure on a big list---nothing to do on our end */

    /* test 2nd read failure on a big list */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0xf0, NULL);

    /* test negative list size */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0xf0, NULL);
    thrift_compact_protocol_write_varint32 (tc, -10, NULL);

    /* test first write error on a small list */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_list_begin (protocol, T_DOUBLE,
                                                     14, NULL) == -1);
    transport_write_error = 0;

    /* test first write error on a big list */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_list_begin (protocol, T_DOUBLE,
                                                     15, NULL) == -1);
    transport_write_error = 0;

    /* test 2nd write error on a big list */
    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_compact_protocol_write_list_begin (protocol, T_DOUBLE,
                                                     15, NULL) == -1);
    transport_write_error_at = -1;

    /* test set operation s*/
    assert (thrift_compact_protocol_write_set_begin (protocol, T_DOUBLE,
                                                    1, NULL) > 0);
    assert (thrift_compact_protocol_write_set_end (protocol, NULL) == 0);

    /* invalid protocol */
    assert (thrift_compact_protocol_write_byte (protocol, 0, NULL) > 0);

    /* invalid version */
    assert (thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u,
                                                NULL) > 0);
    assert (thrift_compact_protocol_write_byte (protocol, 0, NULL) > 0);

    /* send a valid message */
    assert (thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u,
                                                NULL) > 0);
    assert (thrift_compact_protocol_write_byte (protocol, 0x01u, NULL) > 0);
    thrift_compact_protocol_write_varint32 (tc, 1, NULL);
    thrift_compact_protocol_write_string (protocol, "test", NULL);

    /* broken 2nd read */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u, NULL);

    /* send a broken 3rd read */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u, NULL);
    thrift_compact_protocol_write_byte (protocol, 0x01u, NULL);

    /* send a broken 4th read */
    thrift_compact_protocol_write_byte (protocol, (gint8) 0x82u, NULL);
    thrift_compact_protocol_write_byte (protocol, 0x01u, NULL);
    thrift_compact_protocol_write_varint32 (tc, 1, NULL);

    /* send a valid message */
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) > 0);

    assert (thrift_compact_protocol_write_message_end (protocol, NULL) == 0);

    /* send broken writes */
    transport_write_error = 1;
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error = 0;

    transport_write_count = 0;
    transport_write_error_at = 1;
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    transport_write_count = 0;
    transport_write_error_at = 2;
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    transport_write_count = 0;
    transport_write_error_at = 3;
    assert (thrift_compact_protocol_write_message_begin (protocol, "test",
                                                        T_CALL, 1, NULL) == -1);
    transport_write_error_at = -1;

    /* clean up */
    thrift_transport_close (transport, NULL);
    g_object_unref (tsocket);
    g_object_unref (protocol);
    assert (wait (&status) == pid);
    assert (status == 0);
  }
}