| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 byteList = builder.finish(offset); | 100 byteList = builder.finish(offset); |
| 101 } | 101 } |
| 102 // read and verify | 102 // read and verify |
| 103 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); | 103 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); |
| 104 expect(const Int8Reader().vTableGet(object, 0), 10); | 104 expect(const Int8Reader().vTableGet(object, 0), 10); |
| 105 expect(const Int32Reader().vTableGet(object, 1), 20); | 105 expect(const Int32Reader().vTableGet(object, 1), 20); |
| 106 expect(const StringReader().vTableGet(object, 2), '12345'); | 106 expect(const StringReader().vTableGet(object, 2), '12345'); |
| 107 expect(const Int32Reader().vTableGet(object, 3), 40); | 107 expect(const Int32Reader().vTableGet(object, 3), 40); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void test_writeList_ofInt32() { |
| 111 List<int> byteList; |
| 112 { |
| 113 Builder builder = new Builder(initialSize: 0); |
| 114 Offset offset = builder.writeListInt32(<int>[1, 2, 3, 4, 5]); |
| 115 byteList = builder.finish(offset); |
| 116 } |
| 117 // read and verify |
| 118 BufferPointer root = new BufferPointer.fromBytes(byteList); |
| 119 List<int> items = const ListReader<int>(const Int32Reader()).read(root); |
| 120 expect(items, hasLength(5)); |
| 121 expect(items, orderedEquals(<int>[1, 2, 3, 4, 5])); |
| 122 } |
| 123 |
| 110 void test_writeList_ofObjects() { | 124 void test_writeList_ofObjects() { |
| 111 List<int> byteList; | 125 List<int> byteList; |
| 112 { | 126 { |
| 113 Builder builder = new Builder(initialSize: 0); | 127 Builder builder = new Builder(initialSize: 0); |
| 114 // write the object #1 | 128 // write the object #1 |
| 115 Offset object1; | 129 Offset object1; |
| 116 { | 130 { |
| 117 builder.startTable(); | 131 builder.startTable(); |
| 118 builder.addInt32(0, 10); | 132 builder.addInt32(0, 10); |
| 119 builder.addInt32(1, 20); | 133 builder.addInt32(1, 20); |
| 120 object1 = builder.endTable(); | 134 object1 = builder.endTable(); |
| 121 } | 135 } |
| 122 // write the object #1 | 136 // write the object #1 |
| 123 Offset object2; | 137 Offset object2; |
| 124 { | 138 { |
| 125 builder.startTable(); | 139 builder.startTable(); |
| 126 builder.addInt32(0, 100); | 140 builder.addInt32(0, 100); |
| 127 builder.addInt32(1, 200); | 141 builder.addInt32(1, 200); |
| 128 object2 = builder.endTable(); | 142 object2 = builder.endTable(); |
| 129 } | 143 } |
| 130 // write the line | 144 // write the list |
| 131 Offset offset = builder.writeList([object1, object2]); | 145 Offset offset = builder.writeList([object1, object2]); |
| 132 byteList = builder.finish(offset); | 146 byteList = builder.finish(offset); |
| 133 } | 147 } |
| 134 // read and verify | 148 // read and verify |
| 135 BufferPointer root = new BufferPointer.fromBytes(byteList); | 149 BufferPointer root = new BufferPointer.fromBytes(byteList); |
| 136 List<TestPointReader> items = | 150 List<TestPointReader> items = |
| 137 const ListReader<TestPointReader>(const TestPointReader()).read(root); | 151 const ListReader<TestPointReader>(const TestPointReader()).read(root); |
| 138 expect(items, hasLength(2)); | 152 expect(items, hasLength(2)); |
| 139 expect(items[0].x, 10); | 153 expect(items[0].x, 10); |
| 140 expect(items[0].y, 20); | 154 expect(items[0].y, 20); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 220 |
| 207 int get x => const Int32Reader().vTableGet(bp, 0, 0); | 221 int get x => const Int32Reader().vTableGet(bp, 0, 0); |
| 208 | 222 |
| 209 int get y => const Int32Reader().vTableGet(bp, 1, 0); | 223 int get y => const Int32Reader().vTableGet(bp, 1, 0); |
| 210 | 224 |
| 211 @override | 225 @override |
| 212 TestPointReader createReader(BufferPointer object) { | 226 TestPointReader createReader(BufferPointer object) { |
| 213 return new TestPointReader._(object); | 227 return new TestPointReader._(object); |
| 214 } | 228 } |
| 215 } | 229 } |
| OLD | NEW |