Index: runtime/vm/dart_api_impl_test.cc |
=================================================================== |
--- runtime/vm/dart_api_impl_test.cc (revision 44897) |
+++ runtime/vm/dart_api_impl_test.cc (working copy) |
@@ -20,6 +20,7 @@ |
namespace dart { |
DECLARE_FLAG(bool, enable_type_checks); |
+DECLARE_FLAG(int, optimization_counter_threshold); |
DECLARE_FLAG(bool, verify_acquired_data); |
TEST_CASE(ErrorHandleBasics) { |
@@ -1742,6 +1743,74 @@ |
} |
+static const intptr_t kOptExtLength = 16; |
+static int8_t opt_data[kOptExtLength] = { 0x01, 0x02, 0x03, 0x04, |
+ 0x05, 0x06, 0x07, 0x08, |
+ 0x09, 0x0a, 0x0b, 0x0c, |
+ 0x0d, 0x0e, 0x0f, 0x10, }; |
+ |
+static void OptExternalByteDataNativeFunction(Dart_NativeArguments args) { |
+ Dart_EnterScope(); |
+ Dart_Handle external_byte_data = Dart_NewExternalTypedData( |
+ Dart_TypedData_kByteData, opt_data, 16); |
+ EXPECT_VALID(external_byte_data); |
+ EXPECT_EQ(Dart_TypedData_kByteData, |
+ Dart_GetTypeOfTypedData(external_byte_data)); |
+ Dart_SetReturnValue(args, external_byte_data); |
+ Dart_ExitScope(); |
+} |
+ |
+ |
+static Dart_NativeFunction OptExternalByteDataNativeResolver( |
+ Dart_Handle name, int arg_count, bool* auto_setup_scope) { |
+ ASSERT(auto_setup_scope != NULL); |
+ *auto_setup_scope = false; |
+ return &OptExternalByteDataNativeFunction; |
+} |
+ |
+ |
+TEST_CASE(OptimizedExternalByteDataAccess) { |
+ const char* kScriptChars = |
+ "import 'dart:typed_data';\n" |
+ "class Expect {\n" |
+ " static equals(a, b) {\n" |
+ " if (a != b) {\n" |
+ " throw 'not equal. expected: $a, got: $b';\n" |
+ " }\n" |
+ " }\n" |
+ "}\n" |
+ "ByteData createExternalByteData() native 'CreateExternalByteData';" |
+ "access(ByteData a) {" |
+ " Expect.equals(0x04030201, a.getUint32(0, Endianness.LITTLE_ENDIAN));" |
+ " Expect.equals(0x08070605, a.getUint32(4, Endianness.LITTLE_ENDIAN));" |
+ " Expect.equals(0x0c0b0a09, a.getUint32(8, Endianness.LITTLE_ENDIAN));" |
+ " Expect.equals(0x100f0e0d, a.getUint32(12, Endianness.LITTLE_ENDIAN));" |
+ "}" |
+ "ByteData main() {" |
+ " var length = 16;" |
+ " var a = createExternalByteData();" |
+ " Expect.equals(length, a.lengthInBytes);" |
+ " for (int i = 0; i < 20; i++) {" |
+ " access(a);" |
+ " }" |
+ " return a;" |
+ "}\n"; |
+ // Create a test library and Load up a test script in it. |
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
+ |
+ Dart_Handle result = Dart_SetNativeResolver( |
+ lib, &OptExternalByteDataNativeResolver, NULL); |
+ EXPECT_VALID(result); |
+ |
+ // Invoke 'main' function. |
+ int old_oct = FLAG_optimization_counter_threshold; |
+ FLAG_optimization_counter_threshold = 5; |
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
+ EXPECT_VALID(result); |
+ FLAG_optimization_counter_threshold = old_oct; |
+} |
+ |
+ |
static void TestTypedDataDirectAccess() { |
Dart_Handle str = Dart_NewStringFromCString("junk"); |
Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |