backend-infra-engineer: Release v0.3.3 snapshot
This commit is contained in:
@@ -18,7 +18,7 @@ class CanvasAutomationAPITest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
// Create a test canvas with known dimensions
|
||||
canvas_ = std::make_unique<gui::Canvas>("TestCanvas", ImVec2(512, 512),
|
||||
gui::CanvasGridSize::k16x16);
|
||||
gui::CanvasGridSize::k16x16);
|
||||
api_ = canvas_->GetAutomationAPI();
|
||||
ASSERT_NE(api_, nullptr);
|
||||
}
|
||||
@@ -34,21 +34,21 @@ class CanvasAutomationAPITest : public ::testing::Test {
|
||||
TEST_F(CanvasAutomationAPITest, TileToCanvas_BasicConversion) {
|
||||
// At 1.0x zoom, tile (0,0) should be at canvas (0,0)
|
||||
canvas_->set_global_scale(1.0f);
|
||||
|
||||
|
||||
ImVec2 pos = api_->TileToCanvas(0, 0);
|
||||
EXPECT_FLOAT_EQ(pos.x, 0.0f);
|
||||
EXPECT_FLOAT_EQ(pos.y, 0.0f);
|
||||
|
||||
|
||||
// Tile (1,0) should be at (16,0) for 16x16 grid
|
||||
pos = api_->TileToCanvas(1, 0);
|
||||
EXPECT_FLOAT_EQ(pos.x, 16.0f);
|
||||
EXPECT_FLOAT_EQ(pos.y, 0.0f);
|
||||
|
||||
|
||||
// Tile (0,1) should be at (0,16)
|
||||
pos = api_->TileToCanvas(0, 1);
|
||||
EXPECT_FLOAT_EQ(pos.x, 0.0f);
|
||||
EXPECT_FLOAT_EQ(pos.y, 16.0f);
|
||||
|
||||
|
||||
// Tile (10,10) should be at (160,160)
|
||||
pos = api_->TileToCanvas(10, 10);
|
||||
EXPECT_FLOAT_EQ(pos.x, 160.0f);
|
||||
@@ -58,11 +58,11 @@ TEST_F(CanvasAutomationAPITest, TileToCanvas_BasicConversion) {
|
||||
TEST_F(CanvasAutomationAPITest, TileToCanvas_WithZoom) {
|
||||
// At 2.0x zoom, tile coordinates should scale
|
||||
canvas_->set_global_scale(2.0f);
|
||||
|
||||
|
||||
ImVec2 pos = api_->TileToCanvas(1, 1);
|
||||
EXPECT_FLOAT_EQ(pos.x, 32.0f); // 1 * 16 * 2.0
|
||||
EXPECT_FLOAT_EQ(pos.y, 32.0f);
|
||||
|
||||
|
||||
// At 0.5x zoom, tile coordinates should scale down
|
||||
canvas_->set_global_scale(0.5f);
|
||||
pos = api_->TileToCanvas(10, 10);
|
||||
@@ -72,17 +72,17 @@ TEST_F(CanvasAutomationAPITest, TileToCanvas_WithZoom) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, CanvasToTile_BasicConversion) {
|
||||
canvas_->set_global_scale(1.0f);
|
||||
|
||||
|
||||
// Canvas (0,0) should be tile (0,0)
|
||||
ImVec2 tile = api_->CanvasToTile(ImVec2(0, 0));
|
||||
EXPECT_FLOAT_EQ(tile.x, 0.0f);
|
||||
EXPECT_FLOAT_EQ(tile.y, 0.0f);
|
||||
|
||||
|
||||
// Canvas (16,16) should be tile (1,1)
|
||||
tile = api_->CanvasToTile(ImVec2(16, 16));
|
||||
EXPECT_FLOAT_EQ(tile.x, 1.0f);
|
||||
EXPECT_FLOAT_EQ(tile.y, 1.0f);
|
||||
|
||||
|
||||
// Canvas (160,160) should be tile (10,10)
|
||||
tile = api_->CanvasToTile(ImVec2(160, 160));
|
||||
EXPECT_FLOAT_EQ(tile.x, 10.0f);
|
||||
@@ -92,11 +92,11 @@ TEST_F(CanvasAutomationAPITest, CanvasToTile_BasicConversion) {
|
||||
TEST_F(CanvasAutomationAPITest, CanvasToTile_WithZoom) {
|
||||
// At 2.0x zoom
|
||||
canvas_->set_global_scale(2.0f);
|
||||
|
||||
|
||||
ImVec2 tile = api_->CanvasToTile(ImVec2(32, 32));
|
||||
EXPECT_FLOAT_EQ(tile.x, 1.0f); // 32 / (16 * 2.0)
|
||||
EXPECT_FLOAT_EQ(tile.y, 1.0f);
|
||||
|
||||
|
||||
// At 0.5x zoom
|
||||
canvas_->set_global_scale(0.5f);
|
||||
tile = api_->CanvasToTile(ImVec2(8, 8));
|
||||
@@ -106,12 +106,12 @@ TEST_F(CanvasAutomationAPITest, CanvasToTile_WithZoom) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, CoordinateRoundTrip) {
|
||||
canvas_->set_global_scale(1.0f);
|
||||
|
||||
|
||||
// Test round-trip conversion
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
ImVec2 canvas_pos = api_->TileToCanvas(i, i);
|
||||
ImVec2 tile_pos = api_->CanvasToTile(canvas_pos);
|
||||
|
||||
|
||||
EXPECT_FLOAT_EQ(tile_pos.x, static_cast<float>(i));
|
||||
EXPECT_FLOAT_EQ(tile_pos.y, static_cast<float>(i));
|
||||
}
|
||||
@@ -131,7 +131,7 @@ TEST_F(CanvasAutomationAPITest, IsInBounds_InvalidCoordinates) {
|
||||
EXPECT_FALSE(api_->IsInBounds(-1, 0));
|
||||
EXPECT_FALSE(api_->IsInBounds(0, -1));
|
||||
EXPECT_FALSE(api_->IsInBounds(-1, -1));
|
||||
EXPECT_FALSE(api_->IsInBounds(32, 0)); // Out of bounds
|
||||
EXPECT_FALSE(api_->IsInBounds(32, 0)); // Out of bounds
|
||||
EXPECT_FALSE(api_->IsInBounds(0, 32));
|
||||
EXPECT_FALSE(api_->IsInBounds(100, 100));
|
||||
}
|
||||
@@ -147,11 +147,11 @@ TEST_F(CanvasAutomationAPITest, SetTileAt_WithCallback) {
|
||||
painted_tiles.push_back({x, y, tile_id});
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
// Paint some tiles
|
||||
EXPECT_TRUE(api_->SetTileAt(5, 5, 42));
|
||||
EXPECT_TRUE(api_->SetTileAt(10, 10, 100));
|
||||
|
||||
|
||||
ASSERT_EQ(painted_tiles.size(), 2);
|
||||
EXPECT_EQ(painted_tiles[0], std::make_tuple(5, 5, 42));
|
||||
EXPECT_EQ(painted_tiles[1], std::make_tuple(10, 10, 100));
|
||||
@@ -163,12 +163,12 @@ TEST_F(CanvasAutomationAPITest, SetTileAt_OutOfBounds) {
|
||||
callback_called = true;
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
// Out of bounds tiles should return false without calling callback
|
||||
EXPECT_FALSE(api_->SetTileAt(-1, 0, 42));
|
||||
EXPECT_FALSE(api_->SetTileAt(0, -1, 42));
|
||||
EXPECT_FALSE(api_->SetTileAt(100, 100, 42));
|
||||
|
||||
|
||||
EXPECT_FALSE(callback_called);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ TEST_F(CanvasAutomationAPITest, GetTileAt_WithCallback) {
|
||||
api_->SetTileQueryCallback([](int x, int y) {
|
||||
return x * 100 + y; // Simple deterministic value
|
||||
});
|
||||
|
||||
|
||||
EXPECT_EQ(api_->GetTileAt(0, 0), 0);
|
||||
EXPECT_EQ(api_->GetTileAt(1, 0), 100);
|
||||
EXPECT_EQ(api_->GetTileAt(0, 1), 1);
|
||||
@@ -186,7 +186,7 @@ TEST_F(CanvasAutomationAPITest, GetTileAt_WithCallback) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, GetTileAt_OutOfBounds) {
|
||||
api_->SetTileQueryCallback([](int x, int y) { return 42; });
|
||||
|
||||
|
||||
EXPECT_EQ(api_->GetTileAt(-1, 0), -1);
|
||||
EXPECT_EQ(api_->GetTileAt(0, -1), -1);
|
||||
EXPECT_EQ(api_->GetTileAt(100, 100), -1);
|
||||
@@ -198,15 +198,10 @@ TEST_F(CanvasAutomationAPITest, SetTiles_BatchOperation) {
|
||||
painted_tiles.push_back({x, y, tile_id});
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
std::vector<std::tuple<int, int, int>> tiles_to_paint = {
|
||||
{0, 0, 10},
|
||||
{1, 0, 11},
|
||||
{2, 0, 12},
|
||||
{0, 1, 20},
|
||||
{1, 1, 21}
|
||||
};
|
||||
|
||||
{0, 0, 10}, {1, 0, 11}, {2, 0, 12}, {0, 1, 20}, {1, 1, 21}};
|
||||
|
||||
EXPECT_TRUE(api_->SetTiles(tiles_to_paint));
|
||||
EXPECT_EQ(painted_tiles.size(), 5);
|
||||
}
|
||||
@@ -217,7 +212,7 @@ TEST_F(CanvasAutomationAPITest, SetTiles_BatchOperation) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, SelectTile) {
|
||||
api_->SelectTile(5, 5);
|
||||
|
||||
|
||||
auto selection = api_->GetSelection();
|
||||
EXPECT_TRUE(selection.has_selection);
|
||||
EXPECT_EQ(selection.selected_tiles.size(), 1);
|
||||
@@ -225,13 +220,13 @@ TEST_F(CanvasAutomationAPITest, SelectTile) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, SelectTileRect) {
|
||||
api_->SelectTileRect(5, 5, 9, 9);
|
||||
|
||||
|
||||
auto selection = api_->GetSelection();
|
||||
EXPECT_TRUE(selection.has_selection);
|
||||
|
||||
|
||||
// 5x5 rectangle = 25 tiles
|
||||
EXPECT_EQ(selection.selected_tiles.size(), 25);
|
||||
|
||||
|
||||
// Check first and last tiles
|
||||
EXPECT_FLOAT_EQ(selection.selected_tiles[0].x, 5.0f);
|
||||
EXPECT_FLOAT_EQ(selection.selected_tiles[0].y, 5.0f);
|
||||
@@ -242,7 +237,7 @@ TEST_F(CanvasAutomationAPITest, SelectTileRect) {
|
||||
TEST_F(CanvasAutomationAPITest, SelectTileRect_SwappedCoordinates) {
|
||||
// Should handle coordinates in any order
|
||||
api_->SelectTileRect(9, 9, 5, 5); // Reversed
|
||||
|
||||
|
||||
auto selection = api_->GetSelection();
|
||||
EXPECT_TRUE(selection.has_selection);
|
||||
EXPECT_EQ(selection.selected_tiles.size(), 25);
|
||||
@@ -250,12 +245,12 @@ TEST_F(CanvasAutomationAPITest, SelectTileRect_SwappedCoordinates) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, ClearSelection) {
|
||||
api_->SelectTileRect(5, 5, 10, 10);
|
||||
|
||||
|
||||
auto selection = api_->GetSelection();
|
||||
EXPECT_TRUE(selection.has_selection);
|
||||
|
||||
|
||||
api_->ClearSelection();
|
||||
|
||||
|
||||
selection = api_->GetSelection();
|
||||
EXPECT_FALSE(selection.has_selection);
|
||||
EXPECT_EQ(selection.selected_tiles.size(), 0);
|
||||
@@ -265,7 +260,7 @@ TEST_F(CanvasAutomationAPITest, SelectTile_OutOfBounds) {
|
||||
api_->SelectTile(-1, 0);
|
||||
auto selection = api_->GetSelection();
|
||||
EXPECT_FALSE(selection.has_selection);
|
||||
|
||||
|
||||
api_->SelectTile(100, 100);
|
||||
selection = api_->GetSelection();
|
||||
EXPECT_FALSE(selection.has_selection);
|
||||
@@ -278,10 +273,10 @@ TEST_F(CanvasAutomationAPITest, SelectTile_OutOfBounds) {
|
||||
TEST_F(CanvasAutomationAPITest, SetZoom_ValidRange) {
|
||||
api_->SetZoom(1.0f);
|
||||
EXPECT_FLOAT_EQ(api_->GetZoom(), 1.0f);
|
||||
|
||||
|
||||
api_->SetZoom(2.0f);
|
||||
EXPECT_FLOAT_EQ(api_->GetZoom(), 2.0f);
|
||||
|
||||
|
||||
api_->SetZoom(0.5f);
|
||||
EXPECT_FLOAT_EQ(api_->GetZoom(), 0.5f);
|
||||
}
|
||||
@@ -290,10 +285,10 @@ TEST_F(CanvasAutomationAPITest, SetZoom_Clamping) {
|
||||
// Should clamp to 0.25 - 4.0 range
|
||||
api_->SetZoom(10.0f);
|
||||
EXPECT_LE(api_->GetZoom(), 4.0f);
|
||||
|
||||
|
||||
api_->SetZoom(0.1f);
|
||||
EXPECT_GE(api_->GetZoom(), 0.25f);
|
||||
|
||||
|
||||
api_->SetZoom(-1.0f);
|
||||
EXPECT_GE(api_->GetZoom(), 0.25f);
|
||||
}
|
||||
@@ -303,7 +298,7 @@ TEST_F(CanvasAutomationAPITest, ScrollToTile_ValidTile) {
|
||||
api_->ScrollToTile(0, 0, true);
|
||||
api_->ScrollToTile(10, 10, false);
|
||||
api_->ScrollToTile(15, 15, true);
|
||||
|
||||
|
||||
// Just verify no crash - actual scroll behavior depends on ImGui state
|
||||
}
|
||||
|
||||
@@ -311,7 +306,7 @@ TEST_F(CanvasAutomationAPITest, ScrollToTile_OutOfBounds) {
|
||||
// Should handle out of bounds gracefully
|
||||
api_->ScrollToTile(-1, 0, true);
|
||||
api_->ScrollToTile(100, 100, true);
|
||||
|
||||
|
||||
// Should not crash
|
||||
}
|
||||
|
||||
@@ -320,8 +315,9 @@ TEST_F(CanvasAutomationAPITest, CenterOn_ValidTile) {
|
||||
api_->CenterOn(10, 10);
|
||||
api_->CenterOn(0, 0);
|
||||
api_->CenterOn(20, 20);
|
||||
|
||||
// Verify scroll position changed (should be non-zero after centering on non-origin)
|
||||
|
||||
// Verify scroll position changed (should be non-zero after centering on
|
||||
// non-origin)
|
||||
ImVec2 scroll = canvas_->scrolling();
|
||||
// Scroll values will depend on canvas size, just verify they're set
|
||||
}
|
||||
@@ -329,7 +325,7 @@ TEST_F(CanvasAutomationAPITest, CenterOn_ValidTile) {
|
||||
TEST_F(CanvasAutomationAPITest, CenterOn_OutOfBounds) {
|
||||
api_->CenterOn(-1, 0);
|
||||
api_->CenterOn(100, 100);
|
||||
|
||||
|
||||
// Should not crash
|
||||
}
|
||||
|
||||
@@ -339,32 +335,32 @@ TEST_F(CanvasAutomationAPITest, CenterOn_OutOfBounds) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, GetDimensions) {
|
||||
canvas_->set_global_scale(1.0f);
|
||||
|
||||
|
||||
auto dims = api_->GetDimensions();
|
||||
EXPECT_EQ(dims.tile_size, 16); // 16x16 grid
|
||||
EXPECT_EQ(dims.tile_size, 16); // 16x16 grid
|
||||
EXPECT_EQ(dims.width_tiles, 32); // 512 / 16
|
||||
EXPECT_EQ(dims.height_tiles, 32);
|
||||
}
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, GetDimensions_WithZoom) {
|
||||
canvas_->set_global_scale(2.0f);
|
||||
|
||||
|
||||
auto dims = api_->GetDimensions();
|
||||
EXPECT_EQ(dims.tile_size, 16);
|
||||
EXPECT_EQ(dims.width_tiles, 16); // 512 / (16 * 2.0)
|
||||
EXPECT_EQ(dims.width_tiles, 16); // 512 / (16 * 2.0)
|
||||
EXPECT_EQ(dims.height_tiles, 16);
|
||||
}
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, GetVisibleRegion) {
|
||||
canvas_->set_global_scale(1.0f);
|
||||
canvas_->set_scrolling(ImVec2(0, 0));
|
||||
|
||||
|
||||
auto region = api_->GetVisibleRegion();
|
||||
|
||||
|
||||
// At origin with no scroll, should start at (0,0)
|
||||
EXPECT_GE(region.min_x, 0);
|
||||
EXPECT_GE(region.min_y, 0);
|
||||
|
||||
|
||||
// Should have valid bounds
|
||||
EXPECT_GE(region.max_x, region.min_x);
|
||||
EXPECT_GE(region.max_y, region.min_y);
|
||||
@@ -373,11 +369,11 @@ TEST_F(CanvasAutomationAPITest, GetVisibleRegion) {
|
||||
TEST_F(CanvasAutomationAPITest, IsTileVisible_AtOrigin) {
|
||||
canvas_->set_global_scale(1.0f);
|
||||
canvas_->set_scrolling(ImVec2(0, 0));
|
||||
|
||||
|
||||
// Tiles at origin should be visible
|
||||
EXPECT_TRUE(api_->IsTileVisible(0, 0));
|
||||
EXPECT_TRUE(api_->IsTileVisible(1, 1));
|
||||
|
||||
|
||||
// Tiles far away might not be visible (depends on canvas size)
|
||||
// We just verify the method doesn't crash
|
||||
api_->IsTileVisible(50, 50);
|
||||
@@ -396,36 +392,33 @@ TEST_F(CanvasAutomationAPITest, IsTileVisible_OutOfBounds) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, CompleteWorkflow) {
|
||||
// Simulate a complete automation workflow
|
||||
|
||||
|
||||
// 1. Set zoom level
|
||||
api_->SetZoom(1.0f);
|
||||
EXPECT_FLOAT_EQ(api_->GetZoom(), 1.0f);
|
||||
|
||||
|
||||
// 2. Select a tile region
|
||||
api_->SelectTileRect(0, 0, 4, 4);
|
||||
auto selection = api_->GetSelection();
|
||||
EXPECT_EQ(selection.selected_tiles.size(), 25);
|
||||
|
||||
|
||||
// 3. Query tile data with callback
|
||||
api_->SetTileQueryCallback([](int x, int y) {
|
||||
return x + y * 100;
|
||||
});
|
||||
|
||||
api_->SetTileQueryCallback([](int x, int y) { return x + y * 100; });
|
||||
|
||||
EXPECT_EQ(api_->GetTileAt(2, 3), 302);
|
||||
|
||||
|
||||
// 4. Paint tiles with callback
|
||||
std::vector<std::tuple<int, int, int>> painted;
|
||||
api_->SetTilePaintCallback([&](int x, int y, int tile_id) {
|
||||
painted.push_back({x, y, tile_id});
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
std::vector<std::tuple<int, int, int>> tiles = {
|
||||
{0, 0, 10}, {1, 0, 11}, {2, 0, 12}
|
||||
};
|
||||
{0, 0, 10}, {1, 0, 11}, {2, 0, 12}};
|
||||
EXPECT_TRUE(api_->SetTiles(tiles));
|
||||
EXPECT_EQ(painted.size(), 3);
|
||||
|
||||
|
||||
// 5. Clear selection
|
||||
api_->ClearSelection();
|
||||
selection = api_->GetSelection();
|
||||
@@ -434,19 +427,19 @@ TEST_F(CanvasAutomationAPITest, CompleteWorkflow) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, DifferentGridSizes) {
|
||||
// Test with 8x8 grid
|
||||
auto canvas_8x8 = std::make_unique<gui::Canvas>(
|
||||
"Test8x8", ImVec2(512, 512), gui::CanvasGridSize::k8x8);
|
||||
auto canvas_8x8 = std::make_unique<gui::Canvas>("Test8x8", ImVec2(512, 512),
|
||||
gui::CanvasGridSize::k8x8);
|
||||
auto api_8x8 = canvas_8x8->GetAutomationAPI();
|
||||
|
||||
|
||||
auto dims = api_8x8->GetDimensions();
|
||||
EXPECT_EQ(dims.tile_size, 8);
|
||||
EXPECT_EQ(dims.width_tiles, 64); // 512 / 8
|
||||
|
||||
|
||||
// Test with 32x32 grid
|
||||
auto canvas_32x32 = std::make_unique<gui::Canvas>(
|
||||
"Test32x32", ImVec2(512, 512), gui::CanvasGridSize::k32x32);
|
||||
auto api_32x32 = canvas_32x32->GetAutomationAPI();
|
||||
|
||||
|
||||
dims = api_32x32->GetDimensions();
|
||||
EXPECT_EQ(dims.tile_size, 32);
|
||||
EXPECT_EQ(dims.width_tiles, 16); // 512 / 32
|
||||
@@ -454,19 +447,19 @@ TEST_F(CanvasAutomationAPITest, DifferentGridSizes) {
|
||||
|
||||
TEST_F(CanvasAutomationAPITest, MultipleZoomLevels) {
|
||||
float zoom_levels[] = {0.25f, 0.5f, 1.0f, 1.5f, 2.0f, 3.0f, 4.0f};
|
||||
|
||||
|
||||
for (float zoom : zoom_levels) {
|
||||
api_->SetZoom(zoom);
|
||||
float actual_zoom = api_->GetZoom();
|
||||
|
||||
|
||||
// Should be clamped to valid range
|
||||
EXPECT_GE(actual_zoom, 0.25f);
|
||||
EXPECT_LE(actual_zoom, 4.0f);
|
||||
|
||||
|
||||
// Coordinate conversion should still work
|
||||
ImVec2 canvas_pos = api_->TileToCanvas(10, 10);
|
||||
ImVec2 tile_pos = api_->CanvasToTile(canvas_pos);
|
||||
|
||||
|
||||
EXPECT_FLOAT_EQ(tile_pos.x, 10.0f);
|
||||
EXPECT_FLOAT_EQ(tile_pos.y, 10.0f);
|
||||
}
|
||||
@@ -474,4 +467,3 @@ TEST_F(CanvasAutomationAPITest, MultipleZoomLevels) {
|
||||
|
||||
} // namespace test
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "app/gui/canvas/canvas.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "app/gui/canvas/canvas.h"
|
||||
#include "testing.h"
|
||||
|
||||
namespace yaze {
|
||||
@@ -27,8 +26,8 @@ class CanvasCoordinateSyncTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
// Create a test canvas with known dimensions (4096x4096 for overworld)
|
||||
canvas_ = std::make_unique<gui::Canvas>("OverworldCanvas", ImVec2(4096, 4096),
|
||||
gui::CanvasGridSize::k16x16);
|
||||
canvas_ = std::make_unique<gui::Canvas>(
|
||||
"OverworldCanvas", ImVec2(4096, 4096), gui::CanvasGridSize::k16x16);
|
||||
canvas_->set_global_scale(1.0f);
|
||||
}
|
||||
|
||||
@@ -100,16 +99,15 @@ TEST_F(CanvasCoordinateSyncTest, MapCalculation_SmallMaps) {
|
||||
|
||||
// Simulate hover at different world positions
|
||||
std::vector<ImVec2> test_positions = {
|
||||
ImVec2(0, 0), // Map (0, 0)
|
||||
ImVec2(512, 0), // Map (1, 0)
|
||||
ImVec2(0, 512), // Map (0, 1)
|
||||
ImVec2(512, 512), // Map (1, 1)
|
||||
ImVec2(1536, 1024), // Map (3, 2)
|
||||
ImVec2(0, 0), // Map (0, 0)
|
||||
ImVec2(512, 0), // Map (1, 0)
|
||||
ImVec2(0, 512), // Map (0, 1)
|
||||
ImVec2(512, 512), // Map (1, 1)
|
||||
ImVec2(1536, 1024), // Map (3, 2)
|
||||
};
|
||||
|
||||
std::vector<std::pair<int, int>> expected_maps = {
|
||||
{0, 0}, {1, 0}, {0, 1}, {1, 1}, {3, 2}
|
||||
};
|
||||
{0, 0}, {1, 0}, {0, 1}, {1, 1}, {3, 2}};
|
||||
|
||||
for (size_t i = 0; i < test_positions.size(); ++i) {
|
||||
ImVec2 pos = test_positions[i];
|
||||
@@ -127,15 +125,14 @@ TEST_F(CanvasCoordinateSyncTest, MapCalculation_LargeMaps) {
|
||||
|
||||
// Large maps should span multiple standard map coordinates
|
||||
std::vector<ImVec2> test_positions = {
|
||||
ImVec2(0, 0), // Large map (0, 0)
|
||||
ImVec2(1024, 0), // Large map (1, 0)
|
||||
ImVec2(0, 1024), // Large map (0, 1)
|
||||
ImVec2(2048, 2048), // Large map (2, 2)
|
||||
ImVec2(0, 0), // Large map (0, 0)
|
||||
ImVec2(1024, 0), // Large map (1, 0)
|
||||
ImVec2(0, 1024), // Large map (0, 1)
|
||||
ImVec2(2048, 2048), // Large map (2, 2)
|
||||
};
|
||||
|
||||
std::vector<std::pair<int, int>> expected_large_maps = {
|
||||
{0, 0}, {1, 0}, {0, 1}, {2, 2}
|
||||
};
|
||||
{0, 0}, {1, 0}, {0, 1}, {2, 2}};
|
||||
|
||||
for (size_t i = 0; i < test_positions.size(); ++i) {
|
||||
ImVec2 pos = test_positions[i];
|
||||
@@ -152,8 +149,8 @@ TEST_F(CanvasCoordinateSyncTest, MapCalculation_LargeMaps) {
|
||||
// ============================================================================
|
||||
|
||||
TEST_F(CanvasCoordinateSyncTest, HoverPosition_ScaleInvariant) {
|
||||
// REGRESSION TEST: Hover position should be in world space regardless of scale
|
||||
// The bug was scale-dependent because it used screen coordinates
|
||||
// REGRESSION TEST: Hover position should be in world space regardless of
|
||||
// scale The bug was scale-dependent because it used screen coordinates
|
||||
|
||||
auto test_hover_at_scale = [&](float scale) {
|
||||
canvas_->set_global_scale(scale);
|
||||
@@ -186,7 +183,8 @@ TEST_F(CanvasCoordinateSyncTest, OverworldMapHighlight_UsesHoverNotDrawn) {
|
||||
// The pattern used in DrawOverworldEdits (line 664) for painting:
|
||||
auto drawn_pos = canvas_->drawn_tile_position();
|
||||
|
||||
// The pattern that SHOULD be used in CheckForCurrentMap (line 1041) for highlighting:
|
||||
// The pattern that SHOULD be used in CheckForCurrentMap (line 1041) for
|
||||
// highlighting:
|
||||
auto hover_pos = canvas_->hover_mouse_pos();
|
||||
|
||||
// These are different methods for different purposes:
|
||||
@@ -210,19 +208,19 @@ TEST_F(CanvasCoordinateSyncTest, OverworldMapIndex_From8x8Grid) {
|
||||
};
|
||||
|
||||
std::vector<TestCase> test_cases = {
|
||||
// Light World (0x00 - 0x3F)
|
||||
{ImVec2(0, 0), 0, 0}, // Map 0 (Light World)
|
||||
{ImVec2(512, 0), 0, 1}, // Map 1
|
||||
{ImVec2(1024, 512), 0, 10}, // Map 10 = 2 + 1*8
|
||||
// Light World (0x00 - 0x3F)
|
||||
{ImVec2(0, 0), 0, 0}, // Map 0 (Light World)
|
||||
{ImVec2(512, 0), 0, 1}, // Map 1
|
||||
{ImVec2(1024, 512), 0, 10}, // Map 10 = 2 + 1*8
|
||||
|
||||
// Dark World (0x40 - 0x7F)
|
||||
{ImVec2(0, 0), 1, 0x40}, // Map 0x40 (Dark World)
|
||||
{ImVec2(512, 0), 1, 0x41}, // Map 0x41
|
||||
{ImVec2(1024, 512), 1, 0x4A}, // Map 0x4A = 0x40 + 10
|
||||
// Dark World (0x40 - 0x7F)
|
||||
{ImVec2(0, 0), 1, 0x40}, // Map 0x40 (Dark World)
|
||||
{ImVec2(512, 0), 1, 0x41}, // Map 0x41
|
||||
{ImVec2(1024, 512), 1, 0x4A}, // Map 0x4A = 0x40 + 10
|
||||
|
||||
// Special World (0x80+)
|
||||
{ImVec2(0, 0), 2, 0x80}, // Map 0x80 (Special World)
|
||||
{ImVec2(512, 512), 2, 0x89}, // Map 0x89 = 0x80 + 9
|
||||
// Special World (0x80+)
|
||||
{ImVec2(0, 0), 2, 0x80}, // Map 0x80 (Special World)
|
||||
{ImVec2(512, 512), 2, 0x89}, // Map 0x89 = 0x80 + 9
|
||||
};
|
||||
|
||||
for (const auto& tc : test_cases) {
|
||||
@@ -237,8 +235,8 @@ TEST_F(CanvasCoordinateSyncTest, OverworldMapIndex_From8x8Grid) {
|
||||
}
|
||||
|
||||
EXPECT_EQ(hovered_map, tc.expected_map_index)
|
||||
<< "Failed for world " << tc.current_world
|
||||
<< " at position (" << tc.hover_pos.x << ", " << tc.hover_pos.y << ")";
|
||||
<< "Failed for world " << tc.current_world << " at position ("
|
||||
<< tc.hover_pos.x << ", " << tc.hover_pos.y << ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,12 +250,12 @@ TEST_F(CanvasCoordinateSyncTest, MapBoundaries_512x512) {
|
||||
|
||||
// Boundary coordinates (edges of maps)
|
||||
std::vector<ImVec2> boundary_positions = {
|
||||
ImVec2(511, 0), // Right edge of map 0
|
||||
ImVec2(512, 0), // Left edge of map 1
|
||||
ImVec2(0, 511), // Bottom edge of map 0
|
||||
ImVec2(0, 512), // Top edge of map 8
|
||||
ImVec2(511, 511), // Corner of map 0
|
||||
ImVec2(512, 512), // Corner of map 9
|
||||
ImVec2(511, 0), // Right edge of map 0
|
||||
ImVec2(512, 0), // Left edge of map 1
|
||||
ImVec2(0, 511), // Bottom edge of map 0
|
||||
ImVec2(0, 512), // Top edge of map 8
|
||||
ImVec2(511, 511), // Corner of map 0
|
||||
ImVec2(512, 512), // Corner of map 9
|
||||
};
|
||||
|
||||
for (const auto& pos : boundary_positions) {
|
||||
@@ -276,10 +274,10 @@ TEST_F(CanvasCoordinateSyncTest, MapBoundaries_1024x1024) {
|
||||
const int kLargeMapSize = 1024;
|
||||
|
||||
std::vector<ImVec2> boundary_positions = {
|
||||
ImVec2(1023, 0), // Right edge of large map 0
|
||||
ImVec2(1024, 0), // Left edge of large map 1
|
||||
ImVec2(0, 1023), // Bottom edge of large map 0
|
||||
ImVec2(0, 1024), // Top edge of large map 4 (0,1 in 4x4 grid)
|
||||
ImVec2(1023, 0), // Right edge of large map 0
|
||||
ImVec2(1024, 0), // Left edge of large map 1
|
||||
ImVec2(0, 1023), // Bottom edge of large map 0
|
||||
ImVec2(0, 1024), // Top edge of large map 4 (0,1 in 4x4 grid)
|
||||
};
|
||||
|
||||
for (const auto& pos : boundary_positions) {
|
||||
|
||||
@@ -18,7 +18,7 @@ class TileSelectorWidgetTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
// Create a test canvas
|
||||
canvas_ = std::make_unique<gui::Canvas>("TestCanvas", ImVec2(512, 512),
|
||||
gui::CanvasGridSize::k16x16);
|
||||
gui::CanvasGridSize::k16x16);
|
||||
|
||||
// Create a test config
|
||||
config_.tile_size = 16;
|
||||
@@ -97,16 +97,16 @@ TEST_F(TileSelectorWidgetTest, TileOrigin) {
|
||||
|
||||
// Test tile at (1,0)
|
||||
origin = widget.TileOrigin(1);
|
||||
float expected_x = config_.draw_offset.x +
|
||||
(config_.tile_size * config_.display_scale);
|
||||
float expected_x =
|
||||
config_.draw_offset.x + (config_.tile_size * config_.display_scale);
|
||||
EXPECT_FLOAT_EQ(origin.x, expected_x);
|
||||
EXPECT_FLOAT_EQ(origin.y, config_.draw_offset.y);
|
||||
|
||||
// Test tile at (0,1) - first tile of second row
|
||||
origin = widget.TileOrigin(8);
|
||||
expected_x = config_.draw_offset.x;
|
||||
float expected_y = config_.draw_offset.y +
|
||||
(config_.tile_size * config_.display_scale);
|
||||
float expected_y =
|
||||
config_.draw_offset.y + (config_.tile_size * config_.display_scale);
|
||||
EXPECT_FLOAT_EQ(origin.x, expected_x);
|
||||
EXPECT_FLOAT_EQ(origin.y, expected_y);
|
||||
|
||||
@@ -191,4 +191,3 @@ TEST_F(TileSelectorWidgetTest, DifferentConfigs) {
|
||||
|
||||
} // namespace test
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
Reference in New Issue
Block a user