2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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 #include <gtest/gtest.h>
19 #include <gmock/gmock.h>
21 #include <watch_mirror.hh>
23 #include <vconf_mock.h>
26 using namespace tizen_base;
27 using namespace watch_holder;
29 class WatchMirrorStub : public WatchMirror {
31 WatchMirrorStub(Evas_Object* win)
35 void OnChanged(const ISharableWatchBase& watch) override {}
36 void OnAdded(const ISharableWatchBase& watch) override {}
37 void OnUpdated(const ISharableWatchBase& watch) override {}
38 void OnRemoved(const ISharableWatchBase& watch) override {}
41 class SharableWatchStub : public ISharableWatchBase {
44 void Resume() override;
45 void Pause() override;
46 std::shared_ptr<screen_connector::WlBuffer> GetCurrentImage() const override;
47 bool IsBound() const override;
48 std::string GetAppId() const override;
49 int GetPid() const override;
50 virtual tizen_base::Bundle GetExtra() const override;
51 bool IsFaulted() const override;
52 void BlockUpdate(bool enable) override;
55 static int __vconf_notify_key_changed_fake(const char* key, vconf_callback_fn cb,
60 static int __vconf_notify_key_changed_fake2(const char* key, vconf_callback_fn cb,
65 static char* __vconf_get_str_fake(const char* key) {
68 bundle* b = bundle_create();
69 bundle_add_str(b, NOTIFY_CHANGED_EVENT_APPID_KEY, "appid");
70 bundle_add_str(b, NOTIFY_CHANGED_EVENT_RID_KEY, "rid");
72 bundle_encode(b, &raw, &len);
78 class WatchMirrorTest : public ::testing::Test {
80 WatchMirrorStub* mirrorstub;
82 virtual void SetUp() {
83 Evas_Object* mirwin = elm_win_add(NULL, "Watch Mirror", ELM_WIN_BASIC);
84 mirrorstub = new WatchMirrorStub(mirwin);
86 virtual void TearDown() {
91 TEST_F(WatchMirrorTest, CreateMirrorInstance) {
92 EXPECT_NE(WatchMirrorTest::mirrorstub, nullptr);
95 TEST_F(WatchMirrorTest, MirrorListen) {
98 vconf_notify_key_changed_fake.custom_fake = __vconf_notify_key_changed_fake;
99 vconf_get_str_fake.custom_fake = __vconf_get_str_fake;
101 ret = WatchMirrorTest::mirrorstub->Listen();
105 TEST_F(WatchMirrorTest, MirrorListen_N) {
108 vconf_notify_key_changed_fake.custom_fake = __vconf_notify_key_changed_fake2;
110 ret = WatchMirrorTest::mirrorstub->Listen();
114 TEST_F(WatchMirrorTest, MirrorGetCurrent_N) {
115 shared_ptr<ISharableWatchBase> sw;
116 sw = WatchMirrorTest::mirrorstub->GetCurrent();
117 EXPECT_EQ(sw, nullptr);
120 TEST_F(WatchMirrorTest, OnChanged) {
121 Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
122 Watch *w = new Watch(string("test"), watchwin, nullptr, WatchMirrorTest::mirrorstub);
123 EXPECT_NE(w, nullptr);
124 WatchMirror *mr = new WatchMirror(watchwin);
125 EXPECT_NE(mr, nullptr);
131 TEST_F(WatchMirrorTest, OnAdded) {
132 Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
133 SharableWatchStub *w = nullptr;
135 WatchMirror *mr = new WatchMirror(watchwin);
136 EXPECT_NE(mr, nullptr);
142 TEST_F(WatchMirrorTest, OnUpdated) {
143 Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
144 SharableWatchStub *w = nullptr;
146 WatchMirror *mr = new WatchMirror(watchwin);
147 EXPECT_NE(mr, nullptr);
153 TEST_F(WatchMirrorTest, OnRemoved) {
154 Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
155 SharableWatchStub *w = nullptr;
157 WatchMirror *mr = new WatchMirror(watchwin);
158 EXPECT_NE(mr, nullptr);
164 TEST_F(WatchMirrorTest, OnAmbientChanged) {
166 Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
167 WatchMirror *mr = new WatchMirror(watchwin);
168 EXPECT_NE(mr, nullptr);
169 mr->OnAmbientChanged(true, *b);
173 TEST_F(WatchMirrorTest, OnAmbientEvent) {
175 b.Add("__APP_AMBIENT_EVENT__", "1");
176 Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
177 WatchMirror *mr = new WatchMirror(watchwin);
178 EXPECT_NE(mr, nullptr);
179 mr->OnAmbientEvent(AmbientListener::EVENT_AOD_READY, string("sender"), b);