| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // Remaining 6 bytes are the offsets within the object where the ints are | 142 // Remaining 6 bytes are the offsets within the object where the ints are |
| 143 // located. | 143 // located. |
| 144 for (int i = 0; i < 3; i++) { | 144 for (int i = 0; i < 3; i++) { |
| 145 int offset = | 145 int offset = |
| 146 byteData.getUint16(vTableLoc + 4 + 2 * i, Endianness.LITTLE_ENDIAN); | 146 byteData.getUint16(vTableLoc + 4 + 2 * i, Endianness.LITTLE_ENDIAN); |
| 147 expect(byteData.getInt32(tableDataLoc + offset, Endianness.LITTLE_ENDIAN), | 147 expect(byteData.getInt32(tableDataLoc + offset, Endianness.LITTLE_ENDIAN), |
| 148 10 + 10 * i); | 148 10 + 10 * i); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 void test_table_string() { |
| 153 String latinString = 'test'; |
| 154 String unicodeString = 'Проба пера'; |
| 155 List<int> byteList; |
| 156 { |
| 157 Builder builder = new Builder(initialSize: 0); |
| 158 Offset<String> latinStringOffset = builder.writeString(latinString); |
| 159 Offset<String> unicodeStringOffset = builder.writeString(unicodeString); |
| 160 builder.startTable(); |
| 161 builder.addOffset(0, latinStringOffset); |
| 162 builder.addOffset(1, unicodeStringOffset); |
| 163 Offset offset = builder.endTable(); |
| 164 byteList = builder.finish(offset); |
| 165 } |
| 166 // read and verify |
| 167 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); |
| 168 expect(const StringReader().vTableGet(object, 0), latinString); |
| 169 expect(const StringReader().vTableGet(object, 1), unicodeString); |
| 170 } |
| 171 |
| 152 void test_table_types() { | 172 void test_table_types() { |
| 153 List<int> byteList; | 173 List<int> byteList; |
| 154 { | 174 { |
| 155 Builder builder = new Builder(initialSize: 0); | 175 Builder builder = new Builder(initialSize: 0); |
| 156 Offset<String> stringOffset = builder.writeString('12345'); | 176 Offset<String> stringOffset = builder.writeString('12345'); |
| 157 builder.startTable(); | 177 builder.startTable(); |
| 158 builder.addBool(0, true); | 178 builder.addBool(0, true); |
| 159 builder.addInt8(1, 10); | 179 builder.addInt8(1, 10); |
| 160 builder.addInt32(2, 20); | 180 builder.addInt32(2, 20); |
| 161 builder.addOffset(3, stringOffset); | 181 builder.addOffset(3, stringOffset); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 } | 414 } |
| 395 | 415 |
| 396 class TestPointReader extends TableReader<TestPointImpl> { | 416 class TestPointReader extends TableReader<TestPointImpl> { |
| 397 const TestPointReader(); | 417 const TestPointReader(); |
| 398 | 418 |
| 399 @override | 419 @override |
| 400 TestPointImpl createObject(BufferPointer object) { | 420 TestPointImpl createObject(BufferPointer object) { |
| 401 return new TestPointImpl(object); | 421 return new TestPointImpl(object); |
| 402 } | 422 } |
| 403 } | 423 } |
| OLD | NEW |