1#ifndef YAZE_TEST_MOCK_MOCK_MEMORY_H
2#define YAZE_TEST_MOCK_MOCK_MEMORY_H
4#include <gmock/gmock.h>
5#include <gtest/gtest.h>
51 (uint32_t address, uint16_t length), (
const,
override));
91 if (data.size() >
memory_.size()) {
94 std::copy(data.begin(), data.end(),
memory_.begin());
98 if (data.size() >
memory_.size()) {
102 for (
const auto& each : data) {
104 memory_[i + 1] = (each >> 8) & 0xFF;
109 void InsertMemory(
const uint64_t address,
const std::vector<uint8_t>& data) {
110 if (address >
memory_.size()) {
111 memory_.resize(address + data.size());
115 for (
const auto& each : data) {
131 size_t romSize = romData.size();
132 size_t romAddress = 0;
133 const size_t ROM_CHUNK_SIZE = 0x8000;
134 for (
size_t bank = 0x00; bank <= 0xBF; bank += 0x80) {
135 for (
size_t offset = 0x8000; offset <= 0xFFFF; offset += ROM_CHUNK_SIZE) {
136 if (romAddress < romSize) {
137 std::copy(romData.begin() + romAddress,
138 romData.begin() + romAddress + ROM_CHUNK_SIZE,
139 memory_.begin() + (bank << 16) + offset);
140 romAddress += ROM_CHUNK_SIZE;
147 ON_CALL(*
this,
ReadByte(::testing::_))
149 [
this](uint32_t address) {
return memory_.at(address); });
150 ON_CALL(*
this,
ReadWord(::testing::_))
151 .WillByDefault([
this](uint32_t address) {
152 return static_cast<uint16_t
>(
memory_.at(address)) |
153 (
static_cast<uint16_t
>(
memory_.at(address + 1)) << 8);
156 .WillByDefault([
this](uint32_t address) {
157 return static_cast<uint32_t
>(
memory_.at(address)) |
158 (
static_cast<uint32_t
>(
memory_.at(address + 1)) << 8) |
159 (
static_cast<uint32_t
>(
memory_.at(address + 2)) << 16);
162 .WillByDefault([
this](uint32_t address, uint16_t length) {
163 std::vector<uint8_t> data;
164 for (
int i = 0; i < length; i++) {
165 data.push_back(
memory_.at(address + i));
169 ON_CALL(*
this,
WriteByte(::testing::_, ::testing::_))
170 .WillByDefault([
this](uint32_t address, uint8_t value) {
173 ON_CALL(*
this,
WriteWord(::testing::_, ::testing::_))
174 .WillByDefault([
this](uint32_t address, uint16_t value) {
175 memory_[address] = value & 0xFF;
176 memory_[address + 1] = (value >> 8) & 0xFF;
178 ON_CALL(*
this,
PushByte(::testing::_)).WillByDefault([
this](uint8_t value) {
181 ON_CALL(*
this,
PopByte()).WillByDefault([
this]() {
186 ON_CALL(*
this,
PushWord(::testing::_))
187 .WillByDefault([
this](uint16_t value) {
192 ON_CALL(*
this,
PopWord()).WillByDefault([
this]() {
193 uint16_t value =
static_cast<uint16_t
>(
memory_.at(
SP_)) |
194 (
static_cast<uint16_t
>(
memory_.at(
SP_ + 1)) << 8);
198 ON_CALL(*
this,
PushLong(::testing::_))
199 .WillByDefault([
this](uint32_t value) {
204 ON_CALL(*
this,
PopLong()).WillByDefault([
this]() {
205 uint32_t value =
static_cast<uint32_t
>(
memory_.at(
SP_)) |
206 (
static_cast<uint32_t
>(
memory_.at(
SP_ + 1)) << 8) |
207 (
static_cast<uint32_t
>(
memory_.at(
SP_ + 2)) << 16);
211 ON_CALL(*
this,
SP()).WillByDefault([
this]() {
return SP_; });
212 ON_CALL(*
this,
SetSP(::testing::_)).WillByDefault([
this](uint16_t value) {
215 ON_CALL(*
this,
ClearMemory()).WillByDefault([
this]() {
virtual float GetFrequency() const =0
virtual void SetFrequency(float new_frequency)=0
virtual void UpdateClock(double delta)=0
virtual void ResetAccumulatedTime()=0
virtual unsigned long long GetCycleCount() const =0
virtual std::vector< uint8_t > ReadByteVector(uint32_t address, uint16_t length) const =0
virtual void PushLong(uint32_t value)=0
virtual void WriteLong(uint32_t address, uint32_t value)=0
virtual void set_pal_timing(bool value)=0
virtual void PushByte(uint8_t value)=0
virtual uint16_t SP() const =0
virtual void set_v_pos(uint16_t value)=0
virtual void SetSP(uint16_t value)=0
virtual void PushWord(uint16_t value)=0
virtual auto v_pos() const -> uint16_t=0
virtual void WriteByte(uint32_t address, uint8_t value)=0
virtual void set_hdma_run_requested(bool value)=0
virtual uint8_t at(int i) const =0
virtual uint8_t open_bus() const =0
virtual void WriteWord(uint32_t address, uint16_t value)=0
virtual void set_h_pos(uint16_t value)=0
virtual void run_hdma_request()=0
virtual bool hdma_run_requested() const =0
virtual uint8_t ReadByte(uint32_t address) const =0
virtual auto h_pos() const -> uint16_t=0
virtual void set_hdma_init_requested(bool value)=0
virtual uint32_t PopLong()=0
virtual uint16_t ReadWord(uint32_t address) const =0
virtual uint32_t ReadWordLong(uint32_t address) const =0
virtual void init_hdma_request()=0
virtual uint8_t PopByte()=0
virtual uint16_t PopWord()=0
virtual void ClearMemory()=0
virtual auto pal_timing() const -> bool=0
virtual void set_open_bus(uint8_t value)=0
virtual bool hdma_init_requested() const =0
Mock CPU class for testing.
MOCK_METHOD(void, UpdateClock,(double delta),(override))
MOCK_METHOD(void, SetFrequency,(float new_frequency),(override))
MOCK_METHOD(void, ResetAccumulatedTime,(),(override))
MOCK_METHOD(float, GetFrequency,(),(const, override))
MOCK_METHOD(unsigned long long, GetCycleCount,(),(const, override))
A mock implementation of the Memory class.
std::vector< uint8_t > memory_
MOCK_METHOD0(PopByte, uint8_t())
MOCK_METHOD0(PopLong, uint32_t())
MOCK_METHOD1(set_pal_timing, void(bool value))
void SetMemoryContents(const std::vector< uint8_t > &data)
MOCK_METHOD1(set_open_bus, void(uint8_t value))
MOCK_METHOD1(set_v_pos, void(uint16_t value))
MOCK_METHOD2(WriteWord, void(uint32_t address, uint16_t value))
MOCK_CONST_METHOD0(open_bus, uint8_t())
MOCK_CONST_METHOD1(at, uint8_t(int i))
MOCK_METHOD1(PushLong, void(uint32_t value))
MOCK_METHOD2(WriteLong, void(uint32_t address, uint32_t value))
MOCK_METHOD1(LoadData, void(const std::vector< uint8_t > &data))
MOCK_METHOD1(set_hdma_init_requested, void(bool value))
MOCK_METHOD1(PushWord, void(uint16_t value))
void SetMemoryContents(const std::vector< uint16_t > &data)
MOCK_CONST_METHOD0(h_pos, uint16_t())
MOCK_CONST_METHOD0(v_pos, uint16_t())
MOCK_METHOD1(SetMemory, void(const std::vector< uint8_t > &data))
MOCK_CONST_METHOD0(hdma_init_requested, bool())
MOCK_METHOD0(init_hdma_request, void())
void Initialize(const std::vector< uint8_t > &romData)
MOCK_METHOD2(WriteByte, void(uint32_t address, uint8_t value))
MOCK_METHOD(std::vector< uint8_t >, ReadByteVector,(uint32_t address, uint16_t length),(const, override))
MOCK_CONST_METHOD1(ReadWord, uint16_t(uint32_t address))
MOCK_CONST_METHOD1(ReadWordLong, uint32_t(uint32_t address))
uint8_t operator[](int i) const override
MOCK_METHOD0(PopWord, uint16_t())
MOCK_CONST_METHOD0(SP, uint16_t())
MOCK_METHOD1(SetSP, void(uint16_t value))
MOCK_METHOD1(set_h_pos, void(uint16_t value))
MOCK_CONST_METHOD0(pal_timing, bool())
MOCK_METHOD1(PushByte, void(uint8_t value))
void InsertMemory(const uint64_t address, const std::vector< uint8_t > &data)
MOCK_METHOD0(ClearMemory, void())
MOCK_CONST_METHOD1(ReadByte, uint8_t(uint32_t address))
MOCK_CONST_METHOD0(hdma_run_requested, bool())
MOCK_METHOD1(set_hdma_run_requested, void(bool value))
MOCK_METHOD0(run_hdma_request, void())