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_proxy_test.h"
17
18 #include "executor_messenger_proxy.h"
19 #include "iam_ptr.h"
20 #include "mock_remote_object.h"
21
22 namespace OHOS {
23 namespace UserIam {
24 namespace UserAuth {
25 using namespace testing;
26 using namespace testing::ext;
27
SetUpTestCase()28 void ExecutorMessengerProxyTest::SetUpTestCase()
29 {
30 }
31
TearDownTestCase()32 void ExecutorMessengerProxyTest::TearDownTestCase()
33 {
34 }
35
SetUp()36 void ExecutorMessengerProxyTest::SetUp()
37 {
38 }
39
TearDown()40 void ExecutorMessengerProxyTest::TearDown()
41 {
42 }
43
44 HWTEST_F(ExecutorMessengerProxyTest, TestSendData_001, TestSize.Level0)
45 {
46 sptr<MockRemoteObject> obj = new MockRemoteObject();
47 EXPECT_NE(obj, nullptr);
48 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
49 .WillOnce(
__anon6dab37870102(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 50 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
51 EXPECT_EQ(code, ExecutorMessengerInterface::CO_AUTH_SEND_DATA);
52 EXPECT_TRUE(reply.WriteInt32(SUCCESS));
53 return OHOS::NO_ERROR;
54 }
55 );
56
57 uint64_t scheduleId = 6598;
58 uint64_t transNum = 8784;
59 ExecutorRole srcRole = SCHEDULER;
60 ExecutorRole dstRole = COLLECTOR;
61 std::vector<uint8_t> message = {1, 2, 4, 6};
62
63 auto proxy = Common::MakeShared<ExecutorMessengerProxy>(obj);
64 EXPECT_NE(proxy, nullptr);
65 EXPECT_EQ(proxy->SendData(scheduleId, transNum, srcRole, dstRole, message), SUCCESS);
66 }
67
68 HWTEST_F(ExecutorMessengerProxyTest, TestFinish_001, TestSize.Level0)
69 {
70 uint64_t scheduleId = 6598;
71 ExecutorRole srcRole = SCHEDULER;
72 ResultCode resultCode = SUCCESS;
73 std::shared_ptr<Attributes> finalResult = nullptr;
74
75 sptr<MockRemoteObject> obj = new MockRemoteObject();
76 EXPECT_NE(obj, nullptr);
77 auto proxy = Common::MakeShared<ExecutorMessengerProxy>(obj);
78 EXPECT_NE(proxy, nullptr);
79 EXPECT_EQ(proxy->Finish(scheduleId, srcRole, resultCode, finalResult), INVALID_PARAMETERS);
80 }
81
82 HWTEST_F(ExecutorMessengerProxyTest, TestFinish_002, TestSize.Level0)
83 {
84 sptr<MockRemoteObject> obj = new MockRemoteObject();
85 EXPECT_NE(obj, nullptr);
86 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
87 .WillOnce(
__anon6dab37870202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 88 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
89 EXPECT_EQ(code, ExecutorMessengerInterface::CO_AUTH_FINISH);
90 EXPECT_TRUE(reply.WriteInt32(SUCCESS));
91 return OHOS::NO_ERROR;
92 }
93 );
94
95 uint64_t scheduleId = 6598;
96 ExecutorRole srcRole = SCHEDULER;
97 ResultCode resultCode = SUCCESS;
98 std::shared_ptr<Attributes> finalResult = Common::MakeShared<Attributes>();
99 EXPECT_NE(finalResult, nullptr);
100
101 auto proxy = Common::MakeShared<ExecutorMessengerProxy>(obj);
102 EXPECT_NE(proxy, nullptr);
103 EXPECT_EQ(proxy->Finish(scheduleId, srcRole, resultCode, finalResult), SUCCESS);
104 }
105 } // namespace UserAuth
106 } // namespace UserIam
107 } // namespace OHOS
108