From c2d46227374ea516e58013b8e2ee20c55faf691a Mon Sep 17 00:00:00 2001 From: Arkadiusz Pietraszek Date: Thu, 2 Apr 2020 14:03:08 +0200 Subject: [PATCH] [6.0][Bluetooth] Add JS functionalities enabling conversions and comparisons of UUIDs Added functions: uuidTo128bit uuidToShortestPossible uuidsEqual Related ACR: TWDAPI-258 [Verification] Function tested manually in console. Unit test added: + test_UUIDTo128bit.js + test_UUIDToShortestPossible.js + test_UUIDsEqual.js pass rate is 100% Change-Id: I2e41443d4ad5eeb8997a5381901af2c2f96151c8 Signed-off-by: Arkadiusz Pietraszek --- src/bluetooth/bluetooth_api.js | 132 ++++ src/bluetooth/ut/js/test_UUIDTo128bit.js | 245 ++++++++ .../ut/js/test_UUIDToShortestPossible.js | 283 +++++++++ src/bluetooth/ut/js/test_UUIDsEqual.js | 587 ++++++++++++++++++ 4 files changed, 1247 insertions(+) create mode 100644 src/bluetooth/ut/js/test_UUIDTo128bit.js create mode 100644 src/bluetooth/ut/js/test_UUIDToShortestPossible.js create mode 100644 src/bluetooth/ut/js/test_UUIDsEqual.js diff --git a/src/bluetooth/bluetooth_api.js b/src/bluetooth/bluetooth_api.js index 1e274a3b..73afbee3 100755 --- a/src/bluetooth/bluetooth_api.js +++ b/src/bluetooth/bluetooth_api.js @@ -2757,5 +2757,137 @@ BluetoothManager.prototype.getLEAdapter = function() { privUtils_.log('Entered BluetoothManager.getLEAdapter()'); return BluetoothManager_getLEAdapter(); }; + +var BluetoothManager_UUIDIsValid128Bit = function(uuid) { + var re128BitFormat = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; + if (re128BitFormat.test(uuid)) { + return true; + } + return false; +}; + +var BluetoothManager_UUIDIsValid32Bit = function(uuid) { + var re32BitFormat = /^[0-9a-f]{8}$/; + if (re32BitFormat.test(uuid)) { + return true; + } + return false; +}; + +var BluetoothManager_UUIDIsValid16Bit = function(uuid) { + var re16BitFormat = /^[0-9a-f]{4}$/; + if (re16BitFormat.test(uuid)) { + return true; + } + return false; +}; + +var BluetoothManager_UUIDIsConvertibleTo16Bit = function(uuid) { + var re128BitFormat = /^0000[0-9a-f]{4}-0000-1000-8000-00805f9b34fb$/; + if (re128BitFormat.test(uuid)) { + return true; + } + var re32BitFormat = /^0000[0-9a-f]{4}$/; + if (re32BitFormat.test(uuid)) { + return true; + } + return false; +}; + +var BluetoothManager_UUIDIsConvertibleTo32Bit = function(uuid) { + var re = /^[0-9a-f]{8}-0000-1000-8000-00805f9b34fb$/; + if (re.test(uuid)) { + return true; + } + return false; +}; + +var BluetoothManager_UUIDTo128bit = function(uuid) { + uuid = Converter.toString(uuid).toLowerCase(); + if (BluetoothManager_UUIDIsValid128Bit(uuid)) { + return uuid; + } + var baseUuidLast96Bits = '-0000-1000-8000-00805f9b34fb'; + if (BluetoothManager_UUIDIsValid16Bit(uuid)) { + return '0000' + uuid + baseUuidLast96Bits; + } + if (BluetoothManager_UUIDIsValid32Bit(uuid)) { + return uuid + baseUuidLast96Bits; + } + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'Given parameter is not a supported uuid format: ' + uuid + ); +}; + +var BluetoothManager_UUIDToShortestPossible = function(uuid) { + uuid = uuid.toLowerCase(); + if (BluetoothManager_UUIDIsValid16Bit(uuid)) { + return uuid; + } + if (BluetoothManager_UUIDIsValid32Bit(uuid)) { + if (BluetoothManager_UUIDIsConvertibleTo16Bit(uuid)) { + return uuid.substring(4, 8); + } + } + if (!BluetoothManager_UUIDIsValid128Bit(uuid)) { + throw new WebAPIException( + WebAPIException.INVALID_VALUES_ERR, + 'Given parameter is not a supported uuid format: ' + uuid + ); + } + if (BluetoothManager_UUIDIsConvertibleTo16Bit(uuid)) { + return uuid.substring(4, 8); + } + if (BluetoothManager_UUIDIsConvertibleTo32Bit(uuid)) { + return uuid.substring(0, 8); + } + return uuid; +}; + +var BluetoothManager_UUIDsEqual = function(uuid1, uuid2) { + uuid1 = Converter.toString(uuid1).toLowerCase(); + uuid1 = BluetoothManager_UUIDTo128bit(uuid1); + uuid2 = Converter.toString(uuid2).toLowerCase(); + uuid2 = BluetoothManager_UUIDTo128bit(uuid2); + return uuid1 === uuid2; +}; + +BluetoothManager.prototype.uuidTo128bit = function(uuid) { + privUtils_.log('Entered BluetoothManager.uuidTo128bit()'); + var args = AV.validateArgs(arguments, [ + { + name: 'uuid', + type: AV.Types.STRING + } + ]); + return BluetoothManager_UUIDTo128bit(args.uuid); +}; + +BluetoothManager.prototype.uuidToShortestPossible = function(uuid) { + privUtils_.log('Entered BluetoothManager.uuidToShortestPossible()'); + var args = AV.validateArgs(arguments, [ + { + name: 'uuid', + type: AV.Types.STRING + } + ]); + return BluetoothManager_UUIDToShortestPossible(args.uuid); +}; + +BluetoothManager.prototype.uuidsEqual = function(uuid1, uuid2) { + privUtils_.log('Entered BluetoothManager.uuidsEqual()'); + var args = AV.validateArgs(arguments, [ + { + name: 'uuid1', + type: AV.Types.STRING + }, + { + name: 'uuid2', + type: AV.Types.STRING + } + ]); + return BluetoothManager_UUIDsEqual(args.uuid1, args.uuid2); +}; // exports ////////////////////////////////////////// exports = new BluetoothManager(); diff --git a/src/bluetooth/ut/js/test_UUIDTo128bit.js b/src/bluetooth/ut/js/test_UUIDTo128bit.js new file mode 100644 index 00000000..868c6e3e --- /dev/null +++ b/src/bluetooth/ut/js/test_UUIDTo128bit.js @@ -0,0 +1,245 @@ +mocha.setup('bdd'); + +var BASE_UUID_LAST_96_BITS = '-0000-1000-8000-00805f9b34fb'; +var ZEROS = '0000'; + +describe('uuidTo128bit', function() { + it('should return 128 bit representation of given 16 bit UUID 1234', function(done) { + var UUID16Bit = '1234'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID16Bit)).to.equal(UUID128Bit); + done(); + }); + it('should return 128 bit representation of given 16 bit UUID abcd', function(done) { + var UUID16Bit = 'abcd'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID16Bit)).to.equal(UUID128Bit); + done(); + }); + it('should return 128 bit representation of given 16 bit UUID 90df', function(done) { + var UUID16Bit = '90df'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID16Bit)).to.equal(UUID128Bit); + done(); + }); + it('should return 128 bit representation of given 16 bit UUID ABCD', function(done) { + var UUID16Bit = 'ABCD'; + var UUID128Bit = ZEROS + UUID16Bit.toLowerCase() + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID16Bit)).to.equal(UUID128Bit); + done(); + }); + it('should return 128 bit representation of given 16 bit UUID AbCd', function(done) { + var UUID16Bit = 'AbCd'; + var UUID128Bit = ZEROS + UUID16Bit.toLowerCase() + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID16Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return 128 bit representation of given 32 bit UUID 1234abcd', + function(done) { + var UUID32Bit = '1234abcd'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID32Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return 128 bit representation of given 32 bit UUID 12340987', + function(done) { + var UUID32Bit = '12340987'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID32Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return 128 bit representation of given 32 bit UUID fedcabcd', + function(done) { + var UUID32Bit = 'fedcabcd'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID32Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return 128 bit representation of given 32 bit UUID ABCDEFAB', + function(done) { + var UUID32Bit = 'ABCDEFAB'; + var UUID128Bit = UUID32Bit.toLowerCase() + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID32Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return 128 bit representation of given 32 bit UUID FeDcBaCA', + function(done) { + var UUID32Bit = 'FeDcBaCA'; + var UUID128Bit = UUID32Bit.toLowerCase() + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID32Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return given 128 bin UUID, 1234abcd-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID128Bit = '1234abcd-0000-1000-8000-00805f9b34fb'; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID128Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return given 128 bin UUID, 12345678-9012-3456-7890-123456789012', + function(done) { + var UUID128Bit = '12345678-9012-3456-7890-123456789012'; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID128Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return given 128 bin UUID, abcdefab-cdef-abcd-efab-cdefabcdefab', + function(done) { + var UUID128Bit = 'abcdefab-cdef-abcd-efab-cdefabcdefab'; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID128Bit)).to.equal(UUID128Bit); + done(); + }); + // prettier-ignore + it('should return given 128 bin UUID, ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB', + function(done) { + var UUID128Bit = 'ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB'; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID128Bit)).to.equal( + UUID128Bit.toLowerCase() + ); + done(); + }); + // prettier-ignore + it('should return given 128 bin UUID, ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAB', + function(done) { + var UUID128Bit = 'ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAB'; + chai.expect(tizen.bluetooth.uuidTo128bit(UUID128Bit)).to.equal( + UUID128Bit.toLowerCase() + ); + done(); + }); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + 'NotAValidUUID', + function(done) { + try { + tizen.bluetooth.uuidTo128bit('NotAValidUUID'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + // prettier-ignore + it('should throw InvalidValuesError if argument is not valid UUID, 12t4', + function(done) { + try { + tizen.bluetooth.uuidTo128bit('12t4'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + // prettier-ignore + it('should throw InvalidValuesError if argument is not valid UUID, 123456t8', + function(done) { + try { + tizen.bluetooth.uuidTo128bit('123456t8'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-00t0-0000-0000-1234567890ab', + function(done) { + try { + tizen.bluetooth.uuidTo128bit('12345678-00t0-0000-0000-1234567890ab'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + // prettier-ignore + it('should throw InvalidValuesError if argument is not valid UUID, 123', + function(done) { + try { + tizen.bluetooth.uuidTo128bit('123'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + // prettier-ignore + it('should throw InvalidValuesError if argument is not valid UUID, abcdef', + function(done) { + try { + tizen.bluetooth.uuidTo128bit('abcdef'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-9012-3456-7890-12345678901', + function(done) { + try { + tizen.bluetooth.uuidTo128bit('12345678-9012-3456-7890-12345678901'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-9012-3456-7890-1234567890123', + function(done) { + try { + tizen.bluetooth.uuidTo128bit('12345678-9012-3456-7890-1234567890123'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it('should throw InvalidValuesError if argument is undefined', function(done) { + try { + var undef; + tizen.bluetooth.uuidTo128bit(undef); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + it('should throw InvalidValuesError if argument is null', function(done) { + try { + tizen.bluetooth.uuidTo128bit(null); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); +}); + +mocha.checkLeaks(); +mocha + .run() + .on('pass', function(test) { + console.log(test.title + ' OK'); + }) + .on('fail', function(test, err) { + console.error(test.title + ' FAILED'); + console.error(err); + }) + .on('end', function() { + console.log('All done'); + }); diff --git a/src/bluetooth/ut/js/test_UUIDToShortestPossible.js b/src/bluetooth/ut/js/test_UUIDToShortestPossible.js new file mode 100644 index 00000000..c5ada4b6 --- /dev/null +++ b/src/bluetooth/ut/js/test_UUIDToShortestPossible.js @@ -0,0 +1,283 @@ +mocha.setup('bdd'); +var BASE_UUID_LAST_96_BITS = '-0000-1000-8000-00805f9b34fb'; +var ZEROS = '0000'; + +describe('uuidToShortestPossible', function() { + it('should return 16 bit representation of given 128 bit UUID, 1234', function(done) { + var UUID16Bit = '1234'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 128 bit UUID, abcd', function(done) { + var UUID16Bit = 'abcd'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 128 bit UUID, 90df', function(done) { + var UUID16Bit = '90df'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 128 bit UUID, ABCD', function(done) { + var UUID16Bit = 'ABCD'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + UUID16Bit = UUID16Bit.toLowerCase(); + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 128 bit UUID, AbCd', function(done) { + var UUID16Bit = 'AbCd'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + UUID16Bit = UUID16Bit.toLowerCase(); + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 32 bit UUID, 1234', function(done) { + var UUID16Bit = '1234'; + var UUID32Bit = ZEROS + UUID16Bit; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID32Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 32 bit UUID, abcd', function(done) { + var UUID16Bit = 'abcd'; + var UUID32Bit = ZEROS + UUID16Bit; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID32Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 32 bit UUID, 90df', function(done) { + var UUID16Bit = '90df'; + var UUID32Bit = ZEROS + UUID16Bit; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID32Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 32 bit UUID, ABCD', function(done) { + var UUID16Bit = 'ABCD'; + var UUID32Bit = ZEROS + UUID16Bit; + UUID16Bit = UUID16Bit.toLowerCase(); + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID32Bit)).to.equal( + UUID16Bit + ); + done(); + }); + it('should return 16 bit representation of given 32 bit UUID, AbCd', function(done) { + var UUID16Bit = 'AbCd'; + var UUID32Bit = ZEROS + UUID16Bit; + UUID16Bit = UUID16Bit.toLowerCase(); + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID32Bit)).to.equal( + UUID16Bit + ); + done(); + }); + // prettier-ignore + it('should return 32 bit representation of given 128 bit UUID, 12345678', + function(done) { + var UUID32Bit = '12347890'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID32Bit + ); + done(); + }); + // prettier-ignore + it('should return 32 bit representation of given 128 bit UUID, abcdefab', + function(done) { + var UUID32Bit = 'abcdefab'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID32Bit + ); + done(); + }); + // prettier-ignore + it('should return 32 bit representation of given 128 bit UUID, 9012cdef', + function(done) { + var UUID32Bit = '1560cdef'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID32Bit + ); + done(); + }); + // prettier-ignore + it('should return 32 bit representation of given 128 bit UUID, ABCDEFAB', + function(done) { + var UUID32Bit = 'ABCDEFAB'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + UUID32Bit = UUID32Bit.toLowerCase(); + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID32Bit + ); + done(); + }); + // prettier-ignore + it('should return 32 bit representation of given 128 bit UUID, CdEfAbCd', + function(done) { + var UUID32Bit = 'CdEfAbCd'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + UUID32Bit = UUID32Bit.toLowerCase(); + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID32Bit + ); + done(); + }); + // prettier-ignore + it('should return given 128 bit UUID, 12345678-9012-3456-7890-123456789012', + function(done) { + var UUID128Bit = '12345678-9012-3456-7890-123456789012'; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID128Bit + ); + done(); + }); + // prettier-ignore + it('should return given 128 bit UUID, abcdefab-cdef-abcd-efab-cdefabcdefab', + function(done) { + var UUID128Bit = 'abcdefab-cdef-abcd-efab-cdefabcdefab'; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID128Bit + ); + done(); + }); + // prettier-ignore + it('should return given 128 bit UUID, 12345678-90ab-cdef-1234-567890abcdef', + function(done) { + var UUID128Bit = '12345678-90ab-cdef-1234-567890abcdef'; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID128Bit + ); + done(); + }); + // prettier-ignore + it('should return given 128 bit UUID, ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB', + function(done) { + var UUID128Bit = 'ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB'; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID128Bit.toLowerCase() + ); + done(); + }); + // prettier-ignore + it('should return given 128 bit UUID, ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAB', + function(done) { + var UUID128Bit = 'ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAB'; + chai.expect(tizen.bluetooth.uuidToShortestPossible(UUID128Bit)).to.equal( + UUID128Bit.toLowerCase() + ); + done(); + }); + // prettier-ignore + it('should throw InvalidValuesError if argument is not valid UUID, NotAValidUUID', + function(done) { + try { + tizen.bluetooth.uuidToShortestPossible('NotAValidUUID'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + // prettier-ignore + it('should throw InvalidValuesError if argument is not valid UUID, 123', + function(done) { + try { + tizen.bluetooth.uuidToShortestPossible('123'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + // prettier-ignore + it('should throw InvalidValuesError if argument is not valid UUID, abcdef', + function(done) { + try { + tizen.bluetooth.uuidToShortestPossible('abcdef'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-9012-3456-7890-12345678901', + function(done) { + try { + tizen.bluetooth.uuidToShortestPossible( + '12345678-9012-3456-7890-12345678901' + ); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-9012-3456-7890-1234567890123', + function(done) { + try { + tizen.bluetooth.uuidToShortestPossible( + '12345678-9012-3456-7890-1234567890123' + ); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it('should throw InvalidValuesError if argument is undefined', function(done) { + try { + var undef; + tizen.bluetooth.uuidToShortestPossible(undef); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + it('should throw InvalidValuesError if argument is null', function(done) { + try { + tizen.bluetooth.uuidToShortestPossible(null); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); +}); + +mocha.checkLeaks(); +mocha + .run() + .on('pass', function(test) { + console.log(test.title + ' OK'); + }) + .on('fail', function(test, err) { + console.error(test.title + ' FAILED'); + console.error(err); + }) + .on('end', function() { + console.log('All done'); + }); diff --git a/src/bluetooth/ut/js/test_UUIDsEqual.js b/src/bluetooth/ut/js/test_UUIDsEqual.js new file mode 100644 index 00000000..ca02be25 --- /dev/null +++ b/src/bluetooth/ut/js/test_UUIDsEqual.js @@ -0,0 +1,587 @@ +mocha.setup('bdd'); + +var BASE_UUID_LAST_96_BITS = '-0000-1000-8000-00805f9b34fb'; +var ZEROS = '0000'; + +describe('uuidsEqual', function() { + it('should return true, 1234', function(done) { + var UUID16Bit = '1234'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID16Bit)).to.equal(true); + done(); + }); + it('should return true, abcd', function(done) { + var UUID16Bit = 'abcd'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID16Bit)).to.equal(true); + done(); + }); + it('should return true, 56df', function(done) { + var UUID16Bit = '56df'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID16Bit)).to.equal(true); + done(); + }); + it('should return true, aBcD and AbCd', function(done) { + var UUID16Bit1 = 'aBcD'; + var UUID16Bit2 = 'AbCd'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit1, UUID16Bit2)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit2, UUID16Bit1)).to.equal(true); + done(); + }); + it('should return true, abcd and ABCD', function(done) { + var UUID16Bit1 = 'abcd'; + var UUID16Bit2 = 'ABCD'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit1, UUID16Bit2)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit2, UUID16Bit1)).to.equal(true); + done(); + }); + it('should return false, 1234 and 1235', function(done) { + var UUID16Bit1 = '1234'; + var UUID16Bit2 = '1235'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit1, UUID16Bit2)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit2, UUID16Bit1)).to.equal(false); + done(); + }); + it('should return false, abcd and abce', function(done) { + var UUID16Bit1 = 'abcd'; + var UUID16Bit2 = 'abce'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit1, UUID16Bit2)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit2, UUID16Bit1)).to.equal(false); + done(); + }); + it('should return false, 89df and 89de', function(done) { + var UUID16Bit1 = '89df'; + var UUID16Bit2 = '89de'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit1, UUID16Bit2)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit2, UUID16Bit1)).to.equal(false); + done(); + }); + it('should return false, CDEF and CDEA', function(done) { + var UUID16Bit1 = 'CDEF'; + var UUID16Bit2 = 'CDEA'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit1, UUID16Bit2)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit2, UUID16Bit1)).to.equal(false); + done(); + }); + it('should return false, aBcD and aBce', function(done) { + var UUID16Bit1 = 'aBcD'; + var UUID16Bit2 = 'aBce'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit1, UUID16Bit2)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit2, UUID16Bit1)).to.equal(false); + done(); + }); + + it('should return true, 1234 and 00001234', function(done) { + var UUID16Bit = '1234'; + var UUID32Bit = ZEROS + UUID16Bit; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(true); + done(); + }); + it('should return true, abcd and 0000abcd', function(done) { + var UUID16Bit = 'abcd'; + var UUID32Bit = ZEROS + UUID16Bit; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(true); + done(); + }); + it('should return true, 56ef and 000056ef', function(done) { + var UUID16Bit = '56ef'; + var UUID32Bit = ZEROS + UUID16Bit; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(true); + done(); + }); + it('should return true, ABCD and 0000ABCD', function(done) { + var UUID16Bit = 'ABCD'; + var UUID32Bit = ZEROS + UUID16Bit; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(true); + done(); + }); + it('should return true, AbCd and 0000AbCd', function(done) { + var UUID16Bit = 'AbCd'; + var UUID32Bit = ZEROS + UUID16Bit; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(true); + done(); + }); + it('should return false, 1234 and 00001233', function(done) { + var UUID16Bit = '1234'; + var UUID32Bit = ZEROS + '1233'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(false); + done(); + }); + it('should return false, abcd and 0000abcd', function(done) { + var UUID16Bit = 'abcd'; + var UUID32Bit = ZEROS + 'bbcd'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(false); + done(); + }); + it('should return false, 56ef and 000056ef', function(done) { + var UUID16Bit = '56ef'; + var UUID32Bit = ZEROS + '56e0'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(false); + done(); + }); + it('should return false, ABCD and 0000AACD', function(done) { + var UUID16Bit = 'ABCD'; + var UUID32Bit = ZEROS + 'AACD'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(false); + done(); + }); + it('should return false, AbCd and 0000Abdd', function(done) { + var UUID16Bit = 'AbCd'; + var UUID32Bit = ZEROS + 'Abdd'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID32Bit)).to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID16Bit)).to.equal(false); + done(); + }); + // prettier-ignore + it('should return true, 1234 and 00001234-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = '1234'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return true, abcd and 0000abcd-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = 'abcd'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return true, 56ef and 000056ef-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = '56ef'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return true, ABCD and 0000ABCD-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = 'ABCD'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return true, AbCd and 0000AbCd-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = 'AbCd'; + var UUID128Bit = ZEROS + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return false, 1234 and 00002234-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = '1234'; + var UUID128Bit = ZEROS + '2234' + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return false, abcd and 0000aacd-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = 'abcd'; + var UUID128Bit = ZEROS + 'aacd' + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return false, 56ef and 000056ff-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = '56ef'; + var UUID128Bit = ZEROS + '56ff' + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return false, ABCD and 0000ABCC-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = 'ABCD'; + var UUID128Bit = ZEROS + 'ABCC' + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return false, AbCd and 1000AbCd-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID16Bit = 'AbCd'; + var UUID128Bit = '1000' + UUID16Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID16Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID16Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return true, 12345678 and 12345678-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = '12345678'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return true, abcdefab and abcdefab-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = 'abcdefab'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return true, cdef9012 and cdef9012-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = 'cdef9012'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return true, ABCDEFAB and ABCDEFAB-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = 'ABCDEFAB'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return true, CdEfAbdC and CdEfAbdC-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = 'CdEfAbdC'; + var UUID128Bit = UUID32Bit + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)).to.equal(true); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)).to.equal(true); + done(); + }); + // prettier-ignore + it('should return false, 12345678 and 34345678-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = '12345678'; + var UUID128Bit = '34345678' + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return false, abcdefab and ababefab-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = 'abcdefab'; + var UUID128Bit = 'ababefab' + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return false, cdef9012 and cdef1212-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = 'cdef9012'; + var UUID128Bit = 'cdef1212' + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return false, ABCDEFAB and ABCDEFEF-0000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = 'ABCDEFAB'; + var UUID128Bit = 'ABCDEFEF' + BASE_UUID_LAST_96_BITS; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)) + .to.equal(false); + done(); + }); + // prettier-ignore + it('should return false, CdEfAbdC and CdEfAbdC-1000-1000-8000-00805f9b34fb', + function(done) { + var UUID32Bit = 'CdEfAbdC'; + var UUID128Bit = 'CdEfAbdC-1000-1000-8000-00805f9b34fb'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID32Bit, UUID128Bit)) + .to.equal(false); + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID32Bit)) + .to.equal(false); + done(); + }); + + it('should return true, 12345678-9012-3456-7890-123456789012', function(done) { + var UUID128Bit = '12345678-9012-3456-7890-123456789012'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID128Bit)).to.equal(true); + done(); + }); + it('should return true, abcdefab-cdef-abcd-efab-cdefabcdefab', function(done) { + var UUID128Bit = 'abcdefab-cdef-abcd-efab-cdefabcdefab'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID128Bit)).to.equal(true); + done(); + }); + it('should return true, 12345678-90ab-cdef-1234-567890abcdef', function(done) { + var UUID128Bit = '12345678-90ab-cdef-1234-567890abcdef'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID128Bit)).to.equal(true); + done(); + }); + it('should return true, ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB', function(done) { + var UUID128Bit = 'ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID128Bit)).to.equal(true); + done(); + }); + it('should return true, ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAB', function(done) { + var UUID128Bit = 'ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAB'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit, UUID128Bit)).to.equal(true); + done(); + }); + it('should return false, 12345678-9012-3456-7890-123456789012', function(done) { + var UUID128Bit1 = '12345678-9012-3456-7890-123456789012'; + var UUID128Bit2 = '22345678-9012-3456-7890-123456789012'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit1, UUID128Bit2)).to.equal(false); + done(); + }); + it('should return false, abcdefab-cdef-abcd-efab-cdefabcdefab', function(done) { + var UUID128Bit1 = 'abcdefab-cdef-abcd-efab-cdefabcdefab'; + var UUID128Bit2 = 'abcdefab-ddef-abcd-efab-cdefabcdefab'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit1, UUID128Bit2)).to.equal(false); + done(); + }); + it('should return false, 12345678-90ab-cdef-1234-567890abcdef', function(done) { + var UUID128Bit1 = '12345678-90ab-cdef-1234-567890abcdef'; + var UUID128Bit2 = '12345678-90ab-ddef-1234-567890abcdef'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit1, UUID128Bit2)).to.equal(false); + done(); + }); + it('should return false, ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB', function(done) { + var UUID128Bit1 = 'ABCDEFAB-CDEF-ABCD-EFAB-CDEFABCDEFAB'; + var UUID128Bit2 = 'ABCDEFAB-CDEF-ABCD-EFAA-CDEFABCDEFAB'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit1, UUID128Bit2)).to.equal(false); + done(); + }); + it('should return false, ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAB', function(done) { + var UUID128Bit1 = 'ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAB'; + var UUID128Bit2 = 'ABCDEFAB-cdef-ABCD-efab-CDEFABCDEFAA'; + chai.expect(tizen.bluetooth.uuidsEqual(UUID128Bit1, UUID128Bit2)).to.equal(false); + done(); + }); + + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + 'NotAValidUUID - first argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual('NotAValidUUID', '1234'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '123 - first argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual('123', '1234'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + 'abcdef - first argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual('abcdef', '1234'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-9012-3456-7890-12345678901 - first argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual('12345678-9012-3456-7890-12345678901', '1234'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-9012-3456-7890-1234567890123 - first argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual( + '12345678-9012-3456-7890-1234567890123', + '1234' + ); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it('should throw InvalidValuesError if first argument is undefined', function(done) { + try { + var undef; + tizen.bluetooth.uuidsEqual(undef, '1234'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + it('should throw InvalidValuesError if first argument is null', function(done) { + try { + tizen.bluetooth.uuidsEqual(null, '1234'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + 'NotAValidUUID - second argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual('1234', 'NotAValidUUID'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '123 - second argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual('1234', '123'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + 'abcdef - second argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual('1234', 'abcdef'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-9012-3456-7890-12345678901 - second argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual('1234', '12345678-9012-3456-7890-12345678901'); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it( + 'should throw InvalidValuesError if argument is not valid UUID, ' + + '12345678-9012-3456-7890-1234567890123 - second argument', + function(done) { + try { + tizen.bluetooth.uuidsEqual( + '1234', + '12345678-9012-3456-7890-1234567890123' + ); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + } + ); + it('should throw InvalidValuesError if second argument is undefined', function(done) { + try { + var undef; + tizen.bluetooth.uuidsEqual('1234', undef); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); + it('should throw InvalidValuesError if second argument is null', function(done) { + try { + tizen.bluetooth.uuidsEqual('1234', null); + done(new Error('Expected InvalidValuesError.')); + } catch (error) { + chai.expect(error.name).to.equal('InvalidValuesError'); + done(); + } + }); +}); + +mocha.checkLeaks(); +mocha + .run() + .on('pass', function(test) { + console.log(test.title + ' OK'); + }) + .on('fail', function(test, err) { + console.error(test.title + ' FAILED'); + console.error(err); + }) + .on('end', function() { + console.log('All done'); + }); -- 2.34.1