Source code formating unification
[framework/web/wrt-commons.git] / tests / dpl / dbus / dbus_test.h
1 /*
2  * Copyright (c) 2011 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    dbus_test.h
18  * @author  Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  * @brief   Header file for DBusTest and DBusTestManager.
20  */
21
22 #ifndef WRT_TESTS_DBUS_TESTS_DBUS_TEST_H
23 #define WRT_TESTS_DBUS_TESTS_DBUS_TEST_H
24
25 #include <string>
26 #include <dpl/event/controller.h>
27 #include <dpl/generic_event.h>
28
29 DECLARE_GENERIC_EVENT_0(QuitEvent)
30 DECLARE_GENERIC_EVENT_0(TimeoutEvent)
31
32 class DBusTest :
33     private DPL::Event::Controller<DPL::TypeListDecl<QuitEvent,
34                                                      TimeoutEvent>::Type>
35 {
36   public:
37     enum class Status
38     {
39         NONE,
40         SUCCESS,
41         FAILED
42     };
43
44     explicit DBusTest(const std::string& name);
45
46     void run(unsigned int timeout);
47     void quit();
48
49     void setStatus(Status status);
50     void setMessage(const std::string& message);
51
52     void success();
53     void fail(const std::string& message = std::string());
54
55   private:
56     void OnEventReceived(const TimeoutEvent& event);
57     void OnEventReceived(const QuitEvent& event);
58
59     std::string m_name;
60     Status m_status;
61     std::string m_message;
62 };
63
64 class DBusTestManager : private DPL::Noncopyable
65 {
66   public:
67     static DBusTestManager& getInstance();
68
69     DBusTest& getCurrentTest() const;
70     void setCurrentTest(DBusTest& test);
71
72     void clear();
73
74   private:
75     DBusTestManager();
76
77     DBusTest* m_test;
78 };
79
80 #define DBUS_TEST(TestProc)                                                    \
81     void DBus##TestProc();                                                     \
82     RUNNER_TEST(TestProc)                                                      \
83     {                                                                          \
84         DBusTest test(#TestProc);                                              \
85         DBusTestManager::getInstance().setCurrentTest(test);                   \
86         DBus##TestProc();                                                      \
87         DBusTestManager::getInstance().clear();                                \
88     }                                                                          \
89     void DBus##TestProc()
90
91 #endif