• 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 "user_idm_callback_stub_test.h"
17 
18 #include "message_parcel.h"
19 
20 #include "iam_ptr.h"
21 #include "mock_user_idm_callback_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 UserIdmCallbackStubTest::SetUpTestCase()
30 {
31 }
32 
TearDownTestCase()33 void UserIdmCallbackStubTest::TearDownTestCase()
34 {
35 }
36 
SetUp()37 void UserIdmCallbackStubTest::SetUp()
38 {
39 }
40 
TearDown()41 void UserIdmCallbackStubTest::TearDown()
42 {
43 }
44 
45 HWTEST_F(UserIdmCallbackStubTest, TestOnResultStub_001, TestSize.Level0)
46 {
47     int32_t result = 0;
48     std::vector<uint8_t> extraInfo = {1, 2, 3, 4};
49 
50     MessageParcel data;
51     MessageParcel reply;
52     MessageOption option(MessageOption::TF_SYNC);
53     uint32_t code = IdmCallbackInterface::IDM_CALLBACK_ON_RESULT;
54 
55     EXPECT_TRUE(data.WriteInterfaceToken(IdmCallbackInterface::GetDescriptor()));
56     EXPECT_TRUE(data.WriteInt32(result));
57     EXPECT_TRUE(data.WriteUInt8Vector(extraInfo));
58 
59     auto service = Common::MakeShared<MockIdmCallbackService>();
60     EXPECT_NE(service, nullptr);
61     EXPECT_CALL(*service, OnResult(_, _)).Times(1);
62 
63     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
64 }
65 
66 HWTEST_F(UserIdmCallbackStubTest, TestOnAcquireInfoStub_001, TestSize.Level0)
67 {
68     int32_t module = 10;
69     int32_t acquireInfo = 20;
70     std::vector<uint8_t> extraInfo = {1, 2, 3, 4};
71 
72     MessageParcel data;
73     MessageParcel reply;
74     MessageOption option(MessageOption::TF_SYNC);
75     uint32_t code = IdmCallbackInterface::IDM_CALLBACK_ON_ACQUIRE_INFO;
76 
77     EXPECT_TRUE(data.WriteInterfaceToken(IdmCallbackInterface::GetDescriptor()));
78     EXPECT_TRUE(data.WriteInt32(module));
79     EXPECT_TRUE(data.WriteInt32(acquireInfo));
80     EXPECT_TRUE(data.WriteUInt8Vector(extraInfo));
81 
82     auto service = Common::MakeShared<MockIdmCallbackService>();
83     EXPECT_NE(service, nullptr);
84     EXPECT_CALL(*service, OnAcquireInfo(_, _, _)).Times(1);
85 
86     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
87 }
88 
89 HWTEST_F(UserIdmCallbackStubTest, TestOnCredentialInfosStub_001, TestSize.Level0)
90 {
91     uint32_t infoSize = 1;
92     uint64_t credentialId = 10;
93     AuthType authType = FACE;
94     PinSubType subType = PIN_SIX;
95     uint64_t templateId = 20;
96 
97     MessageParcel data;
98     MessageParcel reply;
99     MessageOption option(MessageOption::TF_SYNC);
100     uint32_t code = IdmGetCredInfoCallbackInterface::ON_GET_INFO;
101 
102     EXPECT_TRUE(data.WriteInterfaceToken(IdmGetCredInfoCallbackInterface::GetDescriptor()));
103     EXPECT_TRUE(data.WriteUint32(infoSize));
104     EXPECT_TRUE(data.WriteUint64(credentialId));
105     EXPECT_TRUE(data.WriteInt32(authType));
106     EXPECT_TRUE(data.WriteInt32(subType));
107     EXPECT_TRUE(data.WriteUint64(templateId));
108 
109     auto service = Common::MakeShared<MockIdmGetCredInfoCallbackService>();
110     EXPECT_NE(service, nullptr);
111     EXPECT_CALL(*service, OnCredentialInfos(_, _)).Times(1);
112 
113     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
114 }
115 
116 HWTEST_F(UserIdmCallbackStubTest, TestOnSecureUserInfoStub_001, TestSize.Level0)
117 {
118     uint64_t secUid = 10;
119     uint32_t infoSize = 1;
120 
121     MessageParcel data;
122     MessageParcel reply;
123     MessageOption option(MessageOption::TF_SYNC);
124     uint32_t code = IdmGetSecureUserInfoCallbackInterface::ON_GET_SEC_INFO;
125 
126     EXPECT_TRUE(data.WriteInterfaceToken(IdmGetSecureUserInfoCallbackInterface::GetDescriptor()));
127     EXPECT_TRUE(data.WriteUint64(secUid));
128     EXPECT_TRUE(data.WriteUint32(infoSize));
129 
130     auto service = Common::MakeShared<MockIdmGetSecureUserInfoCallbackService>();
131     EXPECT_NE(service, nullptr);
132     EXPECT_CALL(*service, OnSecureUserInfo(_)).Times(1);
133 
134     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
135 }
136 } // namespace UserAuth
137 } // namespace UserIam
138 } // namespace OHOS
139