begin\r
if b\r
then result := 'true'\r
- else result := 'false';
-end;
-
-// not available in all versions, so make sure we have this one imported
-function IsDebuggerPresent: BOOL; stdcall; external KERNEL32 name 'IsDebuggerPresent';
-
-{ TTestClient }
-
+ else result := 'false';\r
+end;\r
+\r
+// not available in all versions, so make sure we have this one imported\r
+function IsDebuggerPresent: BOOL; stdcall; external KERNEL32 name 'IsDebuggerPresent';\r
+\r
+{ TTestClient }\r
+\r
class procedure TTestClient.Execute(const args: array of string);\r
var\r
i : Integer;\r
i2 : IXtruct2;\r
mapout : IThriftDictionary<Integer,Integer>;\r
mapin : IThriftDictionary<Integer,Integer>;\r
+ strmapout : IThriftDictionary<string,string>;\r
+ strmapin : IThriftDictionary<string,string>;\r
j : Integer;\r
first : Boolean;\r
key : Integer;\r
+ strkey : string;\r
listout : IThriftList<Integer>;\r
listin : IThriftList<Integer>;\r
setout : IHashSet<Integer>;\r
\r
begin\r
client := TThriftTest.TClient.Create( FProtocol);\r
- try\r
- if not FTransport.IsOpen then\r
- begin\r
- FTransport.Open;\r
- end;\r
- except\r
- on E: Exception do\r
- begin\r
- Console.WriteLine( E.Message );\r
- Exit;\r
- end;\r
- end;\r
+ FTransport.Open;\r
\r
// in-depth exception test\r
// (1) do we get an exception at all?\r
// (2) do we get the right exception?\r
// (3) does the exception contain the expected data?\r
StartTestGroup( 'testException');\r
+ // case 1: exception type declared in IDL at the function call\r
try\r
client.testException('Xception');\r
Expect( FALSE, 'testException(''Xception''): must trow an exception');\r
except\r
on e:TXception do begin\r
- Expect( e.ErrorCode = 1001, 'error code');\r
- Expect( e.Message_ = 'This is an Xception', 'error message');\r
+ Expect( e.ErrorCode = 1001, 'error code');\r
+ Expect( e.Message_ = 'Xception', 'error message');\r
Console.WriteLine( ' = ' + IntToStr(e.ErrorCode) + ', ' + e.Message_ );\r
end;\r
on e:TTransportException do Expect( FALSE, 'Unexpected : "'+e.ToString+'"');\r
on e:Exception do Expect( FALSE, 'Unexpected exception type "'+e.ClassName+'"');\r
end;\r
\r
+ // case 2: exception type NOT declared in IDL at the function call\r
+ // this will close the connection\r
+ try\r
+ client.testException('TException');\r
+ Expect( FALSE, 'testException(''TException''): must trow an exception');\r
+ except\r
+ on e:TTransportException do begin\r
+ Console.WriteLine( e.ClassName+' = '+e.Message); // this is what we get\r
+ if FTransport.IsOpen then FTransport.Close;\r
+ FTransport.Open; // re-open connection, server has already closed\r
+ end;\r
+ on e:TException do Expect( FALSE, 'Unexpected exception type "'+e.ClassName+'"');\r
+ on e:Exception do Expect( FALSE, 'Unexpected exception type "'+e.ClassName+'"');\r
+ end;\r
+\r
+ // case 3: no exception\r
+ try\r
+ client.testException('something');\r
+ Expect( TRUE, 'testException(''something''): must not trow an exception');\r
+ except\r
+ on e:TTransportException do Expect( FALSE, 'Unexpected : "'+e.ToString+'"');\r
+ on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'"');\r
+ end;\r
+\r
+\r
// simple things\r
StartTestGroup( 'simple Thrift calls');\r
client.testVoid();\r
end;\r
\r
\r
+ // map<type1,type2>: A map of strictly unique keys to values.\r
+ // Translates to an STL map, Java HashMap, PHP associative array, Python/Ruby dictionary, etc.\r
+ StartTestGroup( 'testStringMap');\r
+ strmapout := TThriftDictionaryImpl<string,string>.Create;\r
+ for j := 0 to 4 do\r
+ begin\r
+ strmapout.AddOrSetValue( IntToStr(j), IntToStr(j - 10));\r
+ end;\r
+ Console.Write('testStringMap({');\r
+ first := True;\r
+ for strkey in strmapout.Keys do\r
+ begin\r
+ if first\r
+ then first := False\r
+ else Console.Write( ', ' );\r
+ Console.Write( strkey + ' => ' + strmapout[strkey]);\r
+ end;\r
+ Console.WriteLine('})');\r
+\r
+ strmapin := client.testStringMap( strmapout );\r
+ Expect( strmapin.Count = strmapout.Count, 'testStringMap: strmapin.Count = strmapout.Count');\r
+ for j := 0 to 4 do\r
+ begin\r
+ Expect( strmapout.ContainsKey(IntToStr(j)),\r
+ 'testStringMap: strmapout.ContainsKey('+IntToStr(j)+') = '\r
+ + BoolToString(strmapout.ContainsKey(IntToStr(j))));\r
+ end;\r
+ for strkey in strmapin.Keys do\r
+ begin\r
+ Expect( strmapin[strkey] = strmapout[strkey], 'testStringMap: '+strkey + ' => ' + strmapin[strkey]);\r
+ Expect( strmapin[strkey] = IntToStr( StrToInt(strkey) - 10), 'testStringMap: strmapin['+strkey+'] = '+strmapin[strkey]);\r
+ end;\r
+\r
+\r
// set<type>: An unordered set of unique elements.\r
// Translates to an STL set, Java HashSet, set in Python, etc.\r
// Note: PHP does not support sets, so it is treated similar to a List\r
Expect( not looney.__isset_UserMap, 'looney.__isset_UserMap = '+BoolToString(looney.__isset_UserMap));\r
Expect( not looney.__isset_Xtructs, 'looney.__isset_Xtructs = '+BoolToString(looney.__isset_Xtructs));\r
//\r
- for ret in [TNumberz.SIX, TNumberz.THREE] do begin\r
+ for ret in [TNumberz.TWO, TNumberz.THREE] do begin\r
crazy := first_map[ret];\r
Console.WriteLine('first_map['+intToStr(Ord(ret))+']');\r
\r
Expect( goodbye.__isset_I32_thing, 'goodbye.__isset_I32_thing = '+BoolToString(goodbye.__isset_I32_thing));\r
Expect( goodbye.__isset_I64_thing, 'goodbye.__isset_I64_thing = '+BoolToString(goodbye.__isset_I64_thing));\r
\r
- Expect( hello.String_thing = 'hello', 'hello.String_thing = "'+hello.String_thing+'"');\r
+ Expect( hello.String_thing = 'Hello2', 'hello.String_thing = "'+hello.String_thing+'"');\r
Expect( hello.Byte_thing = 2, 'hello.Byte_thing = '+IntToStr(hello.Byte_thing));\r
Expect( hello.I32_thing = 2, 'hello.I32_thing = '+IntToStr(hello.I32_thing));\r
Expect( hello.I64_thing = 2, 'hello.I64_thing = '+IntToStr(hello.I64_thing));\r
Console.WriteLine('FAILED TESTS:');\r
for sLine in FErrors do Console.WriteLine('- '+sLine);\r
Console.WriteLine( StringOfChar('=',60));\r
+ InterlockedIncrement( ExitCode); // return <> 0 on errors\r
end;\r
Console.WriteLine('');\r
end;\r
Console.WriteLine('testException(' + arg + ')');
if ( arg = 'Xception') then
begin
- raise TXception.Create( 1001, 'This is an Xception');
+ raise TXception.Create( 1001, arg);
end;
+
+ if (arg = 'TException') then
+ begin
+ raise TException.Create('');
+ end;
+
+ // else do not throw anything
end;
function TTestServer.TTestHandlerImpl.testI32(thing: Integer): Integer;
Console.WriteLine('testInsanity()');
hello := TXtructImpl.Create;
- hello.String_thing := 'hello';
+ hello.String_thing := 'Hello2';
hello.Byte_thing := 2;
hello.I32_thing := 2;
hello.I64_thing := 2;
first_map := TThriftDictionaryImpl<TNumberz, IInsanity>.Create;
second_map := TThriftDictionaryImpl<TNumberz, IInsanity>.Create;
- first_map.AddOrSetValue( TNumberz.SIX, crazy);
+ first_map.AddOrSetValue( TNumberz.TWO, crazy);
first_map.AddOrSetValue( TNumberz.THREE, crazy);
second_map.AddOrSetValue( TNumberz.SIX, looney);
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('})');
+ Result := thing;
end;
function TTestServer.TTestHandlerImpl.testTypedef( const thing: Int64): Int64;