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

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
« no previous file with comments | « 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 15794)
+++ tests/standalone/byte_array_test.dart (working copy)
@@ -9,10 +9,12 @@
#import('dart:scalarlist');
-void testCreateByteArray() {
+void testCreateUint8ByteArray() {
Uint8List byteArray;
byteArray = new Uint8List(0);
+ Expect.isTrue(byteArray is Uint8List);
+ Expect.isFalse(byteArray is Uint8ClampedList);
Expect.equals(0, byteArray.length);
byteArray = new Uint8List(10);
@@ -20,7 +22,21 @@
for (int i = 0; i < 10; i++) {
Expect.equals(0, byteArray[i]);
}
+}
+void testCreateClampedUint8ByteArray() {
+ 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) {
@@ -43,6 +59,22 @@
}
}
+void testClampedUnsignedByteArrayRange(bool check_throws) {
+ 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) {
Int8List byteArray;
byteArray = new Int8List(10);
@@ -62,9 +94,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 +116,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 +134,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 +158,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,11 +203,19 @@
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();
+ testCreateUint8ByteArray();
+ testCreateClampedUint8ByteArray();
testByteArrayRange(false);
testUnsignedByteArrayRange(false);
+ testClampedUnsignedByteArrayRange(false);
testSetRange();
testIndexOutOfRange();
testIndexOf();
« no previous file with comments | « sdk/lib/scalarlist/byte_arrays.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698