From 242a3c0558be6bd4cf1699883c4656270c51247e Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 5 Nov 2020 13:57:06 -0800 Subject: [PATCH 1/2] change multi mock behavior --- Source/Mock/lhc_mock.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Mock/lhc_mock.cpp b/Source/Mock/lhc_mock.cpp index 43c2be16..a19c74d4 100644 --- a/Source/Mock/lhc_mock.cpp +++ b/Source/Mock/lhc_mock.cpp @@ -54,8 +54,8 @@ bool Mock_Internal_HCHttpCallPerformAsync( auto& mocks{ httpSingleton->m_mocks }; HC_MOCK_CALL* mock{ nullptr }; - // Use the most recently added mock that matches (similar to a stack). - for (auto iter = mocks.rbegin(); iter != mocks.rend(); ++iter) + // Use the first mock that matches this call + for (auto iter = mocks.begin(); iter != mocks.end(); ++iter) { if (DoesMockCallMatch(*iter, originalCall)) { @@ -106,5 +106,17 @@ bool Mock_Internal_HCHttpCallPerformAsync( HCHttpCallResponseSetHeader(originalCall, str1, str2); } + // If this is not the only mock that matches, remove it from the list of mocks so that multiple can be used in sequence + auto countMatching = std::count_if(mocks.rbegin(), mocks.rend(), [originalCall](auto m) + { + return DoesMockCallMatch(m, originalCall); + } + ); + + if (countMatching > 1) + { + HCMockRemoveMock(mock); + } + return true; } From 065f4c74cc76794322fe43a2d824fd340455ea1e Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 6 Nov 2020 01:52:15 -0800 Subject: [PATCH 2/2] use correct iterators --- Source/Mock/lhc_mock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Mock/lhc_mock.cpp b/Source/Mock/lhc_mock.cpp index a19c74d4..a9b6a815 100644 --- a/Source/Mock/lhc_mock.cpp +++ b/Source/Mock/lhc_mock.cpp @@ -107,7 +107,7 @@ bool Mock_Internal_HCHttpCallPerformAsync( } // If this is not the only mock that matches, remove it from the list of mocks so that multiple can be used in sequence - auto countMatching = std::count_if(mocks.rbegin(), mocks.rend(), [originalCall](auto m) + auto countMatching = std::count_if(mocks.begin(), mocks.end(), [originalCall](auto m) { return DoesMockCallMatch(m, originalCall); }