+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
-#include "mock/test_fixture.h"
-
-#include <watch_holder.hh>
-#include <watch.hh>
-#include <mock/aul_mock.h>
-#include <mock/appsvc_mock.h>
-#include <mock/evas_mock.h>
-#include <mock/vconf_mock.h>
-
-#include <memory>
-
-using namespace std;
-using namespace tizen_base;
-using namespace watch_holder;
-
-using ::testing::_;
-using ::testing::Return;
-using ::testing::Invoke;
-
-class WatchHolderStub : public WatchHolder {
- public:
- WatchHolderStub(Evas_Object* win)
- : WatchHolder(win) {
- }
-
- void InvokeAmbientChanged(bool enter, Bundle& extra) {
- OnAmbientChanged(enter, extra);
- }
- void InvokeAmbientEvent(EventType ev, string sender,
- Bundle extra) {
- OnAmbientEvent(ev, std::move(sender), std::move(extra));
- }
- void OnAdded(const WatchBase& watch) override {}
- void OnUpdated(const WatchBase& watch) override {}
- void OnRemoved(const WatchBase& watch) override {}
- void OnLaunched(const WatchBase& watch) override {}
- void OnDead(const WatchBase& watch) override {}
- void OnBound(const WatchBase& watch) override {}
-
- std::shared_ptr<WatchBase> CreateWatch(int rid, std::string id,
- std::string appid, bool mock) override {
- return WatchHolder::CreateWatch(rid, std::move(id), std::move(appid), true);
- }
-
- std::shared_ptr<WatchBase> CreateWatch(int rid, std::string id,
- std::string appid, tizen_base::Bundle extra, bool mock) override {
- return WatchHolder::CreateWatch(rid, std::move(id), std::move(appid),
- std::move(extra), true);
- }
-};
-
-namespace {
-
-static int (*__app_com_cb)(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data);
-static Bundle b;
-static string global_end;
-aul_app_com_connection_h *global_conn;
-
-static int __aul_app_get_appid_bypid_fake(int pid, char* appid, int len) {
- snprintf(appid, len, "%s", "org.tizen.watch");
- return 0;
-}
-
-int __aul_app_com_create_fake(const char* end, aul_app_com_permission_h permission,
- app_com_cb cb, void* user_data, aul_app_com_connection_h* conn) {
- *conn = *global_conn;
- b = Bundle();
- b.Add("__AUL_APPID__", "org.tizen.watch");
- b.Add("__AUL_PID__", "111");
- b.Add("__AUL_IS_FAULT__", "is_fault");
- b.Add("__AUL_WIDGET_VIEWER__", "org.tizen.watch");
- b.Add("__AMBIENT_MODE__", "100");
- b.Add("__APP_AMBIENT_EVENT__", "0");
- b.Add("__APP_AMBIENT_SENDER__", "sender");
-
- if(strcmp(end, global_end.c_str()) == 0)
- __app_com_cb = cb;
- return 0;
-}
-
-static int __aul_app_com_leave_fake(aul_app_com_connection_h conn) {
- return 0;
-}
-
-void __evas_object_geometry_get(const Evas_Object *eo_obj, Evas_Coord *x,
- Evas_Coord *y, Evas_Coord *w, Evas_Coord *h) {
- *w = 100;
- *h = 100;
-}
-
-class Mocks :
- public ::testing::NiceMock<AulMock>,
- public ::testing::NiceMock<AppSvcMock>,
- public ::testing::NiceMock<VconfMock>,
- public ::testing::NiceMock<EvasMock> {};
-
-} // namespace
-
-class WatchHolderTest : public TestFixture {
- public:
- WatchHolderTest() : TestFixture(std::make_unique<Mocks>()) {}
- virtual ~WatchHolderTest() {}
- WatchHolderStub* stub = nullptr;
-
- virtual void SetUp() {
- EXPECT_CALL(GetMock<AulMock>(), aul_app_com_create(_, _, _, _, _))
- .WillRepeatedly(Invoke(__aul_app_com_create_fake));
- EXPECT_CALL(GetMock<AulMock>(), aul_app_com_leave(_))
- .WillRepeatedly(Invoke(__aul_app_com_leave_fake));
- EXPECT_CALL(GetMock<AulMock>(),
- aul_app_get_appid_bypid(_, _, _))
- .WillRepeatedly(Invoke(__aul_app_get_appid_bypid_fake));
- EXPECT_CALL(GetMock<AulMock>(),
- aul_svc_set_appid(_, _)).WillRepeatedly(Return(0));
- EXPECT_CALL(GetMock<AppSvcMock>(),
- appsvc_run_service(_, _, _, _)).WillRepeatedly(Return(0));
- EXPECT_CALL(GetMock<EvasMock>(), evas_object_geometry_get(_, _, _, _, _))
- .WillRepeatedly(Invoke(__evas_object_geometry_get));
- EXPECT_CALL(GetMock<EvasMock>(), elm_win_add(_, _, _))
- .WillRepeatedly(Return(reinterpret_cast<Evas_Object*>(
- calloc(1, sizeof(char)))));
-
- global_conn = (aul_app_com_connection_h*)malloc(sizeof(aul_app_com_connection_h));
-
- Evas_Object* win = elm_win_add(NULL, "Watch Holder", ELM_WIN_BASIC);
- stub = new WatchHolderStub(win);
- }
- virtual void TearDown() {
- free(global_conn);
- delete stub;
- }
-};
-
-TEST_F(WatchHolderTest, CreateInstance) {
- EXPECT_NE(WatchHolderTest::stub, nullptr);
-}
-
-TEST_F(WatchHolderTest, CreateWatch) {
- std::shared_ptr<WatchBase> w =
- WatchHolderTest::stub->CreateWatch(1, string("id"), string("appid"), true);
- EXPECT_NE(w, nullptr);
-
- Bundle b;
- b.Add("__APP_AMBIENT_EVENT__", "1");
- std::shared_ptr<WatchBase> w2 =
- WatchHolderTest::stub->CreateWatch(1, string("id"),
- string("appid"), b, true);
- EXPECT_NE(w2, nullptr);
-}
-
-TEST_F(WatchHolderTest, LaunchWatch) {
- EXPECT_CALL(GetMock<AppSvcMock>(), appsvc_run_service(_, _, _, _))
- .WillRepeatedly(Return(0));
- string appid("org.tizen.watch");
- int ret;
-
- ret = WatchHolderTest::stub->Launch(appid, false, nullptr);
- EXPECT_NE(ret, -1);
-}
-
-TEST_F(WatchHolderTest, GetStack) {
- std::list<std::shared_ptr<WatchBase>> list;
- list = WatchHolderTest::stub->GetStack();
- EXPECT_EQ(list.size(), 0);
-}
-
-TEST_F(WatchHolderTest, GetCurrent_N) {
- EXPECT_EQ(WatchHolderTest::stub->GetCurrent(), nullptr);
- global_end = "watch.launch";
-}
-
-TEST_F(WatchHolderTest, OnLaunchSignal) {
- EXPECT_NE(WatchHolderTest::stub, nullptr);
- int ret;
- string appid("org.tizen.watch");
- ret = WatchHolderTest::stub->Launch(appid, false, b.GetHandle());
- EXPECT_NE(ret, -1);
- __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
-
- ret = WatchHolderTest::stub->Launch(appid, false, nullptr);
- EXPECT_NE(ret, -1);
- __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
- global_end = "watch.dead";
-}
-
-TEST_F(WatchHolderTest, OnDeadSignal) {
- EXPECT_NE(WatchHolderTest::stub, nullptr);
- __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
- global_end = "watch.ambientchange";
-}
-
-TEST_F(WatchHolderTest, OnAmbientChangedSignal) {
- EXPECT_NE(WatchHolderTest::stub, nullptr);
- __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
- global_end = "aod.ambientevent";
-}
-
-TEST_F(WatchHolderTest, OnReceiveSignal) {
- EXPECT_NE(WatchHolderTest::stub, nullptr);
- __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
-}
-
-TEST_F(WatchHolderTest, OnAmbientChanged) {
- Bundle *b = nullptr;
- EXPECT_NE(WatchHolderTest::stub, nullptr);
- WatchHolderTest::stub->InvokeAmbientChanged(true, *b);
-}
-
-TEST_F(WatchHolderTest, OnAmbientEvent) {
- Bundle b;
- b.Add("__APP_AMBIENT_EVENT__", "1");
- EXPECT_NE(WatchHolderTest::stub, nullptr);
- WatchHolderTest::stub->InvokeAmbientEvent(AmbientListener::EVENT_AOD_READY, string("sender"), b);
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
-
-#include <watch_mirror.hh>
-#include <watch.hh>
-#include <aul_mock.h>
-#include <vconf_mock.h>
-#include <evas_mock.h>
-
-#include "test_fixture.h"
-
-#include <memory>
-
-using namespace std;
-using namespace tizen_base;
-using namespace watch_holder;
-
-using ::testing::_;
-using ::testing::Invoke;
-using ::testing::Return;
-
-class WatchMirrorStub : public WatchMirror {
- public:
- WatchMirrorStub(Evas_Object* win)
- : WatchMirror(win) {
- }
-
- void OnChanged(const ISharableWatchBase& watch) override {}
- void OnAdded(const ISharableWatchBase& watch) override {}
- void OnUpdated(const ISharableWatchBase& watch) override {}
- void OnRemoved(const ISharableWatchBase& watch) override {}
-};
-
-class SharableWatchStub : public ISharableWatchBase {
- public:
-
- void Resume() override;
- void Pause() override;
- std::shared_ptr<screen_connector::WlBuffer> GetCurrentImage() const override;
- bool IsBound() const override;
- std::string GetAppId() const override;
- int GetPid() const override;
- virtual tizen_base::Bundle GetExtra() const override;
- bool IsFaulted() const override;
- void BlockUpdate(bool enable) override;
-};
-
-static char* __vconf_get_str_fake(const char* key) {
- bundle_raw* raw;
- int len;
- bundle* b = bundle_create();
- bundle_add_str(b, NOTIFY_CHANGED_EVENT_APPID_KEY, "appid");
- bundle_add_str(b, NOTIFY_CHANGED_EVENT_RID_KEY, "rid");
-
- bundle_encode(b, &raw, &len);
- bundle_free(b);
- return (char*)raw;
-}
-
-namespace {
-
-class Mocks : public ::testing::NiceMock<VconfMock>,
- public ::testing::NiceMock<AulMock>,
- public ::testing::NiceMock<EvasMock> {};
-
-} // namespace
-
-class WatchMirrorTest : public TestFixture {
- public:
- WatchMirrorTest() : TestFixture(std::make_unique<Mocks>()) {}
- WatchMirrorStub* mirrorstub;
-
- virtual void SetUp() {
- EXPECT_CALL(GetMock<AulMock>(), aul_app_com_create(_, _, _, _, _))
- .WillRepeatedly(Return(0));
- EXPECT_CALL(GetMock<AulMock>(), aul_app_com_leave(_))
- .WillRepeatedly(Return(0));
- EXPECT_CALL(GetMock<VconfMock>(), vconf_notify_key_changed(_, _, _))
- .WillRepeatedly(Return(0));
- EXPECT_CALL(GetMock<VconfMock>(), vconf_ignore_key_changed(_, _))
- .WillRepeatedly(Return(0));
- EXPECT_CALL(GetMock<EvasMock>(), elm_win_add(_, _, _))
- .WillRepeatedly(Return(reinterpret_cast<Evas_Object*>(
- calloc(1, sizeof(char)))));
- Evas_Object* mirwin = elm_win_add(NULL, "Watch Mirror", ELM_WIN_BASIC);
- mirrorstub = new WatchMirrorStub(mirwin);
- }
- virtual void TearDown() {
- delete mirrorstub;
- }
-};
-
- TEST_F(WatchMirrorTest, CreateMirrorInstance) {
- EXPECT_NE(WatchMirrorTest::mirrorstub, nullptr);
- }
-
-TEST_F(WatchMirrorTest, MirrorListen) {
- EXPECT_CALL(GetMock<VconfMock>(), vconf_get_str(_))
- .WillRepeatedly(Invoke(__vconf_get_str_fake));
-
- int ret = WatchMirrorTest::mirrorstub->Listen();
- EXPECT_EQ(ret, 0);
-}
-
-TEST_F(WatchMirrorTest, MirrorListen_N) {
- EXPECT_CALL(GetMock<VconfMock>(), vconf_notify_key_changed(_, _, _))
- .WillRepeatedly(Return(-1));
-
- int ret = WatchMirrorTest::mirrorstub->Listen();
- EXPECT_NE(ret, 0);
-}
-
-TEST_F(WatchMirrorTest, MirrorGetCurrent_N) {
- shared_ptr<ISharableWatchBase> sw;
- sw = WatchMirrorTest::mirrorstub->GetCurrent();
- EXPECT_EQ(sw, nullptr);
-}
-
-TEST_F(WatchMirrorTest, OnChanged) {
- Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
- Watch *w = new Watch(string("test"), watchwin, WatchMirrorTest::mirrorstub, true);
- EXPECT_NE(w, nullptr);
- WatchMirror *mr = new WatchMirror(watchwin);
- EXPECT_NE(mr, nullptr);
- mr->OnChanged(*w);
- delete w;
- delete mr;
-}
-
-TEST_F(WatchMirrorTest, OnAdded) {
- Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
- SharableWatchStub *w = nullptr;
-
- WatchMirror *mr = new WatchMirror(watchwin);
- EXPECT_NE(mr, nullptr);
- mr->OnAdded(*w);
-
- delete mr;
-}
-
-TEST_F(WatchMirrorTest, OnUpdated) {
- Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
- SharableWatchStub *w = nullptr;
-
- WatchMirror *mr = new WatchMirror(watchwin);
- EXPECT_NE(mr, nullptr);
- mr->OnUpdated(*w);
-
- delete mr;
-}
-
-TEST_F(WatchMirrorTest, OnRemoved) {
- Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
- SharableWatchStub *w = nullptr;
-
- WatchMirror *mr = new WatchMirror(watchwin);
- EXPECT_NE(mr, nullptr);
- mr->OnRemoved(*w);
-
- delete mr;
-}
-
-TEST_F(WatchMirrorTest, OnAmbientChanged) {
- Bundle *b = nullptr;
- Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
- WatchMirror *mr = new WatchMirror(watchwin);
- EXPECT_NE(mr, nullptr);
- mr->OnAmbientChanged(true, *b);
- delete mr;
-}
-
-TEST_F(WatchMirrorTest, OnAmbientEvent) {
- Bundle b;
- b.Add("__APP_AMBIENT_EVENT__", "1");
- Evas_Object* watchwin = elm_win_add(NULL, "Watch", ELM_WIN_BASIC);
- WatchMirror *mr = new WatchMirror(watchwin);
- EXPECT_NE(mr, nullptr);
- mr->OnAmbientEvent(AmbientListener::EVENT_AOD_READY, string("sender"), b);
- delete mr;
-}
\ No newline at end of file