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
20 namespace OHOS {
21 namespace NFC {
22 namespace TEST {
23 using namespace testing::ext;
24 using namespace OHOS::NFC;
25 class NfcControllerImplTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase()33 void NfcControllerImplTest::SetUpTestCase()
34 {
35 std::cout << " SetUpTestCase NfcControllerImplTest." << std::endl;
36 }
37
TearDownTestCase()38 void NfcControllerImplTest::TearDownTestCase()
39 {
40 std::cout << " TearDownTestCase NfcControllerImplTest." << std::endl;
41 }
42
SetUp()43 void NfcControllerImplTest::SetUp()
44 {
45 std::cout << " SetUp NfcControllerImplTest." << std::endl;
46 }
47
TearDown()48 void NfcControllerImplTest::TearDown()
49 {
50 std::cout << " TearDown NfcControllerImplTest." << std::endl;
51 }
52
53 /**
54 * @tc.name: GetState001
55 * @tc.desc: Test NfcControllerImplTest GetState.
56 * @tc.type: FUNC
57 */
58 HWTEST_F(NfcControllerImplTest, GetState001, TestSize.Level1)
59 {
60 std::shared_ptr<NfcService> nfcService = nullptr;
61 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
62 int getState = nfcControllerImpl->GetState();
63 ASSERT_TRUE(getState == KITS::ERR_NFC_PARAMETERS);
64 }
65
66 /**
67 * @tc.name: TurnOn001
68 * @tc.desc: Test NfcControllerImplTest TurnOn.
69 * @tc.type: FUNC
70 */
71 HWTEST_F(NfcControllerImplTest, TurnOn001, TestSize.Level1)
72 {
73 std::shared_ptr<NfcService> nfcService = nullptr;
74 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
75 int turnOn = nfcControllerImpl->TurnOn();
76 ASSERT_TRUE(turnOn == KITS::ERR_NFC_PARAMETERS);
77 }
78
79 /**
80 * @tc.name: TurnOff001
81 * @tc.desc: Test NfcControllerImplTest TurnOff.
82 * @tc.type: FUNC
83 */
84 HWTEST_F(NfcControllerImplTest, TurnOff001, TestSize.Level1)
85 {
86 std::shared_ptr<NfcService> nfcService = nullptr;
87 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
88 int turnOff = nfcControllerImpl->TurnOff();
89 ASSERT_TRUE(turnOff == KITS::ERR_NFC_PARAMETERS);
90 }
91
92 /**
93 * @tc.name: IsNfcOpen001
94 * @tc.desc: Test NfcControllerImplTest IsNfcOpen.
95 * @tc.type: FUNC
96 */
97 HWTEST_F(NfcControllerImplTest, IsNfcOpen001, TestSize.Level1)
98 {
99 bool isOpen = false;
100 std::shared_ptr<NfcService> nfcService = nullptr;
101 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
102 int isNfcOpen = nfcControllerImpl->IsNfcOpen(isOpen);
103 ASSERT_TRUE(isNfcOpen == KITS::ERR_NFC_PARAMETERS);
104 }
105
106 /**
107 * @tc.name: RegisterCallBack001
108 * @tc.desc: Test NfcControllerImplTest RegisterCallBack.
109 * @tc.type: FUNC
110 */
111 HWTEST_F(NfcControllerImplTest, RegisterCallBack001, TestSize.Level1)
112 {
113 sptr<INfcControllerCallback> callback = nullptr;
114 std::string type = "";
115 Security::AccessToken::AccessTokenID callerToken = 0;
116 std::shared_ptr<NfcService> nfcService = nullptr;
117 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
118 KITS::ErrorCode error = nfcControllerImpl->RegisterCallBack(callback, type, callerToken);
119 ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
120 }
121
122 /**
123 * @tc.name: UnRegisterCallBack001
124 * @tc.desc: Test NfcControllerImplTest UnRegisterCallBack.
125 * @tc.type: FUNC
126 */
127 HWTEST_F(NfcControllerImplTest, UnRegisterCallBack001, TestSize.Level1)
128 {
129 std::string type = "";
130 Security::AccessToken::AccessTokenID callerToken = 0;
131 std::shared_ptr<NfcService> nfcService = nullptr;
132 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
133 KITS::ErrorCode error = nfcControllerImpl->UnRegisterCallBack(type, callerToken);
134 ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
135 }
136
137 /**
138 * @tc.name: UnRegisterAllCallBack001
139 * @tc.desc: Test NfcControllerImplTest UnRegisterAllCallBack.
140 * @tc.type: FUNC
141 */
142 HWTEST_F(NfcControllerImplTest, UnRegisterAllCallBack001, TestSize.Level1)
143 {
144 Security::AccessToken::AccessTokenID callerToken = 0;
145 std::shared_ptr<NfcService> nfcService = nullptr;
146 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
147 KITS::ErrorCode error = nfcControllerImpl->UnRegisterAllCallBack(callerToken);
148 ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
149 }
150
151 /**
152 * @tc.name: GetTagServiceIface001
153 * @tc.desc: Test NfcControllerImplTest GetTagServiceIface.
154 * @tc.type: FUNC
155 */
156 HWTEST_F(NfcControllerImplTest, GetTagServiceIface001, TestSize.Level1)
157 {
158 std::shared_ptr<NfcService> nfcService = nullptr;
159 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
160 sptr<IRemoteObject> iRemoteObject = nfcControllerImpl->GetTagServiceIface();
161 ASSERT_TRUE(iRemoteObject == nullptr);
162 }
163
164 /**
165 * @tc.name: RegNdefMsgCallback001
166 * @tc.desc: Test NfcControllerImplTest RegNdefMsgCallback.
167 * @tc.type: FUNC
168 */
169 HWTEST_F(NfcControllerImplTest, RegNdefMsgCallback001, TestSize.Level1)
170 {
171 sptr<INdefMsgCallback> callback = nullptr;
172 std::shared_ptr<NfcService> nfcService = nullptr;
173 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
174 KITS::ErrorCode error = nfcControllerImpl->RegNdefMsgCallback(callback);
175 ASSERT_TRUE(error == KITS::ERR_NFC_PARAMETERS);
176 }
177 #ifdef VENDOR_APPLICATIONS_ENABLED
178 /**
179 * @tc.name: RegQueryApplicationCb001
180 * @tc.desc: Test NfcControllerImplTest RegQueryApplicationCb.
181 * @tc.type: FUNC
182 */
183 HWTEST_F(NfcControllerImplTest, RegQueryApplicationCb001, TestSize.Level1)
184 {
185 sptr<IQueryAppInfoCallback> callback = nullptr;
186 std::shared_ptr<NfcService> nfcService = nullptr;
187 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
188 KITS::ErrorCode error = nfcControllerImpl->RegQueryApplicationCb(callback);
189 ASSERT_TRUE(error == KITS::ERR_NONE);
190 }
191
192 /**
193 * @tc.name: RegCardEmulationNotifyCb001
194 * @tc.desc: Test NfcControllerImplTest RegCardEmulationNotifyCb.
195 * @tc.type: FUNC
196 */
197 HWTEST_F(NfcControllerImplTest, RegCardEmulationNotifyCb001, TestSize.Level1)
198 {
199 sptr<IOnCardEmulationNotifyCb> callback = nullptr;
200 std::shared_ptr<NfcService> nfcService = nullptr;
201 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
202 KITS::ErrorCode error = nfcControllerImpl->RegCardEmulationNotifyCb(callback);
203 ASSERT_TRUE(error == KITS::ERR_NONE);
204 }
205 #endif
206 /**
207 * @tc.name: GetHceServiceIface001
208 * @tc.desc: Test NfcControllerImplTest GetHceServiceIface.
209 * @tc.type: FUNC
210 */
211 HWTEST_F(NfcControllerImplTest, GetHceServiceIface001, TestSize.Level1)
212 {
213 std::shared_ptr<NfcService> nfcService = nullptr;
214 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
215 sptr<IRemoteObject> iRemoteObject = nfcControllerImpl->GetHceServiceIface();
216 ASSERT_TRUE(iRemoteObject == nullptr);
217 }
218
219 /**
220 * @tc.name: Dump001
221 * @tc.desc: Test NfcControllerImplTest Dump.
222 * @tc.type: FUNC
223 */
224 HWTEST_F(NfcControllerImplTest, Dump001, TestSize.Level1)
225 {
226 int32_t fd = 0;
227 std::vector<std::u16string> args;
228 std::shared_ptr<NfcService> nfcService = nullptr;
229 std::shared_ptr<NfcControllerImpl> nfcControllerImpl = std::make_shared<NfcControllerImpl>(nfcService);
230 int dump = nfcControllerImpl->Dump(fd, args);
231 ASSERT_TRUE(dump == KITS::ERR_NFC_PARAMETERS);
232 }
233 }
234 }
235 }