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 <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2019-08-30 14:12:40 +03:00 committed by Ioannis Glaropoulos
commit 51ffabfa56

View file

@ -18,6 +18,10 @@ static struct bt_uuid_128 uuid_128 = BT_UUID_INIT_128(
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00);
static struct bt_uuid_128 le_128 = BT_UUID_INIT_128(
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00);
static void test_uuid_cmp(void)
{
/* Compare UUID 16 bits */
@ -41,10 +45,54 @@ static void test_uuid_cmp(void)
"Test UUIDs match");
}
static void test_uuid_create(void)
{
u8_t le16[] = { 0x01, 0x00 };
u8_t be16[] = { 0x00, 0x01 };
union {
struct bt_uuid uuid;
struct bt_uuid_16 u16;
struct bt_uuid_128 u128;
} u;
/* Create UUID from LE 16 bit byte array */
zassert_true(bt_uuid_create(&u.uuid, le16, sizeof(le16)),
"Unable create UUID");
/* Compare UUID 16 bits */
zassert_true(bt_uuid_cmp(&u.uuid, BT_UUID_DECLARE_16(0x0001)) == 0,
"Test UUIDs don't match");
/* Compare UUID 128 bits */
zassert_true(bt_uuid_cmp(&u.uuid, &le_128.uuid) == 0,
"Test UUIDs don't match");
/* Compare swapped UUID 16 bits */
zassert_false(bt_uuid_cmp(&u.uuid, BT_UUID_DECLARE_16(0x0100)) == 0,
"Test UUIDs match");
/* Create UUID from BE 16 bit byte array */
zassert_true(bt_uuid_create(&u.uuid, be16, sizeof(be16)),
"Unable create UUID");
/* Compare UUID 16 bits */
zassert_false(bt_uuid_cmp(&u.uuid, BT_UUID_DECLARE_16(0x0001)) == 0,
"Test UUIDs match");
/* Compare UUID 128 bits */
zassert_false(bt_uuid_cmp(&u.uuid, &le_128.uuid) == 0,
"Test UUIDs match");
/* Compare swapped UUID 16 bits */
zassert_true(bt_uuid_cmp(&u.uuid, BT_UUID_DECLARE_16(0x0100)) == 0,
"Test UUIDs don't match");
}
/*test case main entry*/
void test_main(void)
{
ztest_test_suite(test_uuid,
ztest_unit_test(test_uuid_cmp));
ztest_unit_test(test_uuid_cmp),
ztest_unit_test(test_uuid_create));
ztest_run_test_suite(test_uuid);
}