blob: 0ece2ad782e70bf236550c21d9634e8e8b02e6c7 [file] [log] [blame]
Nobuaki Sukegawa362a5ed2015-12-01 22:17:24 +09001#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
2#include <thrift/c_glib/protocol/thrift_protocol.h>
3#include <thrift/c_glib/transport/thrift_memory_buffer.h>
4#include <thrift/c_glib/transport/thrift_transport.h>
5#include "gen-c_glib/t_test_debug_proto_test_types.h"
6
7static void struct_read_write_length_should_equal() {
8 GError* error = NULL;
9 ThriftTransport* transport
10 = THRIFT_TRANSPORT(g_object_new(THRIFT_TYPE_MEMORY_BUFFER, "buf_size", 2048, NULL));
11 ThriftProtocol* protocol
12 = THRIFT_PROTOCOL(g_object_new(THRIFT_TYPE_BINARY_PROTOCOL, "transport", transport, NULL));
13 TTestBonk* src = g_object_new(T_TEST_TYPE_BONK, NULL);
14 TTestBonk* dst = g_object_new(T_TEST_TYPE_BONK, NULL);
15 TTestBonkClass* cls = T_TEST_BONK_GET_CLASS(src);
16
17 int write_len = THRIFT_STRUCT_CLASS(cls)->write(THRIFT_STRUCT(src), protocol, &error);
18 g_assert(!error);
19 g_assert(write_len > 0);
20
21 int read_len = THRIFT_STRUCT_CLASS(cls)->read(THRIFT_STRUCT(dst), protocol, &error);
22 g_assert(!error);
23 g_assert_cmpint(write_len, ==, read_len);
24
25 g_object_unref(dst);
26 g_object_unref(src);
27 g_object_unref(protocol);
28 g_object_unref(transport);
29}
30
31int main(int argc, char* argv[]) {
32#if (!GLIB_CHECK_VERSION(2, 36, 0))
33 g_type_init();
34#endif
35 g_test_init(&argc, &argv, NULL);
36
37 g_test_add_func("/testserialization/StructReadWriteLengthShouldEqual",
38 struct_read_write_length_should_equal);
39 return g_test_run();
40}