1 #include <bluetooth/bluetooth.h>
2 #include <bluetooth/uuid.h>
4 const char *base = "00000000-0000-1000-8000-00805F9B34FB";
6 uint8_t xbase[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
7 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb};
9 uint16_t sixteen = 0x1234;
10 const char *uuidsixteen128 = "00001234-0000-1000-8000-00805F9B34FB";
11 const char *uuidsixteen16 = "0x1234";
12 const char *uuidsixteen16a = "1234";
14 uint8_t xuuidsixteen[] = {0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x10, 0x00,
15 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb};
17 uint32_t thirtytwo = 0x12345678;
18 const char *uuidthirtytwo32 = "0x12345678";
19 const char *uuidthirtytwo32a = "12345678";
20 const char *uuidthirtytwo128 = "12345678-0000-1000-8000-00805F9B34FB";
22 uint8_t xuuidthirtytwo[] = {0x12, 0x34, 0x56, 0x78, 0x00, 0x00, 0x10, 0x00,
23 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb};
25 const char *malformed[] = {
37 "00001234-0000-1000-8000-00805F9B34F",
38 "00001234-0000-1000-8000 00805F9B34FB",
39 "00001234-0000-1000-8000-00805F9B34FBC",
40 "00001234-0000-1000-800G-00805F9B34FB",
44 int main(int argc, char *argv[])
46 bt_uuid_t u, u2, u3, u4, u5, ub, u128;
51 memcpy(&n, xbase, 16);
54 if (bt_string_to_uuid(&u, base)) {
55 printf("Fail %d\n", __LINE__);
59 if (bt_string_to_uuid(&ub, base)) {
60 printf("Fail %d\n", __LINE__);
65 printf("Fail %d\n", __LINE__);
70 printf("Fail %d\n", __LINE__);
74 if (memcmp(&u.value.u128, &i, 16) != 0) {
75 printf("Fail %d\n", __LINE__);
79 if (memcmp(&ub.value.u128, &i, 16) != 0) {
80 printf("Fail %d\n", __LINE__);
84 if (memcmp(&ub.value.u128, &u.value.u128, 16) != 0) {
85 printf("Fail %d\n", __LINE__);
89 if (bt_uuid_cmp(&u, &ub) != 0) {
90 printf("Fail %d\n", __LINE__);
94 bt_uuid_to_string(&u, buf, sizeof(buf));
95 /* printf("%s\n", buf); */
97 if (strcasecmp(buf, base) != 0) {
98 printf("Fail %d\n", __LINE__);
102 memcpy(&n, xuuidsixteen, 16);
105 bt_uuid16_create(&u, sixteen);
106 bt_uuid_to_uuid128(&u, &u128);
108 if (bt_string_to_uuid(&u2, uuidsixteen16)) {
109 printf("Fail %d\n", __LINE__);
113 if (bt_string_to_uuid(&u3, uuidsixteen16a)) {
114 printf("Fail %d\n", __LINE__);
118 if (bt_string_to_uuid(&u4, uuidsixteen128)) {
119 printf("Fail %d\n", __LINE__);
123 bt_uuid128_create(&u5, i);
126 printf("Fail %d\n", __LINE__);
130 if (u128.type != 128) {
131 printf("Fail %d\n", __LINE__);
135 if (u.value.u16 != sixteen) {
136 printf("Fail %d\n", __LINE__);
141 printf("Fail %d\n", __LINE__);
146 printf("Fail %d\n", __LINE__);
150 if (u4.type != 128) {
151 printf("Fail %d\n", __LINE__);
155 if (u5.type != 128) {
156 printf("Fail %d\n", __LINE__);
160 if (bt_uuid_cmp(&u, &u2) != 0) {
161 printf("Fail %d\n", __LINE__);
165 if (bt_uuid_cmp(&u2, &u3) != 0) {
166 printf("Fail %d\n", __LINE__);
170 if (bt_uuid_cmp(&u, &u3) != 0) {
171 printf("Fail %d\n", __LINE__);
175 if (bt_uuid_cmp(&u3, &u4) != 0) {
176 printf("Fail %d\n", __LINE__);
180 if (bt_uuid_cmp(&u4, &u5) != 0) {
181 printf("Fail %d\n", __LINE__);
185 if (bt_uuid_cmp(&u5, &u) != 0) {
186 printf("Fail %d\n", __LINE__);
190 if (bt_uuid_cmp(&u, &ub) == 0) {
191 printf("Fail %d\n", __LINE__);
195 if (bt_uuid_cmp(&u5, &ub) == 0) {
196 printf("Fail %d\n", __LINE__);
200 if (bt_uuid_cmp(&u, &u128) != 0) {
201 printf("Fail %d\n", __LINE__);
205 if (bt_uuid_cmp(&ub, &u128) == 0) {
206 printf("Fail %d\n", __LINE__);
210 memcpy(&n, xuuidthirtytwo, 16);
213 bt_uuid32_create(&u, thirtytwo);
214 bt_uuid_to_uuid128(&u, &u128);
215 bt_string_to_uuid(&u2, uuidthirtytwo32);
216 bt_string_to_uuid(&u3, uuidthirtytwo32a);
217 bt_string_to_uuid(&u4, uuidthirtytwo128);
218 bt_uuid128_create(&u5, i);
221 bt_uuid_to_string(&u2, buf, sizeof(buf));
224 bt_uuid_to_string(&u3, buf, sizeof(buf));
227 bt_uuid_to_string(&u4, buf, sizeof(buf));
232 printf("Fail %d\n", __LINE__);
236 if (u128.type != 128) {
237 printf("Fail %d\n", __LINE__);
241 if (u.value.u32 != thirtytwo) {
242 printf("Fail %d\n", __LINE__);
247 printf("Fail %d\n", __LINE__);
252 printf("Fail %d\n", __LINE__);
256 if (u4.type != 128) {
257 printf("Fail %d\n", __LINE__);
261 if (u5.type != 128) {
262 printf("Fail %d\n", __LINE__);
266 if (bt_uuid_cmp(&u, &u2) != 0) {
267 printf("Fail %d\n", __LINE__);
271 if (bt_uuid_cmp(&u2, &u3) != 0) {
272 printf("Fail %d\n", __LINE__);
276 if (bt_uuid_cmp(&u3, &u4) != 0) {
277 printf("Fail %d\n", __LINE__);
281 if (bt_uuid_cmp(&u4, &u5) != 0) {
282 printf("Fail %d\n", __LINE__);
286 if (bt_uuid_cmp(&u5, &u) != 0) {
287 printf("Fail %d\n", __LINE__);
291 if (bt_uuid_cmp(&u, &ub) == 0) {
292 printf("Fail %d\n", __LINE__);
296 if (bt_uuid_cmp(&u5, &ub) == 0) {
297 printf("Fail %d\n", __LINE__);
301 if (bt_uuid_cmp(&u, &u128) != 0) {
302 printf("Fail %d\n", __LINE__);
306 if (bt_uuid_cmp(&ub, &u128) == 0) {
307 printf("Fail %d\n", __LINE__);
311 for (s = 0; malformed[s]; ++s) {
312 if (bt_string_to_uuid(&u3, malformed[s]) == 0) {
313 printf("Fail %s %d\n", malformed[s], __LINE__);