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 8705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8716 Dart_Handle result = Dart_Invoke(lib, | 8716 Dart_Handle result = Dart_Invoke(lib, |
8717 NewString("main"), | 8717 NewString("main"), |
8718 1, | 8718 1, |
8719 dart_args); | 8719 dart_args); |
8720 int64_t value = 0; | 8720 int64_t value = 0; |
8721 result = Dart_IntegerToInt64(result, &value); | 8721 result = Dart_IntegerToInt64(result, &value); |
8722 EXPECT_VALID(result); | 8722 EXPECT_VALID(result); |
8723 EXPECT_EQ(6, value); | 8723 EXPECT_EQ(6, value); |
8724 } | 8724 } |
8725 | 8725 |
| 8726 TEST_CASE(StringFromExternalTypedData) { |
| 8727 const char* kScriptChars = |
| 8728 "test(external) {\n" |
| 8729 " var str1 = new String.fromCharCodes(external);\n" |
| 8730 " var str2 = new String.fromCharCodes(new List.from(external));\n" |
| 8731 " if (str2 != str1) throw 'FAIL';\n" |
| 8732 " return str1;\n" |
| 8733 "}\n" |
| 8734 "testView8(external) {\n" |
| 8735 " return test(external.buffer.asUint8List());\n" |
| 8736 "}\n" |
| 8737 "testView16(external) {\n" |
| 8738 " return test(external.buffer.asUint16List());\n" |
| 8739 "}\n"; |
| 8740 Dart_Handle lib = |
| 8741 TestCase::LoadTestScript(kScriptChars, NULL); |
| 8742 |
| 8743 { |
| 8744 uint8_t data[64]; |
| 8745 for (int i = 0; i < 64; i++) { |
| 8746 data[i] = i * 4; |
| 8747 } |
| 8748 // LATIN-1 in external Uint8List. |
| 8749 Dart_Handle external = Dart_NewExternalTypedData( |
| 8750 Dart_TypedData_kUint8, data, 64); |
| 8751 EXPECT_VALID(external); |
| 8752 Dart_Handle dart_args[1]; |
| 8753 dart_args[0] = external; |
| 8754 Dart_Handle result = Dart_Invoke(lib, |
| 8755 NewString("test"), |
| 8756 1, |
| 8757 dart_args); |
| 8758 EXPECT_VALID(result); |
| 8759 EXPECT(Dart_IsString(result)); |
| 8760 |
| 8761 result = Dart_Invoke(lib, |
| 8762 NewString("testView8"), |
| 8763 1, |
| 8764 dart_args); |
| 8765 EXPECT_VALID(result); |
| 8766 EXPECT(Dart_IsString(result)); |
| 8767 } |
| 8768 |
| 8769 { |
| 8770 uint16_t data[64]; |
| 8771 for (int i = 0; i < 64; i++) { |
| 8772 data[i] = i * 4; |
| 8773 } |
| 8774 // LATIN-1 in external Uint16List. |
| 8775 Dart_Handle external = Dart_NewExternalTypedData( |
| 8776 Dart_TypedData_kUint16, data, 64); |
| 8777 EXPECT_VALID(external); |
| 8778 Dart_Handle dart_args[1]; |
| 8779 dart_args[0] = external; |
| 8780 Dart_Handle result = Dart_Invoke(lib, |
| 8781 NewString("test"), |
| 8782 1, |
| 8783 dart_args); |
| 8784 EXPECT_VALID(result); |
| 8785 EXPECT(Dart_IsString(result)); |
| 8786 |
| 8787 result = Dart_Invoke(lib, |
| 8788 NewString("testView16"), |
| 8789 1, |
| 8790 dart_args); |
| 8791 EXPECT_VALID(result); |
| 8792 EXPECT(Dart_IsString(result)); |
| 8793 } |
| 8794 |
| 8795 { |
| 8796 uint16_t data[64]; |
| 8797 for (int i = 0; i < 64; i++) { |
| 8798 data[i] = 0x2000 + i * 4; |
| 8799 } |
| 8800 // Non-LATIN-1 in external Uint16List. |
| 8801 Dart_Handle external = Dart_NewExternalTypedData( |
| 8802 Dart_TypedData_kUint16, data, 64); |
| 8803 EXPECT_VALID(external); |
| 8804 Dart_Handle dart_args[1]; |
| 8805 dart_args[0] = external; |
| 8806 Dart_Handle result = Dart_Invoke(lib, |
| 8807 NewString("test"), |
| 8808 1, |
| 8809 dart_args); |
| 8810 EXPECT_VALID(result); |
| 8811 EXPECT(Dart_IsString(result)); |
| 8812 |
| 8813 result = Dart_Invoke(lib, |
| 8814 NewString("testView16"), |
| 8815 1, |
| 8816 dart_args); |
| 8817 EXPECT_VALID(result); |
| 8818 EXPECT(Dart_IsString(result)); |
| 8819 } |
| 8820 } |
| 8821 |
8726 } // namespace dart | 8822 } // namespace dart |
OLD | NEW |