| 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 library mock_util; | 5 library mock_util; |
| 6 | 6 |
| 7 import 'package:fixnum/fixnum.dart' show Int64; |
| 7 import 'package:protobuf/protobuf.dart' | 8 import 'package:protobuf/protobuf.dart' |
| 8 show GeneratedMessage, BuilderInfo, CreateBuilderFunc, PbFieldType; | 9 show GeneratedMessage, BuilderInfo, CreateBuilderFunc, PbFieldType; |
| 9 | 10 |
| 10 BuilderInfo mockInfo(String className, CreateBuilderFunc create) { | 11 BuilderInfo mockInfo(String className, CreateBuilderFunc create) { |
| 11 return new BuilderInfo(className) | 12 return new BuilderInfo(className) |
| 12 ..a(1, "val", PbFieldType.O3, 42) | 13 ..a(1, "val", PbFieldType.O3, 42) |
| 13 ..a(2, "str", PbFieldType.OS) | 14 ..a(2, "str", PbFieldType.OS) |
| 14 ..a(3, "child", PbFieldType.OM, create, create) | 15 ..a(3, "child", PbFieldType.OM, create, create) |
| 15 ..p(4, "int32s", PbFieldType.P3); | 16 ..p(4, "int32s", PbFieldType.P3) |
| 17 ..a(5, "int64", PbFieldType.O6); |
| 16 } | 18 } |
| 17 | 19 |
| 18 /// A minimal protobuf implementation for testing. | 20 /// A minimal protobuf implementation for testing. |
| 19 abstract class MockMessage extends GeneratedMessage { | 21 abstract class MockMessage extends GeneratedMessage { |
| 20 // subclasses must provide these | 22 // subclasses must provide these |
| 21 BuilderInfo get info_; | 23 BuilderInfo get info_; |
| 22 | 24 |
| 23 int get val => $_get(0, 1, 42); | 25 int get val => $_get(0, 1, 42); |
| 24 set val(x) => setField(1, x); | 26 set val(x) => setField(1, x); |
| 25 | 27 |
| 26 String get str => $_get(1, 2, ""); | 28 String get str => $_get(1, 2, ""); |
| 27 set str(x) => $_setString(1, 2, x); | 29 set str(x) => $_setString(1, 2, x); |
| 28 | 30 |
| 29 MockMessage get child => $_get(2, 3, null); | 31 MockMessage get child => $_get(2, 3, null); |
| 30 set child(x) => setField(3, x); | 32 set child(x) => setField(3, x); |
| 31 | 33 |
| 32 List<int> get int32s => $_get(3, 4, null); | 34 List<int> get int32s => $_get(3, 4, null); |
| 33 | 35 |
| 36 Int64 get int64 => $_get(4, 5, 0); |
| 37 set int64(x) => setField(5, x); |
| 38 |
| 34 clone() { | 39 clone() { |
| 35 CreateBuilderFunc create = info_.byName["child"].subBuilder; | 40 CreateBuilderFunc create = info_.byName["child"].subBuilder; |
| 36 return create()..mergeFromMessage(this); | 41 return create()..mergeFromMessage(this); |
| 37 } | 42 } |
| 38 } | 43 } |
| OLD | NEW |