THRIFT-3834 Erlang namespacing and exception metadata

Client: Erlang
Patch: Steve Cohen <steve@pinterest.com>

This closes #1027
This commit is contained in:
Steve Cohen 2016-06-14 00:32:48 +02:00 committed by Jens Geyer
parent 61b170845f
commit 7ea4a87fc5
4 changed files with 163 additions and 153 deletions

View File

@ -64,7 +64,7 @@ public:
} else if( iter->first.compare("otp16") == 0) { } else if( iter->first.compare("otp16") == 0) {
otp16_ = true; otp16_ = true;
} else { } else {
throw "unknown option erl:" + iter->first; throw "unknown option erl:" + iter->first;
} }
} }
@ -227,6 +227,7 @@ private:
*/ */
std::vector<std::string> v_struct_names_; std::vector<std::string> v_struct_names_;
std::vector<std::string> v_enum_names_; std::vector<std::string> v_enum_names_;
std::vector<std::string> v_exception_names_;
std::vector<t_enum*> v_enums_; std::vector<t_enum*> v_enums_;
}; };
@ -339,6 +340,7 @@ void t_erl_generator::close_generator() {
export_types_string("enum_info", 1); export_types_string("enum_info", 1);
export_types_string("enum_names", 0); export_types_string("enum_names", 0);
export_types_string("struct_names", 0); export_types_string("struct_names", 0);
export_types_string("exception_names", 0);
f_types_file_ << "-export([" << export_types_lines_.str() << "])." << endl << endl; f_types_file_ << "-export([" << export_types_lines_.str() << "])." << endl << endl;
@ -351,6 +353,7 @@ void t_erl_generator::close_generator() {
generate_type_metadata("struct_names", v_struct_names_); generate_type_metadata("struct_names", v_struct_names_);
generate_enum_metadata(); generate_enum_metadata();
generate_type_metadata("enum_names", v_enum_names_); generate_type_metadata("enum_names", v_enum_names_);
generate_type_metadata("exception_names", v_exception_names_);
hrl_footer(f_types_hrl_file_, string("BOGUS")); hrl_footer(f_types_hrl_file_, string("BOGUS"));
@ -369,7 +372,7 @@ void t_erl_generator::generate_type_metadata(std::string function_name, vector<s
for(size_t i=0; i < num_structs; i++) { for(size_t i=0; i < num_structs; i++) {
f_types_file_ << atomify(names.at(i)); f_types_file_ << names.at(i);
if (i < num_structs - 1) { if (i < num_structs - 1) {
f_types_file_ << ", "; f_types_file_ << ", ";
@ -400,7 +403,7 @@ void t_erl_generator::generate_enum(t_enum* tenum) {
vector<t_enum_value*>::iterator c_iter; vector<t_enum_value*>::iterator c_iter;
v_enums_.push_back(tenum); v_enums_.push_back(tenum);
v_enum_names_.push_back(tenum->get_name()); v_enum_names_.push_back(atomify(tenum->get_name()));
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) { for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
int value = (*c_iter)->get_value(); int value = (*c_iter)->get_value();
@ -497,7 +500,7 @@ string t_erl_generator::render_const_value(t_type* type, t_const_value* value) {
indent(out) << value->get_integer(); indent(out) << value->get_integer();
} else if (type->is_struct() || type->is_xception()) { } else if (type->is_struct() || type->is_xception()) {
out << "#" << atomify(type->get_name()) << "{"; out << "#" << type_name(type) << "{";
const vector<t_field*>& fields = ((t_struct*)type)->get_members(); const vector<t_field*>& fields = ((t_struct*)type)->get_members();
vector<t_field*>::const_iterator f_iter; vector<t_field*>::const_iterator f_iter;
const map<t_const_value*, t_const_value*>& val = value->get_map(); const map<t_const_value*, t_const_value*>& val = value->get_map();
@ -582,7 +585,7 @@ string t_erl_generator::render_const_value(t_type* type, t_const_value* value) {
string t_erl_generator::render_default_value(t_field* field) { string t_erl_generator::render_default_value(t_field* field) {
t_type* type = field->get_type(); t_type* type = field->get_type();
if (type->is_struct() || type->is_xception()) { if (type->is_struct() || type->is_xception()) {
return "#" + atomify(type->get_name()) + "{}"; return "#" + type_name(type) + "{}";
} else if (type->is_map()) { } else if (type->is_map()) {
if (maps_) { if (maps_) {
return "#{}"; return "#{}";
@ -620,7 +623,7 @@ string t_erl_generator::render_member_type(t_field* field) {
} else if (type->is_enum()) { } else if (type->is_enum()) {
return "integer()"; return "integer()";
} else if (type->is_struct() || type->is_xception()) { } else if (type->is_struct() || type->is_xception()) {
return atomify(type->get_name()) + "()"; return type_name(type) + "()";
} else if (type->is_map()) { } else if (type->is_map()) {
if (maps_) { if (maps_) {
return "#{}"; return "#{}";
@ -657,7 +660,7 @@ string t_erl_generator::render_member_requiredness(t_field* field) {
* Generates a struct * Generates a struct
*/ */
void t_erl_generator::generate_struct(t_struct* tstruct) { void t_erl_generator::generate_struct(t_struct* tstruct) {
v_struct_names_.push_back(tstruct->get_name()); v_struct_names_.push_back(type_name(tstruct));
generate_erl_struct(tstruct, false); generate_erl_struct(tstruct, false);
} }
@ -668,6 +671,7 @@ void t_erl_generator::generate_struct(t_struct* tstruct) {
* @param txception The struct definition * @param txception The struct definition
*/ */
void t_erl_generator::generate_xception(t_struct* txception) { void t_erl_generator::generate_xception(t_struct* txception) {
v_exception_names_.push_back(type_name(txception));
generate_erl_struct(txception, true); generate_erl_struct(txception, true);
} }
@ -1009,6 +1013,12 @@ string t_erl_generator::argument_list(t_struct* tstruct) {
string t_erl_generator::type_name(t_type* ttype) { string t_erl_generator::type_name(t_type* ttype) {
string prefix = ""; string prefix = "";
string erl_namespace = ttype->get_program()->get_namespace("erl");
if (erl_namespace.length() > 0) {
prefix = erl_namespace + ".";
}
string name = ttype->get_name(); string name = ttype->get_name();
if (ttype->is_struct() || ttype->is_xception() || ttype->is_service()) { if (ttype->is_struct() || ttype->is_xception() || ttype->is_service()) {

View File

@ -33,32 +33,32 @@ constant_test_() ->
record_generation_test_() -> record_generation_test_() ->
[ [
{"Bonk record", ?_assertMatch( {"Bonk record", ?_assertMatch(
{'Bonk', _, _}, {'thrift.test.Bonk', _, _},
#'Bonk'{message=null,type=null} #'thrift.test.Bonk'{message=null,type=null}
)}, )},
{"Bools record", ?_assertMatch( {"Bools record", ?_assertMatch(
{'Bools', _, _}, {'thrift.test.Bools', _, _},
#'Bools'{im_true=null,im_false=null} #'thrift.test.Bools'{im_true=null,im_false=null}
)}, )},
{"Xtruct record", ?_assertMatch( {"Xtruct record", ?_assertMatch(
{'Xtruct', _, _, _, _}, {'thrift.test.Xtruct', _, _, _, _},
#'Xtruct'{string_thing=null,byte_thing=null,i32_thing=null,i64_thing=null} #'thrift.test.Xtruct'{string_thing=null,byte_thing=null,i32_thing=null,i64_thing=null}
)}, )},
{"Xtruct2 record", ?_assertMatch( {"Xtruct2 record", ?_assertMatch(
{'Xtruct2', _, _, _}, {'thrift.test.Xtruct2', _, _, _},
#'Xtruct2'{byte_thing=null,struct_thing=null,i32_thing=null} #'thrift.test.Xtruct2'{byte_thing=null,struct_thing=null,i32_thing=null}
)}, )},
{"Xtruct3 record", ?_assertMatch( {"Xtruct3 record", ?_assertMatch(
{'Xtruct3', _, _, _, _}, {'thrift.test.Xtruct3', _, _, _, _},
#'Xtruct3'{string_thing=null,changed=null,i32_thing=null,i64_thing=null} #'thrift.test.Xtruct3'{string_thing=null,changed=null,i32_thing=null,i64_thing=null}
)}, )},
{"Insanity record", ?_assertMatch( {"Insanity record", ?_assertMatch(
{'Insanity', _, _}, {'thrift.test.Insanity', _, _},
#'Insanity'{userMap=null,xtructs=null} #'thrift.test.Insanity'{userMap=null,xtructs=null}
)}, )},
{"CrazyNesting record", ?_assertMatch( {"CrazyNesting record", ?_assertMatch(
{'CrazyNesting', _, _, _, _}, {'thrift.test.CrazyNesting', _, _, _, _},
#'CrazyNesting'{ #'thrift.test.CrazyNesting'{
string_field=null, string_field=null,
set_field=null, set_field=null,
list_field=null, list_field=null,
@ -66,22 +66,22 @@ record_generation_test_() ->
} }
)}, )},
{"Xception record", ?_assertMatch( {"Xception record", ?_assertMatch(
{'Xception', _, _}, {'thrift.test.Xception', _, _},
#'Xception'{errorCode=null,message=null} #'thrift.test.Xception'{errorCode=null,message=null}
)}, )},
{"Xception2 record", ?_assertMatch( {"Xception2 record", ?_assertMatch(
{'Xception2', _, _}, {'thrift.test.Xception2', _, _},
#'Xception2'{errorCode=null,struct_thing=null} #'thrift.test.Xception2'{errorCode=null,struct_thing=null}
)}, )},
{"EmptyStruct record", ?_assertMatch({'EmptyStruct'}, #'EmptyStruct'{})}, {"EmptyStruct record", ?_assertMatch({'thrift.test.EmptyStruct'}, #'thrift.test.EmptyStruct'{})},
{"OneField record", ?_assertMatch({'OneField', _}, #'OneField'{field=null})}, {"OneField record", ?_assertMatch({'thrift.test.OneField', _}, #'thrift.test.OneField'{field=null})},
{"VersioningTestV1 record", ?_assertMatch( {"VersioningTestV1 record", ?_assertMatch(
{'VersioningTestV1', _, _, _}, {'thrift.test.VersioningTestV1', _, _, _},
#'VersioningTestV1'{begin_in_both=null,old_string=null,end_in_both=null} #'thrift.test.VersioningTestV1'{begin_in_both=null,old_string=null,end_in_both=null}
)}, )},
{"VersioningTestV2 record", ?_assertMatch( {"VersioningTestV2 record", ?_assertMatch(
{'VersioningTestV2', _, _, _, _, _, _, _, _, _, _, _, _}, {'thrift.test.VersioningTestV2', _, _, _, _, _, _, _, _, _, _, _, _},
#'VersioningTestV2'{ #'thrift.test.VersioningTestV2'{
begin_in_both=null, begin_in_both=null,
newint=null, newint=null,
newbyte=null, newbyte=null,
@ -97,20 +97,20 @@ record_generation_test_() ->
} }
)}, )},
{"ListTypeVersioningV1 record", ?_assertMatch( {"ListTypeVersioningV1 record", ?_assertMatch(
{'ListTypeVersioningV1', _, _}, {'thrift.test.ListTypeVersioningV1', _, _},
#'ListTypeVersioningV1'{myints=null,hello=null} #'thrift.test.ListTypeVersioningV1'{myints=null,hello=null}
)}, )},
{"ListTypeVersioningV2 record", ?_assertMatch( {"ListTypeVersioningV2 record", ?_assertMatch(
{'ListTypeVersioningV2', _, _}, {'thrift.test.ListTypeVersioningV2', _, _},
#'ListTypeVersioningV2'{strings=null,hello=null} #'thrift.test.ListTypeVersioningV2'{strings=null,hello=null}
)}, )},
{"GuessProtocolStruct record", ?_assertMatch( {"GuessProtocolStruct record", ?_assertMatch(
{'GuessProtocolStruct', _}, {'thrift.test.GuessProtocolStruct', _},
#'GuessProtocolStruct'{map_field=null} #'thrift.test.GuessProtocolStruct'{map_field=null}
)}, )},
{"LargeDeltas record", ?_assertMatch( {"LargeDeltas record", ?_assertMatch(
{'LargeDeltas', _, _, _, _, _, _, _, _, _, _}, {'thrift.test.LargeDeltas', _, _, _, _, _, _, _, _, _, _},
#'LargeDeltas'{ #'thrift.test.LargeDeltas'{
b1=null, b1=null,
b10=null, b10=null,
b100=null, b100=null,
@ -124,34 +124,34 @@ record_generation_test_() ->
} }
)}, )},
{"NestedListsI32x2 record", ?_assertMatch( {"NestedListsI32x2 record", ?_assertMatch(
{'NestedListsI32x2', _}, {'thrift.test.NestedListsI32x2', _},
#'NestedListsI32x2'{integerlist=null} #'thrift.test.NestedListsI32x2'{integerlist=null}
)}, )},
{"NestedListsI32x3 record", ?_assertMatch( {"NestedListsI32x3 record", ?_assertMatch(
{'NestedListsI32x3', _}, {'thrift.test.NestedListsI32x3', _},
#'NestedListsI32x3'{integerlist=null} #'thrift.test.NestedListsI32x3'{integerlist=null}
)}, )},
{"NestedMixedx2 record", ?_assertMatch( {"NestedMixedx2 record", ?_assertMatch(
{'NestedMixedx2', _, _, _}, {'thrift.test.NestedMixedx2', _, _, _},
#'NestedMixedx2'{ #'thrift.test.NestedMixedx2'{
int_set_list=null, int_set_list=null,
map_int_strset=null, map_int_strset=null,
map_int_strset_list=null map_int_strset_list=null
} }
)}, )},
{"ListBonks record", ?_assertMatch({'ListBonks', _}, #'ListBonks'{bonk=null})}, {"ListBonks record", ?_assertMatch({'thrift.test.ListBonks', _}, #'thrift.test.ListBonks'{bonk=null})},
{"NestedListsBonk record", ?_assertMatch( {"NestedListsBonk record", ?_assertMatch(
{'NestedListsBonk', _}, {'thrift.test.NestedListsBonk', _},
#'NestedListsBonk'{bonk=null} #'thrift.test.NestedListsBonk'{bonk=null}
)}, )},
{"BoolTest record", ?_assertMatch( {"BoolTest record", ?_assertMatch(
{'BoolTest', _, _}, {'thrift.test.BoolTest', _, _},
#'BoolTest'{b=null,s=null} #'thrift.test.BoolTest'{b=null,s=null}
)}, )},
{"StructA record", ?_assertMatch({'StructA', _}, #'StructA'{s=null})}, {"StructA record", ?_assertMatch({'thrift.test.StructA', _}, #'thrift.test.StructA'{s=null})},
{"StructB record", ?_assertMatch( {"StructB record", ?_assertMatch(
{'StructB', _, _}, {'thrift.test.StructB', _, _},
#'StructB'{aa=null,ab=null} #'thrift.test.StructB'{aa=null,ab=null}
)} )}
]. ].
@ -159,21 +159,21 @@ struct_info_test_() ->
[ [
{"Bonk definition (short version)", ?_assertEqual( {"Bonk definition (short version)", ?_assertEqual(
{struct, [{1, string}, {2, i32}]}, {struct, [{1, string}, {2, i32}]},
thrift_test_types:struct_info('Bonk') thrift_test_types:struct_info('thrift.test.Bonk')
)}, )},
{"Bonk definition", ?_assertEqual( {"Bonk definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, string, message, undefined}, {1, undefined, string, message, undefined},
{2, undefined, i32, type, undefined} {2, undefined, i32, type, undefined}
]}, ]},
thrift_test_types:struct_info_ext('Bonk') thrift_test_types:struct_info_ext('thrift.test.Bonk')
)}, )},
{"Bools definition", ?_assertEqual( {"Bools definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, bool, im_true, undefined}, {1, undefined, bool, im_true, undefined},
{2, undefined, bool, im_false, undefined} {2, undefined, bool, im_false, undefined}
]}, ]},
thrift_test_types:struct_info_ext('Bools') thrift_test_types:struct_info_ext('thrift.test.Bools')
)}, )},
{"Xtruct definition", ?_assertEqual( {"Xtruct definition", ?_assertEqual(
{struct, [ {struct, [
@ -182,15 +182,15 @@ struct_info_test_() ->
{9, undefined, i32, i32_thing, undefined}, {9, undefined, i32, i32_thing, undefined},
{11, undefined, i64, i64_thing, undefined} {11, undefined, i64, i64_thing, undefined}
]}, ]},
thrift_test_types:struct_info_ext('Xtruct') thrift_test_types:struct_info_ext('thrift.test.Xtruct')
)}, )},
{"Xtruct2 definition", ?_assertEqual( {"Xtruct2 definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, byte, byte_thing, undefined}, {1, undefined, byte, byte_thing, undefined},
{2, undefined, {struct, {'thrift_test_types', 'Xtruct'}}, struct_thing, #'Xtruct'{}}, {2, undefined, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}, struct_thing, #'thrift.test.Xtruct'{}},
{3, undefined, i32, i32_thing, undefined} {3, undefined, i32, i32_thing, undefined}
]}, ]},
thrift_test_types:struct_info_ext('Xtruct2') thrift_test_types:struct_info_ext('thrift.test.Xtruct2')
)}, )},
{"Xtruct3 definition", ?_assertEqual( {"Xtruct3 definition", ?_assertEqual(
{struct, [ {struct, [
@ -199,50 +199,50 @@ struct_info_test_() ->
{9, undefined, i32, i32_thing, undefined}, {9, undefined, i32, i32_thing, undefined},
{11, undefined, i64, i64_thing, undefined} {11, undefined, i64, i64_thing, undefined}
]}, ]},
thrift_test_types:struct_info_ext('Xtruct3') thrift_test_types:struct_info_ext('thrift.test.Xtruct3')
)}, )},
{"Insanity definition", ?_assertEqual( {"Insanity definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {map, i32, i64}, userMap, dict:new()}, {1, undefined, {map, i32, i64}, userMap, dict:new()},
{2, undefined, {list, {struct, {'thrift_test_types', 'Xtruct'}}}, xtructs, []} {2, undefined, {list, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}}, xtructs, []}
]}, ]},
thrift_test_types:struct_info_ext('Insanity') thrift_test_types:struct_info_ext('thrift.test.Insanity')
)}, )},
{"CrazyNesting definition", ?_assertEqual( {"CrazyNesting definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, string, string_field, undefined}, {1, undefined, string, string_field, undefined},
{2, optional, {set, {struct, {'thrift_test_types', 'Insanity'}}}, set_field, sets:new()}, {2, optional, {set, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}}, set_field, sets:new()},
{3, required, {list, {map, {3, required, {list, {map,
{set, i32}, {set, i32},
{map, i32, {set, {list, {map, {struct, {'thrift_test_types', 'Insanity'}}, string}}}} {map, i32, {set, {list, {map, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}, string}}}}
}}, list_field, []}, }}, list_field, []},
{4, undefined, string, binary_field, undefined} {4, undefined, string, binary_field, undefined}
]}, ]},
thrift_test_types:struct_info_ext('CrazyNesting') thrift_test_types:struct_info_ext('thrift.test.CrazyNesting')
)}, )},
{"Xception definition", ?_assertEqual( {"Xception definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, i32, errorCode, undefined}, {1, undefined, i32, errorCode, undefined},
{2, undefined, string, message, undefined} {2, undefined, string, message, undefined}
]}, ]},
thrift_test_types:struct_info_ext('Xception') thrift_test_types:struct_info_ext('thrift.test.Xception')
)}, )},
{"Xception2 definition", ?_assertEqual( {"Xception2 definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, i32, errorCode, undefined}, {1, undefined, i32, errorCode, undefined},
{2, undefined, {struct, {'thrift_test_types', 'Xtruct'}}, struct_thing, #'Xtruct'{}} {2, undefined, {struct, {'thrift_test_types', 'thrift.test.Xtruct'}}, struct_thing, #'thrift.test.Xtruct'{}}
]}, ]},
thrift_test_types:struct_info_ext('Xception2') thrift_test_types:struct_info_ext('thrift.test.Xception2')
)}, )},
{"EmptyStruct definition", ?_assertEqual( {"EmptyStruct definition", ?_assertEqual(
{struct, []}, {struct, []},
thrift_test_types:struct_info_ext('EmptyStruct') thrift_test_types:struct_info_ext('thrift.test.EmptyStruct')
)}, )},
{"OneField definition", ?_assertEqual( {"OneField definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {struct, {'thrift_test_types', 'EmptyStruct'}}, field, #'EmptyStruct'{}} {1, undefined, {struct, {'thrift_test_types', 'thrift.test.EmptyStruct'}}, field, #'thrift.test.EmptyStruct'{}}
]}, ]},
thrift_test_types:struct_info_ext('OneField') thrift_test_types:struct_info_ext('thrift.test.OneField')
)}, )},
{"VersioningTestV1 definition", ?_assertEqual( {"VersioningTestV1 definition", ?_assertEqual(
{struct, [ {struct, [
@ -250,7 +250,7 @@ struct_info_test_() ->
{3, undefined, string, old_string, undefined}, {3, undefined, string, old_string, undefined},
{12, undefined, i32, end_in_both, undefined} {12, undefined, i32, end_in_both, undefined}
]}, ]},
thrift_test_types:struct_info_ext('VersioningTestV1') thrift_test_types:struct_info_ext('thrift.test.VersioningTestV1')
)}, )},
{"VersioningTestV2 definition", ?_assertEqual( {"VersioningTestV2 definition", ?_assertEqual(
{struct, [ {struct, [
@ -260,61 +260,61 @@ struct_info_test_() ->
{4, undefined, i16, newshort, undefined}, {4, undefined, i16, newshort, undefined},
{5, undefined, i64, newlong, undefined}, {5, undefined, i64, newlong, undefined},
{6, undefined, double, newdouble, undefined}, {6, undefined, double, newdouble, undefined},
{7, undefined, {struct, {thrift_test_types, 'Bonk'}}, newstruct, #'Bonk'{}}, {7, undefined, {struct, {thrift_test_types, 'thrift.test.Bonk'}}, newstruct, #'thrift.test.Bonk'{}},
{8, undefined, {list, i32}, newlist, []}, {8, undefined, {list, i32}, newlist, []},
{9, undefined, {set, i32}, newset, sets:new()}, {9, undefined, {set, i32}, newset, sets:new()},
{10, undefined, {map, i32, i32}, newmap, dict:new()}, {10, undefined, {map, i32, i32}, newmap, dict:new()},
{11, undefined, string, newstring, undefined}, {11, undefined, string, newstring, undefined},
{12, undefined, i32, end_in_both, undefined} {12, undefined, i32, end_in_both, undefined}
]}, ]},
thrift_test_types:struct_info_ext('VersioningTestV2') thrift_test_types:struct_info_ext('thrift.test.VersioningTestV2')
)}, )},
{"ListTypeVersioningV1 definition", ?_assertEqual( {"ListTypeVersioningV1 definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {list, i32}, myints, []}, {1, undefined, {list, i32}, myints, []},
{2, undefined, string, hello, undefined} {2, undefined, string, hello, undefined}
]}, ]},
thrift_test_types:struct_info_ext('ListTypeVersioningV1') thrift_test_types:struct_info_ext('thrift.test.ListTypeVersioningV1')
)}, )},
{"ListTypeVersioningV2 definition", ?_assertEqual( {"ListTypeVersioningV2 definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {list, string}, strings, []}, {1, undefined, {list, string}, strings, []},
{2, undefined, string, hello, undefined} {2, undefined, string, hello, undefined}
]}, ]},
thrift_test_types:struct_info_ext('ListTypeVersioningV2') thrift_test_types:struct_info_ext('thrift.test.ListTypeVersioningV2')
)}, )},
{"GuessProtocolStruct definition", ?_assertEqual( {"GuessProtocolStruct definition", ?_assertEqual(
{struct, [ {struct, [
{7, undefined, {map, string, string}, map_field, dict:new()} {7, undefined, {map, string, string}, map_field, dict:new()}
]}, ]},
thrift_test_types:struct_info_ext('GuessProtocolStruct') thrift_test_types:struct_info_ext('thrift.test.GuessProtocolStruct')
)}, )},
{"LargeDeltas definition", ?_assertEqual( {"LargeDeltas definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {struct, {thrift_test_types, 'Bools'}}, b1, #'Bools'{}}, {1, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b1, #'thrift.test.Bools'{}},
{10, undefined, {struct, {thrift_test_types, 'Bools'}}, b10, #'Bools'{}}, {10, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b10, #'thrift.test.Bools'{}},
{100, undefined, {struct, {thrift_test_types, 'Bools'}}, b100, #'Bools'{}}, {100, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b100, #'thrift.test.Bools'{}},
{500, undefined, bool, check_true, undefined}, {500, undefined, bool, check_true, undefined},
{1000, undefined, {struct, {thrift_test_types, 'Bools'}}, b1000, #'Bools'{}}, {1000, undefined, {struct, {thrift_test_types, 'thrift.test.Bools'}}, b1000, #'thrift.test.Bools'{}},
{1500, undefined, bool, check_false, undefined}, {1500, undefined, bool, check_false, undefined},
{2000, undefined, {struct, {thrift_test_types, 'VersioningTestV2'}}, vertwo2000, #'VersioningTestV2'{}}, {2000, undefined, {struct, {thrift_test_types, 'thrift.test.VersioningTestV2'}}, vertwo2000, #'thrift.test.VersioningTestV2'{}},
{2500, undefined, {set, string}, a_set2500, sets:new()}, {2500, undefined, {set, string}, a_set2500, sets:new()},
{3000, undefined, {struct, {thrift_test_types, 'VersioningTestV2'}}, vertwo3000, #'VersioningTestV2'{}}, {3000, undefined, {struct, {thrift_test_types, 'thrift.test.VersioningTestV2'}}, vertwo3000, #'thrift.test.VersioningTestV2'{}},
{4000, undefined, {list, i32}, big_numbers, []} {4000, undefined, {list, i32}, big_numbers, []}
]}, ]},
thrift_test_types:struct_info_ext('LargeDeltas') thrift_test_types:struct_info_ext('thrift.test.LargeDeltas')
)}, )},
{"NestedListsI32x2 definition", ?_assertEqual( {"NestedListsI32x2 definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {list, {list, i32}}, integerlist, []} {1, undefined, {list, {list, i32}}, integerlist, []}
]}, ]},
thrift_test_types:struct_info_ext('NestedListsI32x2') thrift_test_types:struct_info_ext('thrift.test.NestedListsI32x2')
)}, )},
{"NestedListsI32x3 definition", ?_assertEqual( {"NestedListsI32x3 definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {list, {list, {list, i32}}}, integerlist, []} {1, undefined, {list, {list, {list, i32}}}, integerlist, []}
]}, ]},
thrift_test_types:struct_info_ext('NestedListsI32x3') thrift_test_types:struct_info_ext('thrift.test.NestedListsI32x3')
)}, )},
{"NestedMixedx2 definition", ?_assertEqual( {"NestedMixedx2 definition", ?_assertEqual(
{struct, [ {struct, [
@ -322,37 +322,37 @@ struct_info_test_() ->
{2, undefined, {map, i32, {set, string}}, map_int_strset, dict:new()}, {2, undefined, {map, i32, {set, string}}, map_int_strset, dict:new()},
{3, undefined, {list, {map, i32, {set, string}}}, map_int_strset_list, []} {3, undefined, {list, {map, i32, {set, string}}}, map_int_strset_list, []}
]}, ]},
thrift_test_types:struct_info_ext('NestedMixedx2') thrift_test_types:struct_info_ext('thrift.test.NestedMixedx2')
)}, )},
{"ListBonks definition", ?_assertEqual( {"ListBonks definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {list, {struct, {thrift_test_types, 'Bonk'}}}, bonk, []} {1, undefined, {list, {struct, {thrift_test_types, 'thrift.test.Bonk'}}}, bonk, []}
]}, ]},
thrift_test_types:struct_info_ext('ListBonks') thrift_test_types:struct_info_ext('thrift.test.ListBonks')
)}, )},
{"NestedListsBonk definition", ?_assertEqual( {"NestedListsBonk definition", ?_assertEqual(
{struct, [ {struct, [
{1, undefined, {list, {list, {list, {struct, {thrift_test_types, 'Bonk'}}}}}, bonk, []} {1, undefined, {list, {list, {list, {struct, {thrift_test_types, 'thrift.test.Bonk'}}}}}, bonk, []}
]}, ]},
thrift_test_types:struct_info_ext('NestedListsBonk') thrift_test_types:struct_info_ext('thrift.test.NestedListsBonk')
)}, )},
{"BoolTest definition", ?_assertEqual( {"BoolTest definition", ?_assertEqual(
{struct, [ {struct, [
{1, optional, bool, b, true}, {1, optional, bool, b, true},
{2, optional, string, s, "true"} {2, optional, string, s, "true"}
]}, ]},
thrift_test_types:struct_info_ext('BoolTest') thrift_test_types:struct_info_ext('thrift.test.BoolTest')
)}, )},
{"StructA definition", ?_assertEqual( {"StructA definition", ?_assertEqual(
{struct, [{1, required, string, s, undefined}]}, {struct, [{1, required, string, s, undefined}]},
thrift_test_types:struct_info_ext('StructA') thrift_test_types:struct_info_ext('thrift.test.StructA')
)}, )},
{"StructB definition", ?_assertEqual( {"StructB definition", ?_assertEqual(
{struct, [ {struct, [
{1, optional, {struct, {thrift_test_types, 'StructA'}}, aa, #'StructA'{}}, {1, optional, {struct, {thrift_test_types, 'thrift.test.StructA'}}, aa, #'thrift.test.StructA'{}},
{2, required, {struct, {thrift_test_types, 'StructA'}}, ab, #'StructA'{}} {2, required, {struct, {thrift_test_types, 'thrift.test.StructA'}}, ab, #'thrift.test.StructA'{}}
]}, ]},
thrift_test_types:struct_info_ext('StructB') thrift_test_types:struct_info_ext('thrift.test.StructB')
)} )}
]. ].
@ -432,12 +432,12 @@ service_info_test_() ->
)}, )},
{"testStruct params", ?_assertEqual( {"testStruct params", ?_assertEqual(
{struct, [ {struct, [
{1, {struct, {thrift_test_types, 'Xtruct'}}} {1, {struct, {thrift_test_types, 'thrift.test.Xtruct'}}}
]}, ]},
thrift_test_thrift:function_info(testStruct, params_type) thrift_test_thrift:function_info(testStruct, params_type)
)}, )},
{"testStruct reply", ?_assertEqual( {"testStruct reply", ?_assertEqual(
{struct, {thrift_test_types, 'Xtruct'}}, {struct, {thrift_test_types, 'thrift.test.Xtruct'}},
thrift_test_thrift:function_info(testStruct, reply_type) thrift_test_thrift:function_info(testStruct, reply_type)
)}, )},
{"testStruct exceptions", ?_assertEqual( {"testStruct exceptions", ?_assertEqual(
@ -446,12 +446,12 @@ service_info_test_() ->
)}, )},
{"testNest params", ?_assertEqual( {"testNest params", ?_assertEqual(
{struct, [ {struct, [
{1, {struct, {thrift_test_types, 'Xtruct2'}}} {1, {struct, {thrift_test_types, 'thrift.test.Xtruct2'}}}
]}, ]},
thrift_test_thrift:function_info(testNest, params_type) thrift_test_thrift:function_info(testNest, params_type)
)}, )},
{"testNest reply", ?_assertEqual( {"testNest reply", ?_assertEqual(
{struct, {thrift_test_types, 'Xtruct2'}}, {struct, {thrift_test_types, 'thrift.test.Xtruct2'}},
thrift_test_thrift:function_info(testNest, reply_type) thrift_test_thrift:function_info(testNest, reply_type)
)}, )},
{"testNest exceptions", ?_assertEqual( {"testNest exceptions", ?_assertEqual(
@ -556,12 +556,12 @@ service_info_test_() ->
)}, )},
{"testInsanity params", ?_assertEqual( {"testInsanity params", ?_assertEqual(
{struct, [ {struct, [
{1, {struct, {thrift_test_types, 'Insanity'}}} {1, {struct, {thrift_test_types, 'thrift.test.Insanity'}}}
]}, ]},
thrift_test_thrift:function_info(testInsanity, params_type) thrift_test_thrift:function_info(testInsanity, params_type)
)}, )},
{"testInsanity reply", ?_assertEqual( {"testInsanity reply", ?_assertEqual(
{map, i64, {map, i32, {struct, {'thrift_test_types', 'Insanity'}}}}, {map, i64, {map, i32, {struct, {'thrift_test_types', 'thrift.test.Insanity'}}}},
thrift_test_thrift:function_info(testInsanity, reply_type) thrift_test_thrift:function_info(testInsanity, reply_type)
)}, )},
{"testInsanity exceptions", ?_assertEqual( {"testInsanity exceptions", ?_assertEqual(
@ -580,7 +580,7 @@ service_info_test_() ->
thrift_test_thrift:function_info(testMulti, params_type) thrift_test_thrift:function_info(testMulti, params_type)
)}, )},
{"testMulti reply", ?_assertEqual( {"testMulti reply", ?_assertEqual(
{struct, {thrift_test_types, 'Xtruct'}}, {struct, {thrift_test_types, 'thrift.test.Xtruct'}},
thrift_test_thrift:function_info(testMulti, reply_type) thrift_test_thrift:function_info(testMulti, reply_type)
)}, )},
{"testMulti exceptions", ?_assertEqual( {"testMulti exceptions", ?_assertEqual(
@ -597,7 +597,7 @@ service_info_test_() ->
)}, )},
{"testException exceptions", ?_assertEqual( {"testException exceptions", ?_assertEqual(
{struct, [ {struct, [
{1, {struct, {thrift_test_types, 'Xception'}}} {1, {struct, {thrift_test_types, 'thrift.test.Xception'}}}
]}, ]},
thrift_test_thrift:function_info(testException, exceptions) thrift_test_thrift:function_info(testException, exceptions)
)}, )},
@ -606,13 +606,13 @@ service_info_test_() ->
thrift_test_thrift:function_info(testMultiException, params_type) thrift_test_thrift:function_info(testMultiException, params_type)
)}, )},
{"testMultiException reply", ?_assertEqual( {"testMultiException reply", ?_assertEqual(
{struct, {thrift_test_types, 'Xtruct'}}, {struct, {thrift_test_types, 'thrift.test.Xtruct'}},
thrift_test_thrift:function_info(testMultiException, reply_type) thrift_test_thrift:function_info(testMultiException, reply_type)
)}, )},
{"testMultiException exceptions", ?_assertEqual( {"testMultiException exceptions", ?_assertEqual(
{struct, [ {struct, [
{1, {struct, {thrift_test_types, 'Xception'}}}, {1, {struct, {thrift_test_types, 'thrift.test.Xception'}}},
{2, {struct, {thrift_test_types, 'Xception2'}}} {2, {struct, {thrift_test_types, 'thrift.test.Xception2'}}}
]}, ]},
thrift_test_thrift:function_info(testMultiException, exceptions) thrift_test_thrift:function_info(testMultiException, exceptions)
)}, )},

View File

@ -68,13 +68,13 @@ start(Args) ->
{ok, Client0} = thrift_client_util:new( {ok, Client0} = thrift_client_util:new(
"127.0.0.1", Port, thrift_test_thrift, ClientOpts), "127.0.0.1", Port, thrift_test_thrift, ClientOpts),
DemoXtruct = #'Xtruct'{ DemoXtruct = #'thrift.test.Xtruct'{
string_thing = <<"Zero">>, string_thing = <<"Zero">>,
byte_thing = 1, byte_thing = 1,
i32_thing = 9128361, i32_thing = 9128361,
i64_thing = 9223372036854775807}, i64_thing = 9223372036854775807},
DemoNest = #'Xtruct2'{ DemoNest = #'thrift.test.Xtruct2'{
byte_thing = 7, byte_thing = 7,
struct_thing = DemoXtruct, struct_thing = DemoXtruct,
% Note that we don't set i32_thing, it will come back as undefined % Note that we don't set i32_thing, it will come back as undefined
@ -86,9 +86,9 @@ start(Args) ->
DemoDict = dict:from_list([ {Key, Key-10} || Key <- lists:seq(0,10) ]), DemoDict = dict:from_list([ {Key, Key-10} || Key <- lists:seq(0,10) ]),
DemoSet = sets:from_list([ Key || Key <- lists:seq(-3,3) ]), DemoSet = sets:from_list([ Key || Key <- lists:seq(-3,3) ]),
DemoInsane = #'Insanity'{ DemoInsane = #'thrift.test.Insanity'{
userMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_FIVE, 5000}]), userMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_FIVE, 5000}]),
xtructs = [#'Xtruct'{ string_thing = <<"Truck">>, byte_thing = 8, i32_thing = 8, i64_thing = 8}]}, xtructs = [#'thrift.test.Xtruct'{ string_thing = <<"Truck">>, byte_thing = 8, i32_thing = 8, i64_thing = 8}]},
error_logger:info_msg("testVoid"), error_logger:info_msg("testVoid"),
{Client01, {ok, ok}} = thrift_client:call(Client0, testVoid, []), {Client01, {ok, ok}} = thrift_client:call(Client0, testVoid, []),
@ -126,7 +126,7 @@ start(Args) ->
{Client16, {ok, InsaneResult}} = thrift_client:call(Client15, testInsanity, [DemoInsane]), {Client16, {ok, InsaneResult}} = thrift_client:call(Client15, testInsanity, [DemoInsane]),
io:format("~p~n", [InsaneResult]), io:format("~p~n", [InsaneResult]),
{Client17, {ok, #'Xtruct'{string_thing = <<"Message">>}}} = {Client17, {ok, #'thrift.test.Xtruct'{string_thing = <<"Message">>}}} =
thrift_client:call(Client16, testMultiException, ["Safe", "Message"]), thrift_client:call(Client16, testMultiException, ["Safe", "Message"]),
Client18 = Client18 =
@ -135,10 +135,10 @@ start(Args) ->
io:format("Unexpected return! ~p~n", [Result1]), io:format("Unexpected return! ~p~n", [Result1]),
ClientS1 ClientS1
catch catch
throw:{ClientS2, {exception, ExnS1 = #'Xception'{}}} -> throw:{ClientS2, {exception, ExnS1 = #'thrift.test.Xception'{}}} ->
#'Xception'{errorCode = 1001, message = <<"This is an Xception">>} = ExnS1, #'thrift.test.Xception'{errorCode = 1001, message = <<"This is an Xception">>} = ExnS1,
ClientS2; ClientS2;
throw:{ClientS2, {exception, _ExnS1 = #'Xception2'{}}} -> throw:{ClientS2, {exception, _ExnS1 = #'thrift.test.Xception2'{}}} ->
io:format("Wrong exception type!~n", []), io:format("Wrong exception type!~n", []),
ClientS2 ClientS2
end, end,
@ -149,12 +149,12 @@ start(Args) ->
io:format("Unexpected return! ~p~n", [Result2]), io:format("Unexpected return! ~p~n", [Result2]),
ClientS3 ClientS3
catch catch
throw:{ClientS4, {exception, _ExnS2 = #'Xception'{}}} -> throw:{ClientS4, {exception, _ExnS2 = #'thrift.test.Xception'{}}} ->
io:format("Wrong exception type!~n", []), io:format("Wrong exception type!~n", []),
ClientS4; ClientS4;
throw:{ClientS4, {exception, ExnS2 = #'Xception2'{}}} -> throw:{ClientS4, {exception, ExnS2 = #'thrift.test.Xception2'{}}} ->
#'Xception2'{errorCode = 2002, #'thrift.test.Xception2'{errorCode = 2002,
struct_thing = #'Xtruct'{ struct_thing = #'thrift.test.Xtruct'{
string_thing = <<"This is an Xception2">>}} = ExnS2, string_thing = <<"This is an Xception2">>}} = ExnS2,
ClientS4 ClientS4
end, end,

View File

@ -107,10 +107,10 @@ handle_function(testBinary, {S}) when is_binary(S) ->
{reply, S}; {reply, S};
handle_function(testStruct, handle_function(testStruct,
{Struct = #'Xtruct'{string_thing = String, {Struct = #'thrift.test.Xtruct'{string_thing = String,
byte_thing = Byte, byte_thing = Byte,
i32_thing = I32, i32_thing = I32,
i64_thing = I64}}) i64_thing = I64}})
when is_binary(String), when is_binary(String),
is_integer(Byte), is_integer(Byte),
is_integer(I32), is_integer(I32),
@ -119,8 +119,8 @@ when is_binary(String),
{reply, Struct}; {reply, Struct};
handle_function(testNest, handle_function(testNest,
{Nest}) when is_record(Nest, 'Xtruct2'), {Nest}) when is_record(Nest, 'thrift.test.Xtruct2'),
is_record(Nest#'Xtruct2'.struct_thing, 'Xtruct') -> is_record(Nest#'thrift.test.Xtruct2'.struct_thing, 'thrift.test.Xtruct') ->
io:format("testNest: ~p~n", [Nest]), io:format("testNest: ~p~n", [Nest]),
{reply, Nest}; {reply, Nest};
@ -159,22 +159,22 @@ handle_function(testMapMap, {Hello}) ->
{-4, dict:from_list(NegList)}]), {-4, dict:from_list(NegList)}]),
{reply, MapMap}; {reply, MapMap};
handle_function(testInsanity, {Insanity}) when is_record(Insanity, 'Insanity') -> handle_function(testInsanity, {Insanity}) when is_record(Insanity, 'thrift.test.Insanity') ->
Hello = #'Xtruct'{string_thing = <<"Hello2">>, Hello = #'thrift.test.Xtruct'{string_thing = <<"Hello2">>,
byte_thing = 2, byte_thing = 2,
i32_thing = 2, i32_thing = 2,
i64_thing = 2}, i64_thing = 2},
Goodbye = #'Xtruct'{string_thing = <<"Goodbye4">>, Goodbye = #'thrift.test.Xtruct'{string_thing = <<"Goodbye4">>,
byte_thing = 4, byte_thing = 4,
i32_thing = 4, i32_thing = 4,
i64_thing = 4}, i64_thing = 4},
Crazy = #'Insanity'{ Crazy = #'thrift.test.Insanity'{
userMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_EIGHT, 8}]), userMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_EIGHT, 8}]),
xtructs = [Goodbye] xtructs = [Goodbye]
}, },
Looney = #'Insanity'{}, Looney = #'thrift.test.Insanity'{},
FirstMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_TWO, Insanity}, FirstMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_TWO, Insanity},
{?THRIFT_TEST_NUMBERZ_THREE, Insanity}]), {?THRIFT_TEST_NUMBERZ_THREE, Insanity}]),
@ -196,16 +196,16 @@ handle_function(testMulti, Args = {Arg0, Arg1, Arg2, _Arg3, Arg4, Arg5})
is_integer(Arg5) -> is_integer(Arg5) ->
io:format("testMulti(~p)~n", [Args]), io:format("testMulti(~p)~n", [Args]),
{reply, #'Xtruct'{string_thing = <<"Hello2">>, {reply, #'thrift.test.Xtruct'{string_thing = <<"Hello2">>,
byte_thing = Arg0, byte_thing = Arg0,
i32_thing = Arg1, i32_thing = Arg1,
i64_thing = Arg2}}; i64_thing = Arg2}};
handle_function(testException, {String}) when is_binary(String) -> handle_function(testException, {String}) when is_binary(String) ->
io:format("testException(~p)~n", [String]), io:format("testException(~p)~n", [String]),
case String of case String of
<<"Xception">> -> <<"Xception">> ->
throw(#'Xception'{errorCode = 1001, throw(#'thrift.test.Xception'{errorCode = 1001,
message = String}); message = String});
<<"TException">> -> <<"TException">> ->
throw({?TApplicationException_Structure}); throw({?TApplicationException_Structure});
@ -217,14 +217,14 @@ handle_function(testMultiException, {Arg0, Arg1}) ->
io:format("testMultiException(~p, ~p)~n", [Arg0, Arg1]), io:format("testMultiException(~p, ~p)~n", [Arg0, Arg1]),
case Arg0 of case Arg0 of
<<"Xception">> -> <<"Xception">> ->
throw(#'Xception'{errorCode = 1001, throw(#'thrift.test.Xception'{errorCode = 1001,
message = <<"This is an Xception">>}); message = <<"This is an Xception">>});
<<"Xception2">> -> <<"Xception2">> ->
throw(#'Xception2'{errorCode = 2002, throw(#'thrift.test.Xception2'{errorCode = 2002,
struct_thing = struct_thing =
#'Xtruct'{string_thing = <<"This is an Xception2">>}}); #'thrift.test.Xtruct'{string_thing = <<"This is an Xception2">>}});
_ -> _ ->
{reply, #'Xtruct'{string_thing = Arg1}} {reply, #'thrift.test.Xtruct'{string_thing = Arg1}}
end; end;
handle_function(testOneway, {Seconds}) -> handle_function(testOneway, {Seconds}) ->