| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 ApiMessageWriter writer(&buffer, &malloc_allocator); | 124 ApiMessageWriter writer(&buffer, &malloc_allocator); |
| 125 writer.WriteCMessage(root); | 125 writer.WriteCMessage(root); |
| 126 | 126 |
| 127 ApiMessageReader api_reader(buffer, writer.BytesWritten(), &zone_allocator); | 127 ApiMessageReader api_reader(buffer, writer.BytesWritten(), &zone_allocator); |
| 128 Dart_CObject* new_root = api_reader.ReadMessage(); | 128 Dart_CObject* new_root = api_reader.ReadMessage(); |
| 129 | 129 |
| 130 // Check that the two messages are the same. | 130 // Check that the two messages are the same. |
| 131 CompareDartCObjects(root, new_root); | 131 CompareDartCObjects(root, new_root); |
| 132 } | 132 } |
| 133 | 133 |
| 134 | |
| 135 static void ExpectEncodeFail(Dart_CObject* root) { | |
| 136 uint8_t* buffer = NULL; | |
| 137 ApiMessageWriter writer(&buffer, &malloc_allocator); | |
| 138 const bool result = writer.WriteCMessage(root); | |
| 139 EXPECT_EQ(false, result); | |
| 140 } | |
| 141 | |
| 142 | |
| 143 TEST_CASE(SerializeNull) { | 134 TEST_CASE(SerializeNull) { |
| 144 StackZone zone(Isolate::Current()); | 135 StackZone zone(Isolate::Current()); |
| 145 | 136 |
| 146 // Write snapshot with object content. | 137 // Write snapshot with object content. |
| 147 uint8_t* buffer; | 138 uint8_t* buffer; |
| 148 MessageWriter writer(&buffer, &zone_allocator); | 139 MessageWriter writer(&buffer, &zone_allocator); |
| 149 const Object& null_object = Object::Handle(); | 140 const Object& null_object = Object::Handle(); |
| 150 writer.WriteMessage(null_object); | 141 writer.WriteMessage(null_object); |
| 151 intptr_t buffer_len = writer.BytesWritten(); | 142 intptr_t buffer_len = writer.BytesWritten(); |
| 152 | 143 |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 573 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 583 for (int i = 0; i < kArrayLength; i++) { | 574 for (int i = 0; i < kArrayLength; i++) { |
| 584 Dart_CObject* element = root->value.as_array.values[i]; | 575 Dart_CObject* element = root->value.as_array.values[i]; |
| 585 EXPECT_EQ(Dart_CObject_kInt32, element->type); | 576 EXPECT_EQ(Dart_CObject_kInt32, element->type); |
| 586 EXPECT_EQ(i, element->value.as_int32); | 577 EXPECT_EQ(i, element->value.as_int32); |
| 587 } | 578 } |
| 588 CheckEncodeDecodeMessage(root); | 579 CheckEncodeDecodeMessage(root); |
| 589 } | 580 } |
| 590 | 581 |
| 591 | 582 |
| 592 TEST_CASE(FailSerializeLargeArray) { | |
| 593 Dart_CObject root; | |
| 594 root.type = Dart_CObject_kArray; | |
| 595 root.value.as_array.length = Array::kMaxElements + 1; | |
| 596 root.value.as_array.values = NULL; | |
| 597 ExpectEncodeFail(&root); | |
| 598 } | |
| 599 | |
| 600 | |
| 601 TEST_CASE(FailSerializeLargeNestedArray) { | |
| 602 Dart_CObject parent; | |
| 603 Dart_CObject child; | |
| 604 Dart_CObject* values[1] = { &child }; | |
| 605 | |
| 606 parent.type = Dart_CObject_kArray; | |
| 607 parent.value.as_array.length = 1; | |
| 608 parent.value.as_array.values = values; | |
| 609 child.type = Dart_CObject_kArray; | |
| 610 child.value.as_array.length = Array::kMaxElements + 1; | |
| 611 ExpectEncodeFail(&parent); | |
| 612 } | |
| 613 | |
| 614 | |
| 615 TEST_CASE(FailSerializeLargeTypedDataInt8) { | |
| 616 Dart_CObject root; | |
| 617 root.type = Dart_CObject_kTypedData; | |
| 618 root.value.as_typed_data.type = Dart_TypedData_kInt8; | |
| 619 root.value.as_typed_data.length = | |
| 620 TypedData::MaxElements(kTypedDataInt8ArrayCid) + 1; | |
| 621 ExpectEncodeFail(&root); | |
| 622 } | |
| 623 | |
| 624 | |
| 625 TEST_CASE(FailSerializeLargeTypedDataUint8) { | |
| 626 Dart_CObject root; | |
| 627 root.type = Dart_CObject_kTypedData; | |
| 628 root.value.as_typed_data.type = Dart_TypedData_kUint8; | |
| 629 root.value.as_typed_data.length = | |
| 630 TypedData::MaxElements(kTypedDataUint8ArrayCid) + 1; | |
| 631 ExpectEncodeFail(&root); | |
| 632 } | |
| 633 | |
| 634 | |
| 635 TEST_CASE(FailSerializeLargeExternalTypedData) { | |
| 636 Dart_CObject root; | |
| 637 root.type = Dart_CObject_kExternalTypedData; | |
| 638 root.value.as_typed_data.length = | |
| 639 ExternalTypedData::MaxElements(kExternalTypedDataUint8ArrayCid) + 1; | |
| 640 ExpectEncodeFail(&root); | |
| 641 } | |
| 642 | |
| 643 | |
| 644 TEST_CASE(SerializeEmptyArray) { | 583 TEST_CASE(SerializeEmptyArray) { |
| 645 StackZone zone(Isolate::Current()); | 584 StackZone zone(Isolate::Current()); |
| 646 | 585 |
| 647 // Write snapshot with object content. | 586 // Write snapshot with object content. |
| 648 uint8_t* buffer; | 587 uint8_t* buffer; |
| 649 MessageWriter writer(&buffer, &zone_allocator); | 588 MessageWriter writer(&buffer, &zone_allocator); |
| 650 const int kArrayLength = 0; | 589 const int kArrayLength = 0; |
| 651 Array& array = Array::Handle(Array::New(kArrayLength)); | 590 Array& array = Array::Handle(Array::New(kArrayLength)); |
| 652 writer.WriteMessage(array); | 591 writer.WriteMessage(array); |
| 653 intptr_t buffer_len = writer.BytesWritten(); | 592 intptr_t buffer_len = writer.BytesWritten(); |
| (...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 result = Dart_RunLoop(); | 2599 result = Dart_RunLoop(); |
| 2661 EXPECT(Dart_IsError(result)); | 2600 EXPECT(Dart_IsError(result)); |
| 2662 EXPECT(Dart_ErrorHasException(result)); | 2601 EXPECT(Dart_ErrorHasException(result)); |
| 2663 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", | 2602 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", |
| 2664 Dart_GetError(result)); | 2603 Dart_GetError(result)); |
| 2665 | 2604 |
| 2666 Dart_ExitScope(); | 2605 Dart_ExitScope(); |
| 2667 } | 2606 } |
| 2668 | 2607 |
| 2669 } // namespace dart | 2608 } // namespace dart |
| OLD | NEW |