Jens Geyer | 7bb44a3 | 2014-02-07 22:24:37 +0100 | [diff] [blame] | 1 | (* |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | *) |
| 19 | |
| 20 | unit TestClient; |
| 21 | |
Jens Geyer | 9f7f11e | 2016-04-14 21:37:11 +0200 | [diff] [blame] | 22 | {$I ../src/Thrift.Defines.inc} |
| 23 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 24 | {.$DEFINE StressTest} // activate to stress-test the server with frequent connects/disconnects |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 25 | {.$DEFINE PerfTest} // activate the performance test |
| 26 | {$DEFINE Exceptions} // activate the exceptions test (or disable while debugging) |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 27 | |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 28 | {$if CompilerVersion >= 28} |
| 29 | {$DEFINE SupportsAsync} |
| 30 | {$ifend} |
| 31 | |
Jens Geyer | 47f6317 | 2019-06-06 22:42:58 +0200 | [diff] [blame] | 32 | {$WARN SYMBOL_PLATFORM OFF} // Win32Check |
| 33 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 34 | interface |
| 35 | |
| 36 | uses |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 37 | Classes, Windows, SysUtils, Math, ActiveX, ComObj, |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 38 | {$IFDEF SupportsAsync} System.Threading, {$ENDIF} |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 39 | DateUtils, |
| 40 | Generics.Collections, |
| 41 | TestConstants, |
Jens Geyer | 3d55624 | 2018-01-24 19:14:32 +0100 | [diff] [blame] | 42 | ConsoleHelper, |
Jens Geyer | b342bd9 | 2019-06-03 20:27:00 +0200 | [diff] [blame] | 43 | PerfTests, |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 44 | Thrift, |
Jens Geyer | f0e6331 | 2015-03-01 18:47:49 +0100 | [diff] [blame] | 45 | Thrift.Protocol.Compact, |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 46 | Thrift.Protocol.JSON, |
| 47 | Thrift.Protocol, |
| 48 | Thrift.Transport.Pipes, |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 49 | Thrift.Transport.WinHTTP, |
| 50 | Thrift.Transport.MsxmlHTTP, |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 51 | Thrift.Transport, |
| 52 | Thrift.Stream, |
| 53 | Thrift.Test, |
Jens Geyer | 83ff753 | 2019-06-06 22:46:03 +0200 | [diff] [blame] | 54 | Thrift.WinHTTP, |
Jens Geyer | f790445 | 2017-07-26 15:02:12 +0200 | [diff] [blame] | 55 | Thrift.Utils, |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 56 | Thrift.Configuration, |
Jens Geyer | 3d55624 | 2018-01-24 19:14:32 +0100 | [diff] [blame] | 57 | Thrift.Collections; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 58 | |
| 59 | type |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 60 | TClientThread = class; |
| 61 | |
| 62 | TThreadConsole = class(TThriftConsole) |
| 63 | strict private |
| 64 | FThread : TClientThread; |
| 65 | FLogThreadID : Boolean; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 66 | public |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 67 | constructor Create( const aThread: TClientThread; const aLogThreadID : Boolean); |
| 68 | |
| 69 | procedure Write( const S: string); override; |
| 70 | procedure WriteLine( const S: string); override; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 71 | end; |
| 72 | |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 73 | TTestSetup = record |
| 74 | protType : TKnownProtocol; |
| 75 | endpoint : TEndpointTransport; |
| 76 | layered : TLayeredTransports; |
| 77 | useSSL : Boolean; // include where appropriate (TLayeredTransport?) |
| 78 | host : string; |
| 79 | port : Integer; |
| 80 | sPipeName : string; |
| 81 | hAnonRead, hAnonWrite : THandle; |
| 82 | end; |
| 83 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 84 | TClientThread = class( TThread ) |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 85 | private type |
| 86 | TTestGroup = ( |
| 87 | test_Unknown, |
| 88 | test_BaseTypes, |
| 89 | test_Structs, |
| 90 | test_Containers, |
| 91 | test_Exceptions |
| 92 | // new values here |
| 93 | ); |
| 94 | TTestGroups = set of TTestGroup; |
| 95 | |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 96 | TTestSize = ( |
| 97 | Empty, // Edge case: the zero-length empty binary |
| 98 | Normal, // Fairly small array of usual size (256 bytes) |
| 99 | ByteArrayTest, // THRIFT-4454 Large writes/reads may cause range check errors in debug mode |
Jens Geyer | bd1a273 | 2019-06-26 22:52:44 +0200 | [diff] [blame] | 100 | PipeWriteLimit, // THRIFT-4372 Pipe write operations across a network are limited to 65,535 bytes per write. |
Jens Geyer | 2646bd6 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 101 | FifteenMB // quite a bit of data, but still below the default max frame size |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 102 | ); |
| 103 | |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 104 | strict private |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 105 | FSetup : TTestSetup; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 106 | FTransport : ITransport; |
| 107 | FProtocol : IProtocol; |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 108 | FNumIterations : Integer; |
| 109 | |
| 110 | FThreadNo : Integer; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 111 | FConsole : TThreadConsole; |
| 112 | |
| 113 | // test reporting, will be refactored out into separate class later |
| 114 | FTestGroup : string; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 115 | FCurrentTest : TTestGroup; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 116 | FSuccesses : Integer; |
| 117 | FErrors : TStringList; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 118 | FFailed : TTestGroups; |
| 119 | FExecuted : TTestGroups; |
| 120 | procedure StartTestGroup( const aGroup : string; const aTest : TTestGroup); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 121 | procedure Expect( aTestResult : Boolean; const aTestInfo : string); |
| 122 | procedure ReportResults; |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 123 | function CalculateExitCode : Byte; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 124 | |
| 125 | procedure ClientTest; |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 126 | {$IFDEF SupportsAsync} |
| 127 | procedure ClientAsyncTest; |
| 128 | {$ENDIF} |
| 129 | |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 130 | procedure InitializeProtocolTransportStack; |
| 131 | procedure ShutdownProtocolTransportStack; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 132 | function InitializeHttpTransport( const aTimeoutSetting : Integer; const aConfig : IThriftConfiguration = nil) : IHTTPClient; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 133 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 134 | procedure JSONProtocolReadWriteTest; |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 135 | function PrepareBinaryData( aRandomDist : Boolean; aSize : TTestSize) : TBytes; |
Jens Geyer | 718f6ee | 2013-09-06 21:02:34 +0200 | [diff] [blame] | 136 | {$IFDEF StressTest} |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 137 | procedure StressTest(const client : TThriftTest.Iface); |
Jens Geyer | 718f6ee | 2013-09-06 21:02:34 +0200 | [diff] [blame] | 138 | {$ENDIF} |
Jens Geyer | f790445 | 2017-07-26 15:02:12 +0200 | [diff] [blame] | 139 | {$IFDEF Win64} |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 140 | procedure UseInterlockedExchangeAdd64; |
Jens Geyer | f790445 | 2017-07-26 15:02:12 +0200 | [diff] [blame] | 141 | {$ENDIF} |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 142 | |
| 143 | strict protected |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 144 | procedure Execute; override; |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 145 | property Console : TThreadConsole read FConsole; |
| 146 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 147 | public |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 148 | constructor Create( const aSetup : TTestSetup; const aNumIteration, aThreadNo: Integer; const aLogThreadID : Boolean); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 149 | destructor Destroy; override; |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 150 | |
| 151 | property ThreadNo : Integer read FThreadNo; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 152 | end; |
| 153 | |
| 154 | TTestClient = class |
| 155 | private |
| 156 | class var |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 157 | FNumIterations : Integer; |
| 158 | FNumThreads : Integer; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 159 | |
| 160 | class procedure PrintCmdLineHelp; |
| 161 | class procedure InvalidArgs; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 162 | public |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 163 | class function Execute( const arguments: array of string) : Byte; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 164 | end; |
| 165 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 166 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 167 | implementation |
| 168 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 169 | const |
| 170 | EXITCODE_SUCCESS = $00; // no errors bits set |
| 171 | // |
| 172 | EXITCODE_FAILBIT_BASETYPES = $01; |
| 173 | EXITCODE_FAILBIT_STRUCTS = $02; |
| 174 | EXITCODE_FAILBIT_CONTAINERS = $04; |
| 175 | EXITCODE_FAILBIT_EXCEPTIONS = $08; |
| 176 | |
| 177 | MAP_FAILURES_TO_EXITCODE_BITS : array[TClientThread.TTestGroup] of Byte = ( |
| 178 | EXITCODE_SUCCESS, // no bits here |
| 179 | EXITCODE_FAILBIT_BASETYPES, |
| 180 | EXITCODE_FAILBIT_STRUCTS, |
| 181 | EXITCODE_FAILBIT_CONTAINERS, |
| 182 | EXITCODE_FAILBIT_EXCEPTIONS |
| 183 | ); |
| 184 | |
| 185 | |
| 186 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 187 | function BoolToString( b : Boolean) : string; |
| 188 | // overrides global BoolToString() |
| 189 | begin |
| 190 | if b |
| 191 | then result := 'true' |
| 192 | else result := 'false'; |
| 193 | end; |
| 194 | |
| 195 | // not available in all versions, so make sure we have this one imported |
| 196 | function IsDebuggerPresent: BOOL; stdcall; external KERNEL32 name 'IsDebuggerPresent'; |
| 197 | |
| 198 | { TTestClient } |
| 199 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 200 | class procedure TTestClient.PrintCmdLineHelp; |
| 201 | const HELPTEXT = ' [options]'#10 |
| 202 | + #10 |
| 203 | + 'Allowed options:'#10 |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 204 | + ' -h | --help Produces this help message'#10 |
| 205 | + ' --host=arg (localhost) Host to connect'#10 |
| 206 | + ' --port=arg (9090) Port number to connect'#10 |
| 207 | + ' --pipe=arg Windows Named Pipe (e.g. MyThriftPipe)'#10 |
| 208 | + ' --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles)'#10 |
| 209 | + ' --transport=arg (sockets) Transport: buffered, framed, http, winhttp'#10 |
| 210 | + ' --protocol=arg (binary) Protocol: binary, compact, json'#10 |
| 211 | + ' --ssl Encrypted Transport using SSL'#10 |
| 212 | + ' -n=num | --testloops=num (1) Number of Tests'#10 |
| 213 | + ' -t=num | --threads=num (1) Number of Test threads'#10 |
| 214 | + ' --performance Run the built-in performance test (no other arguments)'#10 |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 215 | ; |
| 216 | begin |
| 217 | Writeln( ChangeFileExt(ExtractFileName(ParamStr(0)),'') + HELPTEXT); |
| 218 | end; |
| 219 | |
| 220 | class procedure TTestClient.InvalidArgs; |
| 221 | begin |
| 222 | Console.WriteLine( 'Invalid args.'); |
| 223 | Console.WriteLine( ChangeFileExt(ExtractFileName(ParamStr(0)),'') + ' -h for more information'); |
| 224 | Abort; |
| 225 | end; |
| 226 | |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 227 | class function TTestClient.Execute(const arguments: array of string) : Byte; |
| 228 | |
| 229 | function IsSwitch( const aArgument, aSwitch : string; out sValue : string) : Boolean; |
| 230 | begin |
| 231 | sValue := ''; |
| 232 | result := (Copy( aArgument, 1, Length(aSwitch)) = aSwitch); |
| 233 | if result then begin |
| 234 | if (Copy( aArgument, 1, Length(aSwitch)+1) = (aSwitch+'=')) |
| 235 | then sValue := Copy( aArgument, Length(aSwitch)+2, MAXINT); |
| 236 | end; |
| 237 | end; |
| 238 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 239 | var |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 240 | iArg : Integer; |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 241 | threadExitCode : Byte; |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 242 | sArg, sValue : string; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 243 | threads : array of TThread; |
| 244 | dtStart : TDateTime; |
| 245 | test : Integer; |
| 246 | thread : TThread; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 247 | setup : TTestSetup; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 248 | begin |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 249 | // init record |
| 250 | with setup do begin |
| 251 | protType := prot_Binary; |
| 252 | endpoint := trns_Sockets; |
| 253 | layered := []; |
| 254 | useSSL := FALSE; |
| 255 | host := 'localhost'; |
| 256 | port := 9090; |
| 257 | sPipeName := ''; |
| 258 | hAnonRead := INVALID_HANDLE_VALUE; |
| 259 | hAnonWrite := INVALID_HANDLE_VALUE; |
| 260 | end; |
| 261 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 262 | try |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 263 | iArg := 0; |
| 264 | while iArg < Length(arguments) do begin |
| 265 | sArg := arguments[iArg]; |
| 266 | Inc(iArg); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 267 | |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 268 | if IsSwitch( sArg, '-h', sValue) |
| 269 | or IsSwitch( sArg, '--help', sValue) |
| 270 | then begin |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 271 | // -h [ --help ] produce help message |
| 272 | PrintCmdLineHelp; |
| 273 | result := $FF; // all tests failed |
| 274 | Exit; |
| 275 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 276 | else if IsSwitch( sArg, '--host', sValue) then begin |
Jens Geyer | b360b65 | 2014-09-28 01:55:46 +0200 | [diff] [blame] | 277 | // --host arg (=localhost) Host to connect |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 278 | setup.host := sValue; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 279 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 280 | else if IsSwitch( sArg, '--port', sValue) then begin |
Jens Geyer | b360b65 | 2014-09-28 01:55:46 +0200 | [diff] [blame] | 281 | // --port arg (=9090) Port number to connect |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 282 | setup.port := StrToIntDef(sValue,0); |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 283 | if setup.port <= 0 then InvalidArgs; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 284 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 285 | else if IsSwitch( sArg, '--domain-socket', sValue) then begin |
Jens Geyer | b360b65 | 2014-09-28 01:55:46 +0200 | [diff] [blame] | 286 | // --domain-socket arg Domain Socket (e.g. /tmp/ThriftTest.thrift), instead of host and port |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 287 | raise Exception.Create('domain-socket not supported'); |
| 288 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 289 | // --pipe arg Windows Named Pipe (e.g. MyThriftPipe) |
| 290 | else if IsSwitch( sArg, '--pipe', sValue) then begin |
Jens Geyer | 4a33b18 | 2020-03-22 13:46:34 +0100 | [diff] [blame] | 291 | // --pipe arg Windows Named Pipe (e.g. MyThriftPipe) |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 292 | setup.endpoint := trns_NamedPipes; |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 293 | setup.sPipeName := sValue; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 294 | Console.WriteLine('Using named pipe ('+setup.sPipeName+')'); |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 295 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 296 | else if IsSwitch( sArg, '--anon-pipes', sValue) then begin |
Jens Geyer | b360b65 | 2014-09-28 01:55:46 +0200 | [diff] [blame] | 297 | // --anon-pipes hRead hWrite Windows Anonymous Pipes pair (handles) |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 298 | setup.endpoint := trns_AnonPipes; |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 299 | setup.hAnonRead := THandle( StrToIntDef( arguments[iArg], Integer(INVALID_HANDLE_VALUE))); |
| 300 | Inc(iArg); |
| 301 | setup.hAnonWrite := THandle( StrToIntDef( arguments[iArg], Integer(INVALID_HANDLE_VALUE))); |
| 302 | Inc(iArg); |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 303 | Console.WriteLine('Using anonymous pipes ('+IntToStr(Integer(setup.hAnonRead))+' and '+IntToStr(Integer(setup.hAnonWrite))+')'); |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 304 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 305 | else if IsSwitch( sArg, '--transport', sValue) then begin |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 306 | // --transport arg (=sockets) Transport: buffered, framed, http, winhttp, evhttp |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 307 | if sValue = 'buffered' then Include( setup.layered, trns_Buffered) |
| 308 | else if sValue = 'framed' then Include( setup.layered, trns_Framed) |
| 309 | else if sValue = 'http' then setup.endpoint := trns_MsXmlHttp |
| 310 | else if sValue = 'winhttp' then setup.endpoint := trns_WinHttp |
| 311 | else if sValue = 'evhttp' then setup.endpoint := trns_EvHttp // recognized, but not supported |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 312 | else InvalidArgs; |
| 313 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 314 | else if IsSwitch( sArg, '--protocol', sValue) then begin |
Jens Geyer | b360b65 | 2014-09-28 01:55:46 +0200 | [diff] [blame] | 315 | // --protocol arg (=binary) Protocol: binary, compact, json |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 316 | if sValue = 'binary' then setup.protType := prot_Binary |
| 317 | else if sValue = 'compact' then setup.protType := prot_Compact |
| 318 | else if sValue = 'json' then setup.protType := prot_JSON |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 319 | else InvalidArgs; |
| 320 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 321 | else if IsSwitch( sArg, '--ssl', sValue) then begin |
Jens Geyer | b360b65 | 2014-09-28 01:55:46 +0200 | [diff] [blame] | 322 | // --ssl Encrypted Transport using SSL |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 323 | setup.useSSL := TRUE; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 324 | |
| 325 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 326 | else if IsSwitch( sArg, '-n', sValue) or IsSwitch( sArg, '--testloops', sValue) then begin |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 327 | // -n [ --testloops ] arg (=1) Number of Tests |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 328 | FNumIterations := StrToIntDef( sValue, 0); |
| 329 | if FNumIterations <= 0 |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 330 | then InvalidArgs; |
| 331 | |
| 332 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 333 | else if IsSwitch( sArg, '-t', sValue) or IsSwitch( sArg, '--threads', sValue) then begin |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 334 | // -t [ --threads ] arg (=1) Number of Test threads |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 335 | FNumThreads := StrToIntDef( sValue, 0); |
| 336 | if FNumThreads <= 0 |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 337 | then InvalidArgs; |
| 338 | end |
Jens Geyer | aeda987 | 2020-03-22 15:01:28 +0100 | [diff] [blame] | 339 | else if IsSwitch( sArg, '--performance', sValue) then begin |
Jens Geyer | b342bd9 | 2019-06-03 20:27:00 +0200 | [diff] [blame] | 340 | result := TPerformanceTests.Execute; |
| 341 | Exit; |
| 342 | end |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 343 | else begin |
| 344 | InvalidArgs; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 345 | end; |
| 346 | end; |
| 347 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 348 | |
Roger Meier | 79655fb | 2012-10-20 20:59:41 +0000 | [diff] [blame] | 349 | // In the anonymous pipes mode the client is launched by the test server |
| 350 | // -> behave nicely and allow for attaching a debugger to this process |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 351 | if (setup.endpoint = trns_AnonPipes) and not IsDebuggerPresent |
Roger Meier | 79655fb | 2012-10-20 20:59:41 +0000 | [diff] [blame] | 352 | then MessageBox( 0, 'Attach Debugger and/or click OK to continue.', |
| 353 | 'Thrift TestClient (Delphi)', |
| 354 | MB_OK or MB_ICONEXCLAMATION); |
| 355 | |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 356 | SetLength( threads, FNumThreads); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 357 | dtStart := Now; |
| 358 | |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 359 | // layered transports are not really meant to be stacked upon each other |
| 360 | if (trns_Framed in setup.layered) then begin |
| 361 | Console.WriteLine('Using framed transport'); |
| 362 | end |
| 363 | else if (trns_Buffered in setup.layered) then begin |
| 364 | Console.WriteLine('Using buffered transport'); |
| 365 | end; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 366 | |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 367 | Console.WriteLine(THRIFT_PROTOCOLS[setup.protType]+' protocol'); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 368 | |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 369 | if FNumThreads <> 1 |
| 370 | then Console.WriteLine(IntToStr(FNumThreads)+' client threads'); |
| 371 | |
| 372 | if FNumIterations <> 1 |
| 373 | then Console.WriteLine(IntToStr(FNumIterations)+' iterations'); |
| 374 | |
| 375 | for test := 0 to FNumThreads - 1 do begin |
| 376 | thread := TClientThread.Create( setup, FNumIterations, test, FNumThreads<>1); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 377 | threads[test] := thread; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 378 | thread.Start; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 379 | end; |
| 380 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 381 | result := 0; |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 382 | for test := 0 to FNumThreads - 1 do begin |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 383 | threadExitCode := threads[test].WaitFor; |
| 384 | result := result or threadExitCode; |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 385 | threads[test].Free; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 386 | threads[test] := nil; |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 387 | end; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 388 | |
| 389 | Console.Write('Total time: ' + IntToStr( MilliSecondsBetween(Now, dtStart))); |
| 390 | |
| 391 | except |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 392 | on E: EAbort do raise; |
| 393 | on E: Exception do begin |
| 394 | Console.WriteLine( E.Message + #10 + E.StackTrace); |
| 395 | raise; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 396 | end; |
| 397 | end; |
| 398 | |
| 399 | Console.WriteLine(''); |
| 400 | Console.WriteLine('done!'); |
| 401 | end; |
| 402 | |
| 403 | { TClientThread } |
| 404 | |
| 405 | procedure TClientThread.ClientTest; |
| 406 | var |
| 407 | client : TThriftTest.Iface; |
| 408 | s : string; |
| 409 | i8 : ShortInt; |
| 410 | i32 : Integer; |
| 411 | i64 : Int64; |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 412 | binOut,binIn : TBytes; |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 413 | guidIn, guidOut : TGuid; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 414 | dub : Double; |
| 415 | o : IXtruct; |
| 416 | o2 : IXtruct2; |
| 417 | i : IXtruct; |
| 418 | i2 : IXtruct2; |
| 419 | mapout : IThriftDictionary<Integer,Integer>; |
| 420 | mapin : IThriftDictionary<Integer,Integer>; |
| 421 | strmapout : IThriftDictionary<string,string>; |
| 422 | strmapin : IThriftDictionary<string,string>; |
| 423 | j : Integer; |
| 424 | first : Boolean; |
| 425 | key : Integer; |
| 426 | strkey : string; |
| 427 | listout : IThriftList<Integer>; |
| 428 | listin : IThriftList<Integer>; |
Jens Geyer | 6a797b9 | 2022-09-05 13:55:37 +0200 | [diff] [blame] | 429 | setout : IThriftHashSet<Integer>; |
| 430 | setin : IThriftHashSet<Integer>; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 431 | ret : TNumberz; |
| 432 | uid : Int64; |
| 433 | mm : IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>; |
| 434 | pos : IThriftDictionary<Integer, Integer>; |
| 435 | neg : IThriftDictionary<Integer, Integer>; |
| 436 | m2 : IThriftDictionary<Integer, Integer>; |
| 437 | k2 : Integer; |
| 438 | insane : IInsanity; |
| 439 | truck : IXtruct; |
| 440 | whoa : IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>; |
| 441 | key64 : Int64; |
| 442 | val : IThriftDictionary<TNumberz, IInsanity>; |
| 443 | k2_2 : TNumberz; |
| 444 | k3 : TNumberz; |
| 445 | v2 : IInsanity; |
| 446 | userMap : IThriftDictionary<TNumberz, Int64>; |
| 447 | xtructs : IThriftList<IXtruct>; |
| 448 | x : IXtruct; |
| 449 | arg0 : ShortInt; |
| 450 | arg1 : Integer; |
| 451 | arg2 : Int64; |
| 452 | arg3 : IThriftDictionary<SmallInt, string>; |
| 453 | arg4 : TNumberz; |
| 454 | arg5 : Int64; |
Jens Geyer | 9f7f11e | 2016-04-14 21:37:11 +0200 | [diff] [blame] | 455 | {$IFDEF PerfTest} |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 456 | StartTick : Cardinal; |
| 457 | k : Integer; |
Jens Geyer | 9f7f11e | 2016-04-14 21:37:11 +0200 | [diff] [blame] | 458 | {$ENDIF} |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 459 | hello, goodbye : IXtruct; |
| 460 | crazy : IInsanity; |
| 461 | looney : IInsanity; |
| 462 | first_map : IThriftDictionary<TNumberz, IInsanity>; |
| 463 | second_map : IThriftDictionary<TNumberz, IInsanity>; |
Jens Geyer | 540e346 | 2016-12-28 14:25:41 +0100 | [diff] [blame] | 464 | pair : TPair<TNumberz, TUserId>; |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 465 | testsize : TTestSize; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 466 | begin |
| 467 | client := TThriftTest.TClient.Create( FProtocol); |
| 468 | FTransport.Open; |
| 469 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 470 | {$IFDEF StressTest} |
| 471 | StressTest( client); |
| 472 | {$ENDIF StressTest} |
| 473 | |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 474 | {$IFDEF Exceptions} |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 475 | // in-depth exception test |
| 476 | // (1) do we get an exception at all? |
| 477 | // (2) do we get the right exception? |
| 478 | // (3) does the exception contain the expected data? |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 479 | StartTestGroup( 'testException', test_Exceptions); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 480 | // case 1: exception type declared in IDL at the function call |
| 481 | try |
| 482 | client.testException('Xception'); |
| 483 | Expect( FALSE, 'testException(''Xception''): must trow an exception'); |
| 484 | except |
| 485 | on e:TXception do begin |
| 486 | Expect( e.ErrorCode = 1001, 'error code'); |
| 487 | Expect( e.Message_ = 'Xception', 'error message'); |
| 488 | Console.WriteLine( ' = ' + IntToStr(e.ErrorCode) + ', ' + e.Message_ ); |
| 489 | end; |
| 490 | on e:TTransportException do Expect( FALSE, 'Unexpected : "'+e.ToString+'"'); |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 491 | on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'": '+e.Message); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 492 | end; |
| 493 | |
Jens Geyer | cc8c2c6 | 2021-03-29 22:38:30 +0200 | [diff] [blame] | 494 | // re-open connection if needed |
| 495 | if not FTransport.IsOpen |
| 496 | then FTransport.Open; |
| 497 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 498 | // case 2: exception type NOT declared in IDL at the function call |
| 499 | // this will close the connection |
| 500 | try |
| 501 | client.testException('TException'); |
| 502 | Expect( FALSE, 'testException(''TException''): must trow an exception'); |
| 503 | except |
| 504 | on e:TTransportException do begin |
| 505 | Console.WriteLine( e.ClassName+' = '+e.Message); // this is what we get |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 506 | end; |
Jens Geyer | 6bbbf19 | 2014-09-07 01:45:56 +0200 | [diff] [blame] | 507 | on e:TApplicationException do begin |
| 508 | Console.WriteLine( e.ClassName+' = '+e.Message); // this is what we get |
Jens Geyer | 6bbbf19 | 2014-09-07 01:45:56 +0200 | [diff] [blame] | 509 | end; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 510 | on e:TException do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'": '+e.Message); |
| 511 | on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'": '+e.Message); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 512 | end; |
| 513 | |
Jens Geyer | 6f6aa8a | 2016-03-10 19:47:12 +0100 | [diff] [blame] | 514 | |
Jens Geyer | 2ad6c30 | 2015-02-26 19:38:53 +0100 | [diff] [blame] | 515 | if FTransport.IsOpen then FTransport.Close; |
| 516 | FTransport.Open; // re-open connection, server has already closed |
Jens Geyer | 6f6aa8a | 2016-03-10 19:47:12 +0100 | [diff] [blame] | 517 | |
Jens Geyer | 2ad6c30 | 2015-02-26 19:38:53 +0100 | [diff] [blame] | 518 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 519 | // case 3: no exception |
| 520 | try |
| 521 | client.testException('something'); |
| 522 | Expect( TRUE, 'testException(''something''): must not trow an exception'); |
| 523 | except |
| 524 | on e:TTransportException do Expect( FALSE, 'Unexpected : "'+e.ToString+'"'); |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 525 | on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'": '+e.Message); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 526 | end; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 527 | {$ENDIF Exceptions} |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 528 | |
Jens Geyer | cc8c2c6 | 2021-03-29 22:38:30 +0200 | [diff] [blame] | 529 | // re-open connection if needed |
| 530 | if not FTransport.IsOpen |
| 531 | then FTransport.Open; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 532 | |
| 533 | // simple things |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 534 | StartTestGroup( 'simple Thrift calls', test_BaseTypes); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 535 | client.testVoid(); |
| 536 | Expect( TRUE, 'testVoid()'); // success := no exception |
| 537 | |
Jens Geyer | 39ba6b7 | 2015-09-22 00:00:49 +0200 | [diff] [blame] | 538 | s := BoolToString( client.testBool(TRUE)); |
| 539 | Expect( s = BoolToString(TRUE), 'testBool(TRUE) = '+s); |
| 540 | s := BoolToString( client.testBool(FALSE)); |
| 541 | Expect( s = BoolToString(FALSE), 'testBool(FALSE) = '+s); |
| 542 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 543 | s := client.testString('Test'); |
| 544 | Expect( s = 'Test', 'testString(''Test'') = "'+s+'"'); |
| 545 | |
Jens Geyer | cf892d4 | 2017-09-09 10:08:22 +0200 | [diff] [blame] | 546 | s := client.testString(''); // empty string |
| 547 | Expect( s = '', 'testString('''') = "'+s+'"'); |
| 548 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 549 | s := client.testString(HUGE_TEST_STRING); |
| 550 | Expect( length(s) = length(HUGE_TEST_STRING), |
Konrad Grochowski | 3b5dacb | 2014-11-24 10:55:31 +0100 | [diff] [blame] | 551 | 'testString( length(HUGE_TEST_STRING) = '+IntToStr(Length(HUGE_TEST_STRING))+') ' |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 552 | +'=> length(result) = '+IntToStr(Length(s))); |
| 553 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 554 | i8 := client.testByte(1); |
| 555 | Expect( i8 = 1, 'testByte(1) = ' + IntToStr( i8 )); |
| 556 | |
| 557 | i32 := client.testI32(-1); |
| 558 | Expect( i32 = -1, 'testI32(-1) = ' + IntToStr(i32)); |
| 559 | |
| 560 | Console.WriteLine('testI64(-34359738368)'); |
| 561 | i64 := client.testI64(-34359738368); |
| 562 | Expect( i64 = -34359738368, 'testI64(-34359738368) = ' + IntToStr( i64)); |
| 563 | |
Jens Geyer | 62445c1 | 2022-06-29 00:00:00 +0200 | [diff] [blame] | 564 | guidOut := StringToGUID('{00112233-4455-6677-8899-AABBCCDDEEFF}'); |
| 565 | Console.WriteLine('testUuid('+GUIDToString(guidOut)+')'); |
| 566 | try |
| 567 | guidIn := client.testUuid(guidOut); |
| 568 | Expect( IsEqualGUID(guidIn, guidOut), 'testUuid('+GUIDToString(guidOut)+') = '+GUIDToString(guidIn)); |
| 569 | except |
| 570 | on e:TApplicationException do Console.WriteLine('testUuid(): '+e.Message); |
| 571 | on e:Exception do Expect( FALSE, 'testUuid(): Unexpected exception "'+e.ClassName+'": '+e.Message); |
| 572 | end; |
| 573 | |
Jens Geyer | d4df917 | 2017-10-25 22:30:23 +0200 | [diff] [blame] | 574 | // random binary small |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 575 | for testsize := Low(TTestSize) to High(TTestSize) do begin |
| 576 | binOut := PrepareBinaryData( TRUE, testsize); |
Jens Geyer | bd1a273 | 2019-06-26 22:52:44 +0200 | [diff] [blame] | 577 | Console.WriteLine('testBinary('+IntToStr(Length(binOut))+' bytes)'); |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 578 | try |
| 579 | binIn := client.testBinary(binOut); |
Jens Geyer | bd1a273 | 2019-06-26 22:52:44 +0200 | [diff] [blame] | 580 | Expect( Length(binOut) = Length(binIn), 'testBinary('+IntToStr(Length(binOut))+' bytes): '+IntToStr(Length(binIn))+' bytes received'); |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 581 | i32 := Min( Length(binOut), Length(binIn)); |
Jens Geyer | bd1a273 | 2019-06-26 22:52:44 +0200 | [diff] [blame] | 582 | Expect( CompareMem( binOut, binIn, i32), 'testBinary('+IntToStr(Length(binOut))+' bytes): validating received data'); |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 583 | except |
| 584 | on e:TApplicationException do Console.WriteLine('testBinary(): '+e.Message); |
| 585 | on e:Exception do Expect( FALSE, 'testBinary(): Unexpected exception "'+e.ClassName+'": '+e.Message); |
| 586 | end; |
Jens Geyer | cf892d4 | 2017-09-09 10:08:22 +0200 | [diff] [blame] | 587 | end; |
| 588 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 589 | Console.WriteLine('testDouble(5.325098235)'); |
| 590 | dub := client.testDouble(5.325098235); |
| 591 | Expect( abs(dub-5.325098235) < 1e-14, 'testDouble(5.325098235) = ' + FloatToStr( dub)); |
| 592 | |
| 593 | // structs |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 594 | StartTestGroup( 'testStruct', test_Structs); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 595 | Console.WriteLine('testStruct({''Zero'', 1, -3, -5})'); |
| 596 | o := TXtructImpl.Create; |
| 597 | o.String_thing := 'Zero'; |
| 598 | o.Byte_thing := 1; |
| 599 | o.I32_thing := -3; |
| 600 | o.I64_thing := -5; |
| 601 | i := client.testStruct(o); |
| 602 | Expect( i.String_thing = 'Zero', 'i.String_thing = "'+i.String_thing+'"'); |
| 603 | Expect( i.Byte_thing = 1, 'i.Byte_thing = '+IntToStr(i.Byte_thing)); |
| 604 | Expect( i.I32_thing = -3, 'i.I32_thing = '+IntToStr(i.I32_thing)); |
| 605 | Expect( i.I64_thing = -5, 'i.I64_thing = '+IntToStr(i.I64_thing)); |
| 606 | Expect( i.__isset_String_thing, 'i.__isset_String_thing = '+BoolToString(i.__isset_String_thing)); |
| 607 | Expect( i.__isset_Byte_thing, 'i.__isset_Byte_thing = '+BoolToString(i.__isset_Byte_thing)); |
| 608 | Expect( i.__isset_I32_thing, 'i.__isset_I32_thing = '+BoolToString(i.__isset_I32_thing)); |
| 609 | Expect( i.__isset_I64_thing, 'i.__isset_I64_thing = '+BoolToString(i.__isset_I64_thing)); |
| 610 | |
| 611 | // nested structs |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 612 | StartTestGroup( 'testNest', test_Structs); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 613 | Console.WriteLine('testNest({1, {''Zero'', 1, -3, -5}, 5})'); |
| 614 | o2 := TXtruct2Impl.Create; |
| 615 | o2.Byte_thing := 1; |
| 616 | o2.Struct_thing := o; |
| 617 | o2.I32_thing := 5; |
| 618 | i2 := client.testNest(o2); |
| 619 | i := i2.Struct_thing; |
| 620 | Expect( i.String_thing = 'Zero', 'i.String_thing = "'+i.String_thing+'"'); |
| 621 | Expect( i.Byte_thing = 1, 'i.Byte_thing = '+IntToStr(i.Byte_thing)); |
| 622 | Expect( i.I32_thing = -3, 'i.I32_thing = '+IntToStr(i.I32_thing)); |
| 623 | Expect( i.I64_thing = -5, 'i.I64_thing = '+IntToStr(i.I64_thing)); |
| 624 | Expect( i2.Byte_thing = 1, 'i2.Byte_thing = '+IntToStr(i2.Byte_thing)); |
| 625 | Expect( i2.I32_thing = 5, 'i2.I32_thing = '+IntToStr(i2.I32_thing)); |
| 626 | Expect( i.__isset_String_thing, 'i.__isset_String_thing = '+BoolToString(i.__isset_String_thing)); |
| 627 | Expect( i.__isset_Byte_thing, 'i.__isset_Byte_thing = '+BoolToString(i.__isset_Byte_thing)); |
| 628 | Expect( i.__isset_I32_thing, 'i.__isset_I32_thing = '+BoolToString(i.__isset_I32_thing)); |
| 629 | Expect( i.__isset_I64_thing, 'i.__isset_I64_thing = '+BoolToString(i.__isset_I64_thing)); |
| 630 | Expect( i2.__isset_Byte_thing, 'i2.__isset_Byte_thing'); |
| 631 | Expect( i2.__isset_I32_thing, 'i2.__isset_I32_thing'); |
| 632 | |
| 633 | // map<type1,type2>: A map of strictly unique keys to values. |
| 634 | // Translates to an STL map, Java HashMap, PHP associative array, Python/Ruby dictionary, etc. |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 635 | StartTestGroup( 'testMap', test_Containers); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 636 | mapout := TThriftDictionaryImpl<Integer,Integer>.Create; |
| 637 | for j := 0 to 4 do |
| 638 | begin |
| 639 | mapout.AddOrSetValue( j, j - 10); |
| 640 | end; |
| 641 | Console.Write('testMap({'); |
| 642 | first := True; |
| 643 | for key in mapout.Keys do |
| 644 | begin |
| 645 | if first |
| 646 | then first := False |
| 647 | else Console.Write( ', ' ); |
| 648 | Console.Write( IntToStr( key) + ' => ' + IntToStr( mapout[key])); |
| 649 | end; |
| 650 | Console.WriteLine('})'); |
| 651 | |
| 652 | mapin := client.testMap( mapout ); |
| 653 | Expect( mapin.Count = mapout.Count, 'testMap: mapin.Count = mapout.Count'); |
| 654 | for j := 0 to 4 do |
| 655 | begin |
| 656 | Expect( mapout.ContainsKey(j), 'testMap: mapout.ContainsKey('+IntToStr(j)+') = '+BoolToString(mapout.ContainsKey(j))); |
| 657 | end; |
| 658 | for key in mapin.Keys do |
| 659 | begin |
| 660 | Expect( mapin[key] = mapout[key], 'testMap: '+IntToStr(key) + ' => ' + IntToStr( mapin[key])); |
| 661 | Expect( mapin[key] = key - 10, 'testMap: mapin['+IntToStr(key)+'] = '+IntToStr( mapin[key])); |
| 662 | end; |
| 663 | |
| 664 | |
| 665 | // map<type1,type2>: A map of strictly unique keys to values. |
| 666 | // Translates to an STL map, Java HashMap, PHP associative array, Python/Ruby dictionary, etc. |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 667 | StartTestGroup( 'testStringMap', test_Containers); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 668 | strmapout := TThriftDictionaryImpl<string,string>.Create; |
| 669 | for j := 0 to 4 do |
| 670 | begin |
| 671 | strmapout.AddOrSetValue( IntToStr(j), IntToStr(j - 10)); |
| 672 | end; |
| 673 | Console.Write('testStringMap({'); |
| 674 | first := True; |
| 675 | for strkey in strmapout.Keys do |
| 676 | begin |
| 677 | if first |
| 678 | then first := False |
| 679 | else Console.Write( ', ' ); |
| 680 | Console.Write( strkey + ' => ' + strmapout[strkey]); |
| 681 | end; |
| 682 | Console.WriteLine('})'); |
| 683 | |
| 684 | strmapin := client.testStringMap( strmapout ); |
| 685 | Expect( strmapin.Count = strmapout.Count, 'testStringMap: strmapin.Count = strmapout.Count'); |
| 686 | for j := 0 to 4 do |
| 687 | begin |
| 688 | Expect( strmapout.ContainsKey(IntToStr(j)), |
| 689 | 'testStringMap: strmapout.ContainsKey('+IntToStr(j)+') = ' |
| 690 | + BoolToString(strmapout.ContainsKey(IntToStr(j)))); |
| 691 | end; |
| 692 | for strkey in strmapin.Keys do |
| 693 | begin |
| 694 | Expect( strmapin[strkey] = strmapout[strkey], 'testStringMap: '+strkey + ' => ' + strmapin[strkey]); |
| 695 | Expect( strmapin[strkey] = IntToStr( StrToInt(strkey) - 10), 'testStringMap: strmapin['+strkey+'] = '+strmapin[strkey]); |
| 696 | end; |
| 697 | |
| 698 | |
| 699 | // set<type>: An unordered set of unique elements. |
| 700 | // Translates to an STL set, Java HashSet, set in Python, etc. |
| 701 | // Note: PHP does not support sets, so it is treated similar to a List |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 702 | StartTestGroup( 'testSet', test_Containers); |
Jens Geyer | 6a797b9 | 2022-09-05 13:55:37 +0200 | [diff] [blame] | 703 | setout := TThriftHashSetImpl<Integer>.Create; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 704 | for j := -2 to 2 do |
| 705 | begin |
| 706 | setout.Add( j ); |
| 707 | end; |
| 708 | Console.Write('testSet({'); |
| 709 | first := True; |
| 710 | for j in setout do |
| 711 | begin |
| 712 | if first |
| 713 | then first := False |
| 714 | else Console.Write(', '); |
| 715 | Console.Write(IntToStr( j)); |
| 716 | end; |
| 717 | Console.WriteLine('})'); |
| 718 | |
| 719 | setin := client.testSet(setout); |
| 720 | Expect( setin.Count = setout.Count, 'testSet: setin.Count = setout.Count'); |
| 721 | Expect( setin.Count = 5, 'testSet: setin.Count = '+IntToStr(setin.Count)); |
| 722 | for j := -2 to 2 do // unordered, we can't rely on the order => test for known elements only |
| 723 | begin |
| 724 | Expect( setin.Contains(j), 'testSet: setin.Contains('+IntToStr(j)+') => '+BoolToString(setin.Contains(j))); |
| 725 | end; |
| 726 | |
| 727 | // list<type>: An ordered list of elements. |
| 728 | // Translates to an STL vector, Java ArrayList, native arrays in scripting languages, etc. |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 729 | StartTestGroup( 'testList', test_Containers); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 730 | listout := TThriftListImpl<Integer>.Create; |
| 731 | listout.Add( +1); |
| 732 | listout.Add( -2); |
| 733 | listout.Add( +3); |
| 734 | listout.Add( -4); |
| 735 | listout.Add( 0); |
| 736 | Console.Write('testList({'); |
| 737 | first := True; |
| 738 | for j in listout do |
| 739 | begin |
| 740 | if first |
| 741 | then first := False |
| 742 | else Console.Write(', '); |
| 743 | Console.Write(IntToStr( j)); |
| 744 | end; |
| 745 | Console.WriteLine('})'); |
| 746 | |
| 747 | listin := client.testList(listout); |
| 748 | Expect( listin.Count = listout.Count, 'testList: listin.Count = listout.Count'); |
| 749 | Expect( listin.Count = 5, 'testList: listin.Count = '+IntToStr(listin.Count)); |
| 750 | Expect( listin[0] = +1, 'listin[0] = '+IntToStr( listin[0])); |
| 751 | Expect( listin[1] = -2, 'listin[1] = '+IntToStr( listin[1])); |
| 752 | Expect( listin[2] = +3, 'listin[2] = '+IntToStr( listin[2])); |
| 753 | Expect( listin[3] = -4, 'listin[3] = '+IntToStr( listin[3])); |
| 754 | Expect( listin[4] = 0, 'listin[4] = '+IntToStr( listin[4])); |
| 755 | |
| 756 | // enums |
| 757 | ret := client.testEnum(TNumberz.ONE); |
| 758 | Expect( ret = TNumberz.ONE, 'testEnum(ONE) = '+IntToStr(Ord(ret))); |
| 759 | |
| 760 | ret := client.testEnum(TNumberz.TWO); |
| 761 | Expect( ret = TNumberz.TWO, 'testEnum(TWO) = '+IntToStr(Ord(ret))); |
| 762 | |
| 763 | ret := client.testEnum(TNumberz.THREE); |
| 764 | Expect( ret = TNumberz.THREE, 'testEnum(THREE) = '+IntToStr(Ord(ret))); |
| 765 | |
| 766 | ret := client.testEnum(TNumberz.FIVE); |
| 767 | Expect( ret = TNumberz.FIVE, 'testEnum(FIVE) = '+IntToStr(Ord(ret))); |
| 768 | |
| 769 | ret := client.testEnum(TNumberz.EIGHT); |
| 770 | Expect( ret = TNumberz.EIGHT, 'testEnum(EIGHT) = '+IntToStr(Ord(ret))); |
| 771 | |
| 772 | |
| 773 | // typedef |
| 774 | uid := client.testTypedef(309858235082523); |
| 775 | Expect( uid = 309858235082523, 'testTypedef(309858235082523) = '+IntToStr(uid)); |
| 776 | |
| 777 | |
| 778 | // maps of maps |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 779 | StartTestGroup( 'testMapMap(1)', test_Containers); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 780 | mm := client.testMapMap(1); |
| 781 | Console.Write(' = {'); |
| 782 | for key in mm.Keys do |
| 783 | begin |
| 784 | Console.Write( IntToStr( key) + ' => {'); |
| 785 | m2 := mm[key]; |
| 786 | for k2 in m2.Keys do |
| 787 | begin |
| 788 | Console.Write( IntToStr( k2) + ' => ' + IntToStr( m2[k2]) + ', '); |
| 789 | end; |
| 790 | Console.Write('}, '); |
| 791 | end; |
| 792 | Console.WriteLine('}'); |
| 793 | |
| 794 | // verify result data |
| 795 | Expect( mm.Count = 2, 'mm.Count = '+IntToStr(mm.Count)); |
| 796 | pos := mm[4]; |
| 797 | neg := mm[-4]; |
| 798 | for j := 1 to 4 do |
| 799 | begin |
| 800 | Expect( pos[j] = j, 'pos[j] = '+IntToStr(pos[j])); |
| 801 | Expect( neg[-j] = -j, 'neg[-j] = '+IntToStr(neg[-j])); |
| 802 | end; |
| 803 | |
| 804 | |
| 805 | |
| 806 | // insanity |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 807 | StartTestGroup( 'testInsanity', test_Structs); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 808 | insane := TInsanityImpl.Create; |
| 809 | insane.UserMap := TThriftDictionaryImpl<TNumberz, Int64>.Create; |
| 810 | insane.UserMap.AddOrSetValue( TNumberz.FIVE, 5000); |
| 811 | truck := TXtructImpl.Create; |
| 812 | truck.String_thing := 'Truck'; |
Jens Geyer | 540e346 | 2016-12-28 14:25:41 +0100 | [diff] [blame] | 813 | truck.Byte_thing := -8; // byte is signed |
| 814 | truck.I32_thing := 32; |
| 815 | truck.I64_thing := 64; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 816 | insane.Xtructs := TThriftListImpl<IXtruct>.Create; |
| 817 | insane.Xtructs.Add( truck ); |
| 818 | whoa := client.testInsanity( insane ); |
| 819 | Console.Write(' = {'); |
| 820 | for key64 in whoa.Keys do |
| 821 | begin |
| 822 | val := whoa[key64]; |
| 823 | Console.Write( IntToStr( key64) + ' => {'); |
| 824 | for k2_2 in val.Keys do |
| 825 | begin |
| 826 | v2 := val[k2_2]; |
| 827 | Console.Write( IntToStr( Integer( k2_2)) + ' => {'); |
| 828 | userMap := v2.UserMap; |
| 829 | Console.Write('{'); |
| 830 | if userMap <> nil then |
| 831 | begin |
| 832 | for k3 in userMap.Keys do |
| 833 | begin |
| 834 | Console.Write( IntToStr( Integer( k3)) + ' => ' + IntToStr( userMap[k3]) + ', '); |
| 835 | end; |
| 836 | end else |
| 837 | begin |
| 838 | Console.Write('null'); |
| 839 | end; |
| 840 | Console.Write('}, '); |
| 841 | xtructs := v2.Xtructs; |
| 842 | Console.Write('{'); |
| 843 | |
| 844 | if xtructs <> nil then |
| 845 | begin |
| 846 | for x in xtructs do |
| 847 | begin |
| 848 | Console.Write('{"' + x.String_thing + '", ' + |
| 849 | IntToStr( x.Byte_thing) + ', ' + |
| 850 | IntToStr( x.I32_thing) + ', ' + |
| 851 | IntToStr( x.I32_thing) + '}, '); |
| 852 | end; |
| 853 | end else |
| 854 | begin |
| 855 | Console.Write('null'); |
| 856 | end; |
| 857 | Console.Write('}'); |
| 858 | Console.Write('}, '); |
| 859 | end; |
| 860 | Console.Write('}, '); |
| 861 | end; |
| 862 | Console.WriteLine('}'); |
| 863 | |
Jens Geyer | 540e346 | 2016-12-28 14:25:41 +0100 | [diff] [blame] | 864 | (** |
| 865 | * So you think you've got this all worked, out eh? |
| 866 | * |
| 867 | * Creates a the returned map with these values and prints it out: |
| 868 | * { 1 => { 2 => argument, |
| 869 | * 3 => argument, |
| 870 | * }, |
| 871 | * 2 => { 6 => <empty Insanity struct>, }, |
| 872 | * } |
| 873 | * @return map<UserId, map<Numberz,Insanity>> - a map with the above values |
| 874 | *) |
| 875 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 876 | // verify result data |
| 877 | Expect( whoa.Count = 2, 'whoa.Count = '+IntToStr(whoa.Count)); |
| 878 | // |
| 879 | first_map := whoa[1]; |
| 880 | second_map := whoa[2]; |
| 881 | Expect( first_map.Count = 2, 'first_map.Count = '+IntToStr(first_map.Count)); |
| 882 | Expect( second_map.Count = 1, 'second_map.Count = '+IntToStr(second_map.Count)); |
| 883 | // |
| 884 | looney := second_map[TNumberz.SIX]; |
| 885 | Expect( Assigned(looney), 'Assigned(looney) = '+BoolToString(Assigned(looney))); |
| 886 | Expect( not looney.__isset_UserMap, 'looney.__isset_UserMap = '+BoolToString(looney.__isset_UserMap)); |
| 887 | Expect( not looney.__isset_Xtructs, 'looney.__isset_Xtructs = '+BoolToString(looney.__isset_Xtructs)); |
| 888 | // |
| 889 | for ret in [TNumberz.TWO, TNumberz.THREE] do begin |
| 890 | crazy := first_map[ret]; |
| 891 | Console.WriteLine('first_map['+intToStr(Ord(ret))+']'); |
| 892 | |
| 893 | Expect( crazy.__isset_UserMap, 'crazy.__isset_UserMap = '+BoolToString(crazy.__isset_UserMap)); |
| 894 | Expect( crazy.__isset_Xtructs, 'crazy.__isset_Xtructs = '+BoolToString(crazy.__isset_Xtructs)); |
| 895 | |
Jens Geyer | 540e346 | 2016-12-28 14:25:41 +0100 | [diff] [blame] | 896 | Expect( crazy.UserMap.Count = insane.UserMap.Count, 'crazy.UserMap.Count = '+IntToStr(crazy.UserMap.Count)); |
| 897 | for pair in insane.UserMap do begin |
| 898 | Expect( crazy.UserMap[pair.Key] = pair.Value, 'crazy.UserMap['+IntToStr(Ord(pair.key))+'] = '+IntToStr(crazy.UserMap[pair.Key])); |
| 899 | end; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 900 | |
Jens Geyer | 540e346 | 2016-12-28 14:25:41 +0100 | [diff] [blame] | 901 | Expect( crazy.Xtructs.Count = insane.Xtructs.Count, 'crazy.Xtructs.Count = '+IntToStr(crazy.Xtructs.Count)); |
| 902 | for arg0 := 0 to insane.Xtructs.Count-1 do begin |
| 903 | hello := insane.Xtructs[arg0]; |
| 904 | goodbye := crazy.Xtructs[arg0]; |
| 905 | Expect( goodbye.String_thing = hello.String_thing, 'goodbye.String_thing = '+goodbye.String_thing); |
| 906 | Expect( goodbye.Byte_thing = hello.Byte_thing, 'goodbye.Byte_thing = '+IntToStr(goodbye.Byte_thing)); |
| 907 | Expect( goodbye.I32_thing = hello.I32_thing, 'goodbye.I32_thing = '+IntToStr(goodbye.I32_thing)); |
| 908 | Expect( goodbye.I64_thing = hello.I64_thing, 'goodbye.I64_thing = '+IntToStr(goodbye.I64_thing)); |
| 909 | end; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 910 | end; |
| 911 | |
| 912 | |
| 913 | // multi args |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 914 | StartTestGroup( 'testMulti', test_BaseTypes); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 915 | arg0 := 1; |
| 916 | arg1 := 2; |
| 917 | arg2 := High(Int64); |
| 918 | arg3 := TThriftDictionaryImpl<SmallInt, string>.Create; |
| 919 | arg3.AddOrSetValue( 1, 'one'); |
| 920 | arg4 := TNumberz.FIVE; |
| 921 | arg5 := 5000000; |
| 922 | Console.WriteLine('Test Multi(' + IntToStr( arg0) + ',' + |
| 923 | IntToStr( arg1) + ',' + IntToStr( arg2) + ',' + |
| 924 | arg3.ToString + ',' + IntToStr( Integer( arg4)) + ',' + |
| 925 | IntToStr( arg5) + ')'); |
| 926 | |
| 927 | i := client.testMulti( arg0, arg1, arg2, arg3, arg4, arg5); |
| 928 | Expect( i.String_thing = 'Hello2', 'testMulti: i.String_thing = "'+i.String_thing+'"'); |
| 929 | Expect( i.Byte_thing = arg0, 'testMulti: i.Byte_thing = '+IntToStr(i.Byte_thing)); |
| 930 | Expect( i.I32_thing = arg1, 'testMulti: i.I32_thing = '+IntToStr(i.I32_thing)); |
| 931 | Expect( i.I64_thing = arg2, 'testMulti: i.I64_thing = '+IntToStr(i.I64_thing)); |
| 932 | Expect( i.__isset_String_thing, 'testMulti: i.__isset_String_thing = '+BoolToString(i.__isset_String_thing)); |
| 933 | Expect( i.__isset_Byte_thing, 'testMulti: i.__isset_Byte_thing = '+BoolToString(i.__isset_Byte_thing)); |
| 934 | Expect( i.__isset_I32_thing, 'testMulti: i.__isset_I32_thing = '+BoolToString(i.__isset_I32_thing)); |
| 935 | Expect( i.__isset_I64_thing, 'testMulti: i.__isset_I64_thing = '+BoolToString(i.__isset_I64_thing)); |
| 936 | |
| 937 | // multi exception |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 938 | StartTestGroup( 'testMultiException(1)', test_Exceptions); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 939 | try |
| 940 | i := client.testMultiException( 'need more pizza', 'run out of beer'); |
| 941 | Expect( i.String_thing = 'run out of beer', 'i.String_thing = "' +i.String_thing+ '"'); |
| 942 | Expect( i.__isset_String_thing, 'i.__isset_String_thing = '+BoolToString(i.__isset_String_thing)); |
Jens Geyer | 6bbbf19 | 2014-09-07 01:45:56 +0200 | [diff] [blame] | 943 | { this is not necessarily true, these fields are default-serialized |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 944 | Expect( not i.__isset_Byte_thing, 'i.__isset_Byte_thing = '+BoolToString(i.__isset_Byte_thing)); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 945 | Expect( not i.__isset_I32_thing, 'i.__isset_I32_thing = '+BoolToString(i.__isset_I32_thing)); |
| 946 | Expect( not i.__isset_I64_thing, 'i.__isset_I64_thing = '+BoolToString(i.__isset_I64_thing)); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 947 | } |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 948 | except |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 949 | on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'": '+e.Message); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 950 | end; |
| 951 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 952 | StartTestGroup( 'testMultiException(Xception)', test_Exceptions); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 953 | try |
| 954 | i := client.testMultiException( 'Xception', 'second test'); |
| 955 | Expect( FALSE, 'testMultiException(''Xception''): must trow an exception'); |
| 956 | except |
| 957 | on x:TXception do begin |
| 958 | Expect( x.__isset_ErrorCode, 'x.__isset_ErrorCode = '+BoolToString(x.__isset_ErrorCode)); |
Jens Geyer | cd7a2aa | 2022-10-17 14:21:18 +0200 | [diff] [blame] | 959 | Expect( x.__isset_Message, 'x.__isset_Message = '+BoolToString(x.__isset_Message)); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 960 | Expect( x.ErrorCode = 1001, 'x.ErrorCode = '+IntToStr(x.ErrorCode)); |
| 961 | Expect( x.Message_ = 'This is an Xception', 'x.Message = "'+x.Message_+'"'); |
| 962 | end; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 963 | on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'": '+e.Message); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 964 | end; |
| 965 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 966 | StartTestGroup( 'testMultiException(Xception2)', test_Exceptions); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 967 | try |
| 968 | i := client.testMultiException( 'Xception2', 'third test'); |
| 969 | Expect( FALSE, 'testMultiException(''Xception2''): must trow an exception'); |
| 970 | except |
| 971 | on x:TXception2 do begin |
| 972 | Expect( x.__isset_ErrorCode, 'x.__isset_ErrorCode = '+BoolToString(x.__isset_ErrorCode)); |
| 973 | Expect( x.__isset_Struct_thing, 'x.__isset_Struct_thing = '+BoolToString(x.__isset_Struct_thing)); |
| 974 | Expect( x.ErrorCode = 2002, 'x.ErrorCode = '+IntToStr(x.ErrorCode)); |
| 975 | Expect( x.Struct_thing.String_thing = 'This is an Xception2', 'x.Struct_thing.String_thing = "'+x.Struct_thing.String_thing+'"'); |
| 976 | Expect( x.Struct_thing.__isset_String_thing, 'x.Struct_thing.__isset_String_thing = '+BoolToString(x.Struct_thing.__isset_String_thing)); |
Jens Geyer | 6bbbf19 | 2014-09-07 01:45:56 +0200 | [diff] [blame] | 977 | { this is not necessarily true, these fields are default-serialized |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 978 | Expect( not x.Struct_thing.__isset_Byte_thing, 'x.Struct_thing.__isset_Byte_thing = '+BoolToString(x.Struct_thing.__isset_Byte_thing)); |
| 979 | Expect( not x.Struct_thing.__isset_I32_thing, 'x.Struct_thing.__isset_I32_thing = '+BoolToString(x.Struct_thing.__isset_I32_thing)); |
| 980 | Expect( not x.Struct_thing.__isset_I64_thing, 'x.Struct_thing.__isset_I64_thing = '+BoolToString(x.Struct_thing.__isset_I64_thing)); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 981 | } |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 982 | end; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 983 | on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'": '+e.Message); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 984 | end; |
| 985 | |
| 986 | |
| 987 | // oneway functions |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 988 | StartTestGroup( 'Test Oneway(1)', test_Unknown); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 989 | client.testOneway(1); |
| 990 | Expect( TRUE, 'Test Oneway(1)'); // success := no exception |
| 991 | |
| 992 | // call time |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 993 | {$IFDEF PerfTest} |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 994 | StartTestGroup( 'Test Calltime()'); |
Jens Geyer | 9f7f11e | 2016-04-14 21:37:11 +0200 | [diff] [blame] | 995 | StartTick := GetTickCount; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 996 | for k := 0 to 1000 - 1 do |
| 997 | begin |
| 998 | client.testVoid(); |
| 999 | end; |
| 1000 | Console.WriteLine(' = ' + FloatToStr( (GetTickCount - StartTick) / 1000 ) + ' ms a testVoid() call' ); |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 1001 | {$ENDIF PerfTest} |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1002 | |
| 1003 | // no more tests here |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1004 | StartTestGroup( '', test_Unknown); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1005 | end; |
| 1006 | |
| 1007 | |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 1008 | {$IFDEF SupportsAsync} |
| 1009 | procedure TClientThread.ClientAsyncTest; |
| 1010 | var |
| 1011 | client : TThriftTest.IAsync; |
| 1012 | s : string; |
| 1013 | i8 : ShortInt; |
| 1014 | begin |
| 1015 | StartTestGroup( 'Async Tests', test_Unknown); |
| 1016 | client := TThriftTest.TClient.Create( FProtocol); |
| 1017 | FTransport.Open; |
| 1018 | |
| 1019 | // oneway void functions |
| 1020 | client.testOnewayAsync(1).Wait; |
| 1021 | Expect( TRUE, 'Test Oneway(1)'); // success := no exception |
| 1022 | |
| 1023 | // normal functions |
| 1024 | s := client.testStringAsync(HUGE_TEST_STRING).Value; |
| 1025 | Expect( length(s) = length(HUGE_TEST_STRING), |
| 1026 | 'testString( length(HUGE_TEST_STRING) = '+IntToStr(Length(HUGE_TEST_STRING))+') ' |
| 1027 | +'=> length(result) = '+IntToStr(Length(s))); |
| 1028 | |
| 1029 | i8 := client.testByte(1).Value; |
| 1030 | Expect( i8 = 1, 'testByte(1) = ' + IntToStr( i8 )); |
| 1031 | end; |
| 1032 | {$ENDIF} |
| 1033 | |
| 1034 | |
Jens Geyer | 718f6ee | 2013-09-06 21:02:34 +0200 | [diff] [blame] | 1035 | {$IFDEF StressTest} |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 1036 | procedure TClientThread.StressTest(const client : TThriftTest.Iface); |
| 1037 | begin |
| 1038 | while TRUE do begin |
| 1039 | try |
| 1040 | if not FTransport.IsOpen then FTransport.Open; // re-open connection, server has already closed |
| 1041 | try |
| 1042 | client.testString('Test'); |
| 1043 | Write('.'); |
| 1044 | finally |
| 1045 | if FTransport.IsOpen then FTransport.Close; |
| 1046 | end; |
| 1047 | except |
| 1048 | on e:Exception do Writeln(#10+e.message); |
| 1049 | end; |
| 1050 | end; |
| 1051 | end; |
Jens Geyer | 718f6ee | 2013-09-06 21:02:34 +0200 | [diff] [blame] | 1052 | {$ENDIF} |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 1053 | |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 1054 | |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 1055 | function TClientThread.PrepareBinaryData( aRandomDist : Boolean; aSize : TTestSize) : TBytes; |
Jens Geyer | d4df917 | 2017-10-25 22:30:23 +0200 | [diff] [blame] | 1056 | var i : Integer; |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 1057 | begin |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 1058 | case aSize of |
| 1059 | Empty : SetLength( result, 0); |
| 1060 | Normal : SetLength( result, $100); |
| 1061 | ByteArrayTest : SetLength( result, SizeOf(TByteArray) + 128); |
| 1062 | PipeWriteLimit : SetLength( result, 65535 + 128); |
Jens Geyer | 2646bd6 | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1063 | FifteenMB : SetLength( result, 15 * 1024 * 1024); |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 1064 | else |
| 1065 | raise EArgumentException.Create('aSize'); |
| 1066 | end; |
| 1067 | |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 1068 | ASSERT( Low(result) = 0); |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 1069 | if Length(result) = 0 then Exit; |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 1070 | |
| 1071 | // linear distribution, unless random is requested |
| 1072 | if not aRandomDist then begin |
| 1073 | for i := Low(result) to High(result) do begin |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 1074 | result[i] := i mod $100; |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 1075 | end; |
| 1076 | Exit; |
| 1077 | end; |
| 1078 | |
| 1079 | // random distribution of all 256 values |
| 1080 | FillChar( result[0], Length(result) * SizeOf(result[0]), $0); |
Jens Geyer | d4df917 | 2017-10-25 22:30:23 +0200 | [diff] [blame] | 1081 | for i := Low(result) to High(result) do begin |
| 1082 | result[i] := Byte( Random($100)); |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 1083 | end; |
| 1084 | end; |
| 1085 | |
| 1086 | |
Jens Geyer | f790445 | 2017-07-26 15:02:12 +0200 | [diff] [blame] | 1087 | {$IFDEF Win64} |
| 1088 | procedure TClientThread.UseInterlockedExchangeAdd64; |
| 1089 | var a,b : Int64; |
| 1090 | begin |
| 1091 | a := 1; |
| 1092 | b := 2; |
| 1093 | Thrift.Utils.InterlockedExchangeAdd64( a,b); |
| 1094 | Expect( a = 3, 'InterlockedExchangeAdd64'); |
| 1095 | end; |
| 1096 | {$ENDIF} |
| 1097 | |
| 1098 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1099 | procedure TClientThread.JSONProtocolReadWriteTest; |
| 1100 | // Tests only then read/write procedures of the JSON protocol |
| 1101 | // All tests succeed, if we can read what we wrote before |
| 1102 | // Note that passing this test does not imply, that our JSON is really compatible to what |
| 1103 | // other clients or servers expect as the real JSON. This is beyond the scope of this test. |
| 1104 | var prot : IProtocol; |
| 1105 | stm : TStringStream; |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1106 | list : TThriftList; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1107 | config : IThriftConfiguration; |
Jens Geyer | cf892d4 | 2017-09-09 10:08:22 +0200 | [diff] [blame] | 1108 | binary, binRead, emptyBinary : TBytes; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1109 | i,iErr : Integer; |
| 1110 | const |
| 1111 | TEST_SHORT = ShortInt( $FE); |
| 1112 | TEST_SMALL = SmallInt( $FEDC); |
| 1113 | TEST_LONG = LongInt( $FEDCBA98); |
| 1114 | TEST_I64 = Int64( $FEDCBA9876543210); |
| 1115 | TEST_DOUBLE = -1.234e-56; |
| 1116 | DELTA_DOUBLE = TEST_DOUBLE * 1e-14; |
| 1117 | TEST_STRING = 'abc-'#$00E4#$00f6#$00fc; // german umlauts (en-us: "funny chars") |
Phongphan Phuttha | a6509f7 | 2015-10-31 01:09:47 +0700 | [diff] [blame] | 1118 | // Test THRIFT-2336 and THRIFT-3404 with U+1D11E (G Clef symbol) and 'Русское Название'; |
| 1119 | G_CLEF_AND_CYRILLIC_TEXT = #$1d11e' '#$0420#$0443#$0441#$0441#$043a#$043e#$0435' '#$041d#$0430#$0437#$0432#$0430#$043d#$0438#$0435; |
| 1120 | G_CLEF_AND_CYRILLIC_JSON = '"\ud834\udd1e \u0420\u0443\u0441\u0441\u043a\u043e\u0435 \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435"'; |
Jens Geyer | 2136694 | 2013-12-30 22:04:51 +0100 | [diff] [blame] | 1121 | // test both possible solidus encodings |
| 1122 | SOLIDUS_JSON_DATA = '"one/two\/three"'; |
| 1123 | SOLIDUS_EXCPECTED = 'one/two/three'; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1124 | begin |
| 1125 | stm := TStringStream.Create; |
| 1126 | try |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1127 | StartTestGroup( 'JsonProtocolTest', test_Unknown); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1128 | |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1129 | config := TThriftConfigurationImpl.Create; |
| 1130 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1131 | // prepare binary data |
Jens Geyer | 8582715 | 2018-01-12 21:20:59 +0100 | [diff] [blame] | 1132 | binary := PrepareBinaryData( FALSE, Normal); |
Jens Geyer | cf892d4 | 2017-09-09 10:08:22 +0200 | [diff] [blame] | 1133 | SetLength( emptyBinary, 0); // empty binary data block |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1134 | |
| 1135 | // output setup |
| 1136 | prot := TJSONProtocolImpl.Create( |
| 1137 | TStreamTransportImpl.Create( |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1138 | nil, TThriftStreamAdapterDelphi.Create( stm, FALSE), config)); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1139 | |
| 1140 | // write |
Jens Geyer | 17c3ad9 | 2017-09-05 20:31:27 +0200 | [diff] [blame] | 1141 | Init( list, TType.String_, 9); |
| 1142 | prot.WriteListBegin( list); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1143 | prot.WriteBool( TRUE); |
| 1144 | prot.WriteBool( FALSE); |
| 1145 | prot.WriteByte( TEST_SHORT); |
| 1146 | prot.WriteI16( TEST_SMALL); |
| 1147 | prot.WriteI32( TEST_LONG); |
| 1148 | prot.WriteI64( TEST_I64); |
| 1149 | prot.WriteDouble( TEST_DOUBLE); |
| 1150 | prot.WriteString( TEST_STRING); |
| 1151 | prot.WriteBinary( binary); |
Jens Geyer | cf892d4 | 2017-09-09 10:08:22 +0200 | [diff] [blame] | 1152 | prot.WriteString( ''); // empty string |
| 1153 | prot.WriteBinary( emptyBinary); // empty binary data block |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1154 | prot.WriteListEnd; |
| 1155 | |
| 1156 | // input setup |
| 1157 | Expect( stm.Position = stm.Size, 'Stream position/length after write'); |
| 1158 | stm.Position := 0; |
| 1159 | prot := TJSONProtocolImpl.Create( |
| 1160 | TStreamTransportImpl.Create( |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1161 | TThriftStreamAdapterDelphi.Create( stm, FALSE), nil, config)); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1162 | |
| 1163 | // read and compare |
| 1164 | list := prot.ReadListBegin; |
| 1165 | Expect( list.ElementType = TType.String_, 'list element type'); |
| 1166 | Expect( list.Count = 9, 'list element count'); |
| 1167 | Expect( prot.ReadBool, 'WriteBool/ReadBool: TRUE'); |
| 1168 | Expect( not prot.ReadBool, 'WriteBool/ReadBool: FALSE'); |
| 1169 | Expect( prot.ReadByte = TEST_SHORT, 'WriteByte/ReadByte'); |
| 1170 | Expect( prot.ReadI16 = TEST_SMALL, 'WriteI16/ReadI16'); |
| 1171 | Expect( prot.ReadI32 = TEST_LONG, 'WriteI32/ReadI32'); |
| 1172 | Expect( prot.ReadI64 = TEST_I64, 'WriteI64/ReadI64'); |
| 1173 | Expect( abs(prot.ReadDouble-TEST_DOUBLE) < abs(DELTA_DOUBLE), 'WriteDouble/ReadDouble'); |
| 1174 | Expect( prot.ReadString = TEST_STRING, 'WriteString/ReadString'); |
| 1175 | binRead := prot.ReadBinary; |
Jens Geyer | cf892d4 | 2017-09-09 10:08:22 +0200 | [diff] [blame] | 1176 | Expect( Length(prot.ReadString) = 0, 'WriteString/ReadString (empty string)'); |
| 1177 | Expect( Length(prot.ReadBinary) = 0, 'empty WriteBinary/ReadBinary (empty data block)'); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1178 | prot.ReadListEnd; |
| 1179 | |
| 1180 | // test binary data |
| 1181 | Expect( Length(binary) = Length(binRead), 'Binary data length check'); |
| 1182 | iErr := -1; |
| 1183 | for i := Low(binary) to High(binary) do begin |
| 1184 | if binary[i] <> binRead[i] then begin |
| 1185 | iErr := i; |
| 1186 | Break; |
| 1187 | end; |
| 1188 | end; |
| 1189 | if iErr < 0 |
| 1190 | then Expect( TRUE, 'Binary data check ('+IntToStr(Length(binary))+' Bytes)') |
| 1191 | else Expect( FALSE, 'Binary data check at offset '+IntToStr(iErr)); |
| 1192 | |
| 1193 | Expect( stm.Position = stm.Size, 'Stream position after read'); |
| 1194 | |
Jens Geyer | 7bb44a3 | 2014-02-07 22:24:37 +0100 | [diff] [blame] | 1195 | |
Jens Geyer | 2136694 | 2013-12-30 22:04:51 +0100 | [diff] [blame] | 1196 | // Solidus can be encoded in two ways. Make sure we can read both |
| 1197 | stm.Position := 0; |
| 1198 | stm.Size := 0; |
| 1199 | stm.WriteString(SOLIDUS_JSON_DATA); |
| 1200 | stm.Position := 0; |
| 1201 | prot := TJSONProtocolImpl.Create( |
| 1202 | TStreamTransportImpl.Create( |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1203 | TThriftStreamAdapterDelphi.Create( stm, FALSE), nil, config)); |
Jens Geyer | 2136694 | 2013-12-30 22:04:51 +0100 | [diff] [blame] | 1204 | Expect( prot.ReadString = SOLIDUS_EXCPECTED, 'Solidus encoding'); |
| 1205 | |
| 1206 | |
Jens Geyer | 7bb44a3 | 2014-02-07 22:24:37 +0100 | [diff] [blame] | 1207 | // Widechars should work too. Do they? |
| 1208 | // After writing, we ensure that we are able to read it back |
| 1209 | // We can't assume hex-encoding, since (nearly) any Unicode char is valid JSON |
| 1210 | stm.Position := 0; |
| 1211 | stm.Size := 0; |
| 1212 | prot := TJSONProtocolImpl.Create( |
| 1213 | TStreamTransportImpl.Create( |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1214 | nil, TThriftStreamAdapterDelphi.Create( stm, FALSE), config)); |
Phongphan Phuttha | a6509f7 | 2015-10-31 01:09:47 +0700 | [diff] [blame] | 1215 | prot.WriteString( G_CLEF_AND_CYRILLIC_TEXT); |
Jens Geyer | 7bb44a3 | 2014-02-07 22:24:37 +0100 | [diff] [blame] | 1216 | stm.Position := 0; |
| 1217 | prot := TJSONProtocolImpl.Create( |
| 1218 | TStreamTransportImpl.Create( |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1219 | TThriftStreamAdapterDelphi.Create( stm, FALSE), nil, config)); |
Phongphan Phuttha | a6509f7 | 2015-10-31 01:09:47 +0700 | [diff] [blame] | 1220 | Expect( prot.ReadString = G_CLEF_AND_CYRILLIC_TEXT, 'Writing JSON with chars > 8 bit'); |
Jens Geyer | 7bb44a3 | 2014-02-07 22:24:37 +0100 | [diff] [blame] | 1221 | |
| 1222 | // Widechars should work with hex-encoding too. Do they? |
| 1223 | stm.Position := 0; |
| 1224 | stm.Size := 0; |
Phongphan Phuttha | a6509f7 | 2015-10-31 01:09:47 +0700 | [diff] [blame] | 1225 | stm.WriteString( G_CLEF_AND_CYRILLIC_JSON); |
Jens Geyer | 7bb44a3 | 2014-02-07 22:24:37 +0100 | [diff] [blame] | 1226 | stm.Position := 0; |
| 1227 | prot := TJSONProtocolImpl.Create( |
| 1228 | TStreamTransportImpl.Create( |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1229 | TThriftStreamAdapterDelphi.Create( stm, FALSE), nil, config)); |
Phongphan Phuttha | a6509f7 | 2015-10-31 01:09:47 +0700 | [diff] [blame] | 1230 | Expect( prot.ReadString = G_CLEF_AND_CYRILLIC_TEXT, 'Reading JSON with chars > 8 bit'); |
Jens Geyer | 7bb44a3 | 2014-02-07 22:24:37 +0100 | [diff] [blame] | 1231 | |
| 1232 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1233 | finally |
| 1234 | stm.Free; |
| 1235 | prot := nil; //-> Release |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1236 | StartTestGroup( '', test_Unknown); // no more tests here |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1237 | end; |
| 1238 | end; |
| 1239 | |
| 1240 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1241 | procedure TClientThread.StartTestGroup( const aGroup : string; const aTest : TTestGroup); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1242 | begin |
| 1243 | FTestGroup := aGroup; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1244 | FCurrentTest := aTest; |
| 1245 | |
| 1246 | Include( FExecuted, aTest); |
| 1247 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1248 | if FTestGroup <> '' then begin |
| 1249 | Console.WriteLine(''); |
| 1250 | Console.WriteLine( aGroup+' tests'); |
| 1251 | Console.WriteLine( StringOfChar('-',60)); |
| 1252 | end; |
| 1253 | end; |
| 1254 | |
| 1255 | |
| 1256 | procedure TClientThread.Expect( aTestResult : Boolean; const aTestInfo : string); |
| 1257 | begin |
| 1258 | if aTestResult then begin |
| 1259 | Inc(FSuccesses); |
| 1260 | Console.WriteLine( aTestInfo+': passed'); |
| 1261 | end |
| 1262 | else begin |
| 1263 | FErrors.Add( FTestGroup+': '+aTestInfo); |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1264 | Include( FFailed, FCurrentTest); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1265 | Console.WriteLine( aTestInfo+': *** FAILED ***'); |
| 1266 | |
| 1267 | // We have a failed test! |
| 1268 | // -> issue DebugBreak ONLY if a debugger is attached, |
| 1269 | // -> unhandled DebugBreaks would cause Windows to terminate the app otherwise |
Jens Geyer | 9f7f11e | 2016-04-14 21:37:11 +0200 | [diff] [blame] | 1270 | if IsDebuggerPresent |
| 1271 | then {$IFDEF CPUX64} DebugBreak {$ELSE} asm int 3 end {$ENDIF}; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1272 | end; |
| 1273 | end; |
| 1274 | |
| 1275 | |
| 1276 | procedure TClientThread.ReportResults; |
| 1277 | var nTotal : Integer; |
| 1278 | sLine : string; |
| 1279 | begin |
| 1280 | // prevent us from stupid DIV/0 errors |
| 1281 | nTotal := FSuccesses + FErrors.Count; |
| 1282 | if nTotal = 0 then begin |
| 1283 | Console.WriteLine('No results logged'); |
| 1284 | Exit; |
| 1285 | end; |
| 1286 | |
| 1287 | Console.WriteLine(''); |
| 1288 | Console.WriteLine( StringOfChar('=',60)); |
| 1289 | Console.WriteLine( IntToStr(nTotal)+' tests performed'); |
| 1290 | Console.WriteLine( IntToStr(FSuccesses)+' tests succeeded ('+IntToStr(round(100*FSuccesses/nTotal))+'%)'); |
| 1291 | Console.WriteLine( IntToStr(FErrors.Count)+' tests failed ('+IntToStr(round(100*FErrors.Count/nTotal))+'%)'); |
| 1292 | Console.WriteLine( StringOfChar('=',60)); |
| 1293 | if FErrors.Count > 0 then begin |
| 1294 | Console.WriteLine('FAILED TESTS:'); |
| 1295 | for sLine in FErrors do Console.WriteLine('- '+sLine); |
| 1296 | Console.WriteLine( StringOfChar('=',60)); |
| 1297 | InterlockedIncrement( ExitCode); // return <> 0 on errors |
| 1298 | end; |
| 1299 | Console.WriteLine(''); |
| 1300 | end; |
| 1301 | |
| 1302 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1303 | function TClientThread.CalculateExitCode : Byte; |
| 1304 | var test : TTestGroup; |
| 1305 | begin |
| 1306 | result := EXITCODE_SUCCESS; |
| 1307 | for test := Low(TTestGroup) to High(TTestGroup) do begin |
| 1308 | if (test in FFailed) or not (test in FExecuted) |
| 1309 | then result := result or MAP_FAILURES_TO_EXITCODE_BITS[test]; |
| 1310 | end; |
| 1311 | end; |
| 1312 | |
| 1313 | |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1314 | constructor TClientThread.Create( const aSetup : TTestSetup; const aNumIteration, aThreadNo: Integer; const aLogThreadID : Boolean); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1315 | begin |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1316 | FSetup := aSetup; |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1317 | FThreadNo := aThreadNo; |
| 1318 | FNumIterations := aNumIteration; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1319 | |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1320 | FConsole := TThreadConsole.Create( Self, aLogThreadID); |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1321 | FCurrentTest := test_Unknown; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1322 | |
| 1323 | // error list: keep correct order, allow for duplicates |
| 1324 | FErrors := TStringList.Create; |
| 1325 | FErrors.Sorted := FALSE; |
| 1326 | FErrors.Duplicates := dupAccept; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1327 | |
| 1328 | inherited Create( TRUE); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1329 | end; |
| 1330 | |
| 1331 | destructor TClientThread.Destroy; |
| 1332 | begin |
| 1333 | FreeAndNil( FConsole); |
| 1334 | FreeAndNil( FErrors); |
| 1335 | inherited; |
| 1336 | end; |
| 1337 | |
| 1338 | procedure TClientThread.Execute; |
| 1339 | var |
| 1340 | i : Integer; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1341 | begin |
| 1342 | // perform all tests |
| 1343 | try |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1344 | {$IFDEF Win64} |
Jens Geyer | f790445 | 2017-07-26 15:02:12 +0200 | [diff] [blame] | 1345 | UseInterlockedExchangeAdd64; |
Jens Geyer | 14f5d50 | 2017-12-09 13:47:09 +0100 | [diff] [blame] | 1346 | {$ENDIF} |
Jens Geyer | 7bb44a3 | 2014-02-07 22:24:37 +0100 | [diff] [blame] | 1347 | JSONProtocolReadWriteTest; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1348 | |
| 1349 | // must be run in the context of the thread |
| 1350 | InitializeProtocolTransportStack; |
| 1351 | try |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1352 | for i := 0 to FNumIterations - 1 do begin |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1353 | ClientTest; |
| 1354 | {$IFDEF SupportsAsync} |
| 1355 | ClientAsyncTest; |
| 1356 | {$ENDIF} |
| 1357 | end; |
| 1358 | |
| 1359 | // report the outcome |
| 1360 | ReportResults; |
| 1361 | SetReturnValue( CalculateExitCode); |
| 1362 | |
| 1363 | finally |
| 1364 | ShutdownProtocolTransportStack; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1365 | end; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1366 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1367 | except |
| 1368 | on e:Exception do Expect( FALSE, 'unexpected exception: "'+e.message+'"'); |
| 1369 | end; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1370 | end; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1371 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1372 | |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1373 | function TClientThread.InitializeHttpTransport( const aTimeoutSetting : Integer; const aConfig : IThriftConfiguration) : IHTTPClient; |
Jens Geyer | 83ff753 | 2019-06-06 22:46:03 +0200 | [diff] [blame] | 1374 | var sUrl : string; |
| 1375 | comps : URL_COMPONENTS; |
| 1376 | dwChars : DWORD; |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1377 | begin |
| 1378 | ASSERT( FSetup.endpoint in [trns_MsxmlHttp, trns_WinHttp]); |
| 1379 | |
| 1380 | if FSetup.useSSL |
| 1381 | then sUrl := 'https://' |
| 1382 | else sUrl := 'http://'; |
| 1383 | |
| 1384 | sUrl := sUrl + FSetup.host; |
| 1385 | |
Jens Geyer | 83ff753 | 2019-06-06 22:46:03 +0200 | [diff] [blame] | 1386 | // add the port number if necessary and at the right place |
| 1387 | FillChar( comps, SizeOf(comps), 0); |
| 1388 | comps.dwStructSize := SizeOf(comps); |
| 1389 | comps.dwSchemeLength := MAXINT; |
| 1390 | comps.dwHostNameLength := MAXINT; |
| 1391 | comps.dwUserNameLength := MAXINT; |
| 1392 | comps.dwPasswordLength := MAXINT; |
| 1393 | comps.dwUrlPathLength := MAXINT; |
| 1394 | comps.dwExtraInfoLength := MAXINT; |
| 1395 | Win32Check( WinHttpCrackUrl( PChar(sUrl), Length(sUrl), 0, comps)); |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1396 | case FSetup.port of |
Jens Geyer | 83ff753 | 2019-06-06 22:46:03 +0200 | [diff] [blame] | 1397 | 80 : if FSetup.useSSL then comps.nPort := FSetup.port; |
| 1398 | 443 : if not FSetup.useSSL then comps.nPort := FSetup.port; |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1399 | else |
Jens Geyer | 83ff753 | 2019-06-06 22:46:03 +0200 | [diff] [blame] | 1400 | if FSetup.port > 0 then comps.nPort := FSetup.port; |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1401 | end; |
Jens Geyer | 83ff753 | 2019-06-06 22:46:03 +0200 | [diff] [blame] | 1402 | dwChars := Length(sUrl) + 64; |
| 1403 | SetLength( sUrl, dwChars); |
| 1404 | Win32Check( WinHttpCreateUrl( comps, 0, @sUrl[1], dwChars)); |
| 1405 | SetLength( sUrl, dwChars); |
| 1406 | |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1407 | |
| 1408 | Console.WriteLine('Target URL: '+sUrl); |
| 1409 | case FSetup.endpoint of |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1410 | trns_MsxmlHttp : result := TMsxmlHTTPClientImpl.Create( sUrl, aConfig); |
| 1411 | trns_WinHttp : result := TWinHTTPClientImpl.Create( sUrl, aConfig); |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1412 | else |
| 1413 | raise Exception.Create(ENDPOINT_TRANSPORTS[FSetup.endpoint]+' unhandled case'); |
| 1414 | end; |
| 1415 | |
| 1416 | result.DnsResolveTimeout := aTimeoutSetting; |
| 1417 | result.ConnectionTimeout := aTimeoutSetting; |
| 1418 | result.SendTimeout := aTimeoutSetting; |
| 1419 | result.ReadTimeout := aTimeoutSetting; |
| 1420 | end; |
| 1421 | |
| 1422 | |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1423 | procedure TClientThread.InitializeProtocolTransportStack; |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1424 | var streamtrans : IStreamTransport; |
Jens Geyer | 47f6317 | 2019-06-06 22:42:58 +0200 | [diff] [blame] | 1425 | canSSL : Boolean; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1426 | const |
| 1427 | DEBUG_TIMEOUT = 30 * 1000; |
| 1428 | RELEASE_TIMEOUT = DEFAULT_THRIFT_TIMEOUT; |
| 1429 | PIPE_TIMEOUT = RELEASE_TIMEOUT; |
| 1430 | HTTP_TIMEOUTS = 10 * 1000; |
| 1431 | begin |
| 1432 | // needed for HTTP clients as they utilize the MSXML COM components |
| 1433 | OleCheck( CoInitialize( nil)); |
| 1434 | |
Jens Geyer | 47f6317 | 2019-06-06 22:42:58 +0200 | [diff] [blame] | 1435 | canSSL := FALSE; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1436 | case FSetup.endpoint of |
| 1437 | trns_Sockets: begin |
| 1438 | Console.WriteLine('Using sockets ('+FSetup.host+' port '+IntToStr(FSetup.port)+')'); |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1439 | streamtrans := TSocketImpl.Create( FSetup.host, FSetup.port); |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1440 | FTransport := streamtrans; |
| 1441 | end; |
| 1442 | |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1443 | trns_MsxmlHttp, |
| 1444 | trns_WinHttp: begin |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1445 | Console.WriteLine('Using HTTPClient'); |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 1446 | FTransport := InitializeHttpTransport( HTTP_TIMEOUTS); |
Jens Geyer | 47f6317 | 2019-06-06 22:42:58 +0200 | [diff] [blame] | 1447 | canSSL := TRUE; |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1448 | end; |
| 1449 | |
| 1450 | trns_EvHttp: begin |
| 1451 | raise Exception.Create(ENDPOINT_TRANSPORTS[FSetup.endpoint]+' transport not implemented'); |
| 1452 | end; |
| 1453 | |
| 1454 | trns_NamedPipes: begin |
| 1455 | streamtrans := TNamedPipeTransportClientEndImpl.Create( FSetup.sPipeName, 0, nil, PIPE_TIMEOUT, PIPE_TIMEOUT); |
| 1456 | FTransport := streamtrans; |
| 1457 | end; |
| 1458 | |
| 1459 | trns_AnonPipes: begin |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 1460 | streamtrans := TAnonymousPipeTransportImpl.Create( FSetup.hAnonRead, FSetup.hAnonWrite, FALSE, PIPE_TIMEOUT); |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1461 | FTransport := streamtrans; |
| 1462 | end; |
| 1463 | |
| 1464 | else |
| 1465 | raise Exception.Create('Unhandled endpoint transport'); |
| 1466 | end; |
| 1467 | ASSERT( FTransport <> nil); |
| 1468 | |
| 1469 | // layered transports are not really meant to be stacked upon each other |
| 1470 | if (trns_Framed in FSetup.layered) then begin |
| 1471 | FTransport := TFramedTransportImpl.Create( FTransport); |
| 1472 | end |
| 1473 | else if (trns_Buffered in FSetup.layered) and (streamtrans <> nil) then begin |
| 1474 | FTransport := TBufferedTransportImpl.Create( streamtrans, 32); // small buffer to test read() |
| 1475 | end; |
| 1476 | |
Jens Geyer | 47f6317 | 2019-06-06 22:42:58 +0200 | [diff] [blame] | 1477 | if FSetup.useSSL and not canSSL then begin |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1478 | raise Exception.Create('SSL/TLS not implemented'); |
| 1479 | end; |
| 1480 | |
| 1481 | // create protocol instance, default to BinaryProtocol |
Jens Geyer | 3b68653 | 2021-07-01 23:04:08 +0200 | [diff] [blame] | 1482 | FProtocol := PROTOCOL_CLASSES[FSetup.protType].Create(FTransport); |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1483 | ASSERT( (FTransport <> nil) and (FProtocol <> nil)); |
| 1484 | end; |
| 1485 | |
| 1486 | |
| 1487 | procedure TClientThread.ShutdownProtocolTransportStack; |
| 1488 | begin |
| 1489 | try |
| 1490 | FProtocol := nil; |
| 1491 | |
| 1492 | if FTransport <> nil then begin |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1493 | FTransport.Close; |
| 1494 | FTransport := nil; |
| 1495 | end; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1496 | |
Jens Geyer | af7ecd6 | 2018-06-22 22:41:27 +0200 | [diff] [blame] | 1497 | finally |
| 1498 | CoUninitialize; |
| 1499 | end; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1500 | end; |
| 1501 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 1502 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1503 | { TThreadConsole } |
| 1504 | |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1505 | constructor TThreadConsole.Create( const aThread: TClientThread; const aLogThreadID : Boolean); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1506 | begin |
Jens Geyer | 718f6ee | 2013-09-06 21:02:34 +0200 | [diff] [blame] | 1507 | inherited Create; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1508 | FThread := AThread; |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1509 | FLogThreadID := aLogThreadID; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1510 | end; |
| 1511 | |
| 1512 | procedure TThreadConsole.Write(const S: string); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1513 | begin |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1514 | if FLogThreadID |
| 1515 | then ConsoleHelper.Console.Write( IntToStr(FThread.ThreadNo)+'> '+S) |
| 1516 | else ConsoleHelper.Console.Write( S); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1517 | end; |
| 1518 | |
| 1519 | procedure TThreadConsole.WriteLine(const S: string); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1520 | begin |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1521 | if FLogThreadID |
| 1522 | then ConsoleHelper.Console.WriteLine( IntToStr(FThread.ThreadNo)+'> '+S) |
| 1523 | else ConsoleHelper.Console.WriteLine( S); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1524 | end; |
| 1525 | |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1526 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1527 | initialization |
Jens Geyer | 48d3bef | 2022-09-08 21:48:41 +0200 | [diff] [blame] | 1528 | TTestClient.FNumIterations := 1; |
| 1529 | TTestClient.FNumThreads := 1; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 1530 | |
| 1531 | end. |