8d5fca52b362737d842c8e6137fe088261fed8bc
[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/gio_mock.h"
30 #include "unit_tests/mock/system_info_mock.h"
31 #include "unit_tests/mock/test_fixture.h"
32 #include "unit_tests/mock/widget_service_mock.h"
33
34 using ::testing::_;
35 using ::testing::DoAll;
36 using ::testing::Invoke;
37 using ::testing::Return;
38 using ::testing::SetArgPointee;
39
40 class Mocks : public ::testing::NiceMock<GioMock>,
41               public ::testing::NiceMock<MultiWindowBaseMock>,
42               public ::testing::NiceMock<AppCommonMock>,
43               public ::testing::NiceMock<WidgetServiceMock>,
44               public ::testing::NiceMock<ElmMock>,
45               public ::testing::NiceMock<AulMock>,
46               public ::testing::NiceMock<SystemInfoMock>,
47               public ::testing::NiceMock<EcoreWl2Mock> {};
48
49 class WidgetAppCppTest : public TestFixture {
50  public:
51   WidgetAppCppTest() : TestFixture(std::make_unique<Mocks>()) {}
52 };
53
54 class WidgetApp : public tizen_appfw::WidgetAppBase {
55  public:
56   class Instance : public InstanceBase {
57    public:
58     class Factory : public InstanceBase::Factory {
59      public:
60       std::unique_ptr<InstanceBase> Create(widget_context_h h) override {
61         return std::unique_ptr<InstanceBase>(new Instance(h));
62       }
63     };
64
65     explicit Instance(widget_context_h h) : InstanceBase(h) {}
66     void OnCreate(const tizen_base::Bundle& content, int w, int h) override {}
67     void OnDestroy(DestroyType reason, tizen_base::Bundle* content) override {}
68     void OnPause() override {}
69     void OnResume() override {}
70     void OnResize(int w, int h) override {}
71     void OnUpdate(const tizen_base::Bundle& content, bool force) override {}
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   int ret = app.Run(0, nullptr, std::move(factory));
89   EXPECT_EQ(ret, APP_ERROR_INVALID_PARAMETER);
90 }