Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 16 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 17 | #include "object.h" |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <stdio.h> |
| 21 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include "array-inl.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 23 | #include "art_field-inl.h" |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 24 | #include "asm_support.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 25 | #include "class-inl.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 26 | #include "class_linker.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | #include "class_linker-inl.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame^] | 28 | #include "common_runtime_test.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 29 | #include "dex_file.h" |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 30 | #include "entrypoints/entrypoint_utils.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 31 | #include "gc/accounting/card_table-inl.h" |
| 32 | #include "gc/heap.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | #include "iftable-inl.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 34 | #include "art_method-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | #include "object-inl.h" |
| 36 | #include "object_array-inl.h" |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 37 | #include "sirt_ref.h" |
| 38 | #include "UniquePtr.h" |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 39 | |
| 40 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 41 | namespace mirror { |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 42 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame^] | 43 | class ObjectTest : public CommonRuntimeTest { |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 44 | protected: |
Brian Carlstrom | 0a02d12 | 2013-09-06 15:42:40 -0700 | [diff] [blame] | 45 | void AssertString(int32_t expected_utf16_length, |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 46 | const char* utf8_in, |
| 47 | const char* utf16_expected_le, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 48 | int32_t expected_hash) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 49 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 0a02d12 | 2013-09-06 15:42:40 -0700 | [diff] [blame] | 50 | UniquePtr<uint16_t[]> utf16_expected(new uint16_t[expected_utf16_length]); |
| 51 | for (int32_t i = 0; i < expected_utf16_length; i++) { |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 52 | uint16_t ch = (((utf16_expected_le[i*2 + 0] & 0xff) << 8) | |
| 53 | ((utf16_expected_le[i*2 + 1] & 0xff) << 0)); |
| 54 | utf16_expected[i] = ch; |
| 55 | } |
| 56 | |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 57 | Thread* self = Thread::Current(); |
Brian Carlstrom | 0a02d12 | 2013-09-06 15:42:40 -0700 | [diff] [blame] | 58 | SirtRef<String> string(self, String::AllocFromModifiedUtf8(self, expected_utf16_length, utf8_in)); |
| 59 | ASSERT_EQ(expected_utf16_length, string->GetLength()); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 60 | ASSERT_TRUE(string->GetCharArray() != NULL); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 61 | ASSERT_TRUE(string->GetCharArray()->GetData() != NULL); |
Brian Carlstrom | 0a02d12 | 2013-09-06 15:42:40 -0700 | [diff] [blame] | 62 | // strlen is necessary because the 1-character string "\x00\x00" is interpreted as "" |
| 63 | ASSERT_TRUE(string->Equals(utf8_in) || (expected_utf16_length == 1 && strlen(utf8_in) == 0)); |
| 64 | ASSERT_TRUE(string->Equals(StringPiece(utf8_in)) || (expected_utf16_length == 1 && strlen(utf8_in) == 0)); |
| 65 | for (int32_t i = 0; i < expected_utf16_length; i++) { |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 66 | EXPECT_EQ(utf16_expected[i], string->CharAt(i)); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 67 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 68 | EXPECT_EQ(expected_hash, string->GetHashCode()); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 69 | } |
| 70 | }; |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 71 | |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 72 | // Keep the assembly code in sync |
| 73 | TEST_F(ObjectTest, AsmConstants) { |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 74 | EXPECT_EQ(CLASS_OFFSET, Object::ClassOffset().Int32Value()); |
| 75 | EXPECT_EQ(LOCK_WORD_OFFSET, Object::MonitorOffset().Int32Value()); |
Jeff Hao | 5d91730 | 2013-02-27 17:57:33 -0800 | [diff] [blame] | 76 | |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 77 | EXPECT_EQ(CLASS_COMPONENT_TYPE_OFFSET, Class::ComponentTypeOffset().Int32Value()); |
| 78 | |
| 79 | EXPECT_EQ(ARRAY_LENGTH_OFFSET, Array::LengthOffset().Int32Value()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 80 | EXPECT_EQ(OBJECT_ARRAY_DATA_OFFSET, Array::DataOffset(sizeof(HeapReference<Object>)).Int32Value()); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 81 | |
| 82 | EXPECT_EQ(STRING_VALUE_OFFSET, String::ValueOffset().Int32Value()); |
| 83 | EXPECT_EQ(STRING_COUNT_OFFSET, String::CountOffset().Int32Value()); |
| 84 | EXPECT_EQ(STRING_OFFSET_OFFSET, String::OffsetOffset().Int32Value()); |
| 85 | EXPECT_EQ(STRING_DATA_OFFSET, Array::DataOffset(sizeof(uint16_t)).Int32Value()); |
| 86 | |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 87 | EXPECT_EQ(METHOD_DEX_CACHE_METHODS_OFFSET, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 88 | EXPECT_EQ(METHOD_PORTABLE_CODE_OFFSET, ArtMethod::EntryPointFromPortableCompiledCodeOffset().Int32Value()); |
| 89 | EXPECT_EQ(METHOD_QUICK_CODE_OFFSET, ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value()); |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 92 | TEST_F(ObjectTest, IsInSamePackage) { |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 93 | // Matches |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 94 | EXPECT_TRUE(Class::IsInSamePackage("Ljava/lang/Object;", "Ljava/lang/Class;")); |
| 95 | EXPECT_TRUE(Class::IsInSamePackage("LFoo;", "LBar;")); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 96 | |
| 97 | // Mismatches |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 98 | EXPECT_FALSE(Class::IsInSamePackage("Ljava/lang/Object;", "Ljava/io/File;")); |
| 99 | EXPECT_FALSE(Class::IsInSamePackage("Ljava/lang/Object;", "Ljava/lang/reflect/Method;")); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Elliott Hughes | 081be7f | 2011-09-18 16:50:26 -0700 | [diff] [blame] | 102 | TEST_F(ObjectTest, Clone) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 103 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 104 | SirtRef<ObjectArray<Object> > a1(soa.Self(), |
| 105 | class_linker_->AllocObjectArray<Object>(soa.Self(), 256)); |
Elliott Hughes | 081be7f | 2011-09-18 16:50:26 -0700 | [diff] [blame] | 106 | size_t s1 = a1->SizeOf(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 107 | Object* clone = a1->Clone(soa.Self()); |
Elliott Hughes | 081be7f | 2011-09-18 16:50:26 -0700 | [diff] [blame] | 108 | EXPECT_EQ(s1, clone->SizeOf()); |
| 109 | EXPECT_TRUE(clone->GetClass() == a1->GetClass()); |
| 110 | } |
| 111 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 112 | TEST_F(ObjectTest, AllocObjectArray) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 113 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 114 | SirtRef<ObjectArray<Object> > oa(soa.Self(), |
| 115 | class_linker_->AllocObjectArray<Object>(soa.Self(), 2)); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 116 | EXPECT_EQ(2, oa->GetLength()); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 117 | EXPECT_TRUE(oa->Get(0) == NULL); |
| 118 | EXPECT_TRUE(oa->Get(1) == NULL); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 119 | oa->Set<false>(0, oa.get()); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 120 | EXPECT_TRUE(oa->Get(0) == oa.get()); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 121 | EXPECT_TRUE(oa->Get(1) == NULL); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 122 | oa->Set<false>(1, oa.get()); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 123 | EXPECT_TRUE(oa->Get(0) == oa.get()); |
| 124 | EXPECT_TRUE(oa->Get(1) == oa.get()); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 125 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 126 | Class* aioobe = class_linker_->FindSystemClass(soa.Self(), |
| 127 | "Ljava/lang/ArrayIndexOutOfBoundsException;"); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 128 | |
| 129 | EXPECT_TRUE(oa->Get(-1) == NULL); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 130 | EXPECT_TRUE(soa.Self()->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 131 | EXPECT_EQ(aioobe, soa.Self()->GetException(NULL)->GetClass()); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 132 | soa.Self()->ClearException(); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 133 | |
| 134 | EXPECT_TRUE(oa->Get(2) == NULL); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 135 | EXPECT_TRUE(soa.Self()->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 136 | EXPECT_EQ(aioobe, soa.Self()->GetException(NULL)->GetClass()); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 137 | soa.Self()->ClearException(); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 138 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 139 | ASSERT_TRUE(oa->GetClass() != NULL); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 140 | ClassHelper oa_ch(oa->GetClass()); |
Ian Rogers | d24e264 | 2012-06-06 21:21:43 -0700 | [diff] [blame] | 141 | ASSERT_EQ(2U, oa_ch.NumDirectInterfaces()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 142 | EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Cloneable;"), |
| 143 | oa_ch.GetDirectInterface(0)); |
| 144 | EXPECT_EQ(class_linker_->FindSystemClass(soa.Self(), "Ljava/io/Serializable;"), |
| 145 | oa_ch.GetDirectInterface(1)); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 148 | TEST_F(ObjectTest, AllocArray) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 149 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 150 | Class* c = class_linker_->FindSystemClass(soa.Self(), "[I"); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 151 | SirtRef<Array> a(soa.Self(), Array::Alloc<true>(soa.Self(), c, 1)); |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 152 | ASSERT_TRUE(c == a->GetClass()); |
| 153 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 154 | c = class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 155 | a.reset(Array::Alloc<true>(soa.Self(), c, 1)); |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 156 | ASSERT_TRUE(c == a->GetClass()); |
| 157 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 158 | c = class_linker_->FindSystemClass(soa.Self(), "[[Ljava/lang/Object;"); |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 159 | a.reset(Array::Alloc<true>(soa.Self(), c, 1)); |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 160 | ASSERT_TRUE(c == a->GetClass()); |
| 161 | } |
| 162 | |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 163 | template<typename ArrayT> |
| 164 | void TestPrimitiveArray(ClassLinker* cl) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 165 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 166 | typedef typename ArrayT::ElementType T; |
| 167 | |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 168 | ArrayT* a = ArrayT::Alloc(soa.Self(), 2); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 169 | EXPECT_EQ(2, a->GetLength()); |
| 170 | EXPECT_EQ(0, a->Get(0)); |
| 171 | EXPECT_EQ(0, a->Get(1)); |
| 172 | a->Set(0, T(123)); |
| 173 | EXPECT_EQ(T(123), a->Get(0)); |
| 174 | EXPECT_EQ(0, a->Get(1)); |
| 175 | a->Set(1, T(321)); |
| 176 | EXPECT_EQ(T(123), a->Get(0)); |
| 177 | EXPECT_EQ(T(321), a->Get(1)); |
| 178 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 179 | Class* aioobe = cl->FindSystemClass(soa.Self(), "Ljava/lang/ArrayIndexOutOfBoundsException;"); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 180 | |
| 181 | EXPECT_EQ(0, a->Get(-1)); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 182 | EXPECT_TRUE(soa.Self()->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 183 | EXPECT_EQ(aioobe, soa.Self()->GetException(NULL)->GetClass()); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 184 | soa.Self()->ClearException(); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 185 | |
| 186 | EXPECT_EQ(0, a->Get(2)); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 187 | EXPECT_TRUE(soa.Self()->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 188 | EXPECT_EQ(aioobe, soa.Self()->GetException(NULL)->GetClass()); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 189 | soa.Self()->ClearException(); |
Elliott Hughes | 710a0cb | 2011-08-16 14:32:37 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | TEST_F(ObjectTest, PrimitiveArray_Boolean_Alloc) { |
| 193 | TestPrimitiveArray<BooleanArray>(class_linker_); |
| 194 | } |
| 195 | TEST_F(ObjectTest, PrimitiveArray_Byte_Alloc) { |
| 196 | TestPrimitiveArray<ByteArray>(class_linker_); |
| 197 | } |
| 198 | TEST_F(ObjectTest, PrimitiveArray_Char_Alloc) { |
| 199 | TestPrimitiveArray<CharArray>(class_linker_); |
| 200 | } |
| 201 | TEST_F(ObjectTest, PrimitiveArray_Double_Alloc) { |
| 202 | TestPrimitiveArray<DoubleArray>(class_linker_); |
| 203 | } |
| 204 | TEST_F(ObjectTest, PrimitiveArray_Float_Alloc) { |
| 205 | TestPrimitiveArray<FloatArray>(class_linker_); |
| 206 | } |
| 207 | TEST_F(ObjectTest, PrimitiveArray_Int_Alloc) { |
| 208 | TestPrimitiveArray<IntArray>(class_linker_); |
| 209 | } |
| 210 | TEST_F(ObjectTest, PrimitiveArray_Long_Alloc) { |
| 211 | TestPrimitiveArray<LongArray>(class_linker_); |
| 212 | } |
| 213 | TEST_F(ObjectTest, PrimitiveArray_Short_Alloc) { |
| 214 | TestPrimitiveArray<ShortArray>(class_linker_); |
| 215 | } |
| 216 | |
Elliott Hughes | b408de7 | 2011-10-04 14:35:05 -0700 | [diff] [blame] | 217 | TEST_F(ObjectTest, CheckAndAllocArrayFromCode) { |
Ian Rogers | b886da8 | 2011-09-23 16:27:54 -0700 | [diff] [blame] | 218 | // pretend we are trying to call 'new char[3]' from String.toCharArray |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 219 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 220 | Class* java_util_Arrays = class_linker_->FindSystemClass(soa.Self(), "Ljava/util/Arrays;"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 221 | ArtMethod* sort = java_util_Arrays->FindDirectMethod("sort", "([I)V"); |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 222 | const DexFile::StringId* string_id = java_lang_dex_file_->FindStringId("[I"); |
| 223 | ASSERT_TRUE(string_id != NULL); |
| 224 | const DexFile::TypeId* type_id = java_lang_dex_file_->FindTypeId( |
| 225 | java_lang_dex_file_->GetIndexForStringId(*string_id)); |
| 226 | ASSERT_TRUE(type_id != NULL); |
| 227 | uint32_t type_idx = java_lang_dex_file_->GetIndexForTypeId(*type_id); |
Hiroshi Yamauchi | e4e23c0 | 2013-12-06 13:38:43 -0800 | [diff] [blame] | 228 | Object* array = CheckAndAllocArrayFromCodeInstrumented(type_idx, sort, 3, Thread::Current(), false, |
| 229 | Runtime::Current()->GetHeap()->GetCurrentAllocator()); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 230 | EXPECT_TRUE(array->IsArrayInstance()); |
| 231 | EXPECT_EQ(3, array->AsArray()->GetLength()); |
| 232 | EXPECT_TRUE(array->GetClass()->IsArrayClass()); |
| 233 | EXPECT_TRUE(array->GetClass()->GetComponentType()->IsPrimitive()); |
| 234 | } |
| 235 | |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 236 | TEST_F(ObjectTest, CreateMultiArray) { |
| 237 | ScopedObjectAccess soa(Thread::Current()); |
| 238 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 239 | SirtRef<Class> c(soa.Self(), class_linker_->FindSystemClass(soa.Self(), "I")); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 240 | SirtRef<IntArray> dims(soa.Self(), IntArray::Alloc(soa.Self(), 1)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 241 | dims->Set<false>(0, 1); |
Mathieu Chartier | 5bb9903 | 2014-02-08 16:20:58 -0800 | [diff] [blame] | 242 | Array* multi = Array::CreateMultiArray(soa.Self(), c, dims); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 243 | EXPECT_TRUE(multi->GetClass() == class_linker_->FindSystemClass(soa.Self(), "[I")); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 244 | EXPECT_EQ(1, multi->GetLength()); |
| 245 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 246 | dims->Set<false>(0, -1); |
Mathieu Chartier | 5bb9903 | 2014-02-08 16:20:58 -0800 | [diff] [blame] | 247 | multi = Array::CreateMultiArray(soa.Self(), c, dims); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 248 | EXPECT_TRUE(soa.Self()->IsExceptionPending()); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 249 | EXPECT_EQ(PrettyDescriptor(soa.Self()->GetException(NULL)->GetClass()), |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 250 | "java.lang.NegativeArraySizeException"); |
| 251 | soa.Self()->ClearException(); |
| 252 | |
| 253 | dims.reset(IntArray::Alloc(soa.Self(), 2)); |
| 254 | for (int i = 1; i < 20; ++i) { |
| 255 | for (int j = 0; j < 20; ++j) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 256 | dims->Set<false>(0, i); |
| 257 | dims->Set<false>(1, j); |
Mathieu Chartier | 5bb9903 | 2014-02-08 16:20:58 -0800 | [diff] [blame] | 258 | multi = Array::CreateMultiArray(soa.Self(), c, dims); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 259 | EXPECT_TRUE(multi->GetClass() == class_linker_->FindSystemClass(soa.Self(), "[[I")); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 260 | EXPECT_EQ(i, multi->GetLength()); |
| 261 | for (int k = 0; k < i; ++k) { |
| 262 | Array* outer = multi->AsObjectArray<Array>()->Get(k); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 263 | EXPECT_TRUE(outer->GetClass() == class_linker_->FindSystemClass(soa.Self(), "[I")); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 264 | EXPECT_EQ(j, outer->GetLength()); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 270 | TEST_F(ObjectTest, StaticFieldFromCode) { |
jeffhao | abcfde3 | 2011-09-29 15:05:18 -0700 | [diff] [blame] | 271 | // pretend we are trying to access 'Static.s0' from StaticsFromCode.<clinit> |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 272 | ScopedObjectAccess soa(Thread::Current()); |
| 273 | jobject class_loader = LoadDex("StaticsFromCode"); |
| 274 | const DexFile* dex_file = Runtime::Current()->GetCompileTimeClassPath(class_loader)[0]; |
Brian Carlstrom | 848a4b3 | 2011-09-04 11:29:27 -0700 | [diff] [blame] | 275 | CHECK(dex_file != NULL); |
| 276 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 277 | SirtRef<mirror::ClassLoader> loader(soa.Self(), soa.Decode<ClassLoader*>(class_loader)); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 278 | Class* klass = class_linker_->FindClass(soa.Self(), "LStaticsFromCode;", loader); |
Ian Rogers | 241b5de | 2013-10-09 17:58:57 -0700 | [diff] [blame] | 279 | ArtMethod* clinit = klass->FindClassInitializer(); |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 280 | const DexFile::StringId* klass_string_id = dex_file->FindStringId("LStaticsFromCode;"); |
| 281 | ASSERT_TRUE(klass_string_id != NULL); |
| 282 | const DexFile::TypeId* klass_type_id = dex_file->FindTypeId( |
| 283 | dex_file->GetIndexForStringId(*klass_string_id)); |
| 284 | ASSERT_TRUE(klass_type_id != NULL); |
| 285 | |
| 286 | const DexFile::StringId* type_string_id = dex_file->FindStringId("Ljava/lang/Object;"); |
| 287 | ASSERT_TRUE(type_string_id != NULL); |
| 288 | const DexFile::TypeId* type_type_id = dex_file->FindTypeId( |
| 289 | dex_file->GetIndexForStringId(*type_string_id)); |
| 290 | ASSERT_TRUE(type_type_id != NULL); |
| 291 | |
| 292 | const DexFile::StringId* name_str_id = dex_file->FindStringId("s0"); |
| 293 | ASSERT_TRUE(name_str_id != NULL); |
| 294 | |
| 295 | const DexFile::FieldId* field_id = dex_file->FindFieldId( |
| 296 | *klass_type_id, *name_str_id, *type_type_id); |
| 297 | ASSERT_TRUE(field_id != NULL); |
| 298 | uint32_t field_idx = dex_file->GetIndexForFieldId(*field_id); |
| 299 | |
Sebastien Hertz | d4beb6b | 2013-10-02 17:07:20 +0200 | [diff] [blame] | 300 | ArtField* field = FindFieldFromCode<StaticObjectRead, true>(field_idx, clinit, Thread::Current(), |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 301 | sizeof(HeapReference<Object>)); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 302 | Object* s0 = field->GetObj(klass); |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 303 | EXPECT_TRUE(s0 != NULL); |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 304 | |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 305 | SirtRef<CharArray> char_array(soa.Self(), CharArray::Alloc(soa.Self(), 0)); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 306 | field->SetObj<false>(field->GetDeclaringClass(), char_array.get()); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 307 | EXPECT_EQ(char_array.get(), field->GetObj(klass)); |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 308 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 309 | field->SetObj<false>(field->GetDeclaringClass(), NULL); |
Ian Rogers | 2fa6b2e | 2012-10-17 00:10:17 -0700 | [diff] [blame] | 310 | EXPECT_EQ(NULL, field->GetObj(klass)); |
Brian Carlstrom | 9f30b38 | 2011-08-28 22:41:38 -0700 | [diff] [blame] | 311 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 312 | // TODO: more exhaustive tests of all 6 cases of ArtField::*FromCode |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 315 | TEST_F(ObjectTest, String) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 316 | ScopedObjectAccess soa(Thread::Current()); |
Brian Carlstrom | 0b138b2 | 2011-07-27 15:19:17 -0700 | [diff] [blame] | 317 | // Test the empty string. |
| 318 | AssertString(0, "", "", 0); |
| 319 | |
| 320 | // Test one-byte characters. |
| 321 | AssertString(1, " ", "\x00\x20", 0x20); |
| 322 | AssertString(1, "", "\x00\x00", 0); |
| 323 | AssertString(1, "\x7f", "\x00\x7f", 0x7f); |
| 324 | AssertString(2, "hi", "\x00\x68\x00\x69", (31 * 0x68) + 0x69); |
| 325 | |
| 326 | // Test two-byte characters. |
| 327 | AssertString(1, "\xc2\x80", "\x00\x80", 0x80); |
| 328 | AssertString(1, "\xd9\xa6", "\x06\x66", 0x0666); |
| 329 | AssertString(1, "\xdf\xbf", "\x07\xff", 0x07ff); |
| 330 | AssertString(3, "h\xd9\xa6i", "\x00\x68\x06\x66\x00\x69", (31 * ((31 * 0x68) + 0x0666)) + 0x69); |
| 331 | |
| 332 | // Test three-byte characters. |
| 333 | AssertString(1, "\xe0\xa0\x80", "\x08\x00", 0x0800); |
| 334 | AssertString(1, "\xe1\x88\xb4", "\x12\x34", 0x1234); |
| 335 | AssertString(1, "\xef\xbf\xbf", "\xff\xff", 0xffff); |
| 336 | AssertString(3, "h\xe1\x88\xb4i", "\x00\x68\x12\x34\x00\x69", (31 * ((31 * 0x68) + 0x1234)) + 0x69); |
| 337 | } |
Jesse Wilson | cbe9fc0 | 2011-07-29 18:59:50 -0400 | [diff] [blame] | 338 | |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 339 | TEST_F(ObjectTest, StringEqualsUtf8) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 340 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 341 | SirtRef<String> string(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 342 | EXPECT_TRUE(string->Equals("android")); |
| 343 | EXPECT_FALSE(string->Equals("Android")); |
| 344 | EXPECT_FALSE(string->Equals("ANDROID")); |
| 345 | EXPECT_FALSE(string->Equals("")); |
| 346 | EXPECT_FALSE(string->Equals("and")); |
| 347 | EXPECT_FALSE(string->Equals("androids")); |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 348 | |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 349 | SirtRef<String> empty(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "")); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 350 | EXPECT_TRUE(empty->Equals("")); |
| 351 | EXPECT_FALSE(empty->Equals("a")); |
Jesse Wilson | cbe9fc0 | 2011-07-29 18:59:50 -0400 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | TEST_F(ObjectTest, StringEquals) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 355 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 356 | SirtRef<String> string(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); |
| 357 | SirtRef<String> string_2(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 358 | EXPECT_TRUE(string->Equals(string_2.get())); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 359 | EXPECT_FALSE(string->Equals("Android")); |
| 360 | EXPECT_FALSE(string->Equals("ANDROID")); |
| 361 | EXPECT_FALSE(string->Equals("")); |
| 362 | EXPECT_FALSE(string->Equals("and")); |
| 363 | EXPECT_FALSE(string->Equals("androids")); |
Jesse Wilson | cbe9fc0 | 2011-07-29 18:59:50 -0400 | [diff] [blame] | 364 | |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 365 | SirtRef<String> empty(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "")); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 366 | EXPECT_TRUE(empty->Equals("")); |
| 367 | EXPECT_FALSE(empty->Equals("a")); |
| 368 | } |
| 369 | |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 370 | TEST_F(ObjectTest, StringCompareTo) { |
| 371 | ScopedObjectAccess soa(Thread::Current()); |
| 372 | SirtRef<String> string(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); |
| 373 | SirtRef<String> string_2(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); |
| 374 | SirtRef<String> string_3(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "Android")); |
| 375 | SirtRef<String> string_4(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "and")); |
| 376 | SirtRef<String> string_5(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "")); |
| 377 | EXPECT_EQ(0, string->CompareTo(string_2.get())); |
| 378 | EXPECT_LT(0, string->CompareTo(string_3.get())); |
| 379 | EXPECT_GT(0, string_3->CompareTo(string.get())); |
| 380 | EXPECT_LT(0, string->CompareTo(string_4.get())); |
| 381 | EXPECT_GT(0, string_4->CompareTo(string.get())); |
| 382 | EXPECT_LT(0, string->CompareTo(string_5.get())); |
| 383 | EXPECT_GT(0, string_5->CompareTo(string.get())); |
| 384 | } |
| 385 | |
jeffhao | 0ce1315 | 2012-03-27 19:45:50 -0700 | [diff] [blame] | 386 | TEST_F(ObjectTest, StringLength) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 387 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 388 | SirtRef<String> string(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); |
jeffhao | 0ce1315 | 2012-03-27 19:45:50 -0700 | [diff] [blame] | 389 | EXPECT_EQ(string->GetLength(), 7); |
| 390 | EXPECT_EQ(string->GetUtfLength(), 7); |
| 391 | |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 392 | string->SetOffset<false>(2); |
| 393 | string->SetCount<false>(5); |
jeffhao | 0ce1315 | 2012-03-27 19:45:50 -0700 | [diff] [blame] | 394 | EXPECT_TRUE(string->Equals("droid")); |
| 395 | EXPECT_EQ(string->GetLength(), 5); |
| 396 | EXPECT_EQ(string->GetUtfLength(), 5); |
| 397 | } |
| 398 | |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 399 | TEST_F(ObjectTest, DescriptorCompare) { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 400 | // Two classloaders conflicts in compile_time_class_paths_. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 401 | ScopedObjectAccess soa(Thread::Current()); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 402 | ClassLinker* linker = class_linker_; |
| 403 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 404 | jobject jclass_loader_1 = LoadDex("ProtoCompare"); |
| 405 | jobject jclass_loader_2 = LoadDex("ProtoCompare2"); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 406 | SirtRef<ClassLoader> class_loader_1(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader_1)); |
| 407 | SirtRef<ClassLoader> class_loader_2(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader_2)); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 408 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 409 | Class* klass1 = linker->FindClass(soa.Self(), "LProtoCompare;", class_loader_1); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 410 | ASSERT_TRUE(klass1 != NULL); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 411 | Class* klass2 = linker->FindClass(soa.Self(), "LProtoCompare2;", class_loader_2); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 412 | ASSERT_TRUE(klass2 != NULL); |
| 413 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 414 | ArtMethod* m1_1 = klass1->GetVirtualMethod(0); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 415 | MethodHelper mh(m1_1); |
| 416 | EXPECT_STREQ(mh.GetName(), "m1"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 417 | ArtMethod* m2_1 = klass1->GetVirtualMethod(1); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 418 | mh.ChangeMethod(m2_1); |
| 419 | EXPECT_STREQ(mh.GetName(), "m2"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 420 | ArtMethod* m3_1 = klass1->GetVirtualMethod(2); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 421 | mh.ChangeMethod(m3_1); |
| 422 | EXPECT_STREQ(mh.GetName(), "m3"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 423 | ArtMethod* m4_1 = klass1->GetVirtualMethod(3); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 424 | mh.ChangeMethod(m4_1); |
| 425 | EXPECT_STREQ(mh.GetName(), "m4"); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 426 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 427 | ArtMethod* m1_2 = klass2->GetVirtualMethod(0); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 428 | mh.ChangeMethod(m1_2); |
| 429 | EXPECT_STREQ(mh.GetName(), "m1"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 430 | ArtMethod* m2_2 = klass2->GetVirtualMethod(1); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 431 | mh.ChangeMethod(m2_2); |
| 432 | EXPECT_STREQ(mh.GetName(), "m2"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 433 | ArtMethod* m3_2 = klass2->GetVirtualMethod(2); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 434 | mh.ChangeMethod(m3_2); |
| 435 | EXPECT_STREQ(mh.GetName(), "m3"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 436 | ArtMethod* m4_2 = klass2->GetVirtualMethod(3); |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 437 | mh.ChangeMethod(m4_2); |
| 438 | EXPECT_STREQ(mh.GetName(), "m4"); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 439 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 440 | mh.ChangeMethod(m1_1); |
| 441 | MethodHelper mh2(m1_2); |
| 442 | EXPECT_TRUE(mh.HasSameNameAndSignature(&mh2)); |
| 443 | EXPECT_TRUE(mh2.HasSameNameAndSignature(&mh)); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 444 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 445 | mh.ChangeMethod(m2_1); |
| 446 | mh2.ChangeMethod(m2_2); |
| 447 | EXPECT_TRUE(mh.HasSameNameAndSignature(&mh2)); |
| 448 | EXPECT_TRUE(mh2.HasSameNameAndSignature(&mh)); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 449 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 450 | mh.ChangeMethod(m3_1); |
| 451 | mh2.ChangeMethod(m3_2); |
| 452 | EXPECT_TRUE(mh.HasSameNameAndSignature(&mh2)); |
| 453 | EXPECT_TRUE(mh2.HasSameNameAndSignature(&mh)); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 454 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 455 | mh.ChangeMethod(m4_1); |
| 456 | mh2.ChangeMethod(m4_2); |
| 457 | EXPECT_TRUE(mh.HasSameNameAndSignature(&mh2)); |
| 458 | EXPECT_TRUE(mh2.HasSameNameAndSignature(&mh)); |
Jesse Wilson | cbe9fc0 | 2011-07-29 18:59:50 -0400 | [diff] [blame] | 459 | } |
| 460 | |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 461 | TEST_F(ObjectTest, StringHashCode) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 462 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 463 | SirtRef<String> empty(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "")); |
| 464 | SirtRef<String> A(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "A")); |
| 465 | SirtRef<String> ABC(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "ABC")); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 466 | |
| 467 | EXPECT_EQ(0, empty->GetHashCode()); |
| 468 | EXPECT_EQ(65, A->GetHashCode()); |
| 469 | EXPECT_EQ(64578, ABC->GetHashCode()); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 472 | TEST_F(ObjectTest, InstanceOf) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 473 | ScopedObjectAccess soa(Thread::Current()); |
| 474 | jobject jclass_loader = LoadDex("XandY"); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 475 | SirtRef<ClassLoader> class_loader(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 476 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 477 | Class* X = class_linker_->FindClass(soa.Self(), "LX;", class_loader); |
| 478 | Class* Y = class_linker_->FindClass(soa.Self(), "LY;", class_loader); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 479 | ASSERT_TRUE(X != NULL); |
| 480 | ASSERT_TRUE(Y != NULL); |
| 481 | |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 482 | SirtRef<Object> x(soa.Self(), X->AllocObject(soa.Self())); |
| 483 | SirtRef<Object> y(soa.Self(), Y->AllocObject(soa.Self())); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 484 | ASSERT_TRUE(x.get() != NULL); |
| 485 | ASSERT_TRUE(y.get() != NULL); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 486 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 487 | EXPECT_TRUE(x->InstanceOf(X)); |
| 488 | EXPECT_FALSE(x->InstanceOf(Y)); |
| 489 | EXPECT_TRUE(y->InstanceOf(X)); |
| 490 | EXPECT_TRUE(y->InstanceOf(Y)); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 491 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 492 | Class* java_lang_Class = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Class;"); |
| 493 | Class* Object_array_class = class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"); |
Elliott Hughes | 92f14b2 | 2011-10-06 12:29:54 -0700 | [diff] [blame] | 494 | |
| 495 | EXPECT_FALSE(java_lang_Class->InstanceOf(Object_array_class)); |
| 496 | EXPECT_TRUE(Object_array_class->InstanceOf(java_lang_Class)); |
| 497 | |
| 498 | // All array classes implement Cloneable and Serializable. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 499 | Object* array = ObjectArray<Object>::Alloc(soa.Self(), Object_array_class, 1); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 500 | Class* java_lang_Cloneable = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Cloneable;"); |
| 501 | Class* java_io_Serializable = class_linker_->FindSystemClass(soa.Self(), "Ljava/io/Serializable;"); |
Elliott Hughes | 92f14b2 | 2011-10-06 12:29:54 -0700 | [diff] [blame] | 502 | EXPECT_TRUE(array->InstanceOf(java_lang_Cloneable)); |
| 503 | EXPECT_TRUE(array->InstanceOf(java_io_Serializable)); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | TEST_F(ObjectTest, IsAssignableFrom) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 507 | ScopedObjectAccess soa(Thread::Current()); |
| 508 | jobject jclass_loader = LoadDex("XandY"); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 509 | SirtRef<ClassLoader> class_loader(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader)); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 510 | Class* X = class_linker_->FindClass(soa.Self(), "LX;", class_loader); |
| 511 | Class* Y = class_linker_->FindClass(soa.Self(), "LY;", class_loader); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 512 | |
| 513 | EXPECT_TRUE(X->IsAssignableFrom(X)); |
| 514 | EXPECT_TRUE(X->IsAssignableFrom(Y)); |
| 515 | EXPECT_FALSE(Y->IsAssignableFrom(X)); |
| 516 | EXPECT_TRUE(Y->IsAssignableFrom(Y)); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 517 | |
| 518 | // class final String implements CharSequence, .. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 519 | Class* string = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/String;"); |
| 520 | Class* charseq = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/CharSequence;"); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 521 | // Can String be assigned to CharSequence without a cast? |
| 522 | EXPECT_TRUE(charseq->IsAssignableFrom(string)); |
| 523 | // Can CharSequence be assigned to String without a cast? |
| 524 | EXPECT_FALSE(string->IsAssignableFrom(charseq)); |
| 525 | |
| 526 | // Primitive types are only assignable to themselves |
| 527 | const char* prims = "ZBCSIJFD"; |
| 528 | Class* prim_types[strlen(prims)]; |
| 529 | for (size_t i = 0; i < strlen(prims); i++) { |
| 530 | prim_types[i] = class_linker_->FindPrimitiveClass(prims[i]); |
| 531 | } |
| 532 | for (size_t i = 0; i < strlen(prims); i++) { |
| 533 | for (size_t j = 0; i < strlen(prims); i++) { |
| 534 | if (i == j) { |
| 535 | EXPECT_TRUE(prim_types[i]->IsAssignableFrom(prim_types[j])); |
| 536 | } else { |
| 537 | EXPECT_FALSE(prim_types[i]->IsAssignableFrom(prim_types[j])); |
| 538 | } |
| 539 | } |
| 540 | } |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | TEST_F(ObjectTest, IsAssignableFromArray) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 544 | ScopedObjectAccess soa(Thread::Current()); |
| 545 | jobject jclass_loader = LoadDex("XandY"); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 546 | SirtRef<ClassLoader> class_loader(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader)); |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 547 | Class* X = class_linker_->FindClass(soa.Self(), "LX;", class_loader); |
| 548 | Class* Y = class_linker_->FindClass(soa.Self(), "LY;", class_loader); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 549 | ASSERT_TRUE(X != NULL); |
| 550 | ASSERT_TRUE(Y != NULL); |
| 551 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 552 | Class* YA = class_linker_->FindClass(soa.Self(), "[LY;", class_loader); |
| 553 | Class* YAA = class_linker_->FindClass(soa.Self(), "[[LY;", class_loader); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 554 | ASSERT_TRUE(YA != NULL); |
| 555 | ASSERT_TRUE(YAA != NULL); |
| 556 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 557 | Class* XAA = class_linker_->FindClass(soa.Self(), "[[LX;", class_loader); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 558 | ASSERT_TRUE(XAA != NULL); |
| 559 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 560 | Class* O = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/Object;"); |
| 561 | Class* OA = class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"); |
| 562 | Class* OAA = class_linker_->FindSystemClass(soa.Self(), "[[Ljava/lang/Object;"); |
| 563 | Class* OAAA = class_linker_->FindSystemClass(soa.Self(), "[[[Ljava/lang/Object;"); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 564 | ASSERT_TRUE(O != NULL); |
| 565 | ASSERT_TRUE(OA != NULL); |
| 566 | ASSERT_TRUE(OAA != NULL); |
| 567 | ASSERT_TRUE(OAAA != NULL); |
| 568 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 569 | Class* S = class_linker_->FindSystemClass(soa.Self(), "Ljava/io/Serializable;"); |
| 570 | Class* SA = class_linker_->FindSystemClass(soa.Self(), "[Ljava/io/Serializable;"); |
| 571 | Class* SAA = class_linker_->FindSystemClass(soa.Self(), "[[Ljava/io/Serializable;"); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 572 | ASSERT_TRUE(S != NULL); |
| 573 | ASSERT_TRUE(SA != NULL); |
| 574 | ASSERT_TRUE(SAA != NULL); |
| 575 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 576 | Class* IA = class_linker_->FindSystemClass(soa.Self(), "[I"); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 577 | ASSERT_TRUE(IA != NULL); |
| 578 | |
| 579 | EXPECT_TRUE(YAA->IsAssignableFrom(YAA)); // identity |
| 580 | EXPECT_TRUE(XAA->IsAssignableFrom(YAA)); // element superclass |
| 581 | EXPECT_FALSE(YAA->IsAssignableFrom(XAA)); |
| 582 | EXPECT_FALSE(Y->IsAssignableFrom(YAA)); |
| 583 | EXPECT_FALSE(YA->IsAssignableFrom(YAA)); |
| 584 | EXPECT_TRUE(O->IsAssignableFrom(YAA)); // everything is an Object |
| 585 | EXPECT_TRUE(OA->IsAssignableFrom(YAA)); |
| 586 | EXPECT_TRUE(OAA->IsAssignableFrom(YAA)); |
| 587 | EXPECT_TRUE(S->IsAssignableFrom(YAA)); // all arrays are Serializable |
| 588 | EXPECT_TRUE(SA->IsAssignableFrom(YAA)); |
| 589 | EXPECT_FALSE(SAA->IsAssignableFrom(YAA)); // unless Y was Serializable |
| 590 | |
| 591 | EXPECT_FALSE(IA->IsAssignableFrom(OA)); |
| 592 | EXPECT_FALSE(OA->IsAssignableFrom(IA)); |
| 593 | EXPECT_TRUE(O->IsAssignableFrom(IA)); |
| 594 | } |
| 595 | |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 596 | TEST_F(ObjectTest, FindInstanceField) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 597 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 598 | SirtRef<String> s(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "ABC")); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 599 | ASSERT_TRUE(s.get() != NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 600 | Class* c = s->GetClass(); |
| 601 | ASSERT_TRUE(c != NULL); |
| 602 | |
| 603 | // Wrong type. |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 604 | EXPECT_TRUE(c->FindDeclaredInstanceField("count", "J") == NULL); |
| 605 | EXPECT_TRUE(c->FindInstanceField("count", "J") == NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 606 | |
| 607 | // Wrong name. |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 608 | EXPECT_TRUE(c->FindDeclaredInstanceField("Count", "I") == NULL); |
| 609 | EXPECT_TRUE(c->FindInstanceField("Count", "I") == NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 610 | |
| 611 | // Right name and type. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 612 | ArtField* f1 = c->FindDeclaredInstanceField("count", "I"); |
| 613 | ArtField* f2 = c->FindInstanceField("count", "I"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 614 | EXPECT_TRUE(f1 != NULL); |
| 615 | EXPECT_TRUE(f2 != NULL); |
| 616 | EXPECT_EQ(f1, f2); |
| 617 | |
| 618 | // TODO: check that s.count == 3. |
| 619 | |
| 620 | // Ensure that we handle superclass fields correctly... |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 621 | c = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/StringBuilder;"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 622 | ASSERT_TRUE(c != NULL); |
| 623 | // No StringBuilder.count... |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 624 | EXPECT_TRUE(c->FindDeclaredInstanceField("count", "I") == NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 625 | // ...but there is an AbstractStringBuilder.count. |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 626 | EXPECT_TRUE(c->FindInstanceField("count", "I") != NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | TEST_F(ObjectTest, FindStaticField) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 630 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 631 | SirtRef<String> s(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "ABC")); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 632 | ASSERT_TRUE(s.get() != NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 633 | Class* c = s->GetClass(); |
| 634 | ASSERT_TRUE(c != NULL); |
| 635 | |
| 636 | // Wrong type. |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 637 | EXPECT_TRUE(c->FindDeclaredStaticField("CASE_INSENSITIVE_ORDER", "I") == NULL); |
| 638 | EXPECT_TRUE(c->FindStaticField("CASE_INSENSITIVE_ORDER", "I") == NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 639 | |
| 640 | // Wrong name. |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 641 | EXPECT_TRUE(c->FindDeclaredStaticField("cASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;") == NULL); |
| 642 | EXPECT_TRUE(c->FindStaticField("cASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;") == NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 643 | |
| 644 | // Right name and type. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 645 | ArtField* f1 = c->FindDeclaredStaticField("CASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;"); |
| 646 | ArtField* f2 = c->FindStaticField("CASE_INSENSITIVE_ORDER", "Ljava/util/Comparator;"); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 647 | EXPECT_TRUE(f1 != NULL); |
| 648 | EXPECT_TRUE(f2 != NULL); |
| 649 | EXPECT_EQ(f1, f2); |
| 650 | |
| 651 | // TODO: test static fields via superclasses. |
| 652 | // TODO: test static fields via interfaces. |
| 653 | // TODO: test that interfaces trump superclasses. |
| 654 | } |
| 655 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 656 | } // namespace mirror |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 657 | } // namespace art |