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.
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19 * @brief Implementation file for DBusTest and DBusTestManager.
22 #include <dpl/test/test_runner.h>
23 #include "loop_control.h"
24 #include "dbus_test.h"
26 DBusTest::DBusTest(const std::string& name)
28 m_status(Status::NONE)
32 void DBusTest::run(unsigned int timeout)
34 DPL::Event::ControllerEventHandler<TimeoutEvent>::Touch();
35 DPL::Event::ControllerEventHandler<QuitEvent>::Touch();
37 DPL::Event::ControllerEventHandler<TimeoutEvent>::PostTimedEvent(
38 TimeoutEvent(), timeout);
40 LoopControl::wrt_start_loop();
45 throw DPL::Test::TestRunner::TestFailed(m_name.c_str(),
59 DPL::Event::ControllerEventHandler<QuitEvent>::PostEvent(QuitEvent());
62 void DBusTest::setStatus(Status status)
67 void DBusTest::setMessage(const std::string& message)
72 void DBusTest::success()
74 m_status = Status::SUCCESS;
77 void DBusTest::fail(const std::string& message)
79 m_status = Status::FAILED;
83 void DBusTest::OnEventReceived(const TimeoutEvent& /*event*/)
85 fail("Test timed out.");
87 // Saving one event dispatch since Quit and Timeout work on the same thread.
88 LoopControl::wrt_end_loop();
91 void DBusTest::OnEventReceived(const QuitEvent& /*event*/)
93 LoopControl::wrt_end_loop();
96 DBusTestManager& DBusTestManager::getInstance()
98 static DBusTestManager instance;
102 DBusTestManager::DBusTestManager() : m_test(NULL) { }
104 DBusTest& DBusTestManager::getCurrentTest() const
106 Assert(NULL != m_test && "Test not set.");
111 void DBusTestManager::setCurrentTest(DBusTest& test)
116 void DBusTestManager::clear()