Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 3 | #include "common_test.h" |
| 4 | #include "class_linker.h" |
| 5 | #include "dex_file.h" |
| 6 | #include "heap.h" |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 7 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 8 | #include "gtest/gtest.h" |
| 9 | |
| 10 | namespace art { |
| 11 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 12 | class ClassLinkerTest : public CommonTest { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 13 | protected: |
| 14 | void AssertNonExistantClass(const StringPiece& descriptor) { |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 15 | EXPECT_TRUE(class_linker_->FindSystemClass(descriptor) == NULL); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | void AssertPrimitiveClass(const StringPiece& descriptor) { |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 19 | Class* primitive = class_linker_->FindSystemClass(descriptor); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 20 | ASSERT_TRUE(primitive != NULL); |
| 21 | ASSERT_TRUE(primitive->GetClass() != NULL); |
| 22 | ASSERT_EQ(primitive->GetClass(), primitive->GetClass()->GetClass()); |
| 23 | EXPECT_TRUE(primitive->GetClass()->GetSuperClass() != NULL); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame^] | 24 | ASSERT_TRUE(primitive->GetDescriptor()->Equals(descriptor)); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 25 | EXPECT_TRUE(primitive->GetSuperClass() == NULL); |
| 26 | EXPECT_FALSE(primitive->HasSuperClass()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 27 | EXPECT_TRUE(primitive->GetClassLoader() == NULL); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 28 | EXPECT_TRUE(primitive->GetComponentType() == NULL); |
| 29 | EXPECT_TRUE(primitive->GetStatus() == Class::kStatusInitialized); |
| 30 | EXPECT_FALSE(primitive->IsErroneous()); |
| 31 | EXPECT_TRUE(primitive->IsVerified()); |
| 32 | EXPECT_TRUE(primitive->IsLinked()); |
| 33 | EXPECT_FALSE(primitive->IsArray()); |
| 34 | EXPECT_EQ(0, primitive->array_rank_); |
| 35 | EXPECT_FALSE(primitive->IsInterface()); |
| 36 | EXPECT_TRUE(primitive->IsPublic()); |
| 37 | EXPECT_TRUE(primitive->IsFinal()); |
| 38 | EXPECT_TRUE(primitive->IsPrimitive()); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 39 | EXPECT_FALSE(primitive->IsSynthetic()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 40 | EXPECT_EQ(0U, primitive->NumDirectMethods()); |
| 41 | EXPECT_EQ(0U, primitive->NumVirtualMethods()); |
| 42 | EXPECT_EQ(0U, primitive->NumInstanceFields()); |
| 43 | EXPECT_EQ(0U, primitive->NumStaticFields()); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 44 | EXPECT_EQ(0U, primitive->NumInterfaces()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void AssertArrayClass(const StringPiece& array_descriptor, |
| 48 | int32_t array_rank, |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 49 | const StringPiece& component_type, |
| 50 | ClassLoader* class_loader) { |
| 51 | Class* array = class_linker_->FindClass(array_descriptor, class_loader); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 52 | ASSERT_TRUE(array != NULL); |
| 53 | ASSERT_TRUE(array->GetClass() != NULL); |
| 54 | ASSERT_EQ(array->GetClass(), array->GetClass()->GetClass()); |
| 55 | EXPECT_TRUE(array->GetClass()->GetSuperClass() != NULL); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame^] | 56 | ASSERT_TRUE(array->GetDescriptor()->Equals(array_descriptor)); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 57 | EXPECT_TRUE(array->GetSuperClass() != NULL); |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 58 | EXPECT_EQ(class_linker_->FindSystemClass("Ljava/lang/Object;"), array->GetSuperClass()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 59 | EXPECT_TRUE(array->HasSuperClass()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 60 | EXPECT_EQ(class_loader, array->GetClassLoader()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 61 | ASSERT_TRUE(array->GetComponentType() != NULL); |
| 62 | ASSERT_TRUE(array->GetComponentType()->GetDescriptor() != NULL); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame^] | 63 | EXPECT_TRUE(array->GetComponentType()->GetDescriptor()->Equals(component_type)); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 64 | EXPECT_TRUE(array->GetStatus() == Class::kStatusInitialized); |
| 65 | EXPECT_FALSE(array->IsErroneous()); |
| 66 | EXPECT_TRUE(array->IsVerified()); |
| 67 | EXPECT_TRUE(array->IsLinked()); |
| 68 | EXPECT_TRUE(array->IsArray()); |
| 69 | EXPECT_EQ(array_rank, array->array_rank_); |
| 70 | EXPECT_FALSE(array->IsInterface()); |
| 71 | EXPECT_EQ(array->GetComponentType()->IsPublic(), array->IsPublic()); |
| 72 | EXPECT_TRUE(array->IsFinal()); |
| 73 | EXPECT_FALSE(array->IsPrimitive()); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 74 | EXPECT_FALSE(array->IsSynthetic()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 75 | EXPECT_EQ(0U, array->NumDirectMethods()); |
| 76 | EXPECT_EQ(0U, array->NumVirtualMethods()); |
| 77 | EXPECT_EQ(0U, array->NumInstanceFields()); |
| 78 | EXPECT_EQ(0U, array->NumStaticFields()); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 79 | EXPECT_EQ(2U, array->NumInterfaces()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 80 | } |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 81 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 82 | void AssertDexFileClass(ClassLoader* class_loader, const char* descriptor) { |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 83 | ASSERT_TRUE(descriptor != NULL); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 84 | Class* klass = class_linker_->FindSystemClass(descriptor); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 85 | ASSERT_TRUE(klass != NULL); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame^] | 86 | EXPECT_TRUE(klass->GetDescriptor()->Equals(descriptor)); |
| 87 | if (klass->descriptor_->Equals(String::AllocFromModifiedUtf8("Ljava/lang/Object;"))) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 88 | EXPECT_FALSE(klass->HasSuperClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 89 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 90 | EXPECT_TRUE(klass->HasSuperClass()); |
| 91 | EXPECT_TRUE(klass->GetSuperClass() != NULL); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 92 | } |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 93 | EXPECT_EQ(class_loader, klass->GetClassLoader()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 94 | EXPECT_TRUE(klass->GetDexCache() != NULL); |
| 95 | EXPECT_TRUE(klass->GetComponentType() == NULL); |
| 96 | EXPECT_TRUE(klass->GetComponentType() == NULL); |
| 97 | EXPECT_EQ(Class::kStatusResolved, klass->GetStatus()); |
| 98 | EXPECT_FALSE(klass->IsErroneous()); |
| 99 | EXPECT_FALSE(klass->IsVerified()); |
| 100 | EXPECT_TRUE(klass->IsLinked()); |
| 101 | EXPECT_TRUE(klass->IsLoaded()); |
| 102 | EXPECT_TRUE(klass->IsInSamePackage(klass)); |
| 103 | EXPECT_TRUE(Class::IsInSamePackage(klass->GetDescriptor(), klass->GetDescriptor())); |
| 104 | if (klass->IsInterface()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 105 | EXPECT_TRUE(klass->IsAbstract()); |
| 106 | if (klass->NumDirectMethods() == 1) { |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 107 | EXPECT_TRUE(klass->GetDirectMethod(0)->GetName()->Equals("<clinit>")); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 108 | } else { |
| 109 | EXPECT_EQ(0U, klass->NumDirectMethods()); |
| 110 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 111 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 112 | if (!klass->IsSynthetic()) { |
| 113 | EXPECT_NE(0U, klass->NumDirectMethods()); |
| 114 | } |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 115 | } |
| 116 | if (klass->IsAbstract()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 117 | EXPECT_FALSE(klass->IsFinal()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 118 | } else { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 119 | EXPECT_FALSE(klass->IsAnnotation()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 120 | } |
| 121 | if (klass->IsFinal()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 122 | EXPECT_FALSE(klass->IsAbstract()); |
| 123 | EXPECT_FALSE(klass->IsAnnotation()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 124 | } |
| 125 | if (klass->IsAnnotation()) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 126 | EXPECT_FALSE(klass->IsFinal()); |
| 127 | EXPECT_TRUE(klass->IsAbstract()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | EXPECT_FALSE(klass->IsPrimitive()); |
| 131 | EXPECT_TRUE(klass->CanAccess(klass)); |
| 132 | |
| 133 | for (size_t i = 0; i < klass->NumDirectMethods(); i++) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 134 | Method* method = klass->GetDirectMethod(i); |
| 135 | EXPECT_TRUE(method != NULL); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 136 | EXPECT_EQ(klass, method->GetDeclaringClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | for (size_t i = 0; i < klass->NumVirtualMethods(); i++) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 140 | Method* method = klass->GetVirtualMethod(i); |
| 141 | EXPECT_TRUE(method != NULL); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | for (size_t i = 0; i < klass->NumInstanceFields(); i++) { |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 145 | Field* field = klass->GetInstanceField(i); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 146 | EXPECT_TRUE(field != NULL); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 147 | EXPECT_FALSE(field->IsStatic()); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 148 | EXPECT_EQ(klass, field->GetDeclaringClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | for (size_t i = 0; i < klass->NumStaticFields(); i++) { |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 152 | Field* field = klass->GetStaticField(i); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 153 | EXPECT_TRUE(field != NULL); |
Jesse Wilson | fd687c5 | 2011-08-04 19:27:35 -0700 | [diff] [blame] | 154 | EXPECT_TRUE(field->IsStatic()); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 155 | EXPECT_EQ(klass, field->GetDeclaringClass()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | // Confirm that all instances fields are packed together at the start |
| 159 | EXPECT_GE(klass->NumInstanceFields(), klass->NumReferenceInstanceFields()); |
| 160 | for (size_t i = 0; i < klass->NumReferenceInstanceFields(); i++) { |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 161 | Field* field = klass->GetInstanceField(i); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 162 | ASSERT_TRUE(field != NULL); |
| 163 | ASSERT_TRUE(field->GetDescriptor() != NULL); |
| 164 | Class* field_type = class_linker_->FindClass(field->GetDescriptor(), class_loader); |
| 165 | ASSERT_TRUE(field_type != NULL); |
| 166 | EXPECT_FALSE(field_type->IsPrimitive()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 167 | } |
| 168 | for (size_t i = klass->NumReferenceInstanceFields(); i < klass->NumInstanceFields(); i++) { |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 169 | Field* field = klass->GetInstanceField(i); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 170 | ASSERT_TRUE(field != NULL); |
| 171 | ASSERT_TRUE(field->GetDescriptor() != NULL); |
| 172 | Class* field_type = class_linker_->FindClass(field->GetDescriptor(), class_loader); |
| 173 | ASSERT_TRUE(field_type != NULL); |
| 174 | EXPECT_TRUE(field_type->IsPrimitive()); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | size_t total_num_reference_instance_fields = 0; |
| 178 | Class* k = klass; |
| 179 | while (k != NULL) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 180 | total_num_reference_instance_fields += k->NumReferenceInstanceFields(); |
| 181 | k = k->GetSuperClass(); |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 182 | } |
| 183 | EXPECT_EQ(klass->GetReferenceOffsets() == 0, |
| 184 | total_num_reference_instance_fields == 0); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 187 | static void TestRootVisitor(Object* root, void* arg) { |
| 188 | EXPECT_TRUE(root != NULL); |
| 189 | } |
| 190 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 191 | void AssertDexFile(const DexFile* dex, ClassLoader* class_loader) { |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 192 | ASSERT_TRUE(dex != NULL); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 193 | for (size_t i = 0; i < dex->NumClassDefs(); i++) { |
| 194 | const DexFile::ClassDef class_def = dex->GetClassDef(i); |
| 195 | const char* descriptor = dex->GetClassDescriptor(class_def); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 196 | AssertDexFileClass(class_loader, descriptor); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 197 | } |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 198 | class_linker_->VisitRoots(TestRootVisitor, NULL); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 199 | } |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 200 | }; |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 201 | |
| 202 | TEST_F(ClassLinkerTest, FindClassNonexistent) { |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 203 | Class* result1 = class_linker_->FindSystemClass("NoSuchClass;"); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 204 | EXPECT_TRUE(result1 == NULL); |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 205 | Class* result2 = class_linker_->FindSystemClass("LNoSuchClass;"); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 206 | EXPECT_TRUE(result2 == NULL); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 209 | TEST_F(ClassLinkerTest, FindClassNested) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 210 | scoped_ptr<DexFile> dex(OpenDexFileBase64(kNestedDex)); |
| 211 | PathClassLoader* class_loader = AllocPathClassLoader(dex.get()); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 212 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 213 | Class* outer = class_linker_->FindClass("LNested;", class_loader); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 214 | ASSERT_TRUE(outer != NULL); |
| 215 | EXPECT_EQ(0U, outer->NumVirtualMethods()); |
| 216 | EXPECT_EQ(1U, outer->NumDirectMethods()); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 217 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 218 | Class* inner = class_linker_->FindClass("LNested$Inner;", class_loader); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 219 | ASSERT_TRUE(inner != NULL); |
| 220 | EXPECT_EQ(0U, inner->NumVirtualMethods()); |
| 221 | EXPECT_EQ(1U, inner->NumDirectMethods()); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 222 | } |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 223 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 224 | TEST_F(ClassLinkerTest, FindClass) { |
Carl Shapiro | 7a90959 | 2011-07-24 19:21:59 -0700 | [diff] [blame] | 225 | ClassLinker* linker = class_linker_; |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 226 | |
| 227 | StringPiece expected = "BCDFIJSZV"; |
| 228 | for (int ch = 0; ch < 255; ch++) { |
| 229 | char* s = reinterpret_cast<char*>(&ch); |
| 230 | StringPiece descriptor(s, 1); |
| 231 | if (expected.find(ch) == StringPiece::npos) { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 232 | AssertNonExistantClass(descriptor); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 233 | } else { |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 234 | AssertPrimitiveClass(descriptor); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
Elliott Hughes | a5780da | 2011-07-17 11:39:39 -0700 | [diff] [blame] | 237 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 238 | Class* JavaLangObject = linker->FindSystemClass("Ljava/lang/Object;"); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 239 | ASSERT_TRUE(JavaLangObject != NULL); |
Brian Carlstrom | a080803 | 2011-07-18 00:39:23 -0700 | [diff] [blame] | 240 | ASSERT_TRUE(JavaLangObject->GetClass() != NULL); |
| 241 | ASSERT_EQ(JavaLangObject->GetClass(), JavaLangObject->GetClass()->GetClass()); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 242 | EXPECT_EQ(JavaLangObject, JavaLangObject->GetClass()->GetSuperClass()); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame^] | 243 | ASSERT_TRUE(JavaLangObject->GetDescriptor()->Equals("Ljava/lang/Object;")); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 244 | EXPECT_TRUE(JavaLangObject->GetSuperClass() == NULL); |
| 245 | EXPECT_FALSE(JavaLangObject->HasSuperClass()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 246 | EXPECT_TRUE(JavaLangObject->GetClassLoader() == NULL); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 247 | EXPECT_TRUE(JavaLangObject->GetComponentType() == NULL); |
| 248 | EXPECT_FALSE(JavaLangObject->IsErroneous()); |
| 249 | EXPECT_FALSE(JavaLangObject->IsVerified()); |
| 250 | EXPECT_TRUE(JavaLangObject->IsLinked()); |
| 251 | EXPECT_FALSE(JavaLangObject->IsArray()); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 252 | EXPECT_EQ(0, JavaLangObject->array_rank_); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 253 | EXPECT_FALSE(JavaLangObject->IsInterface()); |
| 254 | EXPECT_TRUE(JavaLangObject->IsPublic()); |
| 255 | EXPECT_FALSE(JavaLangObject->IsFinal()); |
| 256 | EXPECT_FALSE(JavaLangObject->IsPrimitive()); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 257 | EXPECT_FALSE(JavaLangObject->IsSynthetic()); |
Elliott Hughes | a5b897e | 2011-08-16 11:33:06 -0700 | [diff] [blame] | 258 | EXPECT_EQ(2U, JavaLangObject->NumDirectMethods()); |
| 259 | EXPECT_EQ(11U, JavaLangObject->NumVirtualMethods()); |
Carl Shapiro | f10edca | 2011-07-14 23:16:21 -0700 | [diff] [blame] | 260 | EXPECT_EQ(0U, JavaLangObject->NumInstanceFields()); |
| 261 | EXPECT_EQ(0U, JavaLangObject->NumStaticFields()); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 262 | EXPECT_EQ(0U, JavaLangObject->NumInterfaces()); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 263 | |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 264 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 265 | scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassDex)); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 266 | PathClassLoader* class_loader = AllocPathClassLoader(dex.get()); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 267 | EXPECT_TRUE(linker->FindSystemClass("LMyClass;") == NULL); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 268 | Class* MyClass = linker->FindClass("LMyClass;", class_loader); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 269 | ASSERT_TRUE(MyClass != NULL); |
Brian Carlstrom | a080803 | 2011-07-18 00:39:23 -0700 | [diff] [blame] | 270 | ASSERT_TRUE(MyClass->GetClass() != NULL); |
| 271 | ASSERT_EQ(MyClass->GetClass(), MyClass->GetClass()->GetClass()); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 272 | EXPECT_EQ(JavaLangObject, MyClass->GetClass()->GetSuperClass()); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame^] | 273 | ASSERT_TRUE(MyClass->GetDescriptor()->Equals("LMyClass;")); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 274 | EXPECT_TRUE(MyClass->GetSuperClass() == JavaLangObject); |
| 275 | EXPECT_TRUE(MyClass->HasSuperClass()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 276 | EXPECT_EQ(class_loader, MyClass->GetClassLoader()); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 277 | EXPECT_TRUE(MyClass->GetComponentType() == NULL); |
| 278 | EXPECT_TRUE(MyClass->GetStatus() == Class::kStatusResolved); |
| 279 | EXPECT_FALSE(MyClass->IsErroneous()); |
| 280 | EXPECT_FALSE(MyClass->IsVerified()); |
| 281 | EXPECT_TRUE(MyClass->IsLinked()); |
| 282 | EXPECT_FALSE(MyClass->IsArray()); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 283 | EXPECT_EQ(0, JavaLangObject->array_rank_); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 284 | EXPECT_FALSE(MyClass->IsInterface()); |
| 285 | EXPECT_FALSE(MyClass->IsPublic()); |
| 286 | EXPECT_FALSE(MyClass->IsFinal()); |
| 287 | EXPECT_FALSE(MyClass->IsPrimitive()); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 288 | EXPECT_FALSE(MyClass->IsSynthetic()); |
Carl Shapiro | f10edca | 2011-07-14 23:16:21 -0700 | [diff] [blame] | 289 | EXPECT_EQ(1U, MyClass->NumDirectMethods()); |
| 290 | EXPECT_EQ(0U, MyClass->NumVirtualMethods()); |
| 291 | EXPECT_EQ(0U, MyClass->NumInstanceFields()); |
| 292 | EXPECT_EQ(0U, MyClass->NumStaticFields()); |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 293 | EXPECT_EQ(0U, MyClass->NumInterfaces()); |
Brian Carlstrom | a080803 | 2011-07-18 00:39:23 -0700 | [diff] [blame] | 294 | |
| 295 | EXPECT_EQ(JavaLangObject->GetClass()->GetClass(), MyClass->GetClass()->GetClass()); |
| 296 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 297 | // created by class_linker |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 298 | AssertArrayClass("[C", 1, "C", NULL); |
| 299 | AssertArrayClass("[Ljava/lang/Object;", 1, "Ljava/lang/Object;", NULL); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 300 | // synthesized on the fly |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 301 | AssertArrayClass("[[C", 2, "C", NULL); |
| 302 | AssertArrayClass("[[[LMyClass;", 3, "LMyClass;", class_loader); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 303 | // or not available at all |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 304 | AssertNonExistantClass("[[[[LNonExistantClass;"); |
| 305 | } |
| 306 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 307 | TEST_F(ClassLinkerTest, LibCore) { |
Jesse Wilson | ac5b9e2 | 2011-07-27 15:11:13 -0400 | [diff] [blame] | 308 | scoped_ptr<DexFile> libcore_dex_file(GetLibCoreDex()); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 309 | EXPECT_TRUE(libcore_dex_file.get() != NULL); |
| 310 | AssertDexFile(libcore_dex_file.get(), NULL); |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 313 | // C++ fields must exactly match the fields in the Java classes. If this fails, |
Jesse Wilson | ac5b9e2 | 2011-07-27 15:11:13 -0400 | [diff] [blame] | 314 | // reorder the fields in the C++ class. Managed class fields are ordered by |
| 315 | // ClassLinker::LinkInstanceFields. |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 316 | TEST_F(ClassLinkerTest, ValidateFieldOrderOfJavaCppUnionClasses) { |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 317 | Class* string = class_linker_->FindSystemClass( "Ljava/lang/String;"); |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 318 | ASSERT_EQ(4U, string->NumInstanceFields()); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 319 | EXPECT_TRUE(string->GetInstanceField(0)->GetName()->Equals("value")); |
| 320 | EXPECT_TRUE(string->GetInstanceField(1)->GetName()->Equals("hashCode")); |
| 321 | EXPECT_TRUE(string->GetInstanceField(2)->GetName()->Equals("offset")); |
| 322 | EXPECT_TRUE(string->GetInstanceField(3)->GetName()->Equals("count")); |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 323 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 324 | Class* accessible_object = class_linker_->FindSystemClass("Ljava/lang/reflect/AccessibleObject;"); |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 325 | ASSERT_EQ(1U, accessible_object->NumInstanceFields()); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 326 | EXPECT_TRUE(accessible_object->GetInstanceField(0)->GetName()->Equals("flag")); |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 327 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 328 | Class* field = class_linker_->FindSystemClass("Ljava/lang/reflect/Field;"); |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 329 | ASSERT_EQ(6U, field->NumInstanceFields()); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 330 | EXPECT_TRUE(field->GetInstanceField(0)->GetName()->Equals("declaringClass")); |
| 331 | EXPECT_TRUE(field->GetInstanceField(1)->GetName()->Equals("genericType")); |
| 332 | EXPECT_TRUE(field->GetInstanceField(2)->GetName()->Equals("type")); |
| 333 | EXPECT_TRUE(field->GetInstanceField(3)->GetName()->Equals("name")); |
| 334 | EXPECT_TRUE(field->GetInstanceField(4)->GetName()->Equals("slot")); |
| 335 | EXPECT_TRUE(field->GetInstanceField(5)->GetName()->Equals("genericTypesAreInitialized")); |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 336 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 337 | Class* method = class_linker_->FindSystemClass("Ljava/lang/reflect/Method;"); |
Jesse Wilson | 46cdd4b | 2011-07-28 17:40:48 -0400 | [diff] [blame] | 338 | ASSERT_EQ(11U, method->NumInstanceFields()); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 339 | EXPECT_TRUE(method->GetInstanceField( 0)->GetName()->Equals("declaringClass")); |
| 340 | EXPECT_TRUE(method->GetInstanceField( 1)->GetName()->Equals("exceptionTypes")); |
| 341 | EXPECT_TRUE(method->GetInstanceField( 2)->GetName()->Equals("formalTypeParameters")); |
| 342 | EXPECT_TRUE(method->GetInstanceField( 3)->GetName()->Equals("genericExceptionTypes")); |
| 343 | EXPECT_TRUE(method->GetInstanceField( 4)->GetName()->Equals("genericParameterTypes")); |
| 344 | EXPECT_TRUE(method->GetInstanceField( 5)->GetName()->Equals("genericReturnType")); |
| 345 | EXPECT_TRUE(method->GetInstanceField( 6)->GetName()->Equals("returnType")); |
| 346 | EXPECT_TRUE(method->GetInstanceField( 7)->GetName()->Equals("name")); |
| 347 | EXPECT_TRUE(method->GetInstanceField( 8)->GetName()->Equals("parameterTypes")); |
| 348 | EXPECT_TRUE(method->GetInstanceField( 9)->GetName()->Equals("genericTypesAreInitialized")); |
| 349 | EXPECT_TRUE(method->GetInstanceField(10)->GetName()->Equals("slot")); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 350 | |
| 351 | Class* class_loader = class_linker_->FindSystemClass("Ljava/lang/ClassLoader;"); |
| 352 | ASSERT_EQ(2U, class_loader->NumInstanceFields()); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 353 | EXPECT_TRUE(class_loader->GetInstanceField(0)->GetName()->Equals("packages")); |
| 354 | EXPECT_TRUE(class_loader->GetInstanceField(1)->GetName()->Equals("parent")); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 355 | |
| 356 | Class* dex_base_class_loader = class_linker_->FindSystemClass("Ldalvik/system/BaseDexClassLoader;"); |
| 357 | ASSERT_EQ(2U, dex_base_class_loader->NumInstanceFields()); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 358 | EXPECT_TRUE(dex_base_class_loader->GetInstanceField(0)->GetName()->Equals("originalPath")); |
| 359 | EXPECT_TRUE(dex_base_class_loader->GetInstanceField(1)->GetName()->Equals("pathList")); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 362 | // The first reference array element must be a multiple of 8 bytes from the |
| 363 | // start of the object |
| 364 | TEST_F(ClassLinkerTest, ValidateObjectArrayElementsOffset) { |
| 365 | Class* array_class = class_linker_->FindSystemClass("[Ljava/lang/String;"); |
| 366 | ObjectArray<String>* array = ObjectArray<String>::Alloc(array_class, 0); |
| 367 | uint32_t array_offset = reinterpret_cast<uint32_t>(array); |
| 368 | uint32_t data_offset = reinterpret_cast<uint32_t>(array->GetData()); |
| 369 | EXPECT_EQ(16U, data_offset - array_offset); |
| 370 | } |
| 371 | |
| 372 | TEST_F(ClassLinkerTest, ValidatePrimitiveArrayElementsOffset) { |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 373 | LongArray* array = LongArray::Alloc(0); |
| 374 | EXPECT_EQ(class_linker_->FindSystemClass("[J"), array->GetClass()); |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 375 | uint32_t array_offset = reinterpret_cast<uint32_t>(array); |
| 376 | uint32_t data_offset = reinterpret_cast<uint32_t>(array->GetData()); |
| 377 | EXPECT_EQ(16U, data_offset - array_offset); |
| 378 | } |
| 379 | |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 380 | TEST_F(ClassLinkerTest, TwoClassLoadersOneClass) { |
| 381 | scoped_ptr<DexFile> dex_1(OpenDexFileBase64(kMyClassDex)); |
| 382 | scoped_ptr<DexFile> dex_2(OpenDexFileBase64(kMyClassDex)); |
| 383 | PathClassLoader* class_loader_1 = AllocPathClassLoader(dex_1.get()); |
| 384 | PathClassLoader* class_loader_2 = AllocPathClassLoader(dex_2.get()); |
| 385 | Class* MyClass_1 = class_linker_->FindClass("LMyClass;", class_loader_1); |
| 386 | Class* MyClass_2 = class_linker_->FindClass("LMyClass;", class_loader_2); |
| 387 | EXPECT_TRUE(MyClass_1 != NULL); |
| 388 | EXPECT_TRUE(MyClass_2 != NULL); |
| 389 | EXPECT_NE(MyClass_1, MyClass_2); |
Jesse Wilson | ac5b9e2 | 2011-07-27 15:11:13 -0400 | [diff] [blame] | 390 | } |
| 391 | |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 392 | TEST_F(ClassLinkerTest, StaticFields) { |
| 393 | // TODO: uncomment expectations of initial values when InitializeClass works |
| 394 | scoped_ptr<DexFile> dex(OpenDexFileBase64(kStatics)); |
| 395 | PathClassLoader* class_loader = AllocPathClassLoader(dex.get()); |
| 396 | Class* statics = class_linker_->FindClass("LStatics;", class_loader); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 397 | // class_linker_->InitializeClass(statics); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 398 | |
| 399 | EXPECT_EQ(10U, statics->NumStaticFields()); |
| 400 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 401 | Field* s0 = statics->GetStaticField(0); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame^] | 402 | EXPECT_TRUE(s0->GetClass()->descriptor_->Equals("Ljava/lang/reflect/Field;")); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 403 | EXPECT_EQ('Z', s0->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 404 | // EXPECT_EQ(true, s0->GetBoolean()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 405 | s0->SetBoolean(false); |
| 406 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 407 | Field* s1 = statics->GetStaticField(1); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 408 | EXPECT_EQ('B', s1->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 409 | // EXPECT_EQ(5, s1->GetByte()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 410 | s1->SetByte(6); |
| 411 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 412 | Field* s2 = statics->GetStaticField(2); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 413 | EXPECT_EQ('C', s2->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 414 | // EXPECT_EQ('a', s2->GetChar()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 415 | s2->SetChar('b'); |
| 416 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 417 | Field* s3 = statics->GetStaticField(3); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 418 | EXPECT_EQ('S', s3->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 419 | // EXPECT_EQ(65000, s3->GetShort()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 420 | s3->SetShort(65001); |
| 421 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 422 | Field* s4 = statics->GetStaticField(4); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 423 | EXPECT_EQ('I', s4->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 424 | // EXPECT_EQ(2000000000, s4->GetInt()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 425 | s4->SetInt(2000000001); |
| 426 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 427 | Field* s5 = statics->GetStaticField(5); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 428 | EXPECT_EQ('J', s5->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 429 | // EXPECT_EQ(0x1234567890abcdefLL, s5->GetLong()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 430 | s5->SetLong(0x34567890abcdef12LL); |
| 431 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 432 | Field* s6 = statics->GetStaticField(6); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 433 | EXPECT_EQ('F', s6->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 434 | // EXPECT_EQ(0.5, s6->GetFloat()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 435 | s6->SetFloat(0.75); |
| 436 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 437 | Field* s7 = statics->GetStaticField(7); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 438 | EXPECT_EQ('D', s7->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 439 | // EXPECT_EQ(16777217, s7->GetDouble()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 440 | s7->SetDouble(16777219); |
| 441 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 442 | Field* s8 = statics->GetStaticField(8); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 443 | EXPECT_EQ('L', s8->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 444 | // EXPECT_TRUE(down_cast<String*>(s8->GetObject())->Equals("android")); // TODO: uncomment this |
Elliott Hughes | bfaadc8 | 2011-08-18 17:36:58 -0700 | [diff] [blame] | 445 | s8->SetObject(String::AllocFromModifiedUtf8("robot")); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 446 | |
Jesse Wilson | 35baaab | 2011-08-10 16:18:03 -0400 | [diff] [blame] | 447 | Field* s9 = statics->GetStaticField(9); |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 448 | EXPECT_EQ('[', s9->GetType()); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 449 | // EXPECT_EQ(NULL, s9->GetObject()); // TODO: uncomment this |
Jesse Wilson | 7833bd2 | 2011-08-09 18:31:44 -0400 | [diff] [blame] | 450 | s9->SetObject(NULL); |
| 451 | |
| 452 | EXPECT_EQ(false, s0->GetBoolean()); |
| 453 | EXPECT_EQ(6, s1->GetByte()); |
| 454 | EXPECT_EQ('b', s2->GetChar()); |
| 455 | EXPECT_EQ(65001, s3->GetShort()); |
| 456 | EXPECT_EQ(2000000001, s4->GetInt()); |
| 457 | EXPECT_EQ(0x34567890abcdef12LL, s5->GetLong()); |
| 458 | EXPECT_EQ(0.75, s6->GetFloat()); |
| 459 | EXPECT_EQ(16777219, s7->GetDouble()); |
| 460 | EXPECT_TRUE(down_cast<String*>(s8->GetObject())->Equals("robot")); |
| 461 | } |
| 462 | |
Jesse Wilson | df4189c | 2011-08-09 17:10:28 -0400 | [diff] [blame] | 463 | } // namespace art |