David Reiss | bfc57a0 | 2009-03-30 20:46:37 +0000 | [diff] [blame] | 1 | -module(test_membuffer). |
| 2 | -export([t/0]). |
| 3 | |
| 4 | -include("thriftTest_types.hrl"). |
| 5 | |
| 6 | test_data() -> |
| 7 | #xtruct{string_thing = <<"foobar">>, |
| 8 | byte_thing = 123, |
| 9 | i32_thing = 1234567, |
| 10 | i64_thing = 12345678900}. |
| 11 | |
| 12 | t1() -> |
| 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 Reiss | 233ace5 | 2009-03-30 20:46:47 +0000 | [diff] [blame^] | 26 | t2() -> |
| 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 Reiss | bfc57a0 | 2009-03-30 20:46:37 +0000 | [diff] [blame] | 43 | t() -> |
David Reiss | 233ace5 | 2009-03-30 20:46:47 +0000 | [diff] [blame^] | 44 | t1(), |
| 45 | t2(). |
David Reiss | bfc57a0 | 2009-03-30 20:46:37 +0000 | [diff] [blame] | 46 | |