2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sys/types.h>
24 #include "common_runtime_test.h"
25 #include "runtime/arch/instruction_set.h"
26 #include "runtime/exec_utils.h"
27 #include "runtime/os.h"
28 #include "runtime/utils.h"
33 class DexDumpTest : public CommonRuntimeTest {
35 virtual void SetUp() {
36 CommonRuntimeTest::SetUp();
37 // Dogfood our own lib core dex file.
38 dex_file_ = GetLibCoreDexFileNames()[0];
41 // Runs test with given arguments.
42 bool Exec(const std::vector<std::string>& args, std::string* error_msg) {
43 // TODO(ajcbik): dexdump2 -> dexdump
44 std::string file_path = GetTestAndroidRoot() + "/bin/dexdump2";
45 EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path";
46 std::vector<std::string> exec_argv = { file_path };
47 exec_argv.insert(exec_argv.end(), args.begin(), args.end());
48 return ::art::Exec(exec_argv, error_msg);
51 std::string dex_file_;
55 TEST_F(DexDumpTest, NoInputFileGiven) {
56 std::string error_msg;
57 ASSERT_FALSE(Exec({}, &error_msg)) << error_msg;
60 TEST_F(DexDumpTest, CantOpenOutput) {
61 std::string error_msg;
62 ASSERT_FALSE(Exec({"-o", "/joho", dex_file_}, &error_msg)) << error_msg;
65 TEST_F(DexDumpTest, BadFlagCombination) {
66 std::string error_msg;
67 ASSERT_FALSE(Exec({"-c", "-i", dex_file_}, &error_msg)) << error_msg;
70 TEST_F(DexDumpTest, FullPlainOutput) {
71 std::string error_msg;
72 ASSERT_TRUE(Exec({"-d", "-f", "-h", "-l", "plain", "-o", "/dev/null",
73 dex_file_}, &error_msg)) << error_msg;
76 TEST_F(DexDumpTest, XMLOutput) {
77 std::string error_msg;
78 ASSERT_TRUE(Exec({"-l", "xml", "-o", "/dev/null",
79 dex_file_}, &error_msg)) << error_msg;