From ce7e3ca493d8aebe60148f6b41caf840ae0c8d95 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 9 Jul 2020 11:34:47 +0300 Subject: [PATCH] [base] Review fixes. Adding tests which check that wrapped methods are called only once. --- base/base_tests/exception_tests.cpp | 77 +++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/base/base_tests/exception_tests.cpp b/base/base_tests/exception_tests.cpp index dfa3512387..8b173f41ec 100644 --- a/base/base_tests/exception_tests.cpp +++ b/base/base_tests/exception_tests.cpp @@ -39,16 +39,83 @@ UNIT_TEST(ExceptionCatcher_Functions) ExceptionCatcher("Function with arg.", FuncThrowsNumberArg, 7); } -UNIT_TEST(ExceptionCatcher_Lambdas) +UNIT_TEST(ExceptionCatcher_LambdasReturnInt) { + size_t callCount = 0; ExceptionCatcher( - "Lambda", [](int) { return 1; }, 7); + "Lambda", + [&callCount](int) { + ++callCount; + return 1; + }, + 7); + TEST_EQUAL(callCount, 1, ()); + ExceptionCatcher( - "Lambda", [](int) -> int { throw RootException("RootException", "RootException"); }, 7); + "Lambda", + [&callCount](int) -> int { + ++callCount; + throw RootException("RootException", "RootException"); + }, + 7); + TEST_EQUAL(callCount, 2, ()); + ExceptionCatcher( - "Lambda", [](int) -> int { throw std::exception(); }, 7); + "Lambda", + [&callCount](int) -> int { + ++callCount; + throw std::exception(); + }, + 7); + TEST_EQUAL(callCount, 3, ()); + ExceptionCatcher( - "Lambda", [](int) -> int { throw 1; }, 7); + "Lambda", + [&callCount](int) -> int { + ++callCount; + throw 1; + }, + 7); + TEST_EQUAL(callCount, 4, ()); +} + +UNIT_TEST(ExceptionCatcher_LambdasReturnVoid) +{ + size_t callCount = 0; + ExceptionCatcher( + "Lambda", + [&callCount](int) { + ++callCount; + }, + 7); + TEST_EQUAL(callCount, 1, ()); + + ExceptionCatcher( + "Lambda", + [&callCount](int) { + ++callCount; + throw RootException("RootException", "RootException"); + }, + 7); + TEST_EQUAL(callCount, 2, ()); + + ExceptionCatcher( + "Lambda", + [&callCount](int) { + ++callCount; + throw std::exception(); + }, + 7); + TEST_EQUAL(callCount, 3, ()); + + ExceptionCatcher( + "Lambda", + [&callCount](int) { + ++callCount; + throw 1; + }, + 7); + TEST_EQUAL(callCount, 4, ()); } UNIT_TEST(ExceptionCatcher_FunctionsReturnVoid)