• 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 "inputer_get_data_proxy_test.h"
17 
18 #include "iam_ptr.h"
19 #include "inputer_get_data_proxy.h"
20 #include "mock_inputer_get_data_service.h"
21 #include "mock_inputer_set_data.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 InputerGetDataProxyTest::SetUpTestCase()
31 {
32 }
33 
TearDownTestCase()34 void InputerGetDataProxyTest::TearDownTestCase()
35 {
36 }
37 
SetUp()38 void InputerGetDataProxyTest::SetUp()
39 {
40 }
41 
TearDown()42 void InputerGetDataProxyTest::TearDown()
43 {
44 }
45 
46 HWTEST_F(InputerGetDataProxyTest, InputerGetDataProxyTest001, TestSize.Level0)
47 {
48     int32_t testAuthSubType = 10000;
49     std::vector<uint8_t> testSalt = {1, 2, 3, 4, 5, 6};
50     sptr<InputerSetData> testInputerSetData(new (std::nothrow) MockInputerSetData());
51     EXPECT_NE(testInputerSetData, nullptr);
52     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
53     EXPECT_NE(obj, nullptr);
54     auto proxy = Common::MakeShared<InputerGetDataProxy>(obj);
55     EXPECT_NE(proxy, nullptr);
56 
57     auto service = Common::MakeShared<MockInputerGetDataService>();
58     EXPECT_NE(service, nullptr);
59     EXPECT_CALL(*service, OnGetData(_, _, _))
60         .Times(Exactly(1))
61         .WillOnce([&testAuthSubType, &testInputerSetData](int32_t authSubType, const std::vector<uint8_t> &salt,
__anon1dc4c9840102(int32_t authSubType, const std::vector<uint8_t> &salt, const sptr<InputerSetData> &inputerSetData) 62             const sptr<InputerSetData> &inputerSetData) {
63             EXPECT_EQ(authSubType, testAuthSubType);
64             EXPECT_EQ(inputerSetData, testInputerSetData);
65             EXPECT_THAT(salt, ElementsAre(1, 2, 3, 4, 5, 6));
66             return;
67         });
68     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
69     ON_CALL(*obj, SendRequest)
__anon1dc4c9840202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 70         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
71             return service->OnRemoteRequest(code, data, reply, option);
72         });
73     proxy->OnGetData(testAuthSubType, testSalt, testInputerSetData);
74 }
75 
76 HWTEST_F(InputerGetDataProxyTest, InputerGetDataProxyTest002, TestSize.Level0)
77 {
78     int32_t testAuthSubType = 10000;
79     std::vector<uint8_t> testSalt = {1, 2, 3, 4, 5, 6};
80     sptr<InputerSetData> testInputerSetData(nullptr);
81     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
82     EXPECT_NE(obj, nullptr);
83     auto proxy = Common::MakeShared<InputerGetDataProxy>(obj);
84     EXPECT_NE(proxy, nullptr);
85 
86     proxy->OnGetData(testAuthSubType, testSalt, testInputerSetData);
87 }
88 } // namespace PinAuth
89 } // namespace UserIam
90 } // namespace OHOS
91