Gridarta Editor
DefaultMapManagerTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.mapmanager;
21 
22 import java.awt.Point;
23 import java.io.File;
24 import java.io.IOException;
33 import net.sf.gridarta.utils.Size2D;
34 import org.junit.Test;
35 
40 public class DefaultMapManagerTest {
41 
47  @Test
48  public void testRevertResizedMap() throws DuplicateArchetypeException, IOException {
49  final File file = File.createTempFile("gridarta", null);
50  try {
51  final TestMapControlCreator testMapControlCreator = new TestMapControlCreator();
52  final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator();
53  final Size2D originalSize = new Size2D(2, 1);
54  final Size2D newSize = new Size2D(1, 2);
55  final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(testMapControlCreator.getPathManager().getMapFile(file), "test", originalSize);
57  final MapManager<TestGameObject, TestMapArchObject, TestArchetype> mapManager = testMapControlCreator.getMapManager();
58 
59  mapModel.beginTransaction("test");
60  try {
61  mapModelHelper.insertFloor(mapModel, new Point(1, 0));
62  } finally {
63  mapModel.endTransaction();
64  }
65  mapControl.save();
66  TestMapModelHelper.checkMapContents(mapModel, "|floor");
67 
68  mapModel.beginTransaction("test");
69  try {
70  mapModel.getMapArchObject().setMapSize(newSize);
71  } finally {
72  mapModel.endTransaction();
73  }
74  mapModel.beginTransaction("test");
75  try {
76  mapModelHelper.insertFloor(mapModel, new Point(0, 1));
77  } finally {
78  mapModel.endTransaction();
79  }
80  TestMapModelHelper.checkMapContents(mapModel, "", "floor");
81 
82  mapModel.beginTransaction("test");
83  try {
84  mapManager.revert(mapControl);
85  } finally {
86  mapModel.endTransaction();
87  }
88  TestMapModelHelper.checkMapContents(mapModel, "|floor");
89  } finally {
90  //noinspection ResultOfMethodCallIgnored
91  file.delete();
92  }
93  }
94 
95 }
net.sf.gridarta.model.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.getMapManager
MapManager< TestGameObject, TestMapArchObject, TestArchetype > getMapManager()
Returns the MapManager.
Definition: TestMapControlCreator.java:224
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.model.mapmodel.MapModel.getMapArchObject
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
net.sf.gridarta.model.mapmanager.MapManager
A MapManager manages all opened maps.
Definition: MapManager.java:37
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapmodel.TestMapModelHelper
Helper class for creating MapModel instances for regression tests.
Definition: TestMapModelHelper.java:45
net.sf.gridarta.model.mapmodel.MapModel.endTransaction
void endTransaction()
End a transaction.
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf
net.sf.gridarta.model.mapmodel.MapModel.beginTransaction
void beginTransaction(@NotNull String name)
Starts a new transaction.
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.mapmanager.DefaultMapManagerTest.testRevertResizedMap
void testRevertResizedMap()
A map that has been resized must still be revertable.
Definition: DefaultMapManagerTest.java:48
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.mapcontrol
Definition: DefaultMapControl.java:20
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.getPathManager
PathManager getPathManager()
Returns the PathManager.
Definition: TestMapControlCreator.java:188
net.sf.gridarta.model.mapcontrol.TestMapControlCreator
Helper class for creating MapControl instances for regression tests.
Definition: TestMapControlCreator.java:68
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.mapmanager.DefaultMapManagerTest
Regression tests for DefaultMapManager.
Definition: DefaultMapManagerTest.java:40
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.newMapModelCreator
TestMapModelHelper newMapModelCreator()
Creates a new TestMapModelHelper instance.
Definition: TestMapControlCreator.java:165
net.sf.gridarta.model.io.PathManager.getMapFile
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Definition: PathManager.java:72
net.sf.gridarta.model.mapmodel.TestMapModelHelper.insertFloor
TestGameObject insertFloor(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a floorArchetype game object into a map model.
Definition: TestMapModelHelper.java:135
net.sf.gridarta.model.mapcontrol.MapControl.save
void save()
Saves the map to a file.
net.sf.gridarta.model
net.sf.gridarta.model.mapmodel.TestMapModelHelper.checkMapContents
static void checkMapContents(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final String... lines)
Checks for expected MapModel's contents.
Definition: TestMapModelHelper.java:230
net.sf.gridarta.model.mapmanager.MapManager.revert
void revert(@NotNull MapControl< G, A, R > mapControl)
Reverts one map.
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.newMapControl
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.
Definition: TestMapControlCreator.java:176
net.sf.gridarta.model.archetype.DuplicateArchetypeException
An Exception indicating that an Archetype name is not unique.
Definition: DuplicateArchetypeException.java:29
net.sf.gridarta.model.mapcontrol.MapControl
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
net.sf.gridarta.model.mapcontrol.MapControl.getMapModel
MapModel< G, A, R > getMapModel()
Returns the map model.
net.sf.gridarta.model.maparchobject.TestMapArchObject
A MapArchObject implementation for testing purposes.
Definition: TestMapArchObject.java:28
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20