| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 test.src.summary.flat_buffers_test; | 5 library test.src.summary.flat_buffers_test; |
| 6 | 6 |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/summary/flat_buffers.dart'; | 9 import 'package:analyzer/src/summary/flat_buffers.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 void test_error_writeString_duringTable() { | 50 void test_error_writeString_duringTable() { |
| 51 Builder builder = new Builder(); | 51 Builder builder = new Builder(); |
| 52 builder.startTable(); | 52 builder.startTable(); |
| 53 expect(() { | 53 expect(() { |
| 54 builder.writeString('12345'); | 54 builder.writeString('12345'); |
| 55 }, throwsStateError); | 55 }, throwsStateError); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void test_file_identifier() { |
| 59 Uint8List byteList; |
| 60 { |
| 61 Builder builder = new Builder(initialSize: 0); |
| 62 builder.startTable(); |
| 63 Offset offset = builder.endTable(); |
| 64 byteList = builder.finish(offset, 'Az~ÿ'); |
| 65 } |
| 66 // Convert byteList to a ByteData so that we can read data from it. |
| 67 ByteData byteData = byteList.buffer.asByteData(byteList.offsetInBytes); |
| 68 // First 4 bytes are an offset to the table data. |
| 69 int tableDataLoc = byteData.getUint32(0, Endianness.LITTLE_ENDIAN); |
| 70 // Next 4 bytes are the file identifier. |
| 71 expect(byteData.getUint8(4), 65); // 'a' |
| 72 expect(byteData.getUint8(5), 122); // 'z' |
| 73 expect(byteData.getUint8(6), 126); // '~' |
| 74 expect(byteData.getUint8(7), 255); // 'ÿ' |
| 75 // First 4 bytes of the table data are a backwards offset to the vtable. |
| 76 int vTableLoc = tableDataLoc - |
| 77 byteData.getInt32(tableDataLoc, Endianness.LITTLE_ENDIAN); |
| 78 // First 2 bytes of the vtable are the size of the vtable in bytes, which |
| 79 // should be 4. |
| 80 expect(byteData.getUint16(vTableLoc, Endianness.LITTLE_ENDIAN), 4); |
| 81 // Next 2 bytes are the size of the object in bytes (including the vtable |
| 82 // pointer), which should be 4. |
| 83 expect(byteData.getUint16(vTableLoc + 2, Endianness.LITTLE_ENDIAN), 4); |
| 84 } |
| 85 |
| 58 void test_low() { | 86 void test_low() { |
| 59 Builder builder = new Builder(initialSize: 0); | 87 Builder builder = new Builder(initialSize: 0); |
| 60 builder.lowReset(); | 88 builder.lowReset(); |
| 61 expect((builder..lowWriteUint8(1)).lowFinish(), [1]); | 89 expect((builder..lowWriteUint8(1)).lowFinish(), [1]); |
| 62 expect((builder..lowWriteUint32(2)).lowFinish(), [2, 0, 0, 0, 0, 0, 0, 1]); | 90 expect((builder..lowWriteUint32(2)).lowFinish(), [2, 0, 0, 0, 0, 0, 0, 1]); |
| 63 expect((builder..lowWriteUint8(3)).lowFinish(), | 91 expect((builder..lowWriteUint8(3)).lowFinish(), |
| 64 [0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1]); | 92 [0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1]); |
| 65 expect((builder..lowWriteUint8(4)).lowFinish(), | 93 expect((builder..lowWriteUint8(4)).lowFinish(), |
| 66 [0, 0, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]); | 94 [0, 0, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]); |
| 67 expect((builder..lowWriteUint8(5)).lowFinish(), | 95 expect((builder..lowWriteUint8(5)).lowFinish(), |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 353 } |
| 326 | 354 |
| 327 class TestPointReader extends TableReader<TestPointImpl> { | 355 class TestPointReader extends TableReader<TestPointImpl> { |
| 328 const TestPointReader(); | 356 const TestPointReader(); |
| 329 | 357 |
| 330 @override | 358 @override |
| 331 TestPointImpl createObject(BufferPointer object) { | 359 TestPointImpl createObject(BufferPointer object) { |
| 332 return new TestPointImpl(object); | 360 return new TestPointImpl(object); |
| 333 } | 361 } |
| 334 } | 362 } |
| OLD | NEW |