adding tesunit tests and documentation for PPU utils

This commit is contained in:
Clément Le Bihan
2021-07-25 15:27:36 +02:00
parent 8d18ca89dc
commit 3ed7e2677d
4 changed files with 52 additions and 8 deletions
+3 -1
View File
@@ -186,8 +186,10 @@ add_executable(unit_tests EXCLUDE_FROM_ALL
tests/CPU/testDMA.cpp
tests/CPU/testAddressingMode.cpp
tests/testMemoryBus.cpp
tests/PPU/testTileRenderer.cpp
tests/PPU/testPPUUtils.cpp
tests/PPU/testCGRAMColorToRGBA.cpp
)
target_include_directories(unit_tests PUBLIC tests)
target_compile_definitions(unit_tests PUBLIC TESTS)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/libs)
+27 -7
View File
@@ -55,20 +55,34 @@ namespace ComSquare::PPU::Utils
uint8_t hScrollPrevValue;
};
//! @brief Takes the bufferSrc and set the values in bufferDest starting at offset
//! @param bufferDest The destination buffer (the one who will be written on)
//! @param bufferSrc The source buffer (the one that will be copied to the bufferSrc)
//! @param offset The starting position to copy bufferSrc to bufferDest
//! @tparam DEST_SIZE_X Horizontal size of bufferDest
//! @tparam DEST_SIZE_Y Vertical size of bufferDest
//! @tparam SRC_SIZE_X Horizontal size of bufferSrc
//! @tparam SRC_SIZE_Y Vertical size of bufferSrc
template <std::size_t DEST_SIZE_Y, std::size_t DEST_SIZE_X, std::size_t SRC_SIZE_Y, std::size_t SRC_SIZE_X>
void merge2DArray(std::array<std::array<uint32_t, DEST_SIZE_X>, DEST_SIZE_Y> &bufferDest,
const std::array<std::array<uint32_t, SRC_SIZE_X>, SRC_SIZE_Y> &bufferSrc,
const Vector2<int> &offset)
{
int offsetY = offset.y;
for (auto &row : bufferSrc) {
for (const auto &row : bufferSrc) {
std::copy(row.begin(), row.end(), bufferDest[offsetY++].begin() + offset.x);
}
}
template <std::size_t SRC_SIZE_Y, std::size_t SRC_SIZE_X>
void VFlipArray(std::array<std::array<uint32_t, SRC_SIZE_X>, SRC_SIZE_Y> &array,
const Vector2<int> &size,
//! @brief Flips Vertically an 2D array
//! @param array The array to be flipped
//! @param size The maximum size you want to be split
//! @param offset The starting position of the flip
//! @tparam HORIZONTAL_SIZE The horizontal size of the array
//! @tparam VERTICAL_SIZE The vertical size of the array
template <std::size_t VERTICAL_SIZE, std::size_t HORIZONTAL_SIZE>
void VFlipArray(std::array<std::array<uint32_t, HORIZONTAL_SIZE>, VERTICAL_SIZE> &array,
const Vector2<int> &size = {HORIZONTAL_SIZE, VERTICAL_SIZE},
const Vector2<int> &offset = {0, 0})
{
for (int i = offset.y; i < offset.y + size.y; i++) {
@@ -76,9 +90,15 @@ namespace ComSquare::PPU::Utils
}
}
template <std::size_t SRC_SIZE_Y, std::size_t SRC_SIZE_X>
void HFlipArray(std::array<std::array<uint32_t, SRC_SIZE_X>, SRC_SIZE_Y> &array,
const Vector2<int> &size,
//! @brief Flips Horizontally an 2D array
//! @param array The array to be flipped
//! @param size The maximum size you want to be split
//! @param offset The starting position of the flip
//! @tparam HORIZONTAL_SIZE The horizontal size of the array
//! @tparam VERTICAL_SIZE The vertical size of the array
template <std::size_t VERTICAL_SIZE, std::size_t HORIZONTAL_SIZE>
void HFlipArray(std::array<std::array<uint32_t, HORIZONTAL_SIZE>, VERTICAL_SIZE> &array,
const Vector2<int> &size = {HORIZONTAL_SIZE, VERTICAL_SIZE},
const Vector2<int> &offset = {0, 0})
{
std::reverse(array.begin() + offset.x, array.begin() + offset.x + size.x);
+22
View File
@@ -0,0 +1,22 @@
//
// Created by cbihan on 25/07/2021.
//
#include <catch2/catch_test_macros.hpp>
#include "PPU/PPUUtils.hpp"
TEST_CASE("Various color conversions CGRAMColorToRGBA", "[PPU][Utils]")
{
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x7210) == 0x8484E7FF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x7398) == 0xC6E7E7FF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x019C) == 0xE76300FF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x521C) == 0xE784A5FF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x039C) == 0xE7E700FF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x0000) == 0x000000FF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x001C) == 0xE70000FF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x5284) == 0x21A5A5FF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x7E20) == 0x008CFFFF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x37BF) == 0xFFEF6BFF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x3E78) == 0xC69C7BFF);
CHECK(ComSquare::PPU::Utils::CGRAMColorToRGBA(0x428B) == 0x5AA584FF);
}
View File