3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
20using ::bb::avm2::testing::InstructionBuilder;
22using ::testing::ElementsAre;
23using ::testing::ReturnRef;
24using ::testing::StrictMock;
26template <
typename T>
auto from = ::bb::avm2::simulation::Operand::from<T>;
28TEST(AvmSimulationAddressingTest, AllDirectAndNonRelative)
34 StrictMock<MockGreaterThan>
gt;
39 const auto instr = InstructionBuilder(
SET_8)
49 StrictMock<MockMemory>
memory;
51 const auto operands = addressing.resolve(instr, memory);
55 from<MemoryAddress>(1),
59 instr.operands.at(2)));
62 const auto instr = InstructionBuilder(
ADD_16)
72 StrictMock<MockMemory>
memory;
74 const auto operands = addressing.resolve(instr, memory);
75 EXPECT_THAT(operands, ElementsAre(from<MemoryAddress>(1), from<MemoryAddress>(2), from<MemoryAddress>(3)));
79TEST(AvmSimulationAddressingTest, RelativeAddressing)
83 StrictMock<MockGreaterThan>
gt;
88 MemoryValue base_addr = MemoryValue::from<uint32_t>(100);
91 const auto instr = InstructionBuilder(
ADD_8)
102 StrictMock<MockMemory>
memory;
103 EXPECT_CALL(memory,
get(0)).WillOnce(ReturnRef(base_addr));
107 const auto operands = addressing.resolve(instr, memory);
109 EXPECT_THAT(operands,
112 from<MemoryAddress>(110),
114 from<MemoryAddress>(20),
116 from<MemoryAddress>(130)));
119TEST(AvmSimulationAddressingTest, IndirectAddressing)
124 StrictMock<MockGreaterThan>
gt;
128 const auto instr = InstructionBuilder(
ADD_8)
133 .operand<uint8_t>(10)
135 .operand<uint8_t>(15)
139 StrictMock<MockMemory>
memory;
140 MemoryValue addr_5_value = MemoryValue::from<uint32_t>(50);
141 EXPECT_CALL(memory,
get(5)).WillOnce(ReturnRef(addr_5_value));
142 MemoryValue addr_15_value = MemoryValue::from<uint32_t>(60);
143 EXPECT_CALL(memory,
get(15)).WillOnce(ReturnRef(addr_15_value));
145 const auto operands = addressing.resolve(instr, memory);
148 EXPECT_THAT(operands,
151 from<MemoryAddress>(50),
153 from<MemoryAddress>(10),
155 from<MemoryAddress>(60)));
158TEST(AvmSimulationAddressingTest, IndirectAndRelativeAddressing)
162 StrictMock<MockGreaterThan>
gt;
166 MemoryValue base_addr = MemoryValue::from<uint32_t>(100);
169 const auto instr = InstructionBuilder(
ADD_8)
175 .operand<uint8_t>(10)
178 .operand<uint8_t>(15)
182 StrictMock<MockMemory>
memory;
183 EXPECT_CALL(memory,
get(0)).WillOnce(ReturnRef(base_addr));
185 MemoryValue addr_105_value = MemoryValue::from<uint32_t>(200);
186 EXPECT_CALL(memory,
get(105)).WillOnce(ReturnRef(addr_105_value));
188 MemoryValue addr_10_value = MemoryValue::from<uint32_t>(60);
189 EXPECT_CALL(memory,
get(10)).WillOnce(ReturnRef(addr_10_value));
193 const auto operands = addressing.resolve(instr, memory);
196 EXPECT_THAT(operands,
199 from<MemoryAddress>(200),
201 from<MemoryAddress>(60),
203 from<MemoryAddress>(115)));
#define AVM_HIGHEST_MEM_ADDRESS
EventEmitter< DataCopyEvent > event_emitter
InstructionInfoDB instruction_info_db
TEST(EmitUnencryptedLogTest, Basic)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept