2 <script src=
"../resources/testharness.js"></script>
3 <script src=
"../resources/testharnessreport.js"></script>
7 var base_uuid
= '00000000-0000-1000-8000-00805f9b34fb'
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.');
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');
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');
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');
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.');
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.');
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.');
69 let all_caps_uuid
= '1A2B3C4D-5E6F-7A8B-9C0D-1E2F3A4B5C6D';
70 assert_throws('SyntaxError', () => BluetoothUUID
.getService(all_caps_uuid
));
71 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(all_caps_uuid
));
72 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(all_caps_uuid
));
73 }, 'A UUID String with uppercase letters is an invalid UUID.');
76 let string_alias
= 'deadbeef';
77 assert_throws('SyntaxError', () => BluetoothUUID
.getService(string_alias
));
78 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(string_alias
));
79 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(string_alias
));
80 }, 'A 32bit *String* alias is invalid.');
83 let invalid_character_uuid
= '0000000g-0000-1000-8000-00805f9b34fb';
84 assert_throws('SyntaxError', () => BluetoothUUID
.getService(invalid_character_uuid
));
85 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(invalid_character_uuid
));
86 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(invalid_character_uuid
));
87 }, 'A UUID with invalid characters is an invalid UUID.');
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_properties'),
95 '00002900-0000-1000-8000-00805f9b34fb');
96 }, 'A valid UUID from a name.');
99 assert_throws('SyntaxError', () => {
100 BluetoothUUID
.getService('aerobic_heart_rate_lower_limit');
102 assert_throws('SyntaxError', () => {
103 BluetoothUUID
.getService('gatt.characteristic_extended_properties');
105 assert_throws('SyntaxError', () => {
106 BluetoothUUID
.getCharacteristic('alert_notification');
108 assert_throws('SyntaxError', () => {
109 BluetoothUUID
.getCharacteristic('gatt.characteristic_extended_properties');
111 assert_throws('SyntaxError', () => {
112 BluetoothUUID
.getDescriptor('alert_notification');
114 assert_throws('SyntaxError', () => {
115 BluetoothUUID
.getDescriptor('aerobic_heart_rate_lower_limit');
117 }, 'Make sure attributes don\'t share a map');
120 let wrong_name
= 'wrong_name';
121 assert_throws('SyntaxError', () => BluetoothUUID
.getService(wrong_name
));
122 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(wrong_name
));
123 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(wrong_name
));
124 }, 'Invalid Descriptor name');
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
));
143 assert_throws('SyntaxError', () => BluetoothUUID
.getService(object
));
144 assert_throws('SyntaxError', () => BluetoothUUID
.getService(array
));
145 assert_throws('SyntaxError', () => BluetoothUUID
.getService(func
));
146 assert_throws('SyntaxError', () => BluetoothUUID
.getService(undefined));
147 assert_throws('SyntaxError', () => BluetoothUUID
.getService(null));
148 assert_throws('SyntaxError', () => BluetoothUUID
.getService(false));
151 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(object
));
152 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(array
));
153 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(func
));
154 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(undefined));
155 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(null));
156 assert_throws('SyntaxError', () => BluetoothUUID
.getCharacteristic(false));
159 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(object
));
160 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(array
));
161 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(func
));
162 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(undefined));
163 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(null));
164 assert_throws('SyntaxError', () => BluetoothUUID
.getDescriptor(false));
165 }, 'Non-number and non-strings');