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

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

Issue 1545483003: Dart: Reorganize files (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix build file Created 4 years, 12 months 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
« no previous file with comments | « mojo/dart/test/uri_base_test.dart ('k') | mojo/dart/tools/presubmit/check_mojom_dart.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:convert';
7 import 'dart:isolate';
8 import 'dart:mojo.builtin' as builtin;
9 import 'dart:typed_data';
10
11 import 'package:_mojo_for_test_only/validation_test_input_parser.dart' as parser ;
12 import 'package:mojo/bindings.dart';
13 import 'package:mojo/core.dart';
14 import 'package:_mojo_for_test_only/mojo/test/validation_test_interfaces.mojom.d art';
15
16 class ConformanceTestInterfaceImpl implements ConformanceTestInterface {
17 ConformanceTestInterfaceStub _stub;
18 Completer _completer;
19
20 ConformanceTestInterfaceImpl(
21 this._completer, MojoMessagePipeEndpoint endpoint) {
22 _stub = new ConformanceTestInterfaceStub.fromEndpoint(endpoint, this);
23 }
24
25 set onError(Function f) {
26 _stub.onError = f;
27 }
28
29 void _complete() => _completer.complete(null);
30
31 method0(double param0) => _complete();
32 method1(StructA param0) => _complete();
33 method2(StructB param0, StructA param1) => _complete();
34 method3(List<bool> param0) => _complete();
35 method4(StructC param0, List<int> param1) => _complete();
36 method5(StructE param0, MojoDataPipeProducer param1) {
37 param1.handle.close();
38 param0.dataPipeConsumer.handle.close();
39 param0.structD.messagePipes.forEach((h) => h.close());
40 _complete();
41 }
42
43 method6(List<List<int>> param0) => _complete();
44 method7(StructF param0, List<List<int>> param1) => _complete();
45 method8(List<List<String>> param0) => _complete();
46 method9(List<List<MojoHandle>> param0) {
47 if (param0 != null) {
48 param0.forEach((l) => l.forEach((h) {
49 if (h != null) h.close();
50 }));
51 }
52 _complete();
53 }
54
55 method10(Map<String, int> param0) => _complete();
56 method11(StructG param0) => _complete();
57 method12(double param0, [Function responseFactory]) {
58 // If there are ever any passing method12 tests added, then this may need
59 // to change.
60 assert(responseFactory != null);
61 _complete();
62 return new Future.value(responseFactory(0.0));
63 }
64
65 method13(InterfaceAProxy param0, int param1, InterfaceAProxy param2) {
66 if (param0 != null) param0.close(immediate: true);
67 if (param2 != null) param2.close(immediate: true);
68 _complete();
69 }
70
71 method14(UnionA param0) => _complete();
72 method15(StructH param0) => _complete();
73
74 Future close({bool immediate: false}) => _stub.close(immediate: immediate);
75 }
76
77 Future runTest(
78 String name, parser.ValidationParseResult test, String expected) {
79 var handles = new List.generate(
80 test.numHandles, (_) => new MojoSharedBuffer.create(10).handle);
81 var pipe = new MojoMessagePipe();
82 var completer = new Completer();
83 var conformanceImpl;
84
85 conformanceImpl =
86 new ConformanceTestInterfaceImpl(completer, pipe.endpoints[0]);
87 conformanceImpl.onError = ((e) {
88 assert(e is MojoCodecError);
89 // TODO(zra): Make the error messages conform?
90 // assert(e == expected);
91 conformanceImpl.close();
92 pipe.endpoints[0].close();
93 pipe.endpoints[1].close();
94 handles.forEach((h) => h.close());
95 completer.completeError(null);
96 });
97
98 var length = (test.data == null) ? 0 : test.data.lengthInBytes;
99 int r = pipe.endpoints[1].write(test.data, length, handles);
100 assert(r == MojoResult.kOk);
101
102 return completer.future.then((_) {
103 assert(expected == "PASS");
104 return conformanceImpl.close().then((_) {
105 pipe.endpoints[0].close();
106 pipe.endpoints[1].close();
107 handles.forEach((h) => h.close());
108 });
109 }, onError: (e) {
110 // Do nothing.
111 });
112 }
113
114 main(List args) async {
115 assert(args.length == 3);
116 List<String> testData = args[2];
117
118 // First test the parser.
119 parser.parserTests();
120
121 // See CollectTests in validation_unittest.cc for information on testData
122 // format.
123 for (var i = 0; i < testData.length; i += 3) {
124 var name = testData[i + 0];
125 var data = testData[i + 1].trim();
126 var expected = testData[i + 2].trim();
127 try {
128 await runTest(name, parser.parse(data), expected);
129 print('$name PASSED.');
130 } catch (e) {
131 print('$name FAILED: $e');
132 }
133 }
134 // TODO(zra): Add integration tests when they no longer rely on Client=
135 MojoHandle.reportLeakedHandles();
136 }
OLDNEW
« no previous file with comments | « mojo/dart/test/uri_base_test.dart ('k') | mojo/dart/tools/presubmit/check_mojom_dart.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698