Skip to content

Commit

Permalink
Merge branch 'canonical:main' into generate-array-map-missing-cast
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-ancell authored Mar 28, 2022
2 parents 8b0fa91 + a74f713 commit e558cf5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 51 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,24 @@ jobs:
run: dart pub get

- name: Run regression tests
run: dart run test_cov
run: dart test

coverage:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- uses: subosito/flutter-action@v1

- name: Print Flutter SDK version
run: flutter --version

- name: Install dependencies
run: flutter pub get

- name: Collect coverage
run: flutter test --coverage

- name: Upload coverage
uses: codecov/codecov-action@v1
Expand Down
6 changes: 3 additions & 3 deletions lib/src/dbus_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ class DBusClient {
Future<void> ping([String destination = 'org.freedesktop.DBus']) async {
await callMethod(
destination: destination,
path: DBusObjectPath('/'),
path: DBusObjectPath.root,
interface: 'org.freedesktop.DBus.Peer',
name: 'Ping',
replySignature: DBusSignature(''));
Expand All @@ -576,7 +576,7 @@ class DBusClient {
[String destination = 'org.freedesktop.DBus']) async {
var result = await callMethod(
destination: destination,
path: DBusObjectPath('/'),
path: DBusObjectPath.root,
interface: 'org.freedesktop.DBus.Peer',
name: 'GetMachineId',
replySignature: DBusSignature('s'));
Expand Down Expand Up @@ -1029,7 +1029,7 @@ class DBusClient {

var signal = DBusSignal(
sender: message.sender?.value ?? '',
path: message.path ?? DBusObjectPath('/'),
path: message.path ?? DBusObjectPath.root,
interface: message.interface?.value ?? '',
name: message.member?.value ?? '',
values: message.values);
Expand Down
56 changes: 20 additions & 36 deletions lib/src/dbus_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ class DBusByte extends DBusValue {
final int value;

/// Creates a new byte with the given [value].
DBusByte(this.value) {
if (value.isNegative || value > 255) {
throw ArgumentError.value(
value, 'value', 'Byte must be in range [0, 255]');
}
}
const DBusByte(this.value)
: assert(value >= 0 && value <= 255, 'Byte must be in range [0, 255]');

@override
DBusSignature get signature {
Expand Down Expand Up @@ -106,12 +102,9 @@ class DBusInt16 extends DBusValue {
final int value;

/// Creates a new signed 16 bit integer with the given [value].
DBusInt16(this.value) {
if (value < -32768 || value > 32767) {
throw ArgumentError.value(
value, 'value', 'Int16 must be in range [-32768, 32767]');
}
}
const DBusInt16(this.value)
: assert(value >= -32768 && value <= 32767,
'Int16 must be in range [-32768, 32767]');

@override
DBusSignature get signature {
Expand Down Expand Up @@ -139,12 +132,9 @@ class DBusUint16 extends DBusValue {
final int value;

/// Creates a new unsigned 16 bit integer with the given [value].
DBusUint16(this.value) {
if (value.isNegative || value > 65535) {
throw ArgumentError.value(
value, 'value', 'Uint16 must be in range [0, 65535]');
}
}
const DBusUint16(this.value)
: assert(
value >= 0 && value <= 65535, 'Uint16 must be in range [0, 65535]');

@override
DBusSignature get signature {
Expand Down Expand Up @@ -172,12 +162,9 @@ class DBusInt32 extends DBusValue {
final int value;

/// Creates a new signed 32 bit integer with the given [value].
DBusInt32(this.value) {
if (value < -2147483648 || value > 2147483647) {
throw ArgumentError.value(
value, 'value', 'Int32 must be in range [-2147483648, 2147483647]');
}
}
const DBusInt32(this.value)
: assert(value >= -2147483648 && value <= 2147483647,
'Int32 must be in range [-2147483648, 2147483647]');

@override
DBusSignature get signature {
Expand Down Expand Up @@ -205,12 +192,9 @@ class DBusUint32 extends DBusValue {
final int value;

/// Creates a new unsigned 32 bit integer with the given [value].
DBusUint32(this.value) {
if (value.isNegative || value > 4294967295) {
throw ArgumentError.value(
value, 'value', 'Uint32 must be in range [0, 4294967295]');
}
}
const DBusUint32(this.value)
: assert(value >= 0 && value <= 4294967295,
'Uint32 must be in range [0, 4294967295]');

@override
DBusSignature get signature {
Expand Down Expand Up @@ -238,12 +222,9 @@ class DBusInt64 extends DBusValue {
final int value;

/// Creates a new signed 64 bit integer with the given [value].
DBusInt64(this.value) {
if (value < -(1 << 63) || value > (1 << 63) - 1) {
throw ArgumentError.value(value, 'value',
'Int64 must be in range [-9223372036854775808, 9223372036854775807]');
}
}
const DBusInt64(this.value)
: assert(value >= -(1 << 63) && value <= (1 << 63) - 1,
'Int64 must be in range [-9223372036854775808, 9223372036854775807]');

@override
DBusSignature get signature {
Expand Down Expand Up @@ -376,6 +357,9 @@ class DBusObjectPath extends DBusString {
/// parameter default value). In all other cases use the standard constructor.
const DBusObjectPath.unchecked(String value) : super(value);

/// The root object path ("/").
static const DBusObjectPath root = DBusObjectPath.unchecked('/');

/// Splits an object path into separate elements, e.g. '/org/freedesktop/DBus' -> [ 'org', 'freedesktop', 'DBus' ].
List<String> split() {
if (value == '/') {
Expand Down
22 changes: 11 additions & 11 deletions test/dbus_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ class TestManagerObject extends DBusObject {

void main() {
test('value - byte', () async {
expect(() => DBusByte(-1), throwsArgumentError);
expect(() => DBusByte(-1), throwsA(isA<AssertionError>()));
expect(DBusByte(0).value, equals(0));
expect(DBusByte(255).value, equals(255));
expect(() => DBusByte(256), throwsArgumentError);
expect(() => DBusByte(256), throwsA(isA<AssertionError>()));
expect(DBusByte(0).signature, equals(DBusSignature('y')));
expect(DBusByte(42).toNative(), equals(42));
expect(DBusByte(42) == DBusByte(42), isTrue);
Expand Down Expand Up @@ -222,11 +222,11 @@ void main() {
});

test('value - int16', () async {
expect(() => DBusInt16(-32769), throwsArgumentError);
expect(() => DBusInt16(-32769), throwsA(isA<AssertionError>()));
expect(DBusInt16(-32768).value, equals(-32768));
expect(DBusInt16(0).value, equals(0));
expect(DBusInt16(32767).value, equals(32767));
expect(() => DBusInt16(32768), throwsArgumentError);
expect(() => DBusInt16(32768), throwsA(isA<AssertionError>()));
expect(DBusInt16(0).signature, equals(DBusSignature('n')));
expect(DBusInt16(-42).toNative(), equals(-42));
expect(DBusInt16(42) == DBusInt16(42), isTrue);
Expand All @@ -240,10 +240,10 @@ void main() {
});

test('value - uint16', () async {
expect(() => DBusUint16(-1), throwsArgumentError);
expect(() => DBusUint16(-1), throwsA(isA<AssertionError>()));
expect(DBusUint16(0).value, equals(0));
expect(DBusUint16(65535).value, equals(65535));
expect(() => DBusUint16(65536), throwsArgumentError);
expect(() => DBusUint16(65536), throwsA(isA<AssertionError>()));
expect(DBusUint16(0).signature, equals(DBusSignature('q')));
expect(DBusUint16(42).toNative(), equals(42));
expect(DBusUint16(42) == DBusUint16(42), isTrue);
Expand All @@ -257,11 +257,11 @@ void main() {
});

test('value - int32', () async {
expect(() => DBusInt32(-2147483649), throwsArgumentError);
expect(() => DBusInt32(-2147483649), throwsA(isA<AssertionError>()));
expect(DBusInt32(-2147483648).value, equals(-2147483648));
expect(DBusInt32(0).value, equals(0));
expect(DBusInt32(2147483647).value, equals(2147483647));
expect(() => DBusInt32(2147483648), throwsArgumentError);
expect(() => DBusInt32(2147483648), throwsA(isA<AssertionError>()));
expect(DBusInt32(0).signature, equals(DBusSignature('i')));
expect(DBusInt32(-42).toNative(), equals(-42));
expect(DBusInt32(42) == DBusInt32(42), isTrue);
Expand All @@ -275,10 +275,10 @@ void main() {
});

test('value - uint32', () async {
expect(() => DBusUint32(-1), throwsArgumentError);
expect(() => DBusUint32(-1), throwsA(isA<AssertionError>()));
expect(DBusUint32(0).value, equals(0));
expect(DBusUint32(4294967295).value, equals(4294967295));
expect(() => DBusUint32(4294967296), throwsArgumentError);
expect(() => DBusUint32(4294967296), throwsA(isA<AssertionError>()));
expect(DBusUint32(0).signature, equals(DBusSignature('u')));
expect(DBusUint32(42).toNative(), equals(42));
expect(DBusUint32(42) == DBusUint32(42), isTrue);
Expand Down Expand Up @@ -310,7 +310,7 @@ void main() {
test('value - uint64', () async {
expect(DBusUint64(0).value, equals(0));
expect(DBusUint64(0xffffffffffffffff).value, equals(0xffffffffffffffff));
expect(() => DBusUint32(4294967296), throwsArgumentError);
expect(() => DBusUint32(4294967296), throwsA(isA<AssertionError>()));
expect(DBusUint64(0).signature, equals(DBusSignature('t')));
expect(DBusUint64(42).toNative(), equals(42));
expect(DBusUint64(42) == DBusUint64(42), isTrue);
Expand Down

0 comments on commit e558cf5

Please sign in to comment.