• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define private public
17 #include <dlfcn.h>
18 #include "plugin_mgr.h"
19 #include "res_type.h"
20 #include "plugin_mgr_test.h"
21 #undef private
22 #include "mock_plugin_mgr.h"
23 #include "socperf_plugin.h"
24 #include "res_data.h"
25 #include "res_type.h"
26 
27 using namespace std;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace ResourceSchedule {
32 namespace {
33     const string LIB_NAME = "libunittest_plugin.z.so";
34 }
35 
SetUpTestCase()36 void PluginMgrTest::SetUpTestCase() {}
37 
TearDownTestCase()38 void PluginMgrTest::TearDownTestCase() {}
39 
SetUp()40 void PluginMgrTest::SetUp()
41 {
42     /**
43      * @tc.setup: initialize the member variable pluginMgr_
44      */
45     pluginMgr_ = make_shared<MockPluginMgr>();
46 }
47 
TearDown()48 void PluginMgrTest::TearDown()
49 {
50     /**
51      * @tc.teardown: clear pluginMgr_
52      */
53     pluginMgr_ = nullptr;
54 }
55 
56 /**
57  * @tc.name: Plugin mgr test Init 001
58  * @tc.desc: Verify if can init success.
59  * @tc.type: FUNC
60  * @tc.require: SR000GGUUN AR000GH37C AR000GH37D AR000GH37E AR000GH37F AR000GH37G AR000GH1JU AR000GH1JO
61  * @tc.author:xukuan
62  */
63 HWTEST_F(PluginMgrTest, Init001, TestSize.Level1)
64 {
65     pluginMgr_->Init();
66     EXPECT_TRUE(pluginMgr_->initStatus == pluginMgr_->INIT_SUCCESS);
67     EXPECT_EQ(pluginMgr_->pluginLibMap_.size(), 0);
68 }
69 
70 /**
71  * @tc.name: Plugin mgr test Stop 001
72  * @tc.desc: Verify if can stop success.
73  * @tc.type: FUNC
74  * @tc.require: SR000GGUUN AR000GH37C AR000GH37D AR000GH37E AR000GH37F AR000GH37G AR000GH1JU AR000GH1JO
75  * @tc.author:xukuan
76  */
77 HWTEST_F(PluginMgrTest, Stop001, TestSize.Level1)
78 {
79     pluginMgr_->Stop();
80     EXPECT_EQ(pluginMgr_->pluginLibMap_.size(), 0);
81     EXPECT_EQ(pluginMgr_->resTypeLibMap_.size(), 0);
82     EXPECT_EQ(pluginMgr_->dispatcherHandlerMap_.size(), 0);
83     EXPECT_TRUE(pluginMgr_->configReader_ == nullptr);
84 }
85 
86 /**
87  * @tc.name: Plugin mgr test GetConfig 001
88  * @tc.desc: Verify if can get config with wrong env.
89  * @tc.type: FUNC
90  * @tc.require: issueI5WWV3
91  * @tc.author:lice
92  */
93 HWTEST_F(PluginMgrTest, GetConfig001, TestSize.Level1)
94 {
95     PluginConfig config = pluginMgr_->GetConfig("", "");
96     EXPECT_TRUE(config.itemList.empty());
97 }
98 
99 /**
100  * @tc.name: Plugin mgr test SubscribeResource 001
101  * @tc.desc: Verify if can stop success.
102  * @tc.type: FUNC
103  * @tc.require: SR000GGUUN AR000GH1JP AR000GH1JR AR000GH1JS AR000GH1JT AR000GH1JV AR000GH1K0
104  * @tc.author:xukuan
105  */
106 HWTEST_F(PluginMgrTest, SubscribeResource001, TestSize.Level1)
107 {
108     pluginMgr_->Init();
109     pluginMgr_->SubscribeResource(LIB_NAME, ResType::RES_TYPE_SCREEN_STATUS);
110     auto iter = pluginMgr_->resTypeLibMap_.find(ResType::RES_TYPE_SCREEN_STATUS);
111     string libName = iter->second.back();
112     EXPECT_EQ(libName.compare(LIB_NAME), 0);
113 }
114 
115 /**
116  * @tc.name: Plugin mgr test Dump 001
117  * @tc.desc: Verify if dump commands is success.
118  * @tc.type: FUNC
119  * @tc.require: issueI5WWV3
120  * @tc.author:lice
121  */
122 HWTEST_F(PluginMgrTest, Dump001, TestSize.Level1)
123 {
124     std::string res;
125     pluginMgr_->Init();
126     pluginMgr_->DumpAllPlugin(res);
127     EXPECT_TRUE(!res.empty());
128     res = "";
129 
130     pluginMgr_->LoadPlugin();
131     pluginMgr_->DumpHelpFromPlugin(res);
132     EXPECT_TRUE(res.empty());
133     res = "";
134 
135     std::vector<std::string> args;
136     pluginMgr_->DumpOnePlugin(res, LIB_NAME, args);
137     EXPECT_TRUE(!res.empty());
138     res = "";
139 
140     args.emplace_back("-h");
141     pluginMgr_->DumpOnePlugin(res, LIB_NAME, args);
142     EXPECT_TRUE(!res.empty());
143 }
144 
145 /**
146  * @tc.name: Plugin mgr test RepairPlugin 001
147  * @tc.desc: Verify if RepairPlugin is success.
148  * @tc.type: FUNC
149  * @tc.require: issueI5WWV3
150  * @tc.author:lice
151  */
152 HWTEST_F(PluginMgrTest, RepairPlugin001, TestSize.Level1)
153 {
154     PluginLib libInfo = pluginMgr_->pluginLibMap_.find(LIB_NAME)->second;
155     pluginMgr_->RepairPlugin(Clock::now(), LIB_NAME, libInfo);
156     EXPECT_TRUE(true);
157 }
158 
159 /**
160  * @tc.name: Plugin mgr test UnSubscribeResource 001
161  * @tc.desc: Verify if can stop success.
162  * @tc.type: FUNC
163  * @tc.require: SR000GGUUN AR000GH1JP AR000GH1JR AR000GH1JS AR000GH1JT AR000GH1JV AR000GH1K0
164  * @tc.author:xukuan
165  */
166 HWTEST_F(PluginMgrTest, UnSubscribeResource001, TestSize.Level1)
167 {
168     pluginMgr_->UnSubscribeResource(LIB_NAME, ResType::RES_TYPE_SCREEN_STATUS);
169     auto iter = pluginMgr_->resTypeLibMap_.find(ResType::RES_TYPE_SCREEN_STATUS);
170     EXPECT_TRUE(iter == pluginMgr_->resTypeLibMap_.end());
171 }
172 
173 /**
174  * @tc.name: Plugin mgr test Remove 001
175  * @tc.desc: Verify if RemoveDisablePluginHandler is success.
176  * @tc.type: FUNC
177  * @tc.require: issueI5WWV3
178  * @tc.author:lice
179  */
180 HWTEST_F(PluginMgrTest, Remove001, TestSize.Level1)
181 {
182     pluginMgr_->RemoveDisablePluginHandler();
183     EXPECT_TRUE(!pluginMgr_->disablePlugins_.size());
184 
185     pluginMgr_->LoadPlugin();
186 }
187 
188 /*
189  * @tc.name: SocPerfSubTest_DispatchResource_001
190  * @tc.desc: DispatchResource Plugin
191  * @tc.type FUNC
192  * @tc.author:zoujie
193  * @tc.require: issueI5VWUI
194  */
195 HWTEST_F(PluginMgrTest, PluginMgrTest_DispatchResource_001, TestSize.Level1)
196 {
197     nlohmann::json payload;
198     auto data = std::make_shared<ResData>(ResType::RES_TYPE_APP_ABILITY_START,
199         ResType::AppStartType::APP_COLD_START, payload);
200     /* Init */
201     SocPerfPlugin::GetInstance().Init();
202     /* HandleAppAbilityStart */
203     SocPerfPlugin::GetInstance().DispatchResource(data);
204     data->value = ResType::AppStartType::APP_WARM_START;
205     SocPerfPlugin::GetInstance().DispatchResource(data);
206 
207     /* HandleWindowFocus */
208     data->resType = ResType::RES_TYPE_WINDOW_FOCUS;
209     data->value = ResType::WindowFocusStatus::WINDOW_FOCUS;
210     SocPerfPlugin::GetInstance().DispatchResource(data);
211 
212     /* HandleEventClick */
213     data->resType = ResType::RES_TYPE_CLICK_RECOGNIZE;
214     data->value = ResType::ClickEventType::TOUCH_EVENT;
215     SocPerfPlugin::GetInstance().DispatchResource(data);
216     data->value = ResType::ClickEventType::CLICK_EVENT;
217     SocPerfPlugin::GetInstance().DispatchResource(data);
218 
219     /* HandlePushPage */
220     data->resType = ResType::RES_TYPE_PUSH_PAGE;
221     data->value = ResType::PushPageType::PUSH_PAGE_START;
222     SocPerfPlugin::GetInstance().DispatchResource(data);
223     data->value = ResType::PushPageType::PUSH_PAGE_COMPLETE;
224     SocPerfPlugin::GetInstance().DispatchResource(data);
225 
226     /* HandlePopPage */
227     data->resType = ResType::RES_TYPE_POP_PAGE;
228     data->value = 0;
229     SocPerfPlugin::GetInstance().DispatchResource(data);
230 
231     /* HandleEventSlide */
232     data->resType = ResType::RES_TYPE_SLIDE_RECOGNIZE;
233     data->value = ResType::SlideEventStatus::SLIDE_EVENT_ON;
234     SocPerfPlugin::GetInstance().DispatchResource(data);
235     data->value = ResType::SlideEventStatus::SLIDE_EVENT_OFF;
236     SocPerfPlugin::GetInstance().DispatchResource(data);
237 
238     /* HandleEventWebGesture */
239     data->resType = ResType::RES_TYPE_WEB_GESTURE;
240     data->value = 0;
241     SocPerfPlugin::GetInstance().DispatchResource(data);
242 
243     /* HandleResizeWindow */
244     data->resType = ResType::RES_TYPE_RESIZE_WINDOW;
245     data->value = ResType::WindowResizeType::WINDOW_RESIZING;
246     SocPerfPlugin::GetInstance().DispatchResource(data);
247     data->value = ResType::WindowResizeType::WINDOW_RESIZE_STOP;
248     SocPerfPlugin::GetInstance().DispatchResource(data);
249 
250     /* HandleMoveWindow */
251     data->resType = ResType::RES_TYPE_MOVE_WINDOW;
252     data->value = ResType::WindowMoveType::WINDOW_MOVING;
253     SocPerfPlugin::GetInstance().DispatchResource(data);
254     data->value = ResType::WindowMoveType::WINDOW_MOVE_STOP;
255     SocPerfPlugin::GetInstance().DispatchResource(data);
256 
257     /* DeInit */
258     SocPerfPlugin::GetInstance().Disable();
259 }
260 } // namespace ResourceSchedule
261 } // namespace OHOS
262