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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/utils.h" 7 #include "platform/utils.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 4527 matching lines...) Expand 10 before | Expand all | Expand 10 after
4538 EXPECT(Dart_IsLibrary(result)); 4538 EXPECT(Dart_IsLibrary(result));
4539 EXPECT(Dart_IdentityEquals(lib, result)); 4539 EXPECT(Dart_IdentityEquals(lib, result));
4540 4540
4541 // Language errors are detected. 4541 // Language errors are detected.
4542 source = Dart_NewString(kBadSourceChars); 4542 source = Dart_NewString(kBadSourceChars);
4543 result = Dart_LoadSource(lib, url, source); 4543 result = Dart_LoadSource(lib, url, source);
4544 EXPECT(Dart_IsError(result)); 4544 EXPECT(Dart_IsError(result));
4545 } 4545 }
4546 4546
4547 4547
4548 TEST_CASE(LoadSource_LateLoad) {
4549 const char* kLibrary1Chars =
4550 "#library('library1_name');\n"
4551 "class OldClass {\n"
4552 " foo() => 'foo';\n"
4553 "}\n";
4554 const char* kSourceChars =
4555 "class NewClass extends OldClass{\n"
4556 " bar() => 'bar';\n"
4557 "}\n";
4558 Dart_Handle url = Dart_NewString("library1_url");
4559 Dart_Handle source = Dart_NewString(kLibrary1Chars);
4560 Dart_Handle lib = Dart_LoadLibrary(url, source);
4561 EXPECT_VALID(lib);
4562 EXPECT(Dart_IsLibrary(lib));
4563
4564 // Call a dynamic function on OldClass.
4565 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("OldClass"));
4566 EXPECT_VALID(cls);
4567 Dart_Handle recv = Dart_New(cls, Dart_Null(), 0, NULL);
4568 Dart_Handle result = Dart_Invoke(recv, Dart_NewString("foo"), 0, NULL);
4569 EXPECT_VALID(result);
4570 EXPECT(Dart_IsString(result));
4571 const char* result_cstr = "";
4572 EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
4573 EXPECT_STREQ("foo", result_cstr);
4574
4575 // Load a source file late.
4576 url = Dart_NewString("source_url");
4577 source = Dart_NewString(kSourceChars);
4578 EXPECT_VALID(Dart_LoadSource(lib, url, source));
4579
4580 // Call a dynamic function on NewClass in the updated library.
4581 cls = Dart_GetClass(lib, Dart_NewString("NewClass"));
4582 EXPECT_VALID(cls);
4583 recv = Dart_New(cls, Dart_Null(), 0, NULL);
4584 result = Dart_Invoke(recv, Dart_NewString("bar"), 0, NULL);
4585 EXPECT_VALID(result);
4586 EXPECT(Dart_IsString(result));
4587 result_cstr = "";
4588 EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
4589 EXPECT_STREQ("bar", result_cstr);
4590 }
4591
4548 static void MyNativeFunction1(Dart_NativeArguments args) { 4592 static void MyNativeFunction1(Dart_NativeArguments args) {
4549 Dart_EnterScope(); 4593 Dart_EnterScope();
4550 Dart_SetReturnValue(args, Dart_NewInteger(654321)); 4594 Dart_SetReturnValue(args, Dart_NewInteger(654321));
4551 Dart_ExitScope(); 4595 Dart_ExitScope();
4552 } 4596 }
4553 4597
4554 4598
4555 static void MyNativeFunction2(Dart_NativeArguments args) { 4599 static void MyNativeFunction2(Dart_NativeArguments args) {
4556 Dart_EnterScope(); 4600 Dart_EnterScope();
4557 Dart_SetReturnValue(args, Dart_NewInteger(123456)); 4601 Dart_SetReturnValue(args, Dart_NewInteger(123456));
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
5474 EXPECT_VALID(result); 5518 EXPECT_VALID(result);
5475 EXPECT(Dart_IsInteger(result)); 5519 EXPECT(Dart_IsInteger(result));
5476 int64_t value = 0; 5520 int64_t value = 0;
5477 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); 5521 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
5478 EXPECT_EQ(0, value); 5522 EXPECT_EQ(0, value);
5479 } 5523 }
5480 5524
5481 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 5525 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
5482 5526
5483 } // namespace dart 5527 } // namespace dart
OLDNEW
« 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