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-2015 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 }
A MapModel reflects the data of a map.
Definition: MapModel.java:75
Graphical User Interface of Gridarta.
static final String MAP_NAME1
The first map name.
MapGrid getMapGrid()
Returns the MapGrid of this view.
Helper class for creating MapModel instances for regression tests.
Helper class for creating MapControl instances for regression tests.
static final MapFile MAP_FILE1
The first map file.
void cut(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executing the Cut command.
A MapArchObject implementation for testing purposes.
MapModel< G, A, R > getMapModel()
Returns the map model.
static void checkContents(@NotNull final Iterable< TestGameObject > mapSquare, @NotNull final BaseObject<?, ?, ?, ?>... gameObjects)
Checks that a MapSquare contains the given game objects.
Helper class for creating MapControl instances for regression tests.
TestGameObject insertFloor(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a floorArchetype game object into a map model.
Base package of all Gridarta classes.
An Exception indicating that an Archetype name is not unique.
GameObjects are the objects based on Archetypes found on maps.
static CopyBuffer< TestGameObject, TestMapArchObject, TestArchetype > newCopyBuffer(@NotNull final TestMapControlCreator mapControlCreator)
Returns a new CopyBuffer instance.
static void checkMapContents(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final String... lines)
Checks for expected MapModel&#39;s contents.
TestMapModelHelper newMapModelCreator()
Creates a new TestMapModelHelper instance.
Base classes for rendering maps.
TestGameObject insertMob21(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a mob21Archetype game object into a map model.
static MapView< TestGameObject, TestMapArchObject, TestArchetype > newMapView(@NotNull final MapControl< TestGameObject, TestMapArchObject, TestArchetype > mapControl)
Creates a new MapView instance.
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
ADD
All squares that are preselected get selected.
An Archetype implementation for testing purposes.
A GameObject implementation for testing purposes.
Modes that describe how squares get selected.
Regression tests for CopyBuffer.
void beginTransaction(@NotNull String name)
Starts a new transaction.
Common base implementation of CopyBuffer.
Definition: CopyBuffer.java:52
void paste(@NotNull final MapView< G, A, R > mapView, @NotNull final Point startLocation)
Executing the Paste command.
The location of a map file with a map directory.
Definition: MapFile.java:31
void testCutPaste1()
Checks that CopyBuffer#cut(MapView, Rectangle) followed by CopyBuffer#paste(MapView, Point) does work.
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.