• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "nfc_controller_impl.h"
19 #include "nfc_service.h"
20 
21 namespace OHOS {
22 namespace NFC {
23 namespace TEST {
24 using namespace testing::ext;
25 using namespace OHOS::NFC;
26 class NfcControllerImplTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
34 class INfcControllerCallbackImpl : public INfcControllerCallback {
35 public:
INfcControllerCallbackImpl()36     INfcControllerCallbackImpl() {}
37 
~INfcControllerCallbackImpl()38     virtual ~INfcControllerCallbackImpl() {}
39 
40 public:
OnNfcStateChanged(int nfcState)41     void OnNfcStateChanged(int nfcState) override
42     {
43     }
44 
AsObject()45     OHOS::sptr<OHOS::IRemoteObject> AsObject() override
46     {
47         return nullptr;
48     }
49 };
50 
SetUpTestCase()51 void NfcControllerImplTest::SetUpTestCase()
52 {
53     std::cout << " SetUpTestCase NfcControllerImplTest." << std::endl;
54 }
55 
TearDownTestCase()56 void NfcControllerImplTest::TearDownTestCase()
57 {
58     std::cout << " TearDownTestCase NfcControllerImplTest." << std::endl;
59 }
60 
SetUp()61 void NfcControllerImplTest::SetUp()
62 {
63     std::cout << " SetUp NfcControllerImplTest." << std::endl;
64 }
65 
TearDown()66 void NfcControllerImplTest::TearDown()
67 {
68     std::cout << " TearDown NfcControllerImplTest." << std::endl;
69 }
70 
71 /**
72  * @tc.name: GetState001
73  * @tc.desc: Test NfcControllerImplTest GetState.
74  * @tc.type: FUNC
75  */
76 HWTEST_F(NfcControllerImplTest, GetState001, TestSize.Level1)
77 {
78     std::shared_ptr<NfcService> nfcService = nullptr;
79     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
80     int getState = nfcControllerImpl->GetState();
81     ASSERT_TRUE(getState == KITS::ERR_NFC_PARAMETERS);
82 }
83 
84 /**
85  * @tc.name: TurnOn001
86  * @tc.desc: Test NfcControllerImplTest TurnOn.
87  * @tc.type: FUNC
88  */
89 HWTEST_F(NfcControllerImplTest, TurnOn001, TestSize.Level1)
90 {
91     std::shared_ptr<NfcService> nfcService = nullptr;
92     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
93     int turnOn = nfcControllerImpl->TurnOn();
94     ASSERT_TRUE(turnOn == KITS::ERR_NFC_PARAMETERS);
95 }
96 
97 /**
98  * @tc.name: TurnOff001
99  * @tc.desc: Test NfcControllerImplTest TurnOff.
100  * @tc.type: FUNC
101  */
102 HWTEST_F(NfcControllerImplTest, TurnOff001, TestSize.Level1)
103 {
104     std::shared_ptr<NfcService> nfcService = nullptr;
105     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
106     int turnOff = nfcControllerImpl->TurnOff();
107     ASSERT_TRUE(turnOff == KITS::ERR_NFC_PARAMETERS);
108 }
109 
110 /**
111  * @tc.name: IsNfcOpen001
112  * @tc.desc: Test NfcControllerImplTest IsNfcOpen.
113  * @tc.type: FUNC
114  */
115 HWTEST_F(NfcControllerImplTest, IsNfcOpen001, TestSize.Level1)
116 {
117     bool isOpen = false;
118     std::shared_ptr<NfcService> nfcService = nullptr;
119     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
120     int isNfcOpen = nfcControllerImpl->IsNfcOpen(isOpen);
121     ASSERT_TRUE(isNfcOpen == KITS::ERR_NFC_PARAMETERS);
122 }
123 
124 /**
125  * @tc.name: RegisterCallBack001
126  * @tc.desc: Test NfcControllerImplTest RegisterCallBack.
127  * @tc.type: FUNC
128  */
129 HWTEST_F(NfcControllerImplTest, RegisterCallBack001, TestSize.Level1)
130 {
131     sptr<INfcControllerCallback> callback = nullptr;
132     std::string type = "";
133     Security::AccessToken::AccessTokenID callerToken = 0;
134     std::shared_ptr<NfcService> nfcService = nullptr;
135     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
136     KITS::ErrorCode error = nfcControllerImpl->RegisterCallBack(callback, type, callerToken);
137     ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
138 }
139 
140 /**
141  * @tc.name: RegisterCallBack002
142  * @tc.desc: Test NfcControllerImplTest RegisterCallBack.
143  * @tc.type: FUNC
144  */
145 HWTEST_F(NfcControllerImplTest, RegisterCallBack002, TestSize.Level1)
146 {
147     sptr<INfcControllerCallback> callback = nullptr;
148     std::string type = "";
149     Security::AccessToken::AccessTokenID callerToken = 0;
150     std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
151     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
152     KITS::ErrorCode error = nfcControllerImpl->RegisterCallBack(callback, type, callerToken);
153     ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
154 }
155 
156 /**
157  * @tc.name: RegisterCallBack003
158  * @tc.desc: Test NfcControllerImplTest RegisterCallBack.
159  * @tc.type: FUNC
160  */
161 HWTEST_F(NfcControllerImplTest, RegisterCallBack003, TestSize.Level1)
162 {
163     sptr<INfcControllerCallbackImpl> callback = new INfcControllerCallbackImpl();
164     std::string type = "";
165     Security::AccessToken::AccessTokenID callerToken = 0;
166     std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
167     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
168     KITS::ErrorCode error = nfcControllerImpl->RegisterCallBack(callback, type, callerToken);
169     ASSERT_TRUE(error == KITS::ERR_NONE);
170 }
171 
172 /**
173  * @tc.name: UnRegisterCallBack001
174  * @tc.desc: Test NfcControllerImplTest UnRegisterCallBack.
175  * @tc.type: FUNC
176  */
177 HWTEST_F(NfcControllerImplTest, UnRegisterCallBack001, TestSize.Level1)
178 {
179     std::string type = "";
180     Security::AccessToken::AccessTokenID callerToken = 0;
181     std::shared_ptr<NfcService> nfcService = nullptr;
182     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
183     KITS::ErrorCode error = nfcControllerImpl->UnRegisterCallBack(type, callerToken);
184     ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
185 }
186 
187 /**
188  * @tc.name: UnRegisterCallBack002
189  * @tc.desc: Test NfcControllerImplTest UnRegisterCallBack.
190  * @tc.type: FUNC
191  */
192 HWTEST_F(NfcControllerImplTest, UnRegisterCallBack002, TestSize.Level1)
193 {
194     std::string type = "";
195     Security::AccessToken::AccessTokenID callerToken = 0;
196     std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
197     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
198     KITS::ErrorCode error = nfcControllerImpl->UnRegisterCallBack(type, callerToken);
199     ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
200 }
201 
202 /**
203  * @tc.name: UnRegisterAllCallBack001
204  * @tc.desc: Test NfcControllerImplTest UnRegisterAllCallBack.
205  * @tc.type: FUNC
206  */
207 HWTEST_F(NfcControllerImplTest, UnRegisterAllCallBack001, TestSize.Level1)
208 {
209     Security::AccessToken::AccessTokenID callerToken = 0;
210     std::shared_ptr<NfcService> nfcService = nullptr;
211     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
212     KITS::ErrorCode error = nfcControllerImpl->UnRegisterAllCallBack(callerToken);
213     ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
214 }
215 
216 /**
217  * @tc.name: UnRegisterAllCallBack002
218  * @tc.desc: Test NfcControllerImplTest UnRegisterAllCallBack.
219  * @tc.type: FUNC
220  */
221 HWTEST_F(NfcControllerImplTest, UnRegisterAllCallBack002, TestSize.Level1)
222 {
223     Security::AccessToken::AccessTokenID callerToken = 0;
224     std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
225     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
226     KITS::ErrorCode error = nfcControllerImpl->UnRegisterAllCallBack(callerToken);
227     ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
228 }
229 
230 /**
231  * @tc.name: GetTagServiceIface001
232  * @tc.desc: Test NfcControllerImplTest GetTagServiceIface.
233  * @tc.type: FUNC
234  */
235 HWTEST_F(NfcControllerImplTest, GetTagServiceIface001, TestSize.Level1)
236 {
237     std::shared_ptr<NfcService> nfcService = nullptr;
238     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
239     sptr<IRemoteObject> iRemoteObject = nfcControllerImpl->GetTagServiceIface();
240     ASSERT_TRUE(iRemoteObject == nullptr);
241 }
242 
243 /**
244  * @tc.name: GetTagServiceIface002
245  * @tc.desc: Test NfcControllerImplTest GetTagServiceIface.
246  * @tc.type: FUNC
247  */
248 HWTEST_F(NfcControllerImplTest, GetTagServiceIface002, TestSize.Level1)
249 {
250     std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
251     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
252     sptr<IRemoteObject> iRemoteObject = nfcControllerImpl->GetTagServiceIface();
253     ASSERT_TRUE(iRemoteObject == nullptr);
254 }
255 
256 /**
257  * @tc.name: RegNdefMsgCallback001
258  * @tc.desc: Test NfcControllerImplTest RegNdefMsgCallback.
259  * @tc.type: FUNC
260  */
261 HWTEST_F(NfcControllerImplTest, RegNdefMsgCallback001, TestSize.Level1)
262 {
263     sptr<INdefMsgCallback> callback = nullptr;
264     std::shared_ptr<NfcService> nfcService = nullptr;
265     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
266     KITS::ErrorCode error = nfcControllerImpl->RegNdefMsgCallback(callback);
267     ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
268 }
269 #ifdef VENDOR_APPLICATIONS_ENABLED
270 /**
271  * @tc.name: RegQueryApplicationCb001
272  * @tc.desc: Test NfcControllerImplTest RegQueryApplicationCb.
273  * @tc.type: FUNC
274  */
275 HWTEST_F(NfcControllerImplTest, RegQueryApplicationCb001, TestSize.Level1)
276 {
277     sptr<IQueryAppInfoCallback> callback = nullptr;
278     std::shared_ptr<NfcService> nfcService = nullptr;
279     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
280     KITS::ErrorCode error = nfcControllerImpl->RegQueryApplicationCb(callback);
281     ASSERT_TRUE(error == KITS::ERR_NONE);
282 }
283 
284 /**
285  * @tc.name: RegCardEmulationNotifyCb001
286  * @tc.desc: Test NfcControllerImplTest RegCardEmulationNotifyCb.
287  * @tc.type: FUNC
288  */
289 HWTEST_F(NfcControllerImplTest, RegCardEmulationNotifyCb001, TestSize.Level1)
290 {
291     sptr<IOnCardEmulationNotifyCb> callback = nullptr;
292     std::shared_ptr<NfcService> nfcService = nullptr;
293     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
294     KITS::ErrorCode error = nfcControllerImpl->RegCardEmulationNotifyCb(callback);
295     ASSERT_TRUE(error == KITS::ERR_NONE);
296 }
297 
298 /**
299  * @tc.name: NotifyEventStatus001
300  * @tc.desc: Test NfcControllerImplTest NotifyEventStatus.
301  * @tc.type: FUNC
302  */
303 HWTEST_F(NfcControllerImplTest, NotifyEventStatus001, TestSize.Level1)
304 {
305     std::shared_ptr<NfcService> nfcService = nullptr;
306     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
307     KITS::ErrorCode error = nfcControllerImpl->NotifyEventStatus(0, 0, "");
308     ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
309 }
310 
311 #endif
312 /**
313  * @tc.name: GetHceServiceIface001
314  * @tc.desc: Test NfcControllerImplTest GetHceServiceIface.
315  * @tc.type: FUNC
316  */
317 HWTEST_F(NfcControllerImplTest, GetHceServiceIface001, TestSize.Level1)
318 {
319     std::shared_ptr<NfcService> nfcService = nullptr;
320     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
321     sptr<IRemoteObject> iRemoteObject = nfcControllerImpl->GetHceServiceIface();
322     ASSERT_TRUE(iRemoteObject == nullptr);
323 }
324 
325 /**
326  * @tc.name: GetHceServiceIface002
327  * @tc.desc: Test NfcControllerImplTest GetHceServiceIface.
328  * @tc.type: FUNC
329  */
330 HWTEST_F(NfcControllerImplTest, GetHceServiceIface002, TestSize.Level1)
331 {
332     std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
333     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
334     sptr<IRemoteObject> iRemoteObject = nfcControllerImpl->GetHceServiceIface();
335     ASSERT_TRUE(iRemoteObject == nullptr);
336 }
337 
338 /**
339  * @tc.name: Dump001
340  * @tc.desc: Test NfcControllerImplTest Dump.
341  * @tc.type: FUNC
342  */
343 HWTEST_F(NfcControllerImplTest, Dump001, TestSize.Level1)
344 {
345     int32_t fd = 0;
346     std::vector<std::u16string> args;
347     std::shared_ptr<NfcService> nfcService = nullptr;
348     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
349     int dump = nfcControllerImpl->Dump(fd, args);
350     ASSERT_TRUE(dump == KITS::ERR_NFC_PARAMETERS);
351 }
352 
353 /**
354  * @tc.name: Dump002
355  * @tc.desc: Test NfcControllerImplTest Dump.
356  * @tc.type: FUNC
357  */
358 HWTEST_F(NfcControllerImplTest, Dump002, TestSize.Level1)
359 {
360     int32_t fd = 0;
361     std::vector<std::u16string> args;
362     std::shared_ptr<NfcService> nfcService = std::make_shared<NfcService>();
363     std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
364     int dump = nfcControllerImpl->Dump(fd, args);
365     ASSERT_TRUE(dump == KITS::ERR_NFC_PARAMETERS);
366 }
367 }
368 }
369 }