Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I mock a method with an open array parameter in PascalMock?
    text
    copied!<p>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:</p> <pre><code>function GetInstance(const AIID: TGUID; out AInstance; const AArgs: array of const; const AContextID: TImplContextID = CID_DEFAULT): Boolean; </code></pre> <p><em>(<code>TImplContextID</code> is just a type alias for Integer)</em></p> <p>This is how far I got:</p> <pre><code>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; </code></pre> <p>But I haven't been able to figure out how I am supposed to mock the open array parameter <code>AArgs</code>. Any ideas?</p> <p>Also, is there maybe a simpler way to to return the <code>out</code>-parameter <code>AInstance</code> and is using the <code>@</code>-notation for the <code>TGUID</code>-typed parameter (essentially a record, i.e. a value type) the right way to go?</p> <p>Is it possible to mock this method with the current version of PascalMock at all?</p> <hr> <p><strong>Update 2:</strong> 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:</p> <pre><code>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; </code></pre> <p>In this the compiler complained about the <code>.ReturnsOutParams([AInstance])</code> saying "Bad argument type in variable type array constructor.".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload