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

Side by Side Diff: runtime/vm/dart_entry_test.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/dart_entry.cc ('k') | runtime/vm/datastream.h » ('j') | 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 "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
11 #include "vm/dart_entry.h" 11 #include "vm/dart_entry.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/resolver.h" 13 #include "vm/resolver.h"
14 #include "vm/symbols.h" 14 #include "vm/symbols.h"
15 #include "vm/unit_test.h" 15 #include "vm/unit_test.h"
16 16
17 namespace dart { 17 namespace dart {
18 18
19 TEST_CASE(DartEntry) { 19 TEST_CASE(DartEntry) {
20 const char* kScriptChars = 20 const char* kScriptChars =
21 "class A {\n" 21 "class A {\n"
22 " static foo() { return 42; }\n" 22 " static foo() { return 42; }\n"
23 "}\n"; 23 "}\n";
24 String& url = String::Handle(String::New("dart-test:DartEntry")); 24 String& url = String::Handle(String::New("dart-test:DartEntry"));
25 String& source = String::Handle(String::New(kScriptChars)); 25 String& source = String::Handle(String::New(kScriptChars));
26 Script& script = Script::Handle(Script::New(url, 26 Script& script =
27 source, 27 Script::Handle(Script::New(url, source, RawScript::kScriptTag));
28 RawScript::kScriptTag));
29 Library& lib = Library::Handle(Library::CoreLibrary()); 28 Library& lib = Library::Handle(Library::CoreLibrary());
30 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); 29 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
31 EXPECT(ClassFinalizer::ProcessPendingClasses()); 30 EXPECT(ClassFinalizer::ProcessPendingClasses());
32 Class& cls = Class::Handle( 31 Class& cls =
33 lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); 32 Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A"))));
34 EXPECT(!cls.IsNull()); // No ambiguity error expected. 33 EXPECT(!cls.IsNull()); // No ambiguity error expected.
35 String& name = String::Handle(String::New("foo")); 34 String& name = String::Handle(String::New("foo"));
36 Function& function = Function::Handle(cls.LookupStaticFunction(name)); 35 Function& function = Function::Handle(cls.LookupStaticFunction(name));
37 EXPECT(!function.IsNull()); 36 EXPECT(!function.IsNull());
38 37
39 EXPECT(CompilerTest::TestCompileFunction(function)); 38 EXPECT(CompilerTest::TestCompileFunction(function));
40 EXPECT(function.HasCode()); 39 EXPECT(function.HasCode());
41 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>( 40 const Smi& retval = Smi::Handle(reinterpret_cast<RawSmi*>(
42 DartEntry::InvokeFunction(function, Object::empty_array()))); 41 DartEntry::InvokeFunction(function, Object::empty_array())));
43 EXPECT_EQ(Smi::New(42), retval.raw()); 42 EXPECT_EQ(Smi::New(42), retval.raw());
44 } 43 }
45 44
46 45
47 TEST_CASE(InvokeStatic_CompileError) { 46 TEST_CASE(InvokeStatic_CompileError) {
48 const char* kScriptChars = 47 const char* kScriptChars =
49 "class A {\n" 48 "class A {\n"
50 " static foo() { return ++++; }\n" 49 " static foo() { return ++++; }\n"
51 "}\n"; 50 "}\n";
52 String& url = String::Handle(String::New("dart-test:DartEntry")); 51 String& url = String::Handle(String::New("dart-test:DartEntry"));
53 String& source = String::Handle(String::New(kScriptChars)); 52 String& source = String::Handle(String::New(kScriptChars));
54 Script& script = Script::Handle(Script::New(url, 53 Script& script =
55 source, 54 Script::Handle(Script::New(url, source, RawScript::kScriptTag));
56 RawScript::kScriptTag));
57 Library& lib = Library::Handle(Library::CoreLibrary()); 55 Library& lib = Library::Handle(Library::CoreLibrary());
58 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); 56 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
59 EXPECT(ClassFinalizer::ProcessPendingClasses()); 57 EXPECT(ClassFinalizer::ProcessPendingClasses());
60 Class& cls = Class::Handle( 58 Class& cls =
61 lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); 59 Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A"))));
62 EXPECT(!cls.IsNull()); // No ambiguity error expected. 60 EXPECT(!cls.IsNull()); // No ambiguity error expected.
63 String& name = String::Handle(String::New("foo")); 61 String& name = String::Handle(String::New("foo"));
64 Function& function = Function::Handle(cls.LookupStaticFunction(name)); 62 Function& function = Function::Handle(cls.LookupStaticFunction(name));
65 EXPECT(!function.IsNull()); 63 EXPECT(!function.IsNull());
66 const Object& retval = Object::Handle( 64 const Object& retval = Object::Handle(
67 DartEntry::InvokeFunction(function, Object::empty_array())); 65 DartEntry::InvokeFunction(function, Object::empty_array()));
68 EXPECT(retval.IsError()); 66 EXPECT(retval.IsError());
69 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); 67 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString());
70 } 68 }
71 69
72 70
73 TEST_CASE(InvokeDynamic_CompileError) { 71 TEST_CASE(InvokeDynamic_CompileError) {
74 const char* kScriptChars = 72 const char* kScriptChars =
75 "class A {\n" 73 "class A {\n"
76 " foo() { return ++++; }\n" 74 " foo() { return ++++; }\n"
77 "}\n"; 75 "}\n";
78 String& url = String::Handle(String::New("dart-test:DartEntry")); 76 String& url = String::Handle(String::New("dart-test:DartEntry"));
79 String& source = String::Handle(String::New(kScriptChars)); 77 String& source = String::Handle(String::New(kScriptChars));
80 Script& script = Script::Handle(Script::New(url, 78 Script& script =
81 source, 79 Script::Handle(Script::New(url, source, RawScript::kScriptTag));
82 RawScript::kScriptTag));
83 Library& lib = Library::Handle(Library::CoreLibrary()); 80 Library& lib = Library::Handle(Library::CoreLibrary());
84 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script)); 81 EXPECT_EQ(true, CompilerTest::TestCompileScript(lib, script));
85 EXPECT(ClassFinalizer::ProcessPendingClasses()); 82 EXPECT(ClassFinalizer::ProcessPendingClasses());
86 Class& cls = Class::Handle( 83 Class& cls =
87 lib.LookupClass(String::Handle(Symbols::New(thread, "A")))); 84 Class::Handle(lib.LookupClass(String::Handle(Symbols::New(thread, "A"))));
88 EXPECT(!cls.IsNull()); // No ambiguity error expected. 85 EXPECT(!cls.IsNull()); // No ambiguity error expected.
89 86
90 // Invoke the constructor. 87 // Invoke the constructor.
91 const Instance& instance = Instance::Handle(Instance::New(cls)); 88 const Instance& instance = Instance::Handle(Instance::New(cls));
92 const Array& constructor_arguments = Array::Handle(Array::New(1)); 89 const Array& constructor_arguments = Array::Handle(Array::New(1));
93 constructor_arguments.SetAt(0, instance); 90 constructor_arguments.SetAt(0, instance);
94 String& constructor_name = String::Handle(Symbols::New(thread, "A.")); 91 String& constructor_name = String::Handle(Symbols::New(thread, "A."));
95 Function& constructor = 92 Function& constructor =
96 Function::Handle(cls.LookupConstructor(constructor_name)); 93 Function::Handle(cls.LookupConstructor(constructor_name));
97 ASSERT(!constructor.IsNull()); 94 ASSERT(!constructor.IsNull());
98 DartEntry::InvokeFunction(constructor, constructor_arguments); 95 DartEntry::InvokeFunction(constructor, constructor_arguments);
99 96
100 // Call foo. 97 // Call foo.
101 String& name = String::Handle(String::New("foo")); 98 String& name = String::Handle(String::New("foo"));
102 Function& function = Function::Handle(cls.LookupDynamicFunction(name)); 99 Function& function = Function::Handle(cls.LookupDynamicFunction(name));
103 EXPECT(!function.IsNull()); 100 EXPECT(!function.IsNull());
104 const Array& args = Array::Handle(Array::New(1)); 101 const Array& args = Array::Handle(Array::New(1));
105 args.SetAt(0, instance); 102 args.SetAt(0, instance);
106 const Object& retval = Object::Handle(DartEntry::InvokeFunction(function, 103 const Object& retval =
107 args)); 104 Object::Handle(DartEntry::InvokeFunction(function, args));
108 EXPECT(retval.IsError()); 105 EXPECT(retval.IsError());
109 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString()); 106 EXPECT_SUBSTRING("++++", Error::Cast(retval).ToErrorCString());
110 } 107 }
111 108
112 } // namespace dart 109 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_entry.cc ('k') | runtime/vm/datastream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698