• 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 #include "launcher_service.h"
17 
18 #include <benchmark/benchmark.h>
19 
20 namespace OHOS {
21 namespace AppExecFwk {
22         class TestBundleStatusCallback : public IBundleStatusCallback {
23         public:
24             TestBundleStatusCallback() = default;
TestBundleStatusCallback(const std::string & code)25             explicit TestBundleStatusCallback(const std::string& code) : testCode_(code)
26             {}
27             ~TestBundleStatusCallback() = default;
28             virtual void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode,
29                 const std::string &resultMsg, const std::string &bundleName) override;
30             virtual void OnBundleAdded(const std::string &bundleName, const int userId) override;
31             virtual void OnBundleUpdated(const std::string &bundleName, const int userId) override;
32             virtual void OnBundleRemoved(const std::string &bundleName, const int userId) override;
33             virtual sptr<IRemoteObject> AsObject() override;
34         private:
35             std::string testCode_ {};
36         };
OnBundleStateChanged(const uint8_t installType,const int32_t resultCode,const std::string & resultMsg,const std::string & bundleName)37         void TestBundleStatusCallback::OnBundleStateChanged(const uint8_t installType, const int32_t resultCode,
38             const std::string &resultMsg, const std::string &bundleName)
39         {
40         }
OnBundleAdded(const std::string & bundleName,const int userId)41         void TestBundleStatusCallback::OnBundleAdded(const std::string &bundleName, const int userId)
42         {
43         }
44 
OnBundleUpdated(const std::string & bundleName,const int userId)45         void TestBundleStatusCallback::OnBundleUpdated(const std::string &bundleName, const int userId)
46         {
47         }
48 
OnBundleRemoved(const std::string & bundleName,const int userId)49         void TestBundleStatusCallback::OnBundleRemoved(const std::string &bundleName, const int userId)
50         {
51         }
52 
AsObject()53         sptr<IRemoteObject> TestBundleStatusCallback::AsObject()
54         {
55             return nullptr;
56         }
57     }
58 }
59 
60 using namespace std;
61 using namespace OHOS;
62 using namespace OHOS::AppExecFwk;
63 
64 namespace {
65     /**
66      * @tc.name: BenchmarkTestForRegisterCallback
67      * @tc.desc: Testcase for testing 'RegisterCallback' function.
68      * @tc.type: FUNC
69      * @tc.require: Issue Number
70      */
BenchmarkTestForRegisterCallback(benchmark::State & state)71     static void BenchmarkTestForRegisterCallback(benchmark::State &state)
72     {
73         LauncherService launcherservice;
74         sptr<TestBundleStatusCallback> callback = new TestBundleStatusCallback();
75         for (auto _ : state) {
76             /* @tc.steps: step1.call RegisterCallback in loop */
77             launcherservice.RegisterCallback(callback);
78         }
79     }
80 
81     /**
82      * @tc.name: BenchmarkTestForUnRegisterCallback
83      * @tc.desc: Testcase for testing 'UnRegisterCallback' function.
84      * @tc.type: FUNC
85      * @tc.require: Issue Number
86      */
BenchmarkTestForUnRegisterCallback(benchmark::State & state)87     static void BenchmarkTestForUnRegisterCallback(benchmark::State &state)
88     {
89         LauncherService launcherservice;
90         for (auto _ : state) {
91             /* @tc.steps: step1.call UnRegisterCallback in loop */
92             launcherservice.UnRegisterCallback();
93         }
94     }
95 
96     /**
97      * @tc.name: BenchmarkTestForGetAbilityList
98      * @tc.desc: Testcase for testing 'GetAbilityList' function.
99      * @tc.type: FUNC
100      * @tc.require: Issue Number
101      */
BenchmarkTestForGetAbilityList(benchmark::State & state)102     static void BenchmarkTestForGetAbilityList(benchmark::State &state)
103     {
104         LauncherService launcherservice;
105         std::string bundleName = "ohos.global.systemres";
106         int userId = 100;
107         std::vector<LauncherAbilityInfo> launcherAbilityInfos;
108         for (auto _ : state) {
109             /* @tc.steps: step1.call GetAbilityList in loop */
110             launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos);
111         }
112     }
113 
114     /**
115      * @tc.name: BenchmarkTestForGetAbilityInfo
116      * @tc.desc: Testcase for testing 'GetAbilityInfo' function.
117      * @tc.type: FUNC
118      * @tc.require: Issue Number
119      */
BenchmarkTestForGetAbilityInfo(benchmark::State & state)120     static void BenchmarkTestForGetAbilityInfo(benchmark::State &state)
121     {
122         LauncherService launcherservice;
123         OHOS::AAFwk::Want want;
124         int userId = 100;
125         LauncherAbilityInfo launcherAbilityInfo;
126         for (auto _ : state) {
127             /* @tc.steps: step1.call GetAbilityInfo in loop */
128             launcherservice.GetAbilityInfo(want, userId, launcherAbilityInfo);
129         }
130     }
131 
132     /**
133      * @tc.name: BenchmarkTestForGetApplicationInfo
134      * @tc.desc: Testcase for testing 'GetApplicationInfo' function.
135      * @tc.type: FUNC
136      * @tc.require: Issue Number
137      */
BenchmarkTestForGetApplicationInfo(benchmark::State & state)138     static void BenchmarkTestForGetApplicationInfo(benchmark::State &state)
139     {
140         LauncherService launcherservice;
141         std::string bundleName = "ohos.global.systemres";
142         int userId = 100;
143         ApplicationInfo applicationInfo;
144         for (auto _ : state) {
145             /* @tc.steps: step1.call GetApplicationInfo in loop */
146             launcherservice.GetApplicationInfo(bundleName,
147                 ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, applicationInfo);
148         }
149     }
150 
151     /**
152      * @tc.name: BenchmarkTestForIsBundleEnabled
153      * @tc.desc: Testcase for testing 'IsBundleEnabled' function.
154      * @tc.type: FUNC
155      * @tc.require: Issue Number
156      */
BenchmarkTestForIsBundleEnabled(benchmark::State & state)157     static void BenchmarkTestForIsBundleEnabled(benchmark::State &state)
158     {
159         LauncherService launcherservice;
160         std::string bundleName = "ohos.global.systemres";
161         for (auto _ : state) {
162             /* @tc.steps: step1.call IsBundleEnabled in loop */
163             launcherservice.IsBundleEnabled(bundleName);
164         }
165     }
166 
167     /**
168      * @tc.name: BenchmarkTestForIsAbilityEnabled
169      * @tc.desc: Testcase for testing 'IsAbilityEnabled' function.
170      * @tc.type: FUNC
171      * @tc.require: Issue Number
172      */
BenchmarkTestForIsAbilityEnabled(benchmark::State & state)173     static void BenchmarkTestForIsAbilityEnabled(benchmark::State &state)
174     {
175         LauncherService launcherservice;
176         AbilityInfo abilityInfo;
177         for (auto _ : state) {
178             /* @tc.steps: step1.call IsAbilityEnabled in loop */
179             launcherservice.IsAbilityEnabled(abilityInfo);
180         }
181     }
182 
183     /**
184      * @tc.name: BenchmarkTestForGetShortcutInfos
185      * @tc.desc: Testcase for testing 'GetShortcutInfos' function.
186      * @tc.type: FUNC
187      * @tc.require: Issue Number
188      */
BenchmarkTestForGetShortcutInfos(benchmark::State & state)189     static void BenchmarkTestForGetShortcutInfos(benchmark::State &state)
190     {
191         LauncherService launcherservice;
192         std::string bundleName = "ohos.global.systemres";
193         std::vector<ShortcutInfo> shortcutInfo;
194         for (auto _ : state) {
195             /* @tc.steps: step1.call GetShortcutInfos in loop */
196             launcherservice.GetShortcutInfos(bundleName, shortcutInfo);
197         }
198     }
199 
200     /**
201      * @tc.name: BenchmarkTestForGetAllLauncherAbilityInfos
202      * @tc.desc: Testcase for testing 'GetAllLauncherAbilityInfos' function.
203      * @tc.type: FUNC
204      * @tc.require: Issue Number
205      */
BenchmarkTestForGetAllLauncherAbilityInfos(benchmark::State & state)206     static void BenchmarkTestForGetAllLauncherAbilityInfos(benchmark::State &state)
207     {
208         LauncherService launcherservice;
209         int32_t userId = 100;
210         std::vector<LauncherAbilityInfo> launcherAbilityInfos;
211         for (auto _ : state) {
212             /* @tc.steps: step1.call GetAllLauncherAbilityInfos in loop */
213             launcherservice.GetAllLauncherAbilityInfos(userId, launcherAbilityInfos);
214         }
215     }
216 
217     BENCHMARK(BenchmarkTestForRegisterCallback)->Iterations(1000);
218     BENCHMARK(BenchmarkTestForUnRegisterCallback)->Iterations(1000);
219     BENCHMARK(BenchmarkTestForGetAbilityList)->Iterations(1000);
220     BENCHMARK(BenchmarkTestForGetAbilityInfo)->Iterations(1000);
221     BENCHMARK(BenchmarkTestForGetApplicationInfo)->Iterations(1000);
222     BENCHMARK(BenchmarkTestForIsBundleEnabled)->Iterations(1000);
223     BENCHMARK(BenchmarkTestForIsAbilityEnabled)->Iterations(1000);
224     BENCHMARK(BenchmarkTestForGetShortcutInfos)->Iterations(1000);
225     BENCHMARK(BenchmarkTestForGetAllLauncherAbilityInfos)->Iterations(1000);
226 }
227 
228 BENCHMARK_MAIN();