"Fossies" - the Fresh Open Source Software Archive

Member "vnstat-2.9/tests/iflist_tests.c" (7 Jul 2019, 3032 Bytes) of package /linux/misc/vnstat-2.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include "common.h"
    2 #include "vnstat_tests.h"
    3 #include "iflist_tests.h"
    4 #include "iflist.h"
    5 
    6 START_TEST(iflistfree_can_free_null)
    7 {
    8     iflist *ifl = NULL;
    9     iflistfree(&ifl);
   10 }
   11 END_TEST
   12 
   13 START_TEST(iflistadd_can_add)
   14 {
   15     int ret;
   16     iflist *ifl = NULL;
   17     ck_assert_ptr_eq(ifl, NULL);
   18 
   19     ret = iflistadd(&ifl, "eth0", 0);
   20     ck_assert_int_eq(ret, 1);
   21     ck_assert_str_eq(ifl->interface, "eth0");
   22     ck_assert_int_eq(ifl->bandwidth, 0);
   23     ck_assert_ptr_eq(ifl->next, NULL);
   24 
   25     ret = iflistadd(&ifl, "eth1", 1);
   26     ck_assert_int_eq(ret, 1);
   27     ck_assert_str_eq(ifl->interface, "eth0");
   28     ck_assert_int_eq(ifl->bandwidth, 0);
   29     ck_assert_ptr_ne(ifl->next, NULL);
   30     ck_assert_str_eq(ifl->next->interface, "eth1");
   31     ck_assert_int_eq(ifl->next->bandwidth, 1);
   32 
   33     ret = iflistadd(&ifl, "eth0", 2);
   34     ck_assert_int_eq(ret, 1);
   35     ck_assert_str_eq(ifl->interface, "eth0");
   36     ck_assert_int_eq(ifl->bandwidth, 0);
   37     ck_assert_ptr_ne(ifl->next, NULL);
   38     ck_assert_str_eq(ifl->next->interface, "eth1");
   39     ck_assert_int_eq(ifl->next->bandwidth, 1);
   40     ck_assert_ptr_ne(ifl->next->next, NULL);
   41     ck_assert_str_eq(ifl->next->next->interface, "eth0");
   42     ck_assert_int_eq(ifl->next->next->bandwidth, 2);
   43 
   44     iflistfree(&ifl);
   45     ck_assert_ptr_eq(ifl, NULL);
   46 }
   47 END_TEST
   48 
   49 START_TEST(iflistsearch_can_search)
   50 {
   51     int ret;
   52     iflist *ifl = NULL;
   53     ck_assert_ptr_eq(ifl, NULL);
   54 
   55     ret = iflistsearch(&ifl, "eth0");
   56     ck_assert_int_eq(ret, 0);
   57 
   58     ret = iflistadd(&ifl, "eth0", 0);
   59     ck_assert_int_eq(ret, 1);
   60 
   61     ret = iflistsearch(&ifl, "eth0");
   62     ck_assert_int_eq(ret, 1);
   63 
   64     ret = iflistadd(&ifl, "eth1", 1);
   65     ck_assert_int_eq(ret, 1);
   66 
   67     ret = iflistsearch(&ifl, "eth0");
   68     ck_assert_int_eq(ret, 1);
   69 
   70     ret = iflistadd(&ifl, "eth0", 2);
   71     ck_assert_int_eq(ret, 1);
   72 
   73     ret = iflistsearch(&ifl, "eth0");
   74     ck_assert_int_eq(ret, 1);
   75 
   76     ret = iflistadd(&ifl, "eth2", 10);
   77     ck_assert_int_eq(ret, 1);
   78 
   79     ret = iflistsearch(&ifl, "eth0");
   80     ck_assert_int_eq(ret, 1);
   81 
   82     ret = iflistsearch(&ifl, "eth2");
   83     ck_assert_int_eq(ret, 1);
   84 
   85     ret = iflistsearch(&ifl, "eth0");
   86     ck_assert_int_eq(ret, 1);
   87 
   88     ret = iflistsearch(&ifl, "eth1");
   89     ck_assert_int_eq(ret, 1);
   90 
   91     ret = iflistsearch(&ifl, "eth3");
   92     ck_assert_int_eq(ret, 0);
   93 
   94     ret = iflistadd(&ifl, "eth3", 0);
   95     ck_assert_int_eq(ret, 1);
   96 
   97     ret = iflistsearch(&ifl, "eth3");
   98     ck_assert_int_eq(ret, 1);
   99 
  100     ret = iflistadd(&ifl, "eth4", 0);
  101     ck_assert_int_eq(ret, 1);
  102 
  103     ret = iflistsearch(&ifl, "eth3");
  104     ck_assert_int_eq(ret, 1);
  105 
  106     iflistfree(&ifl);
  107     ck_assert_ptr_eq(ifl, NULL);
  108 }
  109 END_TEST
  110 
  111 void add_iflist_tests(Suite *s)
  112 {
  113     TCase *tc_iflist = tcase_create("Iflist");
  114     tcase_add_checked_fixture(tc_iflist, setup, teardown);
  115     tcase_add_unchecked_fixture(tc_iflist, setup, teardown);
  116     tcase_add_test(tc_iflist, iflistfree_can_free_null);
  117     tcase_add_test(tc_iflist, iflistadd_can_add);
  118     tcase_add_test(tc_iflist, iflistsearch_can_search);
  119     suite_add_tcase(s, tc_iflist);
  120 }