@@ -298,6 +298,49 @@ void test_mixed_formats(void)
298298 ASSERT_TEST (buf [test_strlen (buf )] == '\0' , "Mixed format null termination" );
299299}
300300
301+ /* Test 11: List helpers behavior */
302+ typedef struct {
303+ int val ;
304+ list_node_t node ;
305+ } list_node_item_t ;
306+
307+ void test_list_pushback_and_remove (void )
308+ {
309+ list_t * list = list_create ();
310+
311+ list_node_item_t first = {.node .next = NULL , .val = 1 };
312+ list_node_item_t second = {.node .next = NULL , .val = 2 };
313+ list_node_item_t third = {.node .next = NULL , .val = 3 };
314+
315+ /* Check node push back normally - unlinked and linked */
316+ list_pushback (list , & first .node );
317+ ASSERT_TEST (list -> length == 1 , "Push back first node " );
318+
319+ list_pushback (list , & second .node );
320+ list_node_item_t * item =
321+ container_of (list -> head -> next , list_node_item_t , node );
322+ ASSERT_TEST (list -> length == 2 && item -> val == 1 ,
323+ "Push back second node and order preserved " );
324+
325+
326+ list_pushback (list , & third .node );
327+ item = container_of (list -> head -> next -> next -> next , list_node_item_t , node );
328+ ASSERT_TEST (list -> length == 3 && item -> val == 3 , "Push back third node " );
329+
330+ /* Remove second node */
331+ list_remove (list , & second .node );
332+ item = container_of (list -> head -> next , list_node_item_t , node );
333+ ASSERT_TEST (list -> length == 2 && item -> val == 1 , "Remove second node " );
334+
335+ /* Remove non-existing node (second time) */
336+
337+ item = container_of (list_pop (list ), list_node_item_t , node );
338+ ASSERT_TEST (list -> length == 1 && item -> val == 1 , "Pop node " );
339+
340+ list_clear (list );
341+ ASSERT_TEST (list_is_empty (list ), "List is cleared " );
342+ }
343+
301344void test_runner (void )
302345{
303346 printf ("\n=== LibC Test Suite ===\n" );
@@ -313,6 +356,7 @@ void test_runner(void)
313356 test_buffer_boundaries ();
314357 test_isr_safety ();
315358 test_mixed_formats ();
359+ test_list_pushback_and_remove ();
316360
317361 printf ("\n=== Test Summary ===\n" );
318362 printf ("Tests run: %d\n" , tests_run );
0 commit comments