Change unittest package name and improves code coverage
[platform/core/appfw/appcore-widget.git] / test / unit_tests / test_widget_app_cpp.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19
20 #include <widget_app.hpp>
21
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"
32
33 using ::testing::_;
34 using ::testing::DoAll;
35 using ::testing::Invoke;
36 using ::testing::Return;
37 using ::testing::SetArgPointee;
38
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> {};
46
47 class WidgetAppCppTest : public TestFixture {
48  public:
49   WidgetAppCppTest() : TestFixture(std::make_unique<Mocks>()) {}
50 };
51
52 class WidgetApp : public tizen_appfw::WidgetAppBase {
53  public:
54   class Instance : public InstanceBase {
55    public:
56     class Factory : public InstanceBase::Factory {
57      public:
58       std::unique_ptr<InstanceBase> Create(widget_context_h h) override {
59         return std::unique_ptr<InstanceBase>(new Instance(h));
60       }
61     };
62
63     explicit Instance(widget_context_h h) : InstanceBase(h) {}
64 /* LCOV_EXCL_START */
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 {}
71 /* LCOV_EXCL_STOP */
72   };
73
74   WidgetApp() {}
75   void OnCreate() override {}
76   void OnTerminate() override {}
77 };
78
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)));
83
84   WidgetApp app;
85   std::unique_ptr<tizen_appfw::WidgetAppBase::InstanceBase::Factory> factory(
86       new WidgetApp::Instance::Factory());
87
88   widget_context_h h = nullptr;
89   factory->Create(h);
90   app.OnCreate();
91   int ret = app.Run(0, nullptr, std::move(factory));
92   EXPECT_EQ(ret, APP_ERROR_INVALID_PARAMETER);
93   app.OnTerminate();
94 }
95
96 TEST_F(WidgetAppCppTest, NullInstance) {
97     EXPECT_CALL(GetMock<SystemInfoMock>(),
98         system_info_get_platform_bool(_, _)).
99             WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(0)));
100
101   widget_context_h h = nullptr;
102   std::unique_ptr<tizen_appfw::WidgetAppBase::InstanceBase> inst(
103       new WidgetApp::Instance(h));
104
105   widget_context_h ret_h = inst->GetHandle();
106   EXPECT_EQ(ret_h, nullptr);
107 }