Upgrading dependency to Thrift 0.12.0

This commit is contained in:
Renan DelValle 2018-11-27 18:03:50 -08:00
parent 3e4590dcc0
commit 356978cb42
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
1302 changed files with 101701 additions and 26784 deletions

View file

@ -0,0 +1,22 @@
struct test1 {
1: i32 one
2: i32 two // omit
3: i32 three
}
struct test2 {
1: i32 one
2: test2 two // omit
3: i32 three
}
struct test3 {
1: i32 one
2: list<test1> two // omit
}
struct test4 {
1: i32 one
2: map<i32,test1> two // omit
}

View file

@ -0,0 +1,54 @@
%%
%% Licensed to the Apache Software Foundation (ASF) under one
%% or more contributor license agreements. See the NOTICE file
%% distributed with this work for additional information
%% regarding copyright ownership. The ASF licenses this file
%% to you under the Apache License, Version 2.0 (the
%% "License"); you may not use this file except in compliance
%% with the License. You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
-module(test_const).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-include("gen-erl/constants_demo_types.hrl").
namespace_test() ->
%% Verify that records produced by ConstantsDemo.thrift have the right namespace.
io:format(user, "in namespace_test()\n", []),
{struct, _} = constants_demo_types:struct_info('consts_thing'),
{struct, _} = constants_demo_types:struct_info('consts_Blah'),
ok.
const_map_test() ->
?assertEqual(233, constants_demo_constants:gen_map(35532)),
?assertError(function_clause, constants_demo_constants:gen_map(0)),
?assertEqual(853, constants_demo_constants:gen_map(43523, default)),
?assertEqual(default, constants_demo_constants:gen_map(10110, default)),
?assertEqual(98325, constants_demo_constants:gen_map2("lkjsdf")),
?assertError(function_clause, constants_demo_constants:gen_map2("nonexist")),
?assertEqual(233, constants_demo_constants:gen_map2("hello", 321)),
?assertEqual(321, constants_demo_constants:gen_map2("goodbye", 321)).
const_list_test() ->
?assertEqual(23598352, constants_demo_constants:gen_list(2)),
?assertError(function_clause, constants_demo_constants:gen_list(0)),
?assertEqual(3253523, constants_demo_constants:gen_list(3, default)),
?assertEqual(default, constants_demo_constants:gen_list(10, default)).
-endif. %% TEST

View file

@ -0,0 +1,79 @@
-module(test_omit).
-include("gen-erl/thrift_omit_with_types.hrl").
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
omit_struct1_test() ->
%% In this test, the field that is deleted is a basic type (an i32).
A = #test1{one = 1, three = 3},
B = #test1{one = 1, two = 2, three = 3},
{ok, Transport} = thrift_membuffer_transport:new(),
{ok, P0} = thrift_binary_protocol:new(Transport),
{P1, ok} = thrift_protocol:write(P0, {{struct, {thrift_omit_with_types, element(1, A)}}, A}),
{P2, {ok, O0}} = thrift_protocol:read(P1, {struct, {thrift_omit_without_types, element(1, A)}}),
?assertEqual(element(1, A), element(1, O0)),
?assertEqual(element(2, A), element(2, O0)),
?assertEqual(element(4, A), element(3, O0)),
{P3, ok} = thrift_protocol:write(P2, {{struct, {thrift_omit_with_types, element(1, B)}}, B}),
{_P4, {ok, O1}} = thrift_protocol:read(P3, {struct, {thrift_omit_without_types, element(1, A)}}),
?assertEqual(element(1, A), element(1, O1)),
?assertEqual(element(2, A), element(2, O1)),
?assertEqual(element(4, A), element(3, O1)),
ok.
omit_struct2_test() ->
%% In this test, the field that is deleted is a struct.
A = #test2{one = 1, two = #test2{one = 10, three = 30}, three = 3},
B = #test2{one = 1, two = #test2{one = 10, two = #test2{one = 100}, three = 30}, three = 3},
{ok, Transport} = thrift_membuffer_transport:new(),
{ok, P0} = thrift_binary_protocol:new(Transport),
{P1, ok} = thrift_protocol:write(P0, {{struct, {thrift_omit_with_types, element(1, A)}}, A}),
{P2, {ok, O0}} = thrift_protocol:read(P1, {struct, {thrift_omit_without_types, element(1, A)}}),
?assertEqual(element(1, A), element(1, O0)),
?assertEqual(element(2, A), element(2, O0)),
?assertEqual(element(4, A), element(3, O0)),
{P3, ok} = thrift_protocol:write(P2, {{struct, {thrift_omit_with_types, element(1, B)}}, B}),
{_P4, {ok, O1}} = thrift_protocol:read(P3, {struct, {thrift_omit_without_types, element(1, A)}}),
?assertEqual(element(1, A), element(1, O1)),
?assertEqual(element(2, A), element(2, O1)),
?assertEqual(element(4, A), element(3, O1)),
ok.
omit_list_test() ->
%% In this test, the field that is deleted is a list.
A = #test1{one = 1, two = 2, three = 3},
B = #test3{one = 1, two = [ A ]},
{ok, Transport} = thrift_membuffer_transport:new(),
{ok, P0} = thrift_binary_protocol:new(Transport),
{P1, ok} = thrift_protocol:write(P0, {{struct, {thrift_omit_with_types, element(1, B)}}, B}),
{_P2, {ok, O0}} = thrift_protocol:read(P1, {struct, {thrift_omit_without_types, element(1, B)}}),
?assertEqual(element(2, B), element(2, O0)),
ok.
omit_map_test() ->
%% In this test, the field that is deleted is a map.
A = #test1{one = 1, two = 2, three = 3},
B = #test4{one = 1, two = dict:from_list([ {2, A} ])},
{ok, Transport} = thrift_membuffer_transport:new(),
{ok, P0} = thrift_binary_protocol:new(Transport),
{P1, ok} = thrift_protocol:write(P0, {{struct, {thrift_omit_with_types, element(1, B)}}, B}),
{_P2, {ok, O0}} = thrift_protocol:read(P1, {struct, {thrift_omit_without_types, element(1, B)}}),
?assertEqual(element(2, B), element(2, O0)),
ok.
-endif. %% TEST

View file

@ -0,0 +1,68 @@
%%
%% Licensed to the Apache Software Foundation (ASF) under one
%% or more contributor license agreements. See the NOTICE file
%% distributed with this work for additional information
%% regarding copyright ownership. The ASF licenses this file
%% to you under the Apache License, Version 2.0 (the
%% "License"); you may not use this file except in compliance
%% with the License. You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
-module(test_rendered_double_constants).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-include("gen-erl/double_constants_test_constants.hrl").
-define(EPSILON, 0.0000001).
rendered_double_constants_test() ->
?assert(abs(1.0 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST) =< ?EPSILON),
?assert(abs(-100.0 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST) =< ?EPSILON),
?assert(abs(9223372036854775807.0 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST) =< ?EPSILON),
?assert(abs(-9223372036854775807.0 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST) =< ?EPSILON),
?assert(abs(3.14159265359 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST) =< ?EPSILON),
?assert(abs(1000000.1 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST) =< ?EPSILON),
?assert(abs(-1000000.1 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST) =< ?EPSILON),
?assert(abs(1.7e+308 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST) =< ?EPSILON),
?assert(abs(9223372036854775816.43 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST) =< ?EPSILON),
?assert(abs(-1.7e+308 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST) =< ?EPSILON),
?assert(abs(-9223372036854775816.43 - ?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST) =< ?EPSILON),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST)),
?assert(is_float(?DOUBLE_CONSTANTS_TEST_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST)).
rendered_double_list_test() ->
?assertEqual(12, length(?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)),
?assert(abs(1.0 - lists:nth(1, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(-100.0 - lists:nth(2, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(100.0 - lists:nth(3, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(9223372036854775807.0 - lists:nth(4, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(-9223372036854775807.0 - lists:nth(5, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(3.14159265359 - lists:nth(6, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(1000000.1 - lists:nth(7, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(-1000000.1 - lists:nth(8, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(1.7e+308 - lists:nth(9, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(-1.7e+308 - lists:nth(10, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(9223372036854775816.43 - lists:nth(11, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON),
?assert(abs(-9223372036854775816.43 - lists:nth(12, ?DOUBLE_CONSTANTS_TEST_DOUBLE_LIST_TEST)) =< ?EPSILON).
-endif. %% TEST

View file

@ -628,18 +628,6 @@ service_info_test_() ->
{struct, []},
thrift_test_thrift:function_info(testOneway, exceptions)
)},
{"blahBlah params", ?_assertEqual(
{struct, []},
second_service_thrift:function_info(blahBlah, params_type)
)},
{"blahBlah reply", ?_assertEqual(
{struct, []},
second_service_thrift:function_info(blahBlah, reply_type)
)},
{"blahBlah exceptions", ?_assertEqual(
{struct, []},
second_service_thrift:function_info(blahBlah, exceptions)
)},
{"secondtestString params", ?_assertEqual(
{struct, [{1, string}]},
second_service_thrift:function_info(secondtestString, params_type)