From fb5ca0a204d6b2991f457433c8dd6a783dbd042f Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 8 Jul 2020 17:15:20 +0300 Subject: [PATCH] [base] Tests on the exception catcher. --- base/base_tests/CMakeLists.txt | 1 + base/base_tests/exception_tests.cpp | 47 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 base/base_tests/exception_tests.cpp diff --git a/base/base_tests/CMakeLists.txt b/base/base_tests/CMakeLists.txt index f3d7bdd061..0defb230d7 100644 --- a/base/base_tests/CMakeLists.txt +++ b/base/base_tests/CMakeLists.txt @@ -17,6 +17,7 @@ set( condition_test.cpp containers_test.cpp control_flow_tests.cpp + exception_tests.cpp fifo_cache_test.cpp file_name_utils_tests.cpp geo_object_id_tests.cpp diff --git a/base/base_tests/exception_tests.cpp b/base/base_tests/exception_tests.cpp new file mode 100644 index 0000000000..38dd9f20d4 --- /dev/null +++ b/base/base_tests/exception_tests.cpp @@ -0,0 +1,47 @@ +#include "testing/testing.hpp" + +#include "base/exception.hpp" + +#include + +namespace +{ +int FuncDoesNotThrow() noexcept { return 1; } +int FuncThrowsRootException() { throw RootException("RootException", "RootException"); } +int FuncThrowsException() { throw std::exception(); } +int FuncThrowsNumber() { throw 1; }; + +int FuncDoesNotThrowArg(int) noexcept { return 1; } +int FuncThrowsRootExceptionArg(int) { throw RootException("RootException", "RootException"); } +int FuncThrowsExceptionArg(int) { throw std::exception(); } +int FuncThrowsNumberArg(int) { throw 1; }; + +UNIT_TEST(ExceptionCatcher_FunctionsWithoutArgs) +{ + ExceptionCatcher("ExceptionCatcher_Smoke", FuncDoesNotThrow); + ExceptionCatcher("ExceptionCatcher_Smoke", FuncThrowsRootException); + ExceptionCatcher("ExceptionCatcher_Smoke", FuncThrowsException); + ExceptionCatcher("ExceptionCatcher_Smoke", FuncThrowsNumber); +} + +UNIT_TEST(ExceptionCatcher_Functions) +{ + ExceptionCatcher("ExceptionCatcher", FuncDoesNotThrowArg, 7); + ExceptionCatcher("ExceptionCatcher", FuncThrowsRootExceptionArg, 7); + ExceptionCatcher("ExceptionCatcher", FuncThrowsExceptionArg, 7); + ExceptionCatcher("ExceptionCatcher", FuncThrowsNumberArg, 7); +} + +UNIT_TEST(ExceptionCatcher_Lambdas) +{ + ExceptionCatcher( + "ExceptionCatcher", [](int) { return 1; }, 7); + ExceptionCatcher( + "ExceptionCatcher", [](int) -> int { throw RootException("RootException", "RootException"); }, + 7); + ExceptionCatcher( + "ExceptionCatcher", [](int) -> int { throw std::exception(); }, 7); + ExceptionCatcher( + "ExceptionCatcher", [](int) -> int { throw 1; }, 7); +} +} // namespace