blob: 66f7f6c4544cb78c55221d16ffe79df948bcd937 [file] [log] [blame]
David Reissbfc57a02009-03-30 20:46:37 +00001-module(test_membuffer).
2-export([t/0]).
3
4-include("thriftTest_types.hrl").
5
6test_data() ->
7 #xtruct{string_thing = <<"foobar">>,
8 byte_thing = 123,
9 i32_thing = 1234567,
10 i64_thing = 12345678900}.
11
12t1() ->
13 {ok, Transport} = thrift_memory_buffer:new(),
14 {ok, Protocol} = thrift_binary_protocol:new(Transport),
15 TestData = test_data(),
16 ok = thrift_protocol:write(Protocol,
17 {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
18 TestData}),
19 {ok, Result} = thrift_protocol:read(Protocol,
20 {struct, element(2, thriftTest_types:struct_info('xtruct'))},
21 'xtruct'),
22
23 Result = TestData.
24
25
David Reiss233ace52009-03-30 20:46:47 +000026t2() ->
27 {ok, Transport} = thrift_memory_buffer:new(),
28 {ok, Protocol} = thrift_binary_protocol:new(Transport),
29 TestData = test_data(),
30 ok = thrift_protocol:write(Protocol,
31 {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
32 TestData}),
33 {ok, Result} = thrift_protocol:read(Protocol,
34 {struct, element(2, thriftTest_types:struct_info('xtruct3'))},
35 'xtruct3'),
36
37 Result = #xtruct3{string_thing = TestData#xtruct.string_thing,
38 changed = undefined,
39 i32_thing = TestData#xtruct.i32_thing,
40 i64_thing = TestData#xtruct.i64_thing}.
41
42
David Reissb3c5f6e2009-03-30 20:46:52 +000043t3() ->
44 {ok, Transport} = thrift_memory_buffer:new(),
45 {ok, Protocol} = thrift_binary_protocol:new(Transport),
46 TestData = #bools{im_true = true, im_false = false},
47 ok = thrift_protocol:write(Protocol,
48 {{struct, element(2, thriftTest_types:struct_info('bools'))},
49 TestData}),
50 {ok, Result} = thrift_protocol:read(Protocol,
51 {struct, element(2, thriftTest_types:struct_info('bools'))},
52 'bools'),
53
54 true = TestData#bools.im_true =:= Result#bools.im_true,
55 true = TestData#bools.im_false =:= Result#bools.im_false.
56
57
David Reissbfc57a02009-03-30 20:46:37 +000058t() ->
David Reiss233ace52009-03-30 20:46:47 +000059 t1(),
David Reissb3c5f6e2009-03-30 20:46:52 +000060 t2(),
61 t3().
David Reissbfc57a02009-03-30 20:46:37 +000062