JsonRPC/examples/Dart/Test.dart

43 lines
921 B
Dart
Raw Normal View History

2022-07-21 16:33:23 +00:00
import 'dart:async';
import 'dart:io';
2022-07-21 07:09:10 +00:00
import "./out/lib/example.dart";
2022-07-20 21:40:44 +00:00
import "dart:convert";
2022-07-21 16:33:23 +00:00
void main() async {
var str = StreamController<Map<String, dynamic>>();
var provider = ServiceProvider(str.stream);
var sock = await Socket.connect("127.0.0.1", 8859);
utf8.decoder.bind(sock).transform(new LineSplitter()).listen((line) {
str.add(jsonDecode(line));
});
provider.output.stream.listen((event) {
sock.writeln(jsonEncode(event));
});
var s = new TestServiceClient(provider);
var r = await s.AddValuesMultipleParams(10, 15);
print(r);
var r2 =
await s.AddValuesSingleParam(AddValueRequest(value1: 10, value2: 15));
print(r2?.value);
var catched = false;
await s.ThrowingError().catchError((err) {
catched = true;
print("Expected error was catched: " + err.toString());
});
2022-07-20 21:40:44 +00:00
2022-07-21 16:33:23 +00:00
if (!catched) {
throw Error();
}
2022-07-20 21:40:44 +00:00
2022-07-21 16:33:23 +00:00
await sock.close();
// exit(0);
2022-07-20 21:40:44 +00:00
}