Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: pkg/analyzer/test/src/summary/flat_buffers_test.dart

Issue 1691033002: Fix table size in flatbuffers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/flat_buffers.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
8
7 import 'package:analyzer/src/summary/flat_buffers.dart'; 9 import 'package:analyzer/src/summary/flat_buffers.dart';
8 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
9 11
10 import '../../reflective_tests.dart'; 12 import '../../reflective_tests.dart';
11 13
12 main() { 14 main() {
13 groupSep = ' | '; 15 groupSep = ' | ';
14 runReflectiveTests(BuilderTest); 16 runReflectiveTests(BuilderTest);
15 } 17 }
16 18
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 byteList = builder.finish(offset); 81 byteList = builder.finish(offset);
80 } 82 }
81 // read and verify 83 // read and verify
82 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject(); 84 BufferPointer object = new BufferPointer.fromBytes(byteList).derefObject();
83 // was not written, so uses the new default value 85 // was not written, so uses the new default value
84 expect(const Int32Reader().vTableGet(object, 0, 15), 15); 86 expect(const Int32Reader().vTableGet(object, 0, 15), 15);
85 // has the written value 87 // has the written value
86 expect(const Int32Reader().vTableGet(object, 1, 15), 20); 88 expect(const Int32Reader().vTableGet(object, 1, 15), 20);
87 } 89 }
88 90
91 void test_table_format() {
92 Uint8List byteList;
93 {
94 Builder builder = new Builder(initialSize: 0);
95 builder.startTable();
96 builder.addInt32(0, 10);
97 builder.addInt32(1, 20);
98 builder.addInt32(2, 30);
99 byteList = builder.finish(builder.endTable());
100 }
101 // Convert byteList to a ByteData so that we can read data from it.
102 ByteData byteData = byteList.buffer.asByteData(byteList.offsetInBytes);
103 // First 4 bytes are an offset to the table data.
104 int tableDataLoc = byteData.getUint32(0, Endianness.LITTLE_ENDIAN);
105 // First 4 bytes of the table data are a backwards offset to the vtable.
106 int vTableLoc = tableDataLoc -
107 byteData.getInt32(tableDataLoc, Endianness.LITTLE_ENDIAN);
108 // First 2 bytes of the vtable are the size of the vtable in bytes, which
109 // should be 10.
110 expect(byteData.getUint16(vTableLoc, Endianness.LITTLE_ENDIAN), 10);
111 // Next 2 bytes are the size of the object in bytes (including the vtable
112 // pointer), which should be 16.
113 expect(byteData.getUint16(vTableLoc + 2, Endianness.LITTLE_ENDIAN), 16);
114 // Remaining 6 bytes are the offsets within the object where the ints are
115 // located.
116 for (int i = 0; i < 3; i++) {
117 int offset =
118 byteData.getUint16(vTableLoc + 4 + 2 * i, Endianness.LITTLE_ENDIAN);
119 expect(byteData.getInt32(tableDataLoc + offset, Endianness.LITTLE_ENDIAN),
120 10 + 10 * i);
121 }
122 }
123
89 void test_table_types() { 124 void test_table_types() {
90 List<int> byteList; 125 List<int> byteList;
91 { 126 {
92 Builder builder = new Builder(initialSize: 0); 127 Builder builder = new Builder(initialSize: 0);
93 Offset<String> stringOffset = builder.writeString('12345'); 128 Offset<String> stringOffset = builder.writeString('12345');
94 builder.startTable(); 129 builder.startTable();
95 builder.addBool(0, true); 130 builder.addBool(0, true);
96 builder.addInt8(1, 10); 131 builder.addInt8(1, 10);
97 builder.addInt32(2, 20); 132 builder.addInt32(2, 20);
98 builder.addOffset(3, stringOffset); 133 builder.addOffset(3, stringOffset);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 293 }
259 294
260 class TestPointReader extends TableReader<TestPointImpl> { 295 class TestPointReader extends TableReader<TestPointImpl> {
261 const TestPointReader(); 296 const TestPointReader();
262 297
263 @override 298 @override
264 TestPointImpl createObject(BufferPointer object) { 299 TestPointImpl createObject(BufferPointer object) {
265 return new TestPointImpl(object); 300 return new TestPointImpl(object);
266 } 301 }
267 } 302 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/flat_buffers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698