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 "inputer_set_data_proxy_test.h"
17
18 #include "iam_common_defines.h"
19 #include "iam_ptr.h"
20 #include "inputer_set_data_proxy.h"
21 #include "mock_inputer_data_impl.h"
22 #include "mock_remote_object.h"
23
24 namespace OHOS {
25 namespace UserIam {
26 namespace PinAuth {
27 using namespace testing;
28 using namespace testing::ext;
29
SetUpTestCase()30 void InputerSetDataProxyTest::SetUpTestCase()
31 {
32 }
33
TearDownTestCase()34 void InputerSetDataProxyTest::TearDownTestCase()
35 {
36 }
37
SetUp()38 void InputerSetDataProxyTest::SetUp()
39 {
40 }
41
TearDown()42 void InputerSetDataProxyTest::TearDown()
43 {
44 }
45
46 HWTEST_F(InputerSetDataProxyTest, InputerSetDataProxyTest, TestSize.Level0)
47 {
48 int32_t testAuthSubType = 10000;
49 std::vector<uint8_t> testData = {1, 2, 3, 4, 5, 6};
50 int32_t testErrorCode = 0;
51 uint32_t testPinLength = 0;
52 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
53 EXPECT_NE(obj, nullptr);
54 auto proxy = Common::MakeShared<InputerSetDataProxy>(obj);
55 EXPECT_NE(proxy, nullptr);
56
57 auto service = Common::MakeShared<MockInputerDataImpl>();
58 EXPECT_NE(service, nullptr);
59 EXPECT_CALL(*service, OnSetData(_, _, _, _))
60 .Times(Exactly(1))
61 .WillOnce([&testAuthSubType, &testErrorCode, &testPinLength]
__anon432017120102(int32_t authSubType, std::vector<uint8_t> data, uint32_t pinLength, int32_t errorCode) 62 (int32_t authSubType, std::vector<uint8_t> data, uint32_t pinLength, int32_t errorCode) {
63 EXPECT_EQ(authSubType, testAuthSubType);
64 EXPECT_THAT(data, ElementsAre(1, 2, 3, 4, 5, 6));
65 EXPECT_EQ(pinLength, testPinLength);
66 EXPECT_EQ(errorCode, testErrorCode);
67 return;
68 });
69 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
70 ON_CALL(*obj, SendRequest)
__anon432017120202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 71 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
72 return service->OnRemoteRequest(code, data, reply, option);
73 });
74 proxy->OnSetData(testAuthSubType, testData, testPinLength, testErrorCode);
75 }
76 } // namespace PinAuth
77 } // namespace UserIam
78 } // namespace OHOS
79