Skip to content

Commit 51ffabf

Browse files
Vudentzioannisg
authored andcommitted
Bluetooth: UUID: Add test for bt_uuid_create
This adds test for bt_uuid_create APIs using a byte array in LE/BE format as it is expected and then proceed to compare with matching and unmatching UUID declared in host byte order. Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 73bf27f commit 51ffabf

File tree

1 file changed

+49
-1
lines changed
  • tests/bluetooth/uuid/src

1 file changed

+49
-1
lines changed

tests/bluetooth/uuid/src/main.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ static struct bt_uuid_128 uuid_128 = BT_UUID_INIT_128(
1818
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
1919
0x00, 0x10, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00);
2020

21+
static struct bt_uuid_128 le_128 = BT_UUID_INIT_128(
22+
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
23+
0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00);
24+
2125
static void test_uuid_cmp(void)
2226
{
2327
/* Compare UUID 16 bits */
@@ -41,10 +45,54 @@ static void test_uuid_cmp(void)
4145
"Test UUIDs match");
4246
}
4347

48+
static void test_uuid_create(void)
49+
{
50+
u8_t le16[] = { 0x01, 0x00 };
51+
u8_t be16[] = { 0x00, 0x01 };
52+
union {
53+
struct bt_uuid uuid;
54+
struct bt_uuid_16 u16;
55+
struct bt_uuid_128 u128;
56+
} u;
57+
58+
/* Create UUID from LE 16 bit byte array */
59+
zassert_true(bt_uuid_create(&u.uuid, le16, sizeof(le16)),
60+
"Unable create UUID");
61+
62+
/* Compare UUID 16 bits */
63+
zassert_true(bt_uuid_cmp(&u.uuid, BT_UUID_DECLARE_16(0x0001)) == 0,
64+
"Test UUIDs don't match");
65+
66+
/* Compare UUID 128 bits */
67+
zassert_true(bt_uuid_cmp(&u.uuid, &le_128.uuid) == 0,
68+
"Test UUIDs don't match");
69+
70+
/* Compare swapped UUID 16 bits */
71+
zassert_false(bt_uuid_cmp(&u.uuid, BT_UUID_DECLARE_16(0x0100)) == 0,
72+
"Test UUIDs match");
73+
74+
/* Create UUID from BE 16 bit byte array */
75+
zassert_true(bt_uuid_create(&u.uuid, be16, sizeof(be16)),
76+
"Unable create UUID");
77+
78+
/* Compare UUID 16 bits */
79+
zassert_false(bt_uuid_cmp(&u.uuid, BT_UUID_DECLARE_16(0x0001)) == 0,
80+
"Test UUIDs match");
81+
82+
/* Compare UUID 128 bits */
83+
zassert_false(bt_uuid_cmp(&u.uuid, &le_128.uuid) == 0,
84+
"Test UUIDs match");
85+
86+
/* Compare swapped UUID 16 bits */
87+
zassert_true(bt_uuid_cmp(&u.uuid, BT_UUID_DECLARE_16(0x0100)) == 0,
88+
"Test UUIDs don't match");
89+
}
90+
4491
/*test case main entry*/
4592
void test_main(void)
4693
{
4794
ztest_test_suite(test_uuid,
48-
ztest_unit_test(test_uuid_cmp));
95+
ztest_unit_test(test_uuid_cmp),
96+
ztest_unit_test(test_uuid_create));
4997
ztest_run_test_suite(test_uuid);
5098
}

0 commit comments

Comments
 (0)