backend-infra-engineer: Pre-0.2.2 2024 Q3 snapshot
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
# GoogleTest ------------------------------------------------------------------
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
|
||||
)
|
||||
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
enable_testing()
|
||||
|
||||
add_executable(
|
||||
yaze_test
|
||||
yaze_test.cc
|
||||
emu/cpu_test.cc
|
||||
emu/spc700_test.cc
|
||||
emu/ppu_test.cc
|
||||
gfx/compression_test.cc
|
||||
gfx/snes_palette_test.cc
|
||||
zelda3/room_object_test.cc
|
||||
../src/cli/patch.cc
|
||||
../src/cli/command_handler.cc
|
||||
../src/app/rom.cc
|
||||
../src/app/emu/cpu/cpu.cc
|
||||
../src/app/emu/cpu/internal/instructions.cc
|
||||
../src/app/emu/cpu/internal/addressing.cc
|
||||
../src/app/emu/audio/internal/addressing.cc
|
||||
../src/app/emu/audio/internal/instructions.cc
|
||||
../src/app/emu/audio/apu.cc
|
||||
../src/app/emu/video/ppu.cc
|
||||
../src/app/emu/audio/dsp.cc
|
||||
../src/app/emu/audio/spc700.cc
|
||||
../src/app/editor/context/gfx_context.cc
|
||||
../src/app/gfx/bitmap.cc
|
||||
../src/app/gfx/snes_tile.cc
|
||||
../src/app/gfx/snes_color.cc
|
||||
../src/app/gfx/snes_palette.cc
|
||||
../src/app/gfx/compression.cc
|
||||
../src/app/core/common.cc
|
||||
../src/app/core/labeling.cc
|
||||
# ${ASAR_STATIC_SRC}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
yaze_test PUBLIC
|
||||
../src/
|
||||
../src/lib/
|
||||
# ../src/lib/asar/src/asar/
|
||||
${SDL2_INCLUDE_DIR}
|
||||
${PNG_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
yaze_test
|
||||
${ABSL_TARGETS}
|
||||
SDL2::SDL2
|
||||
${PNG_LIBRARIES}
|
||||
${GLEW_LIBRARIES}
|
||||
${OPENGL_LIBRARIES}
|
||||
${CMAKE_DL_LIBS}
|
||||
# asar-static
|
||||
# snes_spc
|
||||
ImGui
|
||||
gmock_main
|
||||
gmock
|
||||
gtest_main
|
||||
gtest
|
||||
)
|
||||
target_compile_definitions(yaze_test PRIVATE "linux")
|
||||
target_compile_definitions(yaze_test PRIVATE "stricmp=strcasecmp")
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(yaze_test)
|
||||
4175
test/emu/cpu_test.cc
4175
test/emu/cpu_test.cc
File diff suppressed because it is too large
Load Diff
@@ -1,159 +0,0 @@
|
||||
#include "app/emu/video/ppu.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "app/emu/cpu/clock.h"
|
||||
#include "app/emu/memory/memory.h"
|
||||
#include "app/emu/memory/mock_memory.h"
|
||||
|
||||
namespace yaze_test {
|
||||
namespace emu_test {
|
||||
|
||||
using yaze::app::emu::Clock;
|
||||
using yaze::app::emu::memory::MockClock;
|
||||
using yaze::app::emu::memory::MockMemory;
|
||||
using yaze::app::emu::video::BackgroundMode;
|
||||
using yaze::app::emu::video::PpuInterface;
|
||||
using yaze::app::emu::video::SpriteAttributes;
|
||||
using yaze::app::emu::video::Tilemap;
|
||||
using yaze::app::gfx::Bitmap;
|
||||
|
||||
/**
|
||||
* @brief Mock Ppu class for testing
|
||||
*/
|
||||
class MockPpu : public PpuInterface {
|
||||
public:
|
||||
MOCK_METHOD(void, Write, (uint16_t address, uint8_t data), (override));
|
||||
MOCK_METHOD(uint8_t, Read, (uint16_t address), (const, override));
|
||||
|
||||
MOCK_METHOD(void, RenderFrame, (), (override));
|
||||
MOCK_METHOD(void, RenderScanline, (), (override));
|
||||
MOCK_METHOD(void, RenderBackground, (int layer), (override));
|
||||
MOCK_METHOD(void, RenderSprites, (), (override));
|
||||
|
||||
MOCK_METHOD(void, Init, (), (override));
|
||||
MOCK_METHOD(void, Reset, (), (override));
|
||||
MOCK_METHOD(void, Update, (double deltaTime), (override));
|
||||
MOCK_METHOD(void, UpdateClock, (double deltaTime), (override));
|
||||
MOCK_METHOD(void, UpdateInternalState, (int cycles), (override));
|
||||
|
||||
MOCK_METHOD(const std::vector<uint8_t>&, GetFrameBuffer, (),
|
||||
(const, override));
|
||||
MOCK_METHOD(std::shared_ptr<Bitmap>, GetScreen, (), (const, override));
|
||||
|
||||
MOCK_METHOD(void, UpdateModeSettings, (), (override));
|
||||
MOCK_METHOD(void, UpdateTileData, (), (override));
|
||||
MOCK_METHOD(void, UpdateTileMapData, (), (override));
|
||||
MOCK_METHOD(void, UpdatePaletteData, (), (override));
|
||||
|
||||
MOCK_METHOD(void, ApplyEffects, (), (override));
|
||||
MOCK_METHOD(void, ComposeLayers, (), (override));
|
||||
|
||||
MOCK_METHOD(void, DisplayFrameBuffer, (), (override));
|
||||
MOCK_METHOD(void, Notify, (uint32_t address, uint8_t data), (override));
|
||||
|
||||
std::vector<uint8_t> internalFrameBuffer;
|
||||
std::vector<uint8_t> vram;
|
||||
std::vector<SpriteAttributes> sprites;
|
||||
std::vector<Tilemap> tilemaps;
|
||||
BackgroundMode bgMode;
|
||||
};
|
||||
|
||||
/**
|
||||
* \test Test fixture for PPU unit tests
|
||||
*/
|
||||
class PpuTest : public ::testing::Test {
|
||||
protected:
|
||||
MockMemory mock_memory;
|
||||
MockClock mock_clock;
|
||||
MockPpu mock_ppu;
|
||||
|
||||
PpuTest() {}
|
||||
|
||||
void SetUp() override {
|
||||
ON_CALL(mock_ppu, Init()).WillByDefault([this]() {
|
||||
mock_ppu.internalFrameBuffer.resize(256 * 240);
|
||||
mock_ppu.vram.resize(0x10000);
|
||||
});
|
||||
|
||||
ON_CALL(mock_ppu, Write(::testing::_, ::testing::_))
|
||||
.WillByDefault([this](uint16_t address, uint8_t data) {
|
||||
mock_ppu.vram[address] = data;
|
||||
});
|
||||
|
||||
ON_CALL(mock_ppu, Read(::testing::_))
|
||||
.WillByDefault(
|
||||
[this](uint16_t address) { return mock_ppu.vram[address]; });
|
||||
|
||||
ON_CALL(mock_ppu, RenderScanline()).WillByDefault([this]() {
|
||||
// Simulate scanline rendering logic...
|
||||
});
|
||||
|
||||
ON_CALL(mock_ppu, GetFrameBuffer()).WillByDefault([this]() {
|
||||
return mock_ppu.internalFrameBuffer;
|
||||
});
|
||||
|
||||
// Additional ON_CALL setups as needed...
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
// Common cleanup (if necessary)
|
||||
}
|
||||
|
||||
const uint8_t testVRAMValue = 0xAB;
|
||||
const uint16_t testVRAMAddress = 0x2000;
|
||||
const std::vector<uint8_t> spriteData = {/* ... */};
|
||||
const std::vector<uint8_t> bgData = {/* ... */};
|
||||
const uint8_t testPaletteIndex = 3;
|
||||
const uint16_t testTileIndex = 42;
|
||||
};
|
||||
|
||||
// Test Initialization
|
||||
TEST_F(PpuTest, InitializationSetsCorrectFrameBufferSize) {
|
||||
// EXPECT_CALL(mock_ppu, Init()).Times(1);
|
||||
// mock_ppu.Init();
|
||||
// EXPECT_EQ(mock_ppu.GetFrameBuffer().size(), 256 * 240);
|
||||
}
|
||||
|
||||
// Test State Reset
|
||||
TEST_F(PpuTest, ResetClearsFrameBuffer) {
|
||||
// EXPECT_CALL(mock_ppu, Reset()).Times(1);
|
||||
// mock_ppu.Reset();
|
||||
// auto frameBuffer = mock_ppu.GetFrameBuffer();
|
||||
// EXPECT_TRUE(std::all_of(frameBuffer.begin(), frameBuffer.end(),
|
||||
// [](uint8_t val) { return val == 0; }));
|
||||
}
|
||||
|
||||
// Test Memory Interaction
|
||||
TEST_F(PpuTest, ReadWriteVRAM) {
|
||||
// uint16_t address = testVRAMAddress;
|
||||
// uint8_t value = testVRAMValue;
|
||||
// EXPECT_CALL(mock_ppu, Write(address, value)).Times(1);
|
||||
// mock_ppu.Write(address, value);
|
||||
// EXPECT_EQ(mock_ppu.Read(address), value);
|
||||
}
|
||||
|
||||
// Test Rendering Mechanics
|
||||
TEST_F(PpuTest, RenderScanlineUpdatesFrameBuffer) {
|
||||
// Setup PPU with necessary background and sprite data
|
||||
// Call RenderScanline and check if the framebuffer is updated correctly
|
||||
}
|
||||
|
||||
// Test Mode and Register Handling
|
||||
TEST_F(PpuTest, Mode0Rendering) {
|
||||
// Set PPU to Mode0 and verify correct rendering behavior
|
||||
}
|
||||
|
||||
// Test Interrupts and Counters
|
||||
TEST_F(PpuTest, VBlankInterruptTriggered) {
|
||||
// Simulate conditions for V-Blank and test if the interrupt is triggered
|
||||
}
|
||||
|
||||
// Test Composite Rendering and Output
|
||||
TEST_F(PpuTest, FrameComposition) {
|
||||
// Setup various layers and sprites, call ComposeLayers, and verify the frame
|
||||
// buffer
|
||||
}
|
||||
|
||||
} // namespace emu_test
|
||||
} // namespace yaze_test
|
||||
@@ -1,472 +0,0 @@
|
||||
#include "app/emu/audio/spc700.h"
|
||||
|
||||
#include <gmock/gmock-nice-strict.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace yaze_test {
|
||||
namespace emu_test {
|
||||
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
using yaze::app::emu::audio::AudioRam;
|
||||
using yaze::app::emu::audio::Spc700;
|
||||
|
||||
/**
|
||||
* @brief MockAudioRam is a mock class for the AudioRam class.
|
||||
*/
|
||||
class MockAudioRam : public AudioRam {
|
||||
public:
|
||||
MOCK_METHOD(void, reset, (), (override));
|
||||
MOCK_METHOD(uint8_t, read, (uint16_t address), (const, override));
|
||||
MOCK_METHOD(uint8_t&, mutable_read, (uint16_t address), (override));
|
||||
MOCK_METHOD(void, write, (uint16_t address, uint8_t value), (override));
|
||||
|
||||
void SetupMemory(uint16_t address, const std::vector<uint8_t>& values) {
|
||||
if (address > internal_audio_ram_.size()) {
|
||||
internal_audio_ram_.resize(address + values.size());
|
||||
}
|
||||
int i = 0;
|
||||
for (const auto& each : values) {
|
||||
internal_audio_ram_[address + i] = each;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() {
|
||||
// internal_audio_ram_.resize(0x10000); // 64 K (0x10000)
|
||||
// std::fill(internal_audio_ram_.begin(), internal_audio_ram_.end(), 0);
|
||||
ON_CALL(*this, read(_)).WillByDefault([this](uint16_t address) {
|
||||
return internal_audio_ram_[address];
|
||||
});
|
||||
ON_CALL(*this, mutable_read(_))
|
||||
.WillByDefault([this](uint16_t address) -> uint8_t& {
|
||||
return internal_audio_ram_[address];
|
||||
});
|
||||
ON_CALL(*this, write(_, _))
|
||||
.WillByDefault([this](uint16_t address, uint8_t value) {
|
||||
internal_audio_ram_[address] = value;
|
||||
});
|
||||
ON_CALL(*this, reset()).WillByDefault([this]() {
|
||||
std::fill(internal_audio_ram_.begin(), internal_audio_ram_.end(), 0);
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<uint8_t> internal_audio_ram_ = std::vector<uint8_t>(0x10000, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* \test Spc700Test is a test fixture for the Spc700 class.
|
||||
*/
|
||||
class Spc700Test : public ::testing::Test {
|
||||
public:
|
||||
Spc700Test() = default;
|
||||
void SetUp() override {
|
||||
// Set up the mock
|
||||
audioRAM.SetUp();
|
||||
|
||||
// Set the Spc700 to bank 01
|
||||
spc700.PC = 0x0100;
|
||||
}
|
||||
|
||||
testing::StrictMock<MockAudioRam> audioRAM;
|
||||
Spc700 spc700{audioRAM};
|
||||
};
|
||||
|
||||
// ========================================================
|
||||
// 8-bit Move Memory to Register
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_Immediate) {
|
||||
// MOV A, imm
|
||||
uint8_t opcode = 0xE8;
|
||||
uint8_t immediate_value = 0x5A;
|
||||
audioRAM.SetupMemory(0x0100, {opcode, immediate_value});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, immediate_value);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_X) {
|
||||
// MOV A, X
|
||||
uint8_t opcode = 0x7D;
|
||||
spc700.X = 0x5A;
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, spc700.X);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_Y) {
|
||||
// MOV A, Y
|
||||
uint8_t opcode = 0xDD;
|
||||
spc700.Y = 0x5A;
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, spc700.Y);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_dp) {
|
||||
// MOV A, dp
|
||||
uint8_t opcode = 0xE4;
|
||||
uint8_t dp_value = 0x5A;
|
||||
audioRAM.SetupMemory(0x005A, {0x42});
|
||||
audioRAM.SetupMemory(0x0100, {opcode, dp_value});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(dp_value))
|
||||
.WillOnce(Return(0x42));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x42);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_dp_plus_x) {
|
||||
// MOV A, dp+X
|
||||
uint8_t opcode = 0xF4;
|
||||
uint8_t dp_value = 0x5A;
|
||||
spc700.X = 0x01;
|
||||
audioRAM.SetupMemory(0x005B, {0x42});
|
||||
audioRAM.SetupMemory(0x0100, {opcode, dp_value});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(dp_value + spc700.X))
|
||||
.WillOnce(Return(0x42));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x42);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_dp_indirect_plus_y) {
|
||||
// MOV A, [dp]+Y
|
||||
uint8_t opcode = 0xF7;
|
||||
uint8_t dp_value = 0x5A;
|
||||
spc700.Y = 0x01;
|
||||
audioRAM.SetupMemory(0x005A, {0x00, 0x42});
|
||||
audioRAM.SetupMemory(0x0100, {opcode, dp_value});
|
||||
audioRAM.SetupMemory(0x4201, {0x69});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(dp_value))
|
||||
.WillOnce(Return(0x4200))
|
||||
.WillOnce(Return(0x69));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x69);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_dp_plus_x_indirect) {
|
||||
// MOV A, [dp+X]
|
||||
uint8_t opcode = 0xE7;
|
||||
uint8_t dp_value = 0x5A;
|
||||
spc700.X = 0x01;
|
||||
audioRAM.SetupMemory(0x005B, {0x00, 0x42});
|
||||
audioRAM.SetupMemory(0x0100, {opcode, dp_value});
|
||||
audioRAM.SetupMemory(0x4200, {0x69});
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(dp_value + 1))
|
||||
.WillOnce(Return(0x4200))
|
||||
.WillOnce(Return(0x69));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x69);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, MOV_A_abs) {
|
||||
// MOV A, !abs
|
||||
uint8_t opcode = 0xE5;
|
||||
uint16_t abs_addr = 0x1234;
|
||||
uint8_t abs_value = 0x5A;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(abs_addr & 0xFF)) // Low byte
|
||||
.WillOnce(Return(abs_addr >> 8)); // High byte
|
||||
|
||||
EXPECT_CALL(audioRAM, read(abs_addr)).WillOnce(Return(abs_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, abs_value);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 8-bit Move Register to Memory
|
||||
|
||||
TEST_F(Spc700Test, MOV_Immediate) {
|
||||
// MOV A, imm
|
||||
uint8_t opcode = 0xE8;
|
||||
uint8_t immediate_value = 0x5A;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, immediate_value);
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
TEST_F(Spc700Test, NOP_DoesNothing) {
|
||||
// NOP opcode
|
||||
uint8_t opcode = 0x00;
|
||||
|
||||
uint16_t initialPC = spc700.PC;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
// PC should increment by 1, no other changes
|
||||
EXPECT_EQ(spc700.PC, initialPC + 1);
|
||||
// Add checks for other registers if needed
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ADC_A_Immediate) {
|
||||
// ADC A, #imm
|
||||
uint8_t opcode = 0x88;
|
||||
uint8_t immediate_value = 0x10;
|
||||
spc700.A = 0x01;
|
||||
spc700.PSW.C = 1; // Assume carry is set
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
// Verify A, and flags
|
||||
EXPECT_EQ(spc700.A, 0x12); // 0x01 + 0x10 + 1 (carry)
|
||||
// Check for other flags (Z, C, etc.) based on the result
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, BEQ_BranchesIfZeroFlagSet) {
|
||||
// BEQ rel
|
||||
uint8_t opcode = 0xF0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 1; // Set Zero flag
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC + 1;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + offset);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, STA_Absolute) {
|
||||
// STA !abs
|
||||
uint8_t opcode = 0x85;
|
||||
uint16_t abs_addr = 0x1234;
|
||||
spc700.A = 0x80;
|
||||
|
||||
// Set up the mock to return the address for the absolute addressing
|
||||
EXPECT_CALL(audioRAM, read(_))
|
||||
.WillOnce(Return(abs_addr & 0xFF)) // Low byte
|
||||
.WillOnce(Return(abs_addr >> 8)); // High byte
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteADCWithImmediate) {
|
||||
// ADC A, imm
|
||||
uint8_t opcode = 0x88; // Replace with opcode for ADC A, imm
|
||||
uint8_t immediate_value = 0x10;
|
||||
spc700.A = 0x15;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x25); // 0x15 + 0x10
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
EXPECT_EQ(spc700.PSW.C, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBRA) {
|
||||
// BRA
|
||||
uint8_t opcode = 0x2F;
|
||||
int8_t offset = 0x05;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
// rel() moves the PC forward one after read
|
||||
uint16_t initialPC = spc700.PC + 1;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + offset);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ReadFromAudioRAM) {
|
||||
uint16_t address = 0x1234;
|
||||
uint8_t expected_value = 0x5A;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(address)).WillOnce(Return(expected_value));
|
||||
|
||||
uint8_t value = spc700.read(address);
|
||||
EXPECT_EQ(value, expected_value);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, WriteToAudioRAM) {
|
||||
uint16_t address = 0x1234;
|
||||
uint8_t value = 0x5A;
|
||||
|
||||
EXPECT_CALL(audioRAM, write(address, value));
|
||||
|
||||
spc700.write(address, value);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteANDWithImmediate) {
|
||||
// AND A, imm
|
||||
uint8_t opcode = 0x28;
|
||||
uint8_t immediate_value = 0x0F;
|
||||
spc700.A = 0x5A; // 0101 1010
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x0A); // 0101 1010 & 0000 1111 = 0000 1010
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteORWithImmediate) {
|
||||
// OR A, imm
|
||||
uint8_t opcode = 0x08;
|
||||
uint8_t immediate_value = 0x0F;
|
||||
spc700.A = 0xA0; // 1010 0000
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0xAF); // 1010 0000 | 0000 1111 = 1010 1111
|
||||
EXPECT_EQ(spc700.PSW.Z, 0);
|
||||
// EXPECT_EQ(spc700.PSW.N, 1);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteEORWithImmediate) {
|
||||
// EOR A, imm
|
||||
uint8_t opcode = 0x48;
|
||||
uint8_t immediate_value = 0x5A;
|
||||
spc700.A = 0x5A; // 0101 1010
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(immediate_value));
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x00); // 0101 1010 ^ 0101 1010 = 0000 0000
|
||||
EXPECT_EQ(spc700.PSW.Z, 1);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteINC) {
|
||||
// INC A
|
||||
uint8_t opcode = 0xBC;
|
||||
spc700.A = 0xFF;
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x00);
|
||||
EXPECT_EQ(spc700.PSW.Z, 1);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteDEC) {
|
||||
// DEC A
|
||||
uint8_t opcode = 0x9C;
|
||||
spc700.A = 0x01;
|
||||
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.A, 0x00);
|
||||
EXPECT_EQ(spc700.PSW.Z, 1);
|
||||
EXPECT_EQ(spc700.PSW.N, 0);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBNEWhenNotEqual) {
|
||||
// BNE
|
||||
uint8_t opcode = 0xD0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 0;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC + 1;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + offset);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBNEWhenEqual) {
|
||||
// BNE
|
||||
uint8_t opcode = 0xD0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 1;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + 1); // +1 because of reading the offset
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBEQWhenEqual) {
|
||||
// BEQ
|
||||
uint8_t opcode = 0xF0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 1;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC + 1;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + offset);
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, ExecuteBEQWhenNotEqual) {
|
||||
// BEQ
|
||||
uint8_t opcode = 0xF0;
|
||||
int8_t offset = 0x05;
|
||||
spc700.PSW.Z = 0;
|
||||
|
||||
EXPECT_CALL(audioRAM, read(_)).WillOnce(Return(offset));
|
||||
|
||||
uint16_t initialPC = spc700.PC;
|
||||
spc700.ExecuteInstructions(opcode);
|
||||
|
||||
EXPECT_EQ(spc700.PC, initialPC + 1); // +1 because of reading the offset
|
||||
}
|
||||
|
||||
TEST_F(Spc700Test, BootIplRomOk) {
|
||||
// Boot the IPL ROM
|
||||
// spc700.BootIplRom();
|
||||
// EXPECT_EQ(spc700.PC, 0xFFC1 + 0x3F);
|
||||
}
|
||||
|
||||
} // namespace emu_test
|
||||
} // namespace yaze_test
|
||||
@@ -1,433 +0,0 @@
|
||||
#include "app/gfx/compression.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "absl/status/statusor.h"
|
||||
#include "app/rom.h"
|
||||
|
||||
#define BUILD_HEADER(command, length) (command << 5) + (length - 1)
|
||||
|
||||
namespace yaze_test {
|
||||
namespace gfx_test {
|
||||
|
||||
using yaze::app::Rom;
|
||||
using yaze::app::gfx::lc_lz2::CompressionContext;
|
||||
using yaze::app::gfx::lc_lz2::CompressionPiece;
|
||||
using yaze::app::gfx::lc_lz2::CompressV2;
|
||||
using yaze::app::gfx::lc_lz2::CompressV3;
|
||||
using yaze::app::gfx::lc_lz2::DecompressV2;
|
||||
using yaze::app::gfx::lc_lz2::kCommandByteFill;
|
||||
using yaze::app::gfx::lc_lz2::kCommandDirectCopy;
|
||||
using yaze::app::gfx::lc_lz2::kCommandIncreasingFill;
|
||||
using yaze::app::gfx::lc_lz2::kCommandLongLength;
|
||||
using yaze::app::gfx::lc_lz2::kCommandRepeatingBytes;
|
||||
using yaze::app::gfx::lc_lz2::kCommandWordFill;
|
||||
|
||||
using ::testing::ElementsAre;
|
||||
using ::testing::ElementsAreArray;
|
||||
using ::testing::TypedEq;
|
||||
|
||||
namespace {
|
||||
|
||||
Bytes ExpectCompressOk(Rom& rom, uchar* in, int in_size) {
|
||||
auto load_status = rom.LoadFromPointer(in, in_size);
|
||||
EXPECT_TRUE(load_status.ok());
|
||||
auto compression_status = CompressV3(rom.vector(), 0, in_size);
|
||||
EXPECT_TRUE(compression_status.ok());
|
||||
auto compressed_bytes = std::move(*compression_status);
|
||||
return compressed_bytes;
|
||||
}
|
||||
|
||||
Bytes ExpectDecompressBytesOk(Rom& rom, Bytes& in) {
|
||||
auto load_status = rom.LoadFromBytes(in);
|
||||
EXPECT_TRUE(load_status.ok());
|
||||
auto decompression_status = DecompressV2(rom.data(), 0, in.size());
|
||||
EXPECT_TRUE(decompression_status.ok());
|
||||
auto decompressed_bytes = std::move(*decompression_status);
|
||||
return decompressed_bytes;
|
||||
}
|
||||
|
||||
Bytes ExpectDecompressOk(Rom& rom, uchar* in, int in_size) {
|
||||
auto load_status = rom.LoadFromPointer(in, in_size);
|
||||
EXPECT_TRUE(load_status.ok());
|
||||
auto decompression_status = DecompressV2(rom.data(), 0, in_size);
|
||||
EXPECT_TRUE(decompression_status.ok());
|
||||
auto decompressed_bytes = std::move(*decompression_status);
|
||||
return decompressed_bytes;
|
||||
}
|
||||
|
||||
std::shared_ptr<CompressionPiece> ExpectNewCompressionPieceOk(
|
||||
const char command, const int length, const std::string args,
|
||||
const int argument_length) {
|
||||
auto new_piece = std::make_shared<CompressionPiece>(command, length, args,
|
||||
argument_length);
|
||||
EXPECT_TRUE(new_piece != nullptr);
|
||||
return new_piece;
|
||||
}
|
||||
|
||||
// Helper function to assert compression quality.
|
||||
void AssertCompressionQuality(
|
||||
const std::vector<uint8_t>& uncompressed_data,
|
||||
const std::vector<uint8_t>& expected_compressed_data) {
|
||||
absl::StatusOr<Bytes> result =
|
||||
CompressV3(uncompressed_data, 0, uncompressed_data.size(), 0, false);
|
||||
ASSERT_TRUE(result.ok());
|
||||
auto compressed_data = std::move(*result);
|
||||
EXPECT_THAT(compressed_data, ElementsAreArray(expected_compressed_data));
|
||||
}
|
||||
|
||||
Bytes ExpectCompressV3Ok(const std::vector<uint8_t>& uncompressed_data,
|
||||
const std::vector<uint8_t>& expected_compressed_data) {
|
||||
absl::StatusOr<Bytes> result =
|
||||
CompressV3(uncompressed_data, 0, uncompressed_data.size(), 0, false);
|
||||
EXPECT_TRUE(result.ok());
|
||||
auto compressed_data = std::move(*result);
|
||||
return compressed_data;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> CreateRepeatedBetweenUncompressable(
|
||||
int leftUncompressedSize, int repeatedByteSize, int rightUncompressedSize) {
|
||||
std::vector<uint8_t> result(
|
||||
leftUncompressedSize + repeatedByteSize + rightUncompressedSize, 0);
|
||||
std::fill_n(result.begin() + leftUncompressedSize, repeatedByteSize, 0x00);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, TrivialRepeatedBytes) {
|
||||
AssertCompressionQuality({0x00, 0x00, 0x00}, {0x22, 0x00, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, RepeatedBytesBetweenUncompressable) {
|
||||
AssertCompressionQuality({0x01, 0x00, 0x00, 0x00, 0x10},
|
||||
{0x04, 0x01, 0x00, 0x00, 0x00, 0x10, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, RepeatedBytesBeforeUncompressable) {
|
||||
AssertCompressionQuality({0x00, 0x00, 0x00, 0x10},
|
||||
{0x22, 0x00, 0x00, 0x10, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, RepeatedBytesAfterUncompressable) {
|
||||
AssertCompressionQuality({0x01, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x01, 0x22, 0x00, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, RepeatedBytesAfterUncompressableRepeated) {
|
||||
AssertCompressionQuality(
|
||||
{0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02},
|
||||
{0x22, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x02, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, RepeatedBytesBeforeUncompressableRepeated) {
|
||||
AssertCompressionQuality(
|
||||
{0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00},
|
||||
{0x04, 0x01, 0x00, 0x00, 0x00, 0x02, 0x22, 0x00, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionDecompressionEmptyData) {
|
||||
Rom rom;
|
||||
uchar empty_input[0] = {};
|
||||
auto comp_result = ExpectCompressOk(rom, empty_input, 0);
|
||||
EXPECT_EQ(0, comp_result.size());
|
||||
|
||||
auto decomp_result = ExpectDecompressOk(rom, empty_input, 0);
|
||||
EXPECT_EQ(0, decomp_result.size());
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, NewDecompressionPieceOk) {
|
||||
char command = 1;
|
||||
int length = 1;
|
||||
char args[] = "aaa";
|
||||
int argument_length = 0x02;
|
||||
CompressionPiece old_piece;
|
||||
old_piece.command = command;
|
||||
old_piece.length = length;
|
||||
old_piece.argument = args;
|
||||
old_piece.argument_length = argument_length;
|
||||
old_piece.next = nullptr;
|
||||
|
||||
auto new_piece = ExpectNewCompressionPieceOk(0x01, 0x01, "aaa", 0x02);
|
||||
|
||||
EXPECT_EQ(old_piece.command, new_piece->command);
|
||||
EXPECT_EQ(old_piece.length, new_piece->length);
|
||||
ASSERT_EQ(old_piece.argument_length, new_piece->argument_length);
|
||||
for (int i = 0; i < old_piece.argument_length; ++i) {
|
||||
EXPECT_EQ(old_piece.argument[i], new_piece->argument[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check why header built is off by one
|
||||
// 0x25 instead of 0x24
|
||||
TEST(LC_LZ2_CompressionTest, CompressionSingleSet) {
|
||||
Rom rom;
|
||||
uchar single_set[5] = {0x2A, 0x2A, 0x2A, 0x2A, 0x2A};
|
||||
uchar single_set_expected[3] = {BUILD_HEADER(1, 5), 0x2A, 0xFF};
|
||||
|
||||
auto comp_result = ExpectCompressOk(rom, single_set, 5);
|
||||
EXPECT_THAT(single_set_expected, ElementsAreArray(comp_result.data(), 3));
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionSingleWord) {
|
||||
Rom rom;
|
||||
uchar single_word[6] = {0x2A, 0x01, 0x2A, 0x01, 0x2A, 0x01};
|
||||
uchar single_word_expected[4] = {BUILD_HEADER(0x02, 0x06), 0x2A, 0x01, 0xFF};
|
||||
|
||||
auto comp_result = ExpectCompressOk(rom, single_word, 6);
|
||||
EXPECT_THAT(single_word_expected, ElementsAreArray(comp_result.data(), 4));
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionSingleIncrement) {
|
||||
Rom rom;
|
||||
uchar single_inc[3] = {0x01, 0x02, 0x03};
|
||||
uchar single_inc_expected[3] = {BUILD_HEADER(0x03, 0x03), 0x01, 0xFF};
|
||||
auto comp_result = ExpectCompressOk(rom, single_inc, 3);
|
||||
EXPECT_THAT(single_inc_expected, ElementsAreArray(comp_result.data(), 3));
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionSingleCopy) {
|
||||
Rom rom;
|
||||
uchar single_copy[4] = {0x03, 0x0A, 0x07, 0x14};
|
||||
uchar single_copy_expected[6] = {
|
||||
BUILD_HEADER(0x00, 0x04), 0x03, 0x0A, 0x07, 0x14, 0xFF};
|
||||
auto comp_result = ExpectCompressOk(rom, single_copy, 4);
|
||||
EXPECT_THAT(single_copy_expected, ElementsAreArray(comp_result.data(), 6));
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionSingleOverflowIncrement) {
|
||||
AssertCompressionQuality({0xFE, 0xFF, 0x00, 0x01},
|
||||
{BUILD_HEADER(0x03, 0x04), 0xFE, 0xFF});
|
||||
}
|
||||
/**
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionSingleCopyRepeat) {
|
||||
std::vector<uint8_t> single_copy_expected = {0x03, 0x0A, 0x07, 0x14,
|
||||
0x03, 0x0A, 0x07, 0x14};
|
||||
|
||||
auto comp_result = ExpectCompressV3Ok(
|
||||
single_copy_expected, {BUILD_HEADER(0x00, 0x04), 0x03, 0x0A, 0x07, 0x14,
|
||||
BUILD_HEADER(0x04, 0x04), 0x00, 0x00, 0xFF});
|
||||
EXPECT_THAT(single_copy_expected, ElementsAreArray(comp_result.data(), 6));
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionMixedRepeatIncrement) {
|
||||
AssertCompressionQuality(
|
||||
{0x05, 0x05, 0x05, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
|
||||
0x05, 0x02, 0x05, 0x02, 0x05, 0x02, 0x0A, 0x0B, 0x05, 0x02,
|
||||
0x05, 0x02, 0x05, 0x02, 0x08, 0x0A, 0x00, 0x05},
|
||||
{BUILD_HEADER(0x01, 0x04), 0x05, BUILD_HEADER(0x03, 0x06), 0x06,
|
||||
BUILD_HEADER(0x00, 0x01), 0x05, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionMixedIncrementIntraCopyOffset) {
|
||||
// "Mixing, inc, alternate, intra copy"
|
||||
// compress start: 3, length: 21
|
||||
// compressed length: 9
|
||||
AssertCompressionQuality(
|
||||
{0x05, 0x05, 0x05, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
|
||||
0x05, 0x02, 0x05, 0x02, 0x05, 0x02, 0x0A, 0x0B, 0x05, 0x02,
|
||||
0x05, 0x02, 0x05, 0x02, 0x08, 0x0A, 0x00, 0x05},
|
||||
{BUILD_HEADER(0x03, 0x07), 0x05, BUILD_HEADER(0x02, 0x06), 0x05, 0x02,
|
||||
BUILD_HEADER(0x04, 0x08), 0x05, 0x00, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionMixedIncrementIntraCopySource) {
|
||||
// "Mixing, inc, alternate, intra copy"
|
||||
// 0, 28
|
||||
// 16
|
||||
AssertCompressionQuality(
|
||||
{0x05, 0x05, 0x05, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
|
||||
0x05, 0x02, 0x05, 0x02, 0x05, 0x02, 0x0A, 0x0B, 0x05, 0x02,
|
||||
0x05, 0x02, 0x05, 0x02, 0x08, 0x0A, 0x00, 0x05},
|
||||
{BUILD_HEADER(0x01, 0x04), 0x05, BUILD_HEADER(0x03, 0x06), 0x06,
|
||||
BUILD_HEADER(0x02, 0x06), 0x05, 0x02, BUILD_HEADER(0x04, 0x08), 0x08,
|
||||
0x00, BUILD_HEADER(0x00, 0x04), 0x08, 0x0A, 0x00, 0x05, 0xFF});
|
||||
}
|
||||
|
||||
// Extended Header
|
||||
// 111CCCLL LLLLLLLL
|
||||
// CCC: Real command
|
||||
// LLLLLLLLLL: Length
|
||||
|
||||
// Normally you have 5 bits for the length, so the maximum value you can
|
||||
// represent is 31 (which outputs 32 bytes). With the long length, you get 5
|
||||
// more bits for the length, so the maximum value you can represent becomes
|
||||
// 1023, outputting 1024 bytes at a time.
|
||||
|
||||
void build_extended_header(uint8_t command, uint8_t length, uint8_t& byte1,
|
||||
uint8_t& byte2) {
|
||||
byte1 = command << 3;
|
||||
byte1 += (length - 1);
|
||||
byte1 += 0b11100000;
|
||||
byte2 = length >> 3;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> CreateRepeatedBetweenUncompressable(
|
||||
int leftUncompressedSize, int repeatedByteSize, int rightUncompressedSize) {
|
||||
std::vector<uint8_t> result(
|
||||
leftUncompressedSize + repeatedByteSize + rightUncompressedSize, 0);
|
||||
std::fill_n(result.begin() + leftUncompressedSize, repeatedByteSize, 0x00);
|
||||
return result;
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, LengthBorderCompression) {
|
||||
// "Length border compression"
|
||||
std::vector<uint8_t> result(42, 0);
|
||||
std::fill_n(result.begin(), 42, 0x05);
|
||||
AssertCompressionQuality(result, {BUILD_HEADER(0x04, 42), 0x05, 0x05, 0xFF});
|
||||
|
||||
// "Extended length, 400 repeat of 5"
|
||||
std::vector<uint8_t> result2(400, 0);
|
||||
std::fill_n(result2.begin(), 400, 0x05);
|
||||
uint8_t byte1;
|
||||
uint8_t byte2;
|
||||
build_extended_header(0x01, 42, byte1, byte2);
|
||||
AssertCompressionQuality(result2, {byte1, byte2, 0x05, 0x05, 0xFF});
|
||||
|
||||
// "Extended length, 1050 repeat of 5"
|
||||
std::vector<uint8_t> result3(1050, 0);
|
||||
std::fill_n(result3.begin(), 1050, 0x05);
|
||||
uint8_t byte3;
|
||||
uint8_t byte4;
|
||||
build_extended_header(0x04, 1050, byte3, byte4);
|
||||
AssertCompressionQuality(result3, {byte3, byte4, 0x05, 0x05, 0xFF});
|
||||
|
||||
// // "Extended length, 2050 repeat of 5"
|
||||
std::vector<uint8_t> result4(2050, 0);
|
||||
std::fill_n(result4.begin(), 2050, 0x05);
|
||||
uint8_t byte5;
|
||||
uint8_t byte6;
|
||||
build_extended_header(0x04, 2050, byte5, byte6);
|
||||
AssertCompressionQuality(result4, {byte5, byte6, 0x05, 0x05, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionExtendedWordCopy) {
|
||||
// ROM rom;
|
||||
// uchar buffer[3000];
|
||||
// for (unsigned int i = 0; i < 3000; i += 2) {
|
||||
// buffer[i] = 0x05;
|
||||
// buffer[i + 1] = 0x06;
|
||||
// }
|
||||
// uchar hightlength_word_1050[] = {
|
||||
// 0b11101011, 0xFF, 0x05, 0x06, BUILD_HEADER(0x02, 0x1A), 0x05, 0x06,
|
||||
// 0xFF};
|
||||
|
||||
// // "Extended word copy"
|
||||
// auto comp_result = ExpectCompressOk(rom, buffer, 1050);
|
||||
// EXPECT_THAT(hightlength_word_1050, ElementsAreArray(comp_result.data(),
|
||||
// 8));
|
||||
|
||||
std::vector<uint8_t> buffer(3000, 0);
|
||||
std::fill_n(buffer.begin(), 3000, 0x05);
|
||||
for (unsigned int i = 0; i < 3000; i += 2) {
|
||||
buffer[i] = 0x05;
|
||||
buffer[i + 1] = 0x06;
|
||||
}
|
||||
|
||||
uint8_t byte1;
|
||||
uint8_t byte2;
|
||||
build_extended_header(0x02, 0x1A, byte1, byte2);
|
||||
AssertCompressionQuality(
|
||||
buffer, {0b11101011, 0xFF, 0x05, 0x06, byte1, byte2, 0x05, 0x06, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionMixedPatterns) {
|
||||
AssertCompressionQuality(
|
||||
{0x05, 0x05, 0x05, 0x06, 0x07, 0x06, 0x07, 0x08, 0x09, 0x0A},
|
||||
{BUILD_HEADER(0x01, 0x03), 0x05, BUILD_HEADER(0x02, 0x04), 0x06, 0x07,
|
||||
BUILD_HEADER(0x03, 0x03), 0x08, 0xFF});
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, CompressionLongIntraCopy) {
|
||||
ROM rom;
|
||||
uchar long_data[15] = {0x05, 0x06, 0x07, 0x08, 0x05, 0x06, 0x07, 0x08,
|
||||
0x05, 0x06, 0x07, 0x08, 0x05, 0x06, 0x07};
|
||||
uchar long_expected[] = {BUILD_HEADER(0x00, 0x04), 0x05, 0x06, 0x07, 0x08,
|
||||
BUILD_HEADER(0x04, 0x0C), 0x00, 0x00, 0xFF};
|
||||
|
||||
auto comp_result = ExpectCompressOk(rom, long_data, 15);
|
||||
EXPECT_THAT(long_expected,
|
||||
ElementsAreArray(comp_result.data(), sizeof(long_expected)));
|
||||
}
|
||||
|
||||
*/
|
||||
// Tests for HandleDirectCopy
|
||||
|
||||
TEST(HandleDirectCopyTest, NotDirectCopyWithAccumulatedBytes) {
|
||||
CompressionContext context({0x01, 0x02, 0x03}, 0, 3);
|
||||
context.cmd_with_max = kCommandByteFill;
|
||||
context.comp_accumulator = 2;
|
||||
HandleDirectCopy(context);
|
||||
EXPECT_EQ(context.compressed_data.size(), 3);
|
||||
}
|
||||
|
||||
TEST(HandleDirectCopyTest, NotDirectCopyWithoutAccumulatedBytes) {
|
||||
CompressionContext context({0x01, 0x02, 0x03}, 0, 3);
|
||||
context.cmd_with_max = kCommandByteFill;
|
||||
HandleDirectCopy(context);
|
||||
EXPECT_EQ(context.compressed_data.size(), 2); // Header + 1 byte
|
||||
}
|
||||
|
||||
TEST(HandleDirectCopyTest, AccumulateBytesWithoutMax) {
|
||||
CompressionContext context({0x01, 0x02, 0x03}, 0, 3);
|
||||
context.cmd_with_max = kCommandDirectCopy;
|
||||
HandleDirectCopy(context);
|
||||
EXPECT_EQ(context.comp_accumulator, 1);
|
||||
EXPECT_EQ(context.compressed_data.size(), 0); // No data added yet
|
||||
}
|
||||
|
||||
// Tests for CheckIncByteV3
|
||||
|
||||
TEST(CheckIncByteV3Test, IncreasingSequence) {
|
||||
CompressionContext context({0x01, 0x02, 0x03}, 0, 3);
|
||||
CheckIncByteV3(context);
|
||||
EXPECT_EQ(context.current_cmd.data_size[kCommandIncreasingFill], 3);
|
||||
}
|
||||
|
||||
TEST(CheckIncByteV3Test, IncreasingSequenceSurroundedByIdenticalBytes) {
|
||||
CompressionContext context({0x01, 0x02, 0x03, 0x04, 0x01}, 1,
|
||||
3); // Start from index 1
|
||||
CheckIncByteV3(context);
|
||||
EXPECT_EQ(context.current_cmd.data_size[kCommandIncreasingFill],
|
||||
0); // Reset to prioritize direct copy
|
||||
}
|
||||
|
||||
TEST(CheckIncByteV3Test, NotAnIncreasingSequence) {
|
||||
CompressionContext context({0x01, 0x01, 0x03}, 0, 3);
|
||||
CheckIncByteV3(context);
|
||||
EXPECT_EQ(context.current_cmd.data_size[kCommandIncreasingFill],
|
||||
1); // Only one byte is detected
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, DecompressionValidCommand) {
|
||||
Rom rom;
|
||||
Bytes simple_copy_input = {BUILD_HEADER(0x00, 0x02), 0x2A, 0x45, 0xFF};
|
||||
uchar simple_copy_output[2] = {0x2A, 0x45};
|
||||
auto decomp_result = ExpectDecompressBytesOk(rom, simple_copy_input);
|
||||
EXPECT_THAT(simple_copy_output, ElementsAreArray(decomp_result.data(), 2));
|
||||
}
|
||||
|
||||
TEST(LC_LZ2_CompressionTest, DecompressionMixingCommand) {
|
||||
Rom rom;
|
||||
uchar random1_i[11] = {BUILD_HEADER(0x01, 0x03),
|
||||
0x2A,
|
||||
BUILD_HEADER(0x00, 0x04),
|
||||
0x01,
|
||||
0x02,
|
||||
0x03,
|
||||
0x04,
|
||||
BUILD_HEADER(0x02, 0x02),
|
||||
0x0B,
|
||||
0x16,
|
||||
0xFF};
|
||||
uchar random1_o[9] = {42, 42, 42, 1, 2, 3, 4, 11, 22};
|
||||
auto decomp_result = ExpectDecompressOk(rom, random1_i, 11);
|
||||
EXPECT_THAT(random1_o, ElementsAreArray(decomp_result.data(), 9));
|
||||
}
|
||||
|
||||
} // namespace gfx_test
|
||||
} // namespace yaze_test
|
||||
@@ -1,108 +0,0 @@
|
||||
#include "app/gfx/snes_palette.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "app/gfx/snes_color.h"
|
||||
|
||||
namespace yaze_test {
|
||||
namespace gfx_test {
|
||||
|
||||
using ::testing::ElementsAreArray;
|
||||
using yaze::app::gfx::ConvertRGBtoSNES;
|
||||
using yaze::app::gfx::ConvertSNEStoRGB;
|
||||
using yaze::app::gfx::Extract;
|
||||
using yaze::app::gfx::snes_color;
|
||||
using yaze::app::gfx::snes_palette;
|
||||
using yaze::app::gfx::SnesPalette;
|
||||
|
||||
namespace {
|
||||
unsigned int test_convert(yaze::app::gfx::snes_color col) {
|
||||
unsigned int toret;
|
||||
toret = col.red << 16;
|
||||
toret += col.green << 8;
|
||||
toret += col.blue;
|
||||
return toret;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(SNESPaletteTest, AddColor) {
|
||||
yaze::app::gfx::SnesPalette palette;
|
||||
yaze::app::gfx::SnesColor color;
|
||||
palette.AddColor(color);
|
||||
ASSERT_EQ(palette.size(), 1);
|
||||
}
|
||||
|
||||
TEST(SNESPaletteTest, GetColorOutOfBounds) {
|
||||
yaze::app::gfx::SnesPalette palette;
|
||||
std::vector<yaze::app::gfx::SnesColor> colors(5);
|
||||
palette.Create(colors);
|
||||
|
||||
// TODO: Fix this test, behavior has changed since the original
|
||||
// ASSERT_THROW(palette.GetColor(10), std::exception);
|
||||
// ASSERT_THROW(palette[10], std::exception);
|
||||
}
|
||||
|
||||
TEST(SNESColorTest, ConvertRGBtoSNES) {
|
||||
snes_color color = {132, 132, 132};
|
||||
uint16_t snes = ConvertRGBtoSNES(color);
|
||||
ASSERT_EQ(snes, 0x4210);
|
||||
}
|
||||
|
||||
TEST(SNESColorTest, ConvertSNEStoRGB) {
|
||||
uint16_t snes = 0x4210;
|
||||
snes_color color = ConvertSNEStoRGB(snes);
|
||||
ASSERT_EQ(color.red, 132);
|
||||
ASSERT_EQ(color.green, 132);
|
||||
ASSERT_EQ(color.blue, 132);
|
||||
}
|
||||
|
||||
TEST(SNESColorTest, ConvertSNESToRGB_Binary) {
|
||||
uint16_t red = 0b0000000000011111;
|
||||
uint16_t blue = 0b0111110000000000;
|
||||
uint16_t green = 0b0000001111100000;
|
||||
uint16_t purple = 0b0111110000011111;
|
||||
snes_color testcolor;
|
||||
|
||||
testcolor = ConvertSNEStoRGB(red);
|
||||
ASSERT_EQ(0xFF0000, test_convert(testcolor));
|
||||
testcolor = ConvertSNEStoRGB(green);
|
||||
ASSERT_EQ(0x00FF00, test_convert(testcolor));
|
||||
testcolor = ConvertSNEStoRGB(blue);
|
||||
ASSERT_EQ(0x0000FF, test_convert(testcolor));
|
||||
testcolor = ConvertSNEStoRGB(purple);
|
||||
ASSERT_EQ(0xFF00FF, test_convert(testcolor));
|
||||
}
|
||||
|
||||
TEST(SNESColorTest, Extraction) {
|
||||
// red, blue, green, purple
|
||||
char data[8] = {0x1F, 0x00, 0x00, 0x7C, static_cast<char>(0xE0),
|
||||
0x03, 0x1F, 0x7C};
|
||||
auto pal = Extract(data, 0, 4);
|
||||
ASSERT_EQ(4, pal.size());
|
||||
ASSERT_EQ(0xFF0000, test_convert(pal[0]));
|
||||
ASSERT_EQ(0x0000FF, test_convert(pal[1]));
|
||||
ASSERT_EQ(0x00FF00, test_convert(pal[2]));
|
||||
ASSERT_EQ(0xFF00FF, test_convert(pal[3]));
|
||||
}
|
||||
|
||||
TEST(SNESColorTest, Convert) {
|
||||
// red, blue, green, purple white
|
||||
char data[10] = {0x1F,
|
||||
0x00,
|
||||
0x00,
|
||||
0x7C,
|
||||
static_cast<char>(0xE0),
|
||||
0x03,
|
||||
0x1F,
|
||||
0x7C,
|
||||
static_cast<char>(0xFF),
|
||||
0x1F};
|
||||
auto pal = Extract(data, 0, 5);
|
||||
auto snes_string = Convert(pal);
|
||||
EXPECT_EQ(10, snes_string.size());
|
||||
EXPECT_THAT(data, ElementsAreArray(snes_string.data(), 10));
|
||||
}
|
||||
|
||||
} // namespace gfx_test
|
||||
} // namespace yaze_test
|
||||
@@ -1,14 +0,0 @@
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "absl/debugging/failure_signal_handler.h"
|
||||
#include "absl/debugging/symbolize.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
absl::InitializeSymbolizer(argv[0]);
|
||||
|
||||
absl::FailureSignalHandlerOptions options;
|
||||
absl::InstallFailureSignalHandler(options);
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#include "app/zelda3/dungeon/room_object.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "app/emu/cpu/cpu.h"
|
||||
#include "app/emu/memory/memory.h"
|
||||
#include "app/emu/memory/mock_memory.h"
|
||||
#include "app/emu/video/ppu.h"
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/rom.h"
|
||||
|
||||
namespace yaze_test {
|
||||
namespace zelda3_test {
|
||||
|
||||
using yaze::app::Rom;
|
||||
using yaze::app::zelda3::dungeon::DungeonObjectRenderer;
|
||||
|
||||
TEST(DungeonObjectTest, RenderObjectsAsBitmaps) {
|
||||
Rom rom;
|
||||
// rom.LoadFromFile("/Users/scawful/Code/yaze/build/bin/zelda3.sfc"));
|
||||
// EXPECT_EQ(rom_status, absl::Status::ok());
|
||||
|
||||
DungeonObjectRenderer renderer;
|
||||
}
|
||||
|
||||
} // namespace zelda3_test
|
||||
} // namespace yaze_test
|
||||
Reference in New Issue
Block a user