1 /******************************************************************************
2 *
3 * Copyright 2017 Google, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include "hci_packet.h"
20 #include "l2cap_packet.h"
21 #include "l2cap_test_packets.h"
22
23 #include <gtest/gtest.h>
24 #include <memory>
25
26 using std::shared_ptr;
27 using std::vector;
28
29 namespace test_vendor_lib {
30
31 class TestPacket : public HciPacket {
32 public:
TestPacket(const std::vector<uint8_t> & packet)33 TestPacket(const std::vector<uint8_t>& packet) {
34 complete_packet_ = packet;
35 }
36 TestPacket() = default;
37
38 private:
39 std::vector<uint8_t> complete_packet_;
get_length()40 size_t get_length() {
41 return complete_packet_.size();
42 }
get_at_index(size_t index)43 uint8_t& get_at_index(size_t index) {
44 return complete_packet_[index];
45 }
46 };
47
48 class L2capTest : public ::testing::Test {
49 public:
update_fcs(vector<uint8_t> sdu)50 std::shared_ptr<L2capSdu> update_fcs(vector<uint8_t> sdu) {
51 sdu.resize(sdu.size() - 2);
52
53 return L2capSdu::L2capSduBuilder(sdu);
54 }
55
compare_packets(shared_ptr<HciPacket> expected,shared_ptr<HciPacket> received)56 void compare_packets(shared_ptr<HciPacket> expected, shared_ptr<HciPacket> received) {
57 Iterator expected_begin = expected->get_begin();
58 Iterator expected_end = expected->get_end();
59
60 Iterator received_begin = received->get_begin();
61 Iterator received_end = received->get_end();
62
63 ASSERT_EQ(expected_end - expected_begin, received_end - received_begin);
64
65 while (expected_begin < expected_end) {
66 ASSERT_EQ(*expected_begin, *received_begin);
67 expected_begin++;
68 received_begin++;
69 }
70 }
71 };
72
TEST_F(L2capTest,assembleGoodPackets)73 TEST_F(L2capTest, assembleGoodPackets) {
74 vector<std::shared_ptr<L2capSdu> > test_packet;
75
76 // Test 1: Pass correct packets.
77 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[0]));
78 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
79 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
80
81 shared_ptr<L2capPacket> test_1 = L2capPacket::assemble(test_packet);
82 ASSERT_NE(test_1, nullptr);
83
84 shared_ptr<TestPacket> expected(new TestPacket(good_l2cap_packet));
85
86 compare_packets(expected, test_1);
87
88 test_packet.clear();
89
90 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_1));
91 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_2));
92 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_3));
93 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_4));
94 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_5));
95 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_6));
96 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_7));
97 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_8));
98 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_9));
99
100 test_1 = L2capPacket::assemble(test_packet);
101 ASSERT_NE(test_1, nullptr);
102
103 expected.reset(new TestPacket(complete_l2cap_packet));
104 compare_packets(expected, test_1);
105
106 test_packet.clear();
107 }
108
TEST_F(L2capTest,assembleOutofOrderPackets)109 TEST_F(L2capTest, assembleOutofOrderPackets) {
110 vector<std::shared_ptr<L2capSdu> > test_packet;
111
112 // Test 2: Pass out of order packets.
113 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
114 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[0]));
115 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
116
117 shared_ptr<L2capPacket> test_2 = L2capPacket::assemble(test_packet);
118 EXPECT_EQ(test_2, nullptr);
119
120 test_packet.clear();
121
122 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_1));
123 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_3));
124 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_2));
125 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_6));
126 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_5));
127 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_4));
128 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_8));
129 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_7));
130 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_9));
131
132 test_2 = L2capPacket::assemble(test_packet);
133 EXPECT_EQ(test_2, nullptr);
134
135 test_packet.clear();
136 }
137
TEST_F(L2capTest,assembleBadControlBytes)138 TEST_F(L2capTest, assembleBadControlBytes) {
139 vector<std::shared_ptr<L2capSdu> > test_packet;
140
141 // Test 3: Pass packets missing the finished control bytes.
142 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[0]));
143 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
144
145 shared_ptr<L2capPacket> test_3 = L2capPacket::assemble(test_packet);
146 EXPECT_EQ(test_3, nullptr);
147
148 test_packet.clear();
149
150 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_1));
151 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_2));
152 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_3));
153 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_4));
154 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_5));
155 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_6));
156 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_7));
157 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_8));
158
159 test_3 = L2capPacket::assemble(test_packet);
160 EXPECT_EQ(test_3, nullptr);
161
162 test_packet.clear();
163 }
164
TEST_F(L2capTest,assembleBadFCS)165 TEST_F(L2capTest, assembleBadFCS) {
166 vector<std::shared_ptr<L2capSdu> > test_packet;
167
168 // Test 4: Pass packets with incorrect frame check sequences.
169 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[0]));
170 good_sdu[1][good_sdu[1].size() - 1]++;
171 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
172 good_sdu[1][good_sdu[1].size() - 1]--;
173 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
174
175 shared_ptr<L2capPacket> test_4 = L2capPacket::assemble(test_packet);
176 EXPECT_EQ(test_4, nullptr);
177
178 test_packet.clear();
179
180 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_1));
181 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_2));
182 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_3));
183 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_4));
184 l2cap_test_packet_5[l2cap_test_packet_5.size() - 1]++;
185 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_5));
186 l2cap_test_packet_5[l2cap_test_packet_5.size() - 1]--;
187 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_6));
188 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_7));
189 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_8));
190 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_9));
191
192 test_4 = L2capPacket::assemble(test_packet);
193 EXPECT_EQ(test_4, nullptr);
194
195 test_packet.clear();
196 }
197
TEST_F(L2capTest,assembleEmptyPayload)198 TEST_F(L2capTest, assembleEmptyPayload) {
199 vector<std::shared_ptr<L2capSdu> > test_packet;
200
201 // Test 5: Pass a packet with an empty payload.
202 test_packet.push_back(L2capSdu::L2capSduConstructor(empty_sdu_payload[0]));
203 test_packet.push_back(L2capSdu::L2capSduConstructor(empty_sdu_payload[1]));
204
205 shared_ptr<L2capPacket> test_5 = L2capPacket::assemble(test_packet);
206 ASSERT_NE(test_5, nullptr);
207
208 shared_ptr<TestPacket> expected(new TestPacket(empty_l2cap_payload));
209 compare_packets(expected, test_5);
210
211 test_packet.clear();
212 }
213
TEST_F(L2capTest,assembleAllStartingControlError)214 TEST_F(L2capTest, assembleAllStartingControlError) {
215 vector<std::shared_ptr<L2capSdu> > test_packet;
216
217 // Test 6: Pass a SDU with all the control bytes set to as the starting bytes.
218 test_packet.push_back(L2capSdu::L2capSduConstructor(all_first_packet[0]));
219 test_packet.push_back(L2capSdu::L2capSduConstructor(all_first_packet[1]));
220 test_packet.push_back(L2capSdu::L2capSduConstructor(all_first_packet[2]));
221
222 shared_ptr<L2capPacket> test_6 = L2capPacket::assemble(test_packet);
223 EXPECT_EQ(test_6, nullptr);
224
225 test_packet.clear();
226 }
227
TEST_F(L2capTest,assembleBadCID)228 TEST_F(L2capTest, assembleBadCID) {
229 vector<std::shared_ptr<L2capSdu> > test_packet;
230
231 // Test 7: Pass SDUs with mixed channel ids.
232 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[0]));
233 good_sdu[1][2]++;
234 test_packet.push_back(update_fcs(good_sdu[1]));
235 good_sdu[1][2]--;
236 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
237
238 shared_ptr<L2capPacket> test_7 = L2capPacket::assemble(test_packet);
239 EXPECT_EQ(test_7, nullptr);
240
241 test_packet.clear();
242
243 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_1));
244 l2cap_test_packet_2[2]++;
245 test_packet.push_back((update_fcs(l2cap_test_packet_2)));
246 l2cap_test_packet_2[2]--;
247 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_3));
248 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_4));
249 l2cap_test_packet_5[2]++;
250 test_packet.push_back((update_fcs(l2cap_test_packet_5)));
251 l2cap_test_packet_5[2]--;
252 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_6));
253 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_7));
254 l2cap_test_packet_8[2]--;
255 test_packet.push_back((update_fcs(l2cap_test_packet_8)));
256 l2cap_test_packet_8[2]++;
257 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_9));
258
259 test_7 = L2capPacket::assemble(test_packet);
260 EXPECT_EQ(test_7, nullptr);
261
262 test_packet.clear();
263 }
264
TEST_F(L2capTest,assembleUnsegmentedSDU)265 TEST_F(L2capTest, assembleUnsegmentedSDU) {
266 vector<std::shared_ptr<L2capSdu> > test_packet;
267
268 // Test 8: Pass a complete l2cap packet.
269 test_packet.push_back(L2capSdu::L2capSduConstructor(one_sdu[0]));
270
271 shared_ptr<L2capPacket> test_8 = L2capPacket::assemble(test_packet);
272 EXPECT_NE(test_8, nullptr);
273
274 test_packet.clear();
275 }
276
TEST_F(L2capTest,assembleBadTxSeq)277 TEST_F(L2capTest, assembleBadTxSeq) {
278 vector<std::shared_ptr<L2capSdu> > test_packet;
279
280 // Test 9: Pass SDUs with incorrect TxSeq.
281 good_sdu[0][4] += 4;
282 test_packet.push_back((update_fcs(good_sdu[0])));
283 good_sdu[0][4] -= 4;
284 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
285 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
286
287 shared_ptr<L2capPacket> test_9 = L2capPacket::assemble(test_packet);
288 EXPECT_EQ(test_9, nullptr);
289
290 test_packet.clear();
291 }
292
TEST_F(L2capTest,assembleBadTotalSDULength)293 TEST_F(L2capTest, assembleBadTotalSDULength) {
294 vector<std::shared_ptr<L2capSdu> > test_packet;
295
296 // Test 10: Pass SDUs with an incorrect total SDU length
297 good_sdu[0][7]++;
298 test_packet.push_back((update_fcs(good_sdu[0])));
299 good_sdu[0][7]--;
300 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
301 test_packet.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
302
303 shared_ptr<L2capPacket> test_10 = L2capPacket::assemble(test_packet);
304 EXPECT_EQ(test_10, nullptr);
305
306 test_packet.clear();
307
308 l2cap_test_packet_1[6]++;
309 test_packet.push_back((update_fcs(l2cap_test_packet_1)));
310 l2cap_test_packet_1[6]--;
311 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_2));
312 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_3));
313 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_4));
314 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_5));
315 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_6));
316 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_7));
317 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_8));
318 test_packet.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_9));
319
320 test_10 = L2capPacket::assemble(test_packet);
321
322 EXPECT_EQ(test_10, nullptr);
323
324 test_packet.clear();
325 }
326
327 // Begin Fragment Test1
TEST_F(L2capTest,fragmentSmallSegmentTest)328 TEST_F(L2capTest, fragmentSmallSegmentTest) {
329 std::vector<std::shared_ptr<L2capSdu> > sdu;
330 std::shared_ptr<L2capPacket> l2cap_expected;
331 std::shared_ptr<L2capPacket> l2cap_received;
332
333 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[0]));
334 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
335 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
336
337 l2cap_expected = L2capPacket::assemble(sdu);
338
339 sdu.clear();
340
341 // Test1: Small segments
342 sdu = l2cap_expected->fragment(16, 0x02, 0x41);
343
344 l2cap_received = L2capPacket::assemble(sdu);
345 ASSERT_NE(l2cap_received, nullptr) << "packet reassembly failed after fragment" << std::endl
346 << "Test1: Small Segment request" << std::endl
347 << "sdu used: good_sdu" << std::endl
348 << "function call: fragment(16, 0x02, 0x41)" << std::endl;
349
350 compare_packets(l2cap_expected, l2cap_received);
351
352 sdu.clear();
353 l2cap_expected.reset();
354 l2cap_received.reset();
355 } // End Fragment Test1
356
357 // Begin Fragment Test2
TEST_F(L2capTest,fragmentLargeSegmentTest)358 TEST_F(L2capTest, fragmentLargeSegmentTest) {
359 std::vector<std::shared_ptr<L2capSdu> > sdu;
360 std::shared_ptr<L2capPacket> l2cap_expected;
361 std::shared_ptr<L2capPacket> l2cap_received;
362
363 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_1));
364 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_2));
365 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_3));
366 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_4));
367 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_5));
368 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_6));
369 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_7));
370 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_8));
371 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_9));
372
373 l2cap_expected = L2capPacket::assemble(sdu);
374
375 sdu.clear();
376
377 // Test2: Large Segments
378 sdu = l2cap_expected->fragment(1024, 0x02, 0x41);
379
380 l2cap_received = L2capPacket::assemble(sdu);
381 ASSERT_NE(l2cap_received, nullptr) << "packet reassembly failed after fragment" << std::endl
382 << "Test2: Large Segment request" << std::endl
383 << "sdu used: l2cap_test_packet[1-9]" << std::endl
384 << "function call: fragment(1024, 0x02, 0x41)" << std::endl;
385
386 compare_packets(l2cap_expected, l2cap_received);
387
388 sdu.clear();
389 l2cap_expected.reset();
390 l2cap_received.reset();
391 } // End Fragment Test2
392
393 // Begin Fragment Test3
TEST_F(L2capTest,fragmentTxSeqTest)394 TEST_F(L2capTest, fragmentTxSeqTest) {
395 std::vector<std::shared_ptr<L2capSdu> > sdu;
396 std::shared_ptr<L2capPacket> l2cap_expected;
397 std::shared_ptr<L2capPacket> l2cap_received;
398
399 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[0]));
400 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
401 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
402
403 l2cap_expected = L2capPacket::assemble(sdu);
404
405 sdu.clear();
406
407 // Test3: Non-zero starting TxSeq
408 sdu = l2cap_expected->fragment(24, 0x08, 0x41);
409
410 l2cap_received = L2capPacket::assemble(sdu);
411 ASSERT_NE(l2cap_received, nullptr) << "packet reassembly failed after fragment" << std::endl
412 << "Test3: Non-zero starting TxSeq" << std::endl
413 << "sdu used: good_sdu" << std::endl
414 << "function call: fragment(24, 0x08, 0x41)" << std::endl;
415
416 compare_packets(l2cap_expected, l2cap_received);
417
418 sdu.clear();
419 l2cap_expected.reset();
420 l2cap_received.reset();
421 } // End Fragment Test3
422
423 // Begin Fragment Test4
TEST_F(L2capTest,fragmentPayloadTest)424 TEST_F(L2capTest, fragmentPayloadTest) {
425 std::vector<std::shared_ptr<L2capSdu> > sdu;
426 std::shared_ptr<L2capPacket> l2cap_expected;
427 std::shared_ptr<L2capPacket> l2cap_received;
428
429 sdu.push_back(L2capSdu::L2capSduConstructor(empty_sdu_payload[0]));
430 sdu.push_back(L2capSdu::L2capSduConstructor(empty_sdu_payload[1]));
431
432 l2cap_expected = L2capPacket::assemble(sdu);
433
434 sdu.clear();
435
436 // Test4: Packet with no payload
437 sdu = l2cap_expected->fragment(16, 0x02, 0x41);
438
439 l2cap_received = L2capPacket::assemble(sdu);
440 ASSERT_NE(l2cap_received, nullptr) << "packet reassembly failed after fragment" << std::endl
441 << "Test4: Packet with no payload" << std::endl
442 << "sdu used: empty_sdu_payload" << std::endl
443 << "function call: fragment(16, 0x02, 0x41)" << std::endl;
444
445 compare_packets(l2cap_expected, l2cap_received);
446
447 sdu.clear();
448 l2cap_expected.reset();
449 l2cap_received.reset();
450 } // End Fragment Test4
451
452 // Begin Fragment Test5
TEST_F(L2capTest,fragmentSegmentSizeTest)453 TEST_F(L2capTest, fragmentSegmentSizeTest) {
454 std::vector<std::shared_ptr<L2capSdu> > sdu;
455 std::shared_ptr<L2capPacket> l2cap_expected;
456 std::shared_ptr<L2capPacket> l2cap_received;
457
458 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[0]));
459 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[1]));
460 sdu.push_back(L2capSdu::L2capSduConstructor(good_sdu[2]));
461
462 l2cap_expected = L2capPacket::assemble(sdu);
463
464 sdu.clear();
465
466 // Test5: Larger segment size than packet size
467 sdu = l2cap_expected->fragment(256, 0x02, 0x41);
468
469 l2cap_received = L2capPacket::assemble(sdu);
470 ASSERT_NE(l2cap_received, nullptr) << "packet reassembly failed after fragment" << std::endl
471 << "Test5: Segment size > Payload" << std::endl
472 << "sdu used: good_sdu" << std::endl
473 << "function call: fragment(256, 0x02, 0x41)" << std::endl;
474
475 compare_packets(l2cap_expected, l2cap_received);
476
477 sdu.clear();
478 l2cap_expected.reset();
479 l2cap_received.reset();
480 } // End Fragment Test5
481
482 // Begin Fragment Test6
TEST_F(L2capTest,fragmentSegmentSizeTest2)483 TEST_F(L2capTest, fragmentSegmentSizeTest2) {
484 std::vector<std::shared_ptr<L2capSdu> > sdu;
485 std::shared_ptr<L2capPacket> l2cap_expected;
486 std::shared_ptr<L2capPacket> l2cap_received;
487
488 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_1));
489 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_2));
490 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_3));
491 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_4));
492 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_5));
493 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_6));
494 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_7));
495 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_8));
496 sdu.push_back(L2capSdu::L2capSduConstructor(l2cap_test_packet_9));
497
498 l2cap_expected = L2capPacket::assemble(sdu);
499 sdu.clear();
500
501 // Test6: Small segment size on large packet.
502 sdu = l2cap_expected->fragment(512, 0x02, 0x41);
503
504 l2cap_received = L2capPacket::assemble(sdu);
505 ASSERT_NE(l2cap_received, nullptr) << "packet reassembly failed after fragment" << std::endl
506 << "Test6: Small Segment request on large packet" << std::endl
507 << "sdu used: l2cap_test_packet_[1-9]" << std::endl
508 << "function call: fragment(64, 0x02, 0x41)" << std::endl;
509
510 compare_packets(l2cap_expected, l2cap_received);
511
512 sdu.clear();
513 l2cap_expected.reset();
514 l2cap_received.reset();
515 } // End Fragment Test6
516
517 } // namespace test_vendor_lib
518