From: Inkyun Kil Date: Tue, 24 Oct 2023 23:06:34 +0000 (+0900) Subject: Improve code coverage X-Git-Tag: accepted/tizen/unified/20231025.093306~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7cee9b27c48a0004833dace0e95a5185a212fdf4;p=platform%2Fcore%2Fappfw%2Fwidget-viewer.git Improve code coverage - Remove needless unittest codes - Modify gcov package name and unittest package name Change-Id: I7af17e4f8a7004d6802732697464573190232fe7 Signed-off-by: Inkyun Kil --- diff --git a/packaging/libwidget_viewer.spec b/packaging/libwidget_viewer.spec index 5448f659..67478cae 100644 --- a/packaging/libwidget_viewer.spec +++ b/packaging/libwidget_viewer.spec @@ -171,33 +171,33 @@ While developing the widget applications, this viewer will load it and execute i %postun -n org.tizen.widget_viewer_sdk -p /sbin/ldconfig ################################################# -# widget-viewer-unittests +# libwidget_viewer_evas-unittests ################################################# -%package -n widget-viewer-unittests +%package -n libwidget_viewer_evas-unittests Summary: GTest for widget-viewer Group: Development/Libraries -%description -n widget-viewer-unittests +%description -n libwidget_viewer_evas-unittests GTest for widget-viewer -%files -n widget-viewer-unittests +%files -n libwidget_viewer_evas-unittests %{_bindir}/widget_viewer-unittests %{_bindir}/tizen-unittests/%{name}/run-unittest.sh ################################################# -# widget-viewer-gcov +# libwidget_viewer_evas-gcov ################################################# %if 0%{?gcov:1} -%package -n widget-viewer-gcov +%package -n libwidget_viewer_evas-gcov Summary: Simple string key-val dictionary ADT (gcov) Group: Application Framework/Testing -%description -n widget-viewer-gcov +%description -n libwidget_viewer_evas-gcov Simple string key-val dictionary ADT gcov objects %endif %if 0%{?gcov:1} -%files -n widget-viewer-gcov +%files -n libwidget_viewer_evas-gcov %{_datadir}/gcov/obj/* %endif diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index 1ea1c2db..8ddc0ff4 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -45,23 +45,17 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-O2") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../ambient-viewer/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../ambient-viewer/include) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../watch-holder/src) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../watch-holder-base/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src TEST_SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../ambient-viewer/src AMBIENT_VIEWER_SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../watch-holder-base/src WATCH_HOLDER_BASE_SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../watch-holder/src WATCH_HOLDER_SOURCES) ADD_EXECUTABLE(${PROJECT_NAME} ${TEST_SOURCES} ${MOCK_SOURCES} ${AMBIENT_VIEWER_SOURCES} - ${WATCH_HOLDER_BASE_SOURCES} - ${WATCH_HOLDER_SOURCES} ) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS}") @@ -69,7 +63,6 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}-unittests_LDFLAGS} gmock ambient-viewer - watch-holder ) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) diff --git a/tests/unit_tests/src/test_watch_holder.cc b/tests/unit_tests/src/test_watch_holder.cc deleted file mode 100644 index 3389d458..00000000 --- a/tests/unit_tests/src/test_watch_holder.cc +++ /dev/null @@ -1,233 +0,0 @@ -/* - * 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 "mock/test_fixture.h" - -#include -#include -#include -#include -#include -#include - -#include - -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 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 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, - public ::testing::NiceMock, - public ::testing::NiceMock, - public ::testing::NiceMock {}; - -} // namespace - -class WatchHolderTest : public TestFixture { - public: - WatchHolderTest() : TestFixture(std::make_unique()) {} - virtual ~WatchHolderTest() {} - WatchHolderStub* stub = nullptr; - - virtual void SetUp() { - EXPECT_CALL(GetMock(), aul_app_com_create(_, _, _, _, _)) - .WillRepeatedly(Invoke(__aul_app_com_create_fake)); - EXPECT_CALL(GetMock(), aul_app_com_leave(_)) - .WillRepeatedly(Invoke(__aul_app_com_leave_fake)); - EXPECT_CALL(GetMock(), - aul_app_get_appid_bypid(_, _, _)) - .WillRepeatedly(Invoke(__aul_app_get_appid_bypid_fake)); - EXPECT_CALL(GetMock(), - aul_svc_set_appid(_, _)).WillRepeatedly(Return(0)); - EXPECT_CALL(GetMock(), - appsvc_run_service(_, _, _, _)).WillRepeatedly(Return(0)); - EXPECT_CALL(GetMock(), evas_object_geometry_get(_, _, _, _, _)) - .WillRepeatedly(Invoke(__evas_object_geometry_get)); - EXPECT_CALL(GetMock(), elm_win_add(_, _, _)) - .WillRepeatedly(Return(reinterpret_cast( - 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 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 w2 = - WatchHolderTest::stub->CreateWatch(1, string("id"), - string("appid"), b, true); - EXPECT_NE(w2, nullptr); -} - -TEST_F(WatchHolderTest, LaunchWatch) { - EXPECT_CALL(GetMock(), 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> 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 diff --git a/tests/unit_tests/src/test_watch_mirror.cc b/tests/unit_tests/src/test_watch_mirror.cc deleted file mode 100644 index 8bb8ac53..00000000 --- a/tests/unit_tests/src/test_watch_mirror.cc +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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 -#include -#include -#include - -#include "test_fixture.h" - -#include - -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 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, - public ::testing::NiceMock, - public ::testing::NiceMock {}; - -} // namespace - -class WatchMirrorTest : public TestFixture { - public: - WatchMirrorTest() : TestFixture(std::make_unique()) {} - WatchMirrorStub* mirrorstub; - - virtual void SetUp() { - EXPECT_CALL(GetMock(), aul_app_com_create(_, _, _, _, _)) - .WillRepeatedly(Return(0)); - EXPECT_CALL(GetMock(), aul_app_com_leave(_)) - .WillRepeatedly(Return(0)); - EXPECT_CALL(GetMock(), vconf_notify_key_changed(_, _, _)) - .WillRepeatedly(Return(0)); - EXPECT_CALL(GetMock(), vconf_ignore_key_changed(_, _)) - .WillRepeatedly(Return(0)); - EXPECT_CALL(GetMock(), elm_win_add(_, _, _)) - .WillRepeatedly(Return(reinterpret_cast( - 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(), 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(), vconf_notify_key_changed(_, _, _)) - .WillRepeatedly(Return(-1)); - - int ret = WatchMirrorTest::mirrorstub->Listen(); - EXPECT_NE(ret, 0); -} - -TEST_F(WatchMirrorTest, MirrorGetCurrent_N) { - shared_ptr 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