LCOV - code coverage report
Current view: top level - ccan/list/test - run-list_prev-list_next.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 32 32 100.0 %
Date: 2024-01-02 21:04:04 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : #include <ccan/list/list.h>
       2                 :            : #include <ccan/tap/tap.h>
       3                 :            : #include <ccan/list/list.c>
       4                 :            : #include "helper.h"
       5                 :            : 
       6                 :            : struct parent {
       7                 :            :         const char *name;
       8                 :            :         unsigned int num_children;
       9                 :            :         struct list_head children;
      10                 :            : };
      11                 :            : 
      12                 :            : struct child {
      13                 :            :         const char *name;
      14                 :            :         struct list_node list;
      15                 :            : };
      16                 :            : 
      17                 :         10 : int main(void)
      18                 :            : {
      19                 :            :         struct parent parent;
      20                 :            :         struct child c1, c2, c3;
      21                 :            :         const struct parent *p;
      22                 :            :         const struct child *c;
      23                 :            : 
      24                 :            :         plan_tests(20);
      25                 :         10 :         parent.num_children = 0;
      26                 :         10 :         list_head_init(&parent.children);
      27                 :            : 
      28                 :         10 :         c1.name = "c1";
      29                 :         10 :         list_add(&parent.children, &c1.list);
      30                 :            : 
      31                 :         10 :         ok1(list_next(&parent.children, &c1, list) == NULL);
      32                 :         10 :         ok1(list_prev(&parent.children, &c1, list) == NULL);
      33                 :            : 
      34                 :         10 :         c2.name = "c2";
      35                 :         10 :         list_add_tail(&parent.children, &c2.list);
      36                 :            : 
      37                 :         10 :         ok1(list_next(&parent.children, &c1, list) == &c2);
      38                 :         10 :         ok1(list_prev(&parent.children, &c1, list) == NULL);
      39                 :         10 :         ok1(list_next(&parent.children, &c2, list) == NULL);
      40                 :         10 :         ok1(list_prev(&parent.children, &c2, list) == &c1);
      41                 :            : 
      42                 :         10 :         c3.name = "c3";
      43                 :         10 :         list_add_tail(&parent.children, &c3.list);
      44                 :            : 
      45                 :         10 :         ok1(list_next(&parent.children, &c1, list) == &c2);
      46                 :         10 :         ok1(list_prev(&parent.children, &c1, list) == NULL);
      47                 :         10 :         ok1(list_next(&parent.children, &c2, list) == &c3);
      48                 :         10 :         ok1(list_prev(&parent.children, &c2, list) == &c1);
      49                 :         10 :         ok1(list_next(&parent.children, &c3, list) == NULL);
      50                 :         10 :         ok1(list_prev(&parent.children, &c3, list) == &c2);
      51                 :            : 
      52                 :            :         /* Const variants */
      53                 :         10 :         p = &parent;
      54                 :         10 :         c = &c2;
      55                 :         10 :         ok1(list_next(&p->children, &c1, list) == &c2);
      56                 :         10 :         ok1(list_prev(&p->children, &c1, list) == NULL);
      57                 :         10 :         ok1(list_next(&p->children, c, list) == &c3);
      58                 :         10 :         ok1(list_prev(&p->children, c, list) == &c1);
      59                 :         10 :         ok1(list_next(&parent.children, c, list) == &c3);
      60                 :         10 :         ok1(list_prev(&parent.children, c, list) == &c1);
      61                 :         10 :         ok1(list_next(&p->children, &c3, list) == NULL);
      62                 :         10 :         ok1(list_prev(&p->children, &c3, list) == &c2);
      63                 :            : 
      64                 :         10 :         return exit_status();
      65                 :            : }

Generated by: LCOV version 1.14