@@ -298,6 +298,51 @@ 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 = container_of (list -> head -> next , list_node_item_t , node );
321+ ASSERT_TEST (list -> length == 2 && item -> val == 1 ,
322+ "Push back second node and order preserved " );
323+
324+
325+ list_pushback (list , & third .node );
326+ item = container_of (list -> head -> next , list_node_item_t , node );
327+ ASSERT_TEST ( list -> length == 3 && item -> val == 3 ,
328+ "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 == 2 ,
334+ "Remove second node " );
335+
336+ /* Remove non-existing node (second time) */
337+
338+ item = container_of (list_pop (list ), list_node_item_t , node );
339+ ASSERT_TEST (list -> length == 2 && item -> val == 1 ,
340+ "Pop node " );
341+
342+ list_clear (list );
343+ ASSERT_TEST (list_is_empty (list ) , "List is cleared " );
344+ }
345+
301346void test_runner (void )
302347{
303348 printf ("\n=== LibC Test Suite ===\n" );
0 commit comments