backend-infra-engineer: Post v0.3.9-hotfix7 snapshot (build cleanup)
This commit is contained in:
96
test/test_utils/mock_rom_generator.h
Normal file
96
test/test_utils/mock_rom_generator.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef YAZE_TEST_UTILS_MOCK_ROM_GENERATOR_H
|
||||
#define YAZE_TEST_UTILS_MOCK_ROM_GENERATOR_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace yaze {
|
||||
namespace test {
|
||||
|
||||
/**
|
||||
* @struct MockRomConfig
|
||||
* @brief Configuration for generating mock ROM data
|
||||
*/
|
||||
struct MockRomConfig {
|
||||
size_t rom_size = 1024 * 1024; // Default 1MB
|
||||
|
||||
bool include_overworld_data = true;
|
||||
bool include_dungeon_data = true;
|
||||
bool include_graphics_data = true;
|
||||
bool include_sprite_data = true;
|
||||
|
||||
// Fill with recognizable test patterns instead of zeros
|
||||
bool populate_with_test_data = true;
|
||||
|
||||
// ZSCustomOverworld version (0 = disabled)
|
||||
uint8_t zscustom_version = 0;
|
||||
|
||||
// Seed for deterministic random data
|
||||
uint32_t random_seed = 12345;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class MockRomGenerator
|
||||
* @brief Generates minimal valid SNES ROM data for testing
|
||||
*
|
||||
* Creates ROMs with valid SNES headers, checksums, and optional
|
||||
* game-specific data structures. Useful for unit tests that need
|
||||
* ROM data but don't require actual game assets.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* MockRomConfig config;
|
||||
* config.rom_size = 2 * 1024 * 1024; // 2MB
|
||||
* config.zscustom_version = 3;
|
||||
*
|
||||
* MockRomGenerator generator(config);
|
||||
* std::vector<uint8_t> rom_data = generator.Generate();
|
||||
*
|
||||
* Rom rom;
|
||||
* rom.LoadFromBytes(rom_data);
|
||||
* @endcode
|
||||
*/
|
||||
class MockRomGenerator {
|
||||
public:
|
||||
explicit MockRomGenerator(const MockRomConfig& config);
|
||||
|
||||
// Generate ROM data according to configuration
|
||||
std::vector<uint8_t> Generate();
|
||||
|
||||
private:
|
||||
void WriteSNESHeader(std::vector<uint8_t>& data);
|
||||
void WriteOverworldData(std::vector<uint8_t>& data);
|
||||
void WriteDungeonData(std::vector<uint8_t>& data);
|
||||
void WriteGraphicsData(std::vector<uint8_t>& data);
|
||||
void WriteSpriteData(std::vector<uint8_t>& data);
|
||||
void WriteChecksum(std::vector<uint8_t>& data);
|
||||
|
||||
uint8_t CalculateRomSizeCode(size_t rom_size);
|
||||
|
||||
MockRomConfig config_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Factory functions for common ROM variants
|
||||
*/
|
||||
|
||||
// Standard 1MB mock ROM with all data structures
|
||||
std::vector<uint8_t> CreateDefaultMockRom();
|
||||
|
||||
// Minimal 256KB ROM with just header (fast loading for unit tests)
|
||||
std::vector<uint8_t> CreateMinimalMockRom();
|
||||
|
||||
// 2MB ROM with ZSCustomOverworld v3 features enabled
|
||||
std::vector<uint8_t> CreateZSCustomV3MockRom();
|
||||
|
||||
// ROM with intentionally corrupted data (for error handling tests)
|
||||
std::vector<uint8_t> CreateCorruptedMockRom();
|
||||
|
||||
// Large 4MB ROM for stress testing
|
||||
std::vector<uint8_t> CreateLargeMockRom();
|
||||
|
||||
} // namespace test
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_TEST_UTILS_MOCK_ROM_GENERATOR_H
|
||||
112
test/test_utils/rom_integrity_validator.h
Normal file
112
test/test_utils/rom_integrity_validator.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#ifndef YAZE_TEST_UTILS_ROM_INTEGRITY_VALIDATOR_H
|
||||
#define YAZE_TEST_UTILS_ROM_INTEGRITY_VALIDATOR_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "rom/rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace test {
|
||||
|
||||
/**
|
||||
* @struct ValidationResult
|
||||
* @brief Results of ROM integrity validation
|
||||
*/
|
||||
struct ValidationResult {
|
||||
bool valid = true;
|
||||
std::vector<std::string> errors;
|
||||
std::vector<std::string> warnings;
|
||||
|
||||
// Add error message
|
||||
void AddError(const std::string& error) {
|
||||
errors.push_back(error);
|
||||
valid = false;
|
||||
}
|
||||
|
||||
// Add warning message (doesn't invalidate)
|
||||
void AddWarning(const std::string& warning) { warnings.push_back(warning); }
|
||||
|
||||
// Get summary string
|
||||
std::string GetSummary() const {
|
||||
if (valid) {
|
||||
if (warnings.empty()) {
|
||||
return "ROM validation passed with no issues";
|
||||
} else {
|
||||
return absl::StrFormat(
|
||||
"ROM validation passed with %zu warnings", warnings.size());
|
||||
}
|
||||
} else {
|
||||
return absl::StrFormat("ROM validation failed with %zu errors",
|
||||
errors.size());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @class RomIntegrityValidator
|
||||
* @brief Validates ROM integrity after edits
|
||||
*
|
||||
* Performs comprehensive validation to ensure that ROM edits
|
||||
* maintain structural integrity and don't corrupt data.
|
||||
*
|
||||
* Validation checks:
|
||||
* - SNES header checksum correctness
|
||||
* - Pointer validity (all pointers within ROM bounds)
|
||||
* - Compression integrity (compressed data can be decompressed)
|
||||
* - Data structure consistency (overworld, dungeons, graphics)
|
||||
* - Boundary checks (no data overflow)
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* Rom rom;
|
||||
* rom.LoadFromFile("zelda3.sfc");
|
||||
*
|
||||
* // Make edits...
|
||||
* rom.WriteByte(0x1234, 0x42);
|
||||
*
|
||||
* RomIntegrityValidator validator;
|
||||
* ValidationResult result = validator.ValidateRomIntegrity(&rom);
|
||||
*
|
||||
* if (!result.valid) {
|
||||
* for (const auto& error : result.errors) {
|
||||
* std::cerr << "Error: " << error << std::endl;
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class RomIntegrityValidator {
|
||||
public:
|
||||
RomIntegrityValidator() = default;
|
||||
|
||||
// Perform full ROM integrity validation
|
||||
ValidationResult ValidateRomIntegrity(Rom* rom);
|
||||
|
||||
// Individual validation methods (can be used separately)
|
||||
bool ValidateChecksum(Rom* rom, ValidationResult* result = nullptr);
|
||||
bool ValidateGraphicsPointers(Rom* rom, ValidationResult* result = nullptr);
|
||||
bool ValidateCompression(Rom* rom, ValidationResult* result = nullptr);
|
||||
bool ValidateOverworldStructure(Rom* rom,
|
||||
ValidationResult* result = nullptr);
|
||||
bool ValidateDungeonStructure(Rom* rom, ValidationResult* result = nullptr);
|
||||
bool ValidateSpriteData(Rom* rom, ValidationResult* result = nullptr);
|
||||
|
||||
private:
|
||||
// Helper methods
|
||||
bool ValidatePointerRange(uint32_t pointer, uint32_t rom_size,
|
||||
const std::string& pointer_name,
|
||||
ValidationResult* result);
|
||||
|
||||
bool ValidateDataRegion(Rom* rom, uint32_t start, uint32_t end,
|
||||
const std::string& region_name,
|
||||
ValidationResult* result);
|
||||
|
||||
bool ValidateCompressedBlock(Rom* rom, uint32_t address,
|
||||
const std::string& block_name,
|
||||
ValidationResult* result);
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_TEST_UTILS_ROM_INTEGRITY_VALIDATOR_H
|
||||
Reference in New Issue
Block a user