• 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 <gtest/gtest.h>
17 
18 #define private public
19 #include "app_mgr_service.h"
20 #undef private
21 #include "hilog_wrapper.h"
22 #include "mock_native_token.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 namespace {
30 const int32_t USER_ID = 100;
31 }  // namespace
32 
33 class AppMgrServiceDumpTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 };
40 
SetUpTestCase(void)41 void AppMgrServiceDumpTest::SetUpTestCase(void)
42 {
43     MockNativeToken::SetNativeToken();
44 }
45 
TearDownTestCase(void)46 void AppMgrServiceDumpTest::TearDownTestCase(void)
47 {}
48 
SetUp()49 void AppMgrServiceDumpTest::SetUp()
50 {}
51 
TearDown()52 void AppMgrServiceDumpTest::TearDown()
53 {}
54 
55 /**
56  * @tc.name: AppMgrServiceDump_GetProcessRunningInfosByUserId_0100
57  * @tc.desc: GetProcessRunningInfosByUserId
58  * @tc.type: FUNC
59  * @tc.require: SR000GH1GO
60  */
61 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_GetProcessRunningInfosByUserId_0100, TestSize.Level1)
62 {
63     HILOG_INFO("AppMgrServiceDump_GetProcessRunningInfosByUserId_0100 start");
64 
65     auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
66     EXPECT_NE(appMgrServiceInner, nullptr);
67 
68     std::vector<RunningProcessInfo> info;
69     auto result = appMgrServiceInner->GetProcessRunningInfosByUserId(info, USER_ID);
70     EXPECT_EQ(result, ERR_OK);
71 
72     HILOG_INFO("AppMgrServiceDump_GetProcessRunningInfosByUserId_0100 end");
73 }
74 
75 /**
76  * @tc.name: AppMgrServiceDump_GetProcessRunningInfosByUserId_0200
77  * @tc.desc: GetProcessRunningInfosByUserId
78  * @tc.type: FUNC
79  * @tc.require: SR000GH1GO
80  */
81 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_GetProcessRunningInfosByUserId_0200, TestSize.Level1)
82 {
83     HILOG_INFO("AppMgrServiceDump_GetProcessRunningInfosByUserId_0200 start");
84 
85     auto appMgrService = std::make_shared<AppMgrService>();
86     EXPECT_NE(appMgrService, nullptr);
87 
88     appMgrService->handler_ = std::make_shared<AMSEventHandler>(
89         EventRunner::Create("AppMgrServiceDumpTest"), appMgrService->appMgrServiceInner_);
90 
91     std::vector<RunningProcessInfo> info;
92     auto result = appMgrService->GetProcessRunningInfosByUserId(info, USER_ID);
93     EXPECT_EQ(result, ERR_OK);
94 
95     HILOG_INFO("AppMgrServiceDump_GetProcessRunningInfosByUserId_0200 end");
96 }
97 
98 /*
99  * @tc.number    : AppMgrServiceDump_0100
100  * @tc.name      : AppMgrService dump
101  * @tc.desc      : 1.Test dump interface
102  */
103 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0100, TestSize.Level1)
104 {
105     HILOG_INFO("AppMgrServiceDump_0100 start");
106 
107     auto appMgrService = std::make_shared<AppMgrService>();
108     EXPECT_NE(appMgrService, nullptr);
109     auto runner = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME);
110     EXPECT_NE(runner, nullptr);
111     appMgrService->handler_ = std::make_shared<AMSEventHandler>(runner, appMgrService->appMgrServiceInner_);
112 
113     constexpr int fd(0);
114     std::vector<std::u16string> args;
115     auto arg = Str8ToStr16("-h");
116     args.emplace_back(arg);
117     auto result = appMgrService->Dump(fd, args);
118     EXPECT_EQ(result, ERR_OK);
119 
120     HILOG_INFO("AppMgrServiceDump_0100 end");
121 }
122 
123 /*
124  * @tc.number    : AppMgrServiceDump_0200
125  * @tc.name      : AppMgrService dump
126  * @tc.desc      : 1.Test dump interface
127  */
128 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0200, TestSize.Level1)
129 {
130     HILOG_INFO("AppMgrServiceDump_0200 start");
131 
132     auto appMgrService = std::make_shared<AppMgrService>();
133     EXPECT_NE(appMgrService, nullptr);
134 
135     constexpr int fd(0);
136     std::vector<std::u16string> args;
137     auto arg = Str8ToStr16("-h");
138     args.emplace_back(arg);
139     auto result = appMgrService->Dump(fd, args);
140     EXPECT_EQ(result, ERR_APPEXECFWK_HIDUMP_ERROR);
141 
142     HILOG_INFO("AppMgrServiceDump_0200 end");
143 }
144 
145 /*
146  * @tc.number    : AppMgrServiceDump_0300
147  * @tc.name      : AppMgrService dump
148  * @tc.desc      : 1.Test dump interface
149  */
150 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0300, TestSize.Level1)
151 {
152     HILOG_INFO("AppMgrServiceDump_0300 start");
153 
154     auto appMgrService = std::make_shared<AppMgrService>();
155     EXPECT_NE(appMgrService, nullptr);
156     auto runner = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME);
157     EXPECT_NE(runner, nullptr);
158     appMgrService->handler_ = std::make_shared<AMSEventHandler>(runner, appMgrService->appMgrServiceInner_);
159 
160     constexpr int fd(0);
161     std::vector<std::u16string> args;
162     auto result = appMgrService->Dump(fd, args);
163     EXPECT_EQ(result, ERR_OK);
164 
165     HILOG_INFO("AppMgrServiceDump_0300 end");
166 }
167 
168 /*
169  * @tc.number    : AppMgrServiceDump_0400
170  * @tc.name      : AppMgrService dump
171  * @tc.desc      : 1.Test dump interface
172  */
173 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0400, TestSize.Level1)
174 {
175     HILOG_INFO("AppMgrServiceDump_0400 start");
176 
177     auto appMgrService = std::make_shared<AppMgrService>();
178     EXPECT_NE(appMgrService, nullptr);
179     auto runner = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME);
180     EXPECT_NE(runner, nullptr);
181     appMgrService->handler_ = std::make_shared<AMSEventHandler>(runner, appMgrService->appMgrServiceInner_);
182 
183     constexpr int fd(0);
184     std::vector<std::u16string> args;
185     auto arg = Str8ToStr16("-i");
186     args.emplace_back(arg);
187     auto result = appMgrService->Dump(fd, args);
188     EXPECT_EQ(result, ERR_OK);
189 
190     HILOG_INFO("AppMgrServiceDump_0400 end");
191 }
192 }  // namespace AppExecFwk
193 }  // namespace OHOS
194