blob: 19ac5277e352ce9840d201f4391caf625c5c7791 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001%%
2%% Licensed to the Apache Software Foundation (ASF) under one
3%% or more contributor license agreements. See the NOTICE file
4%% distributed with this work for additional information
5%% regarding copyright ownership. The ASF licenses this file
6%% to you under the Apache License, Version 2.0 (the
7%% "License"); you may not use this file except in compliance
8%% with the License. You may obtain a copy of the License at
9%%
10%% http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing,
13%% software distributed under the License is distributed on an
14%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15%% KIND, either express or implied. See the License for the
16%% specific language governing permissions and limitations
17%% under the License.
18%%
19
David Reissbfc57a02009-03-30 20:46:37 +000020-module(test_membuffer).
21-export([t/0]).
22
23-include("thriftTest_types.hrl").
24
25test_data() ->
26 #xtruct{string_thing = <<"foobar">>,
27 byte_thing = 123,
28 i32_thing = 1234567,
29 i64_thing = 12345678900}.
30
31t1() ->
32 {ok, Transport} = thrift_memory_buffer:new(),
David Reissf28f23d2010-08-30 22:05:48 +000033 {ok, Protocol0} = thrift_binary_protocol:new(Transport),
David Reissbfc57a02009-03-30 20:46:37 +000034 TestData = test_data(),
David Reissf28f23d2010-08-30 22:05:48 +000035 {Protocol1, ok} = thrift_protocol:write(Protocol0,
David Reissbfc57a02009-03-30 20:46:37 +000036 {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
37 TestData}),
David Reissf28f23d2010-08-30 22:05:48 +000038 {_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
David Reissbfc57a02009-03-30 20:46:37 +000039 {struct, element(2, thriftTest_types:struct_info('xtruct'))},
40 'xtruct'),
41
42 Result = TestData.
43
44
David Reiss233ace52009-03-30 20:46:47 +000045t2() ->
46 {ok, Transport} = thrift_memory_buffer:new(),
David Reissf28f23d2010-08-30 22:05:48 +000047 {ok, Protocol0} = thrift_binary_protocol:new(Transport),
David Reiss233ace52009-03-30 20:46:47 +000048 TestData = test_data(),
David Reissf28f23d2010-08-30 22:05:48 +000049 {Protocol1, ok} = thrift_protocol:write(Protocol0,
David Reiss233ace52009-03-30 20:46:47 +000050 {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
51 TestData}),
David Reissf28f23d2010-08-30 22:05:48 +000052 {_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
David Reiss233ace52009-03-30 20:46:47 +000053 {struct, element(2, thriftTest_types:struct_info('xtruct3'))},
54 'xtruct3'),
55
56 Result = #xtruct3{string_thing = TestData#xtruct.string_thing,
57 changed = undefined,
58 i32_thing = TestData#xtruct.i32_thing,
59 i64_thing = TestData#xtruct.i64_thing}.
60
61
David Reissb3c5f6e2009-03-30 20:46:52 +000062t3() ->
63 {ok, Transport} = thrift_memory_buffer:new(),
David Reissf28f23d2010-08-30 22:05:48 +000064 {ok, Protocol0} = thrift_binary_protocol:new(Transport),
David Reissb3c5f6e2009-03-30 20:46:52 +000065 TestData = #bools{im_true = true, im_false = false},
David Reissf28f23d2010-08-30 22:05:48 +000066 {Protocol1, ok} = thrift_protocol:write(Protocol0,
David Reissb3c5f6e2009-03-30 20:46:52 +000067 {{struct, element(2, thriftTest_types:struct_info('bools'))},
68 TestData}),
David Reissf28f23d2010-08-30 22:05:48 +000069 {_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
David Reissb3c5f6e2009-03-30 20:46:52 +000070 {struct, element(2, thriftTest_types:struct_info('bools'))},
71 'bools'),
72
73 true = TestData#bools.im_true =:= Result#bools.im_true,
74 true = TestData#bools.im_false =:= Result#bools.im_false.
75
76
David Reissb4ab0082010-08-30 22:05:58 +000077t4() ->
78 {ok, Transport} = thrift_memory_buffer:new(),
79 {ok, Protocol0} = thrift_binary_protocol:new(Transport),
80 TestData = #insanity{xtructs=[]},
81 {Protocol1, ok} = thrift_protocol:write(Protocol0,
82 {{struct, element(2, thriftTest_types:struct_info('insanity'))},
83 TestData}),
84 {_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
85 {struct, element(2, thriftTest_types:struct_info('insanity'))},
86 'insanity'),
87
88 TestData = Result.
89
90
David Reissbfc57a02009-03-30 20:46:37 +000091t() ->
David Reiss233ace52009-03-30 20:46:47 +000092 t1(),
David Reissb3c5f6e2009-03-30 20:46:52 +000093 t2(),
David Reissb4ab0082010-08-30 22:05:58 +000094 t3(),
95 t4().
David Reissbfc57a02009-03-30 20:46:37 +000096