• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
37 std::shared_ptr<NfcImpl> nfcImpl = std::make_shared<NfcImpl>();
38 
SetUpTestCase()39 void NfcImplTest::SetUpTestCase()
40 {
41     HDF_LOGD("SetUpTestCase NfcImplTest");
42 }
43 
TearDownTestCase()44 void NfcImplTest::TearDownTestCase()
45 {
46     HDF_LOGD("TearDownTestCase NfcImplTest");
47 }
48 
SetUp()49 void NfcImplTest::SetUp()
50 {
51     HDF_LOGD("SetUp NfcImplTest");
52 }
53 
TearDown()54 void NfcImplTest::TearDown()
55 {
56     HDF_LOGD("TearDown NfcImplTest");
57 }
58 
59 /**
60  * @tc.name: Open001
61  * @tc.desc: Test NfcImplTest Open.
62  * @tc.type: FUNC
63  */
64 HWTEST_F(NfcImplTest, Open001, TestSize.Level1)
65 {
66     sleep(1);
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_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     int ret = nfcImpl->Prediscover(status);
108     ASSERT_TRUE(ret == HDF_SUCCESS);
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_FAILURE);
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_SUCCESS);
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_FAILURE);
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_FAILURE);
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_FAILURE);
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_FAILURE);
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_FAILURE);
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     sleep(1);
263     int ret = nfcImpl->GetVendorConfig(config, status);
264     ASSERT_TRUE(ret == HDF_SUCCESS);
265 }
266 
267 /**
268  * @tc.name: DoFactoryReset001
269  * @tc.desc: Test NfcImplTest DoFactoryReset.
270  * @tc.type: FUNC
271  */
272 HWTEST_F(NfcImplTest, DoFactoryReset001, TestSize.Level1)
273 {
274     NfcStatus status = NfcStatus::OK;
275     int ret = nfcImpl->DoFactoryReset(status);
276     ASSERT_TRUE(ret == HDF_SUCCESS);
277 }
278 }
279 }
280 }
281 }
282 }