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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 864463002: Create string efficiently from Uint16List/View. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests for external typed-data Created 5 years, 11 months 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 | « runtime/vm/bootstrap_natives.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »
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 402257b0cb8ea672ef1ef6e245193577f585532b..71609aa160be346448b09e5921b4c87d18d5a25a 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -8723,4 +8723,100 @@ TEST_CASE(ExternalStringIndexOf) {
EXPECT_EQ(6, value);
}
+TEST_CASE(StringFromExternalTypedData) {
+ const char* kScriptChars =
+ "test(external) {\n"
+ " var str1 = new String.fromCharCodes(external);\n"
+ " var str2 = new String.fromCharCodes(new List.from(external));\n"
+ " if (str2 != str1) throw 'FAIL';\n"
+ " return str1;\n"
+ "}\n"
+ "testView8(external) {\n"
+ " return test(external.buffer.asUint8List());\n"
+ "}\n"
+ "testView16(external) {\n"
+ " return test(external.buffer.asUint16List());\n"
+ "}\n";
+ Dart_Handle lib =
+ TestCase::LoadTestScript(kScriptChars, NULL);
+
+ {
+ uint8_t data[64];
+ for (int i = 0; i < 64; i++) {
+ data[i] = i * 4;
+ }
+ // LATIN-1 in external Uint8List.
+ Dart_Handle external = Dart_NewExternalTypedData(
+ Dart_TypedData_kUint8, data, 64);
+ EXPECT_VALID(external);
+ Dart_Handle dart_args[1];
+ dart_args[0] = external;
+ Dart_Handle result = Dart_Invoke(lib,
+ NewString("test"),
+ 1,
+ dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsString(result));
+
+ result = Dart_Invoke(lib,
+ NewString("testView8"),
+ 1,
+ dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsString(result));
+ }
+
+ {
+ uint16_t data[64];
+ for (int i = 0; i < 64; i++) {
+ data[i] = i * 4;
+ }
+ // LATIN-1 in external Uint16List.
+ Dart_Handle external = Dart_NewExternalTypedData(
+ Dart_TypedData_kUint16, data, 64);
+ EXPECT_VALID(external);
+ Dart_Handle dart_args[1];
+ dart_args[0] = external;
+ Dart_Handle result = Dart_Invoke(lib,
+ NewString("test"),
+ 1,
+ dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsString(result));
+
+ result = Dart_Invoke(lib,
+ NewString("testView16"),
+ 1,
+ dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsString(result));
+ }
+
+ {
+ uint16_t data[64];
+ for (int i = 0; i < 64; i++) {
+ data[i] = 0x2000 + i * 4;
+ }
+ // Non-LATIN-1 in external Uint16List.
+ Dart_Handle external = Dart_NewExternalTypedData(
+ Dart_TypedData_kUint16, data, 64);
+ EXPECT_VALID(external);
+ Dart_Handle dart_args[1];
+ dart_args[0] = external;
+ Dart_Handle result = Dart_Invoke(lib,
+ NewString("test"),
+ 1,
+ dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsString(result));
+
+ result = Dart_Invoke(lib,
+ NewString("testView16"),
+ 1,
+ dart_args);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsString(result));
+ }
+}
+
} // namespace dart
« no previous file with comments | « runtime/vm/bootstrap_natives.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698