THRIFT-4862 better ToString() support for enums and container types
Client: Delphi
Patch: Jens Geyer
This closes #1795
diff --git a/lib/delphi/test/TestServer.pas b/lib/delphi/test/TestServer.pas
index 374472c..4cb0090 100644
--- a/lib/delphi/test/TestServer.pas
+++ b/lib/delphi/test/TestServer.pas
@@ -150,7 +150,7 @@
function TTestServer.TTestHandlerImpl.testEnum(thing: TNumberz): TNumberz;
begin
- Console.WriteLine('testEnum(' + IntToStr( Integer( thing)) + ')');
+ Console.WriteLine('testEnum(' + EnumUtils<TNumberz>.ToString(Ord(thing)) + ')');
Result := thing;
end;
@@ -191,7 +191,10 @@
insane : IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>;
begin
- Console.WriteLine('testInsanity()');
+ Console.Write('testInsanity(');
+ if argument <> nil then Console.Write(argument.ToString);
+ Console.WriteLine(')');
+
(**
* So you think you've got this all worked, out eh?
@@ -222,49 +225,20 @@
Result := insane;
end;
-function TTestServer.TTestHandlerImpl.testList(
- const thing: IThriftList<Integer>): IThriftList<Integer>;
-var
- first : Boolean;
- elem : Integer;
+function TTestServer.TTestHandlerImpl.testList( const thing: IThriftList<Integer>): IThriftList<Integer>;
begin
- Console.Write('testList({');
- first := True;
- for elem in thing do
- begin
- if first then
- begin
- first := False;
- end else
- begin
- Console.Write(', ');
- end;
- Console.Write( IntToStr( elem));
- end;
- Console.WriteLine('})');
+ Console.Write('testList(');
+ if thing <> nil then Console.Write(thing.ToString);
+ Console.WriteLine(')');
Result := thing;
end;
function TTestServer.TTestHandlerImpl.testMap(
const thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>;
-var
- first : Boolean;
- key : Integer;
begin
- Console.Write('testMap({');
- first := True;
- for key in thing.Keys do
- begin
- if (first) then
- begin
- first := false;
- end else
- begin
- Console.Write(', ');
- end;
- Console.Write(IntToStr(key) + ' => ' + IntToStr( thing[key]));
- end;
- Console.WriteLine('})');
+ Console.Write('testMap(');
+ if thing <> nil then Console.Write(thing.ToString);
+ Console.WriteLine(')');
Result := thing;
end;
@@ -313,12 +287,11 @@
x2 : TXception2;
begin
Console.WriteLine('testMultiException(' + arg0 + ', ' + arg1 + ')');
- if ( arg0 = 'Xception') then
- begin
+ if ( arg0 = 'Xception') then begin
raise TXception.Create( 1001, 'This is an Xception'); // test the new rich CTOR
- end else
- if ( arg0 = 'Xception2') then
- begin
+ end;
+
+ if ( arg0 = 'Xception2') then begin
x2 := TXception2.Create; // the old way still works too?
x2.ErrorCode := 2002;
x2.Struct_thing := TXtructImpl.Create;
@@ -332,17 +305,11 @@
end;
function TTestServer.TTestHandlerImpl.testNest( const thing: IXtruct2): IXtruct2;
-var
- temp : IXtruct;
begin
- temp := thing.Struct_thing;
- Console.WriteLine('testNest({' +
- IntToStr( thing.Byte_thing) + ', {' +
- '"' + temp.String_thing + '", ' +
- IntToStr( temp.Byte_thing) + ', ' +
- IntToStr( temp.I32_thing) + ', ' +
- IntToStr( temp.I64_thing) + '}, ' +
- IntToStr( temp.I32_thing) + '})');
+ Console.Write('testNest(');
+ if thing <> nil then Console.Write(thing.ToString);
+ Console.WriteLine(')');
+
Result := thing;
end;
@@ -353,34 +320,18 @@
Console.WriteLine('testOneway finished');
end;
-function TTestServer.TTestHandlerImpl.testSet(
- const thing: IHashSet<Integer>):IHashSet<Integer>;
-var
- first : Boolean;
- elem : Integer;
+function TTestServer.TTestHandlerImpl.testSet( const thing: IHashSet<Integer>):IHashSet<Integer>;
begin
- Console.Write('testSet({');
- first := True;
+ Console.Write('testSet(');
+ if thing <> nil then Console.Write(thing.ToString);
+ Console.WriteLine(')');;
- for elem in thing do
- begin
- if first then
- begin
- first := False;
- end else
- begin
- Console.Write( ', ');
- end;
- Console.Write( IntToStr( elem));
- end;
- Console.WriteLine('})');
Result := thing;
end;
procedure TTestServer.TTestHandlerImpl.testStop;
begin
- if FServer <> nil then
- begin
+ if FServer <> nil then begin
FServer.Stop;
end;
end;
@@ -399,24 +350,11 @@
function TTestServer.TTestHandlerImpl.testStringMap(
const thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>;
-var
- first : Boolean;
- key : string;
begin
- Console.Write('testStringMap({');
- first := True;
- for key in thing.Keys do
- begin
- if (first) then
- begin
- first := false;
- end else
- begin
- Console.Write(', ');
- end;
- Console.Write(key + ' => ' + thing[key]);
- end;
- Console.WriteLine('})');
+ Console.Write('testStringMap(');
+ if thing <> nil then Console.Write(thing.ToString);
+ Console.WriteLine(')');
+
Result := thing;
end;
@@ -433,11 +371,10 @@
function TTestServer.TTestHandlerImpl.testStruct( const thing: IXtruct): IXtruct;
begin
- Console.WriteLine('testStruct({' +
- '"' + thing.String_thing + '", ' +
- IntToStr( thing.Byte_thing) + ', ' +
- IntToStr( thing.I32_thing) + ', ' +
- IntToStr( thing.I64_thing));
+ Console.Write('testStruct(');
+ if thing <> nil then Console.Write(thing.ToString);
+ Console.WriteLine(')');
+
Result := thing;
end;