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

Side by Side Diff: tests/standalone/typed_data_test.dart

Issue 24239003: Fix range checks for typed data in native code and the optimizer. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_optimizer.cc ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Dart test program for testing typed data. 5 // Dart test program for testing typed data.
6 6
7 // VMOptions=--optimization_counter_threshold=10 7 // VMOptions=--optimization_counter_threshold=10
8 8
9 // Library tag to be able to run in html test framework. 9 // Library tag to be able to run in html test framework.
10 library TypedDataTest; 10 library TypedDataTest;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 Expect.equals(20, typed_data[0]); 136 Expect.equals(20, typed_data[0]);
137 Expect.equals(8, typed_data[1]); 137 Expect.equals(8, typed_data[1]);
138 Expect.equals(9, typed_data[2]); 138 Expect.equals(9, typed_data[2]);
139 } 139 }
140 140
141 void testSetRange() { 141 void testSetRange() {
142 testSetRangeHelper(new Uint8List(3)); 142 testSetRangeHelper(new Uint8List(3));
143 testSetRangeHelper(new Uint8ClampedList(3)); 143 testSetRangeHelper(new Uint8ClampedList(3));
144 } 144 }
145 145
146 void testIndexOutOfRangeHelper(typed_data) { 146 class C {
147 List<int> list = const [0, 1, 2, 3]; 147 final x;
148 C(this.x);
149 operator<(o) => false;
150 operator>=(o) => false;
151 operator*(o) => x;
152 }
153
154 void testIndexOutOfRangeHelper(typed_data, value) {
155 List<int> list = new List<int>(typed_data.length + 1);
156 for (int i = 0; i < list.length; i++) list[i] = i;
148 157
149 Expect.throws(() { 158 Expect.throws(() {
150 typed_data.setRange(0, 4, list); 159 typed_data.setRange(0, 4, list);
151 }); 160 });
152 161
153 Expect.throws(() { 162 Expect.throws(() {
154 typed_data.setRange(3, 4, list); 163 typed_data.setRange(3, 4, list);
155 }); 164 });
165
166 Expect.throws(() {
167 typed_data[new C(-4000000)] = value;
168 });
169
170 Expect.throws(() {
171 var size = typed_data.elementSizeInBytes;
172 var i = (typed_data.length - 1) * size + 1;
173 typed_data[new C(i)] = value;
174 });
175
176 Expect.throws(() {
177 typed_data[new C(-1)] = value;
178 });
156 } 179 }
157 180
158 void testIndexOutOfRange() { 181 void testIndexOutOfRange() {
159 testIndexOutOfRangeHelper(new Uint8List(3)); 182 testIndexOutOfRangeHelper(new Int8List(3), 0);
160 testIndexOutOfRangeHelper(new Uint8ClampedList(3)); 183 testIndexOutOfRangeHelper(new Uint8List(3), 0);
184 testIndexOutOfRangeHelper(new Uint8ClampedList(3), 0);
185 testIndexOutOfRangeHelper(new Int16List(3), 0);
186 testIndexOutOfRangeHelper(new Uint16List(3), 0);
187 testIndexOutOfRangeHelper(new Int32List(3), 0);
188 testIndexOutOfRangeHelper(new Uint32List(3), 0);
189 testIndexOutOfRangeHelper(new Int64List(3), 0);
190 testIndexOutOfRangeHelper(new Uint64List(3), 0);
191 testIndexOutOfRangeHelper(new Float32List(3), 0.0);
192 testIndexOutOfRangeHelper(new Float64List(3), 0.0);
193 testIndexOutOfRangeHelper(new Int64List(3), 0);
194 testIndexOutOfRangeHelper(new Uint64List(3), 0);
161 } 195 }
162 196
163 void testIndexOfHelper(list) { 197 void testIndexOfHelper(list) {
164 for (int i = 0; i < list.length; i++) { 198 for (int i = 0; i < list.length; i++) {
165 list[i] = i + 10; 199 list[i] = i + 10;
166 } 200 }
167 Expect.equals(0, list.indexOf(10)); 201 Expect.equals(0, list.indexOf(10));
168 Expect.equals(5, list.indexOf(15)); 202 Expect.equals(5, list.indexOf(15));
169 Expect.equals(9, list.indexOf(19)); 203 Expect.equals(9, list.indexOf(19));
170 Expect.equals(-1, list.indexOf(20)); 204 Expect.equals(-1, list.indexOf(20));
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 testSetAtIndex(float64list, 1.4260258159703532e-105, true); 405 testSetAtIndex(float64list, 1.4260258159703532e-105, true);
372 testGetAtIndex(float64list, 1.4260258159703532e-105); 406 testGetAtIndex(float64list, 1.4260258159703532e-105);
373 } 407 }
374 testTypedDataRange(true); 408 testTypedDataRange(true);
375 testUnsignedTypedDataRange(true); 409 testUnsignedTypedDataRange(true);
376 testViewCreation(); 410 testViewCreation();
377 testWhere(); 411 testWhere();
378 testCreationFromList(); 412 testCreationFromList();
379 } 413 }
380 414
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698