1 /*
2  * Copyright (c) 2023 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 
18 #include "nci_tag_proxy.h"
19 
20 namespace OHOS {
21 namespace NFC {
22 namespace TEST {
23 using namespace testing::ext;
24 using namespace OHOS::NFC::NCI;
25 class NciTagProxyTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp();
30     void TearDown();
31 };
32 
SetUpTestCase()33 void NciTagProxyTest::SetUpTestCase()
34 {
35     std::cout << " SetUpTestCase NciTagProxyTest." << std::endl;
36 }
37 
TearDownTestCase()38 void NciTagProxyTest::TearDownTestCase()
39 {
40     std::cout << " TearDownTestCase NciTagProxyTest." << std::endl;
41 }
42 
SetUp()43 void NciTagProxyTest::SetUp()
44 {
45     std::cout << " SetUp NciTagProxyTest." << std::endl;
46 }
47 
TearDown()48 void NciTagProxyTest::TearDown()
49 {
50     std::cout << " TearDown NciTagProxyTest." << std::endl;
51 }
52 
53 /**
54  * @tc.name: SetTagListener001
55  * @tc.desc: Test NciTagProxyTest SetTagListener.
56  * @tc.type: FUNC
57  */
58 HWTEST_F(NciTagProxyTest, SetTagListener001, TestSize.Level1)
59 {
60     std::shared_ptr<NCI::INciTagInterface::ITagListener> listener = nullptr;
61     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
62     nciTagProxy->SetTagListener(listener);
63     uint32_t tagDiscId = 0;
64     std::vector<AppExecFwk::PacMap> getTechExtrasData = nciTagProxy->GetTechExtrasData(tagDiscId);
65     ASSERT_TRUE(getTechExtrasData.size() == 0);
66 }
67 
68 /**
69  * @tc.name: GetTechList001
70  * @tc.desc: Test NciTagProxyTest GetTechList.
71  * @tc.type: FUNC
72  */
73 HWTEST_F(NciTagProxyTest, GetTechList001, TestSize.Level1)
74 {
75     uint32_t tagDiscId = 0;
76     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
77     std::vector<int> getTechList = nciTagProxy->GetTechList(tagDiscId);
78     ASSERT_TRUE(getTechList.size() == 0);
79 }
80 
81 /**
82  * @tc.name: GetConnectedTech001
83  * @tc.desc: Test NciTagProxyTest GetConnectedTech.
84  * @tc.type: FUNC
85  */
86 HWTEST_F(NciTagProxyTest, GetConnectedTech001, TestSize.Level1)
87 {
88     uint32_t tagDiscId = 0;
89     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
90     int getConnectedTech = nciTagProxy->GetConnectedTech(tagDiscId);
91     ASSERT_TRUE(getConnectedTech == 0);
92 }
93 
94 /**
95  * @tc.name: GetTechExtrasData001
96  * @tc.desc: Test NciTagProxyTest GetTechExtrasData.
97  * @tc.type: FUNC
98  */
99 HWTEST_F(NciTagProxyTest, GetTechExtrasData001, TestSize.Level1)
100 {
101     uint32_t tagDiscId = 0;
102     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
103     std::vector<AppExecFwk::PacMap> getTechExtrasData = nciTagProxy->GetTechExtrasData(tagDiscId);
104     ASSERT_TRUE(getTechExtrasData.size() == 0);
105 }
106 
107 /**
108  * @tc.name: GetTagUid001
109  * @tc.desc: Test NciTagProxyTest GetTagUid.
110  * @tc.type: FUNC
111  */
112 HWTEST_F(NciTagProxyTest, GetTagUid001, TestSize.Level1)
113 {
114     uint32_t tagDiscId = 0;
115     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
116     std::string getTagUid = nciTagProxy->GetTagUid(tagDiscId);
117     ASSERT_TRUE(getTagUid == "");
118 }
119 
120 /**
121  * @tc.name: Connect001
122  * @tc.desc: Test NciTagProxyTest Connect.
123  * @tc.type: FUNC
124  */
125 HWTEST_F(NciTagProxyTest, Connect001, TestSize.Level1)
126 {
127     uint32_t tagDiscId = 0;
128     uint32_t technology = 0;
129     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
130     bool connect = nciTagProxy->Connect(tagDiscId, technology);
131     ASSERT_TRUE(connect == false);
132 }
133 
134 /**
135  * @tc.name: Disconnect001
136  * @tc.desc: Test NciTagProxyTest Disconnect.
137  * @tc.type: FUNC
138  */
139 HWTEST_F(NciTagProxyTest, Disconnect001, TestSize.Level1)
140 {
141     uint32_t tagDiscId = 0;
142     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
143     bool disconnect = nciTagProxy->Disconnect(tagDiscId);
144     ASSERT_TRUE(disconnect == false);
145 }
146 
147 /**
148  * @tc.name: Reconnect001
149  * @tc.desc: Test NciTagProxyTest Reconnect.
150  * @tc.type: FUNC
151  */
152 HWTEST_F(NciTagProxyTest, Reconnect001, TestSize.Level1)
153 {
154     uint32_t tagDiscId = 0;
155     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
156     bool reconnect = nciTagProxy->Reconnect(tagDiscId);
157     ASSERT_TRUE(reconnect == false);
158 }
159 
160 /**
161  * @tc.name: Transceive001
162  * @tc.desc: Test NciTagProxyTest Transceive.
163  * @tc.type: FUNC
164  */
165 HWTEST_F(NciTagProxyTest, Transceive001, TestSize.Level1)
166 {
167     uint32_t tagDiscId = 0;
168     std::string command = "";
169     std::string response = "";
170     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
171     int transceive = nciTagProxy->Transceive(tagDiscId, command, response);
172     ASSERT_TRUE(transceive == 0);
173 }
174 
175 /**
176  * @tc.name: ReadNdef001
177  * @tc.desc: Test NciTagProxyTest ReadNdef.
178  * @tc.type: FUNC
179  */
180 HWTEST_F(NciTagProxyTest, ReadNdef001, TestSize.Level1)
181 {
182     uint32_t tagDiscId = 0;
183     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
184     std::string readNdef = nciTagProxy->ReadNdef(tagDiscId);
185     ASSERT_TRUE(readNdef == "");
186 }
187 
188 /**
189  * @tc.name: FindNdefTech001
190  * @tc.desc: Test NciTagProxyTest FindNdefTech.
191  * @tc.type: FUNC
192  */
193 HWTEST_F(NciTagProxyTest, FindNdefTech001, TestSize.Level1)
194 {
195     uint32_t tagDiscId = 0;
196     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
197     std::string findNdefTech = nciTagProxy->FindNdefTech(tagDiscId);
198     ASSERT_TRUE(findNdefTech == "");
199 }
200 
201 /**
202  * @tc.name: WriteNdef001
203  * @tc.desc: Test NciTagProxyTest WriteNdef.
204  * @tc.type: FUNC
205  */
206 HWTEST_F(NciTagProxyTest, WriteNdef001, TestSize.Level1)
207 {
208     uint32_t tagDiscId = 0;
209     std::string command = "";
210     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
211     bool writeNdef = nciTagProxy->WriteNdef(tagDiscId, command);
212     ASSERT_TRUE(writeNdef == false);
213 }
214 
215 /**
216  * @tc.name: FormatNdef001
217  * @tc.desc: Test NciTagProxyTest FormatNdef.
218  * @tc.type: FUNC
219  */
220 HWTEST_F(NciTagProxyTest, FormatNdef001, TestSize.Level1)
221 {
222     uint32_t tagDiscId = 0;
223     std::string key = "";
224     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
225     bool formatNdef = nciTagProxy->FormatNdef(tagDiscId, key);
226     ASSERT_TRUE(formatNdef == false);
227 }
228 
229 /**
230  * @tc.name: CanMakeReadOnly001
231  * @tc.desc: Test NciTagProxyTest CanMakeReadOnly.
232  * @tc.type: FUNC
233  */
234 HWTEST_F(NciTagProxyTest, CanMakeReadOnly001, TestSize.Level1)
235 {
236     uint32_t ndefType = 0;
237     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
238     bool canMakeReadOnly = nciTagProxy->CanMakeReadOnly(ndefType);
239     ASSERT_TRUE(canMakeReadOnly == false);
240 }
241 
242 /**
243  * @tc.name: SetNdefReadOnly001
244  * @tc.desc: Test NciTagProxyTest SetNdefReadOnly.
245  * @tc.type: FUNC
246  */
247 HWTEST_F(NciTagProxyTest, SetNdefReadOnly001, TestSize.Level1)
248 {
249     uint32_t tagDiscId = 0;
250     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
251     bool setNdefReadOnly = nciTagProxy->SetNdefReadOnly(tagDiscId);
252     ASSERT_TRUE(setNdefReadOnly == false);
253 }
254 
255 /**
256  * @tc.name: DetectNdefInfo001
257  * @tc.desc: Test NciTagProxyTest DetectNdefInfo.
258  * @tc.type: FUNC
259  */
260 HWTEST_F(NciTagProxyTest, DetectNdefInfo001, TestSize.Level1)
261 {
262     uint32_t tagDiscId = 0;
263     std::vector<int> ndefInfo;
264     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
265     bool detectNdefInfo = nciTagProxy->DetectNdefInfo(tagDiscId, ndefInfo);
266     ASSERT_TRUE(detectNdefInfo == false);
267 }
268 
269 /**
270  * @tc.name: IsTagFieldOn001
271  * @tc.desc: Test NciTagProxyTest IsTagFieldOn.
272  * @tc.type: FUNC
273  */
274 HWTEST_F(NciTagProxyTest, IsTagFieldOn001, TestSize.Level1)
275 {
276     uint32_t tagDiscId = 0;
277     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
278     bool isTagFieldOn = nciTagProxy->IsTagFieldOn(tagDiscId);
279     ASSERT_TRUE(isTagFieldOn == false);
280 }
281 
282 /**
283  * @tc.name: StartFieldOnChecking001
284  * @tc.desc: Test NciTagProxyTest StartFieldOnChecking.
285  * @tc.type: FUNC
286  */
287 HWTEST_F(NciTagProxyTest, StartFieldOnChecking001, TestSize.Level1)
288 {
289     uint32_t tagDiscId = 0;
290     uint32_t delayedMs = 0;
291     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
292     nciTagProxy->StartFieldOnChecking(tagDiscId, delayedMs);
293     std::vector<AppExecFwk::PacMap> getTechExtrasData = nciTagProxy->GetTechExtrasData(tagDiscId);
294     ASSERT_TRUE(getTechExtrasData.size() == 0);
295 }
296 
297 /**
298  * @tc.name: SetTimeout001
299  * @tc.desc: Test NciTagProxyTest SetTimeout.
300  * @tc.type: FUNC
301  */
302 HWTEST_F(NciTagProxyTest, SetTimeout001, TestSize.Level1)
303 {
304     uint32_t tagDiscId = 0;
305     uint32_t timeout = 0;
306     uint32_t technology = 0;
307     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
308     nciTagProxy->SetTimeout(tagDiscId, timeout, technology);
309     std::vector<AppExecFwk::PacMap> getTechExtrasData = nciTagProxy->GetTechExtrasData(tagDiscId);
310     ASSERT_TRUE(getTechExtrasData.size() == 0);
311 }
312 
313 /**
314  * @tc.name: GetIsoDepMaxTransceiveLength001
315  * @tc.desc: Test NciTagProxyTest GetIsoDepMaxTransceiveLength.
316  * @tc.type: FUNC
317  */
318 HWTEST_F(NciTagProxyTest, GetIsoDepMaxTransceiveLength001, TestSize.Level1)
319 {
320     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
321     int getIsoDepMaxTransceiveLength = nciTagProxy->GetIsoDepMaxTransceiveLength();
322     ASSERT_TRUE(getIsoDepMaxTransceiveLength != 0);
323 }
324 
325 /**
326  * @tc.name: IsExtendedLengthApduSupported001
327  * @tc.desc: Test NciTagProxyTest IsExtendedLengthApduSupported.
328  * @tc.type: FUNC
329  */
330 HWTEST_F(NciTagProxyTest, IsExtendedLengthApduSupported001, TestSize.Level1)
331 {
332     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
333     bool isExtendedLengthApduSupported = nciTagProxy->IsExtendedLengthApduSupported();
334     ASSERT_TRUE(isExtendedLengthApduSupported == true);
335 }
336 
337 /**
338  * @tc.name: GetTechMaskFromTechList001
339  * @tc.desc: Test NciTagProxyTest GetTechMaskFromTechList.
340  * @tc.type: FUNC
341  */
342 HWTEST_F(NciTagProxyTest, GetTechMaskFromTechList001, TestSize.Level1)
343 {
344     std::vector<uint32_t> discTech = {0, 1, 2, 3, 4, 5};
345     std::shared_ptr<NciTagProxy> nciTagProxy = std::make_shared<NciTagProxy>();
346     int getTechMaskFromTechList = nciTagProxy->GetTechMaskFromTechList(discTech);
347     ASSERT_TRUE(getTechMaskFromTechList != 0);
348 }
349 }
350 }
351 }