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

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

Issue 968243003: Dart: Adds optional named arguments for creating bindings. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Format Created 5 years, 9 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/interface_test.dart ('k') | mojo/public/dart/src/application.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:typed_data'; 8 import 'dart:typed_data';
9 import 'mojo:bindings'; 9 import 'mojo:bindings';
10 import 'mojo:builtin' as builtin; 10 import 'mojo:builtin' as builtin;
11 import 'mojo:core'; 11 import 'mojo:core';
12 12
13 import 'package:mojo/dart/testing/validation_test_input_parser.dart' as parser; 13 import 'package:mojo/dart/testing/validation_test_input_parser.dart' as parser;
14 import 'package:mojo/public/interfaces/bindings/tests/validation_test_interfaces .mojom.dart'; 14 import 'package:mojo/public/interfaces/bindings/tests/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(this._completer, 20 ConformanceTestInterfaceImpl(this._completer,
21 MojoMessagePipeEndpoint endpoint) { 21 MojoMessagePipeEndpoint endpoint) {
22 _stub = new ConformanceTestInterfaceStub.fromEndpoint(endpoint) 22 _stub = new ConformanceTestInterfaceStub.fromEndpoint(endpoint, impl: this);
23 ..delegate = this
24 ..listen();
25 } 23 }
26 24
27 void _complete() => _completer.complete(null); 25 void _complete() => _completer.complete(null);
28 26
29 method0(double param0) => _complete(); 27 method0(double param0) => _complete();
30 method1(StructA param0) => _complete(); 28 method1(StructA param0) => _complete();
31 method2(StructB param0, StructA param1) => _complete(); 29 method2(StructB param0, StructA param1) => _complete();
32 method3(List<bool> param0) => _complete(); 30 method3(List<bool> param0) => _complete();
33 method4(StructC param0, List<int> param1) => _complete(); 31 method4(StructC param0, List<int> param1) => _complete();
34 method5(StructE param0, MojoDataPipeProducer param1) => _complete(); 32 method5(StructE param0, MojoDataPipeProducer param1) => _complete();
35 method6(List<List<int>> param0) => _complete(); 33 method6(List<List<int>> param0) => _complete();
36 method7(StructF param0, List<List<int>> param1) => _complete(); 34 method7(StructF param0, List<List<int>> param1) => _complete();
37 method8(List<List<String>> param0) => _complete(); 35 method8(List<List<String>> param0) => _complete();
38 method9(List<List<MojoHandle>> param0) => _complete(); 36 method9(List<List<MojoHandle>> param0) => _complete();
39 method10(Map<String, int> param0) => _complete(); 37 method10(Map<String, int> param0) => _complete();
40 38
41 void close({bool nodefer : false}) => _stub.close(nodefer: nodefer); 39 void close({bool nodefer: false}) => _stub.close(nodefer: nodefer);
42 } 40 }
43 41
44 parser.ValidationParseResult readAndParseTest(String test) { 42 parser.ValidationParseResult readAndParseTest(String test) {
45 List<int> data = builtin.readSync("${test}.data"); 43 List<int> data = builtin.readSync("${test}.data");
46 String input = new Utf8Decoder().convert(data).trim(); 44 String input = new Utf8Decoder().convert(data).trim();
47 return parser.parse(input); 45 return parser.parse(input);
48 } 46 }
49 47
50 String expectedResult(String test) { 48 String expectedResult(String test) {
51 List<int> data = builtin.readSync("${test}.expected"); 49 List<int> data = builtin.readSync("${test}.expected");
52 return new Utf8Decoder().convert(data).trim(); 50 return new Utf8Decoder().convert(data).trim();
53 } 51 }
54 52
55 runTest(String name, parser.ValidationParseResult test, String expected) { 53 runTest(String name, parser.ValidationParseResult test, String expected) {
56 var handles = new List.generate(test.numHandles, 54 var handles = new List.generate(
55 test.numHandles,
57 (_) => new MojoSharedBuffer.create(10).handle); 56 (_) => new MojoSharedBuffer.create(10).handle);
58 var pipe = new MojoMessagePipe(); 57 var pipe = new MojoMessagePipe();
59 var completer = new Completer(); 58 var completer = new Completer();
60 var conformanceImpl; 59 var conformanceImpl;
61 60
62 runZoned(() { 61 runZoned(() {
63 conformanceImpl = new ConformanceTestInterfaceImpl( 62 conformanceImpl =
64 completer, pipe.endpoints[0]); 63 new ConformanceTestInterfaceImpl(completer, pipe.endpoints[0]);
65 }, 64 }, onError: (e, stackTrace) {
66 onError: (e, stackTrace) {
67 assert(e is MojoCodecError); 65 assert(e is MojoCodecError);
68 // TODO(zra): Make the error messages conform? 66 // TODO(zra): Make the error messages conform?
69 // assert(e == expected); 67 // assert(e == expected);
70 conformanceImpl.close(nodefer: true); 68 conformanceImpl.close(nodefer: true);
71 pipe.endpoints[0].handle.close(); 69 pipe.endpoints[0].handle.close();
72 handles.forEach((h) => h.close()); 70 handles.forEach((h) => h.close());
73 }); 71 });
74 72
75 var length = (test.data == null) ? 0 : test.data.lengthInBytes; 73 var length = (test.data == null) ? 0 : test.data.lengthInBytes;
76 var r = pipe.endpoints[1].write(test.data, length, handles); 74 var r = pipe.endpoints[1].write(test.data, length, handles);
77 assert(r.isOk); 75 assert(r.isOk);
78 76
79 completer.future.then((_) { 77 completer.future.then((_) {
80 assert(expected == "PASS"); 78 assert(expected == "PASS");
81 conformanceImpl.close(); 79 conformanceImpl.close();
82 pipe.endpoints[0].handle.close(); 80 pipe.endpoints[0].handle.close();
83 handles.forEach((h) => h.close()); 81 handles.forEach((h) => h.close());
84 }); 82 });
85 } 83 }
86 84
87 // TODO(zra, yzshen): Some struct versioning tests (with "mthd11" in their 85 // TODO(zra, yzshen): Some struct versioning tests (with "mthd11" in their
88 // names) are skipped. 86 // names) are skipped.
89 Iterable<String> getTestFiles(String path, String prefix) => 87 Iterable<String> getTestFiles(String path, String prefix) =>
90 builtin.enumerateFiles(path) 88 builtin.enumerateFiles(
91 .where((s) => s.startsWith(prefix) && s.endsWith(".data") && 89 path).where(
92 !s.contains("mthd11")) 90 (s) =>
93 .map((s) => s.replaceFirst('.data', '')); 91 s.startsWith(prefix) &&
92 s.endsWith(".data") &&
93 !s.contains("mthd11")).map((s) => s.replaceFirst('.data', '' ));
94 94
95 main(List args) { 95 main(List args) {
96 int handle = args[0]; 96 int handle = args[0];
97 String path = args[1]; 97 String path = args[1];
98 98
99 // First test the parser. 99 // First test the parser.
100 parser.parserTests(); 100 parser.parserTests();
101 101
102 // Then run the conformance tests. 102 // Then run the conformance tests.
103 getTestFiles(path, "$path/conformance_").forEach((test) { 103 getTestFiles(path, "$path/conformance_").forEach((test) {
104 runTest(test, readAndParseTest(test), expectedResult(test)); 104 runTest(test, readAndParseTest(test), expectedResult(test));
105 }); 105 });
106 // TODO(zra): Add integration tests when they no longer rely on Client=. 106 // TODO(zra): Add integration tests when they no longer rely on Client=.
107 } 107 }
OLDNEW
« no previous file with comments | « mojo/dart/test/interface_test.dart ('k') | mojo/public/dart/src/application.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698