• 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 (std::nothrow) 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: BenchmarkTestForGetShortcutInfos
116      * @tc.desc: Testcase for testing 'GetShortcutInfos' function.
117      * @tc.type: FUNC
118      * @tc.require: Issue Number
119      */
BenchmarkTestForGetShortcutInfos(benchmark::State & state)120     static void BenchmarkTestForGetShortcutInfos(benchmark::State &state)
121     {
122         LauncherService launcherservice;
123         std::string bundleName = "ohos.global.systemres";
124         std::vector<ShortcutInfo> shortcutInfo;
125         for (auto _ : state) {
126             /* @tc.steps: step1.call GetShortcutInfos in loop */
127             launcherservice.GetShortcutInfos(bundleName, shortcutInfo);
128         }
129     }
130 
131     /**
132      * @tc.name: BenchmarkTestForGetAllLauncherAbilityInfos
133      * @tc.desc: Testcase for testing 'GetAllLauncherAbilityInfos' function.
134      * @tc.type: FUNC
135      * @tc.require: Issue Number
136      */
BenchmarkTestForGetAllLauncherAbilityInfos(benchmark::State & state)137     static void BenchmarkTestForGetAllLauncherAbilityInfos(benchmark::State &state)
138     {
139         LauncherService launcherservice;
140         int32_t userId = 100;
141         std::vector<LauncherAbilityInfo> launcherAbilityInfos;
142         for (auto _ : state) {
143             /* @tc.steps: step1.call GetAllLauncherAbilityInfos in loop */
144             launcherservice.GetAllLauncherAbilityInfos(userId, launcherAbilityInfos);
145         }
146     }
147 
148     BENCHMARK(BenchmarkTestForRegisterCallback)->Iterations(1000);
149     BENCHMARK(BenchmarkTestForUnRegisterCallback)->Iterations(1000);
150     BENCHMARK(BenchmarkTestForGetAbilityList)->Iterations(1000);
151     BENCHMARK(BenchmarkTestForGetShortcutInfos)->Iterations(1000);
152     BENCHMARK(BenchmarkTestForGetAllLauncherAbilityInfos)->Iterations(1000);
153 }
154 
155 BENCHMARK_MAIN();