sal/qa/systools/test_retry_if_failed.cxx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
New commits: commit b3bfcb2805f45f250540932c1d93216278d1cafb Author: Mike Kaganski <mikekagan...@hotmail.com> AuthorDate: Thu Mar 4 15:04:12 2021 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Mar 4 17:53:58 2021 +0100 Also check number of invocations in the test Change-Id: I4180f14aa633bf0f3f45178c1fd02b52b784f7e3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111960 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sal/qa/systools/test_retry_if_failed.cxx b/sal/qa/systools/test_retry_if_failed.cxx index 7df83cb229a1..a218b3e9ff99 100644 --- a/sal/qa/systools/test_retry_if_failed.cxx +++ b/sal/qa/systools/test_retry_if_failed.cxx @@ -20,27 +20,31 @@ class test_retry_if_failed : public CppUnit::TestFixture public: void test_success() { + unsigned counter = 0; const DWORD nTicksBefore = GetTickCount(); - HRESULT hr = sal::systools::RetryIfFailed(10, 200, Tester(5)); + HRESULT hr = sal::systools::RetryIfFailed(10, 200, Tester(5, counter)); const DWORD nTicksAfter = GetTickCount(); const DWORD nTicksElapsed = nTicksAfter > nTicksBefore ? nTicksAfter - nTicksBefore : std::numeric_limits<DWORD>::max() - nTicksBefore + nTicksAfter; CPPUNIT_ASSERT(SUCCEEDED(hr)); // 5 attempts, 4 sleeps by ~200 ms + CPPUNIT_ASSERT_EQUAL(5U, counter); CPPUNIT_ASSERT_GREATER(DWORD(800 - ClockRes), nTicksElapsed); } void test_failure() { + unsigned counter = 0; const DWORD nTicksBefore = GetTickCount(); - HRESULT hr = sal::systools::RetryIfFailed(10, 100, Tester(15)); + HRESULT hr = sal::systools::RetryIfFailed(10, 100, Tester(15, counter)); const DWORD nTicksAfter = GetTickCount(); const DWORD nTicksElapsed = nTicksAfter > nTicksBefore ? nTicksAfter - nTicksBefore : std::numeric_limits<DWORD>::max() - nTicksBefore + nTicksAfter; CPPUNIT_ASSERT(FAILED(hr)); // 1 + 10 attempts, 10 sleeps by ~100 ms + CPPUNIT_ASSERT_EQUAL(11U, counter); CPPUNIT_ASSERT_GREATER(DWORD(1000 - ClockRes), nTicksElapsed); } @@ -52,18 +56,16 @@ public: private: struct Tester { - Tester(unsigned triesBeforeSuccess) + Tester(unsigned triesBeforeSuccess, unsigned& counter) : m_nTriesBeforeSuccess(triesBeforeSuccess) + , m_rCounter(counter) { } - HRESULT operator()() - { - return ++m_nTriesAttempted >= m_nTriesBeforeSuccess ? S_OK : E_FAIL; - } + HRESULT operator()() { return ++m_rCounter >= m_nTriesBeforeSuccess ? S_OK : E_FAIL; } unsigned m_nTriesBeforeSuccess; - unsigned m_nTriesAttempted = 0; + unsigned& m_rCounter; }; }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits