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 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 Dart_GetTypeOfTypedData(Dart_True())); | 1422 Dart_GetTypeOfTypedData(Dart_True())); |
1423 EXPECT_EQ(Dart_TypedData_kInvalid, | 1423 EXPECT_EQ(Dart_TypedData_kInvalid, |
1424 Dart_GetTypeOfExternalTypedData(Dart_False())); | 1424 Dart_GetTypeOfExternalTypedData(Dart_False())); |
1425 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); | 1425 Dart_Handle byte_array1 = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |
1426 EXPECT_VALID(byte_array1); | 1426 EXPECT_VALID(byte_array1); |
1427 EXPECT_EQ(Dart_TypedData_kUint8, | 1427 EXPECT_EQ(Dart_TypedData_kUint8, |
1428 Dart_GetTypeOfTypedData(byte_array1)); | 1428 Dart_GetTypeOfTypedData(byte_array1)); |
1429 EXPECT_EQ(Dart_TypedData_kInvalid, | 1429 EXPECT_EQ(Dart_TypedData_kInvalid, |
1430 Dart_GetTypeOfExternalTypedData(byte_array1)); | 1430 Dart_GetTypeOfExternalTypedData(byte_array1)); |
1431 EXPECT(Dart_IsList(byte_array1)); | 1431 EXPECT(Dart_IsList(byte_array1)); |
| 1432 EXPECT(!Dart_IsTypedData(Dart_True())); |
| 1433 EXPECT(Dart_IsTypedData(byte_array1)); |
| 1434 EXPECT(!Dart_IsByteBuffer(byte_array1)); |
1432 | 1435 |
1433 intptr_t length = 0; | 1436 intptr_t length = 0; |
1434 Dart_Handle result = Dart_ListLength(byte_array1, &length); | 1437 Dart_Handle result = Dart_ListLength(byte_array1, &length); |
1435 EXPECT_VALID(result); | 1438 EXPECT_VALID(result); |
1436 EXPECT_EQ(10, length); | 1439 EXPECT_EQ(10, length); |
1437 | 1440 |
1438 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); | 1441 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); |
1439 EXPECT(Dart_IsError(result)); | 1442 EXPECT(Dart_IsError(result)); |
1440 | 1443 |
1441 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); | 1444 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 for (intptr_t i = 0; i < 10; ++i) { | 1486 for (intptr_t i = 0; i < 10; ++i) { |
1484 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | 1487 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); |
1485 EXPECT_VALID(integer_obj); | 1488 EXPECT_VALID(integer_obj); |
1486 int64_t int64_t_value = -1; | 1489 int64_t int64_t_value = -1; |
1487 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | 1490 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); |
1488 EXPECT_EQ(10 - i, int64_t_value); | 1491 EXPECT_EQ(10 - i, int64_t_value); |
1489 } | 1492 } |
1490 } | 1493 } |
1491 | 1494 |
1492 | 1495 |
| 1496 TEST_CASE(ByteBufferAccess) { |
| 1497 EXPECT(!Dart_IsByteBuffer(Dart_True())); |
| 1498 Dart_Handle byte_array = Dart_NewTypedData(Dart_TypedData_kUint8, 10); |
| 1499 EXPECT_VALID(byte_array); |
| 1500 // Set through the List API. |
| 1501 for (intptr_t i = 0; i < 10; ++i) { |
| 1502 EXPECT_VALID(Dart_ListSetAt(byte_array, i, Dart_NewInteger(i + 1))); |
| 1503 } |
| 1504 Dart_Handle byte_buffer = Dart_NewByteBuffer(byte_array); |
| 1505 EXPECT_VALID(byte_buffer); |
| 1506 EXPECT(Dart_IsByteBuffer(byte_buffer)); |
| 1507 EXPECT(!Dart_IsTypedData(byte_buffer)); |
| 1508 |
| 1509 Dart_Handle byte_buffer_data = Dart_GetDataFromByteBuffer(byte_buffer); |
| 1510 EXPECT_VALID(byte_buffer_data); |
| 1511 EXPECT(!Dart_IsByteBuffer(byte_buffer_data)); |
| 1512 EXPECT(Dart_IsTypedData(byte_buffer_data)); |
| 1513 |
| 1514 intptr_t length = 0; |
| 1515 Dart_Handle result = Dart_ListLength(byte_buffer_data, &length); |
| 1516 EXPECT_VALID(result); |
| 1517 EXPECT_EQ(10, length); |
| 1518 |
| 1519 for (intptr_t i = 0; i < 10; ++i) { |
| 1520 // Get through the List API. |
| 1521 Dart_Handle integer_obj = Dart_ListGetAt(byte_buffer_data, i); |
| 1522 EXPECT_VALID(integer_obj); |
| 1523 int64_t int64_t_value = -1; |
| 1524 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); |
| 1525 EXPECT_EQ(i + 1, int64_t_value); |
| 1526 } |
| 1527 |
| 1528 // Some negative tests. |
| 1529 result = Dart_NewByteBuffer(Dart_True()); |
| 1530 EXPECT(Dart_IsError(result)); |
| 1531 result = Dart_NewByteBuffer(byte_buffer); |
| 1532 EXPECT(Dart_IsError(result)); |
| 1533 result = Dart_GetDataFromByteBuffer(Dart_False()); |
| 1534 EXPECT(Dart_IsError(result)); |
| 1535 result = Dart_GetDataFromByteBuffer(byte_array); |
| 1536 EXPECT(Dart_IsError(result)); |
| 1537 } |
| 1538 |
| 1539 |
1493 static int kLength = 16; | 1540 static int kLength = 16; |
1494 | 1541 |
1495 static void ByteDataNativeFunction(Dart_NativeArguments args) { | 1542 static void ByteDataNativeFunction(Dart_NativeArguments args) { |
1496 Dart_EnterScope(); | 1543 Dart_EnterScope(); |
1497 Dart_Handle byte_data = Dart_NewTypedData(Dart_TypedData_kByteData, kLength); | 1544 Dart_Handle byte_data = Dart_NewTypedData(Dart_TypedData_kByteData, kLength); |
1498 EXPECT_VALID(byte_data); | 1545 EXPECT_VALID(byte_data); |
1499 EXPECT_EQ(Dart_TypedData_kByteData, Dart_GetTypeOfTypedData(byte_data)); | 1546 EXPECT_EQ(Dart_TypedData_kByteData, Dart_GetTypeOfTypedData(byte_data)); |
1500 Dart_SetReturnValue(args, byte_data); | 1547 Dart_SetReturnValue(args, byte_data); |
1501 Dart_ExitScope(); | 1548 Dart_ExitScope(); |
1502 } | 1549 } |
(...skipping 7009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8512 NewString("main"), | 8559 NewString("main"), |
8513 1, | 8560 1, |
8514 dart_args); | 8561 dart_args); |
8515 int64_t value = 0; | 8562 int64_t value = 0; |
8516 result = Dart_IntegerToInt64(result, &value); | 8563 result = Dart_IntegerToInt64(result, &value); |
8517 EXPECT_VALID(result); | 8564 EXPECT_VALID(result); |
8518 EXPECT_EQ(6, value); | 8565 EXPECT_EQ(6, value); |
8519 } | 8566 } |
8520 | 8567 |
8521 } // namespace dart | 8568 } // namespace dart |
OLD | NEW |