| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <script src="../resources/testharness.js"></script> | |
| 3 <script src="../resources/testharnessreport.js"></script> | |
| 4 <script> | |
| 5 'use strict' | |
| 6 | |
| 7 var base_uuid = '00000000-0000-1000-8000-00805f9b34fb' | |
| 8 | |
| 9 test(() => { | |
| 10 let base_alias = 0x0 | |
| 11 assert_equals(BluetoothUUID.getService(base_alias), base_uuid); | |
| 12 assert_equals(BluetoothUUID.getCharacteristic(base_alias), base_uuid); | |
| 13 assert_equals(BluetoothUUID.getDescriptor(base_alias), base_uuid); | |
| 14 }, '0x0 should produce valid UUID.'); | |
| 15 | |
| 16 test(() => { | |
| 17 assert_equals(BluetoothUUID.getService(NaN), base_uuid); | |
| 18 assert_equals(BluetoothUUID.getCharacteristic(NaN), base_uuid); | |
| 19 assert_equals(BluetoothUUID.getDescriptor(NaN), base_uuid); | |
| 20 }, 'NaN returns basic uuid'); | |
| 21 | |
| 22 test(() => { | |
| 23 let max_uuid = 'ffffffff-0000-1000-8000-00805f9b34fb'; | |
| 24 let nine_digits = 0xfffffffff; | |
| 25 let thirteen_digits = 0xfffffffffffff; | |
| 26 let fourteen_digits = 0xffffffffffffff; | |
| 27 assert_equals(BluetoothUUID.getService(nine_digits), max_uuid); | |
| 28 assert_equals(BluetoothUUID.getCharacteristic(nine_digits), max_uuid); | |
| 29 assert_equals(BluetoothUUID.getDescriptor(nine_digits), max_uuid); | |
| 30 assert_equals(BluetoothUUID.getService(thirteen_digits), max_uuid); | |
| 31 assert_equals(BluetoothUUID.getCharacteristic(thirteen_digits), max_uuid); | |
| 32 assert_equals(BluetoothUUID.getDescriptor(thirteen_digits), max_uuid); | |
| 33 assert_equals(BluetoothUUID.getService(fourteen_digits), base_uuid); | |
| 34 assert_equals(BluetoothUUID.getCharacteristic(fourteen_digits), base_uuid); | |
| 35 assert_equals(BluetoothUUID.getDescriptor(fourteen_digits), base_uuid); | |
| 36 }, 'Values between 0xfffffffff (8 digits) and 0xffffffffffffff (14 digits)' + | |
| 37 'should return max UUID'); | |
| 38 | |
| 39 test(() => { | |
| 40 assert_equals(BluetoothUUID.getService(Infinity), base_uuid); | |
| 41 assert_equals(BluetoothUUID.getCharacteristic(Infinity), base_uuid); | |
| 42 assert_equals(BluetoothUUID.getDescriptor(Infinity), base_uuid); | |
| 43 }, 'Infinity returns base UUID'); | |
| 44 | |
| 45 test(() => { | |
| 46 let deadbeef_alias = 0xDEADBEEF; | |
| 47 let deadbeef_uuid = 'deadbeef-0000-1000-8000-00805f9b34fb'; | |
| 48 assert_equals(BluetoothUUID.getService(deadbeef_alias), deadbeef_uuid); | |
| 49 assert_equals(BluetoothUUID.getCharacteristic(deadbeef_alias), deadbeef_uuid); | |
| 50 assert_equals(BluetoothUUID.getDescriptor(deadbeef_alias), deadbeef_uuid); | |
| 51 }, '0xdeadbeef should produce valid UUID.'); | |
| 52 | |
| 53 test(() => { | |
| 54 let adeadbeef_alias = 0xADEADBEEF; | |
| 55 let adeadbeef_uuid = 'deadbeef-0000-1000-8000-00805f9b34fb'; | |
| 56 assert_equals(BluetoothUUID.getService(adeadbeef_alias), adeadbeef_uuid); | |
| 57 assert_equals(BluetoothUUID.getCharacteristic(adeadbeef_alias), adeadbeef_uuid
); | |
| 58 assert_equals(BluetoothUUID.getDescriptor(adeadbeef_alias), adeadbeef_uuid); | |
| 59 }, 'Only first 32bits should be used.'); | |
| 60 | |
| 61 test(() => { | |
| 62 let basic_uuid = '1a2b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d'; | |
| 63 assert_equals(BluetoothUUID.getService(basic_uuid), basic_uuid); | |
| 64 assert_equals(BluetoothUUID.getCharacteristic(basic_uuid), basic_uuid); | |
| 65 assert_equals(BluetoothUUID.getDescriptor(basic_uuid), basic_uuid); | |
| 66 }, 'A valid UUID String should return the same UUID.'); | |
| 67 | |
| 68 test(() => { | |
| 69 let all_caps_uuid = '1A2B3C4D-5E6F-7A8B-9C0D-1E2F3A4B5C6D'; | |
| 70 assert_throws(TypeError(), () => BluetoothUUID.getService(all_caps_uuid)); | |
| 71 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(all_caps_uuid
)); | |
| 72 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(all_caps_uuid)); | |
| 73 }, 'A UUID String with uppercase letters is an invalid UUID.'); | |
| 74 | |
| 75 test(() => { | |
| 76 let string_alias = 'deadbeef'; | |
| 77 assert_throws(TypeError(), () => BluetoothUUID.getService(string_alias)); | |
| 78 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(string_alias)
); | |
| 79 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(string_alias)); | |
| 80 }, 'A 32bit *String* alias is invalid.'); | |
| 81 | |
| 82 test(() => { | |
| 83 let invalid_character_uuid = '0000000g-0000-1000-8000-00805f9b34fb'; | |
| 84 assert_throws(TypeError(), () => BluetoothUUID.getService(invalid_character_uu
id)); | |
| 85 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(invalid_chara
cter_uuid)); | |
| 86 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(invalid_character
_uuid)); | |
| 87 }, 'A UUID with invalid characters is an invalid UUID.'); | |
| 88 | |
| 89 test(() => { | |
| 90 assert_equals(BluetoothUUID.getService('alert_notification'), | |
| 91 '00001811-0000-1000-8000-00805f9b34fb'); | |
| 92 assert_equals(BluetoothUUID.getCharacteristic('aerobic_heart_rate_lower_limit'
), | |
| 93 '00002a7e-0000-1000-8000-00805f9b34fb'); | |
| 94 assert_equals(BluetoothUUID.getDescriptor('gatt.characteristic_extended_proper
ties'), | |
| 95 '00002900-0000-1000-8000-00805f9b34fb'); | |
| 96 }, 'A valid UUID from a name.'); | |
| 97 | |
| 98 test(() => { | |
| 99 assert_throws(TypeError(), () => { | |
| 100 BluetoothUUID.getService('aerobic_heart_rate_lower_limit'); | |
| 101 }); | |
| 102 assert_throws(TypeError(), () => { | |
| 103 BluetoothUUID.getService('gatt.characteristic_extended_properties'); | |
| 104 }); | |
| 105 assert_throws(TypeError(), () => { | |
| 106 BluetoothUUID.getCharacteristic('alert_notification'); | |
| 107 }); | |
| 108 assert_throws(TypeError(), () => { | |
| 109 BluetoothUUID.getCharacteristic('gatt.characteristic_extended_properties'); | |
| 110 }); | |
| 111 assert_throws(TypeError(), () => { | |
| 112 BluetoothUUID.getDescriptor('alert_notification'); | |
| 113 }); | |
| 114 assert_throws(TypeError(), () => { | |
| 115 BluetoothUUID.getDescriptor('aerobic_heart_rate_lower_limit'); | |
| 116 }); | |
| 117 }, 'Make sure attributes don\'t share a map'); | |
| 118 | |
| 119 test(() => { | |
| 120 let wrong_name = 'wrong_name'; | |
| 121 assert_throws(TypeError(), () => BluetoothUUID.getService(wrong_name)); | |
| 122 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(wrong_name)); | |
| 123 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(wrong_name)); | |
| 124 }, 'Invalid Descriptor name'); | |
| 125 | |
| 126 test(() => { | |
| 127 let object = {}; | |
| 128 let array = []; | |
| 129 let func = () => {}; | |
| 130 | |
| 131 // cannonicalUUID | |
| 132 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(object)); | |
| 133 // [] converts to '', which converts to 0 before the range check. | |
| 134 assert_equals(BluetoothUUID.canonicalUUID(array), base_uuid); | |
| 135 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(func)); | |
| 136 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(undefined)); | |
| 137 assert_equals(BluetoothUUID.canonicalUUID(null), base_uuid); | |
| 138 assert_equals(BluetoothUUID.canonicalUUID(false), base_uuid); | |
| 139 assert_equals(BluetoothUUID.canonicalUUID(true), BluetoothUUID.canonicalUUID(1
)); | |
| 140 assert_throws(new TypeError, () => BluetoothUUID.canonicalUUID(NaN)); | |
| 141 | |
| 142 // getService | |
| 143 assert_throws(TypeError(), () => BluetoothUUID.getService(object)); | |
| 144 assert_throws(TypeError(), () => BluetoothUUID.getService(array)); | |
| 145 assert_throws(TypeError(), () => BluetoothUUID.getService(func)); | |
| 146 assert_throws(TypeError(), () => BluetoothUUID.getService(undefined)); | |
| 147 assert_throws(TypeError(), () => BluetoothUUID.getService(null)); | |
| 148 assert_throws(TypeError(), () => BluetoothUUID.getService(false)); | |
| 149 | |
| 150 // getCharacteristic | |
| 151 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(object)); | |
| 152 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(array)); | |
| 153 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(func)); | |
| 154 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(undefined)); | |
| 155 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(null)); | |
| 156 assert_throws(TypeError(), () => BluetoothUUID.getCharacteristic(false)); | |
| 157 | |
| 158 // getDescriptor | |
| 159 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(object)); | |
| 160 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(array)); | |
| 161 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(func)); | |
| 162 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(undefined)); | |
| 163 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(null)); | |
| 164 assert_throws(TypeError(), () => BluetoothUUID.getDescriptor(false)); | |
| 165 }, 'Non-number and non-strings'); | |
| 166 </script> | |
| OLD | NEW |