diff options
Diffstat (limited to 'internal/game/map_bounds_regression_test.go')
| -rw-r--r-- | internal/game/map_bounds_regression_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/game/map_bounds_regression_test.go b/internal/game/map_bounds_regression_test.go new file mode 100644 index 0000000..dd3423b --- /dev/null +++ b/internal/game/map_bounds_regression_test.go @@ -0,0 +1,34 @@ +package game + +import ( + "testing" + + "thehouseoficarus/internal/player" +) + +// TestMapDimensionsClamped: the player-settable map size drives a direct +// mapHeight x mapWidth allocation in buildFullMap, so an unbounded option +// value is a fatal out-of-memory kill reachable by any authenticated player +// (and persisted in the account file, so it repeats on login). The clamp must +// cap both dimensions while leaving ordinary values alone. +func TestMapDimensionsClamped(t *testing.T) { + p := player.New("mapper") + + p.Options = map[string]any{"map_width": 100000, "map_height": 100000} + w, h := mapDimensions(p) + if w != maxMapDimension || h != maxMapDimension { + t.Fatalf("huge map dimensions = (%d,%d), want (%d,%d)", w, h, maxMapDimension, maxMapDimension) + } + + p.Options = map[string]any{"map_width": -5, "map_height": 0} + w, h = mapDimensions(p) + if w != 5 || h != 5 { + t.Fatalf("undersized map dimensions = (%d,%d), want (5,5)", w, h) + } + + p.Options = map[string]any{"map_width": 30, "map_height": 20} + w, h = mapDimensions(p) + if w != 30 || h != 20 { + t.Fatalf("normal map dimensions = (%d,%d), want (30,20)", w, h) + } +} |
