 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.actions;
22 import java.awt.Point;
40 import org.jetbrains.annotations.NotNull;
41 import org.jetbrains.annotations.Nullable;
42 import org.junit.Assert;
43 import org.junit.Before;
44 import org.junit.Test;
107 final Point point1 =
new Point(3, 4);
108 Assert.assertTrue(actions.
doExitCopy(
false, mapControl, point1));
112 Assert.assertTrue(actions.
doExitCopy(
true, mapControl, point1));
118 Assert.assertFalse(actions.
doExitCopy(
false, mapControl, point1));
136 final Point point1 =
new Point(3, 4);
137 final Point point2 =
new Point(1, 2);
143 Assert.assertFalse(actions.
doExitPaste(
false, mapControl, point1));
154 Assert.assertFalse(actions.
doExitPaste(
false, mapControl, point1));
165 Assert.assertTrue(actions.
doExitPaste(
false, mapControl, point1));
166 checkExit(mapModel, point1, 1,
"",
new Point(0, 0));
169 Assert.assertTrue(actions.
doExitPaste(
true, mapControl, point1));
170 checkExit(mapModel, point1, 1,
"b", point2);
187 final Point point1 =
new Point(3, 4);
188 final Point point2 =
new Point(1, 2);
197 Assert.assertFalse(actions.
doExitCopy(
true, mapControl1, point1));
200 Assert.assertTrue(actions.
doExitPaste(
true, mapControl1, point1));
221 final Point point1 =
new Point(3, 4);
222 final Point point2 =
new Point(1, 2);
228 Assert.assertFalse(actions.
doExitConnect(
false, mapControl1, point1));
239 Assert.assertFalse(actions.
doExitConnect(
false, mapControl1, point1));
250 Assert.assertFalse(actions.
doExitConnect(
false, mapControl1, point1));
261 Assert.assertTrue(actions.
doExitConnect(
false, mapControl1, point1));
262 checkExit(mapModel1, point1, 1,
"",
new Point(0, 0));
263 checkExit(mapModel2, point2, 0,
"",
new Point(0, 0));
266 Assert.assertTrue(actions.
doExitConnect(
true, mapControl1, point1));
267 checkExit(mapModel1, point1, 1,
"b", point2);
268 checkExit(mapModel2, point2, 0,
"a", point1);
289 final Point point1 =
new Point(3, 4);
290 final Point point2 =
new Point(1, 2);
299 Assert.assertFalse(actions.
doExitConnect(
true, mapControl1, point1));
300 checkExit(mapModel1, point1, 0,
null,
null);
301 checkExit(mapModel2, point2, 0,
null,
null);
306 Assert.assertTrue(actions.
doExitConnect(
true, mapControl1, point1));
307 checkExit(mapModel1, point1, 0,
"b", point2);
308 checkExit(mapModel2, point2, 0,
"a", point1);
311 Assert.assertTrue(actions.
doExitConnect(
true, mapControl1, point1));
312 checkExit(mapModel1, point1, 0,
"b", point2);
313 checkExit(mapModel1, point1, 1,
null,
null);
314 checkExit(mapModel2, point2, 0,
"a", point1);
315 checkExit(mapModel2, point2, 1,
null,
null);
327 testPath(
"/HallOfSelection",
"/world/world_104_115",
"/world/world_104_115");
328 testPath(
"/world/world_104_115",
"/HallOfSelection",
"/HallOfSelection");
331 testPath(
"/a/b/c/d",
"/a/d/e",
"../../d/e");
332 testPath(
"/a/b/c/d",
"/a/b/d",
"../d");
334 testPath(
"/a/b/c",
"/a/b/c/d",
"c/d");
337 testPath(
"/a/b/c",
"/b/c/d",
"/b/c/d");
349 private void testPath(@NotNull
final String mapPathFrom, @NotNull
final String mapPathTo, @NotNull
final String expectedExitPath) {
363 final Point pointFrom =
new Point(3, 4);
364 final Point pointTo =
new Point(1, 2);
377 Assert.assertTrue(actions.
doExitPaste(
true, mapControl, pointFrom));
378 checkExit(mapModel, pointFrom, 0, expectedExitPath, pointTo);
398 assert tmpTestMapControlCreator !=
null;
415 if (thisIndex == index) {
420 if (exitPath ==
null || exitPoint ==
null) {
421 Assert.fail(
"exit found but none expected");
422 throw new AssertionError();
425 Assert.assertEquals(exitPath, gameObject.getAttributeString(
BaseObject.
SLAYING));
426 Assert.assertEquals(exitPoint.x, gameObject.getAttributeInt(
BaseObject.
HP));
427 Assert.assertEquals(exitPoint.y, gameObject.getAttributeInt(
BaseObject.
SP));
434 if (exitPath !=
null || exitPoint !=
null) {
435 Assert.fail(
"no exit found");
An Archetype implementation for testing purposes.
MapManager< TestGameObject, TestMapArchObject, TestArchetype > getMapManager()
Returns the MapManager.
A MapModel reflects the data of a map.
void setExitArchetypeName(@NotNull String exitArchetypeName)
Sets the archetype name for creating exit game objects.
Regression tests for ExitConnectorActions.
TestGameObject insertExit(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts an exitArchetype game object into a map model.
Stores information about a remembered exit location.
Base package of all Gridarta classes.
Helper class for creating MapModel instances for regression tests.
String SP
The attribute name of the "sp" attribute.
void endTransaction()
End a transaction.
InsertionModeSet< TestGameObject, TestMapArchObject, TestArchetype > getInsertionModeSet()
Returns the InsertionModeSet.
A GameObject implementation for testing purposes.
ExitConnectorActions< TestGameObject, TestMapArchObject, TestArchetype > createActions(@NotNull final ExitConnectorModel model)
Creates a new ExitConnectorActions instance.
void beginTransaction(@NotNull String name)
Starts a new transaction.
void setExitLocation(@Nullable ExitLocation exitLocation)
Sets the remembered exit location.
void testExitConnect1()
Checks that MapControl, Point) does work.
void testExitPaste1()
Checks that MapControl, Point) does work.
void testExitConnectAuto1()
Checks that MapControl, Point) does work when auto-creating exit objects.
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
Utility class for MapPath related functions.
static final MapFile MAP_FILE1
The first map file.
static final MapFile BASE
The base MapFile for the test.
A FileControl implementation for testing purposes.
ExitConnectorModel implementation for regression tests.
boolean doExitCopy(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point location)
Executes the "exit copy" action.
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
TestMapModelHelper mapModelHelper
The TestMapModelHelper instance.
Helper class for creating MapControl instances for regression tests.
GameObjects are the objects based on Archetypes found on maps.
void testExitPaste2()
Checks that MapControl, Point) does not crash when connecting to an unsaved map.
TestMapModelHelper newMapModelCreator()
Creates a new TestMapModelHelper instance.
TestMapControlCreator testMapControlCreator
The TestMapControlCreator for creating maps.
void setUp()
Initializes the test case.
TestGameObject insertFloor(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a floorArchetype game object into a map model.
void setAutoCreateExit(boolean autoCreateExit)
Sets whether exit game objects should be auto-created when needed.
String SLAYING
The name of the "slaying" attribute.
The location of a map file with a map directory.
Utility class implementing actions that operate on ExitConnectorModels.
static void checkExit(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point, final int index, @Nullable final String exitPath, @Nullable final Point exitPoint)
Checks that a map model contains an exit game object.
static final String MAP_NAME2
The second map name.
void testPath(@NotNull final String mapPathFrom, @NotNull final String mapPathTo, @NotNull final String expectedExitPath)
Checks that an exit path is correctly generated.
ProjectSettings getProjectSettings()
Returns the ProjectSettings.
static final int EXIT_TYPE
The archetype type used for "exit" game objects.
void setMapFile(@Nullable MapFile mapFile)
Sets the map file.
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.
An Exception indicating that an Archetype name is not unique.
ExitLocation getExitLocation()
Returns the remembered exit location.
Currently nothing more than a marker interface for unification.
MapModel< G, A, R > getMapModel()
Returns the map model.
A MapArchObject implementation for testing purposes.
ExitMatcher< TestGameObject, TestMapArchObject, TestArchetype > getExitMatcher()
Returns the ExitMatcher.
String HP
The attribute name of the "hp" attribute.
static final MapFile MAP_FILE2
The second map file.
File getMapsDirectory()
Returns the default maps directory.
void testExitCopy1()
Checks that MapControl, Point) does work.
Stores information needed by the exit connector.
The class Size2D represents a 2d rectangular area.
static final String MAP_NAME1
The first map name.
boolean doExitConnect(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point targetLocation)
Executes the "exit connect" action.
void testPath1()
Checks that exit paths are correctly generated.
boolean doExitPaste(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point targetLocation)
Executes the "exit paste" action.