yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
canvas_selection_test.cc
Go to the documentation of this file.
1#define IMGUI_DEFINE_MATH_OPERATORS
4#include "test_utils.h"
5
6void E2ETest_CanvasSelectionTest(ImGuiTestContext* ctx)
7{
8 yaze::test::gui::LoadRomInTest(ctx, "zelda3.sfc");
9 yaze::core::Controller* controller = (yaze::core::Controller*)ctx->Test->UserData;
10 yaze::zelda3::Overworld* overworld = controller->overworld();
11
12 // 1. Open the Overworld Editor
13 yaze::test::gui::OpenEditorInTest(ctx, "Overworld Editor");
14
15 // 2. Find the canvas
16 ctx->WindowFocus("Overworld Editor");
17 ctx->ItemClick("##Canvas");
18
19 // 3. Get the original tile data
20 // We'll check the 2x2 tile area at the paste location (600, 300)
21 // The tile at (600, 300) is at (75, 37) in tile coordinates.
22 // The overworld map is 128x128 tiles.
23 uint16_t orig_tile1 = overworld->GetTile(75, 37);
24 uint16_t orig_tile2 = overworld->GetTile(76, 37);
25 uint16_t orig_tile3 = overworld->GetTile(75, 38);
26 uint16_t orig_tile4 = overworld->GetTile(76, 38);
27
28 // 4. Perform a rectangle selection that crosses a 512px boundary
29 // The canvas is 1024x1024, with the top-left at (0,0).
30 // We'll select a 2x2 tile area from (510, 256) to (514, 258).
31 // This will cross the 512px boundary.
32 ctx->MouseMoveToPos(ImVec2(510, 256));
33 ctx->MouseDown(0);
34 ctx->MouseMoveToPos(ImVec2(514, 258));
35 ctx->MouseUp(0);
36
37 // 5. Copy the selection
38 ctx->KeyDown(ImGuiKey_LeftCtrl);
39 ctx->KeyPress(ImGuiKey_C);
40 ctx->KeyUp(ImGuiKey_LeftCtrl);
41
42 // 6. Paste the selection
43 ctx->MouseMoveToPos(ImVec2(600, 300));
44 ctx->KeyDown(ImGuiKey_LeftCtrl);
45 ctx->KeyPress(ImGuiKey_V);
46 ctx->KeyUp(ImGuiKey_LeftCtrl);
47
48 // 7. Verify that the pasted tiles are correct
49 uint16_t new_tile1 = overworld->GetTile(75, 37);
50 uint16_t new_tile2 = overworld->GetTile(76, 37);
51 uint16_t new_tile3 = overworld->GetTile(75, 38);
52 uint16_t new_tile4 = overworld->GetTile(76, 38);
53
54 // The bug is that the selection wraps around, so the pasted tiles are incorrect.
55 // We expect the new tiles to be different from the original tiles.
56 IM_CHECK_NE(orig_tile1, new_tile1);
57 IM_CHECK_NE(orig_tile2, new_tile2);
58 IM_CHECK_NE(orig_tile3, new_tile3);
59 IM_CHECK_NE(orig_tile4, new_tile4);
60
61 // We also expect the pasted tiles to be the same as the selected tiles.
62 // The selected tiles are at (63, 32) and (64, 32), (63, 33) and (64, 33).
63 uint16_t selected_tile1 = overworld->GetTile(63, 32);
64 uint16_t selected_tile2 = overworld->GetTile(64, 32);
65 uint16_t selected_tile3 = overworld->GetTile(63, 33);
66 uint16_t selected_tile4 = overworld->GetTile(64, 33);
67
68 IM_CHECK_EQ(new_tile1, selected_tile1);
69 IM_CHECK_EQ(new_tile2, selected_tile2);
70 IM_CHECK_EQ(new_tile3, selected_tile3);
71 IM_CHECK_EQ(new_tile4, selected_tile4);
72
73 ctx->LogInfo("Original tiles: %d, %d, %d, %d", orig_tile1, orig_tile2, orig_tile3, orig_tile4);
74 ctx->LogInfo("Selected tiles: %d, %d, %d, %d", selected_tile1, selected_tile2, selected_tile3, selected_tile4);
75 ctx->LogInfo("New tiles: %d, %d, %d, %d", new_tile1, new_tile2, new_tile3, new_tile4);
76}
void E2ETest_CanvasSelectionTest(ImGuiTestContext *ctx)
Main controller for the application.
Definition controller.h:24
auto overworld() -> yaze::zelda3::Overworld *
Definition controller.h:39
Represents the full Overworld data, light and dark world.
Definition overworld.h:135
uint16_t GetTile(int x, int y) const
Definition overworld.h:293
void LoadRomInTest(ImGuiTestContext *ctx, const std::string &rom_path)
Definition test_utils.cc:8
void OpenEditorInTest(ImGuiTestContext *ctx, const std::string &editor_name)
Definition test_utils.cc:13