@@ -161,7 +161,7 @@ void test_udpard_fragment_gather()
161161
162162 // Test 1: NULL fragment returns 0.
163163 char buf[100 ]; // NOLINT(*-avoid-c-arrays)
164- TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (nullptr , sizeof (buf), static_cast <void *>(buf)));
164+ TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (nullptr , 0 , sizeof (buf), static_cast <void *>(buf)));
165165
166166 // Test 2: NULL destination returns 0.
167167 udpard_fragment_t * const single = make_test_fragment (mem_frag, mem_payload, del_payload, 0 , 5 , " hello" );
@@ -170,18 +170,23 @@ void test_udpard_fragment_gather()
170170 single->index_offset .lr [0 ] = nullptr ;
171171 single->index_offset .lr [1 ] = nullptr ;
172172 single->index_offset .bf = 0 ;
173- TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (single, sizeof (buf), nullptr ));
173+ TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (single, 0 , sizeof (buf), nullptr ));
174174
175175 // Test 3: Single fragment - gather all.
176176 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
177- TEST_ASSERT_EQUAL_size_t (5 , udpard_fragment_gather (single, sizeof (buf), static_cast <void *>(buf)));
177+ TEST_ASSERT_EQUAL_size_t (5 , udpard_fragment_gather (single, 0 , sizeof (buf), static_cast <void *>(buf)));
178178 TEST_ASSERT_EQUAL_MEMORY (" hello" , buf, 5 );
179179
180180 // Test 4: Single fragment - truncation (destination smaller than fragment).
181181 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
182- TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (single, 3 , static_cast <void *>(buf)));
182+ TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (single, 0 , 3 , static_cast <void *>(buf)));
183183 TEST_ASSERT_EQUAL_MEMORY (" hel" , buf, 3 );
184184
185+ // Test 5: Single fragment - offset into the payload.
186+ (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
187+ TEST_ASSERT_EQUAL_size_t (2 , udpard_fragment_gather (single, 2 , 2 , static_cast <void *>(buf)));
188+ TEST_ASSERT_EQUAL_MEMORY (" ll" , buf, 2 );
189+
185190 // Cleanup single fragment.
186191 mem_payload.free (mem_payload.user , single->origin .size , single->origin .data );
187192 mem_frag.free (mem_frag.user , sizeof (udpard_fragment_t ), single);
@@ -214,31 +219,50 @@ void test_udpard_fragment_gather()
214219
215220 // Gather from root - should collect all fragments in order.
216221 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
217- TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (root, sizeof (buf), static_cast <void *>(buf)));
222+ TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (root, 0 , sizeof (buf), static_cast <void *>(buf)));
218223 TEST_ASSERT_EQUAL_MEMORY (" ABCDEMIDWXYZ" , buf, 12 );
219224
220225 // Gather from left child - should still collect all fragments (traverses to root first).
221226 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
222- TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (left, sizeof (buf), static_cast <void *>(buf)));
227+ TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (left, 0 , sizeof (buf), static_cast <void *>(buf)));
223228 TEST_ASSERT_EQUAL_MEMORY (" ABCDEMIDWXYZ" , buf, 12 );
224229
225230 // Gather from right child - should still collect all fragments.
226231 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
227- TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (right, sizeof (buf), static_cast <void *>(buf)));
232+ TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (right, 0 , sizeof (buf), static_cast <void *>(buf)));
228233 TEST_ASSERT_EQUAL_MEMORY (" ABCDEMIDWXYZ" , buf, 12 );
229234
230235 // Test 6: Truncation with multiple fragments - buffer smaller than total.
231236 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
232- TEST_ASSERT_EQUAL_size_t (7 , udpard_fragment_gather (root, 7 , static_cast <void *>(buf)));
237+ TEST_ASSERT_EQUAL_size_t (7 , udpard_fragment_gather (root, 0 , 7 , static_cast <void *>(buf)));
233238 TEST_ASSERT_EQUAL_MEMORY (" ABCDEMI" , buf, 7 );
234239
235240 // Test 7: Truncation mid-fragment.
236241 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
237- TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (root, 3 , static_cast <void *>(buf)));
242+ TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (root, 0 , 3 , static_cast <void *>(buf)));
238243 TEST_ASSERT_EQUAL_MEMORY (" ABC" , buf, 3 );
239244
240- // Test 8: Zero-size destination.
241- TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (root, 0 , static_cast <void *>(buf)));
245+ // Test 8: Offset across fragments.
246+ (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
247+ TEST_ASSERT_EQUAL_size_t (6 , udpard_fragment_gather (root, 2 , 6 , static_cast <void *>(buf)));
248+ TEST_ASSERT_EQUAL_MEMORY (" CDEMID" , buf, 6 );
249+
250+ // Test 9: Start on fragment boundary, span into next.
251+ (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
252+ TEST_ASSERT_EQUAL_size_t (5 , udpard_fragment_gather (root, 5 , 5 , static_cast <void *>(buf)));
253+ TEST_ASSERT_EQUAL_MEMORY (" MIDWX" , buf, 5 );
254+
255+ // Test 10: Start inside last fragment with request beyond stored data.
256+ (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
257+ TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (root, 9 , 10 , static_cast <void *>(buf)));
258+ TEST_ASSERT_EQUAL_MEMORY (" XYZ" , buf, 3 );
259+
260+ // Test 11: Offset beyond available payload.
261+ (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
262+ TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (root, 100 , sizeof (buf), static_cast <void *>(buf)));
263+
264+ // Test 12: Zero-size destination.
265+ TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (root, 0 , 0 , static_cast <void *>(buf)));
242266
243267 // Cleanup.
244268 mem_payload.free (mem_payload.user , left->origin .size , left->origin .data );
0 commit comments