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

Side by Side Diff: test/hash_code_test.dart

Issue 63173006: Add test for protocol buffer hash code (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin.git@master
Patch Set: Addressed review comments Created 7 years, 1 month 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/all_tests.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
(Empty)
1 #!/usr/bin/env dart
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file.
5
6 library hash_code_tests;
7
8 import 'dart:typed_data';
9
10 import 'package:fixnum/fixnum.dart';
11 import 'package:protobuf/protobuf.dart';
12 import 'package:unittest/unittest.dart';
13
14 import '../out/protos/google/protobuf/unittest.pb.dart';
15
16 void main() {
17 test('testHashCodeEmptyMessage', () {
18 var m1 = new TestAllTypes();
19 var m2 = new TestAllTypes();
20 expect(m1.hashCode, m2.hashCode);
21 });
22
23 test('testHashCodeOptionalInt32', () {
24 var m1 = new TestAllTypes()..optionalInt32 = 42;
25 var m2 = new TestAllTypes()..optionalInt32 = 42;
26 expect(m1.hashCode, m2.hashCode);
27
28 m1.optionalInt32 = 43;
29 expect(m1.hashCode, isNot(m2.hashCode));
30
31 m2.optionalInt32 = 43;
32 expect(m1.hashCode, m2.hashCode);
33 });
34
35 test('testHashCodeOptionalInt64', () {
36 var m1 = new TestAllTypes()..optionalInt64 = new Int64(42);
37 var m2 = new TestAllTypes()..optionalInt64 = new Int64(42);
38 expect(m1.hashCode, m2.hashCode);
39
40 m1.optionalInt64 = new Int64(43);
41 expect(m1.hashCode, isNot(m2.hashCode));
42
43 m2.optionalInt64 = new Int64(43);
44 expect(m1.hashCode, m2.hashCode);
45 });
46
47 test('testHashCodeOptionalString', () {
48 var m1 = new TestAllTypes()..optionalString = "Dart";
49 var m2 = new TestAllTypes()..optionalString = "Dart";
50 expect(m1.hashCode, m2.hashCode);
51
52 m1.optionalString = "JavaScript";
53 expect(m1.hashCode, isNot(m2.hashCode));
54
55 m2.optionalString = "JavaScript";
56 expect(m1.hashCode, m2.hashCode);
57 });
58
59 test('testHashCodeOptionalEnum', () {
60 var m1 = new TestAllTypes()
61 ..optionalNestedEnum = TestAllTypes_NestedEnum.BAR;
62 var m2 = new TestAllTypes()
63 ..optionalNestedEnum = TestAllTypes_NestedEnum.BAR;
64 expect(m1.hashCode, m2.hashCode);
65
66 m1.optionalNestedEnum = TestAllTypes_NestedEnum.BAZ;
67 expect(m1.hashCode, isNot(m2.hashCode));
68
69 m2.optionalNestedEnum = TestAllTypes_NestedEnum.BAZ;
70 expect(m1.hashCode, m2.hashCode);
71 });
72
73 test('testHashCodeRepeatedInt32', () {
74 var m1 = new TestAllTypes();
75 var m2 = new TestAllTypes();
76 m1.repeatedInt32.add(42);
77 m2.repeatedInt32.add(42);
78 expect(m1.hashCode, m2.hashCode);
79 });
80
81 test('testHashCodeRepeatedInt64', () {
82 var m1 = new TestAllTypes();
83 var m2 = new TestAllTypes();
84 m1.repeatedInt32.add(42);
85 m2.repeatedInt32.add(42);
86 expect(m1.hashCode, m2.hashCode);
87
88 m1.repeatedInt32.add(43);
89 expect(m1.hashCode, isNot(m2.hashCode));
90
91 m2.repeatedInt32.add(43);
92 expect(m1.hashCode, m2.hashCode);
93
94 m1.repeatedInt32.clear();
95 expect(m1.hashCode, isNot(m2.hashCode));
96
97 m2.repeatedInt32.clear();
98 expect(m1.hashCode, m2.hashCode);
99 });
100
101 test('testHashCodeRepeatedString', () {
102 var m1 = new TestAllTypes();
103 var m2 = new TestAllTypes();
104 m1.repeatedString.add("Dart");
105 m2.repeatedString.add("Dart");
106 expect(m1.hashCode, m2.hashCode);
107
108 m1.repeatedString.add("JavaScript");
109 expect(m1.hashCode, isNot(m2.hashCode));
110
111 m2.repeatedString.add("JavaScript");
112 expect(m1.hashCode, m2.hashCode);
113
114 m1.repeatedString.clear();
115 expect(m1.hashCode, isNot(m2.hashCode));
116
117 m2.repeatedString.clear();
118 expect(m1.hashCode, m2.hashCode);
119 });
120
121 test('testHashCodeRepeatedEnum', () {
122 var m1 = new TestAllTypes();
123 var m2 = new TestAllTypes();
124 m1.repeatedNestedEnum.add(TestAllTypes_NestedEnum.BAR);
125 m2.repeatedNestedEnum.add(TestAllTypes_NestedEnum.BAR);
126 expect(m1.hashCode, m2.hashCode);
127
128 m1.repeatedNestedEnum.add(TestAllTypes_NestedEnum.BAZ);
129 expect(m1.hashCode, isNot(m2.hashCode));
130
131 m2.repeatedNestedEnum.add(TestAllTypes_NestedEnum.BAZ);
132 expect(m1.hashCode, m2.hashCode);
133 });
134
135 test('testHashCodeUnknownFields', () {
136 var m1 = new TestAllTypes();
137 var m2 = new TestAllTypes();
138 m1.unknownFields.mergeVarintField(12345, new Int64(123));
139 m2.unknownFields.mergeVarintField(12345, new Int64(123));
140 expect(m1.hashCode, m2.hashCode);
141 });
142
143 test('testHashCodeCombined', () {
144 var m1 = new TestAllTypes()
145 ..optionalInt32 = 42
146 ..optionalInt64 = new Int64(42)
147 ..optionalString = "Dart"
148 ..optionalNestedEnum = TestAllTypes_NestedEnum.BAR;
149 var m2 = new TestAllTypes()
150 ..optionalInt32 = 42
151 ..optionalInt64 = new Int64(42)
152 ..optionalString = "Dart"
153 ..optionalNestedEnum = TestAllTypes_NestedEnum.BAR;
154 expect(m1.hashCode, m2.hashCode);
155
156 m1.repeatedInt32..add(42)..add(43);
157 m2.repeatedInt32..add(42)..add(43);
158 m1.repeatedInt64..add(new Int64(42))..add(new Int64(43));
159 m2.repeatedInt64..add(new Int64(42))..add(new Int64(43));
160 m1.repeatedString..add("Dart")..add("JavaScript");
161 m2.repeatedString..add("Dart")..add("JavaScript");
162 m1.repeatedNestedEnum
163 ..add(TestAllTypes_NestedEnum.BAR)
164 ..add(TestAllTypes_NestedEnum.BAZ);
165 m2.repeatedNestedEnum
166 ..add(TestAllTypes_NestedEnum.BAR)
167 ..add(TestAllTypes_NestedEnum.BAZ);
168 expect(m1.hashCode, m2.hashCode);
169
170 m1.unknownFields.mergeVarintField(12345, new Int64(123));
171 m2.unknownFields.mergeVarintField(12345, new Int64(123));
172 expect(m1.hashCode, m2.hashCode);
173 expect(m1.hashCode, m2.hashCode);
174 });
175 }
OLDNEW
« no previous file with comments | « test/all_tests.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698