Gridarta Editor
CopyBufferTest.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.gui.copybuffer;
21 
22 import java.awt.Point;
23 import java.awt.Rectangle;
24 import java.io.File;
37 import net.sf.gridarta.utils.Size2D;
38 import org.junit.Test;
39 
44 public class CopyBufferTest {
45 
49  private static final MapFile MAP_FILE1 = new MapFile(new File("a"));
50 
54  private static final String MAP_NAME1 = "name1";
55 
61  @Test
63  final TestMapControlCreator testMapControlCreator = new TestMapControlCreator();
64  final TestMapModelHelper mapModelHelper = testMapControlCreator.newMapModelCreator();
65  final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(3, 3));
66 
67  final Point point = new Point(1, 1);
69  mapModel.beginTransaction("TEST");
70  final TestGameObject ob1 = mapModelHelper.insertFloor(mapModel, point);
71  final TestGameObject ob2 = mapModelHelper.insertMob21(ob1);
72 
73  TestMapModelHelper.checkMapContents(mapModel, "||", "|floor|", "||");
75 
76  // select + cut
79  mapView.getMapGrid().select(new Point(1, 1), SelectionMode.ADD);
80  copyBuffer.cut(mapView, new Rectangle(1, 1, 1, 1));
81 
82  TestMapModelHelper.checkMapContents(mapModel, "||", "||", "||");
83 
84  // paste
85  copyBuffer.paste(mapView, new Point(1, 1));
86 
87  TestMapModelHelper.checkMapContents(mapModel, "||", "|floor|", "||");
88  }
89 
90 }
net.sf.gridarta.model.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.gui.map.mapview.MapView.getMapGrid
MapGrid getMapGrid()
Returns the MapGrid of this view.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.copybuffer.CopyBufferTest.MAP_FILE1
static final MapFile MAP_FILE1
The first map file.
Definition: CopyBufferTest.java:49
net.sf.gridarta.model.mapmodel.TestMapModelHelper
Helper class for creating MapModel instances for regression tests.
Definition: TestMapModelHelper.java:45
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.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.gui.copybuffer.CopyBufferTest.MAP_NAME1
static final String MAP_NAME1
The first map name.
Definition: CopyBufferTest.java:54
net.sf.gridarta.model.mapcontrol
Definition: DefaultMapControl.java:20
net.sf.gridarta.gui.map.test.TestMapControlCreatorUtils.newCopyBuffer
static CopyBuffer< TestGameObject, TestMapArchObject, TestArchetype > newCopyBuffer(@NotNull final TestMapControlCreator mapControlCreator)
Returns a new CopyBuffer instance.
Definition: TestMapControlCreatorUtils.java:76
net.sf.gridarta.gui.map.test.TestMapControlCreatorUtils.newMapView
static MapView< TestGameObject, TestMapArchObject, TestArchetype > newMapView(@NotNull final MapControl< TestGameObject, TestMapArchObject, TestArchetype > mapControl)
Creates a new MapView instance.
Definition: TestMapControlCreatorUtils.java:64
net.sf.gridarta.model.mapmodel.TestMapModelHelper.insertMob21
TestGameObject insertMob21(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a mob21Archetype game object into a map model.
Definition: TestMapModelHelper.java:157
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
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.gui.copybuffer.CopyBufferTest
Regression tests for CopyBuffer.
Definition: CopyBufferTest.java:44
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.newMapModelCreator
TestMapModelHelper newMapModelCreator()
Creates a new TestMapModelHelper instance.
Definition: TestMapControlCreator.java:165
net.sf.gridarta.gui.map.mapview
Definition: AbstractMapView.java:20
net.sf.gridarta.gui.map.mapview.MapView
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
net.sf.gridarta.model.mapgrid.SelectionMode
Modes that describe how squares get selected.
Definition: SelectionMode.java:26
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.gui.copybuffer.CopyBuffer
Common base implementation of CopyBuffer.
Definition: CopyBuffer.java:52
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.gui.copybuffer.CopyBuffer.cut
void cut(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executes the Cut command.
Definition: CopyBuffer.java:127
net.sf.gridarta.gui.map.test.TestMapControlCreatorUtils
Helper class for creating MapControl instances for regression tests.
Definition: TestMapControlCreatorUtils.java:50
net.sf.gridarta.model.mapgrid.SelectionMode.ADD
ADD
All squares that are preselected get selected.
Definition: SelectionMode.java:31
net.sf.gridarta.gui.copybuffer.CopyBuffer.paste
void paste(@NotNull final MapView< G, A, R > mapView, @NotNull final Point startLocation)
Executes the Paste command.
Definition: CopyBuffer.java:180
net.sf.gridarta.model.mapgrid
Definition: MapGrid.java:20
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.gui.copybuffer.CopyBufferTest.testCutPaste1
void testCutPaste1()
Checks that CopyBuffer#cut(MapView, Rectangle) followed by {} does work.
Definition: CopyBufferTest.java:62
net.sf.gridarta.gui.map
Base classes for rendering maps.
Definition: AbstractPerMapDialogManager.java:20
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
net.sf.gridarta.model.mapmodel.TestMapModelHelper.checkContents
static void checkContents(@NotNull final Iterable< TestGameObject > mapSquare, @NotNull final BaseObject<?, ?, ?, ?>... gameObjects)
Checks that a MapSquare contains the given game objects.
Definition: TestMapModelHelper.java:277
net.sf.gridarta.gui.map.test
Definition: TestMapControlCreatorUtils.java:20