1%%
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
20-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(),
33    {ok, Protocol} = thrift_binary_protocol:new(Transport),
34    TestData = test_data(),
35    ok = thrift_protocol:write(Protocol,
36			       {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
37				TestData}),
38    {ok, Result} = thrift_protocol:read(Protocol,
39					{struct, element(2, thriftTest_types:struct_info('xtruct'))},
40					'xtruct'),
41
42    Result = TestData.
43
44
45t2() ->
46    {ok, Transport} = thrift_memory_buffer:new(),
47    {ok, Protocol} = thrift_binary_protocol:new(Transport),
48    TestData = test_data(),
49    ok = thrift_protocol:write(Protocol,
50			       {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
51				TestData}),
52    {ok, Result} = thrift_protocol:read(Protocol,
53					{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
62t3() ->
63    {ok, Transport} = thrift_memory_buffer:new(),
64    {ok, Protocol} = thrift_binary_protocol:new(Transport),
65    TestData = #bools{im_true = true, im_false = false},
66    ok = thrift_protocol:write(Protocol,
67			       {{struct, element(2, thriftTest_types:struct_info('bools'))},
68				TestData}),
69    {ok, Result} = thrift_protocol:read(Protocol,
70					{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
77t() ->
78    t1(),
79    t2(),
80    t3().
81
82