2
0

tests.rtti.impl.pas 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777
  1. unit Tests.Rtti.Impl;
  2. {$ifdef fpc}
  3. {$mode objfpc}{$H+}
  4. {$endif}
  5. { $define debug}
  6. interface
  7. uses
  8. {$IFDEF FPC}
  9. fpcunit,testregistry, testutils,
  10. {$ELSE FPC}
  11. TestFramework,
  12. {$ENDIF FPC}
  13. sysutils, typinfo, Rtti,
  14. Tests.Rtti.Util,
  15. tests.rtti.impltypes;
  16. { Note: Delphi does not provide a CreateImplementation for TRttiInvokableType
  17. and its descendants, so these tests are disabled for Delphi }
  18. type
  19. { TTestImplBase }
  20. TTestImplBase = class(TTestCase)
  21. Protected
  22. InputArgs: array of TValue;
  23. OutputArgs: array of TValue;
  24. ResultValue: TValue;
  25. InOutMapping: array of SizeInt;
  26. InputUntypedTypes: array of PTypeInfo;
  27. InvokedMethodName: String;
  28. procedure OnHandleIntfMethod(aMethod: TRttiMethod; const aArgs: TValueArray; out aResult: TValue);
  29. procedure DoIntfImpl(aIntf: IInterface; aTypeInfo: PTypeInfo; aIndex: LongInt; aInputArgs, aOutputArgs: TValueArray; aInOutMapping: array of SizeInt; aResult: TValue);
  30. {$ifdef fpc}
  31. procedure OnHandleInvokable(aInvokable: TRttiInvokableType; const aArgs: TValueArray; out aResult: TValue);
  32. procedure DoMethodImpl(aTypeInfo: PTypeInfo; aInputArgs, aOutputArgs: TValueArray; aInOutMapping: array of SizeInt; aResult: TValue);
  33. procedure DoProcImpl(aTypeInfo: PTypeInfo; aInputArgs, aOutputArgs: TValueArray; aInOutMapping: array of SizeInt; aResult: TValue);
  34. {$endif}
  35. end;
  36. (*
  37. TTestImpl = class(TTestCase)
  38. private
  39. published
  40. procedure TestIntfMethods;
  41. {$ifdef fpc}
  42. procedure TestMethodVars;
  43. procedure TestProcVars;
  44. {$endif}
  45. end;
  46. *)
  47. { TTestIntfMethods }
  48. TTestIntfMethods = class(TTestImplBase)
  49. private
  50. intf: ITestInterface;
  51. public
  52. procedure DoTestIntfImpl(aIndex: LongInt; const aInputArgs, aOutputArgs: TValueArray; const aInOutMapping: array of SizeInt; aResult: TValue);
  53. procedure Setup; override;
  54. procedure teardown; override;
  55. published
  56. Procedure Test1;
  57. procedure Test2;
  58. procedure Test3;
  59. procedure Test4;
  60. procedure Test5;
  61. procedure Test6;
  62. procedure Test7;
  63. procedure Test8;
  64. procedure Test9;
  65. procedure Test10;
  66. procedure Test11;
  67. procedure Test12;
  68. procedure Test13;
  69. procedure Test14;
  70. procedure Test15;
  71. procedure Test16;
  72. procedure Test17;
  73. procedure Test18;
  74. procedure Test19;
  75. procedure Test20;
  76. procedure Test21;
  77. procedure Test21s;
  78. procedure Test22;
  79. end;
  80. { TTestDirectIntfCalls }
  81. TIntfCallCallBack = Procedure(aIntf : ITestInterface) of object;
  82. TTestDirectIntfCalls = class(TTestImplBase)
  83. private
  84. Fintf: ITestInterface;
  85. FActualResult : TValue;
  86. FProgress : Boolean;
  87. RecordedOutputArgs : Array of TValue;
  88. procedure CallTestMethod1(aIntf: ITestInterface);
  89. procedure CallTestMethod2(aIntf: ITestInterface);
  90. procedure CallTestMethod3(aIntf: ITestInterface);
  91. procedure CallTestMethod4(aIntf: ITestInterface);
  92. procedure CallTestMethod5(aIntf: ITestInterface);
  93. procedure CallTestMethod6(aIntf: ITestInterface);
  94. procedure CallTestMethod7(aIntf: ITestInterface);
  95. procedure CallTestMethod8(aIntf: ITestInterface);
  96. procedure CallTestMethod9(aIntf: ITestInterface);
  97. procedure CallTestMethod10(aIntf: ITestInterface);
  98. procedure CallTestMethod11(aIntf: ITestInterface);
  99. procedure CallTestMethod12(aIntf: ITestInterface);
  100. procedure CallTestMethod13(aIntf: ITestInterface);
  101. procedure CallTestMethod14(aIntf: ITestInterface);
  102. procedure CallTestMethod15(aIntf: ITestInterface);
  103. procedure CallTestMethod16(aIntf: ITestInterface);
  104. procedure CallTestMethod17(aIntf: ITestInterface);
  105. procedure CallTestMethod18(aIntf: ITestInterface);
  106. procedure CallTestMethod19(aIntf: ITestInterface);
  107. procedure CallTestMethod20(aIntf: ITestInterface);
  108. procedure CallTestMethod21(aIntf: ITestInterface);
  109. procedure CallTestMethod21s(aIntf: ITestInterface);
  110. procedure CallTestMethod22(aIntf: ITestInterface);
  111. procedure DoStep(const aname: string);
  112. public
  113. procedure DoTestIntfImpl(aCall : TIntfCallCallBack; const aName : string; const aInputArgs, aOutputArgs: TValueArray; const aInOutMapping: array of SizeInt; aResult: TValue);
  114. procedure Setup; override;
  115. procedure teardown; override;
  116. published
  117. Procedure Test1;
  118. procedure Test2;
  119. procedure Test3;
  120. procedure Test4;
  121. procedure Test5;
  122. procedure Test6;
  123. procedure Test7;
  124. procedure Test8;
  125. procedure Test9;
  126. procedure Test10;
  127. procedure Test11;
  128. procedure Test12;
  129. procedure Test13;
  130. procedure Test14;
  131. procedure Test15;
  132. procedure Test16;
  133. procedure Test17;
  134. procedure Test18;
  135. procedure Test19;
  136. procedure Test20;
  137. procedure Test21;
  138. procedure Test21s;
  139. procedure Test22;
  140. end;
  141. { TTestMethodVars }
  142. TTestMethodVars = class(TTestImplBase)
  143. Published
  144. Procedure TestMethodVar1;
  145. Procedure TestMethodVar2;
  146. procedure TestMethodVar3;
  147. procedure TestMethodVar4;
  148. procedure TestMethodVar5;
  149. procedure TestMethodVar6;
  150. procedure TestMethodVar7;
  151. procedure TestMethodVar8;
  152. procedure TestMethodVar9;
  153. procedure TestMethodVar10;
  154. procedure TestMethodVar11;
  155. procedure TestMethodVar12;
  156. procedure TestMethodVar13;
  157. procedure TestMethodVar14;
  158. procedure TestMethodVar15;
  159. procedure TestMethodVar16;
  160. procedure TestMethodVar17;
  161. procedure TestMethodVar18;
  162. procedure TestMethodVar19;
  163. procedure TestMethodVar20;
  164. procedure TestMethodVar21;
  165. procedure TestMethodVar21as;
  166. procedure TestMethodVar21ss;
  167. end;
  168. { TTestProcVars }
  169. TTestProcVars = class (TTestImplBase)
  170. Published
  171. Procedure TestProcVar1;
  172. Procedure TestProcVar2;
  173. procedure TestProcVar3;
  174. procedure TestProcVar4;
  175. procedure TestProcVar5;
  176. procedure TestProcVar6;
  177. procedure TestProcVar7;
  178. procedure TestProcVar8;
  179. procedure TestProcVar9;
  180. procedure TestProcVar10;
  181. procedure TestProcVar11;
  182. procedure TestProcVar12;
  183. procedure TestProcVar13;
  184. procedure TestProcVar14;
  185. procedure TestProcVar15;
  186. procedure TestProcVar16;
  187. procedure TestProcVar17;
  188. procedure TestProcVar18;
  189. procedure TestProcVar19;
  190. procedure TestProcVar20;
  191. procedure TestProcVar21;
  192. procedure TestProcVar21as;
  193. procedure TestProcVar21ss;
  194. end;
  195. implementation
  196. { TTestImpl }
  197. procedure TTestImplBase.OnHandleIntfMethod(aMethod: TRttiMethod; const aArgs: TValueArray; out aResult: TValue);
  198. var
  199. selfofs, i: SizeInt;
  200. begin
  201. selfofs := 1;
  202. Status('In Callback');
  203. InvokedMethodName := aMethod.Name;
  204. // Status('Self: ' + HexStr(Self));
  205. if Assigned(aMethod.ReturnType) then
  206. aResult := CopyValue(ResultValue);
  207. // Status('Setting input args');
  208. SetLength(InputArgs, Length(aArgs));
  209. for i := 0 to High(aArgs) do begin
  210. // Status('Arg %d: %p %p %s', [i, aArgs[i].GetReferenceToRawData, PPointer(aArgs[i].GetReferenceToRawData)^, aArgs[i].TypeInfo^.Name]);
  211. // Writeln('Untyped: ',Assigned(InputUntypedTypes[i]));
  212. if Assigned(InputUntypedTypes[i]) then
  213. begin
  214. // Writeln('Input type untyped, creating value for actual type ',InputUntypedTypes[i]^.Name);
  215. TValue.Make(PPointer(aArgs[i].GetReferenceToRawData)^, InputUntypedTypes[i], InputArgs[i])
  216. end
  217. else
  218. InputArgs[i] := CopyValue(aArgs[i]);
  219. // Writeln('OK');
  220. end;
  221. { Note: account for Self }
  222. for i := 0 to High(InOutMapping) do begin
  223. Move(OutputArgs[i].GetReferenceToRawData^, aArgs[InOutMapping[i] + selfofs].GetReferenceToRawData^, OutputArgs[i].DataSize);
  224. end;
  225. Status('Callback done');
  226. end;
  227. procedure TTestImplBase.DoIntfImpl(aIntf: IInterface; aTypeInfo: PTypeInfo; aIndex: LongInt; aInputArgs, aOutputArgs: TValueArray; aInOutMapping: array of SizeInt; aResult: TValue);
  228. var
  229. context: TRttiContext;
  230. t: TRttiType;
  231. instance, res: TValue;
  232. method: TRttiMethod;
  233. i: SizeInt;
  234. input: array of TValue;
  235. intf: TRttiInterfaceType;
  236. params: array of TRttiParameter;
  237. name : string;
  238. begin
  239. input:=nil;
  240. name := 'TestMethod' + IntToStr(aIndex);
  241. context := TRttiContext.Create;
  242. try
  243. t := context.GetType(aTypeInfo);
  244. Check(t is TRttiInterfaceType, 'Not a interface type: ' + aTypeInfo^.Name);
  245. intf := t as TRttiInterfaceType;
  246. method := intf.GetMethod(name);
  247. Check(Assigned(method), 'Method not found: ' + name);
  248. Status('Executing method %s', [name]);
  249. CheckEquals(Length(aOutputArgs), Length(aInOutMapping), 'Invalid in/out mapping');
  250. Check(Length(aOutputArgs) <= Length(aInputArgs), 'Output args not part of input args');
  251. params := method.GetParameters;
  252. TValue.Make(@aIntf, aTypeInfo, instance);
  253. { arguments might be modified by Invoke (Note: Copy() does not uniquify the
  254. IValueData of managed types) }
  255. SetLength(input, Length(aInputArgs) + 1);
  256. SetLength(InputUntypedTypes, Length(aInputArgs) + 1);
  257. input[0] := instance;
  258. InputUntypedTypes[0] := Nil;
  259. for i := 0 to High(aInputArgs) do begin
  260. input[i + 1] := CopyValue(aInputArgs[i]);
  261. if not Assigned(params[i].ParamType) then
  262. InputUntypedTypes[i + 1] := aInputArgs[i].TypeInfo
  263. else
  264. InputUntypedTypes[i + 1] := Nil;
  265. end;
  266. SetLength(InOutMapping, Length(aInOutMapping));
  267. for i := 0 to High(InOutMapping) do
  268. InOutMapping[i] := aInOutMapping[i];
  269. SetLength(OutputArgs, Length(aOutputArgs));
  270. for i := 0 to High(OutputArgs) do
  271. OutputArgs[i] := CopyValue(aOutputArgs[i]);
  272. ResultValue := aResult;
  273. res := method.Invoke(instance, aInputArgs);
  274. Status('After invoke');
  275. CheckEquals(name, InvokedMethodName, 'Invoked method name differs for ' + name);
  276. Check(EqualValues(ResultValue, res), 'Reported result value differs from returned for ' + name);
  277. Check(EqualValues(aResult, res), 'Expected result value differs from returned for ' + name);
  278. CheckEquals(Length(input), Length(InputArgs), 'Count of input args differs for ' + name);
  279. for i := 0 to High(input) do begin
  280. Check(EqualValues(input[i], InputArgs[i]), Format('Input argument %d differs for %s', [i + 1, name]));
  281. end;
  282. for i := 0 to High(aOutputArgs) do begin
  283. Check(EqualValues(aOutputArgs[i], aInputArgs[InOutMapping[i]]), Format('New output argument %d differs from expected output for %s', [i + 1, name]));
  284. end;
  285. finally
  286. context.Free;
  287. end;
  288. end;
  289. {$ifdef fpc}
  290. procedure TTestImplBase.OnHandleInvokable(aInvokable: TRttiInvokableType; const aArgs: TValueArray; out
  291. aResult: TValue);
  292. var
  293. selfofs, i: SizeInt;
  294. begin
  295. CheckTrue((aInvokable is TRttiMethodType) or (aInvokable is TRttiProcedureType), 'Invokable is not a method or procedure variable: ' + aInvokable.ClassName);
  296. selfofs := 0;
  297. if aInvokable is TRttiMethodType then
  298. selfofs := 1;
  299. Status('In Callback');
  300. Status('Self: ' + HexStr(Self));
  301. if Assigned(aInvokable.ReturnType) then
  302. aResult := CopyValue(ResultValue);
  303. Status('Setting input args');
  304. SetLength(InputArgs, Length(aArgs));
  305. for i := 0 to High(aArgs) do begin
  306. Status('Arg %d: %p %p', [i, aArgs[i].GetReferenceToRawData, PPointer(aArgs[i].GetReferenceToRawData)^]);
  307. if Assigned(InputUntypedTypes[i]) then
  308. TValue.Make(PPointer(aArgs[i].GetReferenceToRawData)^, InputUntypedTypes[i], InputArgs[i])
  309. else
  310. InputArgs[i] := CopyValue(aArgs[i]);
  311. end;
  312. Status('Setting output args');
  313. { Note: account for Self }
  314. for i := 0 to High(InOutMapping) do begin
  315. Status('OutputArg %d -> Arg %d', [i, InOutMapping[i] + selfofs]);
  316. { check input arg type? }
  317. Move(OutputArgs[i].GetReferenceToRawData^, aArgs[InOutMapping[i] + selfofs].GetReferenceToRawData^, OutputArgs[i].DataSize);
  318. end;
  319. Status('Callback done');
  320. end;
  321. procedure TTestImplBase.DoMethodImpl(aTypeInfo: PTypeInfo; aInputArgs,
  322. aOutputArgs: TValueArray; aInOutMapping: array of SizeInt; aResult: TValue);
  323. var
  324. context: TRttiContext;
  325. t: TRttiType;
  326. callable, res: TValue;
  327. method: TRttiMethodType;
  328. i: SizeInt;
  329. input: array of TValue;
  330. impl: TMethodImplementation;
  331. mrec: TMethod;
  332. name: String;
  333. params: array of TRttiParameter;
  334. begin
  335. Input:=nil;
  336. name := aTypeInfo^.Name;
  337. impl := Nil;
  338. context := TRttiContext.Create;
  339. try
  340. t := context.GetType(aTypeInfo);
  341. Check(t is TRttiMethodType, 'Not a method variable: ' + name);
  342. method := t as TRttiMethodType;
  343. Status('Executing method %s', [name]);
  344. CheckEquals(Length(aOutputArgs), Length(aInOutMapping), 'Invalid in/out mapping');
  345. Check(Length(aOutputArgs) <= Length(aInputArgs), 'Output args not part of input args');
  346. params := method.GetParameters;
  347. { arguments might be modified by Invoke (Note: Copy() does not uniquify the
  348. IValueData of managed types) }
  349. SetLength(input, Length(aInputArgs) + 1);
  350. SetLength(InputUntypedTypes, Length(aInputArgs) + 1);
  351. input[0] := GetPointerValue(Self);
  352. InputUntypedTypes[0] := Nil;
  353. for i := 0 to High(aInputArgs) do begin
  354. input[i + 1] := CopyValue(aInputArgs[i]);
  355. if not Assigned(params[i].ParamType) then
  356. InputUntypedTypes[i + 1] := aInputArgs[i].TypeInfo
  357. else
  358. InputUntypedTypes[i + 1] := Nil;
  359. end;
  360. try
  361. impl := method.CreateImplementation({$ifdef fpc}@{$endif}OnHandleInvokable);
  362. except
  363. on e: ENotImplemented do
  364. Exit;
  365. end;
  366. CheckNotNull(impl, 'Method implementation is Nil');
  367. mrec.Data := Self;
  368. mrec.Code := impl.CodeAddress;
  369. TValue.Make(@mrec, aTypeInfo, callable);
  370. SetLength(InOutMapping, Length(aInOutMapping));
  371. for i := 0 to High(InOutMapping) do
  372. InOutMapping[i] := aInOutMapping[i];
  373. SetLength(OutputArgs, Length(aOutputArgs));
  374. for i := 0 to High(OutputArgs) do
  375. OutputArgs[i] := CopyValue(aOutputArgs[i]);
  376. ResultValue := aResult;
  377. res := method.Invoke(callable, aInputArgs);
  378. Status('After invoke');
  379. Check(EqualValues(ResultValue, res), 'Reported result value differs from returned for ' + name);
  380. Check(EqualValues(aResult, res), 'Expected result value differs from returned for ' + name);
  381. CheckEquals(Length(input), Length(InputArgs), 'Count of input args differs for ' + name);
  382. for i := 0 to High(input) do begin
  383. Check(EqualValues(input[i], InputArgs[i]), Format('Input argument %d differs for %s', [i + 1, name]));
  384. end;
  385. for i := 0 to High(aOutputArgs) do begin
  386. Check(EqualValues(aOutputArgs[i], aInputArgs[InOutMapping[i]]), Format('New output argument %d differs from expected output for %s', [i + 1, name]));
  387. end;
  388. finally
  389. impl.Free;
  390. context.Free;
  391. end;
  392. end;
  393. procedure TTestImplBase.DoProcImpl(aTypeInfo: PTypeInfo; aInputArgs,
  394. aOutputArgs: TValueArray; aInOutMapping: array of SizeInt; aResult: TValue);
  395. var
  396. context: TRttiContext;
  397. t: TRttiType;
  398. callable, res: TValue;
  399. proc: TRttiProcedureType;
  400. i: SizeInt;
  401. input: array of TValue;
  402. impl: TMethodImplementation;
  403. name: String;
  404. cp: CodePointer;
  405. params: array of TRttiParameter;
  406. begin
  407. Input:=nil;
  408. name := aTypeInfo^.Name;
  409. impl := Nil;
  410. context := TRttiContext.Create;
  411. try
  412. t := context.GetType(aTypeInfo);
  413. Check(t is TRttiProcedureType, 'Not a procedure variable: ' + name);
  414. proc := t as TRttiProcedureType;
  415. Status('Executing procedure %s', [name]);
  416. CheckEquals(Length(aOutputArgs), Length(aInOutMapping), 'Invalid in/out mapping');
  417. Check(Length(aOutputArgs) <= Length(aInputArgs), 'Output args not part of input args');
  418. params := proc.GetParameters;
  419. { arguments might be modified by Invoke (Note: Copy() does not uniquify the
  420. IValueData of managed types) }
  421. SetLength(input, Length(aInputArgs));
  422. SetLength(InputUntypedTypes, Length(aInputArgs));
  423. for i := 0 to High(aInputArgs) do begin
  424. input[i] := CopyValue(aInputArgs[i]);
  425. if not Assigned(params[i].ParamType) then
  426. InputUntypedTypes[i] := aInputArgs[i].TypeInfo
  427. else
  428. InputUntypedTypes[i] := Nil;
  429. end;
  430. try
  431. impl := proc.CreateImplementation({$ifdef fpc}@{$endif}OnHandleInvokable);
  432. except
  433. on e: ENotImplemented do
  434. Exit;
  435. end;
  436. CheckNotNull(impl, 'Method implementation is Nil');
  437. cp := impl.CodeAddress;
  438. TValue.Make(@cp, aTypeInfo, callable);
  439. SetLength(InOutMapping, Length(aInOutMapping));
  440. for i := 0 to High(InOutMapping) do
  441. InOutMapping[i] := aInOutMapping[i];
  442. SetLength(OutputArgs, Length(aOutputArgs));
  443. for i := 0 to High(OutputArgs) do
  444. OutputArgs[i] := CopyValue(aOutputArgs[i]);
  445. ResultValue := aResult;
  446. res := proc.Invoke(callable, aInputArgs);
  447. Status('After invoke');
  448. Check(EqualValues(ResultValue, res), 'Reported result value differs from returned for ' + name);
  449. Check(EqualValues(aResult, res), 'Expected result value differs from returned for ' + name);
  450. CheckEquals(Length(input), Length(InputArgs), 'Count of input args differs for ' + name);
  451. for i := 0 to High(input) do begin
  452. Check(EqualValues(input[i], InputArgs[i]), Format('Input argument %d differs for %s', [i + 1, name]));
  453. end;
  454. for i := 0 to High(aOutputArgs) do begin
  455. Check(EqualValues(aOutputArgs[i], aInputArgs[InOutMapping[i]]), Format('New output argument %d differs from expected output for %s', [i + 1, name]));
  456. end;
  457. finally
  458. impl.Free;
  459. context.Free;
  460. end;
  461. end;
  462. {$endif}
  463. procedure TTestIntfMethods.teardown;
  464. begin
  465. Intf:=Nil;
  466. end;
  467. procedure TTestIntfMethods.Setup;
  468. begin
  469. inherited;
  470. try
  471. intf := TVirtualInterface.Create(PTypeInfo(TypeInfo(ITestInterface)), {$ifdef fpc}@{$endif}OnHandleIntfMethod) as ITestInterface;
  472. except
  473. on e: ENotImplemented do
  474. Ignore('TVirtualInterface not supported for ' + {$I %FPCTARGETCPU%} + '-' + {$I %FPCTARGETOS%}+': '+E.Message);
  475. end;
  476. Check(Assigned(intf), 'ITestInterface instance is Nil');
  477. end;
  478. procedure TTestIntfMethods.DoTestIntfImpl(aIndex: LongInt; const aInputArgs, aOutputArgs: TValueArray; const aInOutMapping: array of SizeInt; aResult: TValue);
  479. begin
  480. DoIntfImpl(Intf, TypeInfo(ITestInterface),aIndex,aInputArgs,aOutputArgs,aInOutMapping,aResult);
  481. end;
  482. procedure TTestIntfMethods.Test1;
  483. begin
  484. DoTestIntfImpl(1, [], [], [], TValue.Empty);
  485. end;
  486. procedure TTestIntfMethods.Test2;
  487. begin
  488. DoTestIntfImpl(2, [GetIntValue(42)], [], [], GetIntValue(21));
  489. end;
  490. procedure TTestIntfMethods.Test3;
  491. begin
  492. DoTestIntfImpl(3, [GetAnsiString('Hello World')], [], [], TValue.Empty);
  493. end;
  494. procedure TTestIntfMethods.Test4;
  495. begin
  496. DoTestIntfImpl(4, [GetShortString('Hello World')], [], [], TValue.Empty);
  497. end;
  498. procedure TTestIntfMethods.Test5;
  499. begin
  500. DoTestIntfImpl(5, [], [], [], GetAnsiString('Hello World'));
  501. end;
  502. procedure TTestIntfMethods.Test6;
  503. begin
  504. DoTestIntfImpl(6, [], [], [], GetShortString('Hello World'));
  505. end;
  506. procedure TTestIntfMethods.Test7;
  507. begin
  508. DoTestIntfImpl(7, [
  509. GetIntValue(1234), GetIntValue(4321), GetIntValue(0), GetIntValue(9876)
  510. ], [
  511. GetIntValue(5678), GetIntValue(6789)
  512. ], [1, 2], TValue.Empty);
  513. end;
  514. procedure TTestIntfMethods.Test8;
  515. begin
  516. DoTestIntfImpl(8, [
  517. GetAnsiString('Alpha'), GetAnsiString('Beta'), GetAnsiString(''), GetAnsiString('Delta')
  518. ], [
  519. GetAnsiString('Gamma'), GetAnsiString('Epsilon')
  520. ], [1, 2], TValue.Empty);
  521. end;
  522. procedure TTestIntfMethods.Test9;
  523. begin
  524. DoTestIntfImpl(9, [
  525. GetShortString('Alpha'), GetShortString('Beta'), GetShortString(''), GetShortString('Delta')
  526. ], [
  527. GetShortString('Gamma'), GetShortString('Epsilon')
  528. ], [1, 2], TValue.Empty);
  529. end;
  530. procedure TTestIntfMethods.Test10;
  531. begin
  532. DoTestIntfImpl(10, [
  533. GetSingleValue(SingleArg1), GetSingleValue(SingleArg2In), GetSingleValue(0), GetSingleValue(SingleArg4)
  534. ], [
  535. GetSingleValue(SingleArg2Out), GetSingleValue(SingleArg3Out)
  536. ], [1, 2], TValue.Empty);
  537. end;
  538. procedure TTestIntfMethods.Test11;
  539. begin
  540. DoTestIntfImpl(11, [
  541. GetDoubleValue(DoubleArg1), GetDoubleValue(DoubleArg2In), GetDoubleValue(0), GetDoubleValue(DoubleArg4)
  542. ], [
  543. GetDoubleValue(DoubleArg2Out), GetDoubleValue(DoubleArg3Out)
  544. ], [1, 2], TValue.Empty);
  545. end;
  546. procedure TTestIntfMethods.Test12;
  547. begin
  548. DoTestIntfImpl(12, [
  549. GetExtendedValue(ExtendedArg1), GetExtendedValue(ExtendedArg2In), GetExtendedValue(0), GetExtendedValue(ExtendedArg4)
  550. ], [
  551. GetExtendedValue(ExtendedArg2Out), GetExtendedValue(ExtendedArg3Out)
  552. ], [1, 2], TValue.Empty);
  553. end;
  554. procedure TTestIntfMethods.Test13;
  555. begin
  556. DoTestIntfImpl(13, [
  557. GetCompValue(CompArg1), GetCompValue(CompArg2In), GetCompValue(0), GetCompValue(CompArg4)
  558. ], [
  559. GetCompValue(CompArg2Out), GetCompValue(CompArg3Out)
  560. ], [1, 2], TValue.Empty);
  561. end;
  562. procedure TTestIntfMethods.Test14;
  563. begin
  564. DoTestIntfImpl( 14, [
  565. GetCurrencyValue(CurrencyArg1), GetCurrencyValue(CurrencyArg2In), GetCurrencyValue(0), GetCurrencyValue(CurrencyArg4)
  566. ], [
  567. GetCurrencyValue(CurrencyArg2Out), GetCurrencyValue(CurrencyArg3Out)
  568. ], [1, 2], TValue.Empty);
  569. end;
  570. procedure TTestIntfMethods.Test15;
  571. begin
  572. DoTestIntfImpl(15, [
  573. GetIntValue(1), GetIntValue(2), GetIntValue(3), GetIntValue(4), GetIntValue(5),
  574. GetIntValue(6), GetIntValue(7), GetIntValue(8), GetIntValue(9), GetIntValue(10)
  575. ], [], [], GetIntValue(11));
  576. end;
  577. procedure TTestIntfMethods.Test16;
  578. begin
  579. DoTestIntfImpl(16, [
  580. GetSingleValue(SingleAddArg1), GetSingleValue(SingleAddArg2), GetSingleValue(SingleAddArg3), GetSingleValue(SingleAddArg4), GetSingleValue(SingleAddArg5),
  581. GetSingleValue(SingleAddArg6), GetSingleValue(SingleAddArg7), GetSingleValue(SingleAddArg8), GetSingleValue(SingleAddArg9), GetSingleValue(SingleAddArg10)
  582. ], [], [], GetSingleValue(SingleAddRes));
  583. end;
  584. procedure TTestIntfMethods.Test17;
  585. begin
  586. DoTestIntfImpl(17, [
  587. GetDoubleValue(DoubleAddArg1), GetDoubleValue(DoubleAddArg2), GetDoubleValue(DoubleAddArg3), GetDoubleValue(DoubleAddArg4), GetDoubleValue(DoubleAddArg5),
  588. GetDoubleValue(DoubleAddArg6), GetDoubleValue(DoubleAddArg7), GetDoubleValue(DoubleAddArg8), GetDoubleValue(DoubleAddArg9), GetDoubleValue(DoubleAddArg10)
  589. ], [], [], GetDoubleValue(DoubleAddRes));
  590. end;
  591. procedure TTestIntfMethods.Test18;
  592. begin
  593. DoTestIntfImpl(18, [
  594. GetExtendedValue(ExtendedAddArg1), GetExtendedValue(ExtendedAddArg2), GetExtendedValue(ExtendedAddArg3), GetExtendedValue(ExtendedAddArg4), GetExtendedValue(ExtendedAddArg5),
  595. GetExtendedValue(ExtendedAddArg6), GetExtendedValue(ExtendedAddArg7), GetExtendedValue(ExtendedAddArg8), GetExtendedValue(ExtendedAddArg9), GetExtendedValue(ExtendedAddArg10)
  596. ], [], [], GetExtendedValue(ExtendedAddRes));
  597. end;
  598. procedure TTestIntfMethods.Test19;
  599. begin
  600. DoTestIntfImpl(19, [
  601. GetCompValue(CompAddArg1), GetCompValue(CompAddArg2), GetCompValue(CompAddArg3), GetCompValue(CompAddArg4), GetCompValue(CompAddArg5),
  602. GetCompValue(CompAddArg6), GetCompValue(CompAddArg7), GetCompValue(CompAddArg8), GetCompValue(CompAddArg9), GetCompValue(CompAddArg10)
  603. ], [], [], GetCompValue(CompAddRes));
  604. end;
  605. procedure TTestIntfMethods.Test20;
  606. begin
  607. DoTestIntfImpl(20, [
  608. GetCurrencyValue(CurrencyAddArg1), GetCurrencyValue(CurrencyAddArg2), GetCurrencyValue(CurrencyAddArg3), GetCurrencyValue(CurrencyAddArg4), GetCurrencyValue(CurrencyAddArg5),
  609. GetCurrencyValue(CurrencyAddArg6), GetCurrencyValue(CurrencyAddArg7), GetCurrencyValue(CurrencyAddArg8), GetCurrencyValue(CurrencyAddArg9), GetCurrencyValue(CurrencyAddArg10)
  610. ], [], [], GetCurrencyValue(CurrencyAddRes));
  611. end;
  612. procedure TTestIntfMethods.Test21;
  613. begin
  614. DoTestIntfImpl(21, [
  615. GetIntValue(1234), GetIntValue(4321), GetIntValue(0), GetIntValue(9876)
  616. ], [
  617. GetIntValue(5678), GetIntValue(6789)
  618. ], [0, 1], TValue.Empty);
  619. end;
  620. procedure TTestIntfMethods.Test21s;
  621. begin
  622. DoTestIntfImpl(21, [
  623. GetAnsiString('Alpha'), GetAnsiString('Beta'), GetAnsiString(''), GetAnsiString('Delta')
  624. ], [
  625. GetAnsiString('Gamma'), GetAnsiString('Epsilon')
  626. ], [0, 1], TValue.Empty);
  627. end;
  628. procedure TTestIntfMethods.Test22;
  629. begin
  630. { for some reason this fails, though it fails in Delphi as well :/ }
  631. {
  632. DoTestIntfImpl(21, [
  633. GetShortString('Alpha'), GetShortString('Beta'), GetShortString(''), GetShortString('Delta')
  634. ], [
  635. GetShortString('Gamma'), GetShortString('Epsilon')
  636. ], [0, 1], TValue.Empty);
  637. }
  638. end;
  639. { TTestDirectIntfCalls }
  640. procedure TTestDirectIntfCalls.DoStep(const aname : string);
  641. begin
  642. if FProgress then
  643. Writeln(aname);
  644. end;
  645. procedure TTestDirectIntfCalls.DoTestIntfImpl(aCall: TIntfCallCallBack;
  646. const aName : string;
  647. const aInputArgs, aOutputArgs: TValueArray;
  648. const aInOutMapping: array of SizeInt; aResult: TValue);
  649. var
  650. context: TRttiContext;
  651. t: TRttiType;
  652. instance: TValue;
  653. method: TRttiMethod;
  654. i: SizeInt;
  655. input: array of TValue;
  656. intf: TRttiInterfaceType;
  657. params: array of TRttiParameter;
  658. i6 : Int64;
  659. begin
  660. // FProgress:=True;
  661. input:=nil;
  662. context := TRttiContext.Create;
  663. try
  664. t := context.GetType(TypeInfo(ITestInterface));
  665. Check(t is TRttiInterfaceType, 'Not a interface type !');
  666. intf := t as TRttiInterfaceType;
  667. method := intf.GetMethod(aname);
  668. Check(Assigned(method), 'Method not found: ' + aname);
  669. params := method.GetParameters;
  670. dostep('a');
  671. CheckEquals(Length(aOutputArgs), Length(aInOutMapping), 'Invalid in/out mapping');
  672. dostep('b');
  673. Check(Length(aOutputArgs) <= Length(aInputArgs), 'Output args not part of input args');
  674. dostep('c');
  675. TValue.Make(@FIntf, TypeInfo(ITestInterface), instance);
  676. dostep('d');
  677. { arguments might be modified by Invoke (Note: Copy() does not uniquify the
  678. IValueData of managed types) }
  679. SetLength(input, Length(aInputArgs) + 1);
  680. dostep('e');
  681. SetLength(InputUntypedTypes, Length(aInputArgs) + 1);
  682. dostep('f');
  683. input[0] := instance;
  684. dostep('g');
  685. InputUntypedTypes[0] := Nil;
  686. dostep('h');
  687. for i := 0 to High(aInputArgs) do begin
  688. dostep('h_'+IntToStr(i));
  689. input[i + 1] := CopyValue(aInputArgs[i]);
  690. dostep('h__'+IntToStr(i));
  691. if not Assigned(params[i].ParamType) then
  692. begin
  693. dostep('h__/'+IntToStr(i)+' : Param '+params[i].Name+' is untyped, Actual type is '+aInputArgs[i].TypeInfo^.Name);
  694. InputUntypedTypes[i + 1] := aInputArgs[i].TypeInfo
  695. end
  696. else
  697. begin
  698. dostep('h__\'+IntToStr(i)+' : Param '+params[i].Name+' is typed');
  699. InputUntypedTypes[i + 1] := Nil;
  700. end;
  701. end;
  702. dostep('i');
  703. SetLength(InOutMapping, Length(aInOutMapping));
  704. dostep('j');
  705. for i := 0 to High(InOutMapping) do
  706. InOutMapping[i] := aInOutMapping[i];
  707. dostep('k');
  708. SetLength(OutputArgs, Length(aOutputArgs));
  709. for i := 0 to High(OutputArgs) do
  710. OutputArgs[i] := CopyValue(aOutputArgs[i]);
  711. dostep('l');
  712. ResultValue := aResult;
  713. dostep('m');
  714. aCall(self.FIntf);
  715. dostep('n');
  716. CheckEquals(aName, InvokedMethodName, 'Invoked method name differs');
  717. dostep('o');
  718. Check(EqualValues(ResultValue, FActualResult), Format('Actual result %s value differs from saved expected %s',[FActualResult.ToString,ResultValue.ToString]));
  719. dostep('p');
  720. Check(EqualValues(aResult, FActualResult), Format('Actual result %s value differs from expected %s',[FActualResult.ToString, aResult.ToString]));
  721. dostep('q');
  722. CheckEquals(Length(input), Length(InputArgs), 'Count of input args differs');
  723. dostep('q1');
  724. for i := 0 to Length(InputArgs)-1 do
  725. begin
  726. // Can't compare untyped in direct call.
  727. if (I=0) or Assigned(Params[I-1].ParamType) then
  728. Check(EqualValues(input[i], InputArgs[i]), Format('Input argument %d differs (actual: %s, expected: %s)', [i,input[i].tostring, InputArgs[i].toString]));
  729. end;
  730. dostep('r');
  731. CheckEquals(Length(aOutputArgs), Length(RecordedOutputArgs), 'Count of recorded and expected output args differs');
  732. for i := 0 to High(aOutputArgs) do begin
  733. Check(EqualValues(aOutputArgs[i], RecordedOutputArgs[i]), Format('New output argument %d (%s) differs from expected output (%s)', [i + 1, RecordedOutputArgs[i].ToString, aOutputArgs[i].toString]));
  734. end;
  735. dostep('s');
  736. finally
  737. context.Free;
  738. end;
  739. end;
  740. procedure TTestDirectIntfCalls.Setup;
  741. begin
  742. inherited;
  743. try
  744. Fintf := TVirtualInterface.Create(PTypeInfo(TypeInfo(ITestInterface)), {$ifdef fpc}@{$endif}OnHandleIntfMethod) as ITestInterface;
  745. except
  746. on e: ENotImplemented do
  747. Ignore('TVirtualInterface not supported for ' + {$I %FPCTARGETCPU%} + '-' + {$I %FPCTARGETOS%}+': '+E.Message);
  748. end;
  749. Check(Assigned(Fintf), 'ITestInterface instance is Nil');
  750. FActualResult:=TValue.Empty;
  751. end;
  752. procedure TTestDirectIntfCalls.teardown;
  753. begin
  754. FIntf:=nil;
  755. inherited teardown;
  756. end;
  757. procedure TTestDirectIntfCalls.CallTestMethod1(aIntf : ITestInterface);
  758. begin
  759. DoStep('> TTestDirectIntfCalls.CallTestMethod1');
  760. aIntf.TestMethod1;
  761. DoStep('< TTestDirectIntfCalls.CallTestMethod1');
  762. end;
  763. procedure TTestDirectIntfCalls.Test1;
  764. begin
  765. DoTestIntfImpl(@CallTestMethod1,'TestMethod1', [], [], [], TValue.Empty);
  766. DoStep('< TTestDirectIntfCalls.Test1');
  767. end;
  768. procedure TTestDirectIntfCalls.CallTestMethod2(aIntf : ITestInterface);
  769. var
  770. I : Integer;
  771. begin
  772. DoStep('> TTestDirectIntfCalls.CallTestMethod2');
  773. I:=aIntf.TestMethod2(42);
  774. TValue.Make(I,TypeInfo(Sizeint),FActualResult);
  775. DoStep('< TTestDirectIntfCalls.CallTestMethod2');
  776. end;
  777. procedure TTestDirectIntfCalls.Test2;
  778. begin
  779. DoTestIntfImpl(@CallTestMethod2,'TestMethod2', [GetIntValue(42)], [], [], GetIntValue(21));
  780. end;
  781. procedure TTestDirectIntfCalls.CallTestMethod3(aIntf: ITestInterface);
  782. begin
  783. DoStep('> TTestDirectIntfCalls.CallTestMethod3');
  784. aIntf.TestMethod3('Hello World');
  785. DoStep('< TTestDirectIntfCalls.CallTestMethod3');
  786. end;
  787. procedure TTestDirectIntfCalls.Test3;
  788. begin
  789. DoTestIntfImpl(@CallTestMethod3,'TestMethod3', [GetAnsiString('Hello World')], [], [], TValue.Empty);
  790. end;
  791. procedure TTestDirectIntfCalls.CallTestMethod4(aIntf: ITestInterface);
  792. var
  793. S : ShortString;
  794. begin
  795. DoStep('> TTestDirectIntfCalls.CallTestMethod4');
  796. S:='Hello World';
  797. aIntf.TestMethod4(S);
  798. DoStep('< TTestDirectIntfCalls.CallTestMethod4');
  799. end;
  800. procedure TTestDirectIntfCalls.Test4;
  801. begin
  802. DoTestIntfImpl(@CallTestMethod4,'TestMethod4', [GetShortString('Hello World')], [], [], TValue.Empty);
  803. end;
  804. procedure TTestDirectIntfCalls.CallTestMethod5(aIntf: ITestInterface);
  805. var
  806. S : AnsiString;
  807. begin
  808. DoStep('> TTestDirectIntfCalls.CallTestMethod5');
  809. S:=aIntf.TestMethod5();
  810. TValue.Make(@S,TypeInfo(AnsiString),FActualResult);
  811. DoStep('< TTestDirectIntfCalls.CallTestMethod5');
  812. end;
  813. procedure TTestDirectIntfCalls.Test5;
  814. begin
  815. DoTestIntfImpl(@CallTestMethod5,'TestMethod5', [], [], [], GetAnsiString('Hello World'));
  816. end;
  817. procedure TTestDirectIntfCalls.CallTestMethod6(aIntf: ITestInterface);
  818. var
  819. S : ShortString;
  820. begin
  821. DoStep('> TTestDirectIntfCalls.CallTestMethod6');
  822. S:=aIntf.TestMethod6();
  823. TValue.Make(@S,TypeInfo(ShortString),FActualResult);
  824. DoStep('< TTestDirectIntfCalls.CallTestMethod6');
  825. end;
  826. procedure TTestDirectIntfCalls.Test6;
  827. begin
  828. DoTestIntfImpl(@CallTestMethod6, 'TestMethod6', [], [], [], GetShortString('Hello World'));
  829. end;
  830. procedure TTestDirectIntfCalls.CallTestMethod7(aIntf: ITestInterface);
  831. Var
  832. i2,i3 : SizeInt;
  833. begin
  834. i2:=4321;
  835. i3:=0;
  836. aIntf.TestMethod7(1234,I2,I3,9876);
  837. SetLength(RecordedOutputArgs,2);
  838. TValue.Make(@I2,TypeInfo(SizeInt),RecordedOutputArgs[0]);
  839. TValue.Make(@I3,TypeInfo(SizeInt),RecordedOutputArgs[1]);
  840. end;
  841. procedure TTestDirectIntfCalls.Test7;
  842. begin
  843. DoTestIntfImpl(@CallTestMethod7, 'TestMethod7', [
  844. GetIntValue(1234), GetIntValue(4321), GetIntValue(0), GetIntValue(9876)
  845. ], [
  846. GetIntValue(5678), GetIntValue(6789)
  847. ], [1, 2], TValue.Empty);
  848. end;
  849. procedure TTestDirectIntfCalls.CallTestMethod8(aIntf: ITestInterface);
  850. var
  851. s2,s3 : AnsiString;
  852. begin
  853. s2:='Beta';
  854. s3:='';
  855. aIntf.TestMethod8('Alpha',S2,S3,'Delta');
  856. SetLength(RecordedOutputArgs,2);
  857. TValue.Make(@S2,TypeInfo(AnsiString),RecordedOutputArgs[0]);
  858. TValue.Make(@S3,TypeInfo(AnsiString),RecordedOutputArgs[1]);
  859. end;
  860. procedure TTestDirectIntfCalls.Test8;
  861. begin
  862. DoTestIntfImpl(@CallTestMethod8, 'TestMethod8', [
  863. GetAnsiString('Alpha'), GetAnsiString('Beta'), GetAnsiString(''), GetAnsiString('Delta')
  864. ], [
  865. GetAnsiString('Gamma'), GetAnsiString('Epsilon')
  866. ], [1, 2], TValue.Empty);
  867. end;
  868. procedure TTestDirectIntfCalls.CallTestMethod9(aIntf: ITestInterface);
  869. Var
  870. S1,S2,S3,S4 : Shortstring;
  871. begin
  872. S1:='Alpha';
  873. S2:='Beta';
  874. S3:='';
  875. S4:='Delta';
  876. aIntf.TestMethod9(S1,S2,S3,S4);
  877. SetLength(RecordedOutputArgs,2);
  878. TValue.Make(@S2,TypeInfo(ShortString),RecordedOutputArgs[0]);
  879. TValue.Make(@S3,TypeInfo(ShortString),RecordedOutputArgs[1]);
  880. end;
  881. procedure TTestDirectIntfCalls.Test9;
  882. begin
  883. DoTestIntfImpl(@CallTestMethod9, 'TestMethod9', [
  884. GetShortString('Alpha'), GetShortString('Beta'), GetShortString(''), GetShortString('Delta')
  885. ], [
  886. GetShortString('Gamma'), GetShortString('Epsilon')
  887. ], [1, 2], TValue.Empty);
  888. end;
  889. procedure TTestDirectIntfCalls.CallTestMethod10(aIntf: ITestInterface);
  890. var
  891. S1,S2,S3,S4 : Single;
  892. begin
  893. S1:=SingleArg1;
  894. S2:=SingleArg2in;
  895. S3:=0;
  896. S4:=SingleArg4;
  897. aIntf.TestMethod10(S1,S2,S3,S4);
  898. SetLength(RecordedOutputArgs,2);
  899. TValue.Make(@S2,TypeInfo(Single),RecordedOutputArgs[0]);
  900. TValue.Make(@S3,TypeInfo(Single),RecordedOutputArgs[1]);
  901. end;
  902. procedure TTestDirectIntfCalls.Test10;
  903. begin
  904. DoTestIntfImpl(@CallTestMethod10, 'TestMethod10', [
  905. GetSingleValue(SingleArg1), GetSingleValue(SingleArg2In), GetSingleValue(0), GetSingleValue(SingleArg4)
  906. ], [
  907. GetSingleValue(SingleArg2Out), GetSingleValue(SingleArg3Out)
  908. ], [1, 2], TValue.Empty);
  909. end;
  910. procedure TTestDirectIntfCalls.CallTestMethod11(aIntf: ITestInterface);
  911. var
  912. S1,S2,S3,S4 : Double;
  913. begin
  914. S1:=DoubleArg1;
  915. S2:=DoubleArg2in;
  916. S3:=0;
  917. S4:=DoubleArg4;
  918. aIntf.TestMethod11(S1,S2,S3,S4);
  919. SetLength(RecordedOutputArgs,2);
  920. TValue.Make(@S2,TypeInfo(Double),RecordedOutputArgs[0]);
  921. TValue.Make(@S3,TypeInfo(Double),RecordedOutputArgs[1]);
  922. end;
  923. procedure TTestDirectIntfCalls.Test11;
  924. begin
  925. DoTestIntfImpl(@CallTestMethod11, 'TestMethod11', [
  926. GetDoubleValue(DoubleArg1), GetDoubleValue(DoubleArg2In), GetDoubleValue(0), GetDoubleValue(DoubleArg4)
  927. ], [
  928. GetDoubleValue(DoubleArg2Out), GetDoubleValue(DoubleArg3Out)
  929. ], [1, 2], TValue.Empty);
  930. end;
  931. procedure TTestDirectIntfCalls.CallTestMethod12(aIntf: ITestInterface);
  932. var
  933. S1,S2,S3,S4 : Extended;
  934. begin
  935. S1:=ExtendedArg1;
  936. S2:=ExtendedArg2in;
  937. S3:=0;
  938. S4:=ExtendedArg4;
  939. aIntf.TestMethod12(S1,S2,S3,S4);
  940. SetLength(RecordedOutputArgs,2);
  941. TValue.Make(@S2,TypeInfo(Extended),RecordedOutputArgs[0]);
  942. TValue.Make(@S3,TypeInfo(Extended),RecordedOutputArgs[1]);
  943. end;
  944. procedure TTestDirectIntfCalls.Test12;
  945. begin
  946. DoTestIntfImpl(@CallTestMethod12, 'TestMethod12', [
  947. GetExtendedValue(ExtendedArg1), GetExtendedValue(ExtendedArg2In), GetExtendedValue(0), GetExtendedValue(ExtendedArg4)
  948. ], [
  949. GetExtendedValue(ExtendedArg2Out), GetExtendedValue(ExtendedArg3Out)
  950. ], [1, 2], TValue.Empty);
  951. end;
  952. procedure TTestDirectIntfCalls.CallTestMethod13(aIntf: ITestInterface);
  953. var
  954. S1,S2,S3,S4 : Comp;
  955. begin
  956. S1:=CompArg1;
  957. S2:=CompArg2in;
  958. S3:=0;
  959. S4:=CompArg4;
  960. aIntf.TestMethod13(S1,S2,S3,S4);
  961. SetLength(RecordedOutputArgs,2);
  962. TValue.Make(@S2,TypeInfo(Comp),RecordedOutputArgs[0]);
  963. TValue.Make(@S3,TypeInfo(Comp),RecordedOutputArgs[1]);
  964. end;
  965. procedure TTestDirectIntfCalls.Test13;
  966. begin
  967. DoTestIntfImpl(@CallTestMethod13, 'TestMethod13', [
  968. GetCompValue(CompArg1), GetCompValue(CompArg2In), GetCompValue(0), GetCompValue(CompArg4)
  969. ], [
  970. GetCompValue(CompArg2Out), GetCompValue(CompArg3Out)
  971. ], [1, 2], TValue.Empty);
  972. end;
  973. procedure TTestDirectIntfCalls.CallTestMethod14(aIntf: ITestInterface);
  974. var
  975. S1,S2,S3,S4 : Currency;
  976. begin
  977. S1:=CurrencyArg1;
  978. S2:=CurrencyArg2in;
  979. S3:=0;
  980. S4:=CurrencyArg4;
  981. aIntf.TestMethod14(S1,S2,S3,S4);
  982. SetLength(RecordedOutputArgs,2);
  983. TValue.Make(@S2,TypeInfo(Currency),RecordedOutputArgs[0]);
  984. TValue.Make(@S3,TypeInfo(Currency),RecordedOutputArgs[1]);
  985. end;
  986. procedure TTestDirectIntfCalls.Test14;
  987. begin
  988. DoTestIntfImpl( @CallTestMethod14, 'TestMethod14', [
  989. GetCurrencyValue(CurrencyArg1), GetCurrencyValue(CurrencyArg2In), GetCurrencyValue(0), GetCurrencyValue(CurrencyArg4)
  990. ], [
  991. GetCurrencyValue(CurrencyArg2Out), GetCurrencyValue(CurrencyArg3Out)
  992. ], [1, 2], TValue.Empty);
  993. end;
  994. procedure TTestDirectIntfCalls.CallTestMethod15(aIntf: ITestInterface);
  995. var
  996. res : SizeInt;
  997. begin
  998. Res:=aIntf.TestMethod15(1,2,3,4,5,6,7,8,9,10);
  999. TValue.Make(@Res,TypeInfo(SizeInt),FActualResult);
  1000. end;
  1001. procedure TTestDirectIntfCalls.Test15;
  1002. begin
  1003. DoTestIntfImpl(@CallTestMethod15, 'TestMethod15', [
  1004. GetIntValue(1), GetIntValue(2), GetIntValue(3), GetIntValue(4), GetIntValue(5),
  1005. GetIntValue(6), GetIntValue(7), GetIntValue(8), GetIntValue(9), GetIntValue(10)
  1006. ], [], [], GetIntValue(11));
  1007. end;
  1008. procedure TTestDirectIntfCalls.CallTestMethod16(aIntf: ITestInterface);
  1009. var
  1010. res : single;
  1011. begin
  1012. Res:=aIntf.TestMethod16(SingleAddArg1,SingleAddArg2,SingleAddArg3,SingleAddArg4,SingleAddArg5,
  1013. SingleAddArg6,SingleAddArg7,SingleAddArg8,SingleAddArg9,SingleAddArg10);
  1014. TValue.Make(@Res,TypeInfo(Single),FActualResult);
  1015. end;
  1016. procedure TTestDirectIntfCalls.Test16;
  1017. begin
  1018. DoTestIntfImpl(@CallTestMethod16, 'TestMethod16', [
  1019. GetSingleValue(SingleAddArg1), GetSingleValue(SingleAddArg2), GetSingleValue(SingleAddArg3), GetSingleValue(SingleAddArg4), GetSingleValue(SingleAddArg5),
  1020. GetSingleValue(SingleAddArg6), GetSingleValue(SingleAddArg7), GetSingleValue(SingleAddArg8), GetSingleValue(SingleAddArg9), GetSingleValue(SingleAddArg10)
  1021. ], [], [], GetSingleValue(SingleAddRes));
  1022. end;
  1023. procedure TTestDirectIntfCalls.CallTestMethod17(aIntf: ITestInterface);
  1024. var
  1025. res : Double;
  1026. begin
  1027. Res:=aIntf.TestMethod17(DoubleAddArg1,DoubleAddArg2,DoubleAddArg3,DoubleAddArg4,DoubleAddArg5,
  1028. DoubleAddArg6,DoubleAddArg7,DoubleAddArg8,DoubleAddArg9,DoubleAddArg10);
  1029. TValue.Make(@Res,TypeInfo(Double),FActualResult);
  1030. end;
  1031. procedure TTestDirectIntfCalls.Test17;
  1032. begin
  1033. DoTestIntfImpl(@CallTestMethod17, 'TestMethod17', [
  1034. GetDoubleValue(DoubleAddArg1), GetDoubleValue(DoubleAddArg2), GetDoubleValue(DoubleAddArg3), GetDoubleValue(DoubleAddArg4), GetDoubleValue(DoubleAddArg5),
  1035. GetDoubleValue(DoubleAddArg6), GetDoubleValue(DoubleAddArg7), GetDoubleValue(DoubleAddArg8), GetDoubleValue(DoubleAddArg9), GetDoubleValue(DoubleAddArg10)
  1036. ], [], [], GetDoubleValue(DoubleAddRes));
  1037. end;
  1038. procedure TTestDirectIntfCalls.CallTestMethod18(aIntf: ITestInterface);
  1039. var
  1040. res : Extended;
  1041. begin
  1042. Res:=aIntf.TestMethod18(ExtendedAddArg1,ExtendedAddArg2,ExtendedAddArg3,ExtendedAddArg4,ExtendedAddArg5,
  1043. ExtendedAddArg6,ExtendedAddArg7,ExtendedAddArg8,ExtendedAddArg9,ExtendedAddArg10);
  1044. TValue.Make(@Res,TypeInfo(Extended),FActualResult);
  1045. end;
  1046. procedure TTestDirectIntfCalls.Test18;
  1047. begin
  1048. DoTestIntfImpl(@CallTestMethod18, 'TestMethod18', [
  1049. GetExtendedValue(ExtendedAddArg1), GetExtendedValue(ExtendedAddArg2), GetExtendedValue(ExtendedAddArg3), GetExtendedValue(ExtendedAddArg4), GetExtendedValue(ExtendedAddArg5),
  1050. GetExtendedValue(ExtendedAddArg6), GetExtendedValue(ExtendedAddArg7), GetExtendedValue(ExtendedAddArg8), GetExtendedValue(ExtendedAddArg9), GetExtendedValue(ExtendedAddArg10)
  1051. ], [], [], GetExtendedValue(ExtendedAddRes));
  1052. end;
  1053. procedure TTestDirectIntfCalls.CallTestMethod19(aIntf: ITestInterface);
  1054. var
  1055. res : comp;
  1056. begin
  1057. Res:=aIntf.TestMethod19(compAddArg1,compAddArg2,compAddArg3,compAddArg4,compAddArg5,
  1058. compAddArg6,compAddArg7,compAddArg8,compAddArg9,compAddArg10);
  1059. TValue.Make(@Res,TypeInfo(comp),FActualResult);
  1060. end;
  1061. procedure TTestDirectIntfCalls.Test19;
  1062. begin
  1063. DoTestIntfImpl(@CallTestMethod19, 'TestMethod19', [
  1064. GetCompValue(CompAddArg1), GetCompValue(CompAddArg2), GetCompValue(CompAddArg3), GetCompValue(CompAddArg4), GetCompValue(CompAddArg5),
  1065. GetCompValue(CompAddArg6), GetCompValue(CompAddArg7), GetCompValue(CompAddArg8), GetCompValue(CompAddArg9), GetCompValue(CompAddArg10)
  1066. ], [], [], GetCompValue(CompAddRes));
  1067. end;
  1068. procedure TTestDirectIntfCalls.CallTestMethod20(aIntf: ITestInterface);
  1069. var
  1070. res : Currency;
  1071. begin
  1072. Res:=aIntf.TestMethod20(CurrencyAddArg1,CurrencyAddArg2,CurrencyAddArg3,CurrencyAddArg4,CurrencyAddArg5,
  1073. CurrencyAddArg6,CurrencyAddArg7,CurrencyAddArg8,CurrencyAddArg9,CurrencyAddArg10);
  1074. TValue.Make(@Res,TypeInfo(Currency),FActualResult);
  1075. end;
  1076. procedure TTestDirectIntfCalls.Test20;
  1077. begin
  1078. DoTestIntfImpl(@CallTestMethod20, 'TestMethod20', [
  1079. GetCurrencyValue(CurrencyAddArg1), GetCurrencyValue(CurrencyAddArg2), GetCurrencyValue(CurrencyAddArg3), GetCurrencyValue(CurrencyAddArg4), GetCurrencyValue(CurrencyAddArg5),
  1080. GetCurrencyValue(CurrencyAddArg6), GetCurrencyValue(CurrencyAddArg7), GetCurrencyValue(CurrencyAddArg8), GetCurrencyValue(CurrencyAddArg9), GetCurrencyValue(CurrencyAddArg10)
  1081. ], [], [], GetCurrencyValue(CurrencyAddRes));
  1082. end;
  1083. procedure TTestDirectIntfCalls.CallTestMethod21(aIntf: ITestInterface);
  1084. var
  1085. S1,S2,S3,S4 : Sizeint;
  1086. begin
  1087. S1:=1234;
  1088. S2:=4321;
  1089. S3:=0;
  1090. S4:=9876;
  1091. aIntf.TestMethod21(s1,s2,s3,s4);
  1092. SetLength(RecordedOutputArgs,2);
  1093. TValue.Make(@S1,TypeInfo(SizeInt),RecordedOutputArgs[0]);
  1094. TValue.Make(@S2,TypeInfo(SizeInt),RecordedOutputArgs[1]);
  1095. end;
  1096. procedure TTestDirectIntfCalls.Test21;
  1097. begin
  1098. DoTestIntfImpl(@CallTestMethod21, 'TestMethod21', [
  1099. GetIntValue(1234), GetIntValue(4321), GetIntValue(0), GetIntValue(9876)
  1100. ], [
  1101. GetIntValue(5678), GetIntValue(6789)
  1102. ], [0, 1], TValue.Empty);
  1103. end;
  1104. procedure TTestDirectIntfCalls.CallTestMethod21s(aIntf: ITestInterface);
  1105. var
  1106. S1,S2,S3,S4 : AnsiString;
  1107. begin
  1108. S1:='Alpha';
  1109. S2:='Beta';
  1110. S3:='';
  1111. S4:='Delta';
  1112. aIntf.TestMethod21(s1,s2,s3,s4);
  1113. SetLength(RecordedOutputArgs,2);
  1114. TValue.Make(@S1,TypeInfo(AnsiString),RecordedOutputArgs[0]);
  1115. TValue.Make(@S2,TypeInfo(AnsiString),RecordedOutputArgs[1]);
  1116. end;
  1117. procedure TTestDirectIntfCalls.Test21s;
  1118. begin
  1119. DoTestIntfImpl(@CallTestMethod21s, 'TestMethod21', [
  1120. GetAnsiString('Alpha'), GetAnsiString('Beta'), GetAnsiString(''), GetAnsiString('Delta')
  1121. ], [
  1122. GetAnsiString('Gamma'), GetAnsiString('Epsilon')
  1123. ], [0, 1], TValue.Empty);
  1124. end;
  1125. procedure TTestDirectIntfCalls.CallTestMethod22(aIntf: ITestInterface);
  1126. var
  1127. S1,S2,S3,S4 : ShortString;
  1128. begin
  1129. S1:='Alpha';
  1130. S2:='Beta';
  1131. S3:='';
  1132. S4:='Delta';
  1133. aIntf.TestMethod21(s1,s2,s3,s4);
  1134. SetLength(RecordedOutputArgs,2);
  1135. TValue.Make(@S1,TypeInfo(ShortString),RecordedOutputArgs[0]);
  1136. TValue.Make(@S2,TypeInfo(ShortString),RecordedOutputArgs[1]);
  1137. end;
  1138. procedure TTestDirectIntfCalls.Test22;
  1139. begin
  1140. { for some reason this fails, though it fails in Delphi as well :/ }
  1141. (*
  1142. DoTestIntfImpl(@CallTestMethod22, 'TestMethod21', [
  1143. GetShortString('Alpha'), GetShortString('Beta'), GetShortString(''), GetShortString('Delta')
  1144. ], [
  1145. GetShortString('Gamma'), GetShortString('Epsilon')
  1146. ], [0, 1], TValue.Empty);
  1147. *)
  1148. end;
  1149. { TTestMethodVars }
  1150. {$ifdef fpc}
  1151. procedure TTestMethodVars.TestMethodVar1;
  1152. begin
  1153. DoMethodImpl(TypeInfo(TTestMethod1),[], [], [], TValue.Empty);
  1154. end;
  1155. procedure TTestMethodVars.TestMethodVar2;
  1156. begin
  1157. DoMethodImpl(TypeInfo(TTestMethod2),[GetIntValue(42)], [], [], GetIntValue(21));
  1158. end;
  1159. procedure TTestMethodVars.TestMethodVar3;
  1160. begin
  1161. DoMethodImpl(TypeInfo(TTestMethod3),[GetAnsiString('Hello World')], [], [], TValue.Empty);
  1162. end;
  1163. procedure TTestMethodVars.TestMethodVar4;
  1164. begin
  1165. DoMethodImpl(TypeInfo(TTestMethod4),[GetShortString('Hello World')], [], [], TValue.Empty);
  1166. end;
  1167. procedure TTestMethodVars.TestMethodVar5;
  1168. begin
  1169. DoMethodImpl(TypeInfo(TTestMethod5),[], [], [], GetAnsiString('Hello World'));
  1170. end;
  1171. procedure TTestMethodVars.TestMethodVar6;
  1172. begin
  1173. DoMethodImpl(TypeInfo(TTestMethod6),[], [], [], GetShortString('Hello World'));
  1174. end;
  1175. procedure TTestMethodVars.TestMethodVar7;
  1176. begin
  1177. DoMethodImpl(TypeInfo(TTestMethod7),[
  1178. GetIntValue(1234), GetIntValue(4321), GetIntValue(0), GetIntValue(9876)
  1179. ], [
  1180. GetIntValue(5678), GetIntValue(6789)
  1181. ], [1, 2], TValue.Empty);
  1182. end;
  1183. procedure TTestMethodVars.TestMethodVar8;
  1184. begin
  1185. DoMethodImpl(TypeInfo(TTestMethod8),[
  1186. GetAnsiString('Alpha'), GetAnsiString('Beta'), GetAnsiString(''), GetAnsiString('Delta')
  1187. ], [
  1188. GetAnsiString('Gamma'), GetAnsiString('Epsilon')
  1189. ], [1, 2], TValue.Empty);
  1190. end;
  1191. procedure TTestMethodVars.TestMethodVar9;
  1192. begin
  1193. DoMethodImpl(TypeInfo(TTestMethod9),[
  1194. GetShortString('Alpha'), GetShortString('Beta'), GetShortString(''), GetShortString('Delta')
  1195. ], [
  1196. GetShortString('Gamma'), GetShortString('Epsilon')
  1197. ], [1, 2], TValue.Empty);
  1198. end;
  1199. procedure TTestMethodVars.TestMethodVar10;
  1200. begin
  1201. DoMethodImpl(TypeInfo(TTestMethod10),[
  1202. GetSingleValue(SingleArg1), GetSingleValue(SingleArg2In), GetSingleValue(0), GetSingleValue(SingleArg4)
  1203. ], [
  1204. GetSingleValue(SingleArg2Out), GetSingleValue(SingleArg3Out)
  1205. ], [1, 2], TValue.Empty);
  1206. end;
  1207. procedure TTestMethodVars.TestMethodVar11;
  1208. begin
  1209. DoMethodImpl(TypeInfo(TTestMethod11),[
  1210. GetDoubleValue(DoubleArg1), GetDoubleValue(DoubleArg2In), GetDoubleValue(0), GetDoubleValue(DoubleArg4)
  1211. ], [
  1212. GetDoubleValue(DoubleArg2Out), GetDoubleValue(DoubleArg3Out)
  1213. ], [1, 2], TValue.Empty);
  1214. end;
  1215. procedure TTestMethodVars.TestMethodVar12;
  1216. begin
  1217. DoMethodImpl(TypeInfo(TTestMethod12),[
  1218. GetExtendedValue(ExtendedArg1), GetExtendedValue(ExtendedArg2In), GetExtendedValue(0), GetExtendedValue(ExtendedArg4)
  1219. ], [
  1220. GetExtendedValue(ExtendedArg2Out), GetExtendedValue(ExtendedArg3Out)
  1221. ], [1, 2], TValue.Empty);
  1222. end;
  1223. procedure TTestMethodVars.TestMethodVar13;
  1224. begin
  1225. DoMethodImpl(TypeInfo(TTestMethod13),[
  1226. GetCompValue(CompArg1), GetCompValue(CompArg2In), GetCompValue(0), GetCompValue(CompArg4)
  1227. ], [
  1228. GetCompValue(CompArg2Out), GetCompValue(CompArg3Out)
  1229. ], [1, 2], TValue.Empty);
  1230. end;
  1231. procedure TTestMethodVars.TestMethodVar14;
  1232. begin
  1233. DoMethodImpl(TypeInfo(TTestMethod14),[
  1234. GetCurrencyValue(CurrencyArg1), GetCurrencyValue(CurrencyArg2In), GetCurrencyValue(0), GetCurrencyValue(CurrencyArg4)
  1235. ], [
  1236. GetCurrencyValue(CurrencyArg2Out), GetCurrencyValue(CurrencyArg3Out)
  1237. ], [1, 2], TValue.Empty);
  1238. end;
  1239. procedure TTestMethodVars.TestMethodVar15;
  1240. begin
  1241. DoMethodImpl(TypeInfo(TTestMethod15),[
  1242. GetIntValue(1), GetIntValue(2), GetIntValue(3), GetIntValue(4), GetIntValue(5),
  1243. GetIntValue(6), GetIntValue(7), GetIntValue(8), GetIntValue(9), GetIntValue(10)
  1244. ], [], [], GetIntValue(11));
  1245. end;
  1246. procedure TTestMethodVars.TestMethodVar16;
  1247. begin
  1248. DoMethodImpl(TypeInfo(TTestMethod16),[
  1249. GetSingleValue(SingleAddArg1), GetSingleValue(SingleAddArg2), GetSingleValue(SingleAddArg3), GetSingleValue(SingleAddArg4), GetSingleValue(SingleAddArg5),
  1250. GetSingleValue(SingleAddArg6), GetSingleValue(SingleAddArg7), GetSingleValue(SingleAddArg8), GetSingleValue(SingleAddArg9), GetSingleValue(SingleAddArg10)
  1251. ], [], [], GetSingleValue(SingleAddRes));
  1252. end;
  1253. procedure TTestMethodVars.TestMethodVar17;
  1254. begin
  1255. DoMethodImpl(TypeInfo(TTestMethod17),[
  1256. GetDoubleValue(DoubleAddArg1), GetDoubleValue(DoubleAddArg2), GetDoubleValue(DoubleAddArg3), GetDoubleValue(DoubleAddArg4), GetDoubleValue(DoubleAddArg5),
  1257. GetDoubleValue(DoubleAddArg6), GetDoubleValue(DoubleAddArg7), GetDoubleValue(DoubleAddArg8), GetDoubleValue(DoubleAddArg9), GetDoubleValue(DoubleAddArg10)
  1258. ], [], [], GetDoubleValue(DoubleAddRes));
  1259. end;
  1260. procedure TTestMethodVars.TestMethodVar18;
  1261. begin
  1262. DoMethodImpl(TypeInfo(TTestMethod18),[
  1263. GetExtendedValue(ExtendedAddArg1), GetExtendedValue(ExtendedAddArg2), GetExtendedValue(ExtendedAddArg3), GetExtendedValue(ExtendedAddArg4), GetExtendedValue(ExtendedAddArg5),
  1264. GetExtendedValue(ExtendedAddArg6), GetExtendedValue(ExtendedAddArg7), GetExtendedValue(ExtendedAddArg8), GetExtendedValue(ExtendedAddArg9), GetExtendedValue(ExtendedAddArg10)
  1265. ], [], [], GetExtendedValue(ExtendedAddRes));
  1266. end;
  1267. procedure TTestMethodVars.TestMethodVar19;
  1268. begin
  1269. DoMethodImpl(TypeInfo(TTestMethod19),[
  1270. GetCompValue(CompAddArg1), GetCompValue(CompAddArg2), GetCompValue(CompAddArg3), GetCompValue(CompAddArg4), GetCompValue(CompAddArg5),
  1271. GetCompValue(CompAddArg6), GetCompValue(CompAddArg7), GetCompValue(CompAddArg8), GetCompValue(CompAddArg9), GetCompValue(CompAddArg10)
  1272. ], [], [], GetCompValue(CompAddRes));
  1273. end;
  1274. procedure TTestMethodVars.TestMethodVar20;
  1275. begin
  1276. DoMethodImpl(TypeInfo(TTestMethod20),[
  1277. GetCurrencyValue(CurrencyAddArg1), GetCurrencyValue(CurrencyAddArg2), GetCurrencyValue(CurrencyAddArg3), GetCurrencyValue(CurrencyAddArg4), GetCurrencyValue(CurrencyAddArg5),
  1278. GetCurrencyValue(CurrencyAddArg6), GetCurrencyValue(CurrencyAddArg7), GetCurrencyValue(CurrencyAddArg8), GetCurrencyValue(CurrencyAddArg9), GetCurrencyValue(CurrencyAddArg10)
  1279. ], [], [], GetCurrencyValue(CurrencyAddRes));
  1280. end;
  1281. procedure TTestMethodVars.TestMethodVar21;
  1282. begin
  1283. DoMethodImpl(TypeInfo(TTestMethod21),[
  1284. GetIntValue(1234), GetIntValue(4321), GetIntValue(0), GetIntValue(9876)
  1285. ], [
  1286. GetIntValue(5678), GetIntValue(6789)
  1287. ], [0, 1], TValue.Empty);
  1288. end;
  1289. procedure TTestMethodVars.TestMethodVar21as;
  1290. begin
  1291. DoMethodImpl(TypeInfo(TTestMethod21),[
  1292. GetAnsiString('Alpha'), GetAnsiString('Beta'), GetAnsiString(''), GetAnsiString('Delta')
  1293. ], [
  1294. GetAnsiString('Gamma'), GetAnsiString('Epsilon')
  1295. ], [0, 1], TValue.Empty);
  1296. end;
  1297. procedure TTestMethodVars.TestMethodVar21ss;
  1298. begin
  1299. { for some reason this fails, though it fails in Delphi as well :/ }
  1300. (*
  1301. DoMethodImpl(TypeInfo(TTestMethod21),[
  1302. GetShortString('Alpha'), GetShortString('Beta'), GetShortString(''), GetShortString('Delta')
  1303. ], [
  1304. GetShortString('Gamma'), GetShortString('Epsilon')
  1305. ], [0, 1], TValue.Empty);
  1306. *)
  1307. end;
  1308. { TTestProcVars }
  1309. procedure TTestProcVars.TestProcVar1;
  1310. begin
  1311. DoProcImpl(TypeInfo(TTestProc1),[], [], [], TValue.Empty);
  1312. end;
  1313. procedure TTestProcVars.TestProcVar2;
  1314. begin
  1315. DoProcImpl(TypeInfo(TTestProc2),[GetIntValue(42)], [], [], GetIntValue(21));
  1316. end;
  1317. procedure TTestProcVars.TestProcVar3;
  1318. begin
  1319. DoProcImpl(TypeInfo(TTestProc3),[GetAnsiString('Hello World')], [], [], TValue.Empty);
  1320. end;
  1321. procedure TTestProcVars.TestProcVar4;
  1322. begin
  1323. DoProcImpl(TypeInfo(TTestProc4),[GetShortString('Hello World')], [], [], TValue.Empty);
  1324. end;
  1325. procedure TTestProcVars.TestProcVar5;
  1326. begin
  1327. DoProcImpl(TypeInfo(TTestProc5),[], [], [], GetAnsiString('Hello World'));
  1328. end;
  1329. procedure TTestProcVars.TestProcVar6;
  1330. begin
  1331. DoProcImpl(TypeInfo(TTestProc6),[], [], [], GetShortString('Hello World'));
  1332. end;
  1333. procedure TTestProcVars.TestProcVar7;
  1334. begin
  1335. DoProcImpl(TypeInfo(TTestProc7),[
  1336. GetIntValue(1234), GetIntValue(4321), GetIntValue(0), GetIntValue(9876)
  1337. ], [
  1338. GetIntValue(5678), GetIntValue(6789)
  1339. ], [1, 2], TValue.Empty);
  1340. end;
  1341. procedure TTestProcVars.TestProcVar8;
  1342. begin
  1343. DoProcImpl(TypeInfo(TTestProc8),[
  1344. GetAnsiString('Alpha'), GetAnsiString('Beta'), GetAnsiString(''), GetAnsiString('Delta')
  1345. ], [
  1346. GetAnsiString('Gamma'), GetAnsiString('Epsilon')
  1347. ], [1, 2], TValue.Empty);
  1348. end;
  1349. procedure TTestProcVars.TestProcVar9;
  1350. begin
  1351. DoProcImpl(TypeInfo(TTestProc9),[
  1352. GetShortString('Alpha'), GetShortString('Beta'), GetShortString(''), GetShortString('Delta')
  1353. ], [
  1354. GetShortString('Gamma'), GetShortString('Epsilon')
  1355. ], [1, 2], TValue.Empty);
  1356. end;
  1357. procedure TTestProcVars.TestProcVar10;
  1358. begin
  1359. DoProcImpl(TypeInfo(TTestProc10),[
  1360. GetSingleValue(SingleArg1), GetSingleValue(SingleArg2In), GetSingleValue(0), GetSingleValue(SingleArg4)
  1361. ], [
  1362. GetSingleValue(SingleArg2Out), GetSingleValue(SingleArg3Out)
  1363. ], [1, 2], TValue.Empty);
  1364. end;
  1365. procedure TTestProcVars.TestProcVar11;
  1366. begin
  1367. DoProcImpl(TypeInfo(TTestProc11),[
  1368. GetDoubleValue(DoubleArg1), GetDoubleValue(DoubleArg2In), GetDoubleValue(0), GetDoubleValue(DoubleArg4)
  1369. ], [
  1370. GetDoubleValue(DoubleArg2Out), GetDoubleValue(DoubleArg3Out)
  1371. ], [1, 2], TValue.Empty);
  1372. end;
  1373. procedure TTestProcVars.TestProcVar12;
  1374. begin
  1375. DoProcImpl(TypeInfo(TTestProc12),[
  1376. GetExtendedValue(ExtendedArg1), GetExtendedValue(ExtendedArg2In), GetExtendedValue(0), GetExtendedValue(ExtendedArg4)
  1377. ], [
  1378. GetExtendedValue(ExtendedArg2Out), GetExtendedValue(ExtendedArg3Out)
  1379. ], [1, 2], TValue.Empty);
  1380. end;
  1381. procedure TTestProcVars.TestProcVar13;
  1382. begin
  1383. DoProcImpl(TypeInfo(TTestProc13),[
  1384. GetCompValue(CompArg1), GetCompValue(CompArg2In), GetCompValue(0), GetCompValue(CompArg4)
  1385. ], [
  1386. GetCompValue(CompArg2Out), GetCompValue(CompArg3Out)
  1387. ], [1, 2], TValue.Empty);
  1388. end;
  1389. procedure TTestProcVars.TestProcVar14;
  1390. begin
  1391. DoProcImpl(TypeInfo(TTestProc14),[
  1392. GetCurrencyValue(CurrencyArg1), GetCurrencyValue(CurrencyArg2In), GetCurrencyValue(0), GetCurrencyValue(CurrencyArg4)
  1393. ], [
  1394. GetCurrencyValue(CurrencyArg2Out), GetCurrencyValue(CurrencyArg3Out)
  1395. ], [1, 2], TValue.Empty);
  1396. end;
  1397. procedure TTestProcVars.TestProcVar15;
  1398. begin
  1399. DoProcImpl(TypeInfo(TTestProc15),[
  1400. GetIntValue(1), GetIntValue(2), GetIntValue(3), GetIntValue(4), GetIntValue(5),
  1401. GetIntValue(6), GetIntValue(7), GetIntValue(8), GetIntValue(9), GetIntValue(10)
  1402. ], [], [], GetIntValue(11));
  1403. end;
  1404. procedure TTestProcVars.TestProcVar16;
  1405. begin
  1406. DoProcImpl(TypeInfo(TTestProc16),[
  1407. GetSingleValue(SingleAddArg1), GetSingleValue(SingleAddArg2), GetSingleValue(SingleAddArg3), GetSingleValue(SingleAddArg4), GetSingleValue(SingleAddArg5),
  1408. GetSingleValue(SingleAddArg6), GetSingleValue(SingleAddArg7), GetSingleValue(SingleAddArg8), GetSingleValue(SingleAddArg9), GetSingleValue(SingleAddArg10)
  1409. ], [], [], GetSingleValue(SingleAddRes));
  1410. end;
  1411. procedure TTestProcVars.TestProcVar17;
  1412. begin
  1413. DoProcImpl(TypeInfo(TTestProc17),[
  1414. GetDoubleValue(DoubleAddArg1), GetDoubleValue(DoubleAddArg2), GetDoubleValue(DoubleAddArg3), GetDoubleValue(DoubleAddArg4), GetDoubleValue(DoubleAddArg5),
  1415. GetDoubleValue(DoubleAddArg6), GetDoubleValue(DoubleAddArg7), GetDoubleValue(DoubleAddArg8), GetDoubleValue(DoubleAddArg9), GetDoubleValue(DoubleAddArg10)
  1416. ], [], [], GetDoubleValue(DoubleAddRes));
  1417. end;
  1418. procedure TTestProcVars.TestProcVar18;
  1419. begin
  1420. DoProcImpl(TypeInfo(TTestProc18),[
  1421. GetExtendedValue(ExtendedAddArg1), GetExtendedValue(ExtendedAddArg2), GetExtendedValue(ExtendedAddArg3), GetExtendedValue(ExtendedAddArg4), GetExtendedValue(ExtendedAddArg5),
  1422. GetExtendedValue(ExtendedAddArg6), GetExtendedValue(ExtendedAddArg7), GetExtendedValue(ExtendedAddArg8), GetExtendedValue(ExtendedAddArg9), GetExtendedValue(ExtendedAddArg10)
  1423. ], [], [], GetExtendedValue(ExtendedAddRes));
  1424. end;
  1425. procedure TTestProcVars.TestProcVar19;
  1426. begin
  1427. DoProcImpl(TypeInfo(TTestProc19),[
  1428. GetCompValue(CompAddArg1), GetCompValue(CompAddArg2), GetCompValue(CompAddArg3), GetCompValue(CompAddArg4), GetCompValue(CompAddArg5),
  1429. GetCompValue(CompAddArg6), GetCompValue(CompAddArg7), GetCompValue(CompAddArg8), GetCompValue(CompAddArg9), GetCompValue(CompAddArg10)
  1430. ], [], [], GetCompValue(CompAddRes));
  1431. end;
  1432. procedure TTestProcVars.TestProcVar20;
  1433. begin
  1434. DoProcImpl(TypeInfo(TTestProc20),[
  1435. GetCurrencyValue(CurrencyAddArg1), GetCurrencyValue(CurrencyAddArg2), GetCurrencyValue(CurrencyAddArg3), GetCurrencyValue(CurrencyAddArg4), GetCurrencyValue(CurrencyAddArg5),
  1436. GetCurrencyValue(CurrencyAddArg6), GetCurrencyValue(CurrencyAddArg7), GetCurrencyValue(CurrencyAddArg8), GetCurrencyValue(CurrencyAddArg9), GetCurrencyValue(CurrencyAddArg10)
  1437. ], [], [], GetCurrencyValue(CurrencyAddRes));
  1438. end;
  1439. procedure TTestProcVars.TestProcVar21;
  1440. begin
  1441. DoProcImpl(TypeInfo(TTestProc21),[
  1442. GetIntValue(1234), GetIntValue(4321), GetIntValue(0), GetIntValue(9876)
  1443. ], [
  1444. GetIntValue(5678), GetIntValue(6789)
  1445. ], [0, 1], TValue.Empty);
  1446. end;
  1447. procedure TTestProcVars.TestProcVar21as;
  1448. begin
  1449. DoProcImpl(TypeInfo(TTestProc21),[
  1450. GetAnsiString('Alpha'), GetAnsiString('Beta'), GetAnsiString(''), GetAnsiString('Delta')
  1451. ], [
  1452. GetAnsiString('Gamma'), GetAnsiString('Epsilon')
  1453. ], [0, 1], TValue.Empty);
  1454. end;
  1455. procedure TTestProcVars.TestProcVar21ss;
  1456. begin
  1457. { for some reason this fails, though it fails in Delphi as well :/ }
  1458. {
  1459. DoProcImpl(TypeInfo(TTestProc21),[
  1460. GetShortString('Alpha'), GetShortString('Beta'), GetShortString(''), GetShortString('Delta')
  1461. ], [
  1462. GetShortString('Gamma'), GetShortString('Epsilon')
  1463. ], [0, 1], TValue.Empty);}
  1464. end;
  1465. {$endif fpc}
  1466. initialization
  1467. {$ifdef fpc}
  1468. RegisterTest(TTestIntfMethods);
  1469. RegisterTest(TTestMethodVars);
  1470. RegisterTest(TTestProcVars);
  1471. RegisterTest(TTestDirectIntfCalls)
  1472. {$else fpc}
  1473. RegisterTest(TTestIntfMethods.Suite);
  1474. {$endif fpc}
  1475. end.