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

Side by Side Diff: test/mock_util.dart

Issue 1852983002: Fix issues with protobuf equality comparisons (Closed) Base URL: git@github.com:dart-lang/dart-protobuf.git@master
Patch Set: tweak _deepEquals, improve tests Created 4 years, 8 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 | « test/message_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:protobuf/protobuf.dart' 7 import 'package:protobuf/protobuf.dart'
8 show GeneratedMessage, BuilderInfo, PbFieldType; 8 show GeneratedMessage, BuilderInfo, CreateBuilderFunc, PbFieldType;
9
10 BuilderInfo mockInfo(String className, CreateBuilderFunc create) {
11 return new BuilderInfo(className)
12 ..a(1, "val", PbFieldType.O3, 42)
13 ..a(2, "str", PbFieldType.OS)
14 ..a(3, "child", PbFieldType.OM, create, create)
15 ..p(4, "int32s", PbFieldType.P3);
16 }
9 17
10 /// A minimal protobuf implementation for testing. 18 /// A minimal protobuf implementation for testing.
11 abstract class MockMessage extends GeneratedMessage { 19 abstract class MockMessage extends GeneratedMessage {
12 BuilderInfo _infoCache;
13
14 // subclasses must provide these 20 // subclasses must provide these
15 String get className; 21 BuilderInfo get info_;
16 MockMessage create();
17 22
18 int get val => $_get(0, 1, 42); 23 int get val => $_get(0, 1, 42);
19 set val(x) => setField(1, x); 24 set val(x) => setField(1, x);
20 25
21 String get str => $_get(1, 2, ""); 26 String get str => $_get(1, 2, "");
22 set str(x) => $_setString(1, 2, x); 27 set str(x) => $_setString(1, 2, x);
23 28
24 MockMessage get child => $_get(2, 3, null); 29 MockMessage get child => $_get(2, 3, null);
25 set child(x) => setField(3, x); 30 set child(x) => setField(3, x);
26 31
27 List<int> get int32s => $_get(3, 4, null); 32 List<int> get int32s => $_get(3, 4, null);
28 33
29 @override 34 clone() {
30 BuilderInfo get info_ { 35 CreateBuilderFunc create = info_.byName["child"].subBuilder;
31 if (_infoCache != null) return _infoCache; 36 return create()..mergeFromMessage(this);
32 _infoCache = new BuilderInfo(className)
33 ..a(1, "val", PbFieldType.O3, 42)
34 ..a(2, "str", PbFieldType.OS)
35 ..a(3, "child", PbFieldType.OM, create, create)
36 ..p(4, "int32s", PbFieldType.P3);
37 return _infoCache;
38 } 37 }
39
40 clone() => create()..mergeFromMessage(this);
41 } 38 }
OLDNEW
« no previous file with comments | « test/message_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698