Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 11280150: Add support for surrogates when serializing and deserializing for native ports (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use iterator reset Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/dart_api_message.cc » ('j') | runtime/vm/dart_api_message.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index ecc1df1ecd978bb81f3f82ded36f1f1e21b030ce..03030e95106697546e0b0ef6f6dea0623c185f74 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -550,6 +550,20 @@ TEST_CASE(IsString) {
}
+static void CheckToUTF8(Dart_Handle str,
+ intptr_t expected_len,
+ uint8_t* expected_utf8,
+ intptr_t expected_utf8_len) {
+ intptr_t len;
+ EXPECT_VALID(Dart_StringLength(str, &len));
+ EXPECT_EQ(expected_len, len);
+ uint8_t* utf8_out;
+ EXPECT_VALID(Dart_StringToUTF8(str, &utf8_out, &len));
+ EXPECT_EQ(expected_utf8_len, len);
+ EXPECT(!memcmp(expected_utf8, utf8_out, expected_utf8_len));
+}
+
+
TEST_CASE(NewString) {
const char* ascii = "string";
Dart_Handle ascii_str = NewString(ascii);
@@ -560,15 +574,74 @@ TEST_CASE(NewString) {
Dart_Handle null_str = NewString(null);
EXPECT(Dart_IsError(null_str));
- uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C.
- Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
- EXPECT_VALID(utf8_str);
- EXPECT(Dart_IsString(utf8_str));
+ {
+ uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C.
+ Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
+ EXPECT_VALID(utf8_str);
+ EXPECT(Dart_IsString(utf8_str));
+ CheckToUTF8(utf8_str, 1, data, sizeof(data));
+ }
+
+ {
+ uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C.
+ Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
+ EXPECT_VALID(utf8_str);
+ EXPECT(Dart_IsString(utf8_str));
+ CheckToUTF8(utf8_str, 1, data, sizeof(data));
+ }
siva 2012/11/28 18:22:46 This test and the one above seem to test identical
Søren Gjesse 2012/11/29 09:06:14 This is all reverted.
+
+ {
+ uint8_t data[] = {0xf0, 0x90, 0x80, 0x80, // U+10000.
+ 0xf0, 0x9f, 0x98, 0x81, // U+1F601.
+ 0xf0, 0x9f, 0x98, 0xb7, // U+1F637.
+ 0xf0, 0xa0, 0x80, 0x80}; // U+20000.
+ Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
+ EXPECT_VALID(utf8_str);
+ EXPECT(Dart_IsString(utf8_str));
+ CheckToUTF8(utf8_str, 8, data, sizeof(data));
+ }
+
+ {
+ uint8_t data[] = {0xed, 0xa0, 0x80}; // U+D800.
+ Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
+ EXPECT_VALID(utf8_str);
+ EXPECT(Dart_IsString(utf8_str));
+ CheckToUTF8(utf8_str, 1, data, sizeof(data));
+ }
+
+ {
+ uint8_t data[] = {0xed, 0xb0, 0x80}; // U+DC00.
+ Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
+ EXPECT_VALID(utf8_str);
+ EXPECT(Dart_IsString(utf8_str));
+ CheckToUTF8(utf8_str, 1, data, sizeof(data));
+ }
+
+ {
+ uint8_t data[] = {0xed, 0xa0, 0x80, // U+D800.
+ 0xed, 0xb0, 0x80}; // U+DC00.
+ Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
+ EXPECT_VALID(utf8_str);
+ EXPECT(Dart_IsString(utf8_str));
+ uint8_t expected_out[] = {0xf0, 0x90, 0x80, 0x80}; // U+10000.
+ CheckToUTF8(utf8_str, 2, expected_out, sizeof(expected_out));
+ }
- uint8_t invalid[] = { 0xE4, 0xBA }; // underflow.
- Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid,
- ARRAY_SIZE(invalid));
- EXPECT(Dart_IsError(invalid_str));
+ {
+ uint8_t data[] = {0xed, 0xb0, 0x80, // U+DC00.
+ 0xed, 0xa0, 0x80}; // U+D800.
+ Dart_Handle utf8_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
+ EXPECT_VALID(utf8_str);
+ EXPECT(Dart_IsString(utf8_str));
+ CheckToUTF8(utf8_str, 2, data, sizeof(data));
+ }
+
+ {
+ uint8_t invalid[] = { 0xE4, 0xBA }; // underflow.
+ Dart_Handle invalid_str = Dart_NewStringFromUTF8(invalid,
+ ARRAY_SIZE(invalid));
+ EXPECT(Dart_IsError(invalid_str));
+ }
}
« no previous file with comments | « no previous file | runtime/vm/dart_api_message.cc » ('j') | runtime/vm/dart_api_message.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698