/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include "DwarfOp.h" #include "MemoryFake.h" namespace unwindstack { template class DwarfOpLogTest : public ::testing::Test { protected: void SetUp() override { op_memory_.Clear(); regular_memory_.Clear(); mem_.reset(new DwarfMemory(&op_memory_)); op_.reset(new DwarfOp(mem_.get(), ®ular_memory_)); } MemoryFake op_memory_; MemoryFake regular_memory_; std::unique_ptr mem_; std::unique_ptr> op_; }; TYPED_TEST_SUITE_P(DwarfOpLogTest); TYPED_TEST_P(DwarfOpLogTest, multiple_ops) { // Multi operation opcodes. std::vector opcode_buffer = { 0x0a, 0x20, 0x10, 0x08, 0x03, 0x12, 0x27, }; this->op_memory_.SetMemory(0, opcode_buffer); std::vector lines; this->op_->GetLogInfo(0, opcode_buffer.size(), &lines); std::vector expected{ "DW_OP_const2u 4128", "Raw Data: 0x0a 0x20 0x10", "DW_OP_const1u 3", "Raw Data: 0x08 0x03", "DW_OP_dup", "Raw Data: 0x12", "DW_OP_xor", "Raw Data: 0x27"}; ASSERT_EQ(expected, lines); } REGISTER_TYPED_TEST_SUITE_P(DwarfOpLogTest, multiple_ops); typedef ::testing::Types DwarfOpLogTestTypes; INSTANTIATE_TYPED_TEST_SUITE_P(Libunwindstack, DwarfOpLogTest, DwarfOpLogTestTypes); } // namespace unwindstack