Add inner tests for deferred macros
[platform/core/test/security-tests.git] / tests / framework / test_cases_deferred.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file        test_cases_deferred.cpp
18  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
19  * @version     1.0
20  * @brief       Inner tests for defer macros mechanism
21  */
22
23 #include <dpl/test/test_exception.h>
24 #include <dpl/test/test_runner.h>
25
26 #define EXPECT_EXCEPTION(expectedCatch, F) {                           \
27     bool catched = false;                                              \
28     try {                                                              \
29         F;                                                             \
30     } catch (const DPL::Test::TestException & ex) {                    \
31         catched = true;                                                \
32     }                                                                  \
33     RUNNER_ASSERT_MSG(catched == expectedCatch,                        \
34                          "Exception catched = " << catched             \
35                          << " while expected is = " << expectedCatch); \
36 }
37
38 #define FILTER(F) { \
39     try {           \
40         F;          \
41     } catch (...) { \
42     }               \
43 }
44
45 #define TRYCATCH(F) {      \
46     RUNNER_DEFER_TRYCATCH( \
47         F;                 \
48     );                     \
49 }
50
51 #define SCOPE(F) {      \
52     RUNNER_DEFER_SCOPE( \
53         F;              \
54     );                  \
55 }
56
57 void fail(void)
58 {
59     RUNNER_FAIL_MSG("Oops!");
60 }
61
62 void pass(void)
63 {
64 }
65
66 RUNNER_TEST_GROUP_INIT(DEFERRED)
67
68 RUNNER_TEST(id01_simple_fail)
69 {
70     EXPECT_EXCEPTION(true, fail());
71 }
72
73 RUNNER_TEST(id02_filtred_fail)
74 {
75     EXPECT_EXCEPTION(false, FILTER(fail()));
76 }
77
78 RUNNER_TEST(id03_saved_filtred_rethrown_fail)
79 {
80     EXPECT_EXCEPTION(true, SCOPE(FILTER(TRYCATCH(fail()))));
81 }
82
83 RUNNER_TEST(id04_saved_filtred_fail)
84 {
85     EXPECT_EXCEPTION(false, FILTER(TRYCATCH(fail())));
86 }
87
88 RUNNER_TEST(id05_filtred_rethrown_fail)
89 {
90     EXPECT_EXCEPTION(false, SCOPE(FILTER(fail())));
91 }
92
93 RUNNER_TEST(id06_saved_rethrown_fail)
94 {
95     EXPECT_EXCEPTION(true, SCOPE(TRYCATCH(fail())));
96 }
97
98 RUNNER_TEST(id07_saved_fail)
99 {
100     EXPECT_EXCEPTION(true, TRYCATCH(fail()));
101 }
102
103 RUNNER_TEST(id08_rethrown_fail)
104 {
105     EXPECT_EXCEPTION(true, SCOPE(fail()));
106 }
107
108 RUNNER_TEST(id09_nested_scope)
109 {
110     EXPECT_EXCEPTION(true, SCOPE(SCOPE(SCOPE(FILTER(TRYCATCH(fail()))))));
111 }
112
113 RUNNER_TEST(id10_nested_scope2)
114 {
115     EXPECT_EXCEPTION(true, SCOPE(SCOPE(FILTER(SCOPE(TRYCATCH(fail()))))));
116 }
117
118 RUNNER_TEST(id11_saved_filtred_rethrown_pass)
119 {
120     EXPECT_EXCEPTION(false, SCOPE(FILTER(TRYCATCH(pass()))));
121 }