THRIFT-2628 struct member name conflicts due to lowercased names
Client: Erlang
Patch: Alisdair Sullivan
This closes #228
diff --git a/lib/erl/test/test_client.erl b/lib/erl/test/test_client.erl
index 79708ca..db4d2d1 100644
--- a/lib/erl/test/test_client.erl
+++ b/lib/erl/test/test_client.erl
@@ -21,7 +21,7 @@
-export([start/0, start/1]).
--include("gen-erl/thriftTest_types.hrl").
+-include("gen-erl/thrift_test_types.hrl").
-record(options, {port = 9090,
client_opts = []}).
@@ -50,15 +50,15 @@
start(Args) ->
#options{port = Port, client_opts = ClientOpts} = parse_args(Args),
{ok, Client0} = thrift_client_util:new(
- "127.0.0.1", Port, thriftTest_thrift, ClientOpts),
+ "127.0.0.1", Port, thrift_test_thrift, ClientOpts),
- DemoXtruct = #xtruct{
+ DemoXtruct = #'Xtruct'{
string_thing = <<"Zero">>,
byte_thing = 1,
i32_thing = 9128361,
i64_thing = 9223372036854775807},
- DemoNest = #xtruct2{
+ DemoNest = #'Xtruct2'{
byte_thing = 7,
struct_thing = DemoXtruct,
% Note that we don't set i32_thing, it will come back as undefined
@@ -88,7 +88,7 @@
{Client11, {ok, DemoDict}} = thrift_client:call(Client10, testMap, [DemoDict]),
{Client12, {ok, DemoSet}} = thrift_client:call(Client11, testSet, [DemoSet]),
{Client13, {ok, [-1,2,3]}} = thrift_client:call(Client12, testList, [[-1,2,3]]),
- {Client14, {ok, 1}} = thrift_client:call(Client13, testEnum, [?thriftTest_Numberz_ONE]),
+ {Client14, {ok, 1}} = thrift_client:call(Client13, testEnum, [?THRIFT_TEST_NUMBERZ_ONE]),
{Client15, {ok, 309858235082523}} = thrift_client:call(Client14, testTypedef, [309858235082523]),
% No python implementation, but works with C++ and Erlang.
@@ -96,7 +96,7 @@
%io:format("~p~n", [InsaneResult]),
Client16 = Client15,
- {Client17, {ok, #xtruct{string_thing = <<"Message">>}}} =
+ {Client17, {ok, #'Xtruct'{string_thing = <<"Message">>}}} =
thrift_client:call(Client16, testMultiException, ["Safe", "Message"]),
Client18 =
@@ -105,10 +105,10 @@
io:format("Unexpected return! ~p~n", [Result1]),
ClientS1
catch
- throw:{ClientS2, {exception, ExnS1 = #xception{}}} ->
- #xception{errorCode = 1001, message = <<"This is an Xception">>} = ExnS1,
+ throw:{ClientS2, {exception, ExnS1 = #'Xception'{}}} ->
+ #'Xception'{errorCode = 1001, message = <<"This is an Xception">>} = ExnS1,
ClientS2;
- throw:{ClientS2, {exception, _ExnS1 = #xception2{}}} ->
+ throw:{ClientS2, {exception, _ExnS1 = #'Xception2'{}}} ->
io:format("Wrong exception type!~n", []),
ClientS2
end,
@@ -119,12 +119,12 @@
io:format("Unexpected return! ~p~n", [Result2]),
ClientS3
catch
- throw:{ClientS4, {exception, _ExnS2 = #xception{}}} ->
+ throw:{ClientS4, {exception, _ExnS2 = #'Xception'{}}} ->
io:format("Wrong exception type!~n", []),
ClientS4;
- throw:{ClientS4, {exception, ExnS2 = #xception2{}}} ->
- #xception2{errorCode = 2002,
- struct_thing = #xtruct{
+ throw:{ClientS4, {exception, ExnS2 = #'Xception2'{}}} ->
+ #'Xception2'{errorCode = 2002,
+ struct_thing = #'Xtruct'{
string_thing = <<"This is an Xception2">>}} = ExnS2,
ClientS4
end,
diff --git a/lib/erl/test/test_disklog.erl b/lib/erl/test/test_disklog.erl
index d8cd4fc..6286bc0 100644
--- a/lib/erl/test/test_disklog.erl
+++ b/lib/erl/test/test_disklog.erl
@@ -31,7 +31,7 @@
{ok, ProtocolFactory} =
thrift_binary_protocol:new_protocol_factory( TransportFactory, []),
{ok, Proto} = ProtocolFactory(),
- {ok, Client0} = thrift_client:new(Proto, thriftTest_thrift),
+ {ok, Client0} = thrift_client:new(Proto, thrift_test_thrift),
io:format("Client started~n"),
@@ -70,7 +70,7 @@
{ok, ProtocolFactory} =
thrift_binary_protocol:new_protocol_factory(BufFactory, []),
{ok, Proto} = ProtocolFactory(),
- {ok, Client0} = thrift_client:new(Proto, thriftTest_thrift),
+ {ok, Client0} = thrift_client:new(Proto, thrift_test_thrift),
io:format("Client started~n"),
diff --git a/lib/erl/test/test_membuffer.erl b/lib/erl/test/test_membuffer.erl
index 8892df0..671ae11 100644
--- a/lib/erl/test/test_membuffer.erl
+++ b/lib/erl/test/test_membuffer.erl
@@ -22,10 +22,10 @@
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
--include("gen-erl/thriftTest_types.hrl").
+-include("gen-erl/thrift_test_types.hrl").
test_data() ->
- #xtruct {
+ #'Xtruct'{
string_thing = <<"foobar">>,
byte_thing = 123,
i32_thing = 1234567,
@@ -37,11 +37,11 @@
{ok, Protocol0} = thrift_binary_protocol:new(Transport),
TestData = test_data(),
{Protocol1, ok} = thrift_protocol:write(Protocol0,
- {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
+ {{struct, element(2, thrift_test_types:struct_info('Xtruct'))},
TestData}),
{_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
- {struct, element(2, thriftTest_types:struct_info('xtruct'))},
- 'xtruct'),
+ {struct, element(2, thrift_test_types:struct_info('Xtruct'))},
+ 'Xtruct'),
Result = TestData.
encode_decode_2_test() ->
@@ -49,43 +49,43 @@
{ok, Protocol0} = thrift_binary_protocol:new(Transport),
TestData = test_data(),
{Protocol1, ok} = thrift_protocol:write(Protocol0,
- {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
+ {{struct, element(2, thrift_test_types:struct_info('Xtruct'))},
TestData}),
{_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
- {struct, element(2, thriftTest_types:struct_info('xtruct3'))},
- 'xtruct3'),
+ {struct, element(2, thrift_test_types:struct_info('Xtruct3'))},
+ 'Xtruct3'),
- Result = #xtruct3{string_thing = TestData#xtruct.string_thing,
+ Result = #'Xtruct3'{string_thing = TestData#'Xtruct'.string_thing,
changed = undefined,
- i32_thing = TestData#xtruct.i32_thing,
- i64_thing = TestData#xtruct.i64_thing}.
+ i32_thing = TestData#'Xtruct'.i32_thing,
+ i64_thing = TestData#'Xtruct'.i64_thing}.
encode_decode_3_test() ->
{ok, Transport} = thrift_memory_buffer:new(),
{ok, Protocol0} = thrift_binary_protocol:new(Transport),
- TestData = #bools{im_true = true, im_false = false},
+ TestData = #'Bools'{im_true = true, im_false = false},
{Protocol1, ok} = thrift_protocol:write(Protocol0,
- {{struct, element(2, thriftTest_types:struct_info('bools'))},
+ {{struct, element(2, thrift_test_types:struct_info('Bools'))},
TestData}),
{_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
- {struct, element(2, thriftTest_types:struct_info('bools'))},
- 'bools'),
+ {struct, element(2, thrift_test_types:struct_info('Bools'))},
+ 'Bools'),
- true = TestData#bools.im_true =:= Result#bools.im_true,
- true = TestData#bools.im_false =:= Result#bools.im_false.
+ true = TestData#'Bools'.im_true =:= Result#'Bools'.im_true,
+ true = TestData#'Bools'.im_false =:= Result#'Bools'.im_false.
encode_decode_4_test() ->
{ok, Transport} = thrift_memory_buffer:new(),
{ok, Protocol0} = thrift_binary_protocol:new(Transport),
- TestData = #insanity{xtructs=[]},
+ TestData = #'Insanity'{xtructs=[]},
{Protocol1, ok} = thrift_protocol:write(Protocol0,
- {{struct, element(2, thriftTest_types:struct_info('insanity'))},
+ {{struct, element(2, thrift_test_types:struct_info('Insanity'))},
TestData}),
{_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
- {struct, element(2, thriftTest_types:struct_info('insanity'))},
- 'insanity'),
+ {struct, element(2, thrift_test_types:struct_info('Insanity'))},
+ 'Insanity'),
TestData = Result.
@@ -98,17 +98,17 @@
{ok, Protocol0} = thrift_binary_protocol:new(Transport0),
TestData = test_data(),
{Protocol1, ok} = thrift_protocol:write(Protocol0,
- {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
+ {{struct, element(2, thrift_test_types:struct_info('Xtruct'))},
TestData}),
% flush now returns the buffer
- {_Protocol2, Buf} = thrift_protocol:flush_transport (Protocol1),
+ {_Protocol2, Buf} = thrift_protocol:flush_transport(Protocol1),
% now the reading part
{ok, T2} = thrift_memory_buffer:new (Buf),
{ok, P2} = thrift_binary_protocol:new(T2),
{_, {ok, Result}} = thrift_protocol:read(P2,
- {struct, element(2, thriftTest_types:struct_info('xtruct'))},
- 'xtruct'),
+ {struct, element(2, thrift_test_types:struct_info('Xtruct'))},
+ 'Xtruct'),
Result = TestData.
diff --git a/lib/erl/test/test_server.erl b/lib/erl/test/test_server.erl
index 8cabd6f..a4145d6 100644
--- a/lib/erl/test/test_server.erl
+++ b/lib/erl/test/test_server.erl
@@ -21,7 +21,7 @@
-export([go/0, go/1, start_link/2, handle_function/2]).
--include("gen-erl/thriftTest_types.hrl").
+-include("gen-erl/thrift_test_types.hrl").
-record(options, {port = 9090,
server_opts = []}).
@@ -82,7 +82,7 @@
{reply, Double};
handle_function(testStruct,
- {Struct = #xtruct{string_thing = String,
+ {Struct = #'Xtruct'{string_thing = String,
byte_thing = Byte,
i32_thing = I32,
i64_thing = I64}})
@@ -94,8 +94,8 @@
{reply, Struct};
handle_function(testNest,
- {Nest}) when is_record(Nest, xtruct2),
- is_record(Nest#xtruct2.struct_thing, xtruct) ->
+ {Nest}) when is_record(Nest, 'Xtruct2'),
+ is_record(Nest#'Xtruct2'.struct_thing, 'Xtruct') ->
io:format("testNest: ~p~n", [Nest]),
{reply, Nest};
@@ -130,30 +130,30 @@
{-4, dict:from_list(NegList)}]),
{reply, MapMap};
-handle_function(testInsanity, {Insanity}) when is_record(Insanity, insanity) ->
- Hello = #xtruct{string_thing = <<"Hello2">>,
+handle_function(testInsanity, {Insanity}) when is_record(Insanity, 'Insanity') ->
+ Hello = #'Xtruct'{string_thing = <<"Hello2">>,
byte_thing = 2,
i32_thing = 2,
i64_thing = 2},
- Goodbye = #xtruct{string_thing = <<"Goodbye4">>,
+ Goodbye = #'Xtruct'{string_thing = <<"Goodbye4">>,
byte_thing = 4,
i32_thing = 4,
i64_thing = 4},
- Crazy = #insanity{
- userMap = dict:from_list([{?thriftTest_Numberz_EIGHT, 8}]),
+ Crazy = #'Insanity'{
+ userMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_EIGHT, 8}]),
xtructs = [Goodbye]
},
- Looney = #insanity{
- userMap = dict:from_list([{?thriftTest_Numberz_FIVE, 5}]),
+ Looney = #'Insanity'{
+ userMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_FIVE, 5}]),
xtructs = [Hello]
},
- FirstMap = dict:from_list([{?thriftTest_Numberz_TWO, Crazy},
- {?thriftTest_Numberz_THREE, Crazy}]),
+ FirstMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_TWO, Crazy},
+ {?THRIFT_TEST_NUMBERZ_THREE, Crazy}]),
- SecondMap = dict:from_list([{?thriftTest_Numberz_SIX, Looney}]),
+ SecondMap = dict:from_list([{?THRIFT_TEST_NUMBERZ_SIX, Looney}]),
Insane = dict:from_list([{1, FirstMap},
{2, SecondMap}]),
@@ -170,7 +170,7 @@
is_integer(Arg5) ->
io:format("testMulti(~p)~n", [Args]),
- {reply, #xtruct{string_thing = <<"Hello2">>,
+ {reply, #'Xtruct'{string_thing = <<"Hello2">>,
byte_thing = Arg0,
i32_thing = Arg1,
i64_thing = Arg2}};
@@ -179,7 +179,7 @@
io:format("testException(~p)~n", [String]),
case String of
<<"Xception">> ->
- throw(#xception{errorCode = 1001,
+ throw(#'Xception'{errorCode = 1001,
message = String});
_ ->
ok
@@ -189,14 +189,14 @@
io:format("testMultiException(~p, ~p)~n", [Arg0, Arg1]),
case Arg0 of
<<"Xception">> ->
- throw(#xception{errorCode = 1001,
+ throw(#'Xception'{errorCode = 1001,
message = <<"This is an Xception">>});
<<"Xception2">> ->
- throw(#xception2{errorCode = 2002,
+ throw(#'Xception2'{errorCode = 2002,
struct_thing =
- #xtruct{string_thing = <<"This is an Xception2">>}});
+ #'Xtruct'{string_thing = <<"This is an Xception2">>}});
_ ->
- {reply, #xtruct{string_thing = Arg1}}
+ {reply, #'Xtruct'{string_thing = Arg1}}
end;
handle_function(testOneway, {Seconds}) ->
diff --git a/lib/erl/test/test_thrift_1151.erl b/lib/erl/test/test_thrift_1151.erl
index 8b1d937..f4a910e 100644
--- a/lib/erl/test/test_thrift_1151.erl
+++ b/lib/erl/test/test_thrift_1151.erl
@@ -6,19 +6,29 @@
-include_lib("eunit/include/eunit.hrl").
unmatched_struct_test() ->
- S1 = #structC{x=#structB{x=1}},
+ S1 = #'StructC'{x=#'StructB'{x=1}},
{ok, Transport} = thrift_memory_buffer:new(),
{ok, Protocol} = thrift_binary_protocol:new(Transport),
- ?assertException (error, struct_unmatched,
- thrift_protocol:write(Protocol,
- {{struct, element(2, thrift1151_types:struct_info('structC'))}, S1})).
+ ?assertException(
+ error,
+ struct_unmatched,
+ thrift_protocol:write(
+ Protocol,
+ {{struct, element(2, thrift1151_types:struct_info('StructC'))}, S1}
+ )
+ ).
badarg_test() ->
- S2 = #structC{x=#structA{x="1"}},
+ S2 = #'StructC'{x=#'StructA'{x="1"}},
{ok, Transport} = thrift_memory_buffer:new(),
{ok, Protocol} = thrift_binary_protocol:new(Transport),
- ?assertException (error, badarg,
- thrift_protocol:write(Protocol,
- {{struct, element(2, thrift1151_types:struct_info('structC'))}, S2})).
+ ?assertException(
+ error,
+ badarg,
+ thrift_protocol:write(
+ Protocol,
+ {{struct, element(2, thrift1151_types:struct_info('StructC'))}, S2}
+ )
+ ).
-endif.