| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 builder.addInt32(0, 100); | 142 builder.addInt32(0, 100); |
| 143 builder.addInt32(1, 200); | 143 builder.addInt32(1, 200); |
| 144 object2 = builder.endTable(); | 144 object2 = builder.endTable(); |
| 145 } | 145 } |
| 146 // write the list | 146 // write the list |
| 147 Offset offset = builder.writeList([object1, object2]); | 147 Offset offset = builder.writeList([object1, object2]); |
| 148 byteList = builder.finish(offset); | 148 byteList = builder.finish(offset); |
| 149 } | 149 } |
| 150 // read and verify | 150 // read and verify |
| 151 BufferPointer root = new BufferPointer.fromBytes(byteList); | 151 BufferPointer root = new BufferPointer.fromBytes(byteList); |
| 152 List<TestPointReader> items = | 152 List<TestPointImpl> items = |
| 153 const ListReader<TestPointReader>(const TestPointReader()).read(root); | 153 const ListReader<TestPointImpl>(const TestPointReader()).read(root); |
| 154 expect(items, hasLength(2)); | 154 expect(items, hasLength(2)); |
| 155 expect(items[0].x, 10); | 155 expect(items[0].x, 10); |
| 156 expect(items[0].y, 20); | 156 expect(items[0].y, 20); |
| 157 expect(items[1].x, 100); | 157 expect(items[1].x, 100); |
| 158 expect(items[1].y, 200); | 158 expect(items[1].y, 200); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void test_writeList_ofStrings_asRoot() { | 161 void test_writeList_ofStrings_asRoot() { |
| 162 List<int> byteList; | 162 List<int> byteList; |
| 163 { | 163 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 182 Builder builder = new Builder(initialSize: 0); | 182 Builder builder = new Builder(initialSize: 0); |
| 183 Offset listOffset = builder.writeList( | 183 Offset listOffset = builder.writeList( |
| 184 [builder.writeString('12345'), builder.writeString('ABC')]); | 184 [builder.writeString('12345'), builder.writeString('ABC')]); |
| 185 builder.startTable(); | 185 builder.startTable(); |
| 186 builder.addOffset(0, listOffset); | 186 builder.addOffset(0, listOffset); |
| 187 Offset offset = builder.endTable(); | 187 Offset offset = builder.endTable(); |
| 188 byteList = builder.finish(offset); | 188 byteList = builder.finish(offset); |
| 189 } | 189 } |
| 190 // read and verify | 190 // read and verify |
| 191 BufferPointer root = new BufferPointer.fromBytes(byteList); | 191 BufferPointer root = new BufferPointer.fromBytes(byteList); |
| 192 StringListWrapperReader reader = new StringListWrapperReader().read(root); | 192 StringListWrapperImpl reader = new StringListWrapperReader().read(root); |
| 193 List<String> items = reader.items; | 193 List<String> items = reader.items; |
| 194 expect(items, hasLength(2)); | 194 expect(items, hasLength(2)); |
| 195 expect(items, contains('12345')); | 195 expect(items, contains('12345')); |
| 196 expect(items, contains('ABC')); | 196 expect(items, contains('ABC')); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 class StringListWrapperReader extends TableReader<StringListWrapperReader> { | 200 class StringListWrapperImpl { |
| 201 final BufferPointer bp; | 201 final BufferPointer bp; |
| 202 | 202 |
| 203 const StringListWrapperReader() : bp = null; | 203 StringListWrapperImpl(this.bp); |
| 204 | |
| 205 StringListWrapperReader._(this.bp); | |
| 206 | 204 |
| 207 List<String> get items => | 205 List<String> get items => |
| 208 const ListReader<String>(const StringReader()).vTableGet(bp, 0); | 206 const ListReader<String>(const StringReader()).vTableGet(bp, 0); |
| 207 } |
| 208 |
| 209 class StringListWrapperReader extends TableReader<StringListWrapperImpl> { |
| 210 const StringListWrapperReader(); |
| 209 | 211 |
| 210 @override | 212 @override |
| 211 StringListWrapperReader createReader(BufferPointer object) { | 213 StringListWrapperImpl createObject(BufferPointer object) { |
| 212 return new StringListWrapperReader._(object); | 214 return new StringListWrapperImpl(object); |
| 213 } | 215 } |
| 214 } | 216 } |
| 215 | 217 |
| 216 class TestPointReader extends TableReader<TestPointReader> { | 218 class TestPointImpl { |
| 217 final BufferPointer bp; | 219 final BufferPointer bp; |
| 218 | 220 |
| 219 const TestPointReader() : bp = null; | 221 TestPointImpl(this.bp); |
| 220 | |
| 221 TestPointReader._(this.bp); | |
| 222 | 222 |
| 223 int get x => const Int32Reader().vTableGet(bp, 0, 0); | 223 int get x => const Int32Reader().vTableGet(bp, 0, 0); |
| 224 | 224 |
| 225 int get y => const Int32Reader().vTableGet(bp, 1, 0); | 225 int get y => const Int32Reader().vTableGet(bp, 1, 0); |
| 226 } |
| 227 |
| 228 class TestPointReader extends TableReader<TestPointImpl> { |
| 229 const TestPointReader(); |
| 226 | 230 |
| 227 @override | 231 @override |
| 228 TestPointReader createReader(BufferPointer object) { | 232 TestPointImpl createObject(BufferPointer object) { |
| 229 return new TestPointReader._(object); | 233 return new TestPointImpl(object); |
| 230 } | 234 } |
| 231 } | 235 } |
| OLD | NEW |