Create write unit test to check the proper choreography and delays, and add CMakeLists.txt for compiling the unit tests

This commit is contained in:
Gustavo Henrique Santos Souza de Miranda 2026-06-03 12:25:03 -03:00
parent 8e4fceec7e
commit 2172ed0735
2 changed files with 44 additions and 0 deletions

25
Tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.22)
project(YMF262_Tests CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2
)
FetchContent_MakeAvailable(googletest)
add_executable(run_tests test_write.cpp)
target_include_directories(run_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../Lib/YMF262-HAL/Inc
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(run_tests PRIVATE gtest_main)
include(GoogleTest)
gtest_discover_tests(run_tests)

19
Tests/test_write.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <gtest/gtest.h>
#include "YMF262-HAL.hpp"
#include "FakeGPIO.hpp"
TEST(YMF262Write, FazDoisCiclos) {
FakeGpio fake;
YMF262_HAL<FakeGpio> hal(fake, 14318000, 216000000);
hal.write(Bank::BANK_0, 0x40, 0x20);
// imprime o que foi registrado (pra você VER a coreografia)
for (const auto& linha : fake.log) {
std::cout << linha << "\n";
}
// verificações básicas: o primeiro ciclo é endereço, o barramento recebeu 0x40 (64)
EXPECT_EQ(fake.log.front(), "a0 ADDR"); // começou em modo endereço
EXPECT_FALSE(fake.log.empty()); // anotou algo
}