Add init and finish functionality
[platform/core/test/security-tests.git] / src / framework / include / dpl / test / test_case_extended.h
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_case_extended.h
18  * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
19  * @version     1.0
20  * @brief       This file is the header file of TestCaseExtended class
21  */
22
23 #ifndef DPL_TEST_CASE_EXTENDED_H
24 #define DPL_TEST_CASE_EXTENDED_H
25
26 #include <cstddef>
27 #include <functional>
28 #include <string>
29 #include <tuple>
30
31 #include <dpl/test/test_case.h>
32
33 namespace DPL {
34 namespace Test {
35 namespace Operations {
36
37 template<size_t N, class T>
38 void init(T &t, const std::string &testName) {
39     (void) t;
40     (void) testName;
41 }
42
43 template<size_t N, class T>
44 void finish(T &t) {
45     (void) t;
46 }
47
48 template<size_t N, class T, typename First, typename ...Rest>
49 void init(T &t, const std::string &testName) {
50     std::get<N>(t).init(testName);
51     init<N+1, T, Rest...>(t, testName);
52 }
53
54 template<size_t N, class T, typename First, typename ...Rest>
55 void finish(T &t) {
56     std::get<N>(t).finish();
57     finish<N-1, T, Rest...>(t);
58 }
59
60 } // namespace Operations
61
62 template<typename ...Args>
63 class TestCaseExtended
64     : public TestCase
65 {
66 public:
67     TestCaseExtended(const std::string &name,
68                      const std::function<void(std::tuple<Args...> &t)> &testFunc)
69         : TestCase(name), m_testFunc(testFunc) {}
70
71 private:
72     virtual void Init() { Operations::init<0, std::tuple<Args...>, Args...>(m_tuple, GetName()); }
73     virtual void Finish() { Operations::finish<sizeof...(Args)-1, std::tuple<Args...>, Args...>(m_tuple); }
74     virtual void Test() { m_testFunc(m_tuple); }
75
76     std::tuple<Args...> m_tuple;
77     std::function<void(std::tuple<Args...> &t)> m_testFunc;
78 };
79
80 } // namespace Test
81 } // namespace DPL
82
83 #endif // DPL_TEST_CASE_EXTENDED_H