| 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
| 8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 for (intptr_t i = 0; i < kSize; ++i) { | 1410 for (intptr_t i = 0; i < kSize; ++i) { |
| 1411 EXPECT_EQ(i & 0xff, data[i]); | 1411 EXPECT_EQ(i & 0xff, data[i]); |
| 1412 } | 1412 } |
| 1413 | 1413 |
| 1414 Dart_Handle result = Dart_ListGetAsBytes(view_obj, 0, data, kSize + 1); | 1414 Dart_Handle result = Dart_ListGetAsBytes(view_obj, 0, data, kSize + 1); |
| 1415 EXPECT(Dart_IsError(result)); | 1415 EXPECT(Dart_IsError(result)); |
| 1416 delete[] data; | 1416 delete[] data; |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 | 1419 |
| 1420 TEST_CASE(TypedDataViewListIsTypedData) { |
| 1421 const int kSize = 1000; |
| 1422 |
| 1423 const char* kScriptChars = |
| 1424 "import 'dart:typed_data';\n" |
| 1425 "List main(int size) {\n" |
| 1426 " var a = new Int8List(size);\n" |
| 1427 " var view = new Int8List.view(a.buffer, 0, size);\n" |
| 1428 " return view;\n" |
| 1429 "}\n"; |
| 1430 // Create a test library and Load up a test script in it. |
| 1431 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1432 |
| 1433 // Create a typed data view object. |
| 1434 Dart_Handle dart_args[1]; |
| 1435 dart_args[0] = Dart_NewInteger(kSize); |
| 1436 Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args); |
| 1437 EXPECT_VALID(view_obj); |
| 1438 // Test that the API considers it a TypedData object. |
| 1439 EXPECT(Dart_IsTypedData(view_obj)); |
| 1440 } |
| 1441 |
| 1442 |
| 1420 TEST_CASE(TypedDataAccess) { | 1443 TEST_CASE(TypedDataAccess) { |
| 1421 EXPECT_EQ(Dart_TypedData_kInvalid, | 1444 EXPECT_EQ(Dart_TypedData_kInvalid, |
| 1422 Dart_GetTypeOfTypedData(Dart_True())); | 1445 Dart_GetTypeOfTypedData(Dart_True())); |
| 1423 EXPECT_EQ(Dart_TypedData_kInvalid, | 1446 EXPECT_EQ(Dart_TypedData_kInvalid, |
| 1424 Dart_GetTypeOfExternalTypedData(Dart_False())); | 1447 Dart_GetTypeOfExternalTypedData(Dart_False())); |
| 1425 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); | 1448 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |
| 1426 EXPECT_VALID(byte_array1); | 1449 EXPECT_VALID(byte_array1); |
| 1427 EXPECT_EQ(Dart_TypedData_kUint8, | 1450 EXPECT_EQ(Dart_TypedData_kUint8, |
| 1428 Dart_GetTypeOfTypedData(byte_array1)); | 1451 Dart_GetTypeOfTypedData(byte_array1)); |
| 1429 EXPECT_EQ(Dart_TypedData_kInvalid, | 1452 EXPECT_EQ(Dart_TypedData_kInvalid, |
| (...skipping 7213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8643 NewString("main"), | 8666 NewString("main"), |
| 8644 1, | 8667 1, |
| 8645 dart_args); | 8668 dart_args); |
| 8646 int64_t value = 0; | 8669 int64_t value = 0; |
| 8647 result = Dart_IntegerToInt64(result, &value); | 8670 result = Dart_IntegerToInt64(result, &value); |
| 8648 EXPECT_VALID(result); | 8671 EXPECT_VALID(result); |
| 8649 EXPECT_EQ(6, value); | 8672 EXPECT_EQ(6, value); |
| 8650 } | 8673 } |
| 8651 | 8674 |
| 8652 } // namespace dart | 8675 } // namespace dart |
| OLD | NEW |