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

Side by Side Diff: test/codec_test.dart

Issue 2094533003: Fix coded buffer reader so all tests pass using dart2js. (Closed) Base URL: git@github.com:dart-lang/dart-protobuf.git@master
Patch Set: Created 4 years, 6 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 | « lib/src/protobuf/coded_buffer_reader.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 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 @TestOn("dart-vm")
7 library pb_codec_tests; 6 library pb_codec_tests;
8 7
9 import 'dart:typed_data'; 8 import 'dart:typed_data';
10 9
11 import 'package:protobuf/protobuf.dart'; 10 import 'package:protobuf/protobuf.dart';
12 import 'package:test/test.dart'; 11 import 'package:test/test.dart';
13 12
14 import 'test_util.dart'; 13 import 'test_util.dart';
15 14
16 void main() { 15 void main() {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 readFloat(int bits) { 178 readFloat(int bits) {
180 var bytes = dataToBytes( 179 var bytes = dataToBytes(
181 new ByteData(4)..setUint32(0, bits, Endianness.LITTLE_ENDIAN)); 180 new ByteData(4)..setUint32(0, bits, Endianness.LITTLE_ENDIAN));
182 return new CodedBufferReader(bytes).readFloat(); 181 return new CodedBufferReader(bytes).readFloat();
183 } 182 }
184 183
185 expect(floatToBits(value), bits); 184 expect(floatToBits(value), bits);
186 expect(readFloat(bits), doubleEquals(value)); 185 expect(readFloat(bits), doubleEquals(value));
187 } 186 }
188 187
188 final doubleToBytes = convertToBytes(PbFieldType.OD);
189
189 void _test64(List<int> hilo, double value) { 190 void _test64(List<int> hilo, double value) {
190 readDouble(int bits) { 191 // Encode a double to its wire format.
191 var bytes = dataToBytes( 192 ByteData data = makeData(doubleToBytes(value));
192 new ByteData(8)..setUint64(0, bits, Endianness.LITTLE_ENDIAN)); 193 var actualHilo = [
193 return new CodedBufferReader(bytes).readDouble(); 194 data.getUint32(4, Endianness.LITTLE_ENDIAN),
194 } 195 data.getUint32(0, Endianness.LITTLE_ENDIAN)
196 ];
197 //int encoded = data.getUint64(0, Endianness.LITTLE_ENDIAN);
198 expect(actualHilo, hilo);
195 199
196 final doubleToBytes = convertToBytes(PbFieldType.OD); 200 // Decode it again (round trip).
197 doubleToBits(double value) => 201 List<int> bytes = dataToBytes(data);
198 makeData(doubleToBytes(value)).getUint64(0, Endianness.LITTLE_ENDIAN); 202 double reencoded = new CodedBufferReader(bytes).readDouble();
199 203 expect(reencoded, doubleEquals(value));
200 int bits = (hilo[0] << 32) | hilo[1];
201 expect(doubleToBits(value), bits);
202 expect(readDouble(bits), doubleEquals(value));
203 } 204 }
204 205
205 test('testFloat', () { 206 test('testFloat', () {
206 // Denorms. 207 // Denorms.
207 _test32(0x1, 1.401298464324817E-45); 208 _test32(0x1, 1.401298464324817E-45);
208 _test32(0x2, 1.401298464324817E-45 * 2.0); 209 _test32(0x2, 1.401298464324817E-45 * 2.0);
209 _test32(0x3, 1.401298464324817E-45 * 3.0); 210 _test32(0x3, 1.401298464324817E-45 * 3.0);
210 _test32(0x00ba98, 1.401298464324817E-45 * 0x00ba98); 211 _test32(0x00ba98, 1.401298464324817E-45 * 0x00ba98);
211 _test32(8034422, 1.401298464324817E-45 * 8034422); 212 _test32(8034422, 1.401298464324817E-45 * 8034422);
212 _test32(0x7fffff, 1.401298464324817E-45 * 0x7fffff); 213 _test32(0x7fffff, 1.401298464324817E-45 * 0x7fffff);
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 expect(readUint64([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]), 745 expect(readUint64([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]),
745 expect64(0xffffffff, 0xffffff)); 746 expect64(0xffffffff, 0xffffff));
746 expect( 747 expect(
747 readUint64( 748 readUint64(
748 [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01]), 749 [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01]),
749 expect64(0xffffffff, 0xffffffff)); 750 expect64(0xffffffff, 0xffffffff));
750 expect(readUint64([180, 222, 252, 255, 255, 255, 255, 255, 255, 1]), 751 expect(readUint64([180, 222, 252, 255, 255, 255, 255, 255, 255, 1]),
751 expect64(0xffff2f34, 0xffffffff)); 752 expect64(0xffff2f34, 0xffffffff));
752 }); 753 });
753 } 754 }
OLDNEW
« no previous file with comments | « lib/src/protobuf/coded_buffer_reader.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698