From: Inkyun Kil Date: Wed, 22 Apr 2020 07:13:13 +0000 (+0900) Subject: Add unittests for Watch class X-Git-Tag: submit/tizen/20200422.092744~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c167c2bfc324cd86abb1f951458216a6096378dc;p=platform%2Fcore%2Fappfw%2Fwidget-viewer.git Add unittests for Watch class Change-Id: Ib105dacd95145e37902da559fc1ef2c4a318e27d Signed-off-by: Inkyun Kil --- diff --git a/unittest/src/test_watch.cc b/unittest/src/test_watch.cc new file mode 100644 index 00000000..4da4ed5c --- /dev/null +++ b/unittest/src/test_watch.cc @@ -0,0 +1,139 @@ +/* + * 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 +#include +#include + +#include +#include + +using namespace std; +using namespace tizen_base; +using namespace watch_holder; + +class WatchMirrorStub : public WatchMirror { + public: + WatchMirrorStub(Evas_Object* win) + : WatchMirror(win) { + } + + void OnChanged(const ISharableWatch& watch) override {} + void OnAdded(const ISharableWatch& watch) override {} + void OnUpdated(const ISharableWatch& watch) override {} + void OnRemoved(const ISharableWatch& watch) override {} +}; + +class WatchStub : public Watch{ + public: + WatchStub(string appid, Evas_Object* win, WatchMirrorStub* listener) + : Watch(appid, win, listener, true) { + } + WatchStub(int rid, std::string id, string appid, Evas_Object* win, WatchMirrorStub* listener) + : Watch(rid, id, appid, win, listener, true) { + } + WatchStub(string appid, Evas_Object* win, tizen_base::Bundle extra,WatchMirrorStub* listener) + : Watch(appid, win, extra, listener, true) { + } + WatchStub(int rid, std::string id, string appid, Evas_Object* win, tizen_base::Bundle extra, WatchMirrorStub* listener) + : Watch(rid, id, appid, win, extra, listener, true) { + } +}; + +class WatchTest : public ::testing::Test { + public: + WatchStub* stub; + WatchMirrorStub* mirrorstub; + + virtual void SetUp() { + Evas_Object* mirwin = elm_win_add(NULL, "Watch Mirror", ELM_WIN_BASIC); + mirrorstub = new WatchMirrorStub(mirwin); + Evas_Object* win = elm_win_add(NULL, "Watch", ELM_WIN_BASIC); + stub = new WatchStub(string("test"), win, mirrorstub); + } + virtual void TearDown() { + delete stub; + delete mirrorstub; + } +}; + +TEST_F(WatchTest, CreateInstance) { + EXPECT_NE(WatchTest::stub, nullptr); +} + +TEST_F(WatchTest, CreateInstance2) { + Evas_Object* mirwin = elm_win_add(NULL, "Watch Mirror", ELM_WIN_BASIC); + WatchMirrorStub* mirrorstub = new WatchMirrorStub(mirwin); + Evas_Object* win = elm_win_add(NULL, "Watch", ELM_WIN_BASIC); + WatchStub* stub = new WatchStub(0, string("id"), string("test"), win, mirrorstub); + EXPECT_NE(stub, nullptr); + delete stub; + delete mirrorstub; +} + +TEST_F(WatchTest, CreateInstance3) { + Bundle b; + b.Add("__APP_AMBIENT_EVENT__", "1"); + b.Add("__APP_AMBIENT_SENDER__", "test"); + Evas_Object* mirwin = elm_win_add(NULL, "Watch Mirror", ELM_WIN_BASIC); + WatchMirrorStub* mirrorstub = new WatchMirrorStub(mirwin); + Evas_Object* win = elm_win_add(NULL, "Watch", ELM_WIN_BASIC); + WatchStub* stub = new WatchStub(string("test"), win, b, mirrorstub); + EXPECT_NE(stub, nullptr); + delete stub; + delete mirrorstub; +} + +TEST_F(WatchTest, CreateInstance4) { + Bundle b; + b.Add("__APP_AMBIENT_EVENT__", "1"); + b.Add("__APP_AMBIENT_SENDER__", "test"); + Evas_Object* mirwin = elm_win_add(NULL, "Watch Mirror", ELM_WIN_BASIC); + WatchMirrorStub* mirrorstub = new WatchMirrorStub(mirwin); + Evas_Object* win = elm_win_add(NULL, "Watch", ELM_WIN_BASIC); + WatchStub* stub = new WatchStub(0, string("id"), string("test"), win, b,mirrorstub); + EXPECT_NE(stub, nullptr); + delete stub; + delete mirrorstub; +} + +TEST_F(WatchTest, Terminate) { + WatchTest::stub->Terminate(); +} + +TEST_F(WatchTest, GetPid) { + WatchTest::stub->GetPid(); +} + +TEST_F(WatchTest, IsBound) { + WatchTest::stub->IsBound(); +} + +TEST_F(WatchTest, GetAppId) { + WatchTest::stub->GetAppId(); +} + +TEST_F(WatchTest, GetCurrentImage) { + WatchTest::stub->GetCurrentImage(); +} + +TEST_F(WatchTest, GetExtra) { + WatchTest::stub->GetExtra(); +} + +TEST_F(WatchTest, IsFaulted) { + WatchTest::stub->IsFaulted(); +} \ No newline at end of file diff --git a/watch-holder/src/watch.cc b/watch-holder/src/watch.cc index 9260962a..fd21051f 100644 --- a/watch-holder/src/watch.cc +++ b/watch-holder/src/watch.cc @@ -32,30 +32,30 @@ using namespace tizen_base; using namespace screen_connector; namespace watch_holder { -Watch::Watch(string appid, Evas_Object* viewer_win, Watch::IEvent* listener) +Watch::Watch(string appid, Evas_Object* viewer_win, Watch::IEvent* listener, bool mock) : RemoteSurfaceEvas(appid, RemoteSurface::WATCH, - make_shared(viewer_win, false)), + make_shared(viewer_win, false), mock), appid_(appid), listener_(listener) { RemoteSurfaceEvas::SetAutoVisibility(false); } -Watch::Watch(int rid, string id, string appid, Evas_Object* viewer_win, Watch::IEvent* listener) +Watch::Watch(int rid, string id, string appid, Evas_Object* viewer_win, Watch::IEvent* listener, bool mock) : RemoteSurfaceEvas(rid, id, RemoteSurface::WATCH, - make_shared(viewer_win, false)), + make_shared(viewer_win, false), mock), appid_(appid), listener_(listener) { RemoteSurfaceEvas::SetAutoVisibility(false); } -Watch::Watch(string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, Watch::IEvent* listener) +Watch::Watch(string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, Watch::IEvent* listener, bool mock) : RemoteSurfaceEvas(appid, RemoteSurface::WATCH, - make_shared(viewer_win, false)), + make_shared(viewer_win, false), mock), appid_(appid), listener_(listener), extra_data_(extra) { RemoteSurfaceEvas::SetAutoVisibility(false); } -Watch::Watch(int rid, string id, string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, Watch::IEvent* listener) +Watch::Watch(int rid, string id, string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, Watch::IEvent* listener, bool mock) : RemoteSurfaceEvas(rid, id, RemoteSurface::WATCH, - make_shared(viewer_win, false)), + make_shared(viewer_win, false), mock), appid_(appid), listener_(listener), extra_data_(extra) { RemoteSurfaceEvas::SetAutoVisibility(false); } diff --git a/watch-holder/src/watch.hh b/watch-holder/src/watch.hh index aeb6856c..5e168cc1 100644 --- a/watch-holder/src/watch.hh +++ b/watch-holder/src/watch.hh @@ -39,13 +39,13 @@ class EXPORT_API Watch : private screen_connector::RemoteSurfaceEvas, virtual void OnRemoved(const Watch& watch) = 0; }; - Watch(std::string appid, Evas_Object* viewer_win, IEvent* listener); + Watch(std::string appid, Evas_Object* viewer_win, IEvent* listener, bool mock = false); Watch(int rid, std::string id, std::string appid, Evas_Object* viewer_win, - Watch::IEvent* listener); + Watch::IEvent* listener, bool mock = false); Watch(std::string appid, Evas_Object* viewer_win, tizen_base::Bundle extra, - IEvent* listener); + IEvent* listener, bool mock = false); Watch(int rid, std::string id, std::string appid, Evas_Object* viewer_win, - tizen_base::Bundle extra, Watch::IEvent* listener); + tizen_base::Bundle extra, Watch::IEvent* listener, bool mock = false); virtual ~Watch() = default; void Resume() override; void Pause() override;