#include <gmock/gmock.h>
#include <ambient-viewer.hh>
-#include <top-app-surface.hh>
#include <watch-surface.hh>
+#include <top-app-surface.hh>
+
+#include "unittest/mock/vconf_mock.h"
+#include "unittest/mock/aul_mock.h"
+#include "ambient-viewer/include/ambient_viewer.h"
+#include "ambient-viewer/include/ambient_viewer_common.h"
+
+#define NOTIFY_CHANGED_EVENT_APPID_KEY "__NOTIFY_CHANGED_EVENT_APPID_KEY__"
+#define NOTIFY_CHANGED_EVENT_RID_KEY "__NOTIFY_CHANGED_EVENT_RID_KEY__"
using namespace std;
using namespace ambient_viewer;
using namespace tizen_base;
+static app_com_cb __app_com_callback;
+static void* __app_com_user_data;
+
+static void __receive_fake_message() {
+ Bundle b;
+ b.Add("__APP_AMBIENT_EVENT__", "1");
+ b.Add("__APP_AMBIENT_SENDER__", "test");
+ __app_com_callback("", AUL_APP_COM_R_OK, b.GetHandle(), __app_com_user_data);
+}
+
+static int __aul_app_com_create(const char *endpoint,
+ aul_app_com_permission_h permission, app_com_cb callback, void *user_data,
+ aul_app_com_connection_h *connection) {
+ __app_com_callback = callback;
+ __app_com_user_data = user_data;
+ return 0;
+}
+
+static int __aul_app_com_leave(aul_app_com_connection_h connection) {
+ return 0;
+}
+
+static int __aul_app_com_send(const char *endpoint, bundle *envelope) {
+ return 0;
+}
+
+static char* __vconf_get_str(const char* key) {
+ if (!key)
+ return nullptr;
+
+ if (strcmp(key, VCONFKEY_WATCH_CURRENT_WATCH_INFO) == 0) {
+ Bundle data;
+ data.Add(NOTIFY_CHANGED_EVENT_APPID_KEY, "TestAppId");
+ data.Add(NOTIFY_CHANGED_EVENT_RID_KEY, "1");
+ return strdup(reinterpret_cast<char*>(data.ToRaw().first.get()));
+ }
+
+ return nullptr;
+}
+
+static int __vconf_notify_key_changed(const char* key, vconf_callback_fn cb,
+ void* user_data) {
+ return 0;
+}
+
+static int __vconf_ignore_key_changed(const char* key, vconf_callback_fn cb) {
+ return 0;
+}
+
+class WatchSurfaceMock : public WatchSurface {
+ public:
+ WatchSurfaceMock(int rid, std::string id,
+ std::string appid, Evas_Object* viewer_win, IAmbientViewer* listener)
+ : WatchSurface(rid, id, std::move(appid), viewer_win, listener, true) {}
+
+ void InvokeEvasAdded() {
+ screen_connector::EvasObject eo(nullptr, false);
+ OnEvasAdded("TestAppId", "TestInstId", 99, eo);
+ }
+
+ void InvokeEvasRemoved() {
+ screen_connector::EvasObject eo(nullptr, false);
+ OnEvasRemoved("TestAppId", "TestInstId", 99, eo);
+ }
+
+ void InvokeEvasChanged() {
+ screen_connector::EvasObject eo(nullptr, false);
+ OnEvasChanged("TestAppId", "TestInstId", 99, eo);
+ }
+};
+
+class TopAppSurfaceMock : public TopAppSurface {
+ public:
+ TopAppSurfaceMock(std::shared_ptr<screen_connector::EvasObject> surface,
+ IAmbientViewer* listener) : TopAppSurface(surface, listener, true) {}
+
+ void InvokeWatcherAdded() {
+ OnWatcherAdded("TestAppId", "TestInstId", 99);
+ }
+
+ void InvokeWatcherChanged() {
+ screen_connector::EvasObject image(nullptr, false);
+ OnWatcherChanged("TestAppId", "TestInstId", 99, image);
+ }
+
+ void InvokeWatcherRemoved() {
+ OnWatcherRemoved("TestAppId", "TestInstId", 99);
+ }
+
+ void InvokeWatcherFocusChanged() {
+ OnWatcherFocusChanged("TestAppId", "TestInstId", 99);
+ }
+};
+
class AmbientViewerStub : public AmbientViewer {
public:
AmbientViewerStub(Evas_Object* win)
: AmbientViewer(win) {
}
- void OnAdded(const ISurface& surface) override {}
- void OnUpdated(const ISurface& surface) override {}
- void OnRemoved(const ISurface& surface) override {}
- void OnReceived(EventType ev, string sender, Bundle extra) override {}
+ void OnAdded(const ISurface& surface) override {
+ added_ = true;
+ }
+ void OnUpdated(const ISurface& surface) override {
+ updated_ = true;
+ }
+ void OnRemoved(const ISurface& surface) override {
+ removed_ = true;
+ }
+ void OnReceived(EventType ev, string sender, Bundle extra) override {
+ AmbientViewer::OnReceived(ev, sender, extra);
+ received_ = true;
+ }
+
+ public:
+ bool added_ = false;
+ bool updated_ = false;
+ bool removed_ = false;
+ bool received_ = false;
+
+ protected:
+ std::shared_ptr<ISurface> CreateWatchSurface(int rid, std::string id,
+ std::string appid, Evas_Object* viewer_win, IAmbientViewer* listener,
+ bool mock = false) override {
+ auto suf = AmbientViewer::CreateWatchSurface(rid, id, appid,
+ viewer_win, listener, true);
+ if (suf.get() == nullptr)
+ return nullptr;
+ return make_shared<WatchSurfaceMock>(rid, id, std::move(appid),
+ viewer_win, listener);
+ }
+
+ std::shared_ptr<ISurface> CreateTopAppSurface(
+ std::shared_ptr<screen_connector::EvasObject> surface,
+ IAmbientViewer* listener, bool mock = false) override {
+ auto suf = AmbientViewer::CreateTopAppSurface(surface, listener, true);
+ if (suf.get() == nullptr)
+ return nullptr;
+ return make_shared<TopAppSurfaceMock>(surface, listener);
+ }
};
class AmbientViewerTest : public ::testing::Test {
AmbientViewerStub* stub;
virtual void SetUp() {
+ vconf_get_str_fake.custom_fake = __vconf_get_str;
+ vconf_notify_key_changed_fake.custom_fake = __vconf_notify_key_changed;
+ vconf_ignore_key_changed_fake.custom_fake = __vconf_ignore_key_changed;
+ aul_app_com_create_fake.custom_fake = __aul_app_com_create;
+ aul_app_com_leave_fake.custom_fake = __aul_app_com_leave;
+ aul_app_com_send_fake.custom_fake = __aul_app_com_send;
+
Evas_Object* win = elm_win_add(NULL, "Widget Viewer", ELM_WIN_BASIC);
stub = new AmbientViewerStub(win);
- AmbientViewerTest::stub->Monitor();
}
virtual void TearDown() {
- AmbientViewerTest::stub->Unmonitor();
delete stub;
}
};
AmbientViewer::DIRECTION_ALL, b), 0);
}
+TEST_F(AmbientViewerTest, NotifyAmbientEvent2) {
+ Bundle b;
+ EXPECT_EQ(AmbientViewerTest::stub->NotifyAmbientEvent(true,
+ AmbientViewer::DIRECTION_VIEWER_AND_WATCH, b), 0);
+}
+
+TEST_F(AmbientViewerTest, NotifyAmbientEvent3) {
+ Bundle b;
+ EXPECT_EQ(AmbientViewerTest::stub->NotifyAmbientEvent(true,
+ AmbientViewer::DIRECTION_VIEWER_AND_TOP_APP, b), 0);
+}
+
TEST_F(AmbientViewerTest, BlockUpdate) {
AmbientViewerTest::stub->BlockUpdate(true);
}
+
+TEST_F(AmbientViewerTest, MonitorUnmonitor) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
+
+ EXPECT_NE(&ws, nullptr);
+
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, WatchSurface_GetAppId) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
+ ASSERT_NE(&ws, nullptr);
+
+ EXPECT_EQ(ws.GetAppId(), "TestAppId");
+
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, WatchSurface_GetInstId) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
+ ASSERT_NE(&ws, nullptr);
+ WatchSurfaceMock* mock = const_cast<WatchSurfaceMock*>(
+ static_cast<const WatchSurfaceMock*>(&ws));
+ mock->InvokeEvasAdded();
+
+ EXPECT_TRUE(stub->added_);
+ EXPECT_EQ(ws.GetInstId(), "TestInstId");
+
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, AmbientViewer_Events) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
+ ASSERT_NE(&ws, nullptr);
+ WatchSurfaceMock* mock = const_cast<WatchSurfaceMock*>(
+ static_cast<const WatchSurfaceMock*>(&ws));
+
+ mock->InvokeEvasAdded();
+ EXPECT_TRUE(stub->added_);
+ mock->InvokeEvasChanged();
+ EXPECT_TRUE(stub->updated_);
+ mock->InvokeEvasRemoved();
+ EXPECT_TRUE(stub->removed_);
+
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, WatchSurface_IsWatch) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
+ ASSERT_NE(&ws, nullptr);
+
+ EXPECT_TRUE(ws.IsWatch());
+
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, AmbientViewer_OnReceived) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
+ ASSERT_NE(&ws, nullptr);
+
+ EXPECT_TRUE(stub->received_);
+
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, TopAppSurface_IsWatch) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetTopAppSurface();
+ ASSERT_NE(&ws, nullptr);
+
+ EXPECT_FALSE(ws.IsWatch());
+
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, TopAppSurface_GetAppId) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetTopAppSurface();
+ ASSERT_NE(&ws, nullptr);
+ TopAppSurfaceMock* mock = const_cast<TopAppSurfaceMock*>(
+ static_cast<const TopAppSurfaceMock*>(&ws));
+ mock->InvokeWatcherAdded();
+
+ EXPECT_EQ(ws.GetAppId(), "TestAppId");
+
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, TopAppSurface_GetInstId) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetTopAppSurface();
+ ASSERT_NE(&ws, nullptr);
+ TopAppSurfaceMock* mock = const_cast<TopAppSurfaceMock*>(
+ static_cast<const TopAppSurfaceMock*>(&ws));
+ mock->InvokeWatcherAdded();
+ mock->InvokeWatcherChanged();
+ mock->InvokeWatcherFocusChanged();
+
+ EXPECT_EQ(ws.GetInstId(), "TestInstId");
+
+ mock->InvokeWatcherRemoved();
+ stub->Unmonitor();
+}
+
+TEST_F(AmbientViewerTest, AmbientViewer_OnReceived2) {
+ stub->Monitor();
+ const auto& ws = AmbientViewerTest::stub->GetWatchSurface();
+ ASSERT_NE(&ws, nullptr);
+ stub->received_ = false;
+ __receive_fake_message();
+
+ EXPECT_TRUE(stub->received_);
+
+ stub->Unmonitor();
+}
+
+class AmbientViewerStubTest : public ::testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_create) {
+ EXPECT_EQ(ambient_viewer_create(nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_destroy) {
+ EXPECT_EQ(ambient_viewer_destroy(nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_notify_ambient_event) {
+ EXPECT_EQ(ambient_viewer_notify_ambient_event(nullptr, true,
+ AMBIENT_VIEWER_DIRECTION_ALL, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_block_update) {
+ EXPECT_EQ(ambient_viewer_block_update(nullptr, true),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_monitor) {
+ ambient_viewer_lifecycle_s lifecycle;
+ EXPECT_EQ(ambient_viewer_monitor(nullptr, lifecycle, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_unmonitor) {
+ EXPECT_EQ(ambient_viewer_unmonitor(nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_set_event_listener) {
+ EXPECT_EQ(ambient_viewer_set_event_listener(nullptr, nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_unset_event_listener) {
+ EXPECT_EQ(ambient_viewer_unset_event_listener(nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_get_watch_surface) {
+ EXPECT_EQ(ambient_viewer_get_watch_surface(nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_get_top_app_surface) {
+ EXPECT_EQ(ambient_viewer_get_top_app_surface(nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_cur_image) {
+ EXPECT_EQ(ambient_viewer_surface_get_cur_image(nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_is_watch) {
+ EXPECT_EQ(ambient_viewer_surface_is_watch(nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_app_id) {
+ EXPECT_EQ(ambient_viewer_surface_get_app_id(nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_inst_id) {
+ EXPECT_EQ(ambient_viewer_surface_get_inst_id(nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(AmbientViewerStubTest, ambient_viewer_surface_get_opr) {
+ EXPECT_EQ(ambient_viewer_surface_get_opr(nullptr, nullptr),
+ AMBIENT_VIEWER_ERROR_INVALID_PARAMETER);
+}