1 /*
2 * Copyright (c) 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 #include <gtest/gtest.h>
16 #include <thread>
17 #include <hdf_log.h>
18
19 #include "nfc_impl.h"
20 #include "mock.h"
21
22 namespace OHOS {
23 namespace HDI {
24 namespace Nfc {
25 namespace V1_1 {
26 namespace TEST {
27 using namespace testing;
28 using namespace testing::ext;
29 using namespace OHOS::HDI::Nfc;
30 class NfcImplTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp();
35 void TearDown();
36 };
37
SetUpTestCase()38 void NfcImplTest::SetUpTestCase()
39 {
40 HDF_LOGD("SetUpTestCase NfcImplTest");
41 }
42
TearDownTestCase()43 void NfcImplTest::TearDownTestCase()
44 {
45 HDF_LOGD("TearDownTestCase NfcImplTest");
46 }
47
SetUp()48 void NfcImplTest::SetUp()
49 {
50 HDF_LOGD("SetUp NfcImplTest");
51 }
52
TearDown()53 void NfcImplTest::TearDown()
54 {
55 HDF_LOGD("TearDown NfcImplTest");
56 }
57
58 /**
59 * @tc.name: Open001
60 * @tc.desc: Test NfcImplTest Open.
61 * @tc.type: FUNC
62 */
HWTEST_F(NfcImplTest, Open001, TestSize.Level1)63 HWTEST_F(NfcImplTest, Open001, TestSize.Level1)
64 {
65 const sptr<INfcCallback> callbackObj = nullptr;
66 NfcStatus status = NfcStatus::OK;
67 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
68 int ret = nfcImpl->Open(callbackObj, status);
69 EXPECT_EQ(ret, HDF_ERR_INVALID_PARAM);
70 }
71
72 /**
73 * @tc.name: CoreInitialized001
74 * @tc.desc: Test NfcImplTest CoreInitialized.
75 * @tc.type: FUNC
76 */
HWTEST_F(NfcImplTest, CoreInitialized001, TestSize.Level1)77 HWTEST_F(NfcImplTest, CoreInitialized001, TestSize.Level1)
78 {
79 std::vector<uint8_t> data;
80 NfcStatus status = NfcStatus::OK;
81 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
82 int ret = nfcImpl->CoreInitialized(data, status);
83 EXPECT_EQ(ret, HDF_ERR_INVALID_PARAM);
84 }
85
86 /**
87 * @tc.name: CoreInitialized002
88 * @tc.desc: Test NfcImplTest CoreInitialized.
89 * @tc.type: FUNC
90 */
HWTEST_F(NfcImplTest, CoreInitialized002, TestSize.Level1)91 HWTEST_F(NfcImplTest, CoreInitialized002, TestSize.Level1)
92 {
93 std::vector<uint8_t> data = {0x01, 0x02, 0x03};
94 NfcStatus status = NfcStatus::OK;
95 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
96 int ret = nfcImpl->CoreInitialized(data, status);
97 EXPECT_EQ(ret, HDF_SUCCESS);
98 }
99
100 /**
101 * @tc.name: Prediscover001
102 * @tc.desc: Test NfcImplTest Prediscover.
103 * @tc.type: FUNC
104 */
HWTEST_F(NfcImplTest, Prediscover001, TestSize.Level1)105 HWTEST_F(NfcImplTest, Prediscover001, TestSize.Level1)
106 {
107 NfcStatus status = NfcStatus::OK;
108 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
109 int ret = nfcImpl->Prediscover(status);
110 ASSERT_TRUE(ret == HDF_FAILURE);
111 }
112
113 /**
114 * @tc.name: Write001
115 * @tc.desc: Test NfcImplTest Write.
116 * @tc.type: FUNC
117 */
HWTEST_F(NfcImplTest, Write001, TestSize.Level1)118 HWTEST_F(NfcImplTest, Write001, TestSize.Level1)
119 {
120 std::vector<uint8_t> data;
121 NfcStatus status = NfcStatus::OK;
122 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
123 int ret = nfcImpl->Write(data, status);
124 ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
125 }
126
127 /**
128 * @tc.name: Write002
129 * @tc.desc: Test NfcImplTest Write.
130 * @tc.type: FUNC
131 */
HWTEST_F(NfcImplTest, Write002, TestSize.Level1)132 HWTEST_F(NfcImplTest, Write002, TestSize.Level1)
133 {
134 std::vector<uint8_t> data = {0x001, 0x002, 0x003};
135 NfcStatus status = NfcStatus::OK;
136 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
137 int ret = nfcImpl->Write(data, status);
138 ASSERT_TRUE(ret == HDF_SUCCESS);
139 }
140
141 /**
142 * @tc.name: ControlGranted001
143 * @tc.desc: Test NfcImplTest ControlGranted.
144 * @tc.type: FUNC
145 */
HWTEST_F(NfcImplTest, ControlGranted001, TestSize.Level1)146 HWTEST_F(NfcImplTest, ControlGranted001, TestSize.Level1)
147 {
148 NfcStatus status = NfcStatus::OK;
149 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
150 int ret = nfcImpl->ControlGranted(status);
151 ASSERT_TRUE(ret == HDF_FAILURE);
152 }
153
154 /**
155 * @tc.name: PowerCycle001
156 * @tc.desc: Test NfcImplTest PowerCycle.
157 * @tc.type: FUNC
158 */
HWTEST_F(NfcImplTest, PowerCycle001, TestSize.Level1)159 HWTEST_F(NfcImplTest, PowerCycle001, TestSize.Level1)
160 {
161 NfcStatus status = NfcStatus::OK;
162 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
163 int ret = nfcImpl->PowerCycle(status);
164 ASSERT_TRUE(ret == HDF_SUCCESS);
165 }
166
167 /**
168 * @tc.name: Close001
169 * @tc.desc: Test NfcImplTest Close.
170 * @tc.type: FUNC
171 */
HWTEST_F(NfcImplTest, Close001, TestSize.Level1)172 HWTEST_F(NfcImplTest, Close001, TestSize.Level1)
173 {
174 NfcStatus status = NfcStatus::OK;
175 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
176 int ret = nfcImpl->Close(status);
177 ASSERT_TRUE(ret == HDF_SUCCESS);
178 }
179
180 /**
181 * @tc.name: Ioctl001
182 * @tc.desc: Test NfcImplTest Ioctl.
183 * @tc.type: FUNC
184 */
HWTEST_F(NfcImplTest, Ioctl001, TestSize.Level1)185 HWTEST_F(NfcImplTest, Ioctl001, TestSize.Level1)
186 {
187 NfcCommand cmd = NfcCommand::CMD_INVALID;
188 std::vector<uint8_t> data;
189 NfcStatus status = NfcStatus::OK;
190 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
191 int ret = nfcImpl->Ioctl(cmd, data, status);
192 ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
193 }
194
195 /**
196 * @tc.name: Ioctl002
197 * @tc.desc: Test NfcImplTest Ioctl.
198 * @tc.type: FUNC
199 */
HWTEST_F(NfcImplTest, Ioctl002, TestSize.Level1)200 HWTEST_F(NfcImplTest, Ioctl002, TestSize.Level1)
201 {
202 NfcCommand cmd = NfcCommand::CMD_INVALID;
203 std::vector<uint8_t> data = {0x01, 0x02, 0x03};
204 NfcStatus status = NfcStatus::OK;
205 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
206 int ret = nfcImpl->Ioctl(cmd, data, status);
207 ASSERT_TRUE(ret == HDF_SUCCESS);
208 }
209
210 /**
211 * @tc.name: IoctlWithResponse001
212 * @tc.desc: Test NfcImplTest IoctlWithResponse.
213 * @tc.type: FUNC
214 */
HWTEST_F(NfcImplTest, IoctlWithResponse001, TestSize.Level1)215 HWTEST_F(NfcImplTest, IoctlWithResponse001, TestSize.Level1)
216 {
217 NfcCommand cmd = NfcCommand::CMD_INVALID;
218 std::vector<uint8_t> data;
219 std::vector<uint8_t> response;
220 NfcStatus status = NfcStatus::OK;
221 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
222 int ret = nfcImpl->IoctlWithResponse(cmd, data, response, status);
223 ASSERT_TRUE(ret == HDF_ERR_INVALID_PARAM);
224 }
225
226 /**
227 * @tc.name: IoctlWithResponse002
228 * @tc.desc: Test NfcImplTest IoctlWithResponse.
229 * @tc.type: FUNC
230 */
HWTEST_F(NfcImplTest, IoctlWithResponse002, TestSize.Level1)231 HWTEST_F(NfcImplTest, IoctlWithResponse002, TestSize.Level1)
232 {
233 NfcCommand cmd = NfcCommand::CMD_INVALID;
234 std::vector<uint8_t> data = {0X001};
235 std::vector<uint8_t> response;
236 NfcStatus status = NfcStatus::OK;
237 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
238 int ret = nfcImpl->IoctlWithResponse(cmd, data, response, status);
239 ASSERT_TRUE(ret == HDF_SUCCESS);
240 }
241
242 /**
243 * @tc.name: IoctlWithResponse003
244 * @tc.desc: Test NfcImplTest IoctlWithResponse.
245 * @tc.type: FUNC
246 */
HWTEST_F(NfcImplTest, IoctlWithResponse003, TestSize.Level1)247 HWTEST_F(NfcImplTest, IoctlWithResponse003, TestSize.Level1)
248 {
249 NfcCommand cmd = NfcCommand::CMD_INVALID;
250 std::vector<uint8_t> data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
251 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
252 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
253 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
254 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
255 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
256 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
257 131, 132, 133};
258 std::vector<uint8_t> response;
259 NfcStatus status = NfcStatus::OK;
260 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
261 int ret = nfcImpl->IoctlWithResponse(cmd, data, response, status);
262 ASSERT_TRUE(ret == HDF_SUCCESS);
263 }
264
265 /**
266 * @tc.name: GetVendorConfig001
267 * @tc.desc: Test NfcImplTest GetVendorConfig.
268 * @tc.type: FUNC
269 */
HWTEST_F(NfcImplTest, GetVendorConfig001, TestSize.Level1)270 HWTEST_F(NfcImplTest, GetVendorConfig001, TestSize.Level1)
271 {
272 NfcVendorConfig config;
273 NfcStatus status = NfcStatus::OK;
274 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
275 int ret = nfcImpl->GetVendorConfig(config, status);
276 ASSERT_TRUE(ret == HDF_FAILURE);
277 }
278
279 /**
280 * @tc.name: DoFactoryReset001
281 * @tc.desc: Test NfcImplTest DoFactoryReset.
282 * @tc.type: FUNC
283 */
HWTEST_F(NfcImplTest, DoFactoryReset001, TestSize.Level1)284 HWTEST_F(NfcImplTest, DoFactoryReset001, TestSize.Level1)
285 {
286 NfcStatus status = NfcStatus::OK;
287 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
288 int ret = nfcImpl->DoFactoryReset(status);
289 ASSERT_TRUE(ret == HDF_FAILURE);
290 }
291
292 /**
293 * @tc.name: Shutdown001
294 * @tc.desc: Test NfcImplTest Shutdown.
295 * @tc.type: FUNC
296 */
HWTEST_F(NfcImplTest, Shutdown001, TestSize.Level1)297 HWTEST_F(NfcImplTest, Shutdown001, TestSize.Level1)
298 {
299 NfcStatus status = NfcStatus::OK;
300 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
301 int ret = nfcImpl->Shutdown(status);
302 ASSERT_TRUE(ret == HDF_SUCCESS);
303 }
304 }
305 }
306 }
307 }
308 }