| OLD | NEW |
| 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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 Dart_CObject* root = api_reader.ReadMessage(); | 620 Dart_CObject* root = api_reader.ReadMessage(); |
| 621 EXPECT_EQ(Dart_CObject::kUint8Array, root->type); | 621 EXPECT_EQ(Dart_CObject::kUint8Array, root->type); |
| 622 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); | 622 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); |
| 623 for (int i = 0; i < kByteArrayLength; i++) { | 623 for (int i = 0; i < kByteArrayLength; i++) { |
| 624 EXPECT(root->value.as_byte_array.values[i] == i); | 624 EXPECT(root->value.as_byte_array.values[i] == i); |
| 625 } | 625 } |
| 626 CheckEncodeDecodeMessage(root); | 626 CheckEncodeDecodeMessage(root); |
| 627 } | 627 } |
| 628 | 628 |
| 629 | 629 |
| 630 #define TEST_TYPED_ARRAY(darttype, ctype) \ |
| 631 { \ |
| 632 StackZone zone(Isolate::Current()); \ |
| 633 uint8_t* buffer; \ |
| 634 MessageWriter writer(&buffer, &zone_allocator); \ |
| 635 const int kArrayLength = 127; \ |
| 636 darttype& array = darttype::Handle(darttype::New(kArrayLength)); \ |
| 637 for (int i = 0; i < kArrayLength; i++) { \ |
| 638 array.SetAt(i, i); \ |
| 639 } \ |
| 640 writer.WriteMessage(array); \ |
| 641 intptr_t buffer_len = writer.BytesWritten(); \ |
| 642 SnapshotReader reader(buffer, buffer_len, \ |
| 643 Snapshot::kMessage, Isolate::Current()); \ |
| 644 darttype& serialized_array = darttype::Handle(); \ |
| 645 serialized_array ^= reader.ReadObject(); \ |
| 646 for (int i = 0; i < kArrayLength; i++) { \ |
| 647 EXPECT_EQ(static_cast<ctype>(i), serialized_array.At(i)); \ |
| 648 } \ |
| 649 } |
| 650 |
| 651 |
| 652 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ |
| 653 { \ |
| 654 StackZone zone(Isolate::Current()); \ |
| 655 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ |
| 656 intptr_t length = ARRAY_SIZE(data); \ |
| 657 External##darttype& array = External##darttype::Handle( \ |
| 658 External##darttype::New(data, length, NULL, NULL)); \ |
| 659 uint8_t* buffer; \ |
| 660 MessageWriter writer(&buffer, &zone_allocator); \ |
| 661 writer.WriteMessage(array); \ |
| 662 intptr_t buffer_len = writer.BytesWritten(); \ |
| 663 SnapshotReader reader(buffer, buffer_len, \ |
| 664 Snapshot::kMessage, Isolate::Current()); \ |
| 665 darttype& serialized_array = darttype::Handle(); \ |
| 666 serialized_array ^= reader.ReadObject(); \ |
| 667 for (int i = 0; i < length; i++) { \ |
| 668 EXPECT_EQ(static_cast<ctype>(data[i]), serialized_array.At(i)); \ |
| 669 } \ |
| 670 } |
| 671 |
| 672 |
| 673 TEST_CASE(SerializeTypedArray) { |
| 674 TEST_TYPED_ARRAY(Int8Array, int8_t); |
| 675 TEST_TYPED_ARRAY(Uint8Array, uint8_t); |
| 676 TEST_TYPED_ARRAY(Int16Array, int16_t); |
| 677 TEST_TYPED_ARRAY(Uint16Array, uint16_t); |
| 678 TEST_TYPED_ARRAY(Int32Array, int32_t); |
| 679 TEST_TYPED_ARRAY(Uint32Array, uint32_t); |
| 680 TEST_TYPED_ARRAY(Int64Array, int64_t); |
| 681 TEST_TYPED_ARRAY(Uint64Array, uint64_t); |
| 682 TEST_TYPED_ARRAY(Float32Array, float); |
| 683 TEST_TYPED_ARRAY(Float64Array, double); |
| 684 } |
| 685 |
| 686 |
| 687 TEST_CASE(SerializeExternalTypedArray) { |
| 688 TEST_EXTERNAL_TYPED_ARRAY(Int8Array, int8_t); |
| 689 TEST_EXTERNAL_TYPED_ARRAY(Uint8Array, uint8_t); |
| 690 TEST_EXTERNAL_TYPED_ARRAY(Int16Array, int16_t); |
| 691 TEST_EXTERNAL_TYPED_ARRAY(Uint16Array, uint16_t); |
| 692 TEST_EXTERNAL_TYPED_ARRAY(Int32Array, int32_t); |
| 693 TEST_EXTERNAL_TYPED_ARRAY(Uint32Array, uint32_t); |
| 694 TEST_EXTERNAL_TYPED_ARRAY(Int64Array, int64_t); |
| 695 TEST_EXTERNAL_TYPED_ARRAY(Uint64Array, uint64_t); |
| 696 TEST_EXTERNAL_TYPED_ARRAY(Float32Array, float); |
| 697 TEST_EXTERNAL_TYPED_ARRAY(Float64Array, double); |
| 698 } |
| 699 |
| 700 |
| 630 TEST_CASE(SerializeEmptyByteArray) { | 701 TEST_CASE(SerializeEmptyByteArray) { |
| 631 StackZone zone(Isolate::Current()); | 702 StackZone zone(Isolate::Current()); |
| 632 | 703 |
| 633 // Write snapshot with object content. | 704 // Write snapshot with object content. |
| 634 uint8_t* buffer; | 705 uint8_t* buffer; |
| 635 MessageWriter writer(&buffer, &zone_allocator); | 706 MessageWriter writer(&buffer, &zone_allocator); |
| 636 const int kByteArrayLength = 0; | 707 const int kByteArrayLength = 0; |
| 637 Uint8Array& byte_array = | 708 Uint8Array& byte_array = |
| 638 Uint8Array::Handle(Uint8Array::New(kByteArrayLength)); | 709 Uint8Array::Handle(Uint8Array::New(kByteArrayLength)); |
| 639 writer.WriteMessage(byte_array); | 710 writer.WriteMessage(byte_array); |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1966 EXPECT(Dart_ErrorHasException(result)); | 2037 EXPECT(Dart_ErrorHasException(result)); |
| 1967 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 2038 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
| 1968 Dart_GetError(result)); | 2039 Dart_GetError(result)); |
| 1969 | 2040 |
| 1970 Dart_ExitScope(); | 2041 Dart_ExitScope(); |
| 1971 } | 2042 } |
| 1972 | 2043 |
| 1973 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 2044 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 1974 | 2045 |
| 1975 } // namespace dart | 2046 } // namespace dart |
| OLD | NEW |