1 /*
2 * Copyright (c) 2021 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 #include "mock_app_mgr_service.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26 const int32_t USER_ID = 100;
27 } // namespace
28
29 class AppMgrStubTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35
36 sptr<MockAppMgrService> mockAppMgrService_;
37
38 void WriteInterfaceToken(MessageParcel &data);
39 };
40
SetUpTestCase(void)41 void AppMgrStubTest::SetUpTestCase(void)
42 {}
43
TearDownTestCase(void)44 void AppMgrStubTest::TearDownTestCase(void)
45 {}
46
SetUp()47 void AppMgrStubTest::SetUp()
48 {
49 GTEST_LOG_(INFO) << "AppMgrStubTest::SetUp()";
50
51 mockAppMgrService_ = new MockAppMgrService();
52 }
53
TearDown()54 void AppMgrStubTest::TearDown()
55 {}
56
WriteInterfaceToken(MessageParcel & data)57 void AppMgrStubTest::WriteInterfaceToken(MessageParcel &data)
58 {
59 GTEST_LOG_(INFO) << "AppMgrStubTest::WriteInterfaceToken()";
60
61 data.WriteInterfaceToken(AppMgrStub::GetDescriptor());
62 }
63
64 /**
65 * @tc.name: AppMgrStub_GetProcessRunningInfosByUserId_0100
66 * @tc.desc: GetProcessRunningInfosByUserId
67 * @tc.type: FUNC
68 * @tc.require: SR000GH1GO
69 */
70 HWTEST_F(AppMgrStubTest, AppMgrStub_GetProcessRunningInfosByUserId_0100, TestSize.Level0)
71 {
72 GTEST_LOG_(INFO) << "AppMgrStub_GetProcessRunningInfosByUserId_0100 start";
73
74 MessageParcel data;
75 MessageParcel reply;
76 MessageOption option;
77
78 WriteInterfaceToken(data);
79 data.WriteInt32(USER_ID);
80
81 EXPECT_CALL(*mockAppMgrService_, GetProcessRunningInfosByUserId(_, _)).Times(1);
82
83 auto result = mockAppMgrService_->OnRemoteRequest(
84 static_cast<uint32_t>(IAppMgr::Message::APP_GET_RUNNING_PROCESSES_BY_USER_ID), data, reply, option);
85 EXPECT_EQ(result, NO_ERROR);
86
87 GTEST_LOG_(INFO) << "AppMgrStub_GetProcessRunningInfosByUserId_0100 end";
88 }
89 } // namespace AppExecFwk
90 } // namespace OHOS
91