| OLD | NEW |
| 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/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| 11 #include "vm/object_store.h" | 11 #include "vm/object_store.h" |
| 12 #include "vm/symbols.h" | 12 #include "vm/symbols.h" |
| 13 #include "vm/unit_test.h" | 13 #include "vm/unit_test.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 TEST_CASE(Class) { | 17 TEST_CASE(Class) { |
| 18 // Allocate the class first. | 18 // Allocate the class first. |
| 19 const String& class_name = String::Handle(Symbols::New("MyClass")); | 19 const String& class_name = String::Handle(Symbols::New("MyClass")); |
| 20 const Script& script = Script::Handle(); | 20 const Script& script = Script::Handle(); |
| 21 const Class& cls = Class::Handle( | 21 const Class& cls = Class::Handle( |
| 22 Class::New(class_name, script, Scanner::kDummyTokenIndex)); | 22 Class::New(class_name, script, Scanner::kDummyTokenIndex)); |
| 23 | 23 |
| 24 // Class has no fields. | 24 // Class has no fields. |
| 25 const Array& no_fields = Array::Handle(Object::empty_array()); | 25 cls.SetFields(Object::empty_array()); |
| 26 cls.SetFields(no_fields); | |
| 27 | 26 |
| 28 // Create and populate the function arrays. | 27 // Create and populate the function arrays. |
| 29 const Array& functions = Array::Handle(Array::New(6)); | 28 const Array& functions = Array::Handle(Array::New(6)); |
| 30 Function& function = Function::Handle(); | 29 Function& function = Function::Handle(); |
| 31 String& function_name = String::Handle(); | 30 String& function_name = String::Handle(); |
| 32 function_name = Symbols::New("foo"); | 31 function_name = Symbols::New("foo"); |
| 33 function = Function::New( | 32 function = Function::New( |
| 34 function_name, RawFunction::kRegularFunction, | 33 function_name, RawFunction::kRegularFunction, |
| 35 false, false, false, false, cls, 0); | 34 false, false, false, false, cls, 0); |
| 36 functions.SetAt(0, function); | 35 functions.SetAt(0, function); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 160 |
| 162 | 161 |
| 163 TEST_CASE(InstanceClass) { | 162 TEST_CASE(InstanceClass) { |
| 164 // Allocate the class first. | 163 // Allocate the class first. |
| 165 String& class_name = String::Handle(Symbols::New("EmptyClass")); | 164 String& class_name = String::Handle(Symbols::New("EmptyClass")); |
| 166 Script& script = Script::Handle(); | 165 Script& script = Script::Handle(); |
| 167 const Class& empty_class = | 166 const Class& empty_class = |
| 168 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); | 167 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); |
| 169 | 168 |
| 170 // No functions and no super class for the EmptyClass. | 169 // No functions and no super class for the EmptyClass. |
| 171 const Array& no_fields = Array::Handle(Object::empty_array()); | 170 empty_class.SetFields(Object::empty_array()); |
| 172 empty_class.SetFields(no_fields); | |
| 173 empty_class.Finalize(); | 171 empty_class.Finalize(); |
| 174 EXPECT_EQ(kObjectAlignment, empty_class.instance_size()); | 172 EXPECT_EQ(kObjectAlignment, empty_class.instance_size()); |
| 175 Instance& instance = Instance::Handle(Instance::New(empty_class)); | 173 Instance& instance = Instance::Handle(Instance::New(empty_class)); |
| 176 EXPECT_EQ(empty_class.raw(), instance.clazz()); | 174 EXPECT_EQ(empty_class.raw(), instance.clazz()); |
| 177 | 175 |
| 178 class_name = Symbols::New("OneFieldClass"); | 176 class_name = Symbols::New("OneFieldClass"); |
| 179 const Class& one_field_class = | 177 const Class& one_field_class = |
| 180 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); | 178 Class::Handle(Class::New(class_name, script, Scanner::kDummyTokenIndex)); |
| 181 | 179 |
| 182 // No functions and no super class for the OneFieldClass. | 180 // No functions and no super class for the OneFieldClass. |
| (...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1647 EXPECT(array.Equals(other_array)); | 1645 EXPECT(array.Equals(other_array)); |
| 1648 | 1646 |
| 1649 other_array.SetAt(1, other_array); | 1647 other_array.SetAt(1, other_array); |
| 1650 EXPECT(!array.Equals(other_array)); | 1648 EXPECT(!array.Equals(other_array)); |
| 1651 | 1649 |
| 1652 other_array = Array::New(kArrayLen - 1); | 1650 other_array = Array::New(kArrayLen - 1); |
| 1653 other_array.SetAt(0, array); | 1651 other_array.SetAt(0, array); |
| 1654 other_array.SetAt(2, array); | 1652 other_array.SetAt(2, array); |
| 1655 EXPECT(!array.Equals(other_array)); | 1653 EXPECT(!array.Equals(other_array)); |
| 1656 | 1654 |
| 1657 EXPECT_EQ(0, Array::Handle(Object::empty_array()).Length()); | 1655 EXPECT_EQ(0, Object::empty_array().Length()); |
| 1658 } | 1656 } |
| 1659 | 1657 |
| 1660 | 1658 |
| 1661 TEST_CASE(StringCodePointIterator) { | 1659 TEST_CASE(StringCodePointIterator) { |
| 1662 const String& str0 = String::Handle(String::New("")); | 1660 const String& str0 = String::Handle(String::New("")); |
| 1663 String::CodePointIterator it0(str0); | 1661 String::CodePointIterator it0(str0); |
| 1664 EXPECT(!it0.Next()); | 1662 EXPECT(!it0.Next()); |
| 1665 | 1663 |
| 1666 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); | 1664 const String& str1 = String::Handle(String::New(" \xc3\xa7 ")); |
| 1667 String::CodePointIterator it1(str1); | 1665 String::CodePointIterator it1(str1); |
| (...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3485 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); | 3483 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); |
| 3486 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); | 3484 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); |
| 3487 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); | 3485 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); |
| 3488 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); | 3486 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); |
| 3489 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); | 3487 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); |
| 3490 } | 3488 } |
| 3491 | 3489 |
| 3492 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3490 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 3493 | 3491 |
| 3494 } // namespace dart | 3492 } // namespace dart |
| OLD | NEW |