OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=--compile_all --error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'package:observatory/object_graph.dart'; |
| 7 import 'package:expect/expect.dart'; |
| 8 import 'dart:typed_data'; |
| 9 |
| 10 testRoundTrip(final int n) { |
| 11 var bytes = []; |
| 12 var remaining = n; |
| 13 while (remaining > 127) { |
| 14 bytes.add(remaining & 127); |
| 15 remaining = remaining >> 7; |
| 16 } |
| 17 bytes.add(remaining + 128); |
| 18 |
| 19 print("Encoded $n as $bytes"); |
| 20 |
| 21 var typedBytes = new ByteData.view(new Uint8List.fromList(bytes).buffer); |
| 22 var stream = new ReadStream([typedBytes]); |
| 23 stream.readUnsigned(); |
| 24 |
| 25 Expect.equals(n == 0, stream.isZero); |
| 26 |
| 27 Expect.equals((n >> 0) & 0xFFFFFFF, stream.low); |
| 28 Expect.equals((n >> 28) & 0xFFFFFFF, stream.mid); |
| 29 Expect.equals((n >> 56) & 0xFFFFFFF, stream.high); |
| 30 |
| 31 const kMaxUint32 = (1 << 32) - 1; |
| 32 if (n > kMaxUint32) { |
| 33 Expect.equals(kMaxUint32, stream.clampedUint32); |
| 34 } else { |
| 35 Expect.equals(n, stream.clampedUint32); |
| 36 } |
| 37 |
| 38 Expect.equals(bytes.length, stream.position); |
| 39 } |
| 40 |
| 41 main() { |
| 42 const kMaxUint64 = (1 << 64) - 1; |
| 43 |
| 44 var n = 3; |
| 45 while (n < kMaxUint64) { |
| 46 testRoundTrip(n); |
| 47 n <<= 1; |
| 48 } |
| 49 |
| 50 n = 5; |
| 51 while (n < kMaxUint64) { |
| 52 testRoundTrip(n); |
| 53 n <<= 1; |
| 54 } |
| 55 } |
OLD | NEW |