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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 10659015: Add a unit test which exercises using Dart_LoadSource to load a "late" (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
===================================================================
--- runtime/vm/dart_api_impl_test.cc (revision 9082)
+++ runtime/vm/dart_api_impl_test.cc (working copy)
@@ -4545,6 +4545,50 @@
}
+TEST_CASE(LoadSource_LateLoad) {
+ const char* kLibrary1Chars =
+ "#library('library1_name');\n"
+ "class OldClass {\n"
+ " foo() => 'foo';\n"
+ "}\n";
+ const char* kSourceChars =
+ "class NewClass extends OldClass{\n"
+ " bar() => 'bar';\n"
+ "}\n";
+ Dart_Handle url = Dart_NewString("library1_url");
+ Dart_Handle source = Dart_NewString(kLibrary1Chars);
+ Dart_Handle lib = Dart_LoadLibrary(url, source);
+ EXPECT_VALID(lib);
+ EXPECT(Dart_IsLibrary(lib));
+
+ // Call a dynamic function on OldClass.
+ Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("OldClass"));
+ EXPECT_VALID(cls);
+ Dart_Handle recv = Dart_New(cls, Dart_Null(), 0, NULL);
+ Dart_Handle result = Dart_Invoke(recv, Dart_NewString("foo"), 0, NULL);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsString(result));
+ const char* result_cstr = "";
+ EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
+ EXPECT_STREQ("foo", result_cstr);
+
+ // Load a source file late.
+ url = Dart_NewString("source_url");
+ source = Dart_NewString(kSourceChars);
+ EXPECT_VALID(Dart_LoadSource(lib, url, source));
+
+ // Call a dynamic function on NewClass in the updated library.
+ cls = Dart_GetClass(lib, Dart_NewString("NewClass"));
+ EXPECT_VALID(cls);
+ recv = Dart_New(cls, Dart_Null(), 0, NULL);
+ result = Dart_Invoke(recv, Dart_NewString("bar"), 0, NULL);
+ EXPECT_VALID(result);
+ EXPECT(Dart_IsString(result));
+ result_cstr = "";
+ EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
+ EXPECT_STREQ("bar", result_cstr);
+}
+
static void MyNativeFunction1(Dart_NativeArguments args) {
Dart_EnterScope();
Dart_SetReturnValue(args, Dart_NewInteger(654321));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698