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