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

Side by Side Diff: runtime/vm/snapshot_test.cc

Issue 12730013: - Use dart:typedata types in the Dart API calls. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/snapshot.cc ('k') | sdk/lib/io/io.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_message.h" 10 #include "vm/dart_api_message.h"
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 606 }
607 607
608 608
609 TEST_CASE(SerializeByteArray) { 609 TEST_CASE(SerializeByteArray) {
610 StackZone zone(Isolate::Current()); 610 StackZone zone(Isolate::Current());
611 611
612 // Write snapshot with object content. 612 // Write snapshot with object content.
613 uint8_t* buffer; 613 uint8_t* buffer;
614 MessageWriter writer(&buffer, &zone_allocator); 614 MessageWriter writer(&buffer, &zone_allocator);
615 const int kByteArrayLength = 256; 615 const int kByteArrayLength = 256;
616 Uint8Array& byte_array = 616 TypedData& byte_array = TypedData::Handle(
617 Uint8Array::Handle(Uint8Array::New(kByteArrayLength)); 617 TypedData::New(kTypedDataUint8ArrayCid, kByteArrayLength));
618 for (int i = 0; i < kByteArrayLength; i++) { 618 for (int i = 0; i < kByteArrayLength; i++) {
619 byte_array.SetAt(i, i); 619 byte_array.SetUint8(i, i);
620 } 620 }
621 writer.WriteMessage(byte_array); 621 writer.WriteMessage(byte_array);
622 intptr_t buffer_len = writer.BytesWritten(); 622 intptr_t buffer_len = writer.BytesWritten();
623 623
624 // Read object back from the snapshot. 624 // Read object back from the snapshot.
625 SnapshotReader reader(buffer, buffer_len, 625 SnapshotReader reader(buffer, buffer_len,
626 Snapshot::kMessage, Isolate::Current()); 626 Snapshot::kMessage, Isolate::Current());
627 ByteArray& serialized_byte_array = ByteArray::Handle(); 627 TypedData& serialized_byte_array = TypedData::Handle();
628 serialized_byte_array ^= reader.ReadObject(); 628 serialized_byte_array ^= reader.ReadObject();
629 EXPECT(serialized_byte_array.IsByteArray()); 629 EXPECT(serialized_byte_array.IsTypedData());
630 630
631 // Read object back from the snapshot into a C structure. 631 // Read object back from the snapshot into a C structure.
632 ApiNativeScope scope; 632 ApiNativeScope scope;
633 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 633 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
634 Dart_CObject* root = api_reader.ReadMessage(); 634 Dart_CObject* root = api_reader.ReadMessage();
635 EXPECT_EQ(Dart_CObject::kUint8Array, root->type); 635 EXPECT_EQ(Dart_CObject::kUint8Array, root->type);
636 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); 636 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length);
637 for (int i = 0; i < kByteArrayLength; i++) { 637 for (int i = 0; i < kByteArrayLength; i++) {
638 EXPECT(root->value.as_byte_array.values[i] == i); 638 EXPECT(root->value.as_byte_array.values[i] == i);
639 } 639 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 } 712 }
713 713
714 714
715 TEST_CASE(SerializeEmptyByteArray) { 715 TEST_CASE(SerializeEmptyByteArray) {
716 StackZone zone(Isolate::Current()); 716 StackZone zone(Isolate::Current());
717 717
718 // Write snapshot with object content. 718 // Write snapshot with object content.
719 uint8_t* buffer; 719 uint8_t* buffer;
720 MessageWriter writer(&buffer, &zone_allocator); 720 MessageWriter writer(&buffer, &zone_allocator);
721 const int kByteArrayLength = 0; 721 const int kByteArrayLength = 0;
722 Uint8Array& byte_array = 722 TypedData& byte_array = TypedData::Handle(
723 Uint8Array::Handle(Uint8Array::New(kByteArrayLength)); 723 TypedData::New(kTypedDataUint8ArrayCid, kByteArrayLength));
724 writer.WriteMessage(byte_array); 724 writer.WriteMessage(byte_array);
725 intptr_t buffer_len = writer.BytesWritten(); 725 intptr_t buffer_len = writer.BytesWritten();
726 726
727 // Read object back from the snapshot. 727 // Read object back from the snapshot.
728 SnapshotReader reader(buffer, buffer_len, 728 SnapshotReader reader(buffer, buffer_len,
729 Snapshot::kMessage, Isolate::Current()); 729 Snapshot::kMessage, Isolate::Current());
730 ByteArray& serialized_byte_array = ByteArray::Handle(); 730 TypedData& serialized_byte_array = TypedData::Handle();
731 serialized_byte_array ^= reader.ReadObject(); 731 serialized_byte_array ^= reader.ReadObject();
732 EXPECT(serialized_byte_array.IsByteArray()); 732 EXPECT(serialized_byte_array.IsTypedData());
733 733
734 // Read object back from the snapshot into a C structure. 734 // Read object back from the snapshot into a C structure.
735 ApiNativeScope scope; 735 ApiNativeScope scope;
736 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); 736 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator);
737 Dart_CObject* root = api_reader.ReadMessage(); 737 Dart_CObject* root = api_reader.ReadMessage();
738 EXPECT_EQ(Dart_CObject::kUint8Array, root->type); 738 EXPECT_EQ(Dart_CObject::kUint8Array, root->type);
739 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); 739 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length);
740 EXPECT(root->value.as_byte_array.values == NULL); 740 EXPECT(root->value.as_byte_array.values == NULL);
741 CheckEncodeDecodeMessage(root); 741 CheckEncodeDecodeMessage(root);
742 } 742 }
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 } 1756 }
1757 } 1757 }
1758 Dart_ExitScope(); 1758 Dart_ExitScope();
1759 Dart_ShutdownIsolate(); 1759 Dart_ShutdownIsolate();
1760 } 1760 }
1761 1761
1762 1762
1763 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { 1763 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
1764 const int kArrayLength = 10; 1764 const int kArrayLength = 10;
1765 static const char* kScriptChars = 1765 static const char* kScriptChars =
1766 "import 'dart:scalarlist';\n" 1766 "import 'dart:typeddata';\n"
1767 "final int kArrayLength = 10;\n" 1767 "final int kArrayLength = 10;\n"
1768 "getStringList() {\n" 1768 "getStringList() {\n"
1769 " var s = 'Hello, world!';\n" 1769 " var s = 'Hello, world!';\n"
1770 " var list = new List<String>(kArrayLength);\n" 1770 " var list = new List<String>(kArrayLength);\n"
1771 " for (var i = 0; i < kArrayLength; i++) list[i] = s;\n" 1771 " for (var i = 0; i < kArrayLength; i++) list[i] = s;\n"
1772 " return list;\n" 1772 " return list;\n"
1773 "}\n" 1773 "}\n"
1774 "getMintList() {\n" 1774 "getMintList() {\n"
1775 " var mint = 0x7FFFFFFFFFFFFFFF;\n" 1775 " var mint = 0x7FFFFFFFFFFFFFFF;\n"
1776 " var list = new List(kArrayLength);\n" 1776 " var list = new List(kArrayLength);\n"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 } 1927 }
1928 } 1928 }
1929 Dart_ExitScope(); 1929 Dart_ExitScope();
1930 Dart_ShutdownIsolate(); 1930 Dart_ShutdownIsolate();
1931 } 1931 }
1932 1932
1933 1933
1934 UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { 1934 UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) {
1935 const int kArrayLength = 10; 1935 const int kArrayLength = 10;
1936 static const char* kScriptChars = 1936 static const char* kScriptChars =
1937 "import 'dart:scalarlist';\n" 1937 "import 'dart:typeddata';\n"
1938 "final int kArrayLength = 10;\n" 1938 "final int kArrayLength = 10;\n"
1939 "getStringList() {\n" 1939 "getStringList() {\n"
1940 " var s = 'Hello, world!';\n" 1940 " var s = 'Hello, world!';\n"
1941 " var list = [s, s, s, s, s, s, s, s, s, s];\n" 1941 " var list = [s, s, s, s, s, s, s, s, s, s];\n"
1942 " return list;\n" 1942 " return list;\n"
1943 "}\n" 1943 "}\n"
1944 "getMintList() {\n" 1944 "getMintList() {\n"
1945 " var mint = 0x7FFFFFFFFFFFFFFF;\n" 1945 " var mint = 0x7FFFFFFFFFFFFFFF;\n"
1946 " var list = [mint, mint, mint, mint, mint,\n" 1946 " var list = [mint, mint, mint, mint, mint,\n"
1947 " mint, mint, mint, mint, mint];\n" 1947 " mint, mint, mint, mint, mint];\n"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 EXPECT(Dart_ErrorHasException(result)); 2199 EXPECT(Dart_ErrorHasException(result));
2200 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", 2200 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n",
2201 Dart_GetError(result)); 2201 Dart_GetError(result));
2202 2202
2203 Dart_ExitScope(); 2203 Dart_ExitScope();
2204 } 2204 }
2205 2205
2206 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 2206 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
2207 2207
2208 } // namespace dart 2208 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.cc ('k') | sdk/lib/io/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698