Chromium Code Reviews| 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) {" |
|
ricow1
2013/08/01 16:29:50
add \n here and below
Florian Schneider
2013/08/02 11:07:33
Done.
Florian Schneider
2013/08/02 11:07:33
Done.
|
| + " var a = new Int8List(size);" |
| + " var view = new Int8List.view(a.buffer, 0, size);" |
| + " return view;" |
| + "}\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())); |