OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Tests event delivery using PbEventMixin. | 5 /// Tests event delivery using PbEventMixin. |
6 library event_test; | 6 library event_test; |
7 | 7 |
8 import 'dart:typed_data' show Uint8List; | 8 import 'dart:typed_data' show Uint8List; |
9 | 9 |
10 import 'package:protobuf/protobuf.dart' | 10 import 'package:protobuf/protobuf.dart' |
11 show GeneratedMessage, Extension, ExtensionRegistry, PbFieldType; | 11 show GeneratedMessage, Extension, ExtensionRegistry, PbFieldType; |
12 import 'package:protobuf/src/protobuf/mixins/event_mixin.dart' | 12 import 'package:protobuf/src/protobuf/mixins/event_mixin.dart' |
13 show PbEventMixin, PbFieldChange; | 13 show PbEventMixin, PbFieldChange; |
14 import 'package:test/test.dart' show test, expect; | 14 import 'package:test/test.dart' show test, expect; |
15 | 15 |
16 import 'mock_util.dart' show MockMessage, mockInfo; | 16 import 'mock_util.dart' show MockMessage, mockInfo; |
17 | 17 |
18 class Rec extends MockMessage with PbEventMixin { | 18 class Rec extends MockMessage with PbEventMixin { |
19 get info_ => _info; | 19 get info_ => _info; |
20 static final _info = mockInfo("Rec", () => new Rec()); | 20 static final _info = mockInfo("Rec", () => new Rec()); |
21 } | 21 } |
22 | 22 |
23 Extension comment = new Extension("Rec", "comment", 5, PbFieldType.OS); | 23 Extension comment = new Extension("Rec", "comment", 6, PbFieldType.OS); |
24 | 24 |
25 main() { | 25 main() { |
26 test('Events are sent when setting and clearing a non-repeated field', () { | 26 test('Events are sent when setting and clearing a non-repeated field', () { |
27 var log = makeLog(); | 27 var log = makeLog(); |
28 var r = new Rec(); | 28 var r = new Rec(); |
29 r.changes.listen((List<PbFieldChange> changes) { | 29 r.changes.listen((List<PbFieldChange> changes) { |
30 log.add(changes); | 30 log.add(changes); |
31 }); | 31 }); |
32 | 32 |
33 r.val = 123; | 33 r.val = 123; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 clear(String expected) { | 217 clear(String expected) { |
218 r.clear(); | 218 r.clear(); |
219 r.deliverChanges(); | 219 r.deliverChanges(); |
220 checkLogOnce(log, [tag, expected, ""]); | 220 checkLogOnce(log, [tag, expected, ""]); |
221 } | 221 } |
222 | 222 |
223 setComment("hello"); | 223 setComment("hello"); |
224 clear("hello"); | 224 clear("hello"); |
225 | 225 |
226 setComment("hello"); | 226 setComment("hello"); |
227 r.setField(5, "hi"); | 227 r.setField(6, "hi"); |
228 r.deliverChanges(); | 228 r.deliverChanges(); |
229 checkLogOnce(log, [tag, "hello", "hi"]); | 229 checkLogOnce(log, [tag, "hello", "hi"]); |
230 clear("hi"); | 230 clear("hi"); |
231 | 231 |
232 setComment("hello"); | 232 setComment("hello"); |
233 r.clearExtension(comment); | 233 r.clearExtension(comment); |
234 r.deliverChanges(); | 234 r.deliverChanges(); |
235 checkLogOnce(log, [tag, "hello", ""]); | 235 checkLogOnce(log, [tag, "hello", ""]); |
236 | 236 |
237 setComment("hello"); | 237 setComment("hello"); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 List toTuple(PbFieldChange fc) { | 292 List toTuple(PbFieldChange fc) { |
293 fixValue(v) { | 293 fixValue(v) { |
294 if (v is GeneratedMessage) { | 294 if (v is GeneratedMessage) { |
295 return "<msg>"; | 295 return "<msg>"; |
296 } | 296 } |
297 return v; | 297 return v; |
298 } | 298 } |
299 return [fc.tag, fixValue(fc.oldValue), fixValue(fc.newValue)]; | 299 return [fc.tag, fixValue(fc.oldValue), fixValue(fc.newValue)]; |
300 } | 300 } |
OLD | NEW |