*/
#include <bundle_cpp.h>
+#include <glib.h>
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <cstdio>
#include <memory>
#include "theme/dbus/command.h"
+#include "theme/dbus/request_broker.h"
#include "theme/dbus/request_handler.h"
+#include "theme/loader/theme_info_loader.h"
#include "theme_provider/control_request_handler.h"
#include "theme_provider/package_event_request_handler.h"
#include "theme_provider/selection_request_handler.h"
#include "theme_provider/theme_info_proxy.h"
+#include "unit_tests/mock/gio_mock.h"
+#include "unit_tests/mock/test_fixture.h"
+using ::testing::_;
+using ::testing::Return;
+using ::testing::Invoke;
+using ttm::loader::IThemeEvent;
using ttm::loader::ThemeInfo;
+using ttm::loader::ThemeInfoLoader;
using ttm::provider::ThemeInfoProxy;
namespace {
const char kTestDb[] = "request_handler_test.db";
+class Timer {
+ public:
+ explicit Timer(int timeout_msec)
+ : loop_(nullptr), timeout_(timeout_msec) {}
+ void WaitForResult() {
+ loop_ = g_main_loop_new(nullptr, FALSE);
+ g_timeout_add(timeout_,
+ [](gpointer user_data) -> gboolean {
+ Timer* t = static_cast<Timer*>(user_data);
+ g_main_loop_quit(t->loop_);
+ return FALSE;
+ }, this);
+ g_main_loop_run(loop_);
+ g_main_loop_unref(loop_);
+ }
+
+ GMainLoop* loop_;
+ int timeout_;
+};
+
} // namespace
-class RequestHandlersTest : public testing::Test {
+class Mocks : public ::testing::NiceMock<GioMock> {};
+
+class RequestHandlersTest : public TestFixture {
public:
+ RequestHandlersTest() : TestFixture(std::make_unique<Mocks>()) {}
virtual ~RequestHandlersTest() {}
virtual void SetUp() {
tizen_base::Bundle b_;
};
+class TestEventMock : public IThemeEvent {
+ public:
+ MOCK_METHOD2(OnThemeChanged, void(const ThemeInfo*,
+ const tizen_base::Bundle& args));
+};
+
TEST_F(RequestHandlersTest, ControlRequestHandler_OnRequest) {
+ auto loader = std::make_shared<ThemeInfoLoader>();
+ auto event = std::make_shared<TestEventMock>();
+
+ EXPECT_CALL(*event, OnThemeChanged(_, _));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_emit_signal(_, _, _, _, _, _, _)).
+ WillOnce(Return(true));
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _)).
+ WillOnce(Invoke(
+ [this](GDBusConnection* arg0, const gchar* arg1,
+ const gchar* arg2, const gchar* arg3, const gchar* arg4,
+ const gchar* arg5, GDBusSignalFlags arg6,
+ GDBusSignalCallback arg7, gpointer arg8,
+ GDestroyNotify arg9) -> guint {
+ g_timeout_add(1000,
+ [](gpointer user_data) -> gboolean {
+ GDBusSignalCallback cb =
+ reinterpret_cast<GDBusSignalCallback>(user_data);
+ tizen_base::Bundle b;
+ b.Add("id", "testid");
+ b.Add("version", "1.0");
+ b.Add("tool_version", "1.1");
+ b.Add("title", "Test");
+ b.Add("resolution", "360X360");
+ b.Add("preview", "shared/res/preview.png");
+ b.Add("description", "test");
+ GVariant* gv = g_variant_new("(is)",
+ static_cast<int>(ttm::dbus::Command::CHANGED),
+ reinterpret_cast<char*>(b.ToRaw().first.get()));
+ cb(nullptr, nullptr, nullptr, nullptr, nullptr, gv,
+ &ttm::dbus::RequestBroker::GetInst());
+ g_variant_unref(gv);
+ return FALSE;
+ }, reinterpret_cast<gpointer>(arg7));
+ return 1;
+ }));
+
+ std::string key = loader->AddEvent(event);
+
using ttm::provider::ControlRequestHandler;
ControlRequestHandler handler(proxy_);
auto cur = proxy_->GetLoadedTheme();
EXPECT_NE(cur, nullptr);
EXPECT_EQ(cur->GetId(), "testid");
+
+ Timer timer(2000);
+ timer.WaitForResult();
+
+ loader->RemoveEvent(key);
}
TEST_F(RequestHandlersTest, PackageRequestHandler_OnRequest) {