Add integration tests for Dungeon Editor and object parsing functionality

- Updated CMakeLists.txt to include new test files for CPU, PPU, SPC700, APU, and dungeon editor integration tests.
- Introduced new testing helpers in testing.h for validating StatusOr objects with specific error messages and codes.
- Added comprehensive integration tests for the DungeonEditor, covering object parsing, rendering, and room graphics.
- Created mock ROM and object data setups to facilitate testing without real ROM files.
- Implemented various test cases to ensure the reliability of object parsing and rendering logic in the dungeon editor.
This commit is contained in:
scawful
2025-09-24 12:44:14 -04:00
parent 8bc896265f
commit 789f577ee3
9 changed files with 1089 additions and 6 deletions

View File

@@ -6,20 +6,95 @@
#include "test/testing.h"
#include "app/rom.h"
namespace yaze {
namespace test {
/**
* @brief Enhanced ROM for testing that behaves like a real ROM but with test data
*
* This class extends Rom to provide testing utilities while maintaining
* all the real ROM functionality. Instead of mocking methods, it loads
* real test data into the ROM.
*/
class MockRom : public Rom {
public:
MockRom() = default;
// Override the only virtual method in Rom
MOCK_METHOD(absl::Status, WriteHelper, (const WriteAction&), (override));
MOCK_METHOD2(ReadHelper, absl::Status(uint8_t&, int));
MOCK_METHOD2(ReadHelper, absl::Status(uint16_t&, int));
MOCK_METHOD2(ReadHelper, absl::Status(std::vector<uint8_t>&, int));
/**
* @brief Load test data into the ROM
* @param data The test ROM data to load
* @return Status of the operation
*/
absl::Status SetTestData(const std::vector<uint8_t>& data) {
auto status = LoadFromData(data, false); // Don't load Zelda3 specific data
if (status.ok()) {
test_data_loaded_ = true;
}
return status;
}
/**
* @brief Store object-specific test data for validation
*/
void SetObjectData(int object_id, const std::vector<uint8_t>& data) {
object_data_[object_id] = data;
}
/**
* @brief Store room-specific test data for validation
*/
void SetRoomData(int room_id, const std::vector<uint8_t>& data) {
room_data_[room_id] = data;
}
/**
* @brief Check if object data has been set for testing
*/
bool HasObjectData(int object_id) const {
return object_data_.find(object_id) != object_data_.end();
}
/**
* @brief Check if room data has been set for testing
*/
bool HasRoomData(int room_id) const {
return room_data_.find(room_id) != room_data_.end();
}
MOCK_METHOD(absl::StatusOr<uint8_t>, ReadByte, (int));
MOCK_METHOD(absl::StatusOr<uint16_t>, ReadWord, (int));
MOCK_METHOD(absl::StatusOr<uint32_t>, ReadLong, (int));
/**
* @brief Check if the mock ROM is valid for testing
*/
bool IsValid() const {
return test_data_loaded_ && is_loaded() && size() > 0;
}
/**
* @brief Get the stored object data for validation
*/
const std::vector<uint8_t>& GetObjectData(int object_id) const {
static const std::vector<uint8_t> empty;
auto it = object_data_.find(object_id);
return (it != object_data_.end()) ? it->second : empty;
}
/**
* @brief Get the stored room data for validation
*/
const std::vector<uint8_t>& GetRoomData(int room_id) const {
static const std::vector<uint8_t> empty;
auto it = room_data_.find(room_id);
return (it != room_data_.end()) ? it->second : empty;
}
private:
bool test_data_loaded_ = false;
std::map<int, std::vector<uint8_t>> object_data_;
std::map<int, std::vector<uint8_t>> room_data_;
};
} // namespace test