Index: runtime/vm/dart_api_impl_test.cc |
=================================================================== |
--- runtime/vm/dart_api_impl_test.cc (revision 25704) |
+++ runtime/vm/dart_api_impl_test.cc (working copy) |
@@ -832,6 +832,39 @@ |
} |
+TEST_CASE(TypedDataViewListGetAsBytes) { |
+ const int kSize = 1000; |
+ |
+ const char* kScriptChars = |
+ "import 'dart:typed_data';\n" |
+ "List main(int size) {\n" |
+ " var a = new Int8List(size);\n" |
+ " var view = new Int8List.view(a.buffer, 0, size);\n" |
+ " return view;\n" |
+ "}\n"; |
+ // Create a test library and Load up a test script in it. |
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
+ |
+ // Test with a typed data view object. |
+ Dart_Handle dart_args[1]; |
+ dart_args[0] = Dart_NewInteger(kSize); |
+ Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args); |
+ EXPECT_VALID(view_obj); |
+ for (intptr_t i = 0; i < kSize; ++i) { |
+ EXPECT_VALID(Dart_ListSetAt(view_obj, i, Dart_NewInteger(i & 0xff))); |
+ } |
+ uint8_t* data = new uint8_t[kSize]; |
+ EXPECT_VALID(Dart_ListGetAsBytes(view_obj, 0, data, kSize)); |
+ for (intptr_t i = 0; i < kSize; ++i) { |
+ EXPECT_EQ(i & 0xff, data[i]); |
+ } |
+ |
+ Dart_Handle result = Dart_ListGetAsBytes(view_obj, 0, data, kSize + 1); |
+ EXPECT(Dart_IsError(result)); |
+ delete[] data; |
+} |
+ |
+ |
TEST_CASE(TypedDataAccess) { |
EXPECT_EQ(Dart_TypedData_kInvalid, |
Dart_GetTypeOfTypedData(Dart_True())); |