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

Side by Side Diff: tests/service_tests/conformance/conformance_service_impl.dart

Issue 2035023003: Remove service-compiler related code. (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file.
4
5 import 'dart/conformance_service.dart';
6
7 class ConformanceServiceImpl implements ConformanceService {
8 int getAge(Person person) {
9 return person.age;
10 }
11
12 int getBoxedAge(PersonBox box) {
13 if (box.person.name != "fisk") {
14 throw new Exception("Incorrect person name");
15 }
16 if (box.person.nameData.length != 4 ||
17 box.person.nameData[0] != "f".codeUnitAt(0) ||
18 box.person.nameData[3] != "k".codeUnitAt(0)) {
19 throw new Exception("Incorrect person name data");
20 }
21 return box.person.age;
22 }
23
24 int _sumAges(Person person) {
25 int sum = getAge(person);
26 List<Person> children = person.children;
27 for (int i = 0; i < children.length; i++) {
28 sum += _sumAges(children[i]);
29 }
30 return sum;
31 }
32
33 void getAgeStats(Person person, AgeStatsBuilder result) {
34 int sum = _sumAges(person);
35 int count = this.count(person);
36 result.averageAge = (sum / count).round();
37 result.sum = sum;
38 }
39
40 void createAgeStats(int avg, int sum, AgeStatsBuilder result) {
41 result.averageAge = avg;
42 result.sum = sum;
43 }
44
45 void createPerson(int numChildren, PersonBuilder result) {
46 result.age = 42;
47 List<PersonBuilder> children = result.initChildren(numChildren);
48 for (int i = 0; i < children.length; ++i) {
49 children[i].age = 12 + (i * 2);
50 }
51 result.name = "person";
52 }
53
54 void createNode(int depth, NodeBuilder result) {
55 if (depth > 1) {
56 ConsBuilder cons = result.initCons();
57 createNode(depth - 1, cons.initFst());
58 createNode(depth - 1, cons.initSnd());
59 } else {
60 result.cond = true;
61 result.num = 42;
62 }
63 }
64
65 int count(Person person) {
66 int sum = 1;
67 List<Person> children = person.children;
68 for (int i = 0; i < children.length; i++) sum += count(children[i]);
69 return sum;
70 }
71
72 int depth(Node node) {
73 if (node.isNum) {
74 if (node.isCond) throw new StateError("Cannot be both num and cond.");
75 return 1;
76 }
77 int left = depth(node.cons.fst);
78 int right = depth(node.cons.snd);
79 return (left > right) ? left + 1 : right + 1;
80 }
81
82 void foo() {
83 }
84
85 int bar(Empty empty) {
86 return 24;
87 }
88
89 int ping() => 42;
90
91 void flipTable(TableFlip flip, TableFlipBuilder result) {
92 var flipTableCodes =
93 [ 40, 9583, 176, 9633, 176, 65289, 9583, 65077, 32, 9531, 9473, 9531 ];
94 String expectedFlip = new String.fromCharCodes(flipTableCodes);
95 if (flip.flip != expectedFlip) throw new Exception("Unexpected table flip");
96 result.flip = expectedFlip;
97 }
98
99 void internalize(InternalFields internalFields,
100 InternalFieldsBuilder result) {
101 int expectedOffset = 1337;
102 var segmentCodes = [ 104, 52, 120, 48, 114 ];
103 String expectedSegment = new String.fromCharCodes(segmentCodes);
104 if (internalFields.offset != expectedOffset) {
105 throw new Exception("Unexpected offset");
106 }
107 if (internalFields.segment != expectedSegment) {
108 throw new Exception("Unexpected segment");
109 }
110 result.offset = expectedOffset;
111 result.segment = expectedSegment;
112 }
113 }
114
115 main() {
116 var impl = new ConformanceServiceImpl();
117 ConformanceService.initialize(impl);
118 while (ConformanceService.hasNextEvent()) {
119 ConformanceService.handleNextEvent();
120 }
121 }
OLDNEW
« no previous file with comments | « tests/service_tests/conformance/conformance_service.idl ('k') | tests/service_tests/conformance/conformance_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698