Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure what the problem in your case is, but when I run the following code with the <a href="https://github.com/dascandy/hippomocks" rel="nofollow">version form the git repoitory</a> </p> <pre><code>struct IColumn { virtual std::string getValue() = 0; }; struct IRecord { virtual IColumn&amp; at( std::string ) = 0; }; void main() { MockRepository mocks; auto mockRec = mocks.Mock&lt;IRecord&gt;(); auto mockCol = mocks.Mock&lt;IColumn&gt;(); auto&amp; firstCall = mocks.OnCall(mockRec, IRecord::at).With("firstName").Return(std::ref(*mockCol)); mocks.OnCall(mockCol, IColumn::getValue).After(firstCall).Return(std::string("John")); auto&amp; lastCall = mocks.OnCall(mockRec, IRecord::at).With("lastName").Return(std::ref(*mockCol)); mocks.OnCall(mockCol, IColumn::getValue).After(lastCall).Return(std::string("Doe")); std::cout &lt;&lt; mockRec-&gt;at("firstName").getValue() &lt;&lt; " " &lt;&lt; mockRec-&gt;at("lastName").getValue() &lt;&lt; "\n"; } </code></pre> <p>I get the correct output.</p> <pre><code>John Doe </code></pre> <p>I find that I almost always use</p> <pre><code>mocks.autoExpect = false; </code></pre> <p>but in this case it doesn't make any difference. </p> <p><strong>Edit:</strong></p> <p>If you require more flexibility, you can do something like this:</p> <pre><code>std::vector&lt;IColumn*&gt; cols; cols.push_back( mocks.Mock&lt;IColumn&gt;() ); cols.push_back( mocks.Mock&lt;IColumn&gt;() ); mocks.OnCall(mockRec, IRecord::at).With("firstName") .Return(std::ref(*cols[0])); mocks.OnCall(mockRec, IRecord::at).With("lastName") .Return(std::ref(*cols[1])); mocks.OnCall(cols[0], IColumn::getValue) .Return(std::string("John")); mocks.OnCall(cols[1], IColumn::getValue) .Return(std::string("Doe")); </code></pre> <p>which will work in any order of the calls. Alternatively you can also use <code>Do</code></p> <pre><code>std::map&lt;std::string, IColumn*&gt; map; map["firstName"] = mocks.Mock&lt;IColumn&gt;(); map["lastName"] = mocks.Mock&lt;IColumn&gt;(); mocks.OnCall(mockRec, IRecord::at) .Do( [&amp;map]( std::string&amp; key){ return std::ref(*map[key]); } ); mocks.OnCall(map["firstName"], IColumn::getValue) .Return(std::string("John")); mocks.OnCall(map["lastName"], IColumn::getValue) .Return(std::string("Doe")); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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