From 863b9dfaa17de81f10ed9465230b8cea3d3c5df6 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Thu, 21 Sep 2023 19:10:39 +0900 Subject: [PATCH 1/1] Change unittest package name and improves code coverage Change-Id: I72dd2629a553fa7b9c83433388061bd21f097ab1 Signed-off-by: Inkyun Kil --- include/widget_app.hpp | 2 + packaging/appcore-widget.spec | 6 +- src/base/widget_base.cc | 13 +++- src/base/widget_base_legacy.c | 4 +- src/efl_base/widget_app.cc | 121 +++++++++++++++++---------------- test/unit_tests/main.cc | 12 ++-- test/unit_tests/mock/ecore_wl2_mock.cc | 27 -------- test/unit_tests/mock/ecore_wl2_mock.h | 12 ---- test/unit_tests/mock/gio_mock.cc | 99 --------------------------- test/unit_tests/mock/gio_mock.h | 67 ------------------ test/unit_tests/test_widget_app.cc | 33 ++++++--- test/unit_tests/test_widget_app_cpp.cc | 23 ++++++- 12 files changed, 130 insertions(+), 289 deletions(-) delete mode 100644 test/unit_tests/mock/gio_mock.cc delete mode 100755 test/unit_tests/mock/gio_mock.h diff --git a/include/widget_app.hpp b/include/widget_app.hpp index fb9a05d..f0fc3c7 100644 --- a/include/widget_app.hpp +++ b/include/widget_app.hpp @@ -97,6 +97,7 @@ class WidgetAppBase : public app_common::AppBase< int Run(int argc, char** argv, std::unique_ptr factory) { factory_ = std::move(factory); +/* LCOV_EXCL_START */ widget_app_lifecycle_callback_s callback = { create : [](void *user_data) -> widget_class_h { WidgetAppBase* b = static_cast(user_data); @@ -170,6 +171,7 @@ class WidgetAppBase : public app_common::AppBase< b->OnTerminate(); } }; +/* LCOV_EXCL_STOP */ return widget_app_main(argc, argv, &callback, this); } diff --git a/packaging/appcore-widget.spec b/packaging/appcore-widget.spec index 762694f..b722455 100644 --- a/packaging/appcore-widget.spec +++ b/packaging/appcore-widget.spec @@ -55,10 +55,10 @@ Requires: %{name} = %{version}-%{release} %description -n capi-appfw-widget-application-devel widget application (development files) -%package -n appcore_widget_unittests +%package -n appcore-widget-unittests Summary: GTest for appcore-widget Group: Development/Libraries -%description -n appcore_widget_unittests +%description -n appcore-widget-unittests GTest for appcore-widget @@ -166,7 +166,7 @@ install -m 0644 appcore-widget.zip %{buildroot}%{_datadir}/gcov/obj/ %{_libdir}/pkgconfig/capi-appfw-widget-application.pc %{_libdir}/libcapi-appfw-widget-application.so -%files -n appcore_widget_unittests +%files -n appcore-widget-unittests %{_bindir}/appcore-widget-unittest %{_bindir}/tizen-unittests/%{name}/run-unittest.sh diff --git a/src/base/widget_base.cc b/src/base/widget_base.cc index 26219b3..20c10e1 100644 --- a/src/base/widget_base.cc +++ b/src/base/widget_base.cc @@ -45,9 +45,11 @@ class AppContext { app_id_ = app_id; } +/* LCOV_EXCL_START */ const std::string& GetAppId() const { return app_id_; } +/* LCOV_EXCL_STOP */ void SetPackageId(const std::string& package_id) { package_id_ = package_id; @@ -72,7 +74,7 @@ class AppContext { bool IsPermanent() const { return permanent_; } - +/* LCOV_EXCL_START */ void SetFgSignal(bool fg_signal) { fg_signal_ = fg_signal; } @@ -80,6 +82,7 @@ class AppContext { bool IsFgSignal() const { return fg_signal_; } +/* LCOV_EXCL_STOP */ int SendUpdateStatus(const std::string& class_id, const std::string& instance_id, int status, int err, @@ -499,6 +502,7 @@ int WidgetBase::OnControl(tizen_base::Bundle b) { return 0; } +/* LCOV_EXCL_START */ void WidgetContext::Impl::OnUpdate(bool force) { parent_->OnUpdate(pending_content_.empty() ? tizen_base::Bundle() : tizen_base::Bundle(pending_content_), force); @@ -509,6 +513,7 @@ void WidgetContext::Impl::OnUpdate(bool force) { WIDGET_INSTANCE_EVENT_UPDATE, 0, nullptr); _D("Updated: %s", id.c_str()); } +/* LCOV_EXCL_STOP */ void WidgetContext::Impl::UpdateProcess(const tizen_base::Bundle& b) { bool force; @@ -534,6 +539,7 @@ void WidgetContext::Impl::UpdateProcess(const tizen_base::Bundle& b) { } } +/* LCOV_EXCL_START */ void WidgetContext::Impl::SetPeriod(double period) { period_ = period; } @@ -548,6 +554,7 @@ void WidgetContext::Impl::SetPeriodicTimer() { TimedOutCb, parent_); } } +/* LCOV_EXCL_STOP */ void WidgetContext::Impl::UnsetPeriodicTimer() { if (periodic_timer_) { @@ -557,6 +564,7 @@ void WidgetContext::Impl::UnsetPeriodicTimer() { } } +/* LCOV_EXCL_START */ gboolean WidgetContext::Impl::TimedOutCb(gpointer user_data) { WidgetContext* wc = reinterpret_cast(user_data); if (wc->IsResumed()) { @@ -573,6 +581,7 @@ gboolean WidgetContext::Impl::TimedOutCb(gpointer user_data) { return G_SOURCE_CONTINUE; } +/* LCOV_EXCL_STOP */ WidgetContext::WidgetContext(std::string context_id, std::string inst_id, AppCoreMultiWindowBase* app) @@ -583,6 +592,7 @@ WidgetContext::WidgetContext(std::string context_id, std::string inst_id, WidgetContext::~WidgetContext() = default; +/* LCOV_EXCL_START */ void WidgetContext::OnPause() { std::string id = GetInstId(); _D("WidgetContext(%s) is paused", id.c_str()); @@ -617,6 +627,7 @@ void WidgetContext::OnResume() { __context.SetFgSignal(true); } } +/* LCOV_EXCL_STOP */ void WidgetContext::OnResize(int w, int h) { } diff --git a/src/base/widget_base_legacy.c b/src/base/widget_base_legacy.c index 40115b7..5e44d2c 100644 --- a/src/base/widget_base_legacy.c +++ b/src/base/widget_base_legacy.c @@ -98,6 +98,7 @@ static bool __is_permanent; static void __call_update_cb(const char *class_id, const char *id, int force, const char *content_raw); +/* LCOV_EXCL_START */ static gboolean __timeout_cb(gpointer user_data) { widget_base_instance_data *data = @@ -911,11 +912,9 @@ EXPORT_API int widget_base_context_set_content_info( free(raw); if (ret < 0) { - /* LCOV_EXCL_START */ LOGE("failed to send content info: %s of %s (%d)", id, class_id, ret); return WIDGET_BASE_ERROR_IO_ERROR; - /* LCOV_EXCL_STOP */ } return WIDGET_BASE_ERROR_NONE; @@ -1574,3 +1573,4 @@ EXPORT_API widget_base_class *widget_base_class_add(widget_base_class cls, return c; } +/* LCOV_EXCL_STOP */ \ No newline at end of file diff --git a/src/efl_base/widget_app.cc b/src/efl_base/widget_app.cc index c35a6a1..a97b2ea 100644 --- a/src/efl_base/widget_app.cc +++ b/src/efl_base/widget_app.cc @@ -87,7 +87,7 @@ class AppWidget : public WidgetBase { WidgetBase::OnTerminate(); return -1; } - +/* LCOV_EXCL_START */ void OnLoopInit(int argc, char** argv) override { elm_init(argc, argv); } @@ -99,17 +99,17 @@ class AppWidget : public WidgetBase { void OnLoopRun() override { elm_run(); } - +/* LCOV_EXCL_STOP */ void OnLoopExit() override { elm_exit(); } - +/* LCOV_EXCL_START */ int OnTrimMemory() override { _D("Trim memory"); elm_cache_all_flush(); return WidgetBase::OnTrimMemory(); } - +/* LCOV_EXCL_STOP */ private: widget_app_lifecycle_callback_s* callback_; void* user_data_; @@ -237,6 +237,7 @@ class AppWidgetContext : public WidgetContext { } private: +/* LCOV_EXCL_START */ void SetIconifyTimer() { if (iconify_timer_) return; @@ -256,7 +257,7 @@ class AppWidgetContext : public WidgetContext { return G_SOURCE_REMOVE; }, this); } - +/* LCOV_EXCL_STOP */ void UnsetIconifyTimer() { if (iconify_timer_) { g_source_remove(iconify_timer_); @@ -294,8 +295,8 @@ API int widget_app_main(int argc, char** argv, } if (callback->create == nullptr) { - _E("widget_app_create_cb() callback must be registered"); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("widget_app_create_cb() callback must be registered");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER;/* LCOV_EXCL_LINE */ } try { @@ -304,8 +305,8 @@ API int widget_app_main(int argc, char** argv, __app_widget->AddEvent(i); __app_widget->Run(argc, argv); - } catch (std::runtime_error& e) { - return WIDGET_ERROR_FAULT; + } catch (std::runtime_error& e) {/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_FAULT;/* LCOV_EXCL_LINE */ } return WIDGET_ERROR_NONE; @@ -337,8 +338,8 @@ API int widget_app_terminate_context(widget_context_h context) { return WIDGET_ERROR_NOT_SUPPORTED; if (context == nullptr) { - _E("Invalid parameter"); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER;/* LCOV_EXCL_LINE */ } auto* cxt = reinterpret_cast(context); @@ -356,8 +357,8 @@ API int widget_app_foreach_context(widget_context_cb cb, void* data) { return WIDGET_ERROR_NOT_SUPPORTED; if (cb == nullptr) { - _E("Invalid parameter"); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER;/* LCOV_EXCL_LINE */ } if (__app_widget.get() == nullptr) @@ -395,15 +396,15 @@ API int widget_app_add_event_handler(app_event_handler_h* event_handler, auto* app_event = new (std::nothrow) AppEvent( ::__app_event_converter[event_type], callback, user_data); if (app_event == nullptr) { - _E("Out of memory"); - return WIDGET_ERROR_OUT_OF_MEMORY; + _E("Out of memory");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_OUT_OF_MEMORY;/* LCOV_EXCL_LINE */ } auto* h = new (std::nothrow) std::shared_ptr(app_event); if (h == nullptr) { - _E("Out of memory"); - delete app_event; - return WIDGET_ERROR_OUT_OF_MEMORY; + _E("Out of memory");/* LCOV_EXCL_LINE */ + delete app_event;/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_OUT_OF_MEMORY;/* LCOV_EXCL_LINE */ } if (__app_widget.get() != nullptr) @@ -444,18 +445,18 @@ API const char* widget_app_get_id(widget_context_h context) { bool feature; int ret = system_info_get_platform_bool(kFeatureShellAppWidget, &feature); if (ret < 0) { - set_last_result(WIDGET_ERROR_FAULT); - return nullptr; + set_last_result(WIDGET_ERROR_FAULT);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } if (!feature) { - set_last_result(WIDGET_ERROR_NOT_SUPPORTED); - return nullptr; + set_last_result(WIDGET_ERROR_NOT_SUPPORTED);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } if (context == nullptr) { - set_last_result(WIDGET_ERROR_INVALID_PARAMETER); - return nullptr; + set_last_result(WIDGET_ERROR_INVALID_PARAMETER);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } auto* cxt = reinterpret_cast(context); @@ -474,8 +475,8 @@ API int widget_app_get_elm_win(widget_context_h context, Evas_Object** win) { return WIDGET_ERROR_NOT_SUPPORTED; if (context == nullptr || win == nullptr) { - _E("Invalid parameter"); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER;/* LCOV_EXCL_LINE */ } auto* cxt = reinterpret_cast(context); @@ -494,9 +495,9 @@ API int widget_app_get_elm_win(widget_context_h context, Evas_Object** win) { Ecore_Wl2_Window* wl_win = ecore_evas_wayland2_window_get( ecore_evas_ecore_evas_get(evas_object_evas_get(ret_win))); if (wl_win == nullptr) { - _E("Failed to get wayland window"); - evas_object_del(ret_win); - return WIDGET_ERROR_FAULT; + _E("Failed to get wayland window");/* LCOV_EXCL_LINE */ + evas_object_del(ret_win);/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_FAULT;/* LCOV_EXCL_LINE */ } ecore_wl2_window_class_set(wl_win, id.c_str()); @@ -527,32 +528,32 @@ API widget_class_h widget_app_class_add(widget_class_h widget_class, bool feature; int ret = system_info_get_platform_bool(kFeatureShellAppWidget, &feature); if (ret < 0) { - set_last_result(WIDGET_ERROR_FAULT); - return nullptr; + set_last_result(WIDGET_ERROR_FAULT);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } if (!feature) { - set_last_result(WIDGET_ERROR_NOT_SUPPORTED); - return nullptr; + set_last_result(WIDGET_ERROR_NOT_SUPPORTED);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } if (class_id == nullptr || callback.create == nullptr) { - _E("Invalid parameter"); - set_last_result(WIDGET_ERROR_INVALID_PARAMETER); - return nullptr; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + set_last_result(WIDGET_ERROR_INVALID_PARAMETER);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } if (__app_widget.get() == nullptr) { - set_last_result(WIDGET_ERROR_FAULT); - return nullptr; + set_last_result(WIDGET_ERROR_FAULT);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } auto factory = std::shared_ptr( new (std::nothrow) AppWidgetContext::Factory( class_id, callback, user_data)); if (factory.get() == nullptr) { - set_last_result(WIDGET_ERROR_OUT_OF_MEMORY); - return nullptr; + set_last_result(WIDGET_ERROR_OUT_OF_MEMORY);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } __app_widget->AddContextFactory(std::move(factory), class_id); @@ -567,26 +568,26 @@ API widget_class_h widget_app_class_create( bool feature; int ret = system_info_get_platform_bool(kFeatureShellAppWidget, &feature); if (ret < 0) { - set_last_result(WIDGET_ERROR_FAULT); - return nullptr; + set_last_result(WIDGET_ERROR_FAULT);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } if (!feature) { - set_last_result(WIDGET_ERROR_NOT_SUPPORTED); - return nullptr; + set_last_result(WIDGET_ERROR_NOT_SUPPORTED);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } if (callback.create == nullptr) { - _E("Invalid parameter"); - set_last_result(WIDGET_ERROR_INVALID_PARAMETER); - return nullptr; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + set_last_result(WIDGET_ERROR_INVALID_PARAMETER);/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } char* appid = nullptr; app_get_id(&appid); if (appid == nullptr) { - LOGE("app_get_id() is failed"); - return nullptr; + LOGE("app_get_id() is failed");/* LCOV_EXCL_LINE */ + return nullptr;/* LCOV_EXCL_LINE */ } std::unique_ptr ptr(appid, std::free); @@ -604,8 +605,8 @@ API int widget_app_context_set_tag(widget_context_h context, void* tag) { return WIDGET_ERROR_NOT_SUPPORTED; if (context == nullptr) { - _E("Invalid parameter"); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER;/* LCOV_EXCL_LINE */ } auto* cxt = reinterpret_cast(context); @@ -623,8 +624,8 @@ API int widget_app_context_get_tag(widget_context_h context, void** tag) { return WIDGET_ERROR_NOT_SUPPORTED; if (context == nullptr || tag == nullptr) { - _E("Invalid parameter"); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER;/* LCOV_EXCL_LINE */ } auto* cxt = reinterpret_cast(context); @@ -643,15 +644,15 @@ API int widget_app_context_set_content_info(widget_context_h context, return WIDGET_ERROR_NOT_SUPPORTED; if (context == nullptr || content_info == nullptr) { - _E("Invalid parameter"); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER;/* LCOV_EXCL_LINE */ } auto* cxt = reinterpret_cast(context); ret = cxt->SetContents(tizen_base::Bundle(content_info)); if (ret != WIDGET_ERROR_NONE) { - _E("Failed to set content"); - return static_cast(ret); + _E("Failed to set content");/* LCOV_EXCL_LINE */ + return static_cast(ret);/* LCOV_EXCL_LINE */ } return WIDGET_ERROR_NONE; @@ -668,13 +669,13 @@ API int widget_app_context_set_title(widget_context_h context, return WIDGET_ERROR_NOT_SUPPORTED; if (context == nullptr || title == nullptr) { - _E("Invalid parameter"); - return WIDGET_ERROR_INVALID_PARAMETER; + _E("Invalid parameter");/* LCOV_EXCL_LINE */ + return WIDGET_ERROR_INVALID_PARAMETER;/* LCOV_EXCL_LINE */ } auto* cxt = reinterpret_cast(context); if (cxt->GetWindow()) - elm_win_title_set(cxt->GetWindow(), title); + elm_win_title_set(cxt->GetWindow(), title);/* LCOV_EXCL_LINE */ return WIDGET_ERROR_NONE; } diff --git a/test/unit_tests/main.cc b/test/unit_tests/main.cc index 5f340cd..d945e33 100644 --- a/test/unit_tests/main.cc +++ b/test/unit_tests/main.cc @@ -9,16 +9,16 @@ int main(int argc, char** argv) { int ret = -1; try { testing::InitGoogleTest(&argc, argv); - } catch(...) { - std::cout << "Exception occurred" << std::endl; + } catch(...) {/* LCOV_EXCL_LINE */ + std::cout << "Exception occurred" << std::endl;/* LCOV_EXCL_LINE */ } try { ret = RUN_ALL_TESTS(); - } catch (const ::testing::internal::GoogleTestFailureException& e) { - ret = -1; - std::cout << "GoogleTestFailureException was thrown:" << e.what() - << std::endl; + } catch (const ::testing::internal::GoogleTestFailureException& e) {/* LCOV_EXCL_LINE */ + ret = -1;/* LCOV_EXCL_LINE */ + std::cout << "GoogleTestFailureException was thrown:" << e.what()/* LCOV_EXCL_LINE */ + << std::endl;/* LCOV_EXCL_LINE */ } return ret; diff --git a/test/unit_tests/mock/ecore_wl2_mock.cc b/test/unit_tests/mock/ecore_wl2_mock.cc index 1cf68e6..08c0649 100644 --- a/test/unit_tests/mock/ecore_wl2_mock.cc +++ b/test/unit_tests/mock/ecore_wl2_mock.cc @@ -25,16 +25,6 @@ extern "C" int ecore_wl2_init() { return MOCK_HOOK_P0(EcoreWl2Mock, ecore_wl2_init); } -extern "C" Ecore_Wl2_Display* ecore_wl2_connected_display_get( - const char *display) { - return MOCK_HOOK_P1(EcoreWl2Mock, ecore_wl2_connected_display_get, display); -} - -extern "C" void ecore_wl2_window_iconified_set( - Ecore_Wl2_Window *win, Eina_Bool flag) { - return MOCK_HOOK_P2(EcoreWl2Mock, ecore_wl2_window_iconified_set, win, flag); -} - extern "C" void ecore_wl2_window_class_set( Ecore_Wl2_Window *win, const char *name) { return MOCK_HOOK_P2(EcoreWl2Mock, ecore_wl2_window_class_set, win, name); @@ -45,19 +35,6 @@ extern "C" int ecore_wl2_window_id_get( return MOCK_HOOK_P1(EcoreWl2Mock, ecore_wl2_window_id_get, win); } -extern "C" void ecore_wl2_display_disconnect( - Ecore_Wl2_Display *display) { - return MOCK_HOOK_P1(EcoreWl2Mock, ecore_wl2_display_disconnect, display); -} - -extern "C" int ecore_wl2_shutdown() { - return MOCK_HOOK_P0(EcoreWl2Mock, ecore_wl2_shutdown); -} - -extern "C" Ecore_Wl2_Display *ecore_wl2_display_connect(const char *conn) { - return MOCK_HOOK_P1(EcoreWl2Mock, ecore_wl2_display_connect, conn); -} - extern "C" Ecore_Wl2_Window *ecore_evas_wayland2_window_get(const Ecore_Evas *ee) { return MOCK_HOOK_P1(EcoreWl2Mock, ecore_evas_wayland2_window_get, ee); } @@ -70,10 +47,6 @@ extern "C" Evas *evas_object_evas_get(const Eo *eo_obj) { return MOCK_HOOK_P1(EcoreWl2Mock, evas_object_evas_get, eo_obj); } -extern "C" void evas_object_del(Evas_Object *obj) { - return MOCK_HOOK_P1(EcoreWl2Mock, evas_object_del, obj); -} - extern "C" struct wl_surface *ecore_wl2_window_surface_get(Ecore_Wl2_Window *window) { return MOCK_HOOK_P1(EcoreWl2Mock, ecore_wl2_window_surface_get, window); } diff --git a/test/unit_tests/mock/ecore_wl2_mock.h b/test/unit_tests/mock/ecore_wl2_mock.h index bf7f84f..e0cd5fd 100644 --- a/test/unit_tests/mock/ecore_wl2_mock.h +++ b/test/unit_tests/mock/ecore_wl2_mock.h @@ -30,28 +30,16 @@ class EcoreWl2Mock : public virtual ModuleMock { MOCK_METHOD0(ecore_wl2_init, int()); - MOCK_METHOD1(ecore_wl2_connected_display_get, - Ecore_Wl2_Display*(const char *)); - MOCK_METHOD2(ecore_wl2_window_iconified_set, - void(Ecore_Wl2_Window *, Eina_Bool)); MOCK_METHOD2(ecore_wl2_window_class_set, void(Ecore_Wl2_Window *, const char *)); MOCK_METHOD1(ecore_wl2_window_id_get, int(Ecore_Wl2_Window *)); - MOCK_METHOD1(ecore_wl2_display_disconnect, - void(Ecore_Wl2_Display *)); - MOCK_METHOD0(ecore_wl2_shutdown, - int()); - MOCK_METHOD1(ecore_wl2_display_connect, - Ecore_Wl2_Display *(const char *)); MOCK_METHOD1(ecore_evas_wayland2_window_get, Ecore_Wl2_Window *(const Ecore_Evas *)); MOCK_METHOD1(ecore_evas_ecore_evas_get, Ecore_Evas *(const Evas *)); MOCK_METHOD1(evas_object_evas_get, Evas *(const Eo *)); - MOCK_METHOD1(evas_object_del, - void (Evas_Object *)); MOCK_METHOD1(ecore_wl2_window_surface_get, struct wl_surface *(Ecore_Wl2_Window *)); MOCK_METHOD3(evas_object_data_set, diff --git a/test/unit_tests/mock/gio_mock.cc b/test/unit_tests/mock/gio_mock.cc deleted file mode 100644 index 4e048fc..0000000 --- a/test/unit_tests/mock/gio_mock.cc +++ /dev/null @@ -1,99 +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 "unit_tests/mock/gio_mock.h" - -#include - -#include "unit_tests/mock/mock_hook.h" -#include "unit_tests/mock/test_fixture.h" - -extern "C" GDBusConnection* g_bus_get_sync(GBusType type, - GCancellable* cancellable, GError** error) { - return MOCK_HOOK_P3(GioMock, g_bus_get_sync, type, cancellable, error); -} - -extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_sync( - GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags, - gint timeout, volatile guint32* out_serial, GCancellable* cancellable, - GError** error) { - return MOCK_HOOK_P7(GioMock, g_dbus_connection_send_message_with_reply_sync, - conn, msg, flags, timeout, out_serial, cancellable, error); -} - -extern "C" GDBusMessage* g_dbus_message_new_method_call(const gchar* arg0, - const gchar* arg1, const gchar* arg2, const gchar* arg3) { - return MOCK_HOOK_P4(GioMock, g_dbus_message_new_method_call, arg0, arg1, arg2, - arg3); -} - -extern "C" void g_dbus_message_set_body(GDBusMessage* arg0, GVariant* arg1) { - return MOCK_HOOK_P2(GioMock, g_dbus_message_set_body, arg0, arg1); -} - -extern "C" GVariant* g_dbus_message_get_body(GDBusMessage* arg0) { - return MOCK_HOOK_P1(GioMock, g_dbus_message_get_body, arg0); -} - -extern "C" gboolean g_dbus_connection_emit_signal(GDBusConnection* arg0, - const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4, - GVariant* arg5, GError** arg6) { - return MOCK_HOOK_P7(GioMock, g_dbus_connection_emit_signal, - arg0, arg1, arg2, arg3, arg4, arg5, arg6); -} - -extern "C" GDBusNodeInfo* g_dbus_node_info_new_for_xml( - const gchar* arg0, GError** arg1) { - return MOCK_HOOK_P2(GioMock, g_dbus_node_info_new_for_xml, arg0, arg1); -} - -extern "C" guint g_dbus_connection_register_object(GDBusConnection* arg0, - const gchar* arg1, GDBusInterfaceInfo* arg2, - const GDBusInterfaceVTable* arg3, gpointer arg4, - GDestroyNotify arg5, GError** arg6) { - return MOCK_HOOK_P7(GioMock, g_dbus_connection_register_object, - arg0, arg1, arg2, arg3, arg4, arg5, arg6); -} - -extern "C" guint g_bus_own_name_on_connection(GDBusConnection* arg0, - const gchar* arg1, GBusNameOwnerFlags arg2, - GBusNameAcquiredCallback arg3, GBusNameLostCallback arg4, - gpointer arg5, GDestroyNotify arg6) { - return MOCK_HOOK_P7(GioMock, g_bus_own_name_on_connection, - arg0, arg1, arg2, arg3, arg4, arg5, arg6); -} - -extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0, - const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4, - const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7, - gpointer arg8, GDestroyNotify arg9) { - return MOCK_HOOK_P10(GioMock, g_dbus_connection_signal_subscribe, - arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); -} - -extern "C" void g_dbus_connection_send_message_with_reply(GDBusConnection* arg0, - GDBusMessage* arg1, GDBusSendMessageFlags arg2, gint arg3, - volatile guint32* arg4, GCancellable* arg5, GAsyncReadyCallback arg6, - gpointer arg7) { - return MOCK_HOOK_P8(GioMock, g_dbus_connection_send_message_with_reply, - arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7); -} - -extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_finish( - GDBusConnection* arg0, GAsyncResult* arg1, GError** arg2) { - return MOCK_HOOK_P3(GioMock, g_dbus_connection_send_message_with_reply_finish, - arg0, arg1, arg2); -} diff --git a/test/unit_tests/mock/gio_mock.h b/test/unit_tests/mock/gio_mock.h deleted file mode 100755 index a85f992..0000000 --- a/test/unit_tests/mock/gio_mock.h +++ /dev/null @@ -1,67 +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. - */ - -#ifndef UNIT_TESTS_MOCK_GIO_MOCK_H_ -#define UNIT_TESTS_MOCK_GIO_MOCK_H_ - -#include -#include - -#include "mock/module_mock.h" - -class GioMock : public virtual ModuleMock { - public: - virtual ~GioMock() {} - - MOCK_METHOD3(g_bus_get_sync, - GDBusConnection*(GBusType, GCancellable*, GError**)); - MOCK_METHOD7(g_bus_own_name_on_connection, - guint(GDBusConnection*, const gchar*, GBusNameOwnerFlags, - GBusNameAcquiredCallback, GBusNameLostCallback, - gpointer, GDestroyNotify)); - - MOCK_METHOD4(g_dbus_message_new_method_call, - GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*)); - MOCK_METHOD2(g_dbus_message_set_body, void(GDBusMessage*, GVariant*)); - MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*)); - - MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync, - GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, - gint, volatile guint32*, GCancellable*, GError**)); - MOCK_METHOD7(g_dbus_connection_emit_signal, - gboolean(GDBusConnection*, const gchar*, const gchar*, const gchar*, - const gchar*, GVariant*, GError**)); - MOCK_METHOD7(g_dbus_connection_register_object, - guint(GDBusConnection*, const gchar*, GDBusInterfaceInfo*, - const GDBusInterfaceVTable*, gpointer, GDestroyNotify, GError**)); - MOCK_METHOD10(g_dbus_connection_signal_subscribe, - guint(GDBusConnection*, const gchar*, const gchar*, const gchar*, - const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback, - gpointer, GDestroyNotify)); - MOCK_METHOD8(g_dbus_connection_send_message_with_reply, - void(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, gint, - volatile guint32*, GCancellable*, GAsyncReadyCallback, gpointer)); - MOCK_METHOD3(g_dbus_connection_send_message_with_reply_finish, - GDBusMessage*(GDBusConnection*, GAsyncResult*, GError**)); - - MOCK_METHOD2(g_dbus_node_info_new_for_xml, - GDBusNodeInfo*(const gchar*, GError**)); - - MOCK_METHOD2(g_dbus_method_invocation_return_value, - GDBusNodeInfo*(GDBusMethodInvocation*, GVariant*)); -}; - -#endif // UNIT_TESTS_MOCK_GIO_MOCK_H_ diff --git a/test/unit_tests/test_widget_app.cc b/test/unit_tests/test_widget_app.cc index 7c73261..dce49a5 100644 --- a/test/unit_tests/test_widget_app.cc +++ b/test/unit_tests/test_widget_app.cc @@ -24,13 +24,13 @@ #include #include "include/widget_app.h" +#include "include/widget_app_internal.h" #include "include/widget_app_efl.h" #include "unit_tests/mock/app_common_mock.h" #include "unit_tests/mock/appcore_multiwindow_base_mock.h" #include "unit_tests/mock/aul_mock.h" #include "unit_tests/mock/ecore_wl2_mock.h" #include "unit_tests/mock/elm_mock.h" -#include "unit_tests/mock/gio_mock.h" #include "unit_tests/mock/system_info_mock.h" #include "unit_tests/mock/test_fixture.h" #include "unit_tests/mock/widget_service_mock.h" @@ -53,6 +53,7 @@ int __instance_destroy_cb(widget_context_h context, return 0; } +/* LCOV_EXCL_START */ int __instance_pause_cb(widget_context_h context, void* user_data) { return 0; } @@ -61,13 +62,14 @@ int __instance_resume_cb(widget_context_h context, void* user_data) { return 0; } -int __instance_resize_cb(widget_context_h context, - int w, int h, void* user_data) { +int __instance_update_cb(widget_context_h context, + bundle* content, int force, void* user_data) { return 0; } +/* LCOV_EXCL_STOP */ -int __instance_update_cb(widget_context_h context, - bundle* content, int force, void* user_data) { +int __instance_resize_cb(widget_context_h context, + int w, int h, void* user_data) { return 0; } @@ -88,18 +90,17 @@ int __aul_app_get_pkgid_bypid_fake(int pid, char* pkgid, int len) { snprintf(pkgid, len, "%s", "test"); return 0; } - +/* LCOV_EXCL_START */ void __app_event_cb(app_event_info_h event_info, void *user_data) { } bool __widget_context_cb(widget_context_h context, void *user_data) { return true; } - +/* LCOV_EXCL_STOP */ } // namespace -class Mocks : public ::testing::NiceMock, - public ::testing::NiceMock, +class Mocks : public ::testing::NiceMock, public ::testing::NiceMock, public ::testing::NiceMock, public ::testing::NiceMock, @@ -221,6 +222,8 @@ class WidgetAppTest : public TestFixture { b.Add("__WIDGET_OP__", "period"); p->OnControl(b); + p->OnReceive(AUL_WIDGET_CONTENT, b); + p->OnTerminate(); } }; @@ -253,6 +256,18 @@ TEST_F(WidgetAppTest, widget_app_main) { }); } +TEST_F(WidgetAppTest, widget_app_restart) { + PrepareContext( + [](widget_context_h context, bundle* content, + int w, int h, void* user_data) -> int { + EXPECT_CALL(GetMock(), + aul_notify_exit()).WillRepeatedly(Return(0)); + widget_app_exit(); + widget_app_restart(); + return 0; + }); +} + TEST_F(WidgetAppTest, widget_app_add_event_handler) { app_event_handler_h handle; EXPECT_CALL(GetMock(), diff --git a/test/unit_tests/test_widget_app_cpp.cc b/test/unit_tests/test_widget_app_cpp.cc index 8d5fca5..ec8ef39 100644 --- a/test/unit_tests/test_widget_app_cpp.cc +++ b/test/unit_tests/test_widget_app_cpp.cc @@ -26,7 +26,6 @@ #include "unit_tests/mock/aul_mock.h" #include "unit_tests/mock/ecore_wl2_mock.h" #include "unit_tests/mock/elm_mock.h" -#include "unit_tests/mock/gio_mock.h" #include "unit_tests/mock/system_info_mock.h" #include "unit_tests/mock/test_fixture.h" #include "unit_tests/mock/widget_service_mock.h" @@ -37,8 +36,7 @@ using ::testing::Invoke; using ::testing::Return; using ::testing::SetArgPointee; -class Mocks : public ::testing::NiceMock, - public ::testing::NiceMock, +class Mocks : public ::testing::NiceMock, public ::testing::NiceMock, public ::testing::NiceMock, public ::testing::NiceMock, @@ -63,12 +61,14 @@ class WidgetApp : public tizen_appfw::WidgetAppBase { }; explicit Instance(widget_context_h h) : InstanceBase(h) {} +/* LCOV_EXCL_START */ void OnCreate(const tizen_base::Bundle& content, int w, int h) override {} void OnDestroy(DestroyType reason, tizen_base::Bundle* content) override {} void OnPause() override {} void OnResume() override {} void OnResize(int w, int h) override {} void OnUpdate(const tizen_base::Bundle& content, bool force) override {} +/* LCOV_EXCL_STOP */ }; WidgetApp() {} @@ -85,6 +85,23 @@ TEST_F(WidgetAppCppTest, Run_InvalidParameter) { std::unique_ptr factory( new WidgetApp::Instance::Factory()); + widget_context_h h = nullptr; + factory->Create(h); + app.OnCreate(); int ret = app.Run(0, nullptr, std::move(factory)); EXPECT_EQ(ret, APP_ERROR_INVALID_PARAMETER); + app.OnTerminate(); } + +TEST_F(WidgetAppCppTest, NullInstance) { + EXPECT_CALL(GetMock(), + system_info_get_platform_bool(_, _)). + WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(0))); + + widget_context_h h = nullptr; + std::unique_ptr inst( + new WidgetApp::Instance(h)); + + widget_context_h ret_h = inst->GetHandle(); + EXPECT_EQ(ret_h, nullptr); +} \ No newline at end of file -- 2.7.4