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

Unified Diff: tests/standalone/byte_array_test.dart

Issue 11437028: Added Uint8ClampedList. COmpielr optimziations to follow in next CL. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
« runtime/vm/raw_object.cc ('K') | « sdk/lib/scalarlist/byte_arrays.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/byte_array_test.dart
===================================================================
--- tests/standalone/byte_array_test.dart (revision 15751)
+++ tests/standalone/byte_array_test.dart (working copy)
@@ -10,37 +10,71 @@
#import('dart:scalarlist');
void testCreateByteArray() {
- Uint8List byteArray;
+ {
+ Uint8List byteArray;
- byteArray = new Uint8List(0);
- Expect.equals(0, byteArray.length);
+ byteArray = new Uint8List(0);
+ Expect.isTrue(byteArray is Uint8List);
+ Expect.isFalse(byteArray is Uint8ClampedList);
+ Expect.equals(0, byteArray.length);
- byteArray = new Uint8List(10);
- Expect.equals(10, byteArray.length);
- for (int i = 0; i < 10; i++) {
- Expect.equals(0, byteArray[i]);
+ byteArray = new Uint8List(10);
+ Expect.equals(10, byteArray.length);
+ for (int i = 0; i < 10; i++) {
+ Expect.equals(0, byteArray[i]);
+ }
}
+ {
cshapiro 2012/12/05 23:01:49 Create a new test?
srdjan 2012/12/06 19:23:14 Done.
+ Uint8ClampedList clampedByteArray;
+ clampedByteArray = new Uint8ClampedList(0);
+ Expect.isTrue(clampedByteArray is Uint8ClampedList);
+ Expect.isFalse(clampedByteArray is Uint8List);
+ Expect.equals(0, clampedByteArray.length);
+
+ clampedByteArray = new Uint8ClampedList(10);
+ Expect.equals(10, clampedByteArray.length);
+ for (int i = 0; i < 10; i++) {
+ Expect.equals(0, clampedByteArray[i]);
+ }
+ }
}
void testUnsignedByteArrayRange(bool check_throws) {
- Uint8List byteArray;
- byteArray = new Uint8List(10);
+ {
+ Uint8List byteArray;
+ byteArray = new Uint8List(10);
- byteArray[1] = 255;
- Expect.equals(255, byteArray[1]);
- byteArray[1] = 0;
- Expect.equals(0, byteArray[1]);
+ byteArray[1] = 255;
+ Expect.equals(255, byteArray[1]);
+ byteArray[1] = 0;
+ Expect.equals(0, byteArray[1]);
- // These should eventually throw.
- byteArray[1] = 256;
- byteArray[1] = -1;
- byteArray[2] = -129;
- if (check_throws) {
- Expect.throws(() {
- byteArray[1] = 1.2;
- });
+ // These should eventually throw.
+ byteArray[1] = 256;
+ byteArray[1] = -1;
+ byteArray[2] = -129;
+ if (check_throws) {
+ Expect.throws(() {
+ byteArray[1] = 1.2;
+ });
+ }
}
+ {
cshapiro 2012/12/05 23:01:49 Same here
srdjan 2012/12/06 19:23:14 Done.
+ Uint8ClampedList byteArray;
+ byteArray = new Uint8ClampedList(10);
+
+ byteArray[1] = 255;
+ Expect.equals(255, byteArray[1]);
+ byteArray[1] = 0;
+ Expect.equals(0, byteArray[1]);
+
+ // These should eventually throw.
+ byteArray[1] = 256;
+ byteArray[2] = -129;
+ Expect.equals(255, byteArray[1]);
+ Expect.equals(0, byteArray[2]);
+ }
}
void testByteArrayRange(bool check_throws) {
@@ -62,9 +96,8 @@
}
}
-void testSetRange() {
- Uint8List byteArray = new Uint8List(3);
+void testSetRangeHelper(byteArray) {
List<int> list = [10, 11, 12];
byteArray.setRange(0, 3, list);
for (int i = 0; i < 3; i++) {
@@ -85,8 +118,13 @@
Expect.equals(9, byteArray[2]);
}
-void testIndexOutOfRange() {
- Uint8List byteArray = new Uint8List(3);
+
+void testSetRange() {
+ testSetRangeHelper(new Uint8List(3));
+ testSetRangeHelper(new Uint8ClampedList(3));
+}
+
+void testIndexOutOfRangeHelper(byteArray) {
List<int> list = const [0, 1, 2, 3];
Expect.throws(() {
@@ -98,8 +136,12 @@
});
}
-void testIndexOf() {
- var list = new Uint8List(10);
+void testIndexOutOfRange() {
+ testIndexOutOfRangeHelper(new Uint8List(3));
+ testIndexOutOfRangeHelper(new Uint8ClampedList(3));
+}
+
+void testIndexOfHelper(list) {
for (int i = 0; i < list.length; i++) {
list[i] = i + 10;
}
@@ -118,8 +160,12 @@
Expect.equals(-1, list.indexOf(20.0));
}
-void testSubArray() {
- var list = new Uint8List(10);
+void testIndexOf() {
+ testIndexOfHelper(new Uint8List(10));
+ testIndexOfHelper(new Uint8ClampedList(10));
+}
+
+void testSubArrayHelper(list) {
var array = list.asByteArray();
Expect.equals(0, array.subByteArray(0, 0).lengthInBytes());
Expect.equals(0, array.subByteArray(5, 0).lengthInBytes());
@@ -159,6 +205,12 @@
Expect.throws(() => array.subByteArray(null), (e) => e is ArgumentError);
}
+
+void testSubArray() {
+ testSubArrayHelper(new Uint8List(10));
+ testSubArrayHelper(new Uint8ClampedList(10));
+}
+
main() {
for (int i = 0; i < 2000; i++) {
testCreateByteArray();
« runtime/vm/raw_object.cc ('K') | « sdk/lib/scalarlist/byte_arrays.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698