@@ -162,17 +162,28 @@ TEST_F(TestTLVPacketBufferBackingStore, MultiBufferEncode)
162
162
// Third entry is 1 control byte, 2 length bytes, 2000 bytes of data,
163
163
// for a total of 2009 bytes.
164
164
constexpr size_t totalSize = 2009 ;
165
- EXPECT_EQ (buffer->TotalLength (), totalSize);
166
- EXPECT_EQ (buffer->DataLength (), static_cast <size_t >(2 ));
167
- ASSERT_TRUE (buffer->HasChainedBuffer ());
168
- auto nextBuffer = buffer->Next ();
169
- EXPECT_EQ (nextBuffer->TotalLength (), totalSize - 2 );
170
- EXPECT_EQ (nextBuffer->DataLength (), PacketBuffer::kMaxSizeWithoutReserve );
171
- ASSERT_TRUE (nextBuffer->HasChainedBuffer ());
172
- nextBuffer = nextBuffer->Next ();
173
- EXPECT_EQ (nextBuffer->TotalLength (), nextBuffer->DataLength ());
174
- EXPECT_EQ (nextBuffer->DataLength (), totalSize - 2 - PacketBuffer::kMaxSizeWithoutReserve );
175
- ASSERT_FALSE (nextBuffer->HasChainedBuffer ());
165
+ #if CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_STANDARD_POOL || CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL
166
+ // In case of pool allocation, the buffer size is always the maximum size.
167
+ constexpr size_t bufferSizes[] = { PacketBuffer::kMaxSizeWithoutReserve , totalSize - PacketBuffer::kMaxSizeWithoutReserve };
168
+ #elif CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP
169
+ constexpr size_t bufferSizes[] = { 2 , PacketBuffer::kMaxSizeWithoutReserve ,
170
+ totalSize - 2 - PacketBuffer::kMaxSizeWithoutReserve };
171
+ #else
172
+ // Skipping the test for other configurations because the allocation method is unknown.
173
+ GTEST_SKIP ();
174
+ #endif
175
+ size_t checkedSize = 0 ;
176
+ auto bufferTmp = buffer.Retain ();
177
+ for (const auto size : bufferSizes)
178
+ {
179
+ ASSERT_FALSE (bufferTmp.IsNull ());
180
+ EXPECT_EQ (bufferTmp->TotalLength (), totalSize - checkedSize);
181
+ EXPECT_EQ (bufferTmp->DataLength (), size);
182
+ bufferTmp = bufferTmp->Next ();
183
+ checkedSize += size;
184
+ }
185
+ // There should be no more buffers.
186
+ ASSERT_TRUE (bufferTmp.IsNull ());
176
187
177
188
// PacketBufferTLVReader cannot handle non-contiguous buffers, and our
178
189
// buffers are too big to stick into a single packet buffer.
0 commit comments