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

Unified Diff: tests/standalone/io/file_typed_data_test.dart

Issue 14142008: Add support for more typed data types on native ports (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 8 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
« runtime/vm/dart_api_message.cc ('K') | « sdk/lib/io/common.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/file_typed_data_test.dart
diff --git a/tests/standalone/io/file_typed_data_test.dart b/tests/standalone/io/file_typed_data_test.dart
index 027c191aad21af20b3ee9632c545a81857bce2b7..3d03e8e9791f226a8d0908c12bb9cd5ef91846ac 100644
--- a/tests/standalone/io/file_typed_data_test.dart
+++ b/tests/standalone/io/file_typed_data_test.dart
@@ -10,6 +10,33 @@ import 'dart:io';
import 'dart:isolate';
import 'dart:typeddata';
+void testWriteInt8ListAndView() {
+ ReceivePort port = new ReceivePort();
+ Int8List list = new Int8List(8);
+ for (int i = 0; i < 8; i++) list[i] = i;
+ var view = new Int8List.view(list.buffer, 2, 4);
+
+ new Directory('').createTemp().then((temp) {
+ var file = new File("${temp.path}/test");
+ file.open(mode: FileMode.WRITE).then((raf) {
+ return raf.writeList(list, 0, 8);
+ }).then((raf) {
+ return raf.writeList(view, 0, 4);
+ }).then((raf) {
+ return raf.close();
+ }).then((_) {
+ var expected = [];
+ expected.addAll(list);
+ expected.addAll(view);
+ var content = file.readAsBytesSync();
+ Expect.listEquals(expected, content);
+ temp.deleteSync(recursive: true);
+ port.close();
+ });
+ });
+}
+
+
void testWriteUint8ListAndView() {
ReceivePort port = new ReceivePort();
Uint8List list = new Uint8List(8);
@@ -37,6 +64,71 @@ void testWriteUint8ListAndView() {
}
+void testWriteInt16ListAndView() {
+ ReceivePort port = new ReceivePort();
+ var list = new Int16List(8);
+ for (int i = 0; i < 8; i++) list[i] = i;
+ var view = new Int16List.view(list.buffer, 2, 4);
+
+ new Directory('').createTemp().then((temp) {
+ var file = new File("${temp.path}/test");
+ file.open(mode: FileMode.WRITE).then((raf) {
+ return raf.writeList(list, 0, 8);
+ }).then((raf) {
+ return raf.writeList(view, 0, 4);
+ }).then((raf) {
+ return raf.close();
+ }).then((_) {
+ var expected = [];
+ expected.addAll(list);
+ expected.addAll(view);
+ var content = file.readAsBytesSync();
+ var typed_data_content = new Uint8List(content.length);
+ for (int i = 0; i < content.length; i++) {
+ typed_data_content[i] = content[i];
+ }
+ Expect.listEquals(expected, new Int16List.view(typed_data_content));
+ temp.deleteSync(recursive: true);
+ port.close();
+ });
+ });
+}
+
+
+void testWriteUint16ListAndView() {
+ ReceivePort port = new ReceivePort();
+ var list = new Uint16List(8);
+ for (int i = 0; i < 8; i++) list[i] = i;
+ var view = new Uint16List.view(list.buffer, 2, 4);
+
+ new Directory('').createTemp().then((temp) {
+ var file = new File("${temp.path}/test");
+ file.open(mode: FileMode.WRITE).then((raf) {
+ return raf.writeList(list, 0, 8);
+ }).then((raf) {
+ return raf.writeList(view, 0, 4);
+ }).then((raf) {
+ return raf.close();
+ }).then((_) {
+ var expected = [];
+ expected.addAll(list);
+ expected.addAll(view);
+ var content = file.readAsBytesSync();
+ var typed_data_content = new Uint8List(content.length);
+ for (int i = 0; i < content.length; i++) {
+ typed_data_content[i] = content[i];
+ }
+ Expect.listEquals(expected, new Uint16List.view(typed_data_content));
+ temp.deleteSync(recursive: true);
+ port.close();
+ });
+ });
+}
+
+
main() {
+ testWriteInt8ListAndView();
testWriteUint8ListAndView();
+ testWriteInt16ListAndView();
+ testWriteUint16ListAndView();
}
« runtime/vm/dart_api_message.cc ('K') | « sdk/lib/io/common.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698