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     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
52     EXPECT_NE(obj, nullptr);
53     auto proxy = Common::MakeShared<InputerSetDataProxy>(obj);
54     EXPECT_NE(proxy, nullptr);
55 
56     auto service = Common::MakeShared<MockInputerDataImpl>();
57     EXPECT_NE(service, nullptr);
58     EXPECT_CALL(*service, OnSetData(_, _, _))
59         .Times(Exactly(1))
60         .WillOnce([&testAuthSubType, &testErrorCode]
__anona69285680102(int32_t authSubType, std::vector<uint8_t> data, int32_t errorCode) 61             (int32_t authSubType, std::vector<uint8_t> data, int32_t errorCode) {
62             EXPECT_EQ(authSubType, testAuthSubType);
63             EXPECT_THAT(data, ElementsAre(1, 2, 3, 4, 5, 6));
64             EXPECT_EQ(errorCode, testErrorCode);
65             return;
66         });
67     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
68     ON_CALL(*obj, SendRequest)
__anona69285680202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 69         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
70             return service->OnRemoteRequest(code, data, reply, option);
71         });
72     proxy->OnSetData(testAuthSubType, testData, testErrorCode);
73 }
74 } // namespace PinAuth
75 } // namespace UserIam
76 } // namespace OHOS
77