Skip to content

Commit

Permalink
More improvements and ToDos
Browse files Browse the repository at this point in the history
  • Loading branch information
fotiDim committed Jul 12, 2024
1 parent 25b857f commit 9ce7956
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 143 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.10.0"
version: "0.11.0"
vector_math:
dependency: transitive
description:
Expand Down
168 changes: 168 additions & 0 deletions test/ble_uuid_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// TODO add Github Action for running on Linux and web
import 'package:flutter_test/flutter_test.dart';
import 'package:universal_ble/universal_ble.dart';

void main() {
group('parse', () {
// TODO test all parse code paths
group('throws exception when', () {
test('when length is less than 4', () {
expect(
() => BleUuid.parse('123'),
throwsFormatException,
);
});
test('when having more "-"s', () {
expect(
() => BleUuid.parse('0000-180a-0000-1000-8000-0080-5f9b-34fb'),
throwsFormatException,
);
});

test('when is too short', () {
expect(
() => BleUuid.parse('0000180a-0000-1000-8000-00805f9b34f'),
throwsFormatException,
);
});

test('when is too long', () {
expect(
() => BleUuid.parse('0000180a-0000-1000-8000-00805f9b34fba'),
throwsFormatException,
);
});
});

group('with success when', () {
test('128-bit UUID in lowercase', () {
expect(
BleUuid.parse('0000180a-0000-1000-8000-00805f9b34fb'),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

test('128-bit UUID in uppercase', () {
expect(
BleUuid.parse('0000180A-0000-1000-8000-00805F9B34FB'),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

test('16-bit UUID in lowercase', () {
expect(
BleUuid.parse('180a'),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

test('16-bit UUID in uppercase', () {
expect(
BleUuid.parse('180A'),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

test('32-bit UUID', () {
expect(
BleUuid.parse('0000180a'),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

test('UUID without dashes', () {
expect(
BleUuid.parse('0000180a00001000800000805f9b34fb'),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

test('lowercase 16-bit String to 128-bit starting with 0x', () {
expect(
() => BleUuid.parse('0x0180a'),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

test('uppercase 16-bit String to 128-bit starting with 0x', () {
expect(
() => BleUuid.parse('0x0180A'),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});
});
});

group('extend', () {
test('16-bit UUID in lowercase', () {
expect(
BleUuid.extend(0x180a),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

test('16-bit UUID in uppercase', () {
expect(
BleUuid.extend(0x180A),
equals('0000180a-0000-1000-8000-00805f9b34fb'),
);
});

// TODO Add 32 and 128 bit tests
// TODO Add tests for failure cases (empty, null, shorter or longer value, non hex)
});

group('equals', () {
test('true for Identical UUIDs', () {
expect(
BleUuid.equals('0000180a-0000-1000-8000-00805f9b34fb',
'0000180a-0000-1000-8000-00805f9b34fb'),
isTrue,
);
});

test('true for UUIDs with different character case', () {
expect(
BleUuid.equals('180A', '180a'),
isTrue,
);
});

test('true for the 16-bit and 128-bit representation of the same UUID', () {
expect(
BleUuid.equals('0000180a-0000-1000-8000-00805f9b34fb', '180a'),
isTrue,
);
});

test(
'true for the 16-bit and 128-bit representation of the same UUID without dashes',
() {
expect(
BleUuid.equals('0000180A00001000800000805F9B34FB', '180a'),
isTrue,
);
});

test('true for the 32-bit and 128-bit representation of the same UUID', () {
expect(
BleUuid.equals('0000180A', '0000180a-0000-1000-8000-00805f9b34fb'),
isTrue,
);
});

test('false for different UUIDs', () {
expect(
BleUuid.equals('180A', '180B'),
isFalse,
);
});

test('false for different UUIDs of different format', () {
expect(
BleUuid.equals('0000180A', '0000180b-0000-1000-8000-00805f9b34fb'),
isFalse,
);
});
});
}
142 changes: 0 additions & 142 deletions test/universal_ble_test.dart

This file was deleted.

0 comments on commit 9ce7956

Please sign in to comment.