2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
20 #include <widget_app.hpp>
22 #include "include/widget_app.h"
23 #include "include/widget_app_efl.h"
24 #include "unit_tests/mock/app_common_mock.h"
25 #include "unit_tests/mock/appcore_multiwindow_base_mock.h"
26 #include "unit_tests/mock/aul_mock.h"
27 #include "unit_tests/mock/ecore_wl2_mock.h"
28 #include "unit_tests/mock/elm_mock.h"
29 #include "unit_tests/mock/system_info_mock.h"
30 #include "unit_tests/mock/test_fixture.h"
31 #include "unit_tests/mock/widget_service_mock.h"
34 using ::testing::DoAll;
35 using ::testing::Invoke;
36 using ::testing::Return;
37 using ::testing::SetArgPointee;
39 class Mocks : public ::testing::NiceMock<MultiWindowBaseMock>,
40 public ::testing::NiceMock<AppCommonMock>,
41 public ::testing::NiceMock<WidgetServiceMock>,
42 public ::testing::NiceMock<ElmMock>,
43 public ::testing::NiceMock<AulMock>,
44 public ::testing::NiceMock<SystemInfoMock>,
45 public ::testing::NiceMock<EcoreWl2Mock> {};
47 class WidgetAppCppTest : public TestFixture {
49 WidgetAppCppTest() : TestFixture(std::make_unique<Mocks>()) {}
52 class WidgetApp : public tizen_appfw::WidgetAppBase {
54 class Instance : public InstanceBase {
56 class Factory : public InstanceBase::Factory {
58 std::unique_ptr<InstanceBase> Create(widget_context_h h) override {
59 return std::unique_ptr<InstanceBase>(new Instance(h));
63 explicit Instance(widget_context_h h) : InstanceBase(h) {}
65 void OnCreate(const tizen_base::Bundle& content, int w, int h) override {}
66 void OnDestroy(DestroyType reason, tizen_base::Bundle* content) override {}
67 void OnPause() override {}
68 void OnResume() override {}
69 void OnResize(int w, int h) override {}
70 void OnUpdate(const tizen_base::Bundle& content, bool force) override {}
75 void OnCreate() override {}
76 void OnTerminate() override {}
79 TEST_F(WidgetAppCppTest, Run_InvalidParameter) {
80 EXPECT_CALL(GetMock<SystemInfoMock>(),
81 system_info_get_platform_bool(_, _)).
82 WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(0)));
85 std::unique_ptr<tizen_appfw::WidgetAppBase::InstanceBase::Factory> factory(
86 new WidgetApp::Instance::Factory());
88 widget_context_h h = nullptr;
91 int ret = app.Run(0, nullptr, std::move(factory));
92 EXPECT_EQ(ret, APP_ERROR_INVALID_PARAMETER);
96 TEST_F(WidgetAppCppTest, NullInstance) {
97 EXPECT_CALL(GetMock<SystemInfoMock>(),
98 system_info_get_platform_bool(_, _)).
99 WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(0)));
101 widget_context_h h = nullptr;
102 std::unique_ptr<tizen_appfw::WidgetAppBase::InstanceBase> inst(
103 new WidgetApp::Instance(h));
105 widget_context_h ret_h = inst->GetHandle();
106 EXPECT_EQ(ret_h, nullptr);