blob: ee9fb5886753572e184b81503bb05bda4862eb62 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:isolate';
import 'dart:mojo_bindings';
import 'dart:mojo_builtin' as builtin;
import 'dart:mojo_core';
import 'dart:typed_data';
import 'package:mojo/dart/testing/validation_test_input_parser.dart' as parser;
import 'package:mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom.dart';
class ConfrmanceTestInterfaceImpl extends ConformanceTestInterface {
Completer _completer;
ConfrmanceTestInterfaceImpl(this._completer, MojoMessagePipeEndpoint endpoint)
: super(endpoint) {
super.delegate = this;
}
void _complete() => _completer.complete(null);
method0(double param0) => _complete();
method1(StructA param0) => _complete();
method2(StructB param0, StructA param1) => _complete();
method3(List<bool> param0) => _complete();
method4(StructC param0, List<int> param1) => _complete();
method5(StructE param0, MojoDataPipeProducer param1) => _complete();
method6(List<List<int>> param0) => _complete();
method7(StructF param0, List<List<int>> param1) => _complete();
method8(List<List<String>> param0) => _complete();
method9(List<List<MojoHandle>> param0) => _complete();
method10(Map<String, int> param0) => _complete();
}
parser.ValidationParseResult readAndParseTest(String test) {
List<int> data = builtin.readSync("${test}.data");
String input = new Utf8Decoder().convert(data).trim();
return parser.parse(input);
}
String expectedResult(String test) {
List<int> data = builtin.readSync("${test}.expected");
return new Utf8Decoder().convert(data).trim();
}
runTest(String name, parser.ValidationParseResult test, String expected) {
var handles = new List.generate(test.numHandles,
(_) => new MojoSharedBuffer.create(10).handle);
var pipe = new MojoMessagePipe();
var completer = new Completer();
var conformanceImpl = new ConfrmanceTestInterfaceImpl(
completer, pipe.endpoints[0]);
runZoned(() {
conformanceImpl.listen();
},
onError: (e, stackTrace) {
assert(e is MojoCodecError);
// TODO(zra): Make the error messages conform?
// assert(e == expected);
conformanceImpl.close(nodefer: true);
pipe.endpoints[0].handle.close();
handles.forEach((h) => h.close());
});
var length = (test.data == null) ? 0 : test.data.lengthInBytes;
var r = pipe.endpoints[1].write(test.data, length, handles);
assert(r.isOk);
completer.future.then((_) {
assert(expected == "PASS");
conformanceImpl.close();
pipe.endpoints[0].handle.close();
handles.forEach((h) => h.close());
});
}
Iterable<String> getTestFiles(String path, String prefix) =>
builtin.enumerateFiles(path)
.where((s) => s.startsWith(prefix) && s.endsWith(".data"))
.map((s) => s.replaceFirst('.data', ''));
main(List args) {
int handle = args[0];
String path = args[1];
// First test the parser.
parser.parserTests();
// Then run the conformance tests.
getTestFiles(path, "$path/conformance_").forEach((test) {
runTest(test, readAndParseTest(test), expectedResult(test));
});
// TODO(zra): Add integration tests when they no longer rely on Client=.
}