001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2010 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.model.floodfill; 021 022import java.awt.Point; 023import java.util.ArrayList; 024import java.util.Collection; 025import java.util.List; 026import net.sf.gridarta.model.archetype.DuplicateArchetypeException; 027import net.sf.gridarta.model.archetype.TestArchetype; 028import net.sf.gridarta.model.baseobject.BaseObject; 029import net.sf.gridarta.model.gameobject.TestGameObject; 030import net.sf.gridarta.model.maparchobject.TestMapArchObject; 031import net.sf.gridarta.model.mapmodel.CannotInsertGameObjectException; 032import net.sf.gridarta.model.mapmodel.MapModel; 033import net.sf.gridarta.model.mapmodel.MapSquare; 034import net.sf.gridarta.model.mapmodel.TestMapModelCreator; 035import net.sf.gridarta.model.mapmodel.TestMapModelHelper; 036import org.junit.Assert; 037import org.junit.Test; 038 039/** 040 * Regression tests for {@link FillUtils}. 041 * @author Andreas Kirschbaum 042 */ 043public class FillUtilsTest { 044 045 /** 046 * Checks that {@link FillUtils#fill(MapModel, Collection, 047 * net.sf.gridarta.model.mapmodel.InsertionMode, List, int, boolean)} works 048 * correctly when skipping adjacent squares. 049 * @throws DuplicateArchetypeException if the test fails 050 * @throws CannotInsertGameObjectException if the test fails 051 */ 052 @Test 053 public void testFillAdjacent() throws CannotInsertGameObjectException, DuplicateArchetypeException { 054 final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); 055 final TestMapModelHelper mapModelHelper = mapModelCreator.newTestMapModelHelper(); 056 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(4, 5); 057 058 final TestArchetype head = mapModelCreator.getArchetype("2x2a"); 059 head.setAttributeInt(BaseObject.TYPE, 1); 060 final TestArchetype tail1 = mapModelCreator.getArchetype("2x2b"); 061 tail1.setMultiX(1); 062 head.addTailPart(tail1); 063 final TestArchetype tail2 = mapModelCreator.getArchetype("2x2c"); 064 tail2.setMultiY(1); 065 head.addTailPart(tail2); 066 final TestArchetype tail3 = mapModelCreator.getArchetype("2x2d"); 067 tail3.setMultiX(1); 068 tail3.setMultiY(1); 069 head.addTailPart(tail3); 070 071 mapModel.beginTransaction("TEST"); 072 mapModelHelper.insertArchetype(mapModel, new Point(0, 2), head, false); 073 074 final Collection<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> selection = new ArrayList<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>>(); 075 selection.add(mapModel.getMapSquare(new Point(2, 0))); 076 final List<TestGameObject> gameObjects = new ArrayList<TestGameObject>(); 077 gameObjects.add(mapModelCreator.getGameObjectFactory().createGameObject(head)); 078 079 FillUtils.fill(mapModel, selection, mapModelCreator.getInsertionModeSet().getTopmostInsertionMode(), gameObjects, 100, true); 080 Assert.assertTrue(mapModel.getMapSquare(new Point(2, 0)).isEmpty()); 081 082 FillUtils.fill(mapModel, selection, mapModelCreator.getInsertionModeSet().getTopmostInsertionMode(), gameObjects, 100, false); 083 Assert.assertFalse(mapModel.getMapSquare(new Point(2, 0)).isEmpty()); 084 } 085 086}