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 | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "dex_file.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 18 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 19 | #include "UniquePtr.h" |
| 20 | #include "common_test.h" |
| 21 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 22 | namespace art { |
| 23 | |
Brian Carlstrom | 9f30b38 | 2011-08-28 22:41:38 -0700 | [diff] [blame] | 24 | class DexFileTest : public CommonTest {}; |
| 25 | |
| 26 | TEST_F(DexFileTest, Open) { |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 27 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 4d6850c | 2012-01-18 15:55:06 -0800 | [diff] [blame] | 28 | const DexFile* dex(OpenTestDexFile("Nested")); |
| 29 | ASSERT_TRUE(dex != NULL); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 30 | } |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 31 | |
Brian Carlstrom | 9f30b38 | 2011-08-28 22:41:38 -0700 | [diff] [blame] | 32 | // Although this is the same content logically as the Nested test dex, |
| 33 | // the DexFileHeader test is sensitive to subtle changes in the |
| 34 | // contents due to the checksum etc, so we embed the exact input here. |
| 35 | // |
| 36 | // class Nested { |
| 37 | // class Inner { |
| 38 | // } |
| 39 | // } |
| 40 | static const char kRawDex[] = |
| 41 | "ZGV4CjAzNQAQedgAe7gM1B/WHsWJ6L7lGAISGC7yjD2IAwAAcAAAAHhWNBIAAAAAAAAAAMQCAAAP" |
| 42 | "AAAAcAAAAAcAAACsAAAAAgAAAMgAAAABAAAA4AAAAAMAAADoAAAAAgAAAAABAABIAgAAQAEAAK4B" |
| 43 | "AAC2AQAAvQEAAM0BAADXAQAA+wEAABsCAAA+AgAAUgIAAF8CAABiAgAAZgIAAHMCAAB5AgAAgQIA" |
| 44 | "AAIAAAADAAAABAAAAAUAAAAGAAAABwAAAAkAAAAJAAAABgAAAAAAAAAKAAAABgAAAKgBAAAAAAEA" |
| 45 | "DQAAAAAAAQAAAAAAAQAAAAAAAAAFAAAAAAAAAAAAAAAAAAAABQAAAAAAAAAIAAAAiAEAAKsCAAAA" |
| 46 | "AAAAAQAAAAAAAAAFAAAAAAAAAAgAAACYAQAAuAIAAAAAAAACAAAAlAIAAJoCAAABAAAAowIAAAIA" |
| 47 | "AgABAAAAiAIAAAYAAABbAQAAcBACAAAADgABAAEAAQAAAI4CAAAEAAAAcBACAAAADgBAAQAAAAAA" |
| 48 | "AAAAAAAAAAAATAEAAAAAAAAAAAAAAAAAAAEAAAABAAY8aW5pdD4ABUlubmVyAA5MTmVzdGVkJElu" |
| 49 | "bmVyOwAITE5lc3RlZDsAIkxkYWx2aWsvYW5ub3RhdGlvbi9FbmNsb3NpbmdDbGFzczsAHkxkYWx2" |
| 50 | "aWsvYW5ub3RhdGlvbi9Jbm5lckNsYXNzOwAhTGRhbHZpay9hbm5vdGF0aW9uL01lbWJlckNsYXNz" |
| 51 | "ZXM7ABJMamF2YS9sYW5nL09iamVjdDsAC05lc3RlZC5qYXZhAAFWAAJWTAALYWNjZXNzRmxhZ3MA" |
| 52 | "BG5hbWUABnRoaXMkMAAFdmFsdWUAAgEABw4AAQAHDjwAAgIBDhgBAgMCCwQADBcBAgQBDhwBGAAA" |
| 53 | "AQEAAJAgAICABNQCAAABAAGAgATwAgAAEAAAAAAAAAABAAAAAAAAAAEAAAAPAAAAcAAAAAIAAAAH" |
| 54 | "AAAArAAAAAMAAAACAAAAyAAAAAQAAAABAAAA4AAAAAUAAAADAAAA6AAAAAYAAAACAAAAAAEAAAMQ" |
| 55 | "AAACAAAAQAEAAAEgAAACAAAAVAEAAAYgAAACAAAAiAEAAAEQAAABAAAAqAEAAAIgAAAPAAAArgEA" |
| 56 | "AAMgAAACAAAAiAIAAAQgAAADAAAAlAIAAAAgAAACAAAAqwIAAAAQAAABAAAAxAIAAA=="; |
| 57 | |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 58 | static const DexFile* OpenDexFileBase64(const char* base64, |
| 59 | const std::string& location) { |
| 60 | // decode base64 |
| 61 | CHECK(base64 != NULL); |
| 62 | size_t length; |
| 63 | UniquePtr<byte[]> dex_bytes(DecodeBase64(base64, &length)); |
| 64 | CHECK(dex_bytes.get() != NULL); |
| 65 | |
| 66 | // write to provided file |
Brian Carlstrom | 7571e8b | 2013-08-12 17:04:14 -0700 | [diff] [blame] | 67 | UniquePtr<File> file(OS::CreateEmptyFile(location.c_str())); |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 68 | CHECK(file.get() != NULL); |
| 69 | if (!file->WriteFully(dex_bytes.get(), length)) { |
| 70 | PLOG(FATAL) << "Failed to write base64 as dex file"; |
| 71 | } |
| 72 | file.reset(); |
| 73 | |
| 74 | // read dex file |
| 75 | ScopedObjectAccess soa(Thread::Current()); |
| 76 | const DexFile* dex_file = DexFile::Open(location, location); |
| 77 | CHECK(dex_file != NULL); |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 78 | EXPECT_EQ(PROT_READ, dex_file->GetPermissions()); |
| 79 | EXPECT_TRUE(dex_file->IsReadOnly()); |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 80 | return dex_file; |
| 81 | } |
| 82 | |
Brian Carlstrom | 9f30b38 | 2011-08-28 22:41:38 -0700 | [diff] [blame] | 83 | TEST_F(DexFileTest, Header) { |
Brian Carlstrom | 33f741e | 2011-10-03 11:24:05 -0700 | [diff] [blame] | 84 | ScratchFile tmp; |
| 85 | UniquePtr<const DexFile> raw(OpenDexFileBase64(kRawDex, tmp.GetFilename())); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 86 | ASSERT_TRUE(raw.get() != NULL); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 87 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 88 | const DexFile::Header& header = raw->GetHeader(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 89 | // TODO: header.magic_ |
| 90 | EXPECT_EQ(0x00d87910U, header.checksum_); |
| 91 | // TODO: header.signature_ |
| 92 | EXPECT_EQ(904U, header.file_size_); |
| 93 | EXPECT_EQ(112U, header.header_size_); |
| 94 | EXPECT_EQ(0U, header.link_size_); |
| 95 | EXPECT_EQ(0U, header.link_off_); |
| 96 | EXPECT_EQ(15U, header.string_ids_size_); |
| 97 | EXPECT_EQ(112U, header.string_ids_off_); |
| 98 | EXPECT_EQ(7U, header.type_ids_size_); |
| 99 | EXPECT_EQ(172U, header.type_ids_off_); |
| 100 | EXPECT_EQ(2U, header.proto_ids_size_); |
| 101 | EXPECT_EQ(200U, header.proto_ids_off_); |
| 102 | EXPECT_EQ(1U, header.field_ids_size_); |
| 103 | EXPECT_EQ(224U, header.field_ids_off_); |
| 104 | EXPECT_EQ(3U, header.method_ids_size_); |
| 105 | EXPECT_EQ(232U, header.method_ids_off_); |
| 106 | EXPECT_EQ(2U, header.class_defs_size_); |
| 107 | EXPECT_EQ(256U, header.class_defs_off_); |
| 108 | EXPECT_EQ(584U, header.data_size_); |
| 109 | EXPECT_EQ(320U, header.data_off_); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 110 | |
| 111 | EXPECT_EQ(header.checksum_, raw->GetLocationChecksum()); |
| 112 | } |
| 113 | |
| 114 | TEST_F(DexFileTest, GetLocationChecksum) { |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 115 | ScopedObjectAccess soa(Thread::Current()); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 116 | const DexFile* raw(OpenTestDexFile("Main")); |
| 117 | EXPECT_NE(raw->GetHeader().checksum_, raw->GetLocationChecksum()); |
| 118 | } |
| 119 | |
| 120 | TEST_F(DexFileTest, GetChecksum) { |
| 121 | uint32_t checksum; |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 122 | ScopedObjectAccess soa(Thread::Current()); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 123 | EXPECT_TRUE(DexFile::GetChecksum(GetLibCoreDexFileName(), checksum)); |
| 124 | EXPECT_EQ(java_lang_dex_file_->GetLocationChecksum(), checksum); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Brian Carlstrom | 9f30b38 | 2011-08-28 22:41:38 -0700 | [diff] [blame] | 127 | TEST_F(DexFileTest, ClassDefs) { |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 128 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 4d6850c | 2012-01-18 15:55:06 -0800 | [diff] [blame] | 129 | const DexFile* raw(OpenTestDexFile("Nested")); |
| 130 | ASSERT_TRUE(raw != NULL); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 131 | EXPECT_EQ(2U, raw->NumClassDefs()); |
| 132 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 133 | const DexFile::ClassDef& c0 = raw->GetClassDef(0); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 134 | EXPECT_STREQ("LNested$Inner;", raw->GetClassDescriptor(c0)); |
| 135 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 136 | const DexFile::ClassDef& c1 = raw->GetClassDef(1); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 137 | EXPECT_STREQ("LNested;", raw->GetClassDescriptor(c1)); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 140 | TEST_F(DexFileTest, GetMethodSignature) { |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 141 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 142 | const DexFile* raw(OpenTestDexFile("GetMethodSignature")); |
Elliott Hughes | 4d6850c | 2012-01-18 15:55:06 -0800 | [diff] [blame] | 143 | ASSERT_TRUE(raw != NULL); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 144 | EXPECT_EQ(1U, raw->NumClassDefs()); |
| 145 | |
| 146 | const DexFile::ClassDef& class_def = raw->GetClassDef(0); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 147 | ASSERT_STREQ("LGetMethodSignature;", raw->GetClassDescriptor(class_def)); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 148 | |
| 149 | const byte* class_data = raw->GetClassData(class_def); |
| 150 | ASSERT_TRUE(class_data != NULL); |
Elliott Hughes | 4d6850c | 2012-01-18 15:55:06 -0800 | [diff] [blame] | 151 | ClassDataItemIterator it(*raw, class_data); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 152 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 153 | EXPECT_EQ(1u, it.NumDirectMethods()); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 154 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 155 | // Check the signature for the static initializer. |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 156 | { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 157 | ASSERT_EQ(1U, it.NumDirectMethods()); |
| 158 | const DexFile::MethodId& method_id = raw->GetMethodId(it.GetMemberIndex()); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 159 | const char* name = raw->StringDataByIdx(method_id.name_idx_); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 160 | ASSERT_STREQ("<init>", name); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 161 | std::string signature(raw->GetMethodSignature(method_id).ToString()); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 162 | ASSERT_EQ("()V", signature); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | // Check both virtual methods. |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 166 | ASSERT_EQ(2U, it.NumVirtualMethods()); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 167 | { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 168 | it.Next(); |
| 169 | const DexFile::MethodId& method_id = raw->GetMethodId(it.GetMemberIndex()); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 170 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 171 | const char* name = raw->StringDataByIdx(method_id.name_idx_); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 172 | ASSERT_STREQ("m1", name); |
| 173 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 174 | std::string signature(raw->GetMethodSignature(method_id).ToString()); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 175 | ASSERT_EQ("(IDJLjava/lang/Object;)Ljava/lang/Float;", signature); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 179 | it.Next(); |
| 180 | const DexFile::MethodId& method_id = raw->GetMethodId(it.GetMemberIndex()); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 181 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 182 | const char* name = raw->StringDataByIdx(method_id.name_idx_); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 183 | ASSERT_STREQ("m2", name); |
| 184 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 185 | std::string signature(raw->GetMethodSignature(method_id).ToString()); |
| 186 | ASSERT_EQ("(ZSC)LGetMethodSignature;", signature); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
| 190 | TEST_F(DexFileTest, FindStringId) { |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 191 | ScopedObjectAccess soa(Thread::Current()); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 192 | const DexFile* raw(OpenTestDexFile("GetMethodSignature")); |
Elliott Hughes | 4d6850c | 2012-01-18 15:55:06 -0800 | [diff] [blame] | 193 | ASSERT_TRUE(raw != NULL); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 194 | EXPECT_EQ(1U, raw->NumClassDefs()); |
| 195 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 196 | const char* strings[] = { "LGetMethodSignature;", "Ljava/lang/Float;", "Ljava/lang/Object;", |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 197 | "D", "I", "J", NULL }; |
| 198 | for (size_t i = 0; strings[i] != NULL; i++) { |
| 199 | const char* str = strings[i]; |
| 200 | const DexFile::StringId* str_id = raw->FindStringId(str); |
| 201 | const char* dex_str = raw->GetStringData(*str_id); |
| 202 | EXPECT_STREQ(dex_str, str); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | TEST_F(DexFileTest, FindTypeId) { |
| 207 | for (size_t i = 0; i < java_lang_dex_file_->NumTypeIds(); i++) { |
| 208 | const char* type_str = java_lang_dex_file_->StringByTypeIdx(i); |
| 209 | const DexFile::StringId* type_str_id = java_lang_dex_file_->FindStringId(type_str); |
| 210 | ASSERT_TRUE(type_str_id != NULL); |
| 211 | uint32_t type_str_idx = java_lang_dex_file_->GetIndexForStringId(*type_str_id); |
| 212 | const DexFile::TypeId* type_id = java_lang_dex_file_->FindTypeId(type_str_idx); |
| 213 | ASSERT_TRUE(type_id != NULL); |
| 214 | EXPECT_EQ(java_lang_dex_file_->GetIndexForTypeId(*type_id), i); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | TEST_F(DexFileTest, FindProtoId) { |
| 219 | for (size_t i = 0; i < java_lang_dex_file_->NumProtoIds(); i++) { |
| 220 | const DexFile::ProtoId& to_find = java_lang_dex_file_->GetProtoId(i); |
| 221 | const DexFile::TypeList* to_find_tl = java_lang_dex_file_->GetProtoParameters(to_find); |
| 222 | std::vector<uint16_t> to_find_types; |
| 223 | if (to_find_tl != NULL) { |
| 224 | for (size_t j = 0; j < to_find_tl->Size(); j++) { |
| 225 | to_find_types.push_back(to_find_tl->GetTypeItem(j).type_idx_); |
| 226 | } |
| 227 | } |
| 228 | const DexFile::ProtoId* found = |
| 229 | java_lang_dex_file_->FindProtoId(to_find.return_type_idx_, to_find_types); |
| 230 | ASSERT_TRUE(found != NULL); |
| 231 | EXPECT_EQ(java_lang_dex_file_->GetIndexForProtoId(*found), i); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | TEST_F(DexFileTest, FindMethodId) { |
| 236 | for (size_t i = 0; i < java_lang_dex_file_->NumMethodIds(); i++) { |
| 237 | const DexFile::MethodId& to_find = java_lang_dex_file_->GetMethodId(i); |
| 238 | const DexFile::TypeId& klass = java_lang_dex_file_->GetTypeId(to_find.class_idx_); |
| 239 | const DexFile::StringId& name = java_lang_dex_file_->GetStringId(to_find.name_idx_); |
| 240 | const DexFile::ProtoId& signature = java_lang_dex_file_->GetProtoId(to_find.proto_idx_); |
| 241 | const DexFile::MethodId* found = java_lang_dex_file_->FindMethodId(klass, name, signature); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 242 | ASSERT_TRUE(found != NULL) << "Didn't find method " << i << ": " |
| 243 | << java_lang_dex_file_->StringByTypeIdx(to_find.class_idx_) << "." |
| 244 | << java_lang_dex_file_->GetStringData(name) |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame^] | 245 | << java_lang_dex_file_->GetMethodSignature(to_find); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 246 | EXPECT_EQ(java_lang_dex_file_->GetIndexForMethodId(*found), i); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 247 | } |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 250 | TEST_F(DexFileTest, FindFieldId) { |
| 251 | for (size_t i = 0; i < java_lang_dex_file_->NumFieldIds(); i++) { |
| 252 | const DexFile::FieldId& to_find = java_lang_dex_file_->GetFieldId(i); |
| 253 | const DexFile::TypeId& klass = java_lang_dex_file_->GetTypeId(to_find.class_idx_); |
| 254 | const DexFile::StringId& name = java_lang_dex_file_->GetStringId(to_find.name_idx_); |
| 255 | const DexFile::TypeId& type = java_lang_dex_file_->GetTypeId(to_find.type_idx_); |
| 256 | const DexFile::FieldId* found = java_lang_dex_file_->FindFieldId(klass, name, type); |
| 257 | ASSERT_TRUE(found != NULL) << "Didn't find field " << i << ": " |
| 258 | << java_lang_dex_file_->StringByTypeIdx(to_find.type_idx_) << " " |
| 259 | << java_lang_dex_file_->StringByTypeIdx(to_find.class_idx_) << "." |
| 260 | << java_lang_dex_file_->GetStringData(name); |
| 261 | EXPECT_EQ(java_lang_dex_file_->GetIndexForFieldId(*found), i); |
| 262 | } |
| 263 | } |
| 264 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 265 | } // namespace art |