1#ifndef YAZE_TEST_TEST_UTILS_H
2#define YAZE_TEST_TEST_UTILS_H
4#ifndef IMGUI_DEFINE_MATH_OPERATORS
5#define IMGUI_DEFINE_MATH_OPERATORS
14#include <gtest/gtest.h>
15#include <gmock/gmock.h>
17#include "absl/strings/str_format.h"
18#include "imgui_test_engine/imgui_te_context.h"
36#ifdef YAZE_ENABLE_ROM_TESTS
48#ifdef YAZE_TEST_ROM_PATH
49 return YAZE_TEST_ROM_PATH;
65 std::ifstream file(rom_path, std::ios::binary);
67 std::cerr <<
"Failed to open test ROM: " << rom_path << std::endl;
72 file.seekg(0, std::ios::end);
73 size_t file_size = file.tellg();
74 file.seekg(0, std::ios::beg);
77 std::vector<uint8_t> rom_data(file_size);
78 file.read(
reinterpret_cast<char*
>(rom_data.data()), file_size);
81 std::cerr <<
"Failed to read test ROM: " << rom_path << std::endl;
94 std::vector<uint8_t> rom_data(size, 0);
97 const size_t header_offset = 0x7FC0;
98 if (size > header_offset + 32) {
100 std::string title =
"YAZE TEST ROM ";
101 std::copy(title.begin(), title.end(), rom_data.begin() + header_offset);
104 rom_data[header_offset + 21] = 0x20;
107 rom_data[header_offset + 23] = 0x0A;
110 uint16_t checksum = 0;
111 for (
size_t i = 0; i < size; ++i) {
112 if (i < header_offset + 28 || i > header_offset + 31) {
113 checksum += rom_data[i];
117 uint16_t checksum_complement = checksum ^ 0xFFFF;
118 rom_data[header_offset + 28] = checksum_complement & 0xFF;
119 rom_data[header_offset + 29] = (checksum_complement >> 8) & 0xFF;
120 rom_data[header_offset + 30] = checksum & 0xFF;
121 rom_data[header_offset + 31] = (checksum >> 8) & 0xFF;
133 GTEST_SKIP() <<
"ROM testing disabled or ROM file not found. "
165 <<
"Failed to load test ROM from " << rom_path;
173#define YAZE_ROM_TEST(test_case_name, test_name) \
174 TEST(test_case_name, test_name) { \
175 yaze::test::TestRomManager::SkipIfRomTestingDisabled(#test_case_name "." #test_name); \
176 YAZE_ROM_TEST_BODY_##test_case_name##_##test_name(); \
178 void YAZE_ROM_TEST_BODY_##test_case_name##_##test_name()
188 ASSERT_FALSE(
test_rom_.empty()) <<
"Failed to load test ROM";
196void LoadRomInTest(ImGuiTestContext* ctx,
const std::string& rom_path);
197void OpenEditorInTest(ImGuiTestContext* ctx,
const std::string& editor_name);
The Rom class is used to load, save, and modify Rom data.
Test fixture for ROM-dependent tests.
std::vector< uint8_t > test_rom_
std::unique_ptr< Rom > rom_instance_
std::string GetBoundRomPath() const
Utility class for handling test ROM files.
static std::vector< uint8_t > CreateMinimalTestRom(size_t size=1024 *1024)
Create a minimal test ROM for unit testing.
static std::string GetTestRomPath()
Get the path to the test ROM file.
static void SkipIfRomTestingDisabled(const std::string &test_name)
Skip test if ROM testing is not enabled.
static bool IsRomTestingEnabled()
Check if ROM testing is enabled and ROM file exists.
static std::vector< uint8_t > LoadTestRom()
Load the test ROM file into memory.
void LoadRomInTest(ImGuiTestContext *ctx, const std::string &rom_path)
void OpenEditorInTest(ImGuiTestContext *ctx, const std::string &editor_name)
Main namespace for the application.