@@ -160,38 +160,47 @@ void test_udpard_fragment_gather()
160160 const udpard_mem_deleter_t del_payload = instrumented_allocator_make_deleter (&alloc_payload);
161161
162162 // Test 1: NULL fragment returns 0.
163- char buf[100 ]; // NOLINT(*-avoid-c-arrays)
164- TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (nullptr , 0 , sizeof (buf), static_cast <void *>(buf)));
163+ char buf[100 ]; // NOLINT(*-avoid-c-arrays)
164+ const udpard_fragment_t * null_frag = nullptr ;
165+ TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (&null_frag, 0 , sizeof (buf), static_cast <void *>(buf)));
165166
166167 // Test 2: NULL destination returns 0.
167168 udpard_fragment_t * const single = make_test_fragment (mem_frag, mem_payload, del_payload, 0 , 5 , " hello" );
168169 TEST_ASSERT_NOT_NULL (single);
169- single->index_offset .up = nullptr ;
170- single->index_offset .lr [0 ] = nullptr ;
171- single->index_offset .lr [1 ] = nullptr ;
172- single->index_offset .bf = 0 ;
173- TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (single, 0 , sizeof (buf), nullptr ));
170+ single->index_offset .up = nullptr ;
171+ single->index_offset .lr [0 ] = nullptr ;
172+ single->index_offset .lr [1 ] = nullptr ;
173+ single->index_offset .bf = 0 ;
174+ const udpard_fragment_t * cursor = single;
175+ TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (&cursor, 0 , sizeof (buf), nullptr ));
176+ TEST_ASSERT_EQUAL_PTR (single, cursor);
174177
175178 // Test 3: Single fragment - gather all.
176179 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
177- TEST_ASSERT_EQUAL_size_t (5 , udpard_fragment_gather (single, 0 , sizeof (buf), static_cast <void *>(buf)));
180+ cursor = single;
181+ TEST_ASSERT_EQUAL_size_t (5 , udpard_fragment_gather (&cursor, 0 , sizeof (buf), static_cast <void *>(buf)));
178182 TEST_ASSERT_EQUAL_MEMORY (" hello" , buf, 5 );
183+ TEST_ASSERT_EQUAL_PTR (single, cursor);
179184
180185 // Test 4: Single fragment - truncation (destination smaller than fragment).
181186 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
182- TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (single, 0 , 3 , static_cast <void *>(buf)));
187+ cursor = single;
188+ TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (&cursor, 0 , 3 , static_cast <void *>(buf)));
183189 TEST_ASSERT_EQUAL_MEMORY (" hel" , buf, 3 );
190+ TEST_ASSERT_EQUAL_PTR (single, cursor);
184191
185192 // Test 5: Single fragment - offset into the payload.
186193 (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)));
194+ cursor = single;
195+ TEST_ASSERT_EQUAL_size_t (2 , udpard_fragment_gather (&cursor, 2 , 2 , static_cast <void *>(buf)));
188196 TEST_ASSERT_EQUAL_MEMORY (" ll" , buf, 2 );
197+ TEST_ASSERT_EQUAL_PTR (single, cursor);
189198
190199 // Cleanup single fragment.
191200 mem_payload.free (mem_payload.user , single->origin .size , single->origin .data );
192201 mem_frag.free (mem_frag.user , sizeof (udpard_fragment_t ), single);
193202
194- // Test 5 : Multiple fragments forming a tree.
203+ // Test 6 : Multiple fragments forming a tree.
195204 // Create tree: root at offset 5 ("MID"), left at offset 0 ("ABCDE"), right at offset 8 ("WXYZ")
196205 // Total payload when gathered: "ABCDE" + "MID" + "WXYZ" = "ABCDEMIDWXYZ" (12 bytes)
197206 udpard_fragment_t * const root = make_test_fragment (mem_frag, mem_payload, del_payload, 5 , 3 , " MID" );
@@ -219,50 +228,70 @@ void test_udpard_fragment_gather()
219228
220229 // Gather from root - should collect all fragments in order.
221230 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
222- TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (root, 0 , sizeof (buf), static_cast <void *>(buf)));
231+ cursor = root;
232+ TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (&cursor, 0 , sizeof (buf), static_cast <void *>(buf)));
223233 TEST_ASSERT_EQUAL_MEMORY (" ABCDEMIDWXYZ" , buf, 12 );
234+ TEST_ASSERT_EQUAL_PTR (right, cursor);
224235
225236 // Gather from left child - should still collect all fragments (traverses to root first).
226237 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
227- TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (left, 0 , sizeof (buf), static_cast <void *>(buf)));
238+ cursor = left;
239+ TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (&cursor, 0 , sizeof (buf), static_cast <void *>(buf)));
228240 TEST_ASSERT_EQUAL_MEMORY (" ABCDEMIDWXYZ" , buf, 12 );
241+ TEST_ASSERT_EQUAL_PTR (right, cursor);
229242
230243 // Gather from right child - should still collect all fragments.
231244 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
232- TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (right, 0 , sizeof (buf), static_cast <void *>(buf)));
245+ cursor = right;
246+ TEST_ASSERT_EQUAL_size_t (12 , udpard_fragment_gather (&cursor, 0 , sizeof (buf), static_cast <void *>(buf)));
233247 TEST_ASSERT_EQUAL_MEMORY (" ABCDEMIDWXYZ" , buf, 12 );
248+ TEST_ASSERT_EQUAL_PTR (right, cursor);
234249
235- // Test 6 : Truncation with multiple fragments - buffer smaller than total.
250+ // Test 7 : Truncation with multiple fragments - buffer smaller than total.
236251 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
237- TEST_ASSERT_EQUAL_size_t (7 , udpard_fragment_gather (root, 0 , 7 , static_cast <void *>(buf)));
252+ cursor = root;
253+ TEST_ASSERT_EQUAL_size_t (7 , udpard_fragment_gather (&cursor, 0 , 7 , static_cast <void *>(buf)));
238254 TEST_ASSERT_EQUAL_MEMORY (" ABCDEMI" , buf, 7 );
255+ TEST_ASSERT_EQUAL_PTR (root, cursor);
239256
240- // Test 7 : Truncation mid-fragment.
257+ // Test 8 : Truncation mid-fragment.
241258 (void )std::memset (static_cast <void *>(buf), 0 , sizeof (buf));
242- TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (root, 0 , 3 , static_cast <void *>(buf)));
259+ cursor = root;
260+ TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (&cursor, 0 , 3 , static_cast <void *>(buf)));
243261 TEST_ASSERT_EQUAL_MEMORY (" ABC" , buf, 3 );
262+ TEST_ASSERT_EQUAL_PTR (left, cursor);
244263
245- // Test 8 : Offset across fragments.
264+ // Test 9 : Offset across fragments.
246265 (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)));
266+ cursor = root;
267+ TEST_ASSERT_EQUAL_size_t (6 , udpard_fragment_gather (&cursor, 2 , 6 , static_cast <void *>(buf)));
248268 TEST_ASSERT_EQUAL_MEMORY (" CDEMID" , buf, 6 );
269+ TEST_ASSERT_EQUAL_PTR (root, cursor);
249270
250- // Test 9 : Start on fragment boundary, span into next.
271+ // Test 10 : Start on fragment boundary, span into next.
251272 (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)));
273+ cursor = root;
274+ TEST_ASSERT_EQUAL_size_t (5 , udpard_fragment_gather (&cursor, 5 , 5 , static_cast <void *>(buf)));
253275 TEST_ASSERT_EQUAL_MEMORY (" MIDWX" , buf, 5 );
276+ TEST_ASSERT_EQUAL_PTR (right, cursor);
254277
255- // Test 10 : Start inside last fragment with request beyond stored data.
278+ // Test 11 : Start inside last fragment with request beyond stored data.
256279 (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)));
280+ cursor = root;
281+ TEST_ASSERT_EQUAL_size_t (3 , udpard_fragment_gather (&cursor, 9 , 10 , static_cast <void *>(buf)));
258282 TEST_ASSERT_EQUAL_MEMORY (" XYZ" , buf, 3 );
283+ TEST_ASSERT_EQUAL_PTR (right, cursor);
259284
260- // Test 11 : Offset beyond available payload.
285+ // Test 12 : Offset beyond available payload.
261286 (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)));
287+ cursor = root;
288+ TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (&cursor, 100 , sizeof (buf), static_cast <void *>(buf)));
289+ TEST_ASSERT_EQUAL_PTR (root, cursor);
290+
291+ // Test 13: Zero-size destination.
292+ cursor = root;
293+ TEST_ASSERT_EQUAL_size_t (0 , udpard_fragment_gather (&cursor, 0 , 0 , static_cast <void *>(buf)));
294+ TEST_ASSERT_EQUAL_PTR (root, cursor);
266295
267296 // Cleanup.
268297 mem_payload.free (mem_payload.user , left->origin .size , left->origin .data );
0 commit comments