Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: mojo/dart/test/validation_test.dart

Issue 1414483010: Dart: Use a RawReceivePort to receive events for Mojo handles. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:isolate'; 7 import 'dart:isolate';
8 import 'dart:mojo.builtin' as builtin; 8 import 'dart:mojo.builtin' as builtin;
9 import 'dart:typed_data'; 9 import 'dart:typed_data';
10 10
11 import 'package:_testing/validation_test_input_parser.dart' as parser; 11 import 'package:_testing/validation_test_input_parser.dart' as parser;
12 import 'package:mojo/bindings.dart'; 12 import 'package:mojo/bindings.dart';
13 import 'package:mojo/core.dart'; 13 import 'package:mojo/core.dart';
14 import 'package:mojom/mojo/test/validation_test_interfaces.mojom.dart'; 14 import 'package:mojom/mojo/test/validation_test_interfaces.mojom.dart';
15 15
16 class ConformanceTestInterfaceImpl implements ConformanceTestInterface { 16 class ConformanceTestInterfaceImpl implements ConformanceTestInterface {
17 ConformanceTestInterfaceStub _stub; 17 ConformanceTestInterfaceStub _stub;
18 Completer _completer; 18 Completer _completer;
19 19
20 ConformanceTestInterfaceImpl( 20 ConformanceTestInterfaceImpl(
21 this._completer, MojoMessagePipeEndpoint endpoint) { 21 this._completer, MojoMessagePipeEndpoint endpoint) {
22 _stub = new ConformanceTestInterfaceStub.fromEndpoint(endpoint, this); 22 _stub = new ConformanceTestInterfaceStub.fromEndpoint(endpoint, this);
23 } 23 }
24 24
25 set onError(Function f) {
26 _stub.onError = f;
27 }
28
25 void _complete() => _completer.complete(null); 29 void _complete() => _completer.complete(null);
26 30
27 method0(double param0) => _complete(); 31 method0(double param0) => _complete();
28 method1(StructA param0) => _complete(); 32 method1(StructA param0) => _complete();
29 method2(StructB param0, StructA param1) => _complete(); 33 method2(StructB param0, StructA param1) => _complete();
30 method3(List<bool> param0) => _complete(); 34 method3(List<bool> param0) => _complete();
31 method4(StructC param0, List<int> param1) => _complete(); 35 method4(StructC param0, List<int> param1) => _complete();
32 method5(StructE param0, MojoDataPipeProducer param1) { 36 method5(StructE param0, MojoDataPipeProducer param1) {
33 param1.handle.close(); 37 param1.handle.close();
34 param0.dataPipeConsumer.handle.close(); 38 param0.dataPipeConsumer.handle.close();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 71 }
68 72
69 Future runTest( 73 Future runTest(
70 String name, parser.ValidationParseResult test, String expected) { 74 String name, parser.ValidationParseResult test, String expected) {
71 var handles = new List.generate( 75 var handles = new List.generate(
72 test.numHandles, (_) => new MojoSharedBuffer.create(10).handle); 76 test.numHandles, (_) => new MojoSharedBuffer.create(10).handle);
73 var pipe = new MojoMessagePipe(); 77 var pipe = new MojoMessagePipe();
74 var completer = new Completer(); 78 var completer = new Completer();
75 var conformanceImpl; 79 var conformanceImpl;
76 80
77 runZoned(() { 81 conformanceImpl =
78 conformanceImpl = 82 new ConformanceTestInterfaceImpl(completer, pipe.endpoints[0]);
79 new ConformanceTestInterfaceImpl(completer, pipe.endpoints[0]); 83 conformanceImpl.onError = ((e) {
80 }, onError: (e, stackTrace) {
81 assert(e is MojoCodecError); 84 assert(e is MojoCodecError);
82 // TODO(zra): Make the error messages conform? 85 // TODO(zra): Make the error messages conform?
83 // assert(e == expected); 86 // assert(e == expected);
84 conformanceImpl.close(immediate: true); 87 conformanceImpl.close();
85 pipe.endpoints[0].close(); 88 pipe.endpoints[0].close();
86 pipe.endpoints[1].close(); 89 pipe.endpoints[1].close();
87 handles.forEach((h) => h.close()); 90 handles.forEach((h) => h.close());
88 completer.completeError(null); 91 completer.completeError(null);
89 }); 92 });
90 93
91 var length = (test.data == null) ? 0 : test.data.lengthInBytes; 94 var length = (test.data == null) ? 0 : test.data.lengthInBytes;
92 var r = pipe.endpoints[1].write(test.data, length, handles); 95 var r = pipe.endpoints[1].write(test.data, length, handles);
93 assert(r.isOk); 96 assert(r.isOk);
94 97
95 return completer.future.then((_) { 98 return completer.future.then((_) {
Cutch 2015/11/11 17:47:17 ... (_) async {
zra 2015/11/11 18:44:33 Acknowledged.
96 assert(expected == "PASS"); 99 assert(expected == "PASS");
97 conformanceImpl.close(); 100 conformanceImpl.close().then((_) {
Cutch 2015/11/11 17:47:17 await conformanceImpl.close(); ...
zra 2015/11/11 18:44:33 Changed to return instead of await since the resul
98 pipe.endpoints[0].close(); 101 pipe.endpoints[0].close();
99 pipe.endpoints[1].close(); 102 pipe.endpoints[1].close();
100 handles.forEach((h) => h.close()); 103 handles.forEach((h) => h.close());
104 });
101 }, onError: (e) { 105 }, onError: (e) {
102 // Do nothing. 106 // Do nothing.
103 }); 107 });
104 } 108 }
105 109
106 main(List args) async { 110 main(List args) async {
107 assert(args.length == 3); 111 assert(args.length == 3);
108 List<String> testData = args[2]; 112 List<String> testData = args[2];
109 113
110 // First test the parser. 114 // First test the parser.
111 parser.parserTests(); 115 parser.parserTests();
112 116
113 // See CollectTests in validation_unittest.cc for information on testData 117 // See CollectTests in validation_unittest.cc for information on testData
114 // format. 118 // format.
115 for (var i = 0; i < testData.length; i += 3) { 119 for (var i = 0; i < testData.length; i += 3) {
116 var name = testData[i + 0]; 120 var name = testData[i + 0];
117 var data = testData[i + 1].trim(); 121 var data = testData[i + 1].trim();
118 var expected = testData[i + 2].trim(); 122 var expected = testData[i + 2].trim();
119 try { 123 try {
120 await runTest(name, parser.parse(data), expected); 124 await runTest(name, parser.parse(data), expected);
121 print('$name PASSED.'); 125 print('$name PASSED.');
122 } catch (e) { 126 } catch (e) {
123 print('$name FAILED: $e'); 127 print('$name FAILED: $e');
124 } 128 }
125 } 129 }
126 // TODO(zra): Add integration tests when they no longer rely on Client= 130 // TODO(zra): Add integration tests when they no longer rely on Client=
127 MojoHandle.reportLeakedHandles(); 131 MojoHandle.reportLeakedHandles();
128 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698