2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file test_cases_deferred.cpp
18 * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
20 * @brief Inner tests for defer macros mechanism
23 #include <dpl/test/test_exception.h>
24 #include <dpl/test/test_runner.h>
26 #define EXPECT_EXCEPTION(expectedCatch, F) { \
27 bool catched = false; \
30 } catch (const DPL::Test::TestException & ex) { \
33 RUNNER_ASSERT_MSG(catched == expectedCatch, \
34 "Exception catched = " << catched \
35 << " while expected is = " << expectedCatch); \
45 #define TRYCATCH(F) { \
46 RUNNER_DEFER_TRYCATCH( \
59 RUNNER_FAIL_MSG("Oops!");
66 RUNNER_TEST_GROUP_INIT(DEFERRED)
68 RUNNER_TEST(id01_simple_fail)
70 EXPECT_EXCEPTION(true, fail());
73 RUNNER_TEST(id02_filtred_fail)
75 EXPECT_EXCEPTION(false, FILTER(fail()));
78 RUNNER_TEST(id03_saved_filtred_rethrown_fail)
80 EXPECT_EXCEPTION(true, SCOPE(FILTER(TRYCATCH(fail()))));
83 RUNNER_TEST(id04_saved_filtred_fail)
85 EXPECT_EXCEPTION(false, FILTER(TRYCATCH(fail())));
88 RUNNER_TEST(id05_filtred_rethrown_fail)
90 EXPECT_EXCEPTION(false, SCOPE(FILTER(fail())));
93 RUNNER_TEST(id06_saved_rethrown_fail)
95 EXPECT_EXCEPTION(true, SCOPE(TRYCATCH(fail())));
98 RUNNER_TEST(id07_saved_fail)
100 EXPECT_EXCEPTION(true, TRYCATCH(fail()));
103 RUNNER_TEST(id08_rethrown_fail)
105 EXPECT_EXCEPTION(true, SCOPE(fail()));
108 RUNNER_TEST(id09_nested_scope)
110 EXPECT_EXCEPTION(true, SCOPE(SCOPE(SCOPE(FILTER(TRYCATCH(fail()))))));
113 RUNNER_TEST(id10_nested_scope2)
115 EXPECT_EXCEPTION(true, SCOPE(SCOPE(FILTER(SCOPE(TRYCATCH(fail()))))));
118 RUNNER_TEST(id11_saved_filtred_rethrown_pass)
120 EXPECT_EXCEPTION(false, SCOPE(FILTER(TRYCATCH(pass()))));