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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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_ERR_INVALID_PARAM);
240 }
241
242 /**
243 * @tc.name: IoctlWithResponse003
244 * @tc.desc: Test NfcImplTest IoctlWithResponse.
245 * @tc.type: FUNC
246 */
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,
251 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
252 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
253 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
254 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
255 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
256 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
257 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
258 120, 121, 122, 123, 124, 125, 126, 127, 128, 129};
259 std::vector<uint8_t> response;
260 NfcStatus status = NfcStatus::OK;
261 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
262 int ret = nfcImpl->IoctlWithResponse(cmd, data, response, status);
263 ASSERT_TRUE(ret == HDF_SUCCESS);
264 }
265
266 /**
267 * @tc.name: GetVendorConfig001
268 * @tc.desc: Test NfcImplTest GetVendorConfig.
269 * @tc.type: FUNC
270 */
271 HWTEST_F(NfcImplTest, GetVendorConfig001, TestSize.Level1)
272 {
273 NfcVendorConfig config;
274 NfcStatus status = NfcStatus::OK;
275 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
276 int ret = nfcImpl->GetVendorConfig(config, status);
277 ASSERT_TRUE(ret == HDF_FAILURE);
278 }
279
280 /**
281 * @tc.name: DoFactoryReset001
282 * @tc.desc: Test NfcImplTest DoFactoryReset.
283 * @tc.type: FUNC
284 */
285 HWTEST_F(NfcImplTest, DoFactoryReset001, TestSize.Level1)
286 {
287 NfcStatus status = NfcStatus::OK;
288 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
289 int ret = nfcImpl->DoFactoryReset(status);
290 ASSERT_TRUE(ret == HDF_FAILURE);
291 }
292
293 /**
294 * @tc.name: Shutdown001
295 * @tc.desc: Test NfcImplTest Shutdown.
296 * @tc.type: FUNC
297 */
298 HWTEST_F(NfcImplTest, Shutdown001, TestSize.Level1)
299 {
300 NfcStatus status = NfcStatus::OK;
301 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
302 int ret = nfcImpl->Shutdown(status);
303 ASSERT_TRUE(ret == HDF_SUCCESS);
304 }
305 }
306 }
307 }
308 }
309 }