I'm currently in the process of getting started with unit testing and mocking for good and I stumbled over the following method that I can't seem to fabricate a working mock implementation for:
function GetInstance(const AIID: TGUID;
out AInstance;
const AArgs: array of const;
const AContextID: TImplContextID = CID_DEFAULT): Boolean;
(TImplContextID
is just a type alias for Integer)
This is how far I got:
function TImplementationProviderMock.GetInstance(
const AIID: TGUID;
out AInstance;
const AArgs: array of const;
const AContextID: TImplContextID): Boolean;
var
lCall: TMockMethod;
begin
lCall := AddCall('GetInstance').WithParams([@AIID, AContextID]);
Pointer(AInstance) := FindVarData(lCall.OutParams[0]).VPointer;
Result := lCall.ReturnValue;
end;
But I haven't been able to figure out how I am supposed to mock the open array parameter AArgs
. Any ideas?
Also, is there maybe a simpler way to to return the out
-parameter AInstance
and is using the @
-notation for the TGUID
-typed parameter (essentially a record, i.e. a value type) the right way to go?
Is it possible to mock this method with the current version of PascalMock at all?
Update 2: I have now cut down the question text for clarity. Originally it contained the following erroneous implementation of the mock method which was what Mason's reply refers to:
function TImplementationProviderMock.GetInstance(
const AIID: TGUID;
out AInstance;
const AArgs: array of const;
const AContextID: TImplContextID): Boolean;
begin
Result := AddCall('GetInstance')
.WithParams([@AIID, AContextID])
.ReturnsOutParams([AInstance])
.ReturnValue;
end;
In this the compiler complained about the .ReturnsOutParams([AInstance])
saying "Bad argument type in variable type array constructor.".