From 17db03f16c4f6da317e326ecdbdf3dbe177051ee Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Tue, 3 Feb 2015 19:21:11 +0100 Subject: [PATCH] Add inner tests for deferred macros Added 11 test cases cover all possible nestings of deferred macros. Change-Id: I35898876f7b2dca740836463a5744fe96972f609 --- tests/CMakeLists.txt | 1 + tests/framework/test_cases_deferred.cpp | 121 ++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/framework/test_cases_deferred.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 045b578..b1b4d87 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,6 +27,7 @@ PKG_CHECK_MODULES(INNER_TARGET_DEP SET(INNER_TARGET_TEST_SOURCES ${PROJECT_SOURCE_DIR}/tests/inner-test.cpp ${PROJECT_SOURCE_DIR}/tests/common/test_cases_timeout.cpp + ${PROJECT_SOURCE_DIR}/tests/framework/test_cases_deferred.cpp ) #header directories diff --git a/tests/framework/test_cases_deferred.cpp b/tests/framework/test_cases_deferred.cpp new file mode 100644 index 0000000..036bc0f --- /dev/null +++ b/tests/framework/test_cases_deferred.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file test_cases_deferred.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Inner tests for defer macros mechanism + */ + +#include +#include + +#define EXPECT_EXCEPTION(expectedCatch, F) { \ + bool catched = false; \ + try { \ + F; \ + } catch (const DPL::Test::TestException & ex) { \ + catched = true; \ + } \ + RUNNER_ASSERT_MSG(catched == expectedCatch, \ + "Exception catched = " << catched \ + << " while expected is = " << expectedCatch); \ +} + +#define FILTER(F) { \ + try { \ + F; \ + } catch (...) { \ + } \ +} + +#define TRYCATCH(F) { \ + RUNNER_DEFER_TRYCATCH( \ + F; \ + ); \ +} + +#define SCOPE(F) { \ + RUNNER_DEFER_SCOPE( \ + F; \ + ); \ +} + +void fail(void) +{ + RUNNER_FAIL_MSG("Oops!"); +} + +void pass(void) +{ +} + +RUNNER_TEST_GROUP_INIT(DEFERRED) + +RUNNER_TEST(id01_simple_fail) +{ + EXPECT_EXCEPTION(true, fail()); +} + +RUNNER_TEST(id02_filtred_fail) +{ + EXPECT_EXCEPTION(false, FILTER(fail())); +} + +RUNNER_TEST(id03_saved_filtred_rethrown_fail) +{ + EXPECT_EXCEPTION(true, SCOPE(FILTER(TRYCATCH(fail())))); +} + +RUNNER_TEST(id04_saved_filtred_fail) +{ + EXPECT_EXCEPTION(false, FILTER(TRYCATCH(fail()))); +} + +RUNNER_TEST(id05_filtred_rethrown_fail) +{ + EXPECT_EXCEPTION(false, SCOPE(FILTER(fail()))); +} + +RUNNER_TEST(id06_saved_rethrown_fail) +{ + EXPECT_EXCEPTION(true, SCOPE(TRYCATCH(fail()))); +} + +RUNNER_TEST(id07_saved_fail) +{ + EXPECT_EXCEPTION(true, TRYCATCH(fail())); +} + +RUNNER_TEST(id08_rethrown_fail) +{ + EXPECT_EXCEPTION(true, SCOPE(fail())); +} + +RUNNER_TEST(id09_nested_scope) +{ + EXPECT_EXCEPTION(true, SCOPE(SCOPE(SCOPE(FILTER(TRYCATCH(fail())))))); +} + +RUNNER_TEST(id10_nested_scope2) +{ + EXPECT_EXCEPTION(true, SCOPE(SCOPE(FILTER(SCOPE(TRYCATCH(fail())))))); +} + +RUNNER_TEST(id11_saved_filtred_rethrown_pass) +{ + EXPECT_EXCEPTION(false, SCOPE(FILTER(TRYCATCH(pass())))); +} -- 2.7.4