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