minor code changes

Sun, 03 Oct 2021 10:43:31 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 03 Oct 2021 10:43:31 +0200
changeset 449
68ad5750ba6b
parent 448
37c5d2fdb36b
child 450
7960298039cf

minor code changes

These changes do not affect program behavior.

test/test_list.c file | annotate | diff | comparison | revisions
test/test_tree.c file | annotate | diff | comparison | revisions
     1.1 --- a/test/test_list.c	Tue Sep 28 18:49:12 2021 +0200
     1.2 +++ b/test/test_list.c	Sun Oct 03 10:43:31 2021 +0200
     1.3 @@ -80,96 +80,96 @@
     1.4      d.prev = &c;
     1.5      d.next = NULL;
     1.6  
     1.7 -    CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&a, 0, loc_next, 0));
     1.8 -    CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&a, 0, loc_next, 1));
     1.9 -    CU_ASSERT_PTR_EQUAL(&c, cx_linked_list_at(&a, 0, loc_next, 2));
    1.10 -    CU_ASSERT_PTR_EQUAL(&d, cx_linked_list_at(&a, 0, loc_next, 3));
    1.11 -    CU_ASSERT_PTR_NULL(cx_linked_list_at(&a, 0, loc_next, 4));
    1.12 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 0), &a)
    1.13 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 1), &b)
    1.14 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 2), &c)
    1.15 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&a, 0, loc_next, 3), &d)
    1.16 +    CU_ASSERT_PTR_NULL(cx_linked_list_at(&a, 0, loc_next, 4))
    1.17  
    1.18 -    CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&b, 1, loc_prev, 0));
    1.19 -    CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&b, 1, loc_next, 1));
    1.20 -    CU_ASSERT_PTR_EQUAL(&c, cx_linked_list_at(&b, 1, loc_next, 2));
    1.21 -    CU_ASSERT_PTR_EQUAL(&d, cx_linked_list_at(&b, 1, loc_next, 3));
    1.22 -    CU_ASSERT_PTR_NULL(cx_linked_list_at(&b, 1, loc_next, 4));
    1.23 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_prev, 0), &a)
    1.24 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 1), &b)
    1.25 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 2), &c)
    1.26 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&b, 1, loc_next, 3), &d)
    1.27 +    CU_ASSERT_PTR_NULL(cx_linked_list_at(&b, 1, loc_next, 4))
    1.28  
    1.29 -    CU_ASSERT_PTR_EQUAL(&a, cx_linked_list_at(&d, 3, loc_prev, 0));
    1.30 -    CU_ASSERT_PTR_EQUAL(&b, cx_linked_list_at(&d, 3, loc_prev, 1));
    1.31 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 0), &a)
    1.32 +    CU_ASSERT_PTR_EQUAL(cx_linked_list_at(&d, 3, loc_prev, 1), &b)
    1.33  }
    1.34  
    1.35  void test_linked_list_add(void) {
    1.36      struct node {
    1.37          void *prev;
    1.38          void *next;
    1.39 -        int value;
    1.40      };
    1.41 -    
    1.42 +
    1.43      struct node nodes[4];
    1.44 -    
    1.45 +
    1.46      // test with begin, end / prev, next
    1.47 -    memset(nodes, 0, 4*sizeof(struct node));
    1.48 +    memset(nodes, 0, 4 * sizeof(struct node));
    1.49      void *begin = NULL;
    1.50      void *end = NULL;
    1.51 -    
    1.52 +
    1.53      ptrdiff_t loc_prev = offsetof(struct node, prev);
    1.54      ptrdiff_t loc_next = offsetof(struct node, next);
    1.55 -    
    1.56 +
    1.57      int ret;
    1.58      ret = cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]);
    1.59 -    CU_ASSERT_EQUAL(ret, 0);
    1.60 -    CU_ASSERT_PTR_EQUAL(begin, &nodes[0]);
    1.61 -    CU_ASSERT_PTR_EQUAL(end, &nodes[0]);
    1.62 -    CU_ASSERT_PTR_EQUAL(nodes[0].prev, NULL);
    1.63 -    CU_ASSERT_PTR_EQUAL(nodes[0].next, NULL);
    1.64 -    
    1.65 +    CU_ASSERT_EQUAL(ret, 0)
    1.66 +    CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
    1.67 +    CU_ASSERT_PTR_EQUAL(end, &nodes[0])
    1.68 +    CU_ASSERT_PTR_EQUAL(nodes[0].prev, NULL)
    1.69 +    CU_ASSERT_PTR_EQUAL(nodes[0].next, NULL)
    1.70 +
    1.71      ret = cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]);
    1.72 -    CU_ASSERT_EQUAL(ret, 0);
    1.73 -    CU_ASSERT_PTR_EQUAL(begin, &nodes[0]);
    1.74 -    CU_ASSERT_PTR_EQUAL(end, &nodes[1]);
    1.75 -    CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]);
    1.76 -    CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]);
    1.77 -    
    1.78 +    CU_ASSERT_EQUAL(ret, 0)
    1.79 +    CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
    1.80 +    CU_ASSERT_PTR_EQUAL(end, &nodes[1])
    1.81 +    CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
    1.82 +    CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
    1.83 +
    1.84      // test with begin only / prev, next
    1.85 -    memset(nodes, 0, 4*sizeof(struct node));
    1.86 +    memset(nodes, 0, 4 * sizeof(struct node));
    1.87      begin = NULL;
    1.88      end = NULL;
    1.89 -    
    1.90 +
    1.91      ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]);
    1.92 -    CU_ASSERT_EQUAL(ret, 0);
    1.93 -    CU_ASSERT_PTR_EQUAL(begin, &nodes[0]);
    1.94 +    CU_ASSERT_EQUAL(ret, 0)
    1.95 +    CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
    1.96      ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]);
    1.97 -    CU_ASSERT_EQUAL(ret, 0);
    1.98 -    CU_ASSERT_PTR_EQUAL(begin, &nodes[0]);
    1.99 -    CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]);
   1.100 -    CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0]);
   1.101 -    
   1.102 +    CU_ASSERT_EQUAL(ret, 0)
   1.103 +    CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
   1.104 +    CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
   1.105 +    CU_ASSERT_PTR_EQUAL(nodes[1].prev, &nodes[0])
   1.106 +
   1.107      ret = cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]);
   1.108 -    CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2]);
   1.109 -    CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1]);
   1.110 -    
   1.111 +    CU_ASSERT_PTR_EQUAL(nodes[1].next, &nodes[2])
   1.112 +    CU_ASSERT_PTR_EQUAL(nodes[2].prev, &nodes[1])
   1.113 +
   1.114      // test with begin, end / next
   1.115 -    memset(nodes, 0, 4*sizeof(struct node));
   1.116 +    memset(nodes, 0, 4 * sizeof(struct node));
   1.117      begin = NULL;
   1.118      end = NULL;
   1.119 -    
   1.120 +
   1.121      ret = cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]);
   1.122 -    CU_ASSERT_EQUAL(ret, 0);
   1.123 -    CU_ASSERT_PTR_EQUAL(begin, &nodes[0]);
   1.124 -    CU_ASSERT_PTR_EQUAL(end, &nodes[0]);
   1.125 +    CU_ASSERT_EQUAL(ret, 0)
   1.126 +    CU_ASSERT_PTR_EQUAL(begin, &nodes[0])
   1.127 +    CU_ASSERT_PTR_EQUAL(end, &nodes[0])
   1.128      ret = cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]);
   1.129 -    CU_ASSERT_PTR_EQUAL(end, &nodes[1]);
   1.130 -    CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1]);
   1.131 -    CU_ASSERT_PTR_EQUAL(nodes[1].prev, NULL);
   1.132 +    CU_ASSERT_EQUAL(ret, 0)
   1.133 +    CU_ASSERT_PTR_EQUAL(end, &nodes[1])
   1.134 +    CU_ASSERT_PTR_EQUAL(nodes[0].next, &nodes[1])
   1.135 +    CU_ASSERT_PTR_NULL(nodes[1].prev)
   1.136  }
   1.137  
   1.138  int main() {
   1.139      CU_pSuite suite = NULL;
   1.140 -    
   1.141 +
   1.142      if (CUE_SUCCESS != CU_initialize_registry()) {
   1.143          return CU_get_error();
   1.144      }
   1.145  
   1.146      suite = CU_add_suite("linked list suite", NULL, NULL);
   1.147 -    
   1.148 +
   1.149      CU_add_test(suite, "linked list: create and destroy", test_linked_list_create);
   1.150      CU_add_test(suite, "linked list: get node at index", test_linked_list_at);
   1.151      CU_add_test(suite, "linked list: add", test_linked_list_add);
     2.1 --- a/test/test_tree.c	Tue Sep 28 18:49:12 2021 +0200
     2.2 +++ b/test/test_tree.c	Sun Oct 03 10:43:31 2021 +0200
     2.3 @@ -40,11 +40,9 @@
     2.4      
     2.5      TestNode *children_begin;
     2.6      TestNode *children_end;
     2.7 -    
     2.8 -    int content;
     2.9  };
    2.10  
    2.11 -void test_cx_tree_add_node() {
    2.12 +void test_cx_tree_add_node(void) {
    2.13      // prepare test tree
    2.14      TestNode root;
    2.15      memset(&root, 0, sizeof(TestNode));
    2.16 @@ -54,8 +52,7 @@
    2.17      root.children_begin = &a;
    2.18      root.children_end = &a;
    2.19      a.parent = &root;
    2.20 -    a.content = 1;
    2.21 -    
    2.22 +
    2.23      // new test nodes
    2.24      TestNode b;
    2.25      memset(&b, 0, sizeof(TestNode));
    2.26 @@ -63,24 +60,22 @@
    2.27      memset(&c, 0, sizeof(TestNode));
    2.28      
    2.29      // test
    2.30 -    b.content = 2;
    2.31      int ret = cx_tree_add_node(&a, offsetof(TestNode, parent), offsetof(TestNode, prev), offsetof(TestNode, next), &b);
    2.32 -    CU_ASSERT_EQUAL(ret, 0);
    2.33 -    CU_ASSERT_PTR_EQUAL(b.parent, &root);
    2.34 -    CU_ASSERT_PTR_EQUAL(b.prev, &a);
    2.35 -    CU_ASSERT_PTR_EQUAL(b.next, NULL);
    2.36 -    CU_ASSERT_PTR_EQUAL(a.next, &b);
    2.37 +    CU_ASSERT_EQUAL(ret, 0)
    2.38 +    CU_ASSERT_PTR_EQUAL(b.parent, &root)
    2.39 +    CU_ASSERT_PTR_EQUAL(b.prev, &a)
    2.40 +    CU_ASSERT_PTR_NULL(b.next)
    2.41 +    CU_ASSERT_PTR_EQUAL(a.next, &b)
    2.42      
    2.43 -    c.content = 3;
    2.44      ret = cx_tree_add_node(&a, -1, -1, offsetof(TestNode, next), &c);
    2.45 -    CU_ASSERT_EQUAL(ret, 0);
    2.46 -    CU_ASSERT_PTR_EQUAL(c.parent, NULL);
    2.47 -    CU_ASSERT_PTR_EQUAL(c.prev, NULL);
    2.48 -    CU_ASSERT_PTR_EQUAL(c.next, NULL);
    2.49 -    CU_ASSERT_PTR_EQUAL(b.next, &c);
    2.50 +    CU_ASSERT_EQUAL(ret, 0)
    2.51 +    CU_ASSERT_PTR_NULL(c.parent)
    2.52 +    CU_ASSERT_PTR_NULL(c.prev)
    2.53 +    CU_ASSERT_PTR_NULL(c.next)
    2.54 +    CU_ASSERT_PTR_EQUAL(b.next, &c)
    2.55  }
    2.56  
    2.57 -void test_cx_tree_add_child_node() {
    2.58 +void test_cx_tree_add_child_node(void) {
    2.59      // prepare test tree
    2.60      TestNode root;
    2.61      memset(&root, 0, sizeof(TestNode));
    2.62 @@ -97,7 +92,6 @@
    2.63      int ret;
    2.64      
    2.65      // test
    2.66 -    a.content = 1;
    2.67      ret = cx_tree_add_child_node(
    2.68              &root,
    2.69              offsetof(TestNode, parent),
    2.70 @@ -106,14 +100,13 @@
    2.71              (void**)&root.children_begin,
    2.72              (void**)&root.children_end,
    2.73              &a);
    2.74 -    CU_ASSERT_EQUAL(ret, 0);
    2.75 -    CU_ASSERT_PTR_EQUAL(root.children_begin, &a);
    2.76 -    CU_ASSERT_PTR_EQUAL(root.children_end, &a);
    2.77 -    CU_ASSERT_PTR_EQUAL(a.parent, &root);
    2.78 -    CU_ASSERT_PTR_EQUAL(a.prev, NULL);
    2.79 -    CU_ASSERT_PTR_EQUAL(a.next, NULL);
    2.80 -    
    2.81 -    b.content = 2;
    2.82 +    CU_ASSERT_EQUAL(ret, 0)
    2.83 +    CU_ASSERT_PTR_EQUAL(root.children_begin, &a)
    2.84 +    CU_ASSERT_PTR_EQUAL(root.children_end, &a)
    2.85 +    CU_ASSERT_PTR_EQUAL(a.parent, &root)
    2.86 +    CU_ASSERT_PTR_NULL(a.prev)
    2.87 +    CU_ASSERT_PTR_NULL(a.next)
    2.88 +
    2.89      ret = cx_tree_add_child_node(
    2.90              &root,
    2.91              offsetof(TestNode, parent),
    2.92 @@ -122,13 +115,13 @@
    2.93              (void**)&root.children_begin,
    2.94              (void**)&root.children_end,
    2.95              &b);
    2.96 -    CU_ASSERT_EQUAL(ret, 0);
    2.97 -    CU_ASSERT_TRUE(root.children_begin ? root.children_begin->next == &b : 0);
    2.98 -    CU_ASSERT_PTR_EQUAL(root.children_end, &b);
    2.99 -    CU_ASSERT_PTR_EQUAL(b.parent, &root);
   2.100 -    CU_ASSERT_PTR_EQUAL(b.prev, &a);
   2.101 +    CU_ASSERT_EQUAL(ret, 0)
   2.102 +    CU_ASSERT_PTR_NOT_NULL(root.children_begin)
   2.103 +    CU_ASSERT_PTR_EQUAL(root.children_begin->next, &b)
   2.104 +    CU_ASSERT_PTR_EQUAL(root.children_end, &b)
   2.105 +    CU_ASSERT_PTR_EQUAL(b.parent, &root)
   2.106 +    CU_ASSERT_PTR_EQUAL(b.prev, &a)
   2.107      
   2.108 -    c.content = 3;
   2.109      ret = cx_tree_add_child_node(
   2.110              &root,
   2.111              -1,
   2.112 @@ -137,14 +130,13 @@
   2.113              (void**)&root.children_begin,
   2.114              NULL,
   2.115              &c);
   2.116 -    CU_ASSERT_EQUAL(ret, 0);
   2.117 -    CU_ASSERT_PTR_EQUAL(root.children_end, &b); // children_end unchanged
   2.118 -    CU_ASSERT_PTR_EQUAL(b.next, &c);
   2.119 -    CU_ASSERT_PTR_EQUAL(c.prev, NULL);
   2.120 -    CU_ASSERT_PTR_EQUAL(c.next, NULL);
   2.121 -    CU_ASSERT_PTR_EQUAL(c.parent, NULL);
   2.122 +    CU_ASSERT_EQUAL(ret, 0)
   2.123 +    CU_ASSERT_PTR_EQUAL(root.children_end, &b) // children_end unchanged
   2.124 +    CU_ASSERT_PTR_EQUAL(b.next, &c)
   2.125 +    CU_ASSERT_PTR_NULL(c.prev)
   2.126 +    CU_ASSERT_PTR_NULL(c.next)
   2.127 +    CU_ASSERT_PTR_NULL(c.parent)
   2.128      
   2.129 -    a1.content = 11;
   2.130      ret = cx_tree_add_child_node(
   2.131              &a,
   2.132              offsetof(TestNode, parent),
   2.133 @@ -156,7 +148,8 @@
   2.134      CU_ASSERT_EQUAL(ret, 0);
   2.135      CU_ASSERT_PTR_EQUAL(a.children_begin, &a1);
   2.136      CU_ASSERT_PTR_EQUAL(a1.parent, &a);
   2.137 -    CU_ASSERT_TRUE(root.children_begin ? root.children_begin->children_begin == &a1 : 0);
   2.138 +    CU_ASSERT_PTR_NOT_NULL(root.children_begin)
   2.139 +    CU_ASSERT_PTR_EQUAL(root.children_begin->children_begin, &a1)
   2.140  }
   2.141  
   2.142  int main() {

mercurial