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_auth_callback_stub_test.h"
17
18 #include "message_parcel.h"
19
20 #include "iam_ptr.h"
21 #include "mock_user_auth_callback_service.h"
22 #include "user_auth_interface.h"
23
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
27 using namespace testing;
28 using namespace testing::ext;
29
SetUpTestCase()30 void UserAuthCallbackStubTest::SetUpTestCase()
31 {
32 }
33
TearDownTestCase()34 void UserAuthCallbackStubTest::TearDownTestCase()
35 {
36 }
37
SetUp()38 void UserAuthCallbackStubTest::SetUp()
39 {
40 }
41
TearDown()42 void UserAuthCallbackStubTest::TearDown()
43 {
44 }
45
46 HWTEST_F(UserAuthCallbackStubTest, TestOnResultStub_001, TestSize.Level0)
47 {
48 int32_t result = 0;
49 std::vector<uint8_t> extraInfo = {1, 2, 3, 4};
50
51 MessageParcel data;
52 MessageParcel reply;
53 MessageOption option(MessageOption::TF_SYNC);
54 uint32_t code = UserAuthInterface::USER_AUTH_ON_RESULT;
55
56 EXPECT_TRUE(data.WriteInterfaceToken(UserAuthCallbackInterface::GetDescriptor()));
57 EXPECT_TRUE(data.WriteInt32(result));
58 EXPECT_TRUE(data.WriteUInt8Vector(extraInfo));
59
60 auto service = Common::MakeShared<MockUserAuthCallbackService>();
61 EXPECT_NE(service, nullptr);
62 EXPECT_CALL(*service, OnResult(_, _)).Times(1);
63
64 EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
65 }
66
67 HWTEST_F(UserAuthCallbackStubTest, TestOnAcquireInfoStub_001, TestSize.Level0)
68 {
69 int32_t module = 10;
70 int32_t acquireInfo = 20;
71 std::vector<uint8_t> extraInfo = {1, 2, 3, 4};
72
73 MessageParcel data;
74 MessageParcel reply;
75 MessageOption option(MessageOption::TF_SYNC);
76 uint32_t code = UserAuthInterface::USER_AUTH_ACQUIRE_INFO;
77
78 EXPECT_TRUE(data.WriteInterfaceToken(UserAuthCallbackInterface::GetDescriptor()));
79 EXPECT_TRUE(data.WriteInt32(module));
80 EXPECT_TRUE(data.WriteInt32(acquireInfo));
81 EXPECT_TRUE(data.WriteUInt8Vector(extraInfo));
82
83 auto service = Common::MakeShared<MockUserAuthCallbackService>();
84 EXPECT_NE(service, nullptr);
85 EXPECT_CALL(*service, OnAcquireInfo(_, _, _)).Times(1);
86
87 EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
88 }
89
90 HWTEST_F(UserAuthCallbackStubTest, TestOnGetExecutorPropertyResultStub_001, TestSize.Level0)
91 {
92 int32_t result = 0;
93 std::vector<uint8_t> extraInfo = {1, 2, 3, 4};
94
95 MessageParcel data;
96 MessageParcel reply;
97 MessageOption option(MessageOption::TF_SYNC);
98 uint32_t code = UserAuthInterface::USER_AUTH_GET_EX_PROP;
99
100 EXPECT_TRUE(data.WriteInterfaceToken(GetExecutorPropertyCallbackInterface::GetDescriptor()));
101 EXPECT_TRUE(data.WriteInt32(result));
102 EXPECT_TRUE(data.WriteUInt8Vector(extraInfo));
103
104 auto service = Common::MakeShared<MockGetExecutorPropertyCallbackService>();
105 EXPECT_NE(service, nullptr);
106 EXPECT_CALL(*service, OnGetExecutorPropertyResult(_, _)).Times(1);
107
108 EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
109 }
110
111 HWTEST_F(UserAuthCallbackStubTest, TestOnSetExecutorPropertyResultStub_001, TestSize.Level0)
112 {
113 int32_t result = 0;
114
115 MessageParcel data;
116 MessageParcel reply;
117 MessageOption option(MessageOption::TF_SYNC);
118 uint32_t code = UserAuthInterface::USER_AUTH_SET_EX_PROP;
119
120 EXPECT_TRUE(data.WriteInterfaceToken(SetExecutorPropertyCallbackInterface::GetDescriptor()));
121 EXPECT_TRUE(data.WriteInt32(result));
122
123 auto service = Common::MakeShared<MockSetExecutorPropertyCallbackService>();
124 EXPECT_NE(service, nullptr);
125 EXPECT_CALL(*service, OnSetExecutorPropertyResult(_)).Times(1);
126
127 EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
128 }
129 } // namespace UserAuth
130 } // namespace UserIam
131 } // namespace OHOS
132