Skip to content

Commit

Permalink
Add bare minimum test case
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-ancell committed Mar 1, 2023
1 parent 1f095ff commit 2683b48
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion test/xdg_status_notifier_item_test.dart
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
void main() {}
import 'dart:io';

import 'package:dbus/dbus.dart';
import 'package:xdg_status_notifier_item/xdg_status_notifier_item.dart';
import 'package:test/test.dart';

class MockNotifierWatcherObject extends DBusObject {
MockNotifierWatcherObject() : super(DBusObjectPath('/StatusNotifierWatcher'));

@override
Future<DBusMethodResponse> handleMethodCall(DBusMethodCall methodCall) async {
if (methodCall.interface != 'org.kde.StatusNotifierWatcher') {
return DBusMethodErrorResponse.unknownInterface();
}

switch (methodCall.name) {
case 'RegisterStatusNotifierItem':
return DBusMethodSuccessResponse();

default:
return DBusMethodErrorResponse.unknownMethod();
}
}
}

class MockNotifierWatcherServer extends DBusClient {
late final MockNotifierWatcherObject _root;

MockNotifierWatcherServer(DBusAddress clientAddress) : super(clientAddress) {
_root = MockNotifierWatcherObject();
}

Future<void> start() async {
await requestName('org.kde.StatusNotifierWatcher');
await registerObject(_root);
}
}

void main() {
test('connect', () async {
var server = DBusServer();
var clientAddress =
await server.listenAddress(DBusAddress.unix(dir: Directory.systemTemp));
addTearDown(() async {
await server.close();
});

var watcher = MockNotifierWatcherServer(clientAddress);
await watcher.start();
addTearDown(() async {
await watcher.close();
});

var client = StatusNotifierItemClient(id: 'test', menu: DBusMenuItem());
addTearDown(() async {
await client.close();
});
await client.connect();
});
}

0 comments on commit 2683b48

Please sign in to comment.