]> git.ipfire.org Git - thirdparty/lldpd.git/blob - tests/check_bitmap.c
tests: display tests/test-suite.log on errors
[thirdparty/lldpd.git] / tests / check_bitmap.c
1 /* -*- mode: c; c-file-style: "openbsd" -*- */
2 /*
3 * Copyright (c) 2020 Vincent Bernat <bernat@luffy.cx>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <check.h>
19
20 #include "../src/daemon/lldpd.h"
21
22 START_TEST(test_empty) {
23 uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {};
24 ck_assert(bitmap_isempty(vlan_bmap));
25 ck_assert_int_eq(bitmap_numbits(vlan_bmap), 0);
26 }
27 END_TEST
28
29 START_TEST(test_first_bit) {
30 uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {};
31 bitmap_set(vlan_bmap, 1);
32 ck_assert_int_eq(vlan_bmap[0], 2);
33 ck_assert_int_eq(bitmap_numbits(vlan_bmap), 1);
34 }
35 END_TEST
36
37 START_TEST(test_some_bits) {
38 uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {};
39 bitmap_set(vlan_bmap, 1);
40 bitmap_set(vlan_bmap, 6);
41 bitmap_set(vlan_bmap, 31);
42 bitmap_set(vlan_bmap, 50);
43 ck_assert_int_eq(vlan_bmap[0], (1L << 1) | (1L << 6) | (1L << 31));
44 ck_assert_int_eq(vlan_bmap[1], (1L << (50-32)));
45 ck_assert_int_eq(vlan_bmap[2], 0);
46 ck_assert_int_eq(bitmap_numbits(vlan_bmap), 4);
47 }
48 END_TEST
49
50 Suite *
51 bitmap_suite(void)
52 {
53 Suite *s = suite_create("Bitmap handling");
54
55 TCase *tc_bitmap = tcase_create("Bitmap handling");
56 tcase_add_test(tc_bitmap, test_empty);
57 tcase_add_test(tc_bitmap, test_first_bit);
58 tcase_add_test(tc_bitmap, test_some_bits);
59 suite_add_tcase(s, tc_bitmap);
60
61 return s;
62 }
63
64 int
65 main()
66 {
67 int number_failed;
68 Suite *s = bitmap_suite();
69 SRunner *sr = srunner_create(s);
70 srunner_run_all(sr, CK_ENV);
71 number_failed = srunner_ntests_failed(sr);
72 srunner_free(sr);
73 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
74 }