2 * Copyright (c) 2011 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_scope_guard.cpp
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 * @brief This file is the implementation file of test scope guard
22 #include <dpl/test/test_runner.h>
23 #include <dpl/scope_guard.h>
26 bool g_guardCalled = false;
28 void regularFunction()
35 explicit Functor(bool& guardCalled)
36 : m_guardCalled(guardCalled)
48 RUNNER_TEST_GROUP_INIT(DPL)
51 Name: ScopeGuard_MakeScopeGuard_RegularFunction
52 Description: tests scope guard, created explicitly, with regular function
53 Expected: guard should be called
55 RUNNER_TEST(ScopeGuard_MakeScopeGuard_RegularFunction)
57 g_guardCalled = false;
59 auto guard = DPL::MakeScopeGuard(regularFunction);
61 RUNNER_ASSERT(g_guardCalled);
65 Name: ScopeGuard_MakeScopeGuard_Functor
66 Description: tests scope guard, created explicitly, with a functor
67 Expected: guard should be called
69 RUNNER_TEST(ScopeGuard_MakeScopeGuard_Functor)
71 g_guardCalled = false;
73 auto guard = DPL::MakeScopeGuard(Functor(g_guardCalled));
75 RUNNER_ASSERT(g_guardCalled);
79 Name: ScopeGuard_MakeScopeGuard_Lambda
80 Description: tests scope guard, created explicitly, with a lambda
81 Expected: guard should be called
83 RUNNER_TEST(ScopeGuard_MakeScopeGuard_Lambda)
85 g_guardCalled = false;
87 auto guard = DPL::MakeScopeGuard(
88 [&g_guardCalled](){ g_guardCalled = true; });
90 RUNNER_ASSERT(g_guardCalled);
94 Name: ScopeGuard_Macro
95 Description: tests scope guard, created implicitly, with a lambda
96 Expected: guard should be called
98 RUNNER_TEST(ScopeGuard_Macro)
100 g_guardCalled = false;
102 DPL_SCOPE_EXIT(&g_guardCalled)
104 g_guardCalled = true;
107 RUNNER_ASSERT(g_guardCalled);
111 Name: ScopeGuard_Release
112 Description: tests scope guard releasing API
113 Expected: guard should not be called
115 RUNNER_TEST(ScopeGuard_Release)
117 g_guardCalled = false;
119 auto guard = DPL::MakeScopeGuard(
120 [&g_guardCalled](){ g_guardCalled = true; });
123 RUNNER_ASSERT(!g_guardCalled);