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