From 3ed7e2677df4479608cd0a036d21e4c4b41fda55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Sun, 25 Jul 2021 15:27:36 +0200 Subject: [PATCH] adding tesunit tests and documentation for PPU utils --- CMakeLists.txt | 4 ++- sources/PPU/PPUUtils.hpp | 34 +++++++++++++++---- tests/PPU/testCGRAMColorToRGBA.cpp | 22 ++++++++++++ ...{testTileRenderer.cpp => testPPUUtils.cpp} | 0 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100755 tests/PPU/testCGRAMColorToRGBA.cpp rename tests/PPU/{testTileRenderer.cpp => testPPUUtils.cpp} (100%) mode change 100644 => 100755 diff --git a/CMakeLists.txt b/CMakeLists.txt index c69d842..63411a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/sources/PPU/PPUUtils.hpp b/sources/PPU/PPUUtils.hpp index e6b099d..aecd073 100644 --- a/sources/PPU/PPUUtils.hpp +++ b/sources/PPU/PPUUtils.hpp @@ -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 void merge2DArray(std::array, DEST_SIZE_Y> &bufferDest, const std::array, SRC_SIZE_Y> &bufferSrc, const Vector2 &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 - void VFlipArray(std::array, SRC_SIZE_Y> &array, - const Vector2 &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 + void VFlipArray(std::array, VERTICAL_SIZE> &array, + const Vector2 &size = {HORIZONTAL_SIZE, VERTICAL_SIZE}, const Vector2 &offset = {0, 0}) { for (int i = offset.y; i < offset.y + size.y; i++) { @@ -76,9 +90,15 @@ namespace ComSquare::PPU::Utils } } - template - void HFlipArray(std::array, SRC_SIZE_Y> &array, - const Vector2 &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 + void HFlipArray(std::array, VERTICAL_SIZE> &array, + const Vector2 &size = {HORIZONTAL_SIZE, VERTICAL_SIZE}, const Vector2 &offset = {0, 0}) { std::reverse(array.begin() + offset.x, array.begin() + offset.x + size.x); diff --git a/tests/PPU/testCGRAMColorToRGBA.cpp b/tests/PPU/testCGRAMColorToRGBA.cpp new file mode 100755 index 0000000..c49d985 --- /dev/null +++ b/tests/PPU/testCGRAMColorToRGBA.cpp @@ -0,0 +1,22 @@ +// +// Created by cbihan on 25/07/2021. +// + +#include +#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); +} diff --git a/tests/PPU/testTileRenderer.cpp b/tests/PPU/testPPUUtils.cpp old mode 100644 new mode 100755 similarity index 100% rename from tests/PPU/testTileRenderer.cpp rename to tests/PPU/testPPUUtils.cpp