blob: 9961df9a558214101cbd9e8755e143848af05d58 [file] [log] [blame]
Brian Carlstrom265091e2013-01-30 14:08:26 -08001/*
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 */
16
17#include "dex_method_iterator.h"
18
19#include "common_test.h"
20
21namespace art {
22
Ian Rogers8d31bbd2013-10-13 10:44:14 -070023class DexMethodIteratorTest : public CommonTest {
24 public:
25 const DexFile* OpenDexFile(const std::string& partial_filename) {
26 std::string dfn = GetDexFileName(partial_filename);
27 std::string error_msg;
28 const DexFile* dexfile = DexFile::Open(dfn.c_str(), dfn.c_str(), &error_msg);
29 if (dexfile == nullptr) {
30 LG << "Failed to open '" << dfn << "': " << error_msg;
31 }
32 return dexfile;
33 }
34};
Brian Carlstrom265091e2013-01-30 14:08:26 -080035
36TEST_F(DexMethodIteratorTest, Basic) {
37 ScopedObjectAccess soa(Thread::Current());
38 std::vector<const DexFile*> dex_files;
Ian Rogers8d31bbd2013-10-13 10:44:14 -070039 dex_files.push_back(OpenDexFile("core"));
40 dex_files.push_back(OpenDexFile("conscrypt"));
41 dex_files.push_back(OpenDexFile("okhttp"));
42 dex_files.push_back(OpenDexFile("core-junit"));
43 dex_files.push_back(OpenDexFile("bouncycastle"));
Brian Carlstrom265091e2013-01-30 14:08:26 -080044 DexMethodIterator it(dex_files);
45 while (it.HasNext()) {
46 const DexFile& dex_file = it.GetDexFile();
47 InvokeType invoke_type = it.GetInvokeType();
48 uint32_t method_idx = it.GetMemberIndex();
49 if (false) {
50 LG << invoke_type << " " << PrettyMethod(method_idx, dex_file);
51 }
52 it.Next();
53 }
54 STLDeleteElements(&dex_files);
55}
56
57} // namespace art