1 /* Copyright (c) 2022 Nordic Semiconductor ASA
2 * SPDX-License-Identifier: Apache-2.0
3 */
4
5 #include <zephyr/bluetooth/addr.h>
6 #include <zephyr/ztest.h>
7
8 ZTEST_SUITE(bt_addr_le_eq, NULL, NULL, NULL, NULL, NULL);
9
ZTEST(bt_addr_le_eq,test_all_zero)10 ZTEST(bt_addr_le_eq, test_all_zero)
11 {
12 bt_addr_le_t a = {.type = 0, .a = {{0, 0, 0, 0, 0, 0}}};
13 bt_addr_le_t b = a;
14
15 zassert_true(bt_addr_le_eq(&a, &b));
16 }
17
ZTEST(bt_addr_le_eq,test_type_not_zero)18 ZTEST(bt_addr_le_eq, test_type_not_zero)
19 {
20 bt_addr_le_t a = {.type = 1, .a = {{1, 2, 3, 4, 5, 6}}};
21 bt_addr_le_t b = a;
22
23 zassert_true(bt_addr_le_eq(&a, &b));
24 }
25
ZTEST(bt_addr_le_eq,test_type_matters)26 ZTEST(bt_addr_le_eq, test_type_matters)
27 {
28 bt_addr_le_t a = {.type = 0, .a = {{1, 2, 3, 4, 5, 6}}};
29 bt_addr_le_t b = a;
30
31 zassume_true(bt_addr_le_eq(&a, &b));
32 a.type = 1;
33 zassert_false(bt_addr_le_eq(&a, &b));
34 }
35
ZTEST(bt_addr_le_eq,test_address_matters_start)36 ZTEST(bt_addr_le_eq, test_address_matters_start)
37 {
38 bt_addr_le_t a = {.type = 0, .a = {{1, 2, 3, 4, 5, 6}}};
39 bt_addr_le_t b = a;
40
41 zassume_true(bt_addr_le_eq(&a, &b));
42 a.a.val[0] = 0;
43 zassert_false(bt_addr_le_eq(&a, &b));
44 }
45
ZTEST(bt_addr_le_eq,test_address_matters_end)46 ZTEST(bt_addr_le_eq, test_address_matters_end)
47 {
48 bt_addr_le_t a = {.type = 0, .a = {{1, 2, 3, 4, 5, 6}}};
49 bt_addr_le_t b = a;
50
51 zassume_true(bt_addr_le_eq(&a, &b));
52 a.a.val[5] = 0;
53 zassert_false(bt_addr_le_eq(&a, &b));
54 }
55
ZTEST(bt_addr_le_eq,test_only_type_and_address_matters)56 ZTEST(bt_addr_le_eq, test_only_type_and_address_matters)
57 {
58 bt_addr_le_t a;
59 bt_addr_le_t b;
60
61 /* Make anything that is not the type and address unequal bytes. */
62 memset(&a, 0xaa, sizeof(a));
63 memset(&b, 0xbb, sizeof(b));
64 a.type = 1;
65 b.type = 1;
66 memset(a.a.val, 1, sizeof(a.a.val));
67 memset(b.a.val, 1, sizeof(b.a.val));
68
69 zassert_true(bt_addr_le_eq(&a, &b));
70 }
71
ZTEST(bt_addr_le_eq,test_same_object)72 ZTEST(bt_addr_le_eq, test_same_object)
73 {
74 bt_addr_le_t a = {.type = 0, .a = {{1, 2, 3, 4, 5, 6}}};
75
76 zassert_true(bt_addr_le_eq(&a, &a));
77 }
78