• 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 "co_auth_client_test.h"
17 
18 #include "co_auth_client.h"
19 #include "iam_ptr.h"
20 #include "mock_co_auth_service.h"
21 #include "mock_executor_register_callback.h"
22 #include "mock_remote_object.h"
23 #include "mock_ipc_client_utils.h"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 using namespace testing;
29 using namespace testing::ext;
30 
SetUpTestCase()31 void CoAuthClientTest::SetUpTestCase()
32 {
33 }
34 
TearDownTestCase()35 void CoAuthClientTest::TearDownTestCase()
36 {
37 }
38 
SetUp()39 void CoAuthClientTest::SetUp()
40 {
41 }
42 
TearDown()43 void CoAuthClientTest::TearDown()
44 {
45 }
46 
47 HWTEST_F(CoAuthClientTest, CoAuthClientRegister_001, TestSize.Level0)
48 {
49     ExecutorInfo 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     auto testCallback = Common::MakeShared<MockExecutorRegisterCallback>();
60     EXPECT_NE(testCallback, nullptr);
61 
62     auto service = Common::MakeShared<MockCoAuthService>();
63     EXPECT_NE(service, nullptr);
64     EXPECT_CALL(*service, ExecutorRegister(_, _)).Times(1);
65     ON_CALL(*service, ExecutorRegister)
66         .WillByDefault(
67             [&testInfo, &testExecutorIndex](const CoAuthInterface::ExecutorRegisterInfo &info,
__anondaa13f6e0102(const CoAuthInterface::ExecutorRegisterInfo &info, sptr<ExecutorCallbackInterface> &callback) 68                 sptr<ExecutorCallbackInterface> &callback) {
69                 EXPECT_EQ(testInfo.authType, info.authType);
70                 EXPECT_EQ(testInfo.executorRole, info.executorRole);
71                 EXPECT_EQ(testInfo.executorSensorHint, info.executorSensorHint);
72                 EXPECT_EQ(testInfo.executorMatcher, info.executorMatcher);
73                 EXPECT_EQ(testInfo.esl, info.esl);
74                 EXPECT_THAT(testInfo.publicKey, ElementsAreArray(info.publicKey));
75                 return testExecutorIndex;
76             }
77         );
78 
79     sptr<MockRemoteObject> obj = new MockRemoteObject();
80     EXPECT_NE(obj, nullptr);
81     IpcClientUtils::SetObj(obj);
82     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
83     ON_CALL(*obj, SendRequest)
84         .WillByDefault(
85             [&service, testExecutorIndex](uint32_t code, MessageParcel &data, MessageParcel &reply,
__anondaa13f6e0202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 86                 MessageOption &option) {
87                 service->OnRemoteRequest(code, data, reply, option);
88                 uint64_t executorIndex = 0;
89                 EXPECT_TRUE(reply.ReadUint64(executorIndex));
90                 EXPECT_EQ(executorIndex, testExecutorIndex);
91                 return true;
92             }
93         );
94 
95     CoAuthClient::GetInstance().Register(testInfo, testCallback);
96     IpcClientUtils::ResetObj();
97 }
98 
99 HWTEST_F(CoAuthClientTest, CoAuthClientRegister_002, TestSize.Level0)
100 {
101     ExecutorInfo testInfo = {};
102     std::shared_ptr<ExecutorRegisterCallback> testCallback = nullptr;
103 
104     CoAuthClient::GetInstance().Register(testInfo, testCallback);
105 }
106 
107 HWTEST_F(CoAuthClientTest, CoAuthClientRegister_003, TestSize.Level0)
108 {
109     ExecutorInfo testInfo = {};
110     IpcClientUtils::ResetObj();
111     auto testCallback = Common::MakeShared<MockExecutorRegisterCallback>();
112     EXPECT_NE(testCallback, nullptr);
113 
114     CoAuthClient::GetInstance().Register(testInfo, testCallback);
115 }
116 } // namespace UserAuth
117 } // namespace UserIam
118 } // namespace OHOS