From 1c2a7d6b1d5837f7a58f9294b591bf2cdb7e94e6 Mon Sep 17 00:00:00 2001 From: Pan Block Date: Fri, 15 May 2026 16:34:10 -0700 Subject: [PATCH] copy mck1117 --- Source/Mock/lhc_mock.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Source/Mock/lhc_mock.cpp b/Source/Mock/lhc_mock.cpp index 73c276ec..c1fb2d7b 100644 --- a/Source/Mock/lhc_mock.cpp +++ b/Source/Mock/lhc_mock.cpp @@ -60,8 +60,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)) { @@ -128,6 +128,21 @@ 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.begin(), + mocks.end(), + [originalCall](auto m) + { + return DoesMockCallMatch(m, originalCall); + }); + + if (countMatching > 1) + { + HCMockRemoveMock(mock); + } + return true; }