From: Hwankyu Jhun Date: Wed, 16 Oct 2019 11:53:41 +0000 (+0900) Subject: Add new testcases for coverage measurement X-Git-Tag: submit/tizen_5.5/20200131.035153~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83f6f29c554d747120b62c5c0b0ad5557c97fb1c;p=platform%2Fcore%2Fappfw%2Fcomponent-based-application.git Add new testcases for coverage measurement Change-Id: Ibedfdfbb9ebf8444e53b633280c7d33a81099cc8 Signed-off-by: Hwankyu Jhun --- diff --git a/component_based/base/application_base.cc b/component_based/base/application_base.cc index 877c389..5a4e2c6 100644 --- a/component_based/base/application_base.cc +++ b/component_based/base/application_base.cc @@ -254,25 +254,37 @@ void ApplicationBase::Exit() { impl_->Exit(); } +// LCOV_EXCL_START void ApplicationBase::OnInit(int argc, char** argv) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ApplicationBase::OnFini() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ApplicationBase::OnRun() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ApplicationBase::OnExit() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START std::map> ApplicationBase::OnCreate() { std::map> facs; return facs; } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ApplicationBase::OnTerminate() { } +// LCOV_EXCL_STOP } // namespace component_based diff --git a/component_based/base/component.cc b/component_based/base/component.cc index 29656fc..577f2f6 100644 --- a/component_based/base/component.cc +++ b/component_based/base/component.cc @@ -116,52 +116,82 @@ void Component::Impl::OnSuspendedStateChanged(SuspendedState::State state) { parent_->OnBaseSuspendedStateChanged(state); } +// LCOV_EXCL_START bool Component::OnBaseCreate() { return true; } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseDestroy() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseStart(AppControl control, bool restarted) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseResume() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBasePause() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseStop() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseRestoreContent(tizen_base::Bundle content) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseSaveContent(tizen_base::Bundle& content) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseAction(std::string action, AppControl app_control) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseDeviceOrientationChanged( DeviceOrientation::Orientation orientation) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseLanguageChanged(std::string language) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseRegionFormatChanged(std::string region) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseLowBattery(LowBattery::Status status) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseLowMemory(LowMemory::Status status) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::OnBaseSuspendedStateChanged(SuspendedState::State state) { } +// LCOV_EXCL_STOP void Component::Impl::RegisterAction(std::string app_control_name) { auto act_iter = act_map_.find(app_control_name); @@ -193,6 +223,7 @@ bool Component::Impl::DeregisterAction(std::string app_control_name) { return true; } +// LCOV_EXCL_START void Component::Impl::OnAppControlReply(app_control_h request, app_control_h reply, app_control_result_e result, @@ -210,7 +241,9 @@ void Component::Impl::OnAppControlReply(app_control_h request, LOGE("Exception occurred (%s)", ex.what()); } } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void Component::Impl::OnAppControlResult(app_control_h request, app_control_error_e result, void* user_data) { @@ -225,6 +258,7 @@ void Component::Impl::OnAppControlResult(app_control_h request, LOGE("Exception occurred (%s)", ex.what()); } } +// LCOV_EXCL_STOP Component::State Component::GetState() { return impl_->state_; diff --git a/component_based/base/content_manager_internal.cc b/component_based/base/content_manager_internal.cc index 66c6618..8e966f3 100644 --- a/component_based/base/content_manager_internal.cc +++ b/component_based/base/content_manager_internal.cc @@ -108,6 +108,7 @@ int ContentManager::File::Read() { return r; } +// LCOV_EXCL_START int ContentManager::File::Delete() { int retry_count = 0; int r = TryDelete(); @@ -119,6 +120,7 @@ int ContentManager::File::Delete() { return r; } +// LCOV_EXCL_STOP bool ContentManager::File::IsExisting() { if (access(path_.c_str(), F_OK) == 0) @@ -238,6 +240,7 @@ int ContentManager::File::TryRead() { return static_cast(total_size); } +// LCOV_EXCL_START int ContentManager::File::TryDelete() { int r = unlink(path_.c_str()); if (r != 0) { @@ -246,6 +249,7 @@ int ContentManager::File::TryDelete() { } return 0; } +// LCOV_EXCL_STOP } // namespace internal } // namespace component_based diff --git a/component_based/base/content_manager_internal.h b/component_based/base/content_manager_internal.h index 9eabb24..2b4722a 100644 --- a/component_based/base/content_manager_internal.h +++ b/component_based/base/content_manager_internal.h @@ -67,7 +67,7 @@ class ContentManager { path_ = std::string(data_path) + ".content/"; free(data_path); } else { - path_ = std::string("/run/aul/dbspace/.content/"); + path_ = std::string("/run/.content/"); } if (access(path_.c_str(), F_OK) != 0) { diff --git a/component_based/base/frame_component.cc b/component_based/base/frame_component.cc index 4101f00..1c3ef52 100644 --- a/component_based/base/frame_component.cc +++ b/component_based/base/frame_component.cc @@ -109,27 +109,41 @@ void FrameComponent::OnBaseRestoreContent(tizen_base::Bundle content) { void FrameComponent::OnBaseSaveContent(tizen_base::Bundle& content) { } +// LCOV_EXCL_START void FrameComponent::OnBaseAction(std::string action, AppControl app_control) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void FrameComponent::OnBaseDeviceOrientationChanged( DeviceOrientation::Orientation orientation) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void FrameComponent::OnBaseLanguageChanged(std::string language) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void FrameComponent::OnBaseRegionFormatChanged(std::string region) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void FrameComponent::OnBaseLowBattery(LowBattery::Status status) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void FrameComponent::OnBaseLowMemory(LowMemory::Status status) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void FrameComponent::OnBaseSuspendedStateChanged(SuspendedState::State state) { } +// LCOV_EXCL_STOP std::unique_ptr FrameComponent::OnCreate() { return nullptr; diff --git a/component_based/base/frame_window.cc b/component_based/base/frame_window.cc index 79fec95..156a332 100644 --- a/component_based/base/frame_window.cc +++ b/component_based/base/frame_window.cc @@ -17,19 +17,26 @@ namespace component_based { +// LCOV_EXCL_START FrameWindow::FrameWindow(int id, void* raw) : id_(id), raw_(raw) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START FrameWindow::~FrameWindow() { - } +// LCOV_EXCL_STOP +// LCOV_EXCL_START int FrameWindow::GetResID() const { return id_; } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void* FrameWindow::GetRaw() { return raw_; } +// LCOV_EXCL_STOP } // namespace component_based diff --git a/component_based/base/service_component.cc b/component_based/base/service_component.cc index b57e7b5..0e19641 100644 --- a/component_based/base/service_component.cc +++ b/component_based/base/service_component.cc @@ -48,42 +48,66 @@ void ServiceComponent::OnBaseStart(AppControl control, bool restarted) { SetContent(std::move(content)); } +// LCOV_EXCL_START void ServiceComponent::OnBaseResume() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBasePause() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseStop() { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseRestoreContent(tizen_base::Bundle content) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseSaveContent(tizen_base::Bundle& content) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseAction(std::string action, AppControl app_control) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseDeviceOrientationChanged( DeviceOrientation::Orientation orientation) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseLanguageChanged(std::string language) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseRegionFormatChanged(std::string region) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseLowBattery(LowBattery::Status status) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseLowMemory(LowMemory::Status status) { } +// LCOV_EXCL_STOP +// LCOV_EXCL_START void ServiceComponent::OnBaseSuspendedStateChanged(SuspendedState::State state) { } +// LCOV_EXCL_STOP bool ServiceComponent::OnCreate() { return false; diff --git a/component_based/efl_base/stub.cc b/component_based/efl_base/stub.cc index 830e5aa..6f731a2 100755 --- a/component_based/efl_base/stub.cc +++ b/component_based/efl_base/stub.cc @@ -340,7 +340,7 @@ class StubServiceComponent : public component_based::ServiceComponent { } void OnBaseAction(std::string action, - component_based::AppControl app_control) override { + component_based::AppControl app_control) override { if (cb_.action) cb_.action(this, action.c_str(), app_control.GetHandle(), user_data_); } @@ -606,4 +606,4 @@ extern "C" EXPORT_API int frame_component_get_resource_id(Evas_Object* win, *res_id = ecore_wl2_window_id_get(wl_win); return COMPONENT_ERROR_NONE; -} \ No newline at end of file +} diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 81ab75a..10e21b2 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -35,7 +35,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock UNIT_TEST_SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/base SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/base BASE_SOURCES) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/efl_base EFL_BASE_SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../component_based/efl_base APPLICATION_SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../component_based/base CORE_BASE_SOURCES) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../component_based/uri URI_SOURCES) @@ -48,6 +49,8 @@ ADD_EXECUTABLE(${PROJECT_NAME} ${CORE_BASE_SOURCES} ${UNIT_TEST_SOURCES} ${SOURCES} + ${BASE_SOURCES} + ${EFL_BASE_SOURCES} ) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${component-based_unittests_LDFLAGS}) diff --git a/unit_tests/mock/mock.cc b/unit_tests/mock/mock.cc index 0a9c423..96f21bc 100644 --- a/unit_tests/mock/mock.cc +++ b/unit_tests/mock/mock.cc @@ -4,10 +4,11 @@ #include "mock.h" -#include "mock_app_control.h" #include "mock_app_common.h" -#include "mock_elementary.h" +#include "mock_app_control.h" #include "mock_appcore_multiwindow_base.h" +#include "mock_aul.h" +#include "mock_elementary.h" DEFINE_FFF_GLOBALS; @@ -24,39 +25,97 @@ DEFINE_FAKE_VALUE_FUNC(int, app_control_add_action_handler, const char*, /* app_common.h */ DEFINE_FAKE_VALUE_FUNC(int, app_get_id, char**); + DEFINE_FAKE_VALUE_FUNC(char*, app_get_data_path); + DEFINE_FAKE_VALUE_FUNC(int, app_get_display_state, app_display_state_e*); + DEFINE_FAKE_VALUE_FUNC(int, app_resource_manager_get, app_resource_e, const char*, char**); /* Elementary.h */ DEFINE_FAKE_VALUE_FUNC(int, elm_init, int, char**); + DEFINE_FAKE_VALUE_FUNC(int, elm_shutdown); + DEFINE_FAKE_VOID_FUNC(elm_run); + DEFINE_FAKE_VOID_FUNC(elm_exit); + DEFINE_FAKE_VALUE_FUNC(Evas_Object*, elm_win_util_standard_add, const char*, const char*); + DEFINE_FAKE_VALUE_FUNC(Evas*, evas_object_evas_get, const Eo*); + DEFINE_FAKE_VALUE_FUNC(Ecore_Evas*, ecore_evas_ecore_evas_get, const Evas*); + DEFINE_FAKE_VALUE_FUNC(Ecore_Wl2_Window*, ecore_evas_wayland2_window_get, - const Ecore_Evas*); + const Ecore_Evas*); + DEFINE_FAKE_VALUE_FUNC(int, ecore_wl2_window_id_get, Ecore_Wl2_Window*); +DEFINE_FAKE_VOID_FUNC(evas_object_del, Evas_Object*); + +DEFINE_FAKE_VOID_FUNC(elm_config_accel_preference_set, const char*); + +DEFINE_FAKE_VOID_FUNC(ecore_wl2_window_activate, Ecore_Wl2_Window*); + +DEFINE_FAKE_VOID_FUNC(ecore_wl2_window_iconified_set, Ecore_Wl2_Window*, + Eina_Bool); + +DEFINE_FAKE_VALUE_FUNC(Ecore_Wl2_Window*, ecore_wl2_display_window_find, + Ecore_Wl2_Display*, unsigned int); /* appcore_multiwindow_base.h */ DEFINE_FAKE_VALUE_FUNC(int, appcore_multiwindow_base_init, appcore_multiwindow_base_ops, int, char**, void*); + DEFINE_FAKE_VALUE_FUNC(appcore_multiwindow_base_instance_h, appcore_multiwindow_base_instance_run, const char*, const char*, void*); + DEFINE_FAKE_VALUE_FUNC(appcore_multiwindow_base_instance_h, appcore_multiwindow_base_instance_find, const char*); + DEFINE_FAKE_VALUE_FUNC(bool, appcore_multiwindow_base_instance_is_resumed, - appcore_multiwindow_base_instance_h); + appcore_multiwindow_base_instance_h); + DEFINE_FAKE_VOID_FUNC(appcore_multiwindow_base_instance_exit, - appcore_multiwindow_base_instance_h); + appcore_multiwindow_base_instance_h); + DEFINE_FAKE_VOID_FUNC(appcore_multiwindow_base_window_unbind, - appcore_multiwindow_base_instance_h); + appcore_multiwindow_base_instance_h); + DEFINE_FAKE_VALUE_FUNC(appcore_multiwindow_base_ops, - appcore_multiwindow_base_get_default_ops); + appcore_multiwindow_base_get_default_ops); + +DEFINE_FAKE_VOID_FUNC(appcore_multiwindow_base_fini); + +DEFINE_FAKE_VOID_FUNC(appcore_multiwindow_base_exit); + +DEFINE_FAKE_VOID_FUNC(appcore_multiwindow_base_class_add, + appcore_multiwindow_base_class); + +DEFINE_FAKE_VALUE_FUNC(const char*, appcore_multiwindow_base_instance_get_id, + appcore_multiwindow_base_instance_h); + +DEFINE_FAKE_VOID_FUNC(appcore_multiwindow_base_instance_resume, + appcore_multiwindow_base_instance_h); + +DEFINE_FAKE_VOID_FUNC(appcore_multiwindow_base_instance_pause, + appcore_multiwindow_base_instance_h); + +DEFINE_FAKE_VOID_FUNC(appcore_multiwindow_base_window_on_visibility, + int, void*); + +DEFINE_FAKE_VALUE_FUNC(appcore_base_event_h, appcore_base_add_event, + enum appcore_base_event, appcore_base_event_cb, void *); + +/* aul.h */ +DEFINE_FAKE_VALUE_FUNC(int, aul_app_group_set_window_v2, const char*, int); + +DEFINE_FAKE_VALUE_FUNC(int, aul_app_group_lower_v2, const char*, bool*); + +DEFINE_FAKE_VALUE_FUNC(int, aul_comp_notify_start, const char*); +DEFINE_FAKE_VALUE_FUNC(int, aul_comp_status_update, const char*, int); diff --git a/unit_tests/mock/mock_app_common.h b/unit_tests/mock/mock_app_common.h index e5b2ac7..ccf80ef 100644 --- a/unit_tests/mock/mock_app_common.h +++ b/unit_tests/mock/mock_app_common.h @@ -27,8 +27,11 @@ extern "C" { #endif DECLARE_FAKE_VALUE_FUNC(int, app_get_id, char**); + DECLARE_FAKE_VALUE_FUNC(char*, app_get_data_path); + DECLARE_FAKE_VALUE_FUNC(int, app_get_display_state, app_display_state_e*); + DECLARE_FAKE_VALUE_FUNC(int, app_resource_manager_get, app_resource_e, const char*, char**); diff --git a/unit_tests/mock/mock_appcore_multiwindow_base.h b/unit_tests/mock/mock_appcore_multiwindow_base.h index d2b00a0..a226df5 100644 --- a/unit_tests/mock/mock_appcore_multiwindow_base.h +++ b/unit_tests/mock/mock_appcore_multiwindow_base.h @@ -27,19 +27,47 @@ extern "C" { DECLARE_FAKE_VALUE_FUNC(int, appcore_multiwindow_base_init, appcore_multiwindow_base_ops, int, char**, void*); + DECLARE_FAKE_VALUE_FUNC(appcore_multiwindow_base_instance_h, - appcore_multiwindow_base_instance_run, - const char*, const char*, void*); + appcore_multiwindow_base_instance_run, const char*, + const char*, void*); + DECLARE_FAKE_VALUE_FUNC(appcore_multiwindow_base_instance_h, appcore_multiwindow_base_instance_find, const char*); + DECLARE_FAKE_VALUE_FUNC(bool, appcore_multiwindow_base_instance_is_resumed, - appcore_multiwindow_base_instance_h); + appcore_multiwindow_base_instance_h); + DECLARE_FAKE_VOID_FUNC(appcore_multiwindow_base_instance_exit, - appcore_multiwindow_base_instance_h); + appcore_multiwindow_base_instance_h); + DECLARE_FAKE_VOID_FUNC(appcore_multiwindow_base_window_unbind, - appcore_multiwindow_base_instance_h); + appcore_multiwindow_base_instance_h); + DECLARE_FAKE_VALUE_FUNC(appcore_multiwindow_base_ops, - appcore_multiwindow_base_get_default_ops); + appcore_multiwindow_base_get_default_ops); + +DECLARE_FAKE_VOID_FUNC(appcore_multiwindow_base_fini); + +DECLARE_FAKE_VOID_FUNC(appcore_multiwindow_base_exit); + +DECLARE_FAKE_VOID_FUNC(appcore_multiwindow_base_class_add, + appcore_multiwindow_base_class); + +DECLARE_FAKE_VALUE_FUNC(const char*, appcore_multiwindow_base_instance_get_id, + appcore_multiwindow_base_instance_h); + +DECLARE_FAKE_VOID_FUNC(appcore_multiwindow_base_instance_resume, + appcore_multiwindow_base_instance_h); + +DECLARE_FAKE_VOID_FUNC(appcore_multiwindow_base_instance_pause, + appcore_multiwindow_base_instance_h); + +DECLARE_FAKE_VOID_FUNC(appcore_multiwindow_base_window_on_visibility, + int, void *) + +DECLARE_FAKE_VALUE_FUNC(appcore_base_event_h, appcore_base_add_event, + enum appcore_base_event, appcore_base_event_cb, void *); #ifdef __cplusplus } diff --git a/unit_tests/mock/mock_aul.h b/unit_tests/mock/mock_aul.h new file mode 100644 index 0000000..099c090 --- /dev/null +++ b/unit_tests/mock/mock_aul.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 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_MOCK_AUL_H_ +#define UNIT_TESTS_MOCK_MOCK_AUL_H_ + +#include + +#include "mock.h" + +#ifdef __cplusplus +extern "C" { +#endif + +DECLARE_FAKE_VALUE_FUNC(int, aul_app_group_set_window_v2, const char*, int); + +DECLARE_FAKE_VALUE_FUNC(int, aul_app_group_lower_v2, const char*, bool*); + +DECLARE_FAKE_VALUE_FUNC(int, aul_comp_notify_start, const char*); + +DECLARE_FAKE_VALUE_FUNC(int, aul_comp_status_update, const char*, int); + +#ifdef __cplusplus +} +#endif + +#endif /* UNIT_TESTS_MOCK_MOCK_AUL_H_ */ diff --git a/unit_tests/mock/mock_elementary.h b/unit_tests/mock/mock_elementary.h index a34fb28..67a6714 100644 --- a/unit_tests/mock/mock_elementary.h +++ b/unit_tests/mock/mock_elementary.h @@ -27,17 +27,36 @@ extern "C" { #endif DECLARE_FAKE_VALUE_FUNC(int, elm_init, int, char**); + DECLARE_FAKE_VALUE_FUNC(int, elm_shutdown); + DECLARE_FAKE_VOID_FUNC(elm_run); + DECLARE_FAKE_VOID_FUNC(elm_exit); -DECLARE_FAKE_VALUE_FUNC(Evas_Object*, elm_win_util_standard_add, - const char*, const char*); + +DECLARE_FAKE_VALUE_FUNC(Evas_Object*, elm_win_util_standard_add, const char*, + const char*); + DECLARE_FAKE_VALUE_FUNC(Evas*, evas_object_evas_get, const Eo*); + DECLARE_FAKE_VALUE_FUNC(Ecore_Evas*, ecore_evas_ecore_evas_get, const Evas*); + DECLARE_FAKE_VALUE_FUNC(Ecore_Wl2_Window*, ecore_evas_wayland2_window_get, - const Ecore_Evas*); + const Ecore_Evas*); + DECLARE_FAKE_VALUE_FUNC(int, ecore_wl2_window_id_get, Ecore_Wl2_Window*); +DECLARE_FAKE_VOID_FUNC(evas_object_del, Evas_Object*); + +DECLARE_FAKE_VOID_FUNC(elm_config_accel_preference_set, const char*); + +DECLARE_FAKE_VOID_FUNC(ecore_wl2_window_activate, Ecore_Wl2_Window*); + +DECLARE_FAKE_VOID_FUNC(ecore_wl2_window_iconified_set, Ecore_Wl2_Window*, + Eina_Bool); + +DECLARE_FAKE_VALUE_FUNC(Ecore_Wl2_Window*, ecore_wl2_display_window_find, + Ecore_Wl2_Display*, unsigned int); #ifdef __cplusplus } diff --git a/unit_tests/src/base/test_component_based_component_mananger.cc b/unit_tests/src/base/test_component_based_component_mananger.cc index 457533a..7c0757b 100644 --- a/unit_tests/src/base/test_component_based_component_mananger.cc +++ b/unit_tests/src/base/test_component_based_component_mananger.cc @@ -78,7 +78,7 @@ class SimpleWindow : public component_based::IWindow { }; }; -appcore_multiwindow_base_instance_h __fake_appcore_multiwindow_base_instance_run( +static appcore_multiwindow_base_instance_h __fake_appcore_multiwindow_base_instance_run( const char* class_id, const char* id, void* extra) { return nullptr; diff --git a/unit_tests/src/efl_base/test_component_based_app.cc b/unit_tests/src/efl_base/test_component_based_app.cc new file mode 100644 index 0000000..d56880a --- /dev/null +++ b/unit_tests/src/efl_base/test_component_based_app.cc @@ -0,0 +1,377 @@ +// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include +#include +#include +#include + +#include "component_based/efl_base/api/frame_component.h" +#include "component_based/efl_base/api/service_component.h" +#include "component_based/efl_base/api/component_based_app.h" + +#include "unit_tests/mock/mock_appcore_multiwindow_base.h" +#include "unit_tests/mock/mock_elementary.h" + +namespace { + +static appcore_multiwindow_base_ops __ops; +static int __argc; +static char** __argv; +static void* __user_data; + +static int __fake_appcore_multiwindow_base_init( + appcore_multiwindow_base_ops ops, + int argc, + char** argv, + void* user_data) { + __ops = ops; + __argc = argc; + __argv = argv; + __user_data = user_data; + + __ops.base.init(__argc, __argv, __user_data); + __ops.base.create(__user_data); + __ops.base.run(__user_data); + + return 0; +} + +static void __fake_appcore_multiwindow_base_fini(void) { + __ops.base.terminate(__user_data); + __ops.base.finish(); +} + +static void __fake_appcore_multiwindow_base_exit(void) { + __ops.base.exit(__user_data); +} + +static int __fake_elm_init(int argc, char** argv) { + return 0; +} + +static int __fake_elm_shutdown(void) { + return 0; +} + +static Evas_Object* __fake_elm_win_util_standard_add(const char* name, + const char* title) { + Evas_Object* win = reinterpret_cast(malloc(sizeof(void*))); + return win; +} + +static void __fake_evas_object_del(Evas_Object* object) { + free(object); +} + +static void __fake_elm_config_accel_preference_set(const char* pref) { +} + +class ComponentBasedAppTest : public ::testing::Test { + protected: + void SetUp() override { + appcore_multiwindow_base_init_fake.custom_fake = + __fake_appcore_multiwindow_base_init; + appcore_multiwindow_base_fini_fake.custom_fake = + __fake_appcore_multiwindow_base_fini; + appcore_multiwindow_base_exit_fake.custom_fake = + __fake_appcore_multiwindow_base_exit; + + elm_init_fake.custom_fake = + __fake_elm_init; + elm_shutdown_fake.custom_fake = + __fake_elm_shutdown; + elm_win_util_standard_add_fake.custom_fake = + __fake_elm_win_util_standard_add; + + evas_object_del_fake.custom_fake = + __fake_evas_object_del; + + elm_config_accel_preference_set_fake.custom_fake = + __fake_elm_config_accel_preference_set; + } + void TearDown() override {} + + bool created_ = false; + bool terminated_ = false; +}; + +static bool __service_component_create_cb(component_h context, + void* user_data) { + return true; +} + +static void __service_component_start_command_cb(component_h context, + app_control_h app_control, bool restarted, void* user_data) { +} + +static void __service_component_destroy_cb(component_h context, + void *user_data) { +} + +static void __service_component_restore_content_cb(component_h context, + bundle* content, void* user_data) { +} + +static void __service_component_save_content_cb(component_h context, + bundle* content, void* user_data) { +} + +static void __service_component_action_cb(component_h context, + const char* action, app_control_h app_control, void* user_data) { +} + +static void __service_component_device_orientation_changed_cb( + component_h context, component_device_orientation_e orientation, + void* user_data) { +} + +static void __service_component_language_changed_cb(component_h context, + const char* language, void* user_data) { +} + +static void __service_component_region_format_changed_cb(component_h context, + const char* region, void* user_data) { +} + +static void __service_component_low_battery_cb(component_h context, + component_low_battery_status_e status, void* user_data) { +} + +static void __service_component_low_memory_cb(component_h context, + component_low_memory_status_e status, void* user_data) { +} + +static void __service_component_suspended_state_changed_cb(component_h context, + component_suspended_state_e state, void* user_data) { +} + +static component_class_h __service_component_add( + component_class_h component_class, const char* component_id, + void* user_data) { + service_component_lifecycle_callback_s callback; + callback.create = + __service_component_create_cb; + callback.start_command = + __service_component_start_command_cb; + callback.destroy = + __service_component_destroy_cb; + callback.restore_content = + __service_component_restore_content_cb; + callback.save_content = + __service_component_save_content_cb; + callback.action = + __service_component_action_cb; + callback.device_orientation_changed = + __service_component_device_orientation_changed_cb; + callback.language_changed = + __service_component_language_changed_cb; + callback.region_format_changed = + __service_component_region_format_changed_cb; + callback.low_battery = + __service_component_low_battery_cb; + callback.low_memory = + __service_component_low_memory_cb; + callback.suspended_state_changed = + __service_component_suspended_state_changed_cb; + + return component_based_app_add_service_component(component_class, + component_id, &callback, user_data); +} + +static Evas_Object* __frame_component_create_cb(component_h context, + void* user_data) { + return elm_win_util_standard_add("frame", "frame"); +} + +static void __frame_component_start_cb(component_h context, + app_control_h app_control, bool restarted, void* user_data) { +} + +static void __frame_component_resume_cb(component_h context, + void* user_data) { +} + +static void __frame_component_pause_cb(component_h context, + void* user_data) { +} + +static void __frame_component_stop_cb(component_h context, + void* user_data) { +} + +static void __frame_component_destroy_cb(component_h context, + void *user_data) { +} + +static void __frame_component_restore_content_cb(component_h context, + bundle* content, void* user_data) { +} + +static void __frame_component_save_content_cb(component_h context, + bundle* content, void* user_data) { +} + +static void __frame_component_action_cb(component_h context, + const char* action, app_control_h app_control, void* user_data) { +} + +static void __frame_component_device_orientation_changed_cb( + component_h context, component_device_orientation_e orientation, + void* user_data) { +} + +static void __frame_component_language_changed_cb(component_h context, + const char* language, void* user_data) { +} + +static void __frame_component_region_format_changed_cb(component_h context, + const char* region, void* user_data) { +} + +static void __frame_component_low_battery_cb(component_h context, + component_low_battery_status_e status, void* user_data) { +} + +static void __frame_component_low_memory_cb(component_h context, + component_low_memory_status_e status, void* user_data) { +} + +static void __frame_component_suspended_state_changed_cb(component_h context, + component_suspended_state_e state, void* user_data) { +} + +static component_class_h __frame_component_add( + component_class_h component_class, const char* component_id, + void* user_data) { + frame_component_lifecycle_callback_s callback; + callback.create = + __frame_component_create_cb; + callback.start = + __frame_component_start_cb; + callback.resume = + __frame_component_resume_cb; + callback.pause = + __frame_component_pause_cb; + callback.stop = + __frame_component_stop_cb; + callback.destroy = + __frame_component_destroy_cb; + callback.restore_content = + __frame_component_restore_content_cb; + callback.save_content = + __frame_component_save_content_cb; + callback.action = + __frame_component_action_cb; + callback.device_orientation_changed = + __frame_component_device_orientation_changed_cb; + callback.language_changed = + __frame_component_language_changed_cb; + callback.region_format_changed = + __frame_component_region_format_changed_cb; + callback.low_battery = + __frame_component_low_battery_cb; + callback.low_memory = + __frame_component_low_memory_cb; + callback.suspended_state_changed = + __frame_component_suspended_state_changed_cb; + + return component_based_app_add_frame_component(component_class, + component_id, &callback, user_data); +} + +static component_class_h __component_based_app_create_cb(void* user_data) { + component_class_h component_class = nullptr; + component_class = __service_component_add(component_class, + "service-component", user_data); + component_class = __frame_component_add(component_class, + "frame-component", user_data); + + return component_class; +} + +static void __component_based_app_terminate_cb(void* user_data) { + +} + +TEST_F(ComponentBasedAppTest, component_based_app_main) { + component_based_app_lifecycle_callback_s callback; + callback.create = __component_based_app_create_cb; + callback.terminate = __component_based_app_terminate_cb; + + int argc = 1; + char tmp_arg[] = "test"; + char** argv = reinterpret_cast(&tmp_arg); + + setenv("AUL_LOADER_INIT", "1", 1); + int ret = component_based_app_main(argc, argv, &callback, this); + unsetenv("AUL_LOADER_INIT"); + EXPECT_EQ(ret, APP_ERROR_NONE); +} + +TEST_F(ComponentBasedAppTest, component_based_app_main_with_hwacc) { + component_based_app_lifecycle_callback_s callback; + callback.create = __component_based_app_create_cb; + callback.terminate = __component_based_app_terminate_cb; + + int argc = 1; + char tmp_arg[] = "test"; + char** argv = reinterpret_cast(&tmp_arg); + + setenv("HWACC", "USE", 1); + int ret = component_based_app_main(argc, argv, &callback, this); + unsetenv("HWACC"); + EXPECT_EQ(ret, APP_ERROR_NONE); +} + +TEST_F(ComponentBasedAppTest, component_based_app_main_without_hwacc) { + component_based_app_lifecycle_callback_s callback; + callback.create = __component_based_app_create_cb; + callback.terminate = __component_based_app_terminate_cb; + + int argc = 1; + char tmp_arg[] = "test"; + char** argv = reinterpret_cast(&tmp_arg); + + setenv("HWACC", "NOT_USE", 1); + int ret = component_based_app_main(argc, argv, &callback, this); + unsetenv("HWACC"); + EXPECT_EQ(ret, APP_ERROR_NONE); +} + +TEST_F(ComponentBasedAppTest, component_based_app_main_with_nullptr) { + int ret = component_based_app_main(0, nullptr, nullptr, nullptr); + EXPECT_EQ(ret, APP_ERROR_INVALID_PARAMETER); +} + +TEST_F(ComponentBasedAppTest, component_based_app_exit) { + int ret = component_based_app_exit(); + EXPECT_EQ(ret, APP_ERROR_NONE); +} + +TEST_F(ComponentBasedAppTest, component_based_app_add_frame_component) { + component_class_h component_class = nullptr; + component_class = __frame_component_add(component_class, + "frame-component-test", nullptr); + EXPECT_NE(component_class, nullptr); +} + +TEST_F(ComponentBasedAppTest, + component_based_app_add_frame_component_with_nullptr) { + component_class_h component_class = nullptr; + component_class = __frame_component_add(component_class, nullptr, nullptr); + EXPECT_EQ(component_class, nullptr); + EXPECT_EQ(get_last_result(), APP_ERROR_INVALID_PARAMETER); +} + + +TEST_F(ComponentBasedAppTest, + component_based_app_add_service_component_with_nullptr) { + component_class_h component_class = nullptr; + component_class = __service_component_add(component_class, nullptr, nullptr); + EXPECT_EQ(component_class, nullptr); + EXPECT_EQ(get_last_result(), APP_ERROR_INVALID_PARAMETER); +} + +} // namespace diff --git a/unit_tests/src/efl_base/test_frame_component.cc b/unit_tests/src/efl_base/test_frame_component.cc new file mode 100644 index 0000000..ad9a7c5 --- /dev/null +++ b/unit_tests/src/efl_base/test_frame_component.cc @@ -0,0 +1,523 @@ +// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include +#include +#include +#include +#include +#include + +#include + +#include "component_based/efl_base/api/frame_component.h" +#include "component_based/efl_base/api/frame_component_internal.h" +#include "component_based/efl_base/api/service_component.h" +#include "component_based/efl_base/api/component_based_app.h" + +#include "unit_tests/mock/mock_app_common.h" +#include "unit_tests/mock/mock_app_control.h" +#include "unit_tests/mock/mock_appcore_multiwindow_base.h" +#include "unit_tests/mock/mock_aul.h" +#include "unit_tests/mock/mock_elementary.h" + +namespace { + +static appcore_multiwindow_base_ops __ops; +static int __argc; +static char** __argv; +static void* __user_data; +static appcore_multiwindow_base_class __cls; +static bool __is_resumed; +static appcore_base_event_cb __event_cb[APPCORE_BASE_EVENT_MAX]; +static void* __event_data[APPCORE_BASE_EVENT_MAX]; + +static void __generate_show_event(void) { + Ecore_Wl2_Event_Window_Show ev = { + .win = 1, + .parent_win = 1, + .event_win = 1, + .data = { 1, } + }; + + __ops.window.show(ECORE_WL2_EVENT_WINDOW_SHOW, &ev, __user_data); +} + +static void __generate_hide_event(void) { + Ecore_Wl2_Event_Window_Hide ev = { + .win = 1, + .parent_win = 1, + .event_win = 1 + }; + + __ops.window.hide(ECORE_WL2_EVENT_WINDOW_HIDE, &ev, __user_data); +} + +static void __generate_lower_event(void) { + Ecore_Wl2_Event_Window_Lower ev = { + .win = 1, + .timestamp = 2 + }; + + __ops.window.lower(ECORE_WL2_EVENT_WINDOW_LOWER, &ev, __user_data); +} + +static void __generate_aux_message(void) { + Ecore_Wl2_Event_Aux_Message ev = { + .win = 1, + .key = "dpms", + .val = "on", + }; + + __ops.window.aux_message(ECORE_WL2_EVENT_AUX_MESSAGE, &ev, __user_data); +} + +static void __generate_pre_visibility_change_event(void) { + Ecore_Wl2_Event_Window_Pre_Visibility_Change ev = { + .win = 1, + .type = ECORE_WL2_WINDOW_VISIBILITY_TYPE_UNOBSCURED, + }; + + __ops.window.pre_visibility(ECORE_WL2_EVENT_WINDOW_PRE_VISIBILITY_CHANGE, &ev, + __user_data); +} + +static void __generate_visibility_change_event(int fully_obscured) { + Ecore_Wl2_Event_Window_Visibility_Change ev = { + .win = 1, + .fully_obscured = fully_obscured + }; + + __ops.window.visibility(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, + &ev, __user_data); +} + +static void __fake_appcore_multiwindow_base_window_on_visibility(int type, + void* event) { + Ecore_Wl2_Event_Window_Visibility_Change* ev = + static_cast(event); + + if (ev->fully_obscured) + appcore_multiwindow_base_instance_pause(nullptr); + else + appcore_multiwindow_base_instance_resume(nullptr); +} + +static int __fake_aul_comp_notify_start(const char *id) { + return 0; +} + +static int __fake_aul_comp_status_update(const char *id, int status) { + return 0; +} + +static void __generate_system_event(void) +{ + char lang[] = "en-US"; + int intval = 1; + void* event; + + for (int i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) { + if (i == APPCORE_BASE_EVENT_LANG_CHANGE || + i == APPCORE_BASE_EVENT_REGION_CHANGE) { + event = static_cast(lang); + } else { + event = static_cast(&intval); + } + + if (__event_cb[i]) { + __event_cb[i](event, __event_data[i]); + } + } +} + +static int __fake_appcore_multiwindow_base_init( + appcore_multiwindow_base_ops ops, + int argc, + char** argv, + void* user_data) { + __ops = ops; + __argc = argc; + __argv = argv; + __user_data = user_data; + + __ops.base.init(__argc, __argv, __user_data); + __ops.base.create(__user_data); + __ops.base.run(__user_data); + + bundle* b = bundle_create(); + bundle_add_str(b, AUL_K_COMPONENT_ID, "test-frame-component"); + bundle_add_str(b, AUL_K_INSTANCE_ID, "@test-frame-component"); + bundle_add_str(b, AUL_K_NEW_INSTANCE, "true"); + std::unique_ptr ptr(b, bundle_free); + + __ops.base.receive(AUL_START, b, __user_data); + __generate_system_event(); + + __ops.base.control(b, __user_data); + __generate_show_event(); + + __ops.base.receive(AUL_RESUME, b, __user_data); + __ops.base.receive(AUL_PAUSE, b, __user_data); + + __generate_hide_event(); + __generate_lower_event(); + __generate_aux_message(); + + __ops.base.receive(AUL_WAKE, b, __user_data); + __ops.base.receive(AUL_SUSPEND, b, __user_data); + + __ops.base.receive(AUL_TERMINATE_INST, b, __user_data); + __ops.base.receive(AUL_TERMINATE_BG_INST, b, __user_data); + __ops.base.receive(AUL_TERMINATE_BGAPP, b, __user_data); + + return 0; +} + +static void __fake_appcore_multiwindow_base_fini(void) { + __cls.terminate(nullptr, __cls.data); + + __ops.base.terminate(__user_data); + __ops.base.finish(); +} + +static void __fake_appcore_multiwindow_base_exit(void) { + __ops.base.exit(__user_data); +} + +static int __fake_elm_init(int argc, char** argv) { + return 0; +} + +static int __fake_elm_shutdown(void) { + return 0; +} + +static Evas_Object* __fake_elm_win_util_standard_add(const char* name, + const char* title) { + Evas_Object* win = reinterpret_cast(malloc(sizeof(void*))); + return win; +} + +static void __fake_evas_object_del(Evas_Object* object) { + free(object); +} + +static void __fake_elm_config_accel_preference_set(const char* pref) { +} + +static void __fake_ecore_wl2_window_activate(Ecore_Wl2_Window* window) { + __generate_pre_visibility_change_event(); + __generate_visibility_change_event(0); +} + +static void __fake_ecore_wl2_window_iconified_set(Ecore_Wl2_Window* window, + Eina_Bool iconified) { + __generate_visibility_change_event(1); +} + +static int __fake_aul_app_group_lower_v2(const char* id, bool* exit) { + *exit = true; + return 0; +} + +static int __fake_aul_app_group_set_window_v2(const char* id, int wid) { + return 0; +} + +static Ecore_Wl2_Window* __fake_ecore_wl2_display_window_find( + Ecore_Wl2_Display* display, unsigned int id) { + static int window; + return reinterpret_cast(&window); +} + +static void __fake_appcore_multiwindow_base_class_add( + appcore_multiwindow_base_class cls) { + __cls = cls; +} + +static appcore_multiwindow_base_instance_h +__fake_appcore_multiwindow_base_instance_run(const char* class_id, + const char* id, void* extra) +{ + static appcore_multiwindow_base_instance_h inst = + reinterpret_cast(&inst); + __cls.create(inst, __cls.data); + + return inst; +} + +static const char* __fake_appcore_multiwindow_base_instance_get_id( + appcore_multiwindow_base_instance_h context) { + return "@test-frame-component"; +} + +static bool __fake_appcore_multiwindow_base_instance_is_resumed( + appcore_multiwindow_base_instance_h context) { + return __is_resumed; +} + +static void __fake_appcore_multiwindow_base_instance_resume( + appcore_multiwindow_base_instance_h context) { + if (__is_resumed) + return; + + __cls.resume(context, __cls.data); + __is_resumed = true; +} + +static void __fake_appcore_multiwindow_base_instance_pause( + appcore_multiwindow_base_instance_h context) { + if (!__is_resumed) + return; + + __cls.pause(context, __cls.data); + __is_resumed = false; +} + +static appcore_base_event_h __fake_appcore_base_add_event( + enum appcore_base_event type, appcore_base_event_cb cb, void* data) { + __event_cb[type] = cb; + __event_data[type] = data; + return nullptr; +} + +static Ecore_Evas* __fake_ecore_evas_ecore_evas_get(const Evas* evas) { + static int ecore_evas; + return reinterpret_cast(&ecore_evas); +} + +static Evas* __fake_evas_object_evas_get(const Eo* eo) { + static int evas; + return reinterpret_cast(&evas); +} + +static Ecore_Wl2_Window* __fake_ecore_evas_wayland2_window_get( + const Ecore_Evas* ee) { + static int wl2_window; + return reinterpret_cast(&wl2_window); +} + +static int __fake_ecore_wl2_window_id_get(Ecore_Wl2_Window* window) { + return 1; +} + +static int __fake_app_get_display_state(app_display_state_e *state) { + *state = APP_DISPLAY_STATE_ON; + return 0; +} + +static int __fake_app_control_add_action_handler(const char* action, + app_control_action_cb callback, void* user_data, + app_control_action_h* handle) { + callback(action, nullptr, user_data); + return 0; +} + +class FrameComponentTest : public ::testing::Test { + protected: + void SetUp() override { + appcore_multiwindow_base_init_fake.custom_fake = + __fake_appcore_multiwindow_base_init; + appcore_multiwindow_base_fini_fake.custom_fake = + __fake_appcore_multiwindow_base_fini; + appcore_multiwindow_base_exit_fake.custom_fake = + __fake_appcore_multiwindow_base_exit; + appcore_multiwindow_base_instance_run_fake.custom_fake = + __fake_appcore_multiwindow_base_instance_run; + appcore_multiwindow_base_class_add_fake.custom_fake = + __fake_appcore_multiwindow_base_class_add; + appcore_multiwindow_base_instance_get_id_fake.custom_fake = + __fake_appcore_multiwindow_base_instance_get_id; + appcore_multiwindow_base_instance_is_resumed_fake.custom_fake = + __fake_appcore_multiwindow_base_instance_is_resumed; + appcore_multiwindow_base_instance_resume_fake.custom_fake = + __fake_appcore_multiwindow_base_instance_resume; + appcore_multiwindow_base_instance_pause_fake.custom_fake = + __fake_appcore_multiwindow_base_instance_pause; + appcore_multiwindow_base_window_on_visibility_fake.custom_fake = + __fake_appcore_multiwindow_base_window_on_visibility; + appcore_base_add_event_fake.custom_fake = + __fake_appcore_base_add_event; + + elm_init_fake.custom_fake = + __fake_elm_init; + elm_shutdown_fake.custom_fake = + __fake_elm_shutdown; + elm_win_util_standard_add_fake.custom_fake = + __fake_elm_win_util_standard_add; + evas_object_del_fake.custom_fake = + __fake_evas_object_del; + elm_config_accel_preference_set_fake.custom_fake = + __fake_elm_config_accel_preference_set; + ecore_wl2_window_activate_fake.custom_fake = + __fake_ecore_wl2_window_activate; + ecore_wl2_window_iconified_set_fake.custom_fake = + __fake_ecore_wl2_window_iconified_set; + ecore_wl2_display_window_find_fake.custom_fake = + __fake_ecore_wl2_display_window_find; + ecore_evas_ecore_evas_get_fake.custom_fake = + __fake_ecore_evas_ecore_evas_get; + evas_object_evas_get_fake.custom_fake = + __fake_evas_object_evas_get; + ecore_evas_wayland2_window_get_fake.custom_fake = + __fake_ecore_evas_wayland2_window_get; + ecore_wl2_window_id_get_fake.custom_fake = + __fake_ecore_wl2_window_id_get; + + aul_app_group_set_window_v2_fake.custom_fake = + __fake_aul_app_group_set_window_v2; + aul_app_group_lower_v2_fake.custom_fake = + __fake_aul_app_group_lower_v2; + aul_comp_notify_start_fake.custom_fake = + __fake_aul_comp_notify_start; + aul_comp_status_update_fake.custom_fake = + __fake_aul_comp_status_update; + + app_get_display_state_fake.custom_fake = + __fake_app_get_display_state; + + app_control_add_action_handler_fake.custom_fake = + __fake_app_control_add_action_handler; + } + + void TearDown() override {} +}; + +static Evas_Object* __frame_component_create_cb(component_h context, + void* user_data) { + return elm_win_util_standard_add("frame", "frame"); +} + +static void __frame_component_start_cb(component_h context, + app_control_h app_control, bool restarted, void* user_data) { + component_register_action(context, "action"); +} + +static void __frame_component_resume_cb(component_h context, + void* user_data) { + component_display_status_e status; + frame_component_get_display_status(context, &status); + + Evas_Object* win = nullptr; + frame_component_get_window(context, &win); + + int res_id = 0; + frame_component_get_resource_id(win, &res_id); +} + +static void __frame_component_pause_cb(component_h context, + void* user_data) { +} + +static void __frame_component_stop_cb(component_h context, + void* user_data) { +} + +static void __frame_component_destroy_cb(component_h context, + void *user_data) { +} + +static void __frame_component_restore_content_cb(component_h context, + bundle* content, void* user_data) { +} + +static void __frame_component_save_content_cb(component_h context, + bundle* content, void* user_data) { +} + +static void __frame_component_action_cb(component_h context, + const char* action, app_control_h app_control, void* user_data) { +} + +static void __frame_component_device_orientation_changed_cb( + component_h context, component_device_orientation_e orientation, + void* user_data) { +} + +static void __frame_component_language_changed_cb(component_h context, + const char* language, void* user_data) { +} + +static void __frame_component_region_format_changed_cb(component_h context, + const char* region, void* user_data) { +} + +static void __frame_component_low_battery_cb(component_h context, + component_low_battery_status_e status, void* user_data) { +} + +static void __frame_component_low_memory_cb(component_h context, + component_low_memory_status_e status, void* user_data) { +} + +static void __frame_component_suspended_state_changed_cb(component_h context, + component_suspended_state_e state, void* user_data) { +} + +static component_class_h __frame_component_add( + component_class_h component_class, const char* component_id, + void* user_data) { + frame_component_lifecycle_callback_s callback; + callback.create = + __frame_component_create_cb; + callback.start = + __frame_component_start_cb; + callback.resume = + __frame_component_resume_cb; + callback.pause = + __frame_component_pause_cb; + callback.stop = + __frame_component_stop_cb; + callback.destroy = + __frame_component_destroy_cb; + callback.restore_content = + __frame_component_restore_content_cb; + callback.save_content = + __frame_component_save_content_cb; + callback.action = + __frame_component_action_cb; + callback.device_orientation_changed = + __frame_component_device_orientation_changed_cb; + callback.language_changed = + __frame_component_language_changed_cb; + callback.region_format_changed = + __frame_component_region_format_changed_cb; + callback.low_battery = + __frame_component_low_battery_cb; + callback.low_memory = + __frame_component_low_memory_cb; + callback.suspended_state_changed = + __frame_component_suspended_state_changed_cb; + + return component_based_app_add_frame_component(component_class, + component_id, &callback, user_data); +} + +static component_class_h __component_based_app_create_cb(void* user_data) { + component_class_h component_class = nullptr; + component_class = __frame_component_add(component_class, + "test-frame-component", user_data); + + return component_class; +} + +static void __component_based_app_terminate_cb(void* user_data) { + +} + +TEST_F(FrameComponentTest, frame_component_test) { + component_based_app_lifecycle_callback_s callback; + callback.create = __component_based_app_create_cb; + callback.terminate = __component_based_app_terminate_cb; + + int argc = 1; + char tmp_arg[] = "test"; + char** argv = reinterpret_cast(&tmp_arg); + + int ret = component_based_app_main(argc, argv, &callback, this); + EXPECT_EQ(ret, APP_ERROR_NONE); +} + +} // namespace diff --git a/unit_tests/src/efl_base/test_service_component.cc b/unit_tests/src/efl_base/test_service_component.cc new file mode 100644 index 0000000..b19f546 --- /dev/null +++ b/unit_tests/src/efl_base/test_service_component.cc @@ -0,0 +1,351 @@ +// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include +#include +#include +#include +#include +#include + +#include + +#include "component_based/efl_base/api/frame_component.h" +#include "component_based/efl_base/api/service_component.h" +#include "component_based/efl_base/api/component_based_app.h" + +#include "unit_tests/mock/mock_app_common.h" +#include "unit_tests/mock/mock_app_control.h" +#include "unit_tests/mock/mock_appcore_multiwindow_base.h" +#include "unit_tests/mock/mock_aul.h" +#include "unit_tests/mock/mock_elementary.h" + +namespace { + +static appcore_multiwindow_base_ops __ops; +static int __argc; +static char** __argv; +static void* __user_data; +static appcore_multiwindow_base_class __cls; +static appcore_base_event_cb __event_cb[APPCORE_BASE_EVENT_MAX]; +static void* __event_data[APPCORE_BASE_EVENT_MAX]; + +static int __fake_aul_comp_notify_start(const char *id) { + return 0; +} + +static int __fake_aul_comp_status_update(const char *id, int status) { + return 0; +} + +static void __generate_system_event(void) +{ + char lang[] = "en-US"; + int intval = 1; + void* event; + + for (int i = APPCORE_BASE_EVENT_START + 1; i < APPCORE_BASE_EVENT_MAX; i++) { + if (i == APPCORE_BASE_EVENT_LANG_CHANGE || + i == APPCORE_BASE_EVENT_REGION_CHANGE) { + event = static_cast(lang); + } else { + event = static_cast(&intval); + } + + if (__event_cb[i]) { + __event_cb[i](event, __event_data[i]); + } + } +} + +static int __fake_appcore_multiwindow_base_init( + appcore_multiwindow_base_ops ops, + int argc, + char** argv, + void* user_data) { + __ops = ops; + __argc = argc; + __argv = argv; + __user_data = user_data; + + __ops.base.init(__argc, __argv, __user_data); + __ops.base.create(__user_data); + __ops.base.run(__user_data); + + bundle* b = bundle_create(); + bundle_add_str(b, AUL_K_COMPONENT_ID, "test-service-component"); + bundle_add_str(b, AUL_K_INSTANCE_ID, "@test-service-component"); + bundle_add_str(b, AUL_K_NEW_INSTANCE, "true"); + std::unique_ptr ptr(b, bundle_free); + + __ops.base.receive(AUL_START, b, __user_data); + + __generate_system_event(); + + __ops.base.control(b, __user_data); + + __ops.base.receive(AUL_RESUME, b, __user_data); + __ops.base.receive(AUL_PAUSE, b, __user_data); + + __ops.base.receive(AUL_WAKE, b, __user_data); + __ops.base.receive(AUL_SUSPEND, b, __user_data); + + __ops.base.receive(AUL_TERMINATE_INST, b, __user_data); + __ops.base.receive(AUL_TERMINATE_BG_INST, b, __user_data); + __ops.base.receive(AUL_TERMINATE_BGAPP, b, __user_data); + + return 0; +} + +static void __fake_appcore_multiwindow_base_fini(void) { + __cls.terminate(nullptr, __cls.data); + + __ops.base.terminate(__user_data); + __ops.base.finish(); +} + +static void __fake_appcore_multiwindow_base_exit(void) { + __ops.base.exit(__user_data); +} + +static int __fake_elm_init(int argc, char** argv) { + return 0; +} + +static int __fake_elm_shutdown(void) { + return 0; +} + +static void __fake_appcore_multiwindow_base_class_add( + appcore_multiwindow_base_class cls) { + __cls = cls; +} + +static appcore_multiwindow_base_instance_h +__fake_appcore_multiwindow_base_instance_run(const char* class_id, + const char* id, void* extra) +{ + static appcore_multiwindow_base_instance_h inst = + reinterpret_cast(&inst); + + __cls.create(inst, __cls.data); + + return inst; +} + +static const char* __fake_appcore_multiwindow_base_instance_get_id( + appcore_multiwindow_base_instance_h context) { + return "@test-service-component"; +} + +static appcore_base_event_h __fake_appcore_base_add_event( + enum appcore_base_event type, appcore_base_event_cb cb, void* data) { + __event_cb[type] = cb; + __event_data[type] = data; + return nullptr; +} + +static int __fake_app_control_add_action_handler(const char* action, + app_control_action_cb callback, void* user_data, + app_control_action_h* handle) { + callback(action, nullptr, user_data); + return 0; +} + +static int __fake_app_control_send_launch_request_async( + app_control_h app_control, + app_control_result_cb result_cb, + app_control_reply_cb reply_cb, + void* user_data) { + result_cb(app_control, APP_CONTROL_ERROR_NONE, user_data); + reply_cb(app_control, app_control, APP_CONTROL_RESULT_SUCCEEDED, user_data); + return 0; +} + +static int __fake_app_control_send_launch_request_sync( + app_control_h app_control, + app_control_h* reply, + app_control_result_e* result) { + app_control_h handle = nullptr; + app_control_create(&handle); + *reply = handle; + *result = APP_CONTROL_RESULT_SUCCEEDED; + return 0; +} + +class ServiceComponentTest : public ::testing::Test { + protected: + void SetUp() override { + appcore_multiwindow_base_init_fake.custom_fake = + __fake_appcore_multiwindow_base_init; + appcore_multiwindow_base_fini_fake.custom_fake = + __fake_appcore_multiwindow_base_fini; + appcore_multiwindow_base_exit_fake.custom_fake = + __fake_appcore_multiwindow_base_exit; + appcore_multiwindow_base_instance_run_fake.custom_fake = + __fake_appcore_multiwindow_base_instance_run; + appcore_multiwindow_base_class_add_fake.custom_fake = + __fake_appcore_multiwindow_base_class_add; + appcore_multiwindow_base_instance_get_id_fake.custom_fake = + __fake_appcore_multiwindow_base_instance_get_id; + appcore_base_add_event_fake.custom_fake = + __fake_appcore_base_add_event; + + elm_init_fake.custom_fake = + __fake_elm_init; + elm_shutdown_fake.custom_fake = + __fake_elm_shutdown; + aul_comp_notify_start_fake.custom_fake = + __fake_aul_comp_notify_start; + aul_comp_status_update_fake.custom_fake = + __fake_aul_comp_status_update; + app_control_add_action_handler_fake.custom_fake = + __fake_app_control_add_action_handler; + app_control_send_launch_request_async_fake.custom_fake = + __fake_app_control_send_launch_request_async; + app_control_send_launch_request_sync_fake.custom_fake = + __fake_app_control_send_launch_request_sync; + } + + void TearDown() override {} +}; + +static void __app_control_result_cb(app_control_h request, + app_control_error_e result, void* user_data) { +} + +static void __app_control_reply_cb(app_control_h request, + app_control_h reply, app_control_result_e result, void* user_data) { +} + +static bool __service_component_create_cb(component_h context, + void* user_data) { + char* id = nullptr; + component_get_id(context, &id); + free(id); + + char* inst_id = nullptr; + component_get_instance_id(context, &inst_id); + free(inst_id); + return true; +} + +static void __service_component_start_command_cb(component_h context, + app_control_h app_control, bool restarted, void* user_data) { + component_register_action(context, "action"); + component_deregister_action(context, "action"); + + app_control_h handle = nullptr; + app_control_create(&handle); + component_send_launch_request_async(context, handle, __app_control_result_cb, + __app_control_reply_cb, nullptr); + + app_control_h reply = nullptr; + app_control_result_e result; + component_send_launch_request_sync(context, handle, &reply, &result); + app_control_destroy(reply); + app_control_destroy(handle); + + component_finish(context); +} + +static void __service_component_destroy_cb(component_h context, + void *user_data) { +} + +static void __service_component_restore_content_cb(component_h context, + bundle* content, void* user_data) { +} + +static void __service_component_save_content_cb(component_h context, + bundle* content, void* user_data) { +} + +static void __service_component_action_cb(component_h context, + const char* action, app_control_h app_control, void* user_data) { +} + +static void __service_component_device_orientation_changed_cb( + component_h context, component_device_orientation_e orientation, + void* user_data) { +} + +static void __service_component_language_changed_cb(component_h context, + const char* language, void* user_data) { +} + +static void __service_component_region_format_changed_cb(component_h context, + const char* region, void* user_data) { +} + +static void __service_component_low_battery_cb(component_h context, + component_low_battery_status_e status, void* user_data) { +} + +static void __service_component_low_memory_cb(component_h context, + component_low_memory_status_e status, void* user_data) { +} + +static void __service_component_suspended_state_changed_cb(component_h context, + component_suspended_state_e state, void* user_data) { +} + +static component_class_h __service_component_add( + component_class_h component_class, const char* component_id, + void* user_data) { + service_component_lifecycle_callback_s callback; + callback.create = + __service_component_create_cb; + callback.start_command = + __service_component_start_command_cb; + callback.destroy = + __service_component_destroy_cb; + callback.restore_content = + __service_component_restore_content_cb; + callback.save_content = + __service_component_save_content_cb; + callback.action = + __service_component_action_cb; + callback.device_orientation_changed = + __service_component_device_orientation_changed_cb; + callback.language_changed = + __service_component_language_changed_cb; + callback.region_format_changed = + __service_component_region_format_changed_cb; + callback.low_battery = + __service_component_low_battery_cb; + callback.low_memory = + __service_component_low_memory_cb; + callback.suspended_state_changed = + __service_component_suspended_state_changed_cb; + + return component_based_app_add_service_component(component_class, + component_id, &callback, user_data); +} + +static component_class_h __component_based_app_create_cb(void* user_data) { + component_class_h component_class = nullptr; + component_class = __service_component_add(component_class, + "test-service-component", user_data); + + return component_class; +} + +static void __component_based_app_terminate_cb(void* user_data) { +} + +TEST_F(ServiceComponentTest, service_component_test) { + component_based_app_lifecycle_callback_s callback; + callback.create = __component_based_app_create_cb; + callback.terminate = __component_based_app_terminate_cb; + + int argc = 1; + char tmp_arg[] = "test"; + char** argv = reinterpret_cast(&tmp_arg); + + int ret = component_based_app_main(argc, argv, &callback, this); + EXPECT_EQ(ret, APP_ERROR_NONE); +} + +} // namespace