1- /* LibC Test Suite - Comprehensive tests for standard library functions .
1+ /* Utility Test Suite - Comprehensive tests for utilities and helpers .
22 *
33 * Current Coverage:
44 * - vsnprintf/snprintf: Buffer overflow protection
55 * * C99 semantics, truncation behavior, ISR safety
66 * * Format specifiers: %s, %d, %u, %x, %p, %c, %%
77 * * Edge cases: size=0, size=1, truncation, null termination
88 *
9+ * - list operations: pushback node, remove node
10+ *
911 * Future Tests (Planned):
1012 * - String functions: strlen, strcmp, strcpy, strncpy, memcpy, memset
1113 * - Memory allocation: malloc, free, realloc
@@ -298,6 +300,51 @@ void test_mixed_formats(void)
298300 ASSERT_TEST (buf [test_strlen (buf )] == '\0' , "Mixed format null termination" );
299301}
300302
303+ /* Test 11: List node helpers behavior */
304+ void test_list_node_pushback_and_remove (void )
305+ {
306+ list_node_t node1 = {0 };
307+ list_node_t node2 = {0 };
308+
309+ node1 .next = & node2 ; /* make node1 artificially “linked” */
310+ list_t * list = list_create ();
311+
312+ /* Check node push back normally - unlinked and linked */
313+ list_pushback_node (list , & node1 );
314+ ASSERT_TEST (list_is_empty (list ), "Linked node pushback fail" );
315+
316+ node1 .next = NULL ;
317+ list_pushback_node (list , & node1 );
318+ ASSERT_TEST (list -> length == 1 , "Unlinked node pushback success " );
319+ ASSERT_TEST (list -> head -> next == & node1 && node1 .next == list -> tail ,
320+ "List consistent after pushback first node " );
321+
322+ /* Check node push back order */
323+ node2 .next = NULL ;
324+ list_pushback_node (list , & node2 );
325+ ASSERT_TEST (list -> length == 2 && list -> head -> next == & node1 &&
326+ node1 .next == & node2 && node2 .next == list -> tail ,
327+ "Insertion order preserved " );
328+
329+ /* Remove last node */
330+ list_remove_node (list , & node2 );
331+ ASSERT_TEST (
332+ list -> length == 1 && node2 .next == NULL && node1 .next == list -> tail ,
333+ "Removing last node must keep list structure consistent" );
334+
335+ /* Remove non-existing node (second time) */
336+ list_remove_node (list , & node2 );
337+ ASSERT_TEST (
338+ list -> length == 1 && node2 .next == NULL && node1 .next == list -> tail ,
339+ "Removing non-existing node must not change the list" );
340+
341+ /* Remove only node */
342+ list_remove_node (list , & node1 );
343+ ASSERT_TEST (list -> length == 0 && list -> head -> next == list -> tail ,
344+ "Removing only node " );
345+ ASSERT_TEST (list_is_empty (list ), "Empty list check " );
346+ }
347+
301348void test_runner (void )
302349{
303350 printf ("\n=== LibC Test Suite ===\n" );
@@ -314,6 +361,10 @@ void test_runner(void)
314361 test_isr_safety ();
315362 test_mixed_formats ();
316363
364+
365+ printf ("\n=== List Test Suite ===\n" );
366+ test_list_node_pushback_and_remove ();
367+
317368 printf ("\n=== Test Summary ===\n" );
318369 printf ("Tests run: %d\n" , tests_run );
319370 printf ("Tests passed: %d\n" , tests_passed );
0 commit comments