RudeMocks/Ordered and Unordered Expectation Recording
From Wiki
Table of Contents
- RudeMocks/Introduction
- RudeMocks/Basic Usage
- RudeMocks/Mocking Classes
- RudeMocks/Mocking Free Functions
- RudeMocks/Setting Up Expectations
- RudeMocks/Out and In-Out Arguments
- RudeMocks/Returning Non-Default Constructible Objects
- RudeMocks/Ordered and Unordered Expectation Recording
- RudeMocks/Ignoring Unexpected Calls
Ordered and Unordered
The mock repository has two main modes of operation when recording expectations: ordered and unordered mode. In ordered mode expectations are verified in the exact same order as they are recorded. In unordered mode functions can be called in arbitrary order when replaying. So the order of recording expectations does not matter. The mock repository can be switched between ordered and unordered mode at any time during recording by calling the Ordered() or Unordered() functions. By default, expectation recording is ordered.
Example
MockRepository mocks; RegisterFunctions(mocks.CreateFreeFunctionMock(), &FunctionA, &FunctionB, &FunctionC, &FunctionD); // Initially the mock repository is in ordered mode. So the order of the following expectation calls matters. // Here we expect FunctionA to be called _before_ FunctionB. FunctionA(); FunctionB(); // Switch the repository to unordered. Now the order of expectation calls does not matter. mocks.Unordered(); // We expect calls to FunctionC and FunctionD, but the order doesn't matter. FunctionD(); FunctionC(); mocks.Replay(); // The following call order will verify successfully. FunctionA(); FunctionB(); FunctionC(); FunctionD(); mocks.Verify();
Note that the following call order would have verified successfully as well:
FunctionA(); FunctionB(); FunctionD(); FunctionC();
But this call order wouldn't verify because the order of FunctionA and FunctionB is incorrect:
FunctionB(); FunctionA(); FunctionC(); FunctionD();