Add Overworld accessors and enhance testing framework
- Introduced new methods in `Controller`, `EditorManager`, and `OverworldEditor` to access the `Overworld` instance, improving modularity and interaction with the overworld data. - Added `GetTile` method in `Overworld` to retrieve tile data based on coordinates, enhancing functionality for tile manipulation. - Implemented a new testing framework with automated GUI tests, including `CanvasSelectionTest` and `FrameworkSmokeTest`, to validate user interactions and ensure robustness. - Updated `CMakeLists.txt` to include new test files and dependencies, streamlining the build process for testing. - Refactored logging behavior to ensure proper file handling during logging operations, improving reliability in logging outputs.
This commit is contained in:
@@ -32,6 +32,7 @@ class Controller {
|
||||
auto window() -> SDL_Window * { return window_.window_.get(); }
|
||||
void set_active(bool active) { active_ = active; }
|
||||
auto active() const { return active_; }
|
||||
auto overworld() -> yaze::zelda3::Overworld* { return editor_manager_.overworld(); }
|
||||
|
||||
private:
|
||||
friend int ::main(int argc, char **argv);
|
||||
|
||||
@@ -101,6 +101,7 @@ class EditorManager {
|
||||
absl::Status SetCurrentRom(Rom* rom);
|
||||
auto GetCurrentRom() -> Rom* { return current_rom_; }
|
||||
auto GetCurrentEditorSet() -> EditorSet* { return current_editor_set_; }
|
||||
auto overworld() -> yaze::zelda3::Overworld* { return ¤t_editor_set_->overworld_editor_.overworld(); }
|
||||
|
||||
// Get current session's feature flags (falls back to global if no session)
|
||||
core::FeatureFlags::Flags* GetCurrentFeatureFlags() {
|
||||
|
||||
@@ -94,6 +94,7 @@ class OverworldEditor : public Editor, public gfx::GfxContext {
|
||||
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
||||
absl::Status Save() override;
|
||||
absl::Status Clear() override;
|
||||
zelda3::Overworld& overworld() { return overworld_; }
|
||||
|
||||
/**
|
||||
* @brief Apply ZSCustomOverworld ASM patch to upgrade ROM version
|
||||
|
||||
@@ -278,6 +278,15 @@ class Overworld {
|
||||
auto expanded_entrances() const { return expanded_entrances_; }
|
||||
void set_current_map(int i) { current_map_ = i; }
|
||||
void set_current_world(int world) { current_world_ = world; }
|
||||
uint16_t GetTile(int x, int y) const {
|
||||
if (current_world_ == 0) {
|
||||
return map_tiles_.light_world[y][x];
|
||||
} else if (current_world_ == 1) {
|
||||
return map_tiles_.dark_world[y][x];
|
||||
} else {
|
||||
return map_tiles_.special_world[y][x];
|
||||
}
|
||||
}
|
||||
auto map_tiles() const { return map_tiles_; }
|
||||
auto mutable_map_tiles() { return &map_tiles_; }
|
||||
auto all_items() const { return all_items_; }
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/flags/parse.h"
|
||||
#include "absl/flags/usage.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
@@ -29,6 +35,9 @@ ABSL_FLAG(std::string, rom, "", "Path to the ROM file");
|
||||
ABSL_FLAG(std::string, output, "", "Output file path");
|
||||
ABSL_FLAG(bool, dry_run, false, "Perform a dry run without making changes");
|
||||
ABSL_FLAG(bool, backup, true, "Create a backup before modifying files");
|
||||
ABSL_FLAG(std::string, test, "", "Name of the test to run");
|
||||
ABSL_FLAG(bool, show_gui, false, "Show the test engine GUI");
|
||||
|
||||
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
@@ -118,6 +127,15 @@ class ModernCLI {
|
||||
return HandleHelpCommand(args);
|
||||
}
|
||||
};
|
||||
|
||||
commands_["test-gui"] = {
|
||||
.name = "test-gui",
|
||||
.description = "Run automated GUI tests",
|
||||
.usage = "z3ed test-gui --rom=<rom_file> --test=<test_name>",
|
||||
.handler = [this](const std::vector<std::string>& args) -> absl::Status {
|
||||
return HandleTestGuiCommand(args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void ShowHelp(const std::string& command = "") {
|
||||
@@ -417,6 +435,78 @@ class ModernCLI {
|
||||
}
|
||||
}
|
||||
|
||||
absl::Status HandleTestGuiCommand(const std::vector<std::string>& args) {
|
||||
std::string rom_file = absl::GetFlag(FLAGS_rom);
|
||||
std::string test_name = absl::GetFlag(FLAGS_test);
|
||||
|
||||
if (rom_file.empty()) {
|
||||
return absl::InvalidArgumentError("ROM file required (use --rom=<file>)");
|
||||
}
|
||||
|
||||
// Get the path to the current executable
|
||||
char exe_path[1024];
|
||||
#ifdef __APPLE__
|
||||
uint32_t size = sizeof(exe_path);
|
||||
if (_NSGetExecutablePath(exe_path, &size) != 0) {
|
||||
return absl::InternalError("Could not get executable path");
|
||||
}
|
||||
#else
|
||||
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
|
||||
if (len == -1) {
|
||||
return absl::InternalError("Could not get executable path");
|
||||
}
|
||||
exe_path[len] = '\0';
|
||||
#endif
|
||||
|
||||
std::string exe_dir = std::string(exe_path);
|
||||
exe_dir = exe_dir.substr(0, exe_dir.find_last_of("/"));
|
||||
|
||||
std::string yaze_test_path = exe_dir + "/yaze_test";
|
||||
|
||||
std::vector<std::string> command_args;
|
||||
command_args.push_back(yaze_test_path);
|
||||
command_args.push_back("--enable-ui-tests");
|
||||
command_args.push_back("--rom-path=" + rom_file);
|
||||
if (!test_name.empty()) {
|
||||
command_args.push_back(test_name);
|
||||
}
|
||||
if (absl::GetFlag(FLAGS_show_gui)) {
|
||||
command_args.push_back("--show-gui");
|
||||
}
|
||||
|
||||
std::vector<char*> argv;
|
||||
for (const auto& arg : command_args) {
|
||||
argv.push_back((char*)arg.c_str());
|
||||
}
|
||||
argv.push_back(nullptr);
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == -1) {
|
||||
return absl::InternalError("Failed to fork process");
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
// Child process
|
||||
execv(yaze_test_path.c_str(), argv.data());
|
||||
// If execv returns, it must have failed
|
||||
return absl::InternalError("Failed to execute yaze_test");
|
||||
} else {
|
||||
// Parent process
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
if (WIFEXITED(status)) {
|
||||
int exit_code = WEXITSTATUS(status);
|
||||
if (exit_code == 0) {
|
||||
return absl::OkStatus();
|
||||
} else {
|
||||
return absl::InternalError(absl::StrFormat("yaze_test exited with code %d", exit_code));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status HandleHelpCommand(const std::vector<std::string>& args) {
|
||||
std::string command = args.empty() ? "" : args[0];
|
||||
ShowHelp(command);
|
||||
|
||||
@@ -42,7 +42,7 @@ static void logf(const absl::FormatSpec<Args...> &format, const Args &...args) {
|
||||
// Reopen file if path changed
|
||||
if (g_log_file_path != last_log_path) {
|
||||
fout.close();
|
||||
fout.open(g_log_file_path, std::ios::out | std::ios::app);
|
||||
fout.open(g_log_file_path, std::ios::out | std::ios::trunc);
|
||||
last_log_path = g_log_file_path;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user