From 81277fdaf1744c2a62929d56520e37e053d806c0 Mon Sep 17 00:00:00 2001 From: Daniel Cronqvist Date: Mon, 28 Apr 2025 20:11:19 +0200 Subject: [PATCH] Add test data that fails due to bug from reported issue --- .../map-duplicate-object-id-bug.cs | 131 ++++++++++++++++++ .../map-duplicate-object-id-bug.tmj | 79 +++++++++++ .../map-duplicate-object-id-bug.tmx | 30 ++++ .../map-duplicate-object-id-bug/template.tj | 18 +++ .../map-duplicate-object-id-bug/template.tx | 6 + .../map-duplicate-object-id-bug/tiles.png | Bin 0 -> 156 bytes .../map-duplicate-object-id-bug/tiles.tsj | 20 +++ .../map-duplicate-object-id-bug/tiles.tsx | 5 + .../UnitTests/Serialization/LoaderTests.cs | 35 +++++ .../UnitTests/Serialization/TestData.cs | 1 + 10 files changed, 325 insertions(+) create mode 100644 src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.cs create mode 100644 src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.tmj create mode 100644 src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.tmx create mode 100644 src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/template.tj create mode 100644 src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/template.tx create mode 100644 src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.png create mode 100644 src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.tsj create mode 100644 src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.tsx diff --git a/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.cs b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.cs new file mode 100644 index 0000000..63aa260 --- /dev/null +++ b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.cs @@ -0,0 +1,131 @@ +namespace DotTiled.Tests; + +public partial class TestData +{ + public static Map MapDuplicateObjectIdBug(string ext) => new Map + { + Class = "", + Orientation = MapOrientation.Orthogonal, + Width = 64, + Height = 64, + TileWidth = 16, + TileHeight = 16, + Infinite = true, + ParallaxOriginX = 0, + ParallaxOriginY = 0, + RenderOrder = RenderOrder.RightDown, + CompressionLevel = -1, + BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, + Version = "1.10", + TiledVersion = "1.11.2", + NextLayerID = 2, + NextObjectID = 3, + Tilesets = [ + new Tileset + { + FirstGID = 1, + Source = ext == "tmx" ? "tiles.tsx" : "tiles.tsj", + Version = "1.10", + TiledVersion = "1.11.2", + Name = "Tiles", + TileWidth = 16, + TileHeight = 16, + TileCount = 4, + Columns = 2, + Grid = new Grid + { + Orientation = GridOrientation.Orthogonal, + Width = 32, + Height = 32 + }, + Image = new Image + { + Source = "tiles.png", + Width = 32, + Height = 32, + Format = ImageFormat.Png + } + } + ], + Layers = [ + new TileLayer + { + ID = 1, + Name = "Tile Layer 1", + Width = ext == "tmx" ? 64 : 16, + Height = ext == "tmx" ? 64 : 16, + Data = new Data + { + Encoding = DataEncoding.Csv, + Chunks = new Optional([ + new Chunk + { + X = 0, + Y = 0, + Width = 16, + Height = 16, + GlobalTileIDs = [ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 + ], + FlippingFlags = GetAllNoneFlippingFlags(16 * 16) + } + ]) + } + }, + new ObjectLayer + { + ID = 3, + Name = "Object Layer 1", + Objects = [ + new TileObject + { + ID = 1, + Template = ext == "tmx" ? "template.tx" : "template.tj", + X = 80, + Y = 144, + + GID = 4, + Width = 16, + Height = 16, + }, + new TileObject + { + ID = 2, + Template = ext == "tmx" ? "template.tx" : "template.tj", + X = 48, + Y = 144, + + GID = 4, + Width = 16, + Height = 16, + } + ] + } + ] + }; + + private static FlippingFlags[] GetAllNoneFlippingFlags(int count) + { + var flippingFlags = new FlippingFlags[count]; + for (int i = 0; i < count; i++) + { + flippingFlags[i] = FlippingFlags.None; + } + return flippingFlags; + } +} diff --git a/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.tmj b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.tmj new file mode 100644 index 0000000..bb2bef5 --- /dev/null +++ b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.tmj @@ -0,0 +1,79 @@ +{ "compressionlevel":-1, + "height":64, + "infinite":true, + "layers":[ + { + "chunks":[ + { + "data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + "height":16, + "width":16, + "x":0, + "y":0 + }], + "height":16, + "id":1, + "name":"Tile Layer 1", + "opacity":1, + "startx":0, + "starty":0, + "type":"tilelayer", + "visible":true, + "width":16, + "x":0, + "y":0 + }, + { + "draworder":"topdown", + "id":3, + "name":"Object Layer 1", + "objects":[ + { + "id":1, + "template":"template.tj", + "x":80, + "y":144 + }, + { + "id":2, + "template":"template.tj", + "x":48, + "y":144 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + }], + "nextlayerid":2, + "nextobjectid":3, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.11.2", + "tileheight":16, + "tilesets":[ + { + "firstgid":1, + "source":"tiles.tsj" + }], + "tilewidth":16, + "type":"map", + "version":"1.10", + "width":64 +} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.tmx b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.tmx new file mode 100644 index 0000000..908a239 --- /dev/null +++ b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/map-duplicate-object-id-bug.tmx @@ -0,0 +1,30 @@ + + + + + + +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 + + + + + + + + diff --git a/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/template.tj b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/template.tj new file mode 100644 index 0000000..239fd52 --- /dev/null +++ b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/template.tj @@ -0,0 +1,18 @@ +{ "object": + { + "gid":4, + "height":16, + "id":2, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":16 + }, + "tileset": + { + "firstgid":1, + "source":"tiles.tsj" + }, + "type":"template" +} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/template.tx b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/template.tx new file mode 100644 index 0000000..eba706f --- /dev/null +++ b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/template.tx @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.png b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.png new file mode 100644 index 0000000000000000000000000000000000000000..b04722c46bc137fb5b14b8ae61095a0ea0b644bd GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6-$0X`wFzZm}i2eN1W|G%H%O|SkoAe*zmBeIx*f$uN~Gak=hkpdKy^mK6y u(Kw&n!04zU@si0aAc2QfIqJX-35Ex{#*86fIxK*S7(8A5T-G@yGywpb$SN}c literal 0 HcmV?d00001 diff --git a/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.tsj b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.tsj new file mode 100644 index 0000000..b6f69db --- /dev/null +++ b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.tsj @@ -0,0 +1,20 @@ +{ "columns":2, + "grid": + { + "height":32, + "orientation":"orthogonal", + "width":32 + }, + "image":"tiles.png", + "imageheight":32, + "imagewidth":32, + "margin":0, + "name":"Tiles", + "spacing":0, + "tilecount":4, + "tiledversion":"1.11.2", + "tileheight":16, + "tilewidth":16, + "type":"tileset", + "version":"1.10" +} \ No newline at end of file diff --git a/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.tsx b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.tsx new file mode 100644 index 0000000..5d6aa69 --- /dev/null +++ b/src/DotTiled.Tests/TestData/Maps/map-duplicate-object-id-bug/tiles.tsx @@ -0,0 +1,5 @@ + + + + + diff --git a/src/DotTiled.Tests/UnitTests/Serialization/LoaderTests.cs b/src/DotTiled.Tests/UnitTests/Serialization/LoaderTests.cs index b25b157..58a70df 100644 --- a/src/DotTiled.Tests/UnitTests/Serialization/LoaderTests.cs +++ b/src/DotTiled.Tests/UnitTests/Serialization/LoaderTests.cs @@ -315,4 +315,39 @@ public class LoaderTests // Assert DotTiledAssert.AssertProperties(customClassDefinition.Members, result.Properties); } + + public static IEnumerable Maps => TestData.MapTests; + + [Theory] + [MemberData(nameof(Maps))] + public void LoadMap_ValidFilesExternalTilesetsAndTemplatesWithCache_ReturnsMapThatEqualsExpected( + string testDataFile, + Func expectedMap, + IReadOnlyCollection customTypeDefinitions) + { + // Arrange + string[] fileFormats = [".tmx", ".tmj"]; + + foreach (var fileFormat in fileFormats) + { + var testDataFileWithFormat = testDataFile + fileFormat; + var resourceReader = Substitute.For(); + resourceReader.Read(Arg.Any()).Returns(callInfo => + { + var filePath = callInfo.Arg(); + return TestData.GetRawStringFor(filePath); + }); + + var loader = Loader.DefaultWith( + resourceReader: resourceReader, + customTypeDefinitions: customTypeDefinitions); + + // Act + var map = loader.LoadMap(testDataFileWithFormat); + + // Assert + Assert.NotNull(map); + DotTiledAssert.AssertMap(expectedMap(fileFormat[1..]), map); + } + } } diff --git a/src/DotTiled.Tests/UnitTests/Serialization/TestData.cs b/src/DotTiled.Tests/UnitTests/Serialization/TestData.cs index 677dfb0..2d59b39 100644 --- a/src/DotTiled.Tests/UnitTests/Serialization/TestData.cs +++ b/src/DotTiled.Tests/UnitTests/Serialization/TestData.cs @@ -34,6 +34,7 @@ public static partial class TestData public static IEnumerable MapTests => [ [GetMapPath("default-map"), (string f) => DefaultMap(), Array.Empty()], + [GetMapPath("map-duplicate-object-id-bug"), (string f) => MapDuplicateObjectIdBug(f), Array.Empty()], [GetMapPath("map-with-common-props"), (string f) => MapWithCommonProps(), Array.Empty()], [GetMapPath("map-with-custom-type-props"), (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()], [GetMapPath("map-with-custom-type-props-without-defs"), (string f) => MapWithCustomTypePropsWithoutDefs(), Array.Empty()],