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

Unified Diff: test/codegen/lib/typed_data/endianness_test.dart

Issue 1673863002: Infra for running lib tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Reformat Created 4 years, 10 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: test/codegen/lib/typed_data/endianness_test.dart
diff --git a/test/codegen/lib/typed_data/endianness_test.dart b/test/codegen/lib/typed_data/endianness_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1fdacd2c1f81f68135e86e9bca4ab50c357993e2
--- /dev/null
+++ b/test/codegen/lib/typed_data/endianness_test.dart
@@ -0,0 +1,84 @@
+// Copyright (c) 2014, 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 'dart:typed_data';
+import "package:expect/expect.dart";
+
+main() {
+ swapTest();
+ swapTestVar(Endianness.LITTLE_ENDIAN, Endianness.BIG_ENDIAN);
+ swapTestVar(Endianness.BIG_ENDIAN, Endianness.LITTLE_ENDIAN);
+}
+
+swapTest() {
+ ByteData data = new ByteData(16);
+ Expect.equals(16, data.lengthInBytes);
+ for (int i = 0; i < 4; i++) {
+ data.setInt32(i * 4, i);
+ }
+
+ for (int i = 0; i < data.lengthInBytes; i += 4) {
+ var e = data.getInt32(i, Endianness.BIG_ENDIAN);
+ data.setInt32(i, e, Endianness.LITTLE_ENDIAN);
+ }
+
+ Expect.equals(0x02000000, data.getInt32(8));
+
+ for (int i = 0; i < data.lengthInBytes; i += 2) {
+ var e = data.getInt16(i, Endianness.BIG_ENDIAN);
+ data.setInt16(i, e, Endianness.LITTLE_ENDIAN);
+ }
+
+ Expect.equals(0x00020000, data.getInt32(8));
+
+ for (int i = 0; i < data.lengthInBytes; i += 4) {
+ var e = data.getUint32(i, Endianness.LITTLE_ENDIAN);
+ data.setUint32(i, e, Endianness.BIG_ENDIAN);
+ }
+
+ Expect.equals(0x00000200, data.getInt32(8));
+
+ for (int i = 0; i < data.lengthInBytes; i += 2) {
+ var e = data.getUint16(i, Endianness.LITTLE_ENDIAN);
+ data.setUint16(i, e, Endianness.BIG_ENDIAN);
+ }
+
+ Expect.equals(0x00000002, data.getInt32(8));
+}
+
+swapTestVar(read, write) {
+ ByteData data = new ByteData(16);
+ Expect.equals(16, data.lengthInBytes);
+ for (int i = 0; i < 4; i++) {
+ data.setInt32(i * 4, i);
+ }
+
+ for (int i = 0; i < data.lengthInBytes; i += 4) {
+ var e = data.getInt32(i, read);
+ data.setInt32(i, e, write);
+ }
+
+ Expect.equals(0x02000000, data.getInt32(8));
+
+ for (int i = 0; i < data.lengthInBytes; i += 2) {
+ var e = data.getInt16(i, read);
+ data.setInt16(i, e, write);
+ }
+
+ Expect.equals(0x00020000, data.getInt32(8));
+
+ for (int i = 0; i < data.lengthInBytes; i += 4) {
+ var e = data.getUint32(i, read);
+ data.setUint32(i, e, write);
+ }
+
+ Expect.equals(0x00000200, data.getInt32(8));
+
+ for (int i = 0; i < data.lengthInBytes; i += 2) {
+ var e = data.getUint16(i, read);
+ data.setUint16(i, e, write);
+ }
+
+ Expect.equals(0x00000002, data.getInt32(8));
+}
« no previous file with comments | « test/codegen/lib/typed_data/constructor_checks_test.dart ('k') | test/codegen/lib/typed_data/float32x4_clamp_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698