OLD | NEW |
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(); |
35 param0.structD.messagePipes.forEach((h) => h.close()); | 39 param0.structD.messagePipes.forEach((h) => h.close()); |
36 _complete(); | 40 _complete(); |
37 } | 41 } |
| 42 |
38 method6(List<List<int>> param0) => _complete(); | 43 method6(List<List<int>> param0) => _complete(); |
39 method7(StructF param0, List<List<int>> param1) => _complete(); | 44 method7(StructF param0, List<List<int>> param1) => _complete(); |
40 method8(List<List<String>> param0) => _complete(); | 45 method8(List<List<String>> param0) => _complete(); |
41 method9(List<List<MojoHandle>> param0) { | 46 method9(List<List<MojoHandle>> param0) { |
42 if (param0 != null) { | 47 if (param0 != null) { |
43 param0.forEach((l) => l.forEach((h) { | 48 param0.forEach((l) => l.forEach((h) { |
44 if (h != null) h.close(); | 49 if (h != null) h.close(); |
45 })); | 50 })); |
46 } | 51 } |
47 _complete(); | 52 _complete(); |
48 } | 53 } |
| 54 |
49 method10(Map<String, int> param0) => _complete(); | 55 method10(Map<String, int> param0) => _complete(); |
50 method11(StructG param0) => _complete(); | 56 method11(StructG param0) => _complete(); |
51 method12(double param0, [Function responseFactory]) { | 57 method12(double param0, [Function responseFactory]) { |
52 // If there are ever any passing method12 tests added, then this may need | 58 // If there are ever any passing method12 tests added, then this may need |
53 // to change. | 59 // to change. |
54 assert(responseFactory != null); | 60 assert(responseFactory != null); |
55 _complete(); | 61 _complete(); |
56 return new Future.value(responseFactory(0.0)); | 62 return new Future.value(responseFactory(0.0)); |
57 } | 63 } |
| 64 |
58 method13(InterfaceAProxy param0, int param1, InterfaceAProxy param2) { | 65 method13(InterfaceAProxy param0, int param1, InterfaceAProxy param2) { |
59 if (param0 != null) param0.close(immediate: true); | 66 if (param0 != null) param0.close(immediate: true); |
60 if (param2 != null) param2.close(immediate: true); | 67 if (param2 != null) param2.close(immediate: true); |
61 _complete(); | 68 _complete(); |
62 } | 69 } |
| 70 |
63 method14(UnionA param0) => _complete(); | 71 method14(UnionA param0) => _complete(); |
64 method15(StructH param0) => _complete(); | 72 method15(StructH param0) => _complete(); |
65 | 73 |
66 Future close({bool immediate: false}) => _stub.close(immediate: immediate); | 74 Future close({bool immediate: false}) => _stub.close(immediate: immediate); |
67 } | 75 } |
68 | 76 |
69 Future runTest( | 77 Future runTest( |
70 String name, parser.ValidationParseResult test, String expected) { | 78 String name, parser.ValidationParseResult test, String expected) { |
71 var handles = new List.generate( | 79 var handles = new List.generate( |
72 test.numHandles, (_) => new MojoSharedBuffer.create(10).handle); | 80 test.numHandles, (_) => new MojoSharedBuffer.create(10).handle); |
73 var pipe = new MojoMessagePipe(); | 81 var pipe = new MojoMessagePipe(); |
74 var completer = new Completer(); | 82 var completer = new Completer(); |
75 var conformanceImpl; | 83 var conformanceImpl; |
76 | 84 |
77 runZoned(() { | 85 conformanceImpl = |
78 conformanceImpl = | 86 new ConformanceTestInterfaceImpl(completer, pipe.endpoints[0]); |
79 new ConformanceTestInterfaceImpl(completer, pipe.endpoints[0]); | 87 conformanceImpl.onError = ((e) { |
80 }, onError: (e, stackTrace) { | |
81 assert(e is MojoCodecError); | 88 assert(e is MojoCodecError); |
82 // TODO(zra): Make the error messages conform? | 89 // TODO(zra): Make the error messages conform? |
83 // assert(e == expected); | 90 // assert(e == expected); |
84 conformanceImpl.close(immediate: true); | 91 conformanceImpl.close(); |
85 pipe.endpoints[0].close(); | 92 pipe.endpoints[0].close(); |
86 pipe.endpoints[1].close(); | 93 pipe.endpoints[1].close(); |
87 handles.forEach((h) => h.close()); | 94 handles.forEach((h) => h.close()); |
88 completer.completeError(null); | 95 completer.completeError(null); |
89 }); | 96 }); |
90 | 97 |
91 var length = (test.data == null) ? 0 : test.data.lengthInBytes; | 98 var length = (test.data == null) ? 0 : test.data.lengthInBytes; |
92 var r = pipe.endpoints[1].write(test.data, length, handles); | 99 var r = pipe.endpoints[1].write(test.data, length, handles); |
93 assert(r.isOk); | 100 assert(r.isOk); |
94 | 101 |
95 return completer.future.then((_) { | 102 return completer.future.then((_) { |
96 assert(expected == "PASS"); | 103 assert(expected == "PASS"); |
97 conformanceImpl.close(); | 104 return conformanceImpl.close().then((_) { |
98 pipe.endpoints[0].close(); | 105 pipe.endpoints[0].close(); |
99 pipe.endpoints[1].close(); | 106 pipe.endpoints[1].close(); |
100 handles.forEach((h) => h.close()); | 107 handles.forEach((h) => h.close()); |
| 108 }); |
101 }, onError: (e) { | 109 }, onError: (e) { |
102 // Do nothing. | 110 // Do nothing. |
103 }); | 111 }); |
104 } | 112 } |
105 | 113 |
106 main(List args) async { | 114 main(List args) async { |
107 assert(args.length == 3); | 115 assert(args.length == 3); |
108 List<String> testData = args[2]; | 116 List<String> testData = args[2]; |
109 | 117 |
110 // First test the parser. | 118 // First test the parser. |
111 parser.parserTests(); | 119 parser.parserTests(); |
112 | 120 |
113 // See CollectTests in validation_unittest.cc for information on testData | 121 // See CollectTests in validation_unittest.cc for information on testData |
114 // format. | 122 // format. |
115 for (var i = 0; i < testData.length; i += 3) { | 123 for (var i = 0; i < testData.length; i += 3) { |
116 var name = testData[i + 0]; | 124 var name = testData[i + 0]; |
117 var data = testData[i + 1].trim(); | 125 var data = testData[i + 1].trim(); |
118 var expected = testData[i + 2].trim(); | 126 var expected = testData[i + 2].trim(); |
119 try { | 127 try { |
120 await runTest(name, parser.parse(data), expected); | 128 await runTest(name, parser.parse(data), expected); |
121 print('$name PASSED.'); | 129 print('$name PASSED.'); |
122 } catch (e) { | 130 } catch (e) { |
123 print('$name FAILED: $e'); | 131 print('$name FAILED: $e'); |
124 } | 132 } |
125 } | 133 } |
126 // TODO(zra): Add integration tests when they no longer rely on Client= | 134 // TODO(zra): Add integration tests when they no longer rely on Client= |
127 MojoHandle.reportLeakedHandles(); | 135 MojoHandle.reportLeakedHandles(); |
128 } | 136 } |
OLD | NEW |