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

Unified Diff: vm/dart_api_impl_test.cc

Issue 11360114: - Add functionality to morph a string into an external string (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: 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 | « vm/dart_api_impl.cc ('k') | vm/object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/dart_api_impl_test.cc
===================================================================
--- vm/dart_api_impl_test.cc (revision 14977)
+++ vm/dart_api_impl_test.cc (working copy)
@@ -7200,6 +7200,152 @@
}
+// Test API call to make strings external.
+static void MakeExternalCback(void* peer) {
+ *static_cast<int*>(peer) *= 2;
+}
+
+
+TEST_CASE(MakeExternalString) {
+ int peer8 = 40;
+ int peer16 = 41;
+ intptr_t length = 0;
+ intptr_t expected_length = 0;
+ {
+ Dart_EnterScope();
+
+ // First test some negative conditions.
+ uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' };
+ const char* err = "string";
+ Dart_Handle err_str = NewString(err);
+ Dart_Handle ext_err_str = Dart_NewExternalUTF8String(
+ data8, ARRAY_SIZE(data8), NULL, NULL);
+ Dart_Handle result = Dart_MakeExternalString(Dart_Null(),
+ data8,
+ ARRAY_SIZE(data8),
+ NULL,
+ NULL);
+ EXPECT(Dart_IsError(result)); // Null string object passed in.
+ result = Dart_MakeExternalString(err_str,
+ NULL,
+ ARRAY_SIZE(data8),
+ NULL,
+ NULL);
+ EXPECT(Dart_IsError(result)); // Null array pointer passed in.
+ result = Dart_MakeExternalString(err_str,
+ data8,
+ 1,
+ NULL,
+ NULL);
+ EXPECT(Dart_IsError(result)); // Invalid length passed in.
+
+ const intptr_t kLength = 10;
+ intptr_t size = 0;
+
+ // Test with an external string.
+ result = Dart_MakeExternalString(ext_err_str,
+ data8,
+ ARRAY_SIZE(data8),
+ NULL,
+ NULL);
+ EXPECT(Dart_IsString(result));
+ EXPECT(Dart_IsExternalString(result));
+
+ // Test with an empty string.
+ Dart_Handle empty_str = NewString("");
+ EXPECT(Dart_IsString(empty_str));
+ EXPECT(!Dart_IsExternalString(empty_str));
+ uint8_t ext_empty_str[kLength];
+ Dart_Handle str = Dart_MakeExternalString(empty_str,
+ ext_empty_str,
+ kLength,
+ NULL,
+ NULL);
+ EXPECT(Dart_IsString(str));
+ EXPECT(Dart_IsString(empty_str));
+ EXPECT(Dart_IsAsciiString(str));
+ EXPECT(Dart_IsAsciiString(empty_str));
+ EXPECT(Dart_IsExternalString(str));
+ EXPECT(Dart_IsExternalString(empty_str));
+ EXPECT_VALID(Dart_StringLength(str, &length));
+ EXPECT_EQ(0, length);
+
+ // Test with a one byte ascii string.
+ const char* ascii = "string";
+ expected_length = strlen(ascii);
+ Dart_Handle ascii_str = NewString(ascii);
+ EXPECT_VALID(ascii_str);
+ EXPECT(Dart_IsString(ascii_str));
+ EXPECT(Dart_IsAsciiString(ascii_str));
+ EXPECT(!Dart_IsExternalString(ascii_str));
+ EXPECT_VALID(Dart_StringLength(ascii_str, &length));
+ EXPECT_EQ(expected_length, length);
+
+ uint8_t ext_ascii_str[kLength];
+ EXPECT_VALID(Dart_StringStorageSize(ascii_str, &size));
+ str = Dart_MakeExternalString(ascii_str,
+ ext_ascii_str,
+ size,
+ &peer8,
+ MakeExternalCback);
+ EXPECT(Dart_IsString(str));
+ EXPECT(Dart_IsString(ascii_str));
+ EXPECT(Dart_IsAsciiString(str));
+ EXPECT(Dart_IsAsciiString(ascii_str));
+ EXPECT(Dart_IsExternalString(str));
+ EXPECT(Dart_IsExternalString(ascii_str));
+ EXPECT_VALID(Dart_StringLength(str, &length));
+ EXPECT_EQ(expected_length, length);
+ EXPECT_VALID(Dart_StringLength(ascii_str, &length));
+ EXPECT_EQ(expected_length, length);
+ EXPECT(Dart_IdentityEquals(str, ascii_str));
+ for (intptr_t i = 0; i < length; i++) {
+ EXPECT_EQ(ascii[i], ext_ascii_str[i]);
+ }
+
+ uint8_t data[] = { 0xE4, 0xBA, 0x8c }; // U+4E8C.
+ expected_length = 1;
+ Dart_Handle utf16_str = Dart_NewStringFromUTF8(data, ARRAY_SIZE(data));
+ EXPECT_VALID(utf16_str);
+ EXPECT(Dart_IsString(utf16_str));
+ EXPECT(!Dart_IsAsciiString(utf16_str));
+ EXPECT(!Dart_IsExternalString(utf16_str));
+ EXPECT_VALID(Dart_StringLength(utf16_str, &length));
+ EXPECT_EQ(expected_length, length);
+
+ // Test with a two byte string.
+ uint16_t ext_utf16_str[kLength];
+ EXPECT_VALID(Dart_StringStorageSize(utf16_str, &size));
+ str = Dart_MakeExternalString(utf16_str,
+ ext_utf16_str,
+ size,
+ &peer16,
+ MakeExternalCback);
+ EXPECT(Dart_IsString(str));
+ EXPECT(Dart_IsString(utf16_str));
+ EXPECT(!Dart_IsAsciiString(str));
+ EXPECT(!Dart_IsAsciiString(utf16_str));
+ EXPECT(Dart_IsExternalString(str));
+ EXPECT(Dart_IsExternalString(utf16_str));
+ EXPECT_VALID(Dart_StringLength(str, &length));
+ EXPECT_EQ(expected_length, length);
+ EXPECT_VALID(Dart_StringLength(utf16_str, &length));
+ EXPECT_EQ(expected_length, length);
+ EXPECT(Dart_IdentityEquals(str, utf16_str));
+ for (intptr_t i = 0; i < length; i++) {
+ EXPECT_EQ(0x4e8c, ext_utf16_str[i]);
+ }
+
+ Dart_ExitScope();
+ }
+ EXPECT_EQ(40, peer8);
+ EXPECT_EQ(41, peer16);
+ Isolate::Current()->heap()->CollectGarbage(Heap::kNew);
+ EXPECT_EQ(80, peer8);
+ EXPECT_EQ(82, peer16);
+}
+
+
TEST_CASE(LazyLoadDeoptimizes) {
const char* kLoadFirst =
"start(a) {\n"
« no previous file with comments | « vm/dart_api_impl.cc ('k') | vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698