• 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 "executor_messenger_stub_test.h"
17 
18 #include "message_parcel.h"
19 
20 #include "iam_ptr.h"
21 #include "mock_executor_messenger_service.h"
22 
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
26 using namespace testing;
27 using namespace testing::ext;
28 
SetUpTestCase()29 void ExecutorMessengerStubTest::SetUpTestCase()
30 {
31 }
32 
TearDownTestCase()33 void ExecutorMessengerStubTest::TearDownTestCase()
34 {
35 }
36 
SetUp()37 void ExecutorMessengerStubTest::SetUp()
38 {
39 }
40 
TearDown()41 void ExecutorMessengerStubTest::TearDown()
42 {
43 }
44 
45 HWTEST_F(ExecutorMessengerStubTest, TestSendDataStub_001, TestSize.Level0)
46 {
47     uint64_t scheduleId = 6598;
48     uint64_t transNum = 8784;
49     ExecutorRole srcRole = SCHEDULER;
50     ExecutorRole dstRole = COLLECTOR;
51     std::vector<uint8_t> message = {1, 2, 4, 6};
52 
53     MessageParcel data;
54     MessageParcel reply;
55     MessageOption option(MessageOption::TF_SYNC);
56     uint32_t code = ExecutorMessengerInterface::CO_AUTH_SEND_DATA;
57 
58     EXPECT_TRUE(data.WriteInterfaceToken(ExecutorMessengerInterface::GetDescriptor()));
59     EXPECT_TRUE(data.WriteUint64(scheduleId));
60     EXPECT_TRUE(data.WriteUint64(transNum));
61     EXPECT_TRUE(data.WriteInt32(srcRole));
62     EXPECT_TRUE(data.WriteInt32(dstRole));
63     EXPECT_TRUE(data.WriteUInt8Vector(message));
64 
65     auto service = Common::MakeShared<MockExecutorMessengerService>();
66     EXPECT_NE(service, nullptr);
67     EXPECT_CALL(*service, SendData(_, _, _, _, _)).Times(1);
68 
69     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
70 }
71 
72 HWTEST_F(ExecutorMessengerStubTest, TestFinishStub_001, TestSize.Level0)
73 {
74     uint64_t scheduleId = 6598;
75     ExecutorRole srcRole = SCHEDULER;
76     ResultCode resultCode = SUCCESS;
77     std::vector<uint8_t> finalResult = {1, 2, 4, 6};
78 
79     MessageParcel data;
80     MessageParcel reply;
81     MessageOption option(MessageOption::TF_SYNC);
82     uint32_t code = ExecutorMessengerInterface::CO_AUTH_FINISH;
83 
84     EXPECT_TRUE(data.WriteInterfaceToken(ExecutorMessengerInterface::GetDescriptor()));
85     EXPECT_TRUE(data.WriteUint64(scheduleId));
86     EXPECT_TRUE(data.WriteInt32(srcRole));
87     EXPECT_TRUE(data.WriteInt32(resultCode));
88     EXPECT_TRUE(data.WriteUInt8Vector(finalResult));
89 
90     auto service = Common::MakeShared<MockExecutorMessengerService>();
91     EXPECT_NE(service, nullptr);
92     EXPECT_CALL(*service, Finish(_, _, _, _)).Times(1);
93 
94     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
95 }
96 } // namespace UserAuth
97 } // namespace UserIam
98 } // namespace OHOS
99