• 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->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME);
89     appMgrService->eventHandler_ = std::make_shared<AMSEventHandler>(
90         appMgrService->taskHandler_, appMgrService->appMgrServiceInner_);
91 
92     std::vector<RunningProcessInfo> info;
93     auto result = appMgrService->GetProcessRunningInfosByUserId(info, USER_ID);
94     EXPECT_EQ(result, ERR_OK);
95 
96     HILOG_INFO("AppMgrServiceDump_GetProcessRunningInfosByUserId_0200 end");
97 }
98 
99 /*
100  * @tc.number    : AppMgrServiceDump_0100
101  * @tc.name      : AppMgrService dump
102  * @tc.desc      : 1.Test dump interface
103  */
104 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0100, TestSize.Level1)
105 {
106     HILOG_INFO("AppMgrServiceDump_0100 start");
107 
108     auto appMgrService = std::make_shared<AppMgrService>();
109     EXPECT_NE(appMgrService, nullptr);
110     appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME);
111     EXPECT_NE(appMgrService->taskHandler_, nullptr);
112     appMgrService->eventHandler_ = std::make_shared<AMSEventHandler>(
113         appMgrService->taskHandler_, appMgrService->appMgrServiceInner_);
114 
115     constexpr int fd(1);
116     std::vector<std::u16string> args;
117     auto arg = Str8ToStr16("-h");
118     args.emplace_back(arg);
119     auto result = appMgrService->Dump(fd, args);
120     EXPECT_EQ(result, ERR_OK);
121 
122     HILOG_INFO("AppMgrServiceDump_0100 end");
123 }
124 
125 /*
126  * @tc.number    : AppMgrServiceDump_0200
127  * @tc.name      : AppMgrService dump
128  * @tc.desc      : 1.Test dump interface
129  */
130 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0200, TestSize.Level1)
131 {
132     HILOG_INFO("AppMgrServiceDump_0200 start");
133 
134     auto appMgrService = std::make_shared<AppMgrService>();
135     EXPECT_NE(appMgrService, nullptr);
136 
137     constexpr int fd(0);
138     std::vector<std::u16string> args;
139     auto arg = Str8ToStr16("-h");
140     args.emplace_back(arg);
141     auto result = appMgrService->Dump(fd, args);
142     EXPECT_EQ(result, ERR_APPEXECFWK_HIDUMP_ERROR);
143 
144     HILOG_INFO("AppMgrServiceDump_0200 end");
145 }
146 
147 /*
148  * @tc.number    : AppMgrServiceDump_0300
149  * @tc.name      : AppMgrService dump
150  * @tc.desc      : 1.Test dump interface
151  */
152 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0300, TestSize.Level1)
153 {
154     HILOG_INFO("AppMgrServiceDump_0300 start");
155 
156     auto appMgrService = std::make_shared<AppMgrService>();
157     EXPECT_NE(appMgrService, nullptr);
158     appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME);
159     EXPECT_NE(appMgrService->taskHandler_, nullptr);
160     appMgrService->eventHandler_ = std::make_shared<AMSEventHandler>(
161         appMgrService->taskHandler_, appMgrService->appMgrServiceInner_);
162 
163     constexpr int fd(1);
164     std::vector<std::u16string> args;
165     auto result = appMgrService->Dump(fd, args);
166     EXPECT_EQ(result, ERR_OK);
167 
168     HILOG_INFO("AppMgrServiceDump_0300 end");
169 }
170 
171 /*
172  * @tc.number    : AppMgrServiceDump_0400
173  * @tc.name      : AppMgrService dump
174  * @tc.desc      : 1.Test dump interface
175  */
176 HWTEST_F(AppMgrServiceDumpTest, AppMgrServiceDump_0400, TestSize.Level1)
177 {
178     HILOG_INFO("AppMgrServiceDump_0400 start");
179 
180     auto appMgrService = std::make_shared<AppMgrService>();
181     EXPECT_NE(appMgrService, nullptr);
182     appMgrService->taskHandler_ = AAFwk::TaskHandlerWrap::CreateQueueHandler(Constants::APP_MGR_SERVICE_NAME);
183     EXPECT_NE(appMgrService->taskHandler_, nullptr);
184     appMgrService->eventHandler_ = std::make_shared<AMSEventHandler>(
185         appMgrService->taskHandler_, appMgrService->appMgrServiceInner_);
186 
187     constexpr int fd(1);
188     std::vector<std::u16string> args;
189     auto arg = Str8ToStr16("-i");
190     args.emplace_back(arg);
191     auto result = appMgrService->Dump(fd, args);
192     EXPECT_EQ(result, ERR_OK);
193 
194     HILOG_INFO("AppMgrServiceDump_0400 end");
195 }
196 }  // namespace AppExecFwk
197 }  // namespace OHOS
198