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

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

Issue 16137009: Fix issue 10898 by fixing the ByteData constructor to implicitly create an ArrayBuffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix length <-> byteLength issue. Created 7 years, 7 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
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/typed_data/byte_data_test.dart
diff --git a/tests/lib/typed_data/byte_data_test.dart b/tests/lib/typed_data/byte_data_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cffa631ab3865f13b021565aa3287a6d464fe911
--- /dev/null
+++ b/tests/lib/typed_data/byte_data_test.dart
@@ -0,0 +1,40 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// 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';
+
+main() {
+ testRegress10898();
+}
+
+testRegress10898() {
+ ByteData data = new ByteData(16);
+ Expect.equals(16, data.lengthInBytes);
+ for (int i = 0; i < data.lengthInBytes; i++) {
+ Expect.equals(0, data.getInt8(i));
+ data.setInt8(i, 42 + i);
+ Expect.equals(42 + i, data.getInt8(i));
+ }
+
+ ByteData backing = new ByteData(16);
+ ByteData view = new ByteData.view(backing.buffer);
+ for (int i = 0; i < view.lengthInBytes; i++) {
+ Expect.equals(0, view.getInt8(i));
+ view.setInt8(i, 87 + i);
+ Expect.equals(87 + i, view.getInt8(i));
+ }
+
+ view = new ByteData.view(backing.buffer, 4);
+ Expect.equals(12, view.lengthInBytes);
+ for (int i = 0; i < view.lengthInBytes; i++) {
+ Expect.equals(87 + i + 4, view.getInt8(i));
+ }
+
+ view = new ByteData.view(backing.buffer, 8, 4);
+ Expect.equals(4, view.lengthInBytes);
+ for (int i = 0; i < view.lengthInBytes; i++) {
+ Expect.equals(87 + i + 8, view.getInt8(i));
+ }
+}
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698