Skip to content

Commit 31cc477

Browse files
committed
- Added unittest for empty span iteration.
1 parent 99730ed commit 31cc477

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/processing/byte_buffer_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,28 @@ TEST(ByteBufferTest, Iterate_ReadOnlyVariableSize_TraversesInOrder) {
247247
EXPECT_FALSE(buffer.GetIsInitializedFromSpan());
248248
}
249249

250+
TEST(ByteBufferTest, Iterate_ReadOnlyEmptySpan_VisitsNoElements) {
251+
std::vector<uint8_t> empty_bytes;
252+
253+
// Fixed-size empty span.
254+
ByteBufferTestProxy fixed_buffer(tcb::span<const uint8_t>(empty_bytes), 2);
255+
size_t fixed_count = 0;
256+
for (const auto element : fixed_buffer) {
257+
(void)element;
258+
++fixed_count;
259+
}
260+
EXPECT_EQ(fixed_count, 0u);
261+
262+
// Variable-size empty span.
263+
ByteBufferTestProxy variable_buffer{tcb::span<const uint8_t>(empty_bytes)};
264+
size_t variable_count = 0;
265+
for (const auto element : variable_buffer) {
266+
(void)element;
267+
++variable_count;
268+
}
269+
EXPECT_EQ(variable_count, 0u);
270+
}
271+
250272
TEST(ByteBufferTest, GetElement_OutOfRange_Throws) {
251273
std::vector<uint8_t> bytes = {0x01, 0x02, 0x03, 0x04};
252274
ByteBufferTestProxy buffer(tcb::span<const uint8_t>(bytes), 2);

0 commit comments

Comments
 (0)