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 "co_auth_proxy_test.h"
17
18 #include "iam_ptr.h"
19 #include "co_auth_proxy.h"
20 #include "executor_callback_service.h"
21 #include "mock_remote_object.h"
22 #include "mock_co_auth_service.h"
23 #include "mock_executor_register_callback.h"
24
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 using namespace testing;
29 using namespace testing::ext;
30
SetUpTestCase()31 void CoAuthProxyTest::SetUpTestCase()
32 {
33 }
34
TearDownTestCase()35 void CoAuthProxyTest::TearDownTestCase()
36 {
37 }
38
SetUp()39 void CoAuthProxyTest::SetUp()
40 {
41 }
42
TearDown()43 void CoAuthProxyTest::TearDown()
44 {
45 }
46
47 HWTEST_F(CoAuthProxyTest, CoAuthProxyExecutorRegister, TestSize.Level0)
48 {
49 CoAuthInterface::ExecutorRegisterInfo testInfo = {};
50 testInfo.authType = PIN;
51 testInfo.executorRole = COLLECTOR;
52 testInfo.executorSensorHint = 11;
53 testInfo.executorMatcher = 22;
54 testInfo.esl = ESL1;
55 testInfo.publicKey = {1, 2, 3, 4};
56
57 uint64_t testExecutorIndex = 73265;
58
59 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
60 EXPECT_NE(obj, nullptr);
61 auto proxy = Common::MakeShared<CoAuthProxy>(obj);
62 EXPECT_NE(proxy, nullptr);
63 auto executorCallback = Common::MakeShared<MockExecutorRegisterCallback>();
64 sptr<ExecutorCallbackInterface> testCallback(new (std::nothrow) ExecutorCallbackService(executorCallback));
65 auto service = Common::MakeShared<MockCoAuthService>();
66 EXPECT_NE(service, nullptr);
67 EXPECT_CALL(*service, ExecutorRegister(_, _))
68 .Times(Exactly(1))
69 .WillOnce(
70 [&testInfo, &testExecutorIndex](const CoAuthInterface::ExecutorRegisterInfo &info,
__anon49e51fa90102(const CoAuthInterface::ExecutorRegisterInfo &info, sptr<ExecutorCallbackInterface> &callback) 71 sptr<ExecutorCallbackInterface> &callback) {
72 EXPECT_EQ(testInfo.authType, info.authType);
73 EXPECT_EQ(testInfo.executorRole, info.executorRole);
74 EXPECT_EQ(testInfo.executorSensorHint, info.executorSensorHint);
75 EXPECT_EQ(testInfo.executorMatcher, info.executorMatcher);
76 EXPECT_EQ(testInfo.esl, info.esl);
77 EXPECT_THAT(testInfo.publicKey, ElementsAreArray(info.publicKey));
78 return testExecutorIndex;
79 });
80 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
81 ON_CALL(*obj, SendRequest)
__anon49e51fa90202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 82 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
83 service->OnRemoteRequest(code, data, reply, option);
84 return OHOS::NO_ERROR;
85 });
86 proxy->ExecutorRegister(testInfo, testCallback);
87 }
88 } // namespace UserAuth
89 } // namespace UserIam
90 } // namespace OHOS