1 #include <bluetooth/bluetooth.h> 2 #include <bluetooth/uuid.h> 3 4 const char *base = "00000000-0000-1000-8000-00805F9B34FB"; 5 6 uint8_t xbase[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 7 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; 8 9 uint16_t sixteen = 0x1234; 10 const char *uuidsixteen128 = "00001234-0000-1000-8000-00805F9B34FB"; 11 const char *uuidsixteen16 = "0x1234"; 12 const char *uuidsixteen16a = "1234"; 13 14 uint8_t xuuidsixteen[] = {0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x10, 0x00, 15 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; 16 17 uint32_t thirtytwo = 0x12345678; 18 const char *uuidthirtytwo32 = "0x12345678"; 19 const char *uuidthirtytwo32a = "12345678"; 20 const char *uuidthirtytwo128 = "12345678-0000-1000-8000-00805F9B34FB"; 21 22 uint8_t xuuidthirtytwo[] = {0x12, 0x34, 0x56, 0x78, 0x00, 0x00, 0x10, 0x00, 23 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; 24 25 const char *malformed[] = { 26 "0", 27 "01", 28 "012", 29 "xxxx", 30 "xxxxx", 31 "0xxxxx", 32 "0123456", 33 "012g4567", 34 "012345678", 35 "0x234567u9", 36 "01234567890", 37 "00001234-0000-1000-8000-00805F9B34F", 38 "00001234-0000-1000-8000 00805F9B34FB", 39 "00001234-0000-1000-8000-00805F9B34FBC", 40 "00001234-0000-1000-800G-00805F9B34FB", 41 NULL, 42 }; 43 44 int main(int argc, char *argv[]) 45 { 46 bt_uuid_t u, u2, u3, u4, u5, ub, u128; 47 uint128_t n, i; 48 char buf[512]; 49 int s; 50 51 memcpy(&n, xbase, 16); 52 ntoh128(&n, &i); 53 54 if (bt_string_to_uuid(&u, base)) { 55 printf("Fail %d\n", __LINE__); 56 return 1; 57 } 58 59 if (bt_string_to_uuid(&ub, base)) { 60 printf("Fail %d\n", __LINE__); 61 return 1; 62 } 63 64 if (u.type != 128) { 65 printf("Fail %d\n", __LINE__); 66 return 1; 67 } 68 69 if (ub.type != 128) { 70 printf("Fail %d\n", __LINE__); 71 return 1; 72 } 73 74 if (memcmp(&u.value.u128, &i, 16) != 0) { 75 printf("Fail %d\n", __LINE__); 76 return 1; 77 } 78 79 if (memcmp(&ub.value.u128, &i, 16) != 0) { 80 printf("Fail %d\n", __LINE__); 81 return 1; 82 } 83 84 if (memcmp(&ub.value.u128, &u.value.u128, 16) != 0) { 85 printf("Fail %d\n", __LINE__); 86 return 1; 87 } 88 89 if (bt_uuid_cmp(&u, &ub) != 0) { 90 printf("Fail %d\n", __LINE__); 91 return 1; 92 } 93 94 bt_uuid_to_string(&u, buf, sizeof(buf)); 95 /* printf("%s\n", buf); */ 96 97 if (strcasecmp(buf, base) != 0) { 98 printf("Fail %d\n", __LINE__); 99 return 1; 100 } 101 102 memcpy(&n, xuuidsixteen, 16); 103 ntoh128(&n, &i); 104 105 bt_uuid16_create(&u, sixteen); 106 bt_uuid_to_uuid128(&u, &u128); 107 108 if (bt_string_to_uuid(&u2, uuidsixteen16)) { 109 printf("Fail %d\n", __LINE__); 110 return 1; 111 } 112 113 if (bt_string_to_uuid(&u3, uuidsixteen16a)) { 114 printf("Fail %d\n", __LINE__); 115 return 1; 116 } 117 118 if (bt_string_to_uuid(&u4, uuidsixteen128)) { 119 printf("Fail %d\n", __LINE__); 120 return 1; 121 } 122 123 bt_uuid128_create(&u5, i); 124 125 if (u.type != 16) { 126 printf("Fail %d\n", __LINE__); 127 return 1; 128 } 129 130 if (u128.type != 128) { 131 printf("Fail %d\n", __LINE__); 132 return 1; 133 } 134 135 if (u.value.u16 != sixteen) { 136 printf("Fail %d\n", __LINE__); 137 return 1; 138 } 139 140 if (u2.type != 16) { 141 printf("Fail %d\n", __LINE__); 142 return 1; 143 } 144 145 if (u3.type != 16) { 146 printf("Fail %d\n", __LINE__); 147 return 1; 148 } 149 150 if (u4.type != 128) { 151 printf("Fail %d\n", __LINE__); 152 return 1; 153 } 154 155 if (u5.type != 128) { 156 printf("Fail %d\n", __LINE__); 157 return 1; 158 } 159 160 if (bt_uuid_cmp(&u, &u2) != 0) { 161 printf("Fail %d\n", __LINE__); 162 return 1; 163 } 164 165 if (bt_uuid_cmp(&u2, &u3) != 0) { 166 printf("Fail %d\n", __LINE__); 167 return 1; 168 } 169 170 if (bt_uuid_cmp(&u, &u3) != 0) { 171 printf("Fail %d\n", __LINE__); 172 return 1; 173 } 174 175 if (bt_uuid_cmp(&u3, &u4) != 0) { 176 printf("Fail %d\n", __LINE__); 177 return 1; 178 } 179 180 if (bt_uuid_cmp(&u4, &u5) != 0) { 181 printf("Fail %d\n", __LINE__); 182 return 1; 183 } 184 185 if (bt_uuid_cmp(&u5, &u) != 0) { 186 printf("Fail %d\n", __LINE__); 187 return 1; 188 } 189 190 if (bt_uuid_cmp(&u, &ub) == 0) { 191 printf("Fail %d\n", __LINE__); 192 return 1; 193 } 194 195 if (bt_uuid_cmp(&u5, &ub) == 0) { 196 printf("Fail %d\n", __LINE__); 197 return 1; 198 } 199 200 if (bt_uuid_cmp(&u, &u128) != 0) { 201 printf("Fail %d\n", __LINE__); 202 return 1; 203 } 204 205 if (bt_uuid_cmp(&ub, &u128) == 0) { 206 printf("Fail %d\n", __LINE__); 207 return 1; 208 } 209 210 memcpy(&n, xuuidthirtytwo, 16); 211 ntoh128(&n, &i); 212 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); 219 220 /* 221 bt_uuid_to_string(&u2, buf, sizeof(buf)); 222 printf("%s\n", buf); 223 224 bt_uuid_to_string(&u3, buf, sizeof(buf)); 225 printf("%s\n", buf); 226 227 bt_uuid_to_string(&u4, buf, sizeof(buf)); 228 printf("%s\n", buf); 229 */ 230 231 if (u.type != 32) { 232 printf("Fail %d\n", __LINE__); 233 return 1; 234 } 235 236 if (u128.type != 128) { 237 printf("Fail %d\n", __LINE__); 238 return 1; 239 } 240 241 if (u.value.u32 != thirtytwo) { 242 printf("Fail %d\n", __LINE__); 243 return 1; 244 } 245 246 if (u2.type != 32) { 247 printf("Fail %d\n", __LINE__); 248 return 1; 249 } 250 251 if (u3.type != 32) { 252 printf("Fail %d\n", __LINE__); 253 return 1; 254 } 255 256 if (u4.type != 128) { 257 printf("Fail %d\n", __LINE__); 258 return 1; 259 } 260 261 if (u5.type != 128) { 262 printf("Fail %d\n", __LINE__); 263 return 1; 264 } 265 266 if (bt_uuid_cmp(&u, &u2) != 0) { 267 printf("Fail %d\n", __LINE__); 268 return 1; 269 } 270 271 if (bt_uuid_cmp(&u2, &u3) != 0) { 272 printf("Fail %d\n", __LINE__); 273 return 1; 274 } 275 276 if (bt_uuid_cmp(&u3, &u4) != 0) { 277 printf("Fail %d\n", __LINE__); 278 return 1; 279 } 280 281 if (bt_uuid_cmp(&u4, &u5) != 0) { 282 printf("Fail %d\n", __LINE__); 283 return 1; 284 } 285 286 if (bt_uuid_cmp(&u5, &u) != 0) { 287 printf("Fail %d\n", __LINE__); 288 return 1; 289 } 290 291 if (bt_uuid_cmp(&u, &ub) == 0) { 292 printf("Fail %d\n", __LINE__); 293 return 1; 294 } 295 296 if (bt_uuid_cmp(&u5, &ub) == 0) { 297 printf("Fail %d\n", __LINE__); 298 return 1; 299 } 300 301 if (bt_uuid_cmp(&u, &u128) != 0) { 302 printf("Fail %d\n", __LINE__); 303 return 1; 304 } 305 306 if (bt_uuid_cmp(&ub, &u128) == 0) { 307 printf("Fail %d\n", __LINE__); 308 return 1; 309 } 310 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__); 314 return 1; 315 } 316 } 317 318 return 0; 319 } 320