From af733e56e8da1a54266739adfbe1be7f2bba4239 Mon Sep 17 00:00:00 2001 From: hyunho Date: Thu, 6 Aug 2020 13:00:51 +0900 Subject: [PATCH] Add widget efl unittests Change-Id: Ic9237c8f2c345e28f18603174d7557eded299c89 Signed-off-by: hyunho --- test/unit_tests/CMakeLists.txt | 2 +- test/unit_tests/mock/app_common_mock.cc | 26 ++ test/unit_tests/mock/app_common_mock.h | 33 ++ .../mock/appcore_multiwindow_base_mock.cc | 37 ++ .../mock/appcore_multiwindow_base_mock.h | 12 + test/unit_tests/mock/aul_mock.cc | 24 ++ test/unit_tests/mock/aul_mock.h | 33 ++ test/unit_tests/mock/ecore_wl2_mock.cc | 31 ++ test/unit_tests/mock/ecore_wl2_mock.h | 18 +- test/unit_tests/mock/elm_mock.cc | 46 +++ test/unit_tests/mock/elm_mock.h | 38 ++ test/unit_tests/test_widget_app.cc | 402 ++++++++++++++++++++- 12 files changed, 695 insertions(+), 7 deletions(-) create mode 100644 test/unit_tests/mock/app_common_mock.cc create mode 100644 test/unit_tests/mock/app_common_mock.h create mode 100644 test/unit_tests/mock/aul_mock.cc create mode 100644 test/unit_tests/mock/aul_mock.h create mode 100644 test/unit_tests/mock/elm_mock.cc create mode 100644 test/unit_tests/mock/elm_mock.h diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt index 5bdc45d..64fd8a4 100644 --- a/test/unit_tests/CMakeLists.txt +++ b/test/unit_tests/CMakeLists.txt @@ -7,7 +7,7 @@ ADD_EXECUTABLE(${TARGET_WIDGET_APPLICATION_UNIT_TEST} TARGET_INCLUDE_DIRECTORIES(${TARGET_WIDGET_APPLICATION_UNIT_TEST} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../" "${CMAKE_CURRENT_SOURCE_DIR}/../../include" - "${CMAKE_CURRENT_SOURCE_DIR}/../../src" + "${CMAKE_CURRENT_SOURCE_DIR}/../../src/efl_base" ) APPLY_PKG_CONFIG(${TARGET_WIDGET_APPLICATION_UNIT_TEST} PUBLIC diff --git a/test/unit_tests/mock/app_common_mock.cc b/test/unit_tests/mock/app_common_mock.cc new file mode 100644 index 0000000..c495c41 --- /dev/null +++ b/test/unit_tests/mock/app_common_mock.cc @@ -0,0 +1,26 @@ +/* + * 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/app_common_mock.h" + +#include + +#include "unit_tests/mock/mock_hook.h" +#include "unit_tests/mock/test_fixture.h" + +extern "C" int app_get_id(char **id) { + return MOCK_HOOK_P1(AppCommonMock, app_get_id, id); +} diff --git a/test/unit_tests/mock/app_common_mock.h b/test/unit_tests/mock/app_common_mock.h new file mode 100644 index 0000000..5fa214e --- /dev/null +++ b/test/unit_tests/mock/app_common_mock.h @@ -0,0 +1,33 @@ +/* + * 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_APP_COMMON_MOCK_H_ +#define UNIT_TESTS_MOCK_APP_COMMON_MOCK_H_ + +#include +#include + +#include "mock/module_mock.h" + +class AppCommonMock : public virtual ModuleMock { + public: + virtual ~AppCommonMock() {} + + MOCK_METHOD1(app_get_id, int (char **id)); +}; + +#endif // UNIT_TESTS_MOCK_APP_COMMON_MOCK_H_ + diff --git a/test/unit_tests/mock/appcore_multiwindow_base_mock.cc b/test/unit_tests/mock/appcore_multiwindow_base_mock.cc index f140a0d..0f88b17 100644 --- a/test/unit_tests/mock/appcore_multiwindow_base_mock.cc +++ b/test/unit_tests/mock/appcore_multiwindow_base_mock.cc @@ -44,3 +44,40 @@ extern "C" const char* appcore_multiwindow_base_instance_get_class_id( return MOCK_HOOK_P1(MultiWindowBaseMock, appcore_multiwindow_base_instance_get_class_id, context); } + +extern "C" void appcore_multiwindow_base_class_add( + appcore_multiwindow_base_class cls) { + return MOCK_HOOK_P1(MultiWindowBaseMock, + appcore_multiwindow_base_class_add, cls); +} + +extern "C" void appcore_multiwindow_base_instance_drop( + appcore_multiwindow_base_instance_h context) { + return MOCK_HOOK_P1(MultiWindowBaseMock, + appcore_multiwindow_base_instance_drop, context); +} + +extern "C" appcore_multiwindow_base_instance_h + appcore_multiwindow_base_instance_find(const char *id) { + return MOCK_HOOK_P1(MultiWindowBaseMock, + appcore_multiwindow_base_instance_find, id); +} + +extern "C" const appcore_multiwindow_base_class * + appcore_multiwindow_base_instance_get_class( + appcore_multiwindow_base_instance_h context) { + return MOCK_HOOK_P1(MultiWindowBaseMock, + appcore_multiwindow_base_instance_get_class, context); +} + +extern "C" void appcore_multiwindow_base_instance_exit( + appcore_multiwindow_base_instance_h context) { + return MOCK_HOOK_P1(MultiWindowBaseMock, + appcore_multiwindow_base_instance_exit, context); +} + +extern "C" void appcore_multiwindow_base_instance_pause( + appcore_multiwindow_base_instance_h context) { + return MOCK_HOOK_P1(MultiWindowBaseMock, + appcore_multiwindow_base_instance_pause, context); +} diff --git a/test/unit_tests/mock/appcore_multiwindow_base_mock.h b/test/unit_tests/mock/appcore_multiwindow_base_mock.h index 6aa400e..e15dc4e 100644 --- a/test/unit_tests/mock/appcore_multiwindow_base_mock.h +++ b/test/unit_tests/mock/appcore_multiwindow_base_mock.h @@ -34,6 +34,18 @@ class MultiWindowBaseMock : public virtual ModuleMock { void *(appcore_multiwindow_base_instance_h)); MOCK_METHOD1(appcore_multiwindow_base_instance_get_class_id, const char *(appcore_multiwindow_base_instance_h)); + MOCK_METHOD1(appcore_multiwindow_base_class_add, + void(appcore_multiwindow_base_class)); + MOCK_METHOD1(appcore_multiwindow_base_instance_drop, + void(appcore_multiwindow_base_instance_h)); + MOCK_METHOD1(appcore_multiwindow_base_instance_find, + appcore_multiwindow_base_instance_h(const char *)); + MOCK_METHOD1(appcore_multiwindow_base_instance_get_class, + const appcore_multiwindow_base_class *(appcore_multiwindow_base_instance_h)); + MOCK_METHOD1(appcore_multiwindow_base_instance_exit, + void(appcore_multiwindow_base_instance_h)); + MOCK_METHOD1(appcore_multiwindow_base_instance_pause, + void(appcore_multiwindow_base_instance_h)); }; #endif // UNIT_TESTS_MOCK_APPCORE_MULTIWINDOW_BASE_MOCK_H_ diff --git a/test/unit_tests/mock/aul_mock.cc b/test/unit_tests/mock/aul_mock.cc new file mode 100644 index 0000000..76ed247 --- /dev/null +++ b/test/unit_tests/mock/aul_mock.cc @@ -0,0 +1,24 @@ +/* + * 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/aul_mock.h" + +#include "unit_tests/mock/mock_hook.h" +#include "unit_tests/mock/test_fixture.h" + +extern "C" int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len) { + return MOCK_HOOK_P3(AulMock, aul_app_get_pkgid_bypid, pid, pkgid, len); +} diff --git a/test/unit_tests/mock/aul_mock.h b/test/unit_tests/mock/aul_mock.h new file mode 100644 index 0000000..359db71 --- /dev/null +++ b/test/unit_tests/mock/aul_mock.h @@ -0,0 +1,33 @@ +/* + * 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_AUL_MOCK_H_ +#define UNIT_TESTS_MOCK_AUL_MOCK_H_ + +#include +#include + +#include "mock/module_mock.h" + +class AulMock : public virtual ModuleMock { + public: + virtual ~AulMock() {} + + MOCK_METHOD3(aul_app_get_pkgid_bypid, int (int , char *, int)); +}; + +#endif // UNIT_TESTS_MOCK_AUL_MOCK_H_ + diff --git a/test/unit_tests/mock/ecore_wl2_mock.cc b/test/unit_tests/mock/ecore_wl2_mock.cc index 11df066..1cf68e6 100644 --- a/test/unit_tests/mock/ecore_wl2_mock.cc +++ b/test/unit_tests/mock/ecore_wl2_mock.cc @@ -57,3 +57,34 @@ extern "C" int 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); +} + +extern "C" Ecore_Evas *ecore_evas_ecore_evas_get(const Evas *e) { + return MOCK_HOOK_P1(EcoreWl2Mock, ecore_evas_ecore_evas_get, e); +} + +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); +} + +extern "C" void evas_object_data_set(Evas_Object *eo_obj, const char *key, + const void *data) { + return MOCK_HOOK_P3(EcoreWl2Mock, evas_object_data_set, eo_obj, key, data); +} + +extern "C" void evas_object_event_callback_add(Evas_Object *eo_obj, + Evas_Callback_Type type, Evas_Object_Event_Cb func, const void *data) { + return MOCK_HOOK_P4(EcoreWl2Mock, evas_object_event_callback_add, + eo_obj, type, func, data); +} diff --git a/test/unit_tests/mock/ecore_wl2_mock.h b/test/unit_tests/mock/ecore_wl2_mock.h index 78e7704..bf7f84f 100644 --- a/test/unit_tests/mock/ecore_wl2_mock.h +++ b/test/unit_tests/mock/ecore_wl2_mock.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "mock/module_mock.h" @@ -42,8 +43,21 @@ class EcoreWl2Mock : public virtual ModuleMock { MOCK_METHOD0(ecore_wl2_shutdown, int()); MOCK_METHOD1(ecore_wl2_display_connect, - Ecore_Wl2_Display *(const char *conn)); - + 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, + void (Evas_Object *, const char *, const void *)); + MOCK_METHOD4(evas_object_event_callback_add, void (Evas_Object *, + Evas_Callback_Type, Evas_Object_Event_Cb, const void *)); }; #endif // UNIT_TESTS_MOCK_ECORE_WL2_MOCK_H_ diff --git a/test/unit_tests/mock/elm_mock.cc b/test/unit_tests/mock/elm_mock.cc new file mode 100644 index 0000000..05bf369 --- /dev/null +++ b/test/unit_tests/mock/elm_mock.cc @@ -0,0 +1,46 @@ +/* + * 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/elm_mock.h" + +#include + +#include "unit_tests/mock/mock_hook.h" +#include "unit_tests/mock/test_fixture.h" + + +extern "C" Evas_Object * elm_win_add(Evas_Object *parent, + const char *name, Elm_Win_Type type) { + return MOCK_HOOK_P3(ElmMock, elm_win_add, parent, name, type); +} + +extern "C" void elm_win_wm_rotation_preferred_rotation_set( + Evas_Object *obj, int rotation) { + return MOCK_HOOK_P2( + ElmMock, elm_win_wm_rotation_preferred_rotation_set, obj, rotation); +} + +extern "C" void elm_win_wm_rotation_available_rotations_set(Elm_Win *obj, + const int *rotations, unsigned int count) { + return MOCK_HOOK_P3( + ElmMock, elm_win_wm_rotation_available_rotations_set, + obj, rotations, count); +} + +extern "C" int elm_win_aux_hint_add(Evas_Object *obj, + const char *hint, const char *val) { + return MOCK_HOOK_P3(ElmMock, elm_win_aux_hint_add, obj, hint, val); +} diff --git a/test/unit_tests/mock/elm_mock.h b/test/unit_tests/mock/elm_mock.h new file mode 100644 index 0000000..efd2ef7 --- /dev/null +++ b/test/unit_tests/mock/elm_mock.h @@ -0,0 +1,38 @@ +/* + * 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_ELM_MOCK_H_ +#define UNIT_TESTS_MOCK_ELM_MOCK_H_ + +#include +#include + +#include "mock/module_mock.h" + +class ElmMock : public virtual ModuleMock { + public: + virtual ~ElmMock() {} + MOCK_METHOD3(elm_win_add, + Evas_Object *(Evas_Object *, const char *, Elm_Win_Type)); + MOCK_METHOD2(elm_win_wm_rotation_preferred_rotation_set, + void (Evas_Object *, int)); + MOCK_METHOD3(elm_win_wm_rotation_available_rotations_set, + void (Elm_Win *, const int *, unsigned int)); + MOCK_METHOD3(elm_win_aux_hint_add, + int (Evas_Object *, const char *, const char *)); +}; + +#endif // UNIT_TESTS_MOCK_ELM_MOCK_H_ diff --git a/test/unit_tests/test_widget_app.cc b/test/unit_tests/test_widget_app.cc index 0460d13..f6c73f5 100644 --- a/test/unit_tests/test_widget_app.cc +++ b/test/unit_tests/test_widget_app.cc @@ -24,20 +24,39 @@ #include #include "widget_app.h" +#include "widget_app_efl.h" #include "unit_tests/mock/gio_mock.h" #include "unit_tests/mock/ecore_wl2_mock.h" #include "unit_tests/mock/system_info_mock.h" #include "unit_tests/mock/appcore_multiwindow_base_mock.h" +#include "unit_tests/mock/app_common_mock.h" +#include "unit_tests/mock/elm_mock.h" +#include "unit_tests/mock/aul_mock.h" #include "unit_tests/mock/test_fixture.h" using ::testing::_; using ::testing::DoAll; using ::testing::Return; using ::testing::SetArgPointee; -using ::testing::StrEq; +using ::testing::Invoke; + +typedef struct _widget_base_instance_data { + bundle* args; + char* id; + char* content; + void* tag; + double period; + guint periodic_timer; + bool pending_update; + char* pending_content; + void* user_data; +} widget_base_instance_data; class Mocks : public ::testing::NiceMock, public ::testing::NiceMock, + public ::testing::NiceMock, + public ::testing::NiceMock, + public ::testing::NiceMock, public ::testing::NiceMock, public ::testing::NiceMock {}; @@ -53,11 +72,139 @@ class WidgetAppTest : public TestFixture { } }; -widget_class_h __app_create_cb(void *user_data) { +int __instance_create_cb(widget_context_h context, bundle* content, + int w, int h, void* user_data) { + return 0; +} + +int __instance_destroy_cb(widget_context_h context, + widget_app_destroy_type_e reason, bundle* content, void* user_data) { + return 0; +} + +int __instance_pause_cb(widget_context_h context, void* user_data) { + return 0; +} + +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) { + return 0; +} + +int __instance_update_cb(widget_context_h context, + bundle* content, int force, void* user_data) { + return 0; +} + +widget_class_h __app_create_cb(void* user_data) { return nullptr; } -void __app_terminate_cb(void *user_data) { +void __app_terminate_cb(void* user_data) { +} + +int __app_get_id_fake(char** id) { + *id = strdup("test"); + return 0; +} + +int __aul_app_get_pkgid_bypid_fake(int pid, char* pkgid, int len) { + snprintf(pkgid, 10, "%s", "test"); + return 0; +} + +struct instance_data { + Evas_Object* win; + guint iconify_timer; + bool is_iconified; +}; + +void* __appcore_multiwindow_base_instance_get_extra_fake( + appcore_multiwindow_base_instance_h handle) { + widget_base_instance_data* data = (widget_base_instance_data*) + calloc(1, sizeof(widget_base_instance_data)); + data->args = bundle_create(); + bundle_add_str(data->args, "__AUL_WIDGET_ID__", "test"); + bundle_add_str(data->args, "__WIDGET_OP__", "optest"); + bundle_add_str(data->args, "__WIDGET_WIDTH__", "320"); + bundle_add_str(data->args, "__WIDGET_HEIGHT__", "320"); + data->pending_content = strdup("test"); + data->content = strdup("test"); + data->id = strdup("id"); + data->user_data = calloc(1, sizeof (struct instance_data)); + + return data; +} + +const char* __appcore_multiwindow_base_instance_get_id_fake( + appcore_multiwindow_base_instance_h handle) { + return strdup("test"); +} + +const char* __appcore_multiwindow_base_instance_get_class_id_fake( + appcore_multiwindow_base_instance_h context) { + return strdup("test"); +} + +appcore_multiwindow_base_class __cls; +void __appcore_multiwindow_base_class_add_fake( + appcore_multiwindow_base_class cls) { + __cls = cls; + cls.create(nullptr, nullptr); + cls.terminate(nullptr, nullptr); + cls.pause((appcore_multiwindow_base_instance_h) + calloc(1, sizeof(char)), nullptr); + cls.resume((appcore_multiwindow_base_instance_h) + calloc(1, sizeof(char)), nullptr); +} + +int __appcore_multiwindow_base_init_fake(appcore_multiwindow_base_ops ops, + int argc, char** argv, void* data) { + tizen_base::Bundle b; + + b.Add("__WIDGET_WIDTH__", "320"); + b.Add("__WIDGET_HEIGHT__", "320"); + b.Add("__AUL_WIDGET_INSTANCE_ID__", "instance_id"); + b.Add("__AUL_WIDGET_ID__", "test"); + b.Add("__WIDGET_OP__", "create"); + ops.base.control(b.GetHandle(), nullptr); + + b.Delete("__WIDGET_OP__"); + b.Add("__WIDGET_OP__", "resize"); + ops.base.control(b.GetHandle(), nullptr); + + b.Delete("__WIDGET_OP__"); + b.Add("__WIDGET_OP__", "update"); + ops.base.control(b.GetHandle(), nullptr); + + b.Delete("__WIDGET_OP__"); + b.Add("__WIDGET_OP__", "destroy"); + ops.base.control(b.GetHandle(), nullptr); + + b.Delete("__WIDGET_OP__"); + b.Add("__WIDGET_OP__", "resume"); + ops.base.control(b.GetHandle(), nullptr); + + b.Delete("__WIDGET_OP__"); + b.Add("__WIDGET_OP__", "pause"); + ops.base.control(b.GetHandle(), nullptr); + + b.Delete("__WIDGET_OP__"); + b.Add("__WIDGET_OP__", "terminate"); + ops.base.control(b.GetHandle(), nullptr); + + b.Delete("__WIDGET_OP__"); + b.Add("__WIDGET_OP__", "period"); + ops.base.control(b.GetHandle(), nullptr); + + ops.base.create(nullptr); + ops.base.terminate(nullptr); + + return 0; } TEST_F(WidgetAppTest, widget_app_main) { @@ -90,8 +237,255 @@ TEST_F(WidgetAppTest, widget_app_main) { EXPECT_CALL(GetMock(), appcore_multiwindow_base_init(_, _, _, _)). - WillOnce(Return(0)); + WillOnce(Invoke(__appcore_multiwindow_base_init_fake)); + + EXPECT_CALL(GetMock(), + aul_app_get_pkgid_bypid(_, _, _)). + WillOnce(Invoke(__aul_app_get_pkgid_bypid_fake)); + + EXPECT_CALL(GetMock(), app_get_id(_)). + WillOnce(Invoke(__app_get_id_fake)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_find(_)). + WillRepeatedly( + Return( + (appcore_multiwindow_base_instance_h)calloc(1, sizeof(char)))); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_class(_)). + WillRepeatedly( + Return(&__cls)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_extra(_)). + WillRepeatedly( + Invoke(__appcore_multiwindow_base_instance_get_extra_fake)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_exit(_)).Times(2); ret = widget_app_main(argc, argv, &callback, nullptr); EXPECT_EQ(WIDGET_ERROR_NONE, ret); } + +TEST_F(WidgetAppTest, widget_app_exit) { + int ret = widget_app_exit(); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +TEST_F(WidgetAppTest, widget_app_terminate_context) { + widget_context_h context = + (widget_context_h)calloc(1, sizeof(widget_context_h)); + int ret = widget_app_terminate_context(context); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +bool __widget_context_cb(widget_context_h context, void *user_data) { + return true; +} + +TEST_F(WidgetAppTest, widget_app_foreach_context) { + int ret = widget_app_foreach_context(__widget_context_cb, nullptr); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +void __app_event_cb(app_event_info_h event_info, void *user_data) { +} + +TEST_F(WidgetAppTest, widget_app_add_event_handler) { + app_event_handler_h handle; + int ret = widget_app_add_event_handler(&handle, APP_EVENT_LOW_MEMORY, + __app_event_cb, nullptr); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +TEST_F(WidgetAppTest, widget_app_remove_event_handler) { + app_event_handler_h handle; + int ret = widget_app_add_event_handler(&handle, APP_EVENT_LOW_MEMORY, + __app_event_cb, nullptr); + ret = widget_app_remove_event_handler(handle); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +TEST_F(WidgetAppTest, widget_app_get_id) { + widget_context_h context = + (widget_context_h)calloc(1, sizeof(widget_context_h)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_id(_)). + WillOnce(Return("test")); + + const char *id = widget_app_get_id(context); + EXPECT_STREQ(id, "test"); +} + +TEST_F(WidgetAppTest, widget_app_class_create) { + widget_instance_lifecycle_callback_s lifecycle; + + lifecycle.create = __instance_create_cb; + lifecycle.destroy = __instance_destroy_cb; + lifecycle.pause = __instance_pause_cb; + lifecycle.resume = __instance_resume_cb; + lifecycle.resize = __instance_resize_cb; + lifecycle.update = __instance_update_cb; + + EXPECT_CALL(GetMock(), app_get_id(_)). + WillOnce(Invoke(__app_get_id_fake)); + + widget_class_h cls = widget_app_class_create(lifecycle, nullptr); + EXPECT_NE(nullptr, cls); +} + +TEST_F(WidgetAppTest, widget_app_context_set_tag) { + widget_context_h context = + (widget_context_h)calloc(1, sizeof(widget_context_h)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_extra(_)). + WillOnce(Invoke(__appcore_multiwindow_base_instance_get_extra_fake)); + + int ret = widget_app_context_set_tag(context, (void*)"test"); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +TEST_F(WidgetAppTest, widget_app_context_get_tag) { + widget_context_h context = + (widget_context_h)calloc(1, sizeof(widget_context_h)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_extra(_)). + WillOnce(Invoke(__appcore_multiwindow_base_instance_get_extra_fake)); + + void* tag; + int ret = widget_app_context_get_tag(context, &tag); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +TEST_F(WidgetAppTest, widget_app_context_set_content_info) { + widget_context_h context = + (widget_context_h)calloc(1, sizeof(widget_context_h)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_extra(_)). + WillOnce(Invoke(__appcore_multiwindow_base_instance_get_extra_fake)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_id(_)). + WillOnce(Invoke(__appcore_multiwindow_base_instance_get_id_fake)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_class_id(_)). + WillOnce(Invoke(__appcore_multiwindow_base_instance_get_class_id_fake)); + + bundle* content_info = bundle_create(); + int ret = widget_app_context_set_content_info(context, content_info); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +TEST_F(WidgetAppTest, widget_app_context_set_title) { + widget_context_h context = + (widget_context_h)calloc(1, sizeof(widget_context_h)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_extra(_)). + WillRepeatedly(Invoke(__appcore_multiwindow_base_instance_get_extra_fake)); + + int ret = widget_app_context_set_title(context, "title"); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +TEST_F(WidgetAppTest, widget_app_class_add) { + widget_instance_lifecycle_callback_s lifecycle; + widget_class_h cls = widget_app_class_add( + nullptr, "test", lifecycle, nullptr); + + lifecycle.create = __instance_create_cb; + lifecycle.destroy = __instance_destroy_cb; + lifecycle.pause = __instance_pause_cb; + lifecycle.resume = __instance_resume_cb; + lifecycle.resize = __instance_resize_cb; + lifecycle.update = __instance_update_cb; + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_class_add(_)). + WillOnce(Invoke(__appcore_multiwindow_base_class_add_fake)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_extra(_)). + WillRepeatedly(Invoke(__appcore_multiwindow_base_instance_get_extra_fake)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_class_id(_)). + WillRepeatedly(Invoke(__appcore_multiwindow_base_instance_get_class_id_fake)); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_drop(_)). + Times(1); + + cls = widget_app_class_add( + nullptr, "test", lifecycle, nullptr); + EXPECT_NE(nullptr, cls); + + tizen_base::Bundle b; + b.Add("__AUL_WIDGET_VIEWER__", "test"); + int ret = bundle_add_str(b.GetHandle(), "KEY", "VALUE"); + ASSERT_EQ(ret, BUNDLE_ERROR_NONE); + + char** argv = nullptr; + int argc = bundle_export_to_argv(b.GetHandle(), &argv); + ASSERT_EQ(get_last_result(), BUNDLE_ERROR_NONE); + ASSERT_NE(argv, nullptr); + ASSERT_NE(argc, 0); + + widget_app_lifecycle_callback_s callback; + callback.create = __app_create_cb; + callback.terminate = __app_terminate_cb; + + ret = widget_app_main(argc, argv, &callback, nullptr); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} + +TEST_F(WidgetAppTest, widget_app_get_elm_win_negative) { + Evas_Object* win; + widget_context_h context = + (widget_context_h)calloc(1, sizeof(widget_context_h)); + int ret = widget_app_get_elm_win(context, &win); + EXPECT_EQ(WIDGET_ERROR_FAULT, ret); +} + +TEST_F(WidgetAppTest, widget_app_get_elm_win) { + EXPECT_CALL(GetMock(), + elm_win_add(_, _, _)). + WillOnce(Return((Evas_Object*)calloc(1, sizeof(char)))); + + EXPECT_CALL(GetMock(), + ecore_evas_wayland2_window_get(_)). + WillOnce(Return((Ecore_Wl2_Window*)calloc(1, sizeof(char)))); + + EXPECT_CALL(GetMock(), + elm_win_aux_hint_add(_, _, _)). + WillOnce(Return(0)); + + EXPECT_CALL(GetMock(), + ecore_wl2_window_surface_get(_)). + WillOnce(Return(nullptr)); + + EXPECT_CALL(GetMock(), + evas_object_event_callback_add(_, _, _, _)). + Times(1); + + EXPECT_CALL(GetMock(), + evas_object_data_set(_, _, _)). + Times(1); + + EXPECT_CALL(GetMock(), + appcore_multiwindow_base_instance_get_extra(_)). + WillRepeatedly(Invoke(__appcore_multiwindow_base_instance_get_extra_fake)); + + Evas_Object* win; + widget_context_h context = + (widget_context_h)calloc(1, sizeof(widget_context_h)); + int ret = widget_app_get_elm_win(context, &win); + EXPECT_EQ(WIDGET_ERROR_NONE, ret); +} -- 2.7.4