blob: 141787e57c6d8d9c864051df62c36ead0efb173e [file] [log] [blame]
Sergei Elin45764092022-09-23 23:21:31 +03001%%
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
Anthony F. Molinaro917d8982011-06-21 06:20:18 +000020-module(test_thrift_1151).
21
Roger Meier25c68f42014-09-29 22:12:50 +020022-include("gen-erl/thrift1151_types.hrl").
Anthony F. Molinaro917d8982011-06-21 06:20:18 +000023
24-ifdef(TEST).
25-include_lib("eunit/include/eunit.hrl").
26
27unmatched_struct_test() ->
Sergei Elin45764092022-09-23 23:21:31 +030028 S1 = #'StructC'{x = #'StructB'{x = 1}},
29 {ok, Transport} = thrift_memory_buffer:new(),
30 {ok, Protocol} = thrift_binary_protocol:new(Transport),
31 ?assertException(
32 error,
33 struct_unmatched,
34 thrift_protocol:write(
35 Protocol,
36 {{struct, element(2, thrift1151_types:struct_info('StructC'))}, S1}
37 )
38 ).
Anthony F. Molinaro917d8982011-06-21 06:20:18 +000039
40badarg_test() ->
Sergei Elin45764092022-09-23 23:21:31 +030041 S2 = #'StructC'{x = #'StructA'{x = "1"}},
42 {ok, Transport} = thrift_memory_buffer:new(),
43 {ok, Protocol} = thrift_binary_protocol:new(Transport),
44 ?assertException(
45 error,
46 badarg,
47 thrift_protocol:write(
48 Protocol,
49 {{struct, element(2, thrift1151_types:struct_info('StructC'))}, S2}
50 )
51 ).
Anthony F. Molinaro917d8982011-06-21 06:20:18 +000052
53-endif.