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 "ndef_bt_data_parser.h"
19
20 namespace OHOS {
21 namespace NFC {
22 namespace TAG {
23 namespace TEST {
24 using namespace testing::ext;
25 using namespace OHOS::NFC;
26 class NdefBtDataParserTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp();
31 void TearDown();
32 };
33
SetUpTestCase()34 void NdefBtDataParserTest::SetUpTestCase()
35 {
36 std::cout << " SetUpTestCase NdefBtDataParserTest." << std::endl;
37 }
38
TearDownTestCase()39 void NdefBtDataParserTest::TearDownTestCase()
40 {
41 std::cout << " TearDownTestCase NdefBtDataParserTest." << std::endl;
42 }
43
SetUp()44 void NdefBtDataParserTest::SetUp()
45 {
46 std::cout << " SetUp NdefBtDataParserTest." << std::endl;
47 }
48
TearDown()49 void NdefBtDataParserTest::TearDown()
50 {
51 std::cout << " TearDown NdefBtDataParserTest." << std::endl;
52 }
53
54 /**
55 * @tc.name: CheckBtRecord001
56 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
57 * @tc.type: FUNC
58 */
59 HWTEST_F(NdefBtDataParserTest, CheckBtRecord001, TestSize.Level1)
60 {
61 std::string msg = "";
62 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
63 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
64 ASSERT_TRUE(btData != nullptr);
65 }
66
67 /**
68 * @tc.name: CheckBtRecord002
69 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
70 * @tc.type: FUNC
71 */
72 HWTEST_F(NdefBtDataParserTest, CheckBtRecord002, TestSize.Level1)
73 {
74 std::string msg = "CheckBtRecord";
75 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
76 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
77 ASSERT_TRUE(btData != nullptr);
78 }
79
80 /**
81 * @tc.name: CheckBtRecord003
82 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
83 * @tc.type: FUNC
84 */
85 HWTEST_F(NdefBtDataParserTest, CheckBtRecord003, TestSize.Level1)
86 {
87 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
88 "702E6F6F625600BE17010E7F04050949435341040D14042C0B030B110C11"
89 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
90 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
91 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
92 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
93 ASSERT_TRUE(btData != nullptr);
94 }
95
96 /**
97 * @tc.name: CheckBtRecord0003
98 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
99 * @tc.type: FUNC
100 */
101 HWTEST_F(NdefBtDataParserTest, CheckBtRecord0003, TestSize.Level1)
102 {
103 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
104 "702E6F6F625600BE17010E7F04050949435341040D14042C0B030B110C11"
105 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
106 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
107 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
108 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
109 ASSERT_TRUE(btData != nullptr);
110 }
111
112 /**
113 * @tc.name: CheckBtRecord0004
114 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
115 * @tc.type: FUNC
116 */
117 HWTEST_F(NdefBtDataParserTest, CheckBtRecord0004, TestSize.Level1)
118 {
119 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
120 "702E6F6F625600";
121 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
122 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
123 ASSERT_TRUE(btData != nullptr);
124 }
125
126 /**
127 * @tc.name: CheckBtRecord0005
128 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
129 * @tc.type: FUNC
130 */
131 HWTEST_F(NdefBtDataParserTest, CheckBtRecord0005, TestSize.Level1)
132 {
133 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
134 "702E6F6F625600BE17010E7F04000849435341040D14042C0B030B110C11"
135 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
136 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
137 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
138 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
139 ASSERT_TRUE(btData != nullptr);
140 }
141
142 /**
143 * @tc.name: CheckBtRecord0006
144 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
145 * @tc.type: FUNC
146 */
147 HWTEST_F(NdefBtDataParserTest, CheckBtRecord0006, TestSize.Level1)
148 {
149 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
150 "702E6F6F625600BE17010E7F04050849435341040D14042C0B030B110C11"
151 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
152 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
153 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
154 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
155 ASSERT_TRUE(btData != nullptr);
156 }
157
158 /**
159 * @tc.name: CheckBtRecord0007
160 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
161 * @tc.type: FUNC
162 */
163 HWTEST_F(NdefBtDataParserTest, CheckBtRecord0007, TestSize.Level1)
164 {
165 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
166 "702E6F6F625600BE17010E7F04000949435341040D14042C0B030B110C11"
167 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
168 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
169 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
170 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
171 ASSERT_TRUE(btData != nullptr);
172 }
173
174 /**
175 * @tc.name: CheckBtRecord0008
176 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
177 * @tc.type: FUNC
178 */
179 HWTEST_F(NdefBtDataParserTest, CheckBtRecord0008, TestSize.Level1)
180 {
181 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
182 "702E6F6F625600BE17010E7F04000049435341040D14042C0B030B110C11"
183 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
184 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
185 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
186 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
187 ASSERT_TRUE(btData != nullptr);
188 }
189
190 /**
191 * @tc.name: CheckBtRecord0009
192 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
193 * @tc.type: FUNC
194 */
195 HWTEST_F(NdefBtDataParserTest, CheckBtRecord0009, TestSize.Level1)
196 {
197 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
198 "702E6F6F625600BE17010E7F04010049435341040D14042C0B030B110C11"
199 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
200 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
201 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
202 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
203 ASSERT_TRUE(btData != nullptr);
204 }
205
206 /**
207 * @tc.name: CheckBtRecord004
208 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
209 * @tc.type: FUNC
210 */
211 HWTEST_F(NdefBtDataParserTest, CheckBtRecord004, TestSize.Level1)
212 {
213 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E65"
214 "701E6F6F625600BE17010E7F04050949435341040D14042C0B030B110C11"
215 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
216 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
217 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
218 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
219 ASSERT_TRUE(btData != nullptr);
220 }
221
222 /**
223 * @tc.name: CheckBtRecord005
224 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
225 * @tc.type: FUNC
226 */
227 HWTEST_F(NdefBtDataParserTest, CheckBtRecord005, TestSize.Level1)
228 {
229 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E60"
230 "702E6F6F625600BE17010E7F04050949435341040D14042C0B030B110C11"
231 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
232 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
233 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
234 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
235 ASSERT_TRUE(btData != nullptr);
236 }
237
238 /**
239 * @tc.name: CheckBtRecord006
240 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
241 * @tc.type: FUNC
242 */
243 HWTEST_F(NdefBtDataParserTest, CheckBtRecord006, TestSize.Level1)
244 {
245 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E6C"
246 "652E6F6F625600BE17010E7F04050949435341040D14042C0B030B110C11"
247 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
248 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
249 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
250 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
251 ASSERT_TRUE(btData != nullptr);
252 }
253
254 /**
255 * @tc.name: CheckBtRecord007
256 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
257 * @tc.type: FUNC
258 */
259 HWTEST_F(NdefBtDataParserTest, CheckBtRecord007, TestSize.Level1)
260 {
261 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E6C"
262 "650E6F6F625600BE17010E7F04050949435341040D14042C0B030B110C11"
263 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
264 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
265 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
266 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
267 ASSERT_TRUE(btData != nullptr);
268 }
269
270 /**
271 * @tc.name: CheckBtRecord008
272 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
273 * @tc.type: FUNC
274 */
275 HWTEST_F(NdefBtDataParserTest, CheckBtRecord008, TestSize.Level1)
276 {
277 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E60"
278 "650E6F6F625600BE17010E7F04050949435341040D14042C0B030B110C11"
279 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
280 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
281 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
282 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
283 ASSERT_TRUE(btData != nullptr);
284 }
285
286 /**
287 * @tc.name: CheckBtRecord009
288 * @tc.desc: Test NdefBtDataParserTest CheckBtRecord.
289 * @tc.type: FUNC
290 */
291 HWTEST_F(NdefBtDataParserTest, CheckBtRecord009, TestSize.Level1)
292 {
293 std::string msg = "D220566170706C69636174696F6E2F766E642E626C7565746F6F74682E60"
294 "701E6F6F625600BE17010E7F04050949435341040D14042C0B030B110C11"
295 "0E111E11001236FF027D0320010240005A45303031810800113000190103"
296 "021901010101020306047F0E0117BE020E52726364687A5238363739393532";
297 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
298 std::shared_ptr<BtData> btData = ndefBtDataParser->CheckBtRecord(msg);
299 ASSERT_TRUE(btData != nullptr);
300 }
301
302 /**
303 * @tc.name: IsVendorPayloadValid001
304 * @tc.desc: Test NdefBtDataParserTest IsVendorPayloadValid.
305 * @tc.type: FUNC
306 */
307 HWTEST_F(NdefBtDataParserTest, IsVendorPayloadValid001, TestSize.Level1)
308 {
309 std::string msg = "1";
310 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
311 bool ret = ndefBtDataParser->IsVendorPayloadValid(msg);
312 ASSERT_TRUE(!ret);
313 }
314
315 /**
316 * @tc.name: IsVendorPayloadValid002
317 * @tc.desc: Test NdefBtDataParserTest IsVendorPayloadValid.
318 * @tc.type: FUNC
319 */
320 HWTEST_F(NdefBtDataParserTest, IsVendorPayloadValid002, TestSize.Level1)
321 {
322 std::string msg(600, '1');
323 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
324 bool ret = ndefBtDataParser->IsVendorPayloadValid(msg);
325 ASSERT_TRUE(!ret);
326 }
327
328 /**
329 * @tc.name: IsVendorPayloadValid003
330 * @tc.desc: Test NdefBtDataParserTest IsVendorPayloadValid.
331 * @tc.type: FUNC
332 */
333 HWTEST_F(NdefBtDataParserTest, IsVendorPayloadValid003, TestSize.Level1)
334 {
335 std::string msg = "test";
336 std::shared_ptr<NdefBtDataParser> ndefBtDataParser = std::make_shared<NdefBtDataParser>();
337 bool ret = ndefBtDataParser->IsVendorPayloadValid(msg);
338 ASSERT_TRUE(ret);
339 }
340 } // namespace TEST
341 } // namespace TAG
342 } // namespace NFC
343 } // namespace OHOS