| 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_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "platform/json.h" | 7 #include "platform/json.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 // Check if we get an exception when accessing beyond limit. | 803 // Check if we get an exception when accessing beyond limit. |
| 804 result = Dart_ListGetAt(ListAccessTestObj, 4); | 804 result = Dart_ListGetAt(ListAccessTestObj, 4); |
| 805 EXPECT(Dart_IsError(result)); | 805 EXPECT(Dart_IsError(result)); |
| 806 } | 806 } |
| 807 | 807 |
| 808 | 808 |
| 809 TEST_CASE(ByteArrayAccess) { | 809 TEST_CASE(ByteArrayAccess) { |
| 810 Dart_Handle byte_array1 = Dart_NewByteArray(10); | 810 Dart_Handle byte_array1 = Dart_NewByteArray(10); |
| 811 EXPECT_VALID(byte_array1); | 811 EXPECT_VALID(byte_array1); |
| 812 EXPECT(Dart_IsByteArray(byte_array1)); | 812 EXPECT(Dart_IsByteArray(byte_array1)); |
| 813 EXPECT(!Dart_IsByteArrayExternal(byte_array1)); |
| 813 EXPECT(Dart_IsList(byte_array1)); | 814 EXPECT(Dart_IsList(byte_array1)); |
| 814 | 815 |
| 815 intptr_t length = 0; | 816 intptr_t length = 0; |
| 816 Dart_Handle result = Dart_ListLength(byte_array1, &length); | 817 Dart_Handle result = Dart_ListLength(byte_array1, &length); |
| 817 EXPECT_VALID(result); | 818 EXPECT_VALID(result); |
| 818 EXPECT_EQ(10, length); | 819 EXPECT_EQ(10, length); |
| 819 | 820 |
| 820 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); | 821 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); |
| 821 EXPECT(Dart_IsError(result)); | 822 EXPECT(Dart_IsError(result)); |
| 822 result = Dart_ByteArraySetUint8At(byte_array1, -1, 1); | 823 result = Dart_ByteArraySetUint8At(byte_array1, -1, 1); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 | 1099 |
| 1099 TEST_CASE(ExternalByteArrayAccess) { | 1100 TEST_CASE(ExternalByteArrayAccess) { |
| 1100 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; | 1101 uint8_t data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; |
| 1101 intptr_t data_length = ARRAY_SIZE(data); | 1102 intptr_t data_length = ARRAY_SIZE(data); |
| 1102 | 1103 |
| 1103 Dart_Handle obj = Dart_NewExternalByteArray(data, data_length, NULL, NULL); | 1104 Dart_Handle obj = Dart_NewExternalByteArray(data, data_length, NULL, NULL); |
| 1104 EXPECT_VALID(obj); | 1105 EXPECT_VALID(obj); |
| 1105 EXPECT(Dart_IsByteArray(obj)); | 1106 EXPECT(Dart_IsByteArray(obj)); |
| 1107 EXPECT(Dart_IsByteArrayExternal(obj)); |
| 1106 EXPECT(Dart_IsList(obj)); | 1108 EXPECT(Dart_IsList(obj)); |
| 1107 | 1109 |
| 1110 void* raw_data = NULL; |
| 1111 EXPECT_VALID(Dart_ExternalByteArrayGetData(obj, &raw_data)); |
| 1112 EXPECT(raw_data == data); |
| 1113 |
| 1108 void* peer = &data; // just a non-NULL value | 1114 void* peer = &data; // just a non-NULL value |
| 1109 EXPECT_VALID(Dart_ExternalByteArrayGetPeer(obj, &peer)); | 1115 EXPECT_VALID(Dart_ExternalByteArrayGetPeer(obj, &peer)); |
| 1110 EXPECT(peer == NULL); | 1116 EXPECT(peer == NULL); |
| 1111 | 1117 |
| 1112 intptr_t list_length = 0; | 1118 intptr_t list_length = 0; |
| 1113 EXPECT_VALID(Dart_ListLength(obj, &list_length)); | 1119 EXPECT_VALID(Dart_ListLength(obj, &list_length)); |
| 1114 EXPECT_EQ(data_length, list_length); | 1120 EXPECT_EQ(data_length, list_length); |
| 1115 | 1121 |
| 1116 // Load and check values from underlying array and API. | 1122 // Load and check values from underlying array and API. |
| 1117 for (intptr_t i = 0; i < list_length; ++i) { | 1123 for (intptr_t i = 0; i < list_length; ++i) { |
| (...skipping 6064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7182 EXPECT(o2 == reinterpret_cast<void*>(&p2)); | 7188 EXPECT(o2 == reinterpret_cast<void*>(&p2)); |
| 7183 } | 7189 } |
| 7184 Dart_ExitScope(); | 7190 Dart_ExitScope(); |
| 7185 isolate->heap()->CollectGarbage(Heap::kOld); | 7191 isolate->heap()->CollectGarbage(Heap::kOld); |
| 7186 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7192 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
| 7187 } | 7193 } |
| 7188 | 7194 |
| 7189 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7195 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 7190 | 7196 |
| 7191 } // namespace dart | 7197 } // namespace dart |
| OLD | NEW |