| 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 'package:analyzer/src/summary/flat_buffers.dart'; | 7 import 'package:analyzer/src/summary/flat_buffers.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 | 9 |
| 10 import '../../reflective_tests.dart'; | 10 import '../../reflective_tests.dart'; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 List<int> byteList; | 90 List<int> byteList; |
| 91 { | 91 { |
| 92 Builder builder = new Builder(initialSize: 0); | 92 Builder builder = new Builder(initialSize: 0); |
| 93 Offset<String> stringOffset = builder.writeString('12345'); | 93 Offset<String> stringOffset = builder.writeString('12345'); |
| 94 builder.startTable(); | 94 builder.startTable(); |
| 95 builder.addBool(0, true); | 95 builder.addBool(0, true); |
| 96 builder.addInt8(1, 10); | 96 builder.addInt8(1, 10); |
| 97 builder.addInt32(2, 20); | 97 builder.addInt32(2, 20); |
| 98 builder.addOffset(3, stringOffset); | 98 builder.addOffset(3, stringOffset); |
| 99 builder.addInt32(4, 40); | 99 builder.addInt32(4, 40); |
| 100 builder.addUint32(5, 0x9ABCDEF0); |
| 100 Offset offset = builder.endTable(); | 101 Offset offset = builder.endTable(); |
| 101 byteList = builder.finish(offset); | 102 byteList = builder.finish(offset); |
| 102 } | 103 } |
| 103 // read and verify | 104 // read and verify |
| 104 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); | 105 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); |
| 105 expect(const BoolReader().vTableGet(object, 0), true); | 106 expect(const BoolReader().vTableGet(object, 0), true); |
| 106 expect(const Int8Reader().vTableGet(object, 1), 10); | 107 expect(const Int8Reader().vTableGet(object, 1), 10); |
| 107 expect(const Int32Reader().vTableGet(object, 2), 20); | 108 expect(const Int32Reader().vTableGet(object, 2), 20); |
| 108 expect(const StringReader().vTableGet(object, 3), '12345'); | 109 expect(const StringReader().vTableGet(object, 3), '12345'); |
| 109 expect(const Int32Reader().vTableGet(object, 4), 40); | 110 expect(const Int32Reader().vTableGet(object, 4), 40); |
| 111 expect(const Uint32Reader().vTableGet(object, 5), 0x9ABCDEF0); |
| 110 } | 112 } |
| 111 | 113 |
| 112 void test_writeList_ofFloat64() { | 114 void test_writeList_ofFloat64() { |
| 113 List<double> values = <double>[-1.234567, 3.4E+9, -5.6E-13, 7.8, 12.13]; | 115 List<double> values = <double>[-1.234567, 3.4E+9, -5.6E-13, 7.8, 12.13]; |
| 114 // write | 116 // write |
| 115 List<int> byteList; | 117 List<int> byteList; |
| 116 { | 118 { |
| 117 Builder builder = new Builder(initialSize: 0); | 119 Builder builder = new Builder(initialSize: 0); |
| 118 Offset offset = builder.writeListFloat64(values); | 120 Offset offset = builder.writeListFloat64(values); |
| 119 byteList = builder.finish(offset); | 121 byteList = builder.finish(offset); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 byteList = builder.finish(offset); | 206 byteList = builder.finish(offset); |
| 205 } | 207 } |
| 206 // read and verify | 208 // read and verify |
| 207 BufferPointer root = new BufferPointer.fromBytes(byteList); | 209 BufferPointer root = new BufferPointer.fromBytes(byteList); |
| 208 StringListWrapperImpl reader = new StringListWrapperReader().read(root); | 210 StringListWrapperImpl reader = new StringListWrapperReader().read(root); |
| 209 List<String> items = reader.items; | 211 List<String> items = reader.items; |
| 210 expect(items, hasLength(2)); | 212 expect(items, hasLength(2)); |
| 211 expect(items, contains('12345')); | 213 expect(items, contains('12345')); |
| 212 expect(items, contains('ABC')); | 214 expect(items, contains('ABC')); |
| 213 } | 215 } |
| 216 |
| 217 void test_writeList_ofUint32() { |
| 218 List<int> byteList; |
| 219 { |
| 220 Builder builder = new Builder(initialSize: 0); |
| 221 Offset offset = builder.writeListUint32(<int>[1, 2, 0x9ABCDEF0]); |
| 222 byteList = builder.finish(offset); |
| 223 } |
| 224 // read and verify |
| 225 BufferPointer root = new BufferPointer.fromBytes(byteList); |
| 226 List<int> items = const ListReader<int>(const Uint32Reader()).read(root); |
| 227 expect(items, hasLength(3)); |
| 228 expect(items, orderedEquals(<int>[1, 2, 0x9ABCDEF0])); |
| 229 } |
| 214 } | 230 } |
| 215 | 231 |
| 216 class StringListWrapperImpl { | 232 class StringListWrapperImpl { |
| 217 final BufferPointer bp; | 233 final BufferPointer bp; |
| 218 | 234 |
| 219 StringListWrapperImpl(this.bp); | 235 StringListWrapperImpl(this.bp); |
| 220 | 236 |
| 221 List<String> get items => | 237 List<String> get items => |
| 222 const ListReader<String>(const StringReader()).vTableGet(bp, 0); | 238 const ListReader<String>(const StringReader()).vTableGet(bp, 0); |
| 223 } | 239 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 242 } | 258 } |
| 243 | 259 |
| 244 class TestPointReader extends TableReader<TestPointImpl> { | 260 class TestPointReader extends TableReader<TestPointImpl> { |
| 245 const TestPointReader(); | 261 const TestPointReader(); |
| 246 | 262 |
| 247 @override | 263 @override |
| 248 TestPointImpl createObject(BufferPointer object) { | 264 TestPointImpl createObject(BufferPointer object) { |
| 249 return new TestPointImpl(object); | 265 return new TestPointImpl(object); |
| 250 } | 266 } |
| 251 } | 267 } |
| OLD | NEW |