1 /*
2 * Copyright (c) 2022-2024 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 InputerGetDataParam testParam = {
49 .mode = GET_DATA_MODE_ALL_IN_ONE_PIN_AUTH,
50 .authSubType = 10000,
51 .algoVersion = 0,
52 .algoParameter = {1, 2, 3, 4, 5, 6},
53 .challenge = {2, 3, 4, 5, 6, 7},
54 .inputerSetData = new (std::nothrow) MockInputerSetData(),
55 };
56
57 ASSERT_NE(testParam.inputerSetData, nullptr);
58 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
59 EXPECT_NE(obj, nullptr);
60 auto proxy = Common::MakeShared<InputerGetDataProxy>(obj);
61 EXPECT_NE(proxy, nullptr);
62
63 auto service = Common::MakeShared<MockInputerGetDataService>();
64 EXPECT_NE(service, nullptr);
65 EXPECT_CALL(*service, OnGetData(_))
66 .Times(Exactly(1))
__anon440f145c0102(const InputerGetDataParam &getDataParam) 67 .WillOnce([&testParam](const InputerGetDataParam &getDataParam) {
68 EXPECT_EQ(getDataParam.mode, testParam.mode);
69 EXPECT_EQ(getDataParam.authSubType, testParam.authSubType);
70 EXPECT_EQ(getDataParam.algoVersion, testParam.algoVersion);
71 EXPECT_THAT(getDataParam.algoParameter, ElementsAre(1, 2, 3, 4, 5, 6));
72 EXPECT_THAT(getDataParam.challenge, ElementsAre(2, 3, 4, 5, 6, 7));
73 return;
74 });
75 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
76 ON_CALL(*obj, SendRequest)
__anon440f145c0202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 77 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
78 return service->OnRemoteRequest(code, data, reply, option);
79 });
80 proxy->OnGetData(testParam);
81 }
82
83 HWTEST_F(InputerGetDataProxyTest, InputerGetDataProxyTest002, TestSize.Level0)
84 {
85 InputerGetDataParam testParam = {
86 .mode = GET_DATA_MODE_ALL_IN_ONE_PIN_AUTH,
87 .authSubType = 10000,
88 .algoVersion = 0,
89 .algoParameter = {1, 2, 3, 4, 5, 6},
90 .challenge = {2, 3, 4, 5, 6, 7},
91 .inputerSetData = new (std::nothrow) MockInputerSetData(),
92 };
93
94 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
95 ASSERT_NE(obj, nullptr);
96 auto proxy = Common::MakeShared<InputerGetDataProxy>(obj);
97 ASSERT_NE(proxy, nullptr);
98
99 proxy->OnGetData(testParam);
100 }
101
102 HWTEST_F(InputerGetDataProxyTest, OnGetDataTest001, TestSize.Level0)
103 {
104 InputerGetDataParam testParam = {
105 .mode = GET_DATA_MODE_ALL_IN_ONE_PIN_AUTH,
106 .authSubType = 10000,
107 .algoVersion = 0,
108 .algoParameter = {1, 2, 3, 4, 5, 6},
109 .challenge = {2, 3, 4, 5, 6, 7},
110 .inputerSetData = nullptr,
111 };
112
113 auto service = Common::MakeShared<MockInputerGetDataService>();
114 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
115 ON_CALL(*obj, SendRequest)
__anon440f145c0302(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 116 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
117 return 100;
118 });
119 auto proxy = Common::MakeShared<InputerGetDataProxy>(obj);
120 ASSERT_NE(proxy, nullptr);
121
122 EXPECT_NO_THROW(proxy->OnGetData(testParam));
123 }
124 } // namespace PinAuth
125 } // namespace UserIam
126 } // namespace OHOS
127