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

Unified Diff: tests/lib/typed_data/typed_list_buffer_test.dart

Issue 138033002: Make VM TypedList not implement ByteBuffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comment saying why Int64 test is omitted in test. Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: tests/lib/typed_data/typed_list_buffer_test.dart
diff --git a/tests/lib/typed_data/typed_list_buffer_test.dart b/tests/lib/typed_data/typed_list_buffer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..29cf7b416733ad6284b330d28da5fc8b659dd5cf
--- /dev/null
+++ b/tests/lib/typed_data/typed_list_buffer_test.dart
@@ -0,0 +1,80 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
siva 2014/01/14 22:02:17 2014
Lasse Reichstein Nielsen 2014/01/15 09:47:58 That'll be a safe comment on all my new files for
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:expect/expect.dart';
+import 'dart:typed_data';
+
+// Test that the sublist of a typed_data list is of the same type.
+
+class TypedDataConstructor {
+ final String name;
+ final Function create;
+ final Function view;
+ TypedDataConstructor(this.name, this.create, this.view);
+}
+
+List constructors = [
+ new TypedDataConstructor("Int8",
+ (int n) => new Int8List(n),
+ (ByteBuffer b) => new Int8List.view(b)),
+ new TypedDataConstructor("Uint8",
+ (int n) => new Uint8List(n),
+ (ByteBuffer b) => new Uint8List.view(b)),
+ new TypedDataConstructor("Uint8Clamped",
+ (int n) => new Uint8ClampedList(n),
+ (ByteBuffer b) => new Uint8ClampedList.view(b)),
+ new TypedDataConstructor("Int16",
+ (int n) => new Int16List(n),
+ (ByteBuffer b) => new Int16List.view(b)),
+ new TypedDataConstructor("Uint16",
+ (int n) => new Uint16List(n),
+ (ByteBuffer b) => new Uint16List.view(b)),
+ new TypedDataConstructor("Int32",
+ (int n) => new Int32List(n),
+ (ByteBuffer b) => new Int32List.view(b)),
+ new TypedDataConstructor("Uint32",
+ (int n) => new Uint32List(n),
+ (ByteBuffer b) => new Uint32List.view(b)),
+ // Int64 and Uint64 are not supported on dart2js compiled code.
+ new TypedDataConstructor("Int64", /// 01: ok
+ (int n) => new Int64List(n), /// 01: continued
+ (ByteBuffer b) => new Int64List.view(b)), /// 01: continued
+ new TypedDataConstructor("Uint64", /// 01: continued
+ (int n) => new Uint64List(n), /// 01: continued
+ (ByteBuffer b) => new Uint64List.view(b)), /// 01: continued
+ new TypedDataConstructor("Float32",
+ (int n) => new Float32List(n),
+ (ByteBuffer b) => new Float32List.view(b)),
+ new TypedDataConstructor("Float64",
+ (int n) => new Float64List(n),
+ (ByteBuffer b) => new Float64List.view(b)),
+ new TypedDataConstructor("Int32x4",
+ (int n) => new Int32x4List(n),
+ (ByteBuffer b) => new Int32x4List.view(b)),
+ new TypedDataConstructor("Float32x4",
+ (int n) => new Float32x4List(n),
+ (ByteBuffer b) => new Float32x4List.view(b))
+];
+
+
+void main() {
+ for (var c in constructors) {
+ String name = c.name;
+ List list = c.create(64);
+ Expect.isTrue(list is! ByteBuffer);
+ ByteBuffer buffer = list.buffer;
+ Expect.isTrue(buffer is! List);
+ Expect.identical(buffer, list.buffer, name);
+ for (var v in constructors) {
+ String testDesc = "${v.name} view, $name buffer";
+ List view = v.view(list.buffer);
+
+ Expect.identical(buffer, view.buffer, testDesc);
+ Expect.isTrue(view is List, testDesc);
+ Expect.isTrue(view.buffer is ByteBuffer, testDesc);
+ Expect.isTrue(view is! ByteBuffer, testDesc);
+ Expect.isTrue(view.buffer is! List, testDesc);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698