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

Side by Side Diff: vm/object_test.cc

Issue 10827249: - Register canonical names for internal VM classes and get rid of the method GetSingletonClassName (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 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 | « vm/object_store.cc ('k') | vm/parser.cc » ('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/assert.h" 5 #include "platform/assert.h"
6 #include "vm/assembler.h" 6 #include "vm/assembler.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
11 #include "vm/symbols.h" 11 #include "vm/symbols.h"
12 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 TEST_CASE(Class) { 16 TEST_CASE(Class) {
17 // Allocate the class first. 17 // Allocate the class first.
18 const String& class_name = String::Handle(Symbols::New("MyClass")); 18 const String& class_name = String::Handle(Symbols::New("MyClass"));
19 const Script& script = Script::Handle(); 19 const Script& script = Script::Handle();
20 const Class& cls = Class::Handle( 20 const Class& cls = Class::Handle(
21 Class::New(class_name, script, Scanner::kDummyTokenIndex)); 21 Class::New(class_name, script, Scanner::kDummyTokenIndex));
22 22
23 // Class has no fields. 23 // Class has no fields.
24 const Array& no_fields = Array::Handle(Array::Empty()); 24 const Array& no_fields = Array::Handle(Object::empty_array());
25 cls.SetFields(no_fields); 25 cls.SetFields(no_fields);
26 26
27 // Create and populate the function arrays. 27 // Create and populate the function arrays.
28 const Array& functions = Array::Handle(Array::New(6)); 28 const Array& functions = Array::Handle(Array::New(6));
29 Function& function = Function::Handle(); 29 Function& function = Function::Handle();
30 String& function_name = String::Handle(); 30 String& function_name = String::Handle();
31 function_name = Symbols::New("foo"); 31 function_name = Symbols::New("foo");
32 function = Function::New( 32 function = Function::New(
33 function_name, RawFunction::kRegularFunction, 33 function_name, RawFunction::kRegularFunction,
34 false, false, false, false, cls, 0); 34 false, false, false, false, cls, 0);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 String& interface_name = String::Handle(); 104 String& interface_name = String::Handle();
105 interface_name = Symbols::New("Harley"); 105 interface_name = Symbols::New("Harley");
106 interface = Class::New(interface_name, script, Scanner::kDummyTokenIndex); 106 interface = Class::New(interface_name, script, Scanner::kDummyTokenIndex);
107 interfaces.SetAt(0, Type::Handle(Type::NewNonParameterizedType(interface))); 107 interfaces.SetAt(0, Type::Handle(Type::NewNonParameterizedType(interface)));
108 interface_name = Symbols::New("Norton"); 108 interface_name = Symbols::New("Norton");
109 interface = Class::New(interface_name, script, Scanner::kDummyTokenIndex); 109 interface = Class::New(interface_name, script, Scanner::kDummyTokenIndex);
110 interfaces.SetAt(1, Type::Handle(Type::NewNonParameterizedType(interface))); 110 interfaces.SetAt(1, Type::Handle(Type::NewNonParameterizedType(interface)));
111 cls.set_interfaces(interfaces); 111 cls.set_interfaces(interfaces);
112 cls.Finalize(); 112 cls.Finalize();
113 113
114 ASSERT(cls.functions_cache() == Array::null());
115 cls.InitFunctionsCache();
114 const Array& array = Array::Handle(cls.functions_cache()); 116 const Array& array = Array::Handle(cls.functions_cache());
115 array.SetAt(0, function_name); 117 array.SetAt(0, function_name);
116 cls.set_functions_cache(array); 118 cls.set_functions_cache(array);
117 String& test_name = String::Handle(); 119 String& test_name = String::Handle();
118 test_name ^= Array::Handle(cls.functions_cache()).At(0); 120 test_name ^= Array::Handle(cls.functions_cache()).At(0);
119 EXPECT(test_name.Equals(function_name)); 121 EXPECT(test_name.Equals(function_name));
120 } 122 }
121 123
122 124
123 TEST_CASE(TypeArguments) { 125 TEST_CASE(TypeArguments) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 167
166 168
167 TEST_CASE(InstanceClass) { 169 TEST_CASE(InstanceClass) {
168 // Allocate the class first. 170 // Allocate the class first.
169 String& class_name = String::Handle(Symbols::New("EmptyClass")); 171 String& class_name = String::Handle(Symbols::New("EmptyClass"));
170 Script& script = Script::Handle(); 172 Script& script = Script::Handle();
171 const Class& empty_class = 173 const Class& empty_class =
172 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); 174 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex));
173 175
174 // No functions and no super class for the EmptyClass. 176 // No functions and no super class for the EmptyClass.
175 const Array& no_fields = Array::Handle(Array::Empty()); 177 const Array& no_fields = Array::Handle(Object::empty_array());
176 empty_class.SetFields(no_fields); 178 empty_class.SetFields(no_fields);
177 empty_class.Finalize(); 179 empty_class.Finalize();
178 EXPECT_EQ(kObjectAlignment, empty_class.instance_size()); 180 EXPECT_EQ(kObjectAlignment, empty_class.instance_size());
179 Instance& instance = Instance::Handle(Instance::New(empty_class)); 181 Instance& instance = Instance::Handle(Instance::New(empty_class));
180 EXPECT_EQ(empty_class.raw(), instance.clazz()); 182 EXPECT_EQ(empty_class.raw(), instance.clazz());
181 183
182 class_name = Symbols::New("OneFieldClass"); 184 class_name = Symbols::New("OneFieldClass");
183 const Class& one_field_class = 185 const Class& one_field_class =
184 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); 186 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex));
185 187
(...skipping 10 matching lines...) Expand all
196 one_field_class.instance_size()); 198 one_field_class.instance_size());
197 EXPECT_EQ(header_size, field.Offset()); 199 EXPECT_EQ(header_size, field.Offset());
198 } 200 }
199 201
200 202
201 TEST_CASE(Interface) { 203 TEST_CASE(Interface) {
202 String& class_name = String::Handle(Symbols::New("EmptyClass")); 204 String& class_name = String::Handle(Symbols::New("EmptyClass"));
203 Script& script = Script::Handle(); 205 Script& script = Script::Handle();
204 const Class& factory_class = 206 const Class& factory_class =
205 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); 207 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex));
206 const Array& no_fields = Array::Handle(Array::Empty()); 208 const Array& no_fields = Array::Handle(Object::empty_array());
207 // Finalizes the class. 209 // Finalizes the class.
208 factory_class.SetFields(no_fields); 210 factory_class.SetFields(no_fields);
209 211
210 String& interface_name = String::Handle(Symbols::New("MyInterface")); 212 String& interface_name = String::Handle(Symbols::New("MyInterface"));
211 const Class& interface = Class::Handle( 213 const Class& interface = Class::Handle(
212 Class::NewInterface(interface_name, script, Scanner::kDummyTokenIndex)); 214 Class::NewInterface(interface_name, script, Scanner::kDummyTokenIndex));
213 EXPECT(interface.is_interface()); 215 EXPECT(interface.is_interface());
214 EXPECT(!factory_class.is_interface()); 216 EXPECT(!factory_class.is_interface());
215 EXPECT(!interface.HasFactoryClass()); 217 EXPECT(!interface.HasFactoryClass());
216 interface.set_factory_class(factory_class); 218 interface.set_factory_class(factory_class);
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1758 EXPECT(array.Equals(other_array)); 1760 EXPECT(array.Equals(other_array));
1759 1761
1760 other_array.SetAt(1, other_array); 1762 other_array.SetAt(1, other_array);
1761 EXPECT(!array.Equals(other_array)); 1763 EXPECT(!array.Equals(other_array));
1762 1764
1763 other_array = Array::New(kArrayLen - 1); 1765 other_array = Array::New(kArrayLen - 1);
1764 other_array.SetAt(0, array); 1766 other_array.SetAt(0, array);
1765 other_array.SetAt(2, array); 1767 other_array.SetAt(2, array);
1766 EXPECT(!array.Equals(other_array)); 1768 EXPECT(!array.Equals(other_array));
1767 1769
1768 EXPECT_EQ(0, Array::Handle(Array::Empty()).Length()); 1770 EXPECT_EQ(0, Array::Handle(Object::empty_array()).Length());
1769 } 1771 }
1770 1772
1771 1773
1772 TEST_CASE(GrowableObjectArray) { 1774 TEST_CASE(GrowableObjectArray) {
1773 const int kArrayLen = 5; 1775 const int kArrayLen = 5;
1774 Smi& value = Smi::Handle(); 1776 Smi& value = Smi::Handle();
1775 Smi& expected_value = Smi::Handle(); 1777 Smi& expected_value = Smi::Handle();
1776 GrowableObjectArray& array = GrowableObjectArray::Handle(); 1778 GrowableObjectArray& array = GrowableObjectArray::Handle();
1777 1779
1778 // Test basic growing functionality. 1780 // Test basic growing functionality.
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2865 "#6 MyClass.foo (dart:test-lib:32:14)\n" 2867 "#6 MyClass.foo (dart:test-lib:32:14)\n"
2866 "#7 MyClass.MyClass.<anonymous closure> (dart:test-lib:21:15)\n" 2868 "#7 MyClass.MyClass.<anonymous closure> (dart:test-lib:21:15)\n"
2867 "#8 MyClass.MyClass (dart:test-lib:21:18)\n" 2869 "#8 MyClass.MyClass (dart:test-lib:21:18)\n"
2868 "#9 main.<anonymous closure> (dart:test-lib:37:10)\n" 2870 "#9 main.<anonymous closure> (dart:test-lib:37:10)\n"
2869 "#10 main (dart:test-lib:37:24)"); 2871 "#10 main (dart:test-lib:37:24)");
2870 } 2872 }
2871 2873
2872 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 2874 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
2873 2875
2874 } // namespace dart 2876 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object_store.cc ('k') | vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698