OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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:mojo_bindings' as bindings; | 5 import 'dart:mojo_bindings' as bindings; |
6 import 'dart:mojo_core' as core; | 6 import 'dart:mojo_core' as core; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import 'package:mojo/dart/testing/expect.dart'; | 9 import 'package:mojo/dart/testing/expect.dart'; |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 | 97 |
98 class TestFoo { | 98 class TestFoo { |
99 static const String kFooby = "Fooby"; | 99 static const String kFooby = "Fooby"; |
100 | 100 |
101 int x = 0; | 101 int x = 0; |
102 int y = 0; | 102 int y = 0; |
103 bool a = true; | 103 bool a = true; |
104 bool b = false; | 104 bool b = false; |
105 bool c = false; | 105 bool c = false; |
106 core.RawMojoHandle source = null; | 106 core.MojoHandle source = null; |
107 TestBar bar = null; | 107 TestBar bar = null; |
108 List<int> data = null; | 108 List<int> data = null; |
109 List<TestBar> extra_bars = null; | 109 List<TestBar> extra_bars = null; |
110 String name = kFooby; | 110 String name = kFooby; |
111 List<core.RawMojoHandle> input_streams = null; | 111 List<core.MojoHandle> input_streams = null; |
112 List<core.RawMojoHandle> output_streams = null; | 112 List<core.MojoHandle> output_streams = null; |
113 List<List<bool>> array_of_array_of_bools = null; | 113 List<List<bool>> array_of_array_of_bools = null; |
114 List<List<List<String>>> multi_array_of_strings = null; | 114 List<List<List<String>>> multi_array_of_strings = null; |
115 List<bool> array_of_bools = null; | 115 List<bool> array_of_bools = null; |
116 | 116 |
117 TestFoo(); | 117 TestFoo(); |
118 | 118 |
119 static const int encodedSize = bindings.kStructHeaderSize + 88; | 119 static const int encodedSize = bindings.kStructHeaderSize + 88; |
120 | 120 |
121 static TestFoo decode(bindings.MojoDecoder decoder) { | 121 static TestFoo decode(bindings.MojoDecoder decoder) { |
122 int packed; | 122 int packed; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 foo.extra_bars = [ | 195 foo.extra_bars = [ |
196 new TestBar(), new TestBar(), new TestBar(), | 196 new TestBar(), new TestBar(), new TestBar(), |
197 ]; | 197 ]; |
198 for (int i = 0; i < foo.extra_bars.length; ++i) { | 198 for (int i = 0; i < foo.extra_bars.length; ++i) { |
199 foo.extra_bars[i].alpha = 1 * i; | 199 foo.extra_bars[i].alpha = 1 * i; |
200 foo.extra_bars[i].beta = 2 * i; | 200 foo.extra_bars[i].beta = 2 * i; |
201 foo.extra_bars[i].gamma = 3 * i; | 201 foo.extra_bars[i].gamma = 3 * i; |
202 } | 202 } |
203 foo.name = "I am a banana"; | 203 foo.name = "I am a banana"; |
204 // This is supposed to be a handle, but we fake it with an integer. | 204 // This is supposed to be a handle, but we fake it with an integer. |
205 foo.source = new core.RawMojoHandle(23423782); | 205 foo.source = new core.MojoHandle(23423782); |
206 foo.array_of_array_of_bools = [ | 206 foo.array_of_array_of_bools = [ |
207 [true], [false, true] | 207 [true], [false, true] |
208 ]; | 208 ]; |
209 foo.array_of_bools = [ | 209 foo.array_of_bools = [ |
210 true, false, true, false, true, false, true, true | 210 true, false, true, false, true, false, true, true |
211 ]; | 211 ]; |
212 | 212 |
213 | 213 |
214 var name = 31; | 214 var name = 31; |
215 var payloadSize = 304; | 215 var payloadSize = 304; |
216 | 216 |
217 var builder = new bindings.MessageBuilder(name, payloadSize); | 217 var builder = new bindings.MessageBuilder(name, payloadSize); |
218 builder.encodeStruct(TestFoo, foo); | 218 builder.encodeStruct(TestFoo, foo); |
219 | 219 |
220 var message = builder.finish(); | 220 var message = builder.finish(); |
221 | 221 |
222 var expectedMemory = new Uint8List.fromList([ | 222 var expectedMemory = new Uint8List.fromList([ |
223 /* 0: */ 16, 0, 0, 0, 2, 0, 0, 0, | 223 /* 0: */ 16, 0, 0, 0, 2, 0, 0, 0, |
224 /* 8: */ 31, 0, 0, 0, 0, 0, 0, 0, | 224 /* 8: */ 31, 0, 0, 0, 0, 0, 0, 0, |
225 /* 16: */ 96, 0, 0, 0, 15, 0, 0, 0, | 225 /* 16: */ 96, 0, 0, 0, 15, 0, 0, 0, |
226 /* 24: */ 0xD5, 0xB4, 0x12, 0x02, 0x93, 0x6E, 0x01, 0, | 226 /* 24: */ 0xD5, 0xB4, 0x12, 0x02, 0x93, 0x6E, 0x01, 0, |
227 /* 32: */ 5, 0, 0, 0, 0, 0, 0, 0, | 227 /* 32: */ 5, 0, 0, 0, 0, 0, 0, 0, |
228 /* 40: */ 72, 0, 0, 0, 0, 0, 0, 0, | 228 /* 40: */ 72, 0, 0, 0, 0, 0, 0, 0, |
229 ]); | 229 ]); |
230 // TODO(abarth): Test more of the message's raw memory. | 230 // TODO(abarth): Test more of the message's raw memory. |
231 var allActualMemory = message.buffer.buffer.asUint8List(); | 231 var allActualMemory = message.buffer.buffer.asUint8List(); |
232 var actualMemory = allActualMemory.sublist(0, expectedMemory.length); | 232 var actualMemory = allActualMemory.sublist(0, expectedMemory.length); |
233 Expect.listEquals(expectedMemory, actualMemory); | 233 Expect.listEquals(expectedMemory, actualMemory); |
234 | 234 |
235 var expectedHandles = <core.RawMojoHandle>[ | 235 var expectedHandles = <core.MojoHandle>[ |
236 new core.RawMojoHandle(23423782), | 236 new core.MojoHandle(23423782), |
237 ]; | 237 ]; |
238 | 238 |
239 Expect.listEquals(expectedHandles, message.handles); | 239 Expect.listEquals(expectedHandles, message.handles); |
240 | 240 |
241 var reader = new bindings.MessageReader(message); | 241 var reader = new bindings.MessageReader(message); |
242 | 242 |
243 Expect.equals(payloadSize, reader.payloadSize); | 243 Expect.equals(payloadSize, reader.payloadSize); |
244 Expect.equals(name, reader.name); | 244 Expect.equals(name, reader.name); |
245 | 245 |
246 var foo2 = reader.decodeStruct(TestFoo); | 246 var foo2 = reader.decodeStruct(TestFoo); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 | 458 |
459 | 459 |
460 main() { | 460 main() { |
461 testAlign(); | 461 testAlign(); |
462 testTypes(); | 462 testTypes(); |
463 testBar(); | 463 testBar(); |
464 testFoo(); | 464 testFoo(); |
465 testNamedRegion(); | 465 testNamedRegion(); |
466 testUtf8(); | 466 testUtf8(); |
467 } | 467 } |
OLD | NEW |