@@ -18,6 +18,10 @@ static struct bt_uuid_128 uuid_128 = BT_UUID_INIT_128(
18
18
0xfb , 0x34 , 0x9b , 0x5f , 0x80 , 0x00 , 0x00 , 0x80 ,
19
19
0x00 , 0x10 , 0x00 , 0x00 , 0xff , 0xff , 0x00 , 0x00 );
20
20
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
+
21
25
static void test_uuid_cmp (void )
22
26
{
23
27
/* Compare UUID 16 bits */
@@ -41,10 +45,54 @@ static void test_uuid_cmp(void)
41
45
"Test UUIDs match" );
42
46
}
43
47
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
+
44
91
/*test case main entry*/
45
92
void test_main (void )
46
93
{
47
94
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 ));
49
97
ztest_run_test_suite (test_uuid );
50
98
}
0 commit comments