From 34462a31f1c1abecca72c411a7b5c14146d29cc4 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 21 Mar 2022 20:52:08 +0100 Subject: [PATCH 1/3] Add DBusObjectPath.root constant --- lib/src/dbus_client.dart | 6 +++--- lib/src/dbus_value.dart | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/dbus_client.dart b/lib/src/dbus_client.dart index f565a5b..c2aec79 100644 --- a/lib/src/dbus_client.dart +++ b/lib/src/dbus_client.dart @@ -564,7 +564,7 @@ class DBusClient { Future 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('')); @@ -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')); @@ -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); diff --git a/lib/src/dbus_value.dart b/lib/src/dbus_value.dart index 464d0de..96ec4b5 100644 --- a/lib/src/dbus_value.dart +++ b/lib/src/dbus_value.dart @@ -376,6 +376,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 split() { if (value == '/') { From 5386775ccb1ab877508dd61f2bd2824dcf54fd1c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 22 Mar 2022 18:27:06 +0100 Subject: [PATCH 2/3] CI: use flutter_tools for collecting coverage test_cov has issues with assert() as discussed in #334. --- .github/workflows/test.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13c8b1c..1294f1d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 From a74f7133cc60244d026d5ccbb1f24935323a6d96 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 21 Mar 2022 11:22:52 +0100 Subject: [PATCH 3/3] Const constructors for integer value types Close: #332 --- lib/src/dbus_value.dart | 53 +++++++++++++---------------------------- test/dbus_test.dart | 22 ++++++++--------- 2 files changed, 28 insertions(+), 47 deletions(-) diff --git a/lib/src/dbus_value.dart b/lib/src/dbus_value.dart index 96ec4b5..6175529f 100644 --- a/lib/src/dbus_value.dart +++ b/lib/src/dbus_value.dart @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/test/dbus_test.dart b/test/dbus_test.dart index 959dd62..0f32931 100644 --- a/test/dbus_test.dart +++ b/test/dbus_test.dart @@ -188,10 +188,10 @@ class TestManagerObject extends DBusObject { void main() { test('value - byte', () async { - expect(() => DBusByte(-1), throwsArgumentError); + expect(() => DBusByte(-1), throwsA(isA())); expect(DBusByte(0).value, equals(0)); expect(DBusByte(255).value, equals(255)); - expect(() => DBusByte(256), throwsArgumentError); + expect(() => DBusByte(256), throwsA(isA())); expect(DBusByte(0).signature, equals(DBusSignature('y'))); expect(DBusByte(42).toNative(), equals(42)); expect(DBusByte(42) == DBusByte(42), isTrue); @@ -222,11 +222,11 @@ void main() { }); test('value - int16', () async { - expect(() => DBusInt16(-32769), throwsArgumentError); + expect(() => DBusInt16(-32769), throwsA(isA())); 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())); expect(DBusInt16(0).signature, equals(DBusSignature('n'))); expect(DBusInt16(-42).toNative(), equals(-42)); expect(DBusInt16(42) == DBusInt16(42), isTrue); @@ -240,10 +240,10 @@ void main() { }); test('value - uint16', () async { - expect(() => DBusUint16(-1), throwsArgumentError); + expect(() => DBusUint16(-1), throwsA(isA())); expect(DBusUint16(0).value, equals(0)); expect(DBusUint16(65535).value, equals(65535)); - expect(() => DBusUint16(65536), throwsArgumentError); + expect(() => DBusUint16(65536), throwsA(isA())); expect(DBusUint16(0).signature, equals(DBusSignature('q'))); expect(DBusUint16(42).toNative(), equals(42)); expect(DBusUint16(42) == DBusUint16(42), isTrue); @@ -257,11 +257,11 @@ void main() { }); test('value - int32', () async { - expect(() => DBusInt32(-2147483649), throwsArgumentError); + expect(() => DBusInt32(-2147483649), throwsA(isA())); 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())); expect(DBusInt32(0).signature, equals(DBusSignature('i'))); expect(DBusInt32(-42).toNative(), equals(-42)); expect(DBusInt32(42) == DBusInt32(42), isTrue); @@ -275,10 +275,10 @@ void main() { }); test('value - uint32', () async { - expect(() => DBusUint32(-1), throwsArgumentError); + expect(() => DBusUint32(-1), throwsA(isA())); expect(DBusUint32(0).value, equals(0)); expect(DBusUint32(4294967295).value, equals(4294967295)); - expect(() => DBusUint32(4294967296), throwsArgumentError); + expect(() => DBusUint32(4294967296), throwsA(isA())); expect(DBusUint32(0).signature, equals(DBusSignature('u'))); expect(DBusUint32(42).toNative(), equals(42)); expect(DBusUint32(42) == DBusUint32(42), isTrue); @@ -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())); expect(DBusUint64(0).signature, equals(DBusSignature('t'))); expect(DBusUint64(42).toNative(), equals(42)); expect(DBusUint64(42) == DBusUint64(42), isTrue);