yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor_integration_test.cc
Go to the documentation of this file.
1#define IMGUI_DEFINE_MATH_OPERATORS
2
4
5#include <SDL.h>
6
7#include "app/core/window.h"
8#include "app/gui/style.h"
9#include "imgui/backends/imgui_impl_sdl2.h"
10#include "imgui/backends/imgui_impl_sdlrenderer2.h"
11#include "imgui/imgui.h"
12
13#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
14#include "imgui_test_engine/imgui_te_context.h"
15#include "imgui_test_engine/imgui_te_engine.h"
16#include "imgui_test_engine/imgui_te_imconfig.h"
17#include "imgui_test_engine/imgui_te_ui.h"
18#endif
19
20namespace yaze {
21namespace test {
22
24#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
25 : engine_(nullptr), show_demo_window_(true)
26#else
27
28#endif
29{}
30
32#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
33 if (engine_) {
34 ImGuiTestEngine_Stop(engine_);
35 ImGuiTestEngine_DestroyContext(engine_);
36 }
37#endif
38}
39
41 // Create renderer for test
42 test_renderer_ = std::make_unique<gfx::SDL2Renderer>();
43 RETURN_IF_ERROR(core::CreateWindow(window_, test_renderer_.get(), SDL_WINDOW_RESIZABLE));
44
45 IMGUI_CHECKVERSION();
46 ImGui::CreateContext();
47
48#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
49 // Initialize Test Engine
50 engine_ = ImGuiTestEngine_CreateContext();
51 ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine_);
52 test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info;
53 test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug;
54#endif
55
56 ImGuiIO& io = ImGui::GetIO();
57 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
58
59 // Initialize ImGui for SDL
60 SDL_Renderer* sdl_renderer = static_cast<SDL_Renderer*>(test_renderer_->GetBackendRenderer());
61 ImGui_ImplSDL2_InitForSDLRenderer(controller_.window(), sdl_renderer);
62 ImGui_ImplSDLRenderer2_Init(sdl_renderer);
63
64#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
65 // Register tests
66 RegisterTests(engine_);
67 ImGuiTestEngine_Start(engine_, ImGui::GetCurrentContext());
68#endif
70
71 // Set the default style
73
74 return absl::OkStatus();
75}
76
78 auto status = Initialize();
79 if (!status.ok()) {
80 return EXIT_FAILURE;
81 }
82
83 // Build a new ImGui frame
84 ImGui_ImplSDLRenderer2_NewFrame();
85 ImGui_ImplSDL2_NewFrame();
86
87 while (controller_.IsActive()) {
89 auto status = Update();
90 if (!status.ok()) {
91 return EXIT_FAILURE;
92 }
94 }
95
96 return EXIT_SUCCESS;
97}
98
100 ImGui::NewFrame();
101
102#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
103 // Show test engine windows
104 ImGuiTestEngine_ShowTestEngineWindows(engine_, &show_demo_window_);
105#endif
106
107 return absl::OkStatus();
108}
109
110
111// Helper methods for testing with a ROM
112absl::Status EditorIntegrationTest::LoadTestRom(const std::string& filename) {
113 test_rom_ = std::make_unique<Rom>();
114 return test_rom_->LoadFromFile(filename);
115}
116
117absl::Status EditorIntegrationTest::SaveTestRom(const std::string& filename) {
118 if (!test_rom_) {
119 return absl::FailedPreconditionError("No test ROM loaded");
120 }
121 Rom::SaveSettings settings;
122 settings.backup = false;
123 settings.save_new = false;
124 settings.filename = filename;
125 return test_rom_->SaveToFile(settings);
126}
127
129 if (!editor) {
130 return absl::InternalError("Editor is null");
131 }
132 editor->Initialize();
133 return absl::OkStatus();
134}
135
137 if (!editor) {
138 return absl::InternalError("Editor is null");
139 }
140 return editor->Load();
141}
142
144 if (!editor) {
145 return absl::InternalError("Editor is null");
146 }
147 return editor->Save();
148}
149
151 if (!editor) {
152 return absl::InternalError("Editor is null");
153 }
154 return editor->Update();
155}
156
158 if (!editor) {
159 return absl::InternalError("Editor is null");
160 }
161 return editor->Cut();
162}
163
165 if (!editor) {
166 return absl::InternalError("Editor is null");
167 }
168 return editor->Copy();
169}
170
172 if (!editor) {
173 return absl::InternalError("Editor is null");
174 }
175 return editor->Paste();
176}
177
179 if (!editor) {
180 return absl::InternalError("Editor is null");
181 }
182 return editor->Undo();
183}
184
186 if (!editor) {
187 return absl::InternalError("Editor is null");
188 }
189 return editor->Redo();
190}
191
193 if (!editor) {
194 return absl::InternalError("Editor is null");
195 }
196 return editor->Find();
197}
198
200 if (!editor) {
201 return absl::InternalError("Editor is null");
202 }
203 return editor->Clear();
204}
205
206} // namespace test
207} // namespace yaze
auto window() -> SDL_Window *
Definition controller.h:36
bool IsActive() const
Definition controller.h:26
void set_active(bool active)
Definition controller.h:37
Interface for editor classes.
Definition editor.h:82
virtual absl::Status Cut()=0
virtual absl::Status Copy()=0
virtual absl::Status Redo()=0
virtual void Initialize()=0
virtual absl::Status Clear()
Definition editor.h:108
virtual absl::Status Save()=0
virtual absl::Status Find()=0
virtual absl::Status Paste()=0
virtual absl::Status Load()=0
virtual absl::Status Update()=0
virtual absl::Status Undo()=0
absl::Status TestEditorClear(editor::Editor *editor)
absl::Status TestEditorInitialize(editor::Editor *editor)
absl::Status SaveTestRom(const std::string &filename)
absl::Status TestEditorUpdate(editor::Editor *editor)
virtual void RegisterTests(void *engine)
absl::Status TestEditorSave(editor::Editor *editor)
absl::Status TestEditorLoad(editor::Editor *editor)
absl::Status TestEditorCut(editor::Editor *editor)
absl::Status TestEditorFind(editor::Editor *editor)
absl::Status TestEditorUndo(editor::Editor *editor)
absl::Status TestEditorPaste(editor::Editor *editor)
absl::Status TestEditorCopy(editor::Editor *editor)
absl::Status LoadTestRom(const std::string &filename)
std::unique_ptr< gfx::SDL2Renderer > test_renderer_
absl::Status TestEditorRedo(editor::Editor *editor)
#define RETURN_IF_ERROR(expression)
Definition macro.h:53
absl::Status CreateWindow(Window &window, gfx::IRenderer *renderer, int flags)
Definition window.cc:57
void ColorsYaze()
Definition style.cc:32
Main namespace for the application.
std::string filename
Definition rom.h:77