| 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_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 EXPECT(Dart_IsString(utf8_str)); | 1100 EXPECT(Dart_IsString(utf8_str)); |
| 1101 | 1101 |
| 1102 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. | 1102 uint8_t invalid[] = { 0xE4, 0xBA }; // underflow. |
| 1103 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, | 1103 Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid, |
| 1104 ARRAY_SIZE(invalid)); | 1104 ARRAY_SIZE(invalid)); |
| 1105 EXPECT(Dart_IsError(invalid_str)); | 1105 EXPECT(Dart_IsError(invalid_str)); |
| 1106 } | 1106 } |
| 1107 | 1107 |
| 1108 | 1108 |
| 1109 TEST_CASE(MalformedStringToUTF8) { | 1109 TEST_CASE(MalformedStringToUTF8) { |
| 1110 // 1D11E = treble clef | |
| 1111 // [0] should be high surrogate D834 | |
| 1112 // [1] should be low surrogate DD1E | |
| 1113 // Strings are allowed to have individual or out of order surrogates, even | |
| 1114 // if that doesn't make sense as renderable characters. | |
| 1115 const char* kScriptChars = | 1110 const char* kScriptChars = |
| 1116 "String lowSurrogate() {" | 1111 "String testMain() {" |
| 1117 " return '\\u{1D11E}'[1];" | 1112 " return '\\u{1D11E}'[1];" |
| 1118 "}" | 1113 "}"; |
| 1119 "String highSurrogate() {" | |
| 1120 " return '\\u{1D11E}'[0];" | |
| 1121 "}" | |
| 1122 "String reversed() => lowSurrogate() + highSurrogate();"; | |
| 1123 | 1114 |
| 1124 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1115 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1125 Dart_Handle str1 = Dart_Invoke(lib, NewString("lowSurrogate"), 0, NULL); | 1116 Dart_Handle str1 = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 1126 EXPECT_VALID(str1); | 1117 EXPECT_VALID(str1); |
| 1127 | 1118 |
| 1128 uint8_t* utf8_encoded = NULL; | 1119 uint8_t* utf8_encoded = NULL; |
| 1129 intptr_t utf8_length = 0; | 1120 intptr_t utf8_length = 0; |
| 1130 Dart_Handle result = Dart_StringToUTF8(str1, &utf8_encoded, &utf8_length); | 1121 Dart_Handle result = Dart_StringToUTF8(str1, &utf8_encoded, &utf8_length); |
| 1131 EXPECT_VALID(result); | 1122 EXPECT_VALID(result); |
| 1132 EXPECT_EQ(3, utf8_length); | 1123 EXPECT_EQ(3, utf8_length); |
| 1133 EXPECT_EQ(237, static_cast<intptr_t>(utf8_encoded[0])); | 1124 EXPECT_EQ(237, static_cast<intptr_t>(utf8_encoded[0])); |
| 1134 EXPECT_EQ(180, static_cast<intptr_t>(utf8_encoded[1])); | 1125 EXPECT_EQ(180, static_cast<intptr_t>(utf8_encoded[1])); |
| 1135 EXPECT_EQ(158, static_cast<intptr_t>(utf8_encoded[2])); | 1126 EXPECT_EQ(158, static_cast<intptr_t>(utf8_encoded[2])); |
| 1136 | 1127 |
| 1137 Dart_Handle str2 = Dart_NewStringFromUTF8(utf8_encoded, utf8_length); | 1128 Dart_Handle str2 = Dart_NewStringFromUTF8(utf8_encoded, utf8_length); |
| 1138 EXPECT_VALID(str2); // Standalone low surrogate, but still valid | 1129 EXPECT(Dart_IsError(str2)); // Invalid UTF-8. |
| 1139 | |
| 1140 Dart_Handle reversed = Dart_Invoke(lib, NewString("reversed"), 0, NULL); | |
| 1141 EXPECT_VALID(reversed); // This is also allowed. | |
| 1142 uint8_t* utf8_encoded_reversed = NULL; | |
| 1143 intptr_t utf8_length_reversed = 0; | |
| 1144 result = Dart_StringToUTF8(reversed, | |
| 1145 &utf8_encoded_reversed, &utf8_length_reversed); | |
| 1146 EXPECT_VALID(result); | |
| 1147 EXPECT_EQ(6, utf8_length_reversed); | |
| 1148 uint8_t expected[6] = {237, 180, 158, 237, 160, 180}; | |
| 1149 for (int i = 0; i < 6; i++) { | |
| 1150 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); | |
| 1151 } | |
| 1152 } | 1130 } |
| 1153 | 1131 |
| 1154 | 1132 |
| 1155 static void ExternalStringCallbackFinalizer(void* peer) { | 1133 static void ExternalStringCallbackFinalizer(void* peer) { |
| 1156 *static_cast<int*>(peer) *= 2; | 1134 *static_cast<int*>(peer) *= 2; |
| 1157 } | 1135 } |
| 1158 | 1136 |
| 1159 | 1137 |
| 1160 TEST_CASE(ExternalStringCallback) { | 1138 TEST_CASE(ExternalStringCallback) { |
| 1161 int peer8 = 40; | 1139 int peer8 = 40; |
| (...skipping 8271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9433 // Heartbeat test. | 9411 // Heartbeat test. |
| 9434 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9412 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
| 9435 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9413 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
| 9436 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9414 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
| 9437 | 9415 |
| 9438 // Free buffer allocated by AppendStreamConsumer | 9416 // Free buffer allocated by AppendStreamConsumer |
| 9439 free(data.buffer); | 9417 free(data.buffer); |
| 9440 } | 9418 } |
| 9441 | 9419 |
| 9442 } // namespace dart | 9420 } // namespace dart |
| OLD | NEW |