Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test for entry and exit flags to put the matter to rest.
Also cleaned up a few other things regarding tests.
- Loading branch information
Showing
4 changed files
with
192 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/test/java/com/sk89q/worldguard/protection/PRTreeRegionEntryExitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// $Id$ | ||
/* | ||
* WorldGuard | ||
* Copyright (C) 2010 sk89q <http://www.sk89q.com> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.worldguard.protection; | ||
|
||
import com.sk89q.worldguard.protection.managers.PRTreeRegionManager; | ||
import com.sk89q.worldguard.protection.managers.RegionManager; | ||
|
||
public class PRTreeRegionEntryExitTest extends RegionEntryExitTest { | ||
@Override | ||
protected RegionManager createRegionManager() throws Exception { | ||
return new PRTreeRegionManager(null); | ||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
src/test/java/com/sk89q/worldguard/protection/RegionEntryExitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// $Id$ | ||
/* | ||
* WorldGuard | ||
* Copyright (C) 2013 sk89q <http://www.sk89q.com> and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.worldguard.protection; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.sk89q.worldedit.BlockVector; | ||
import com.sk89q.worldedit.Vector; | ||
import com.sk89q.worldguard.TestPlayer; | ||
import com.sk89q.worldguard.domains.DefaultDomain; | ||
import com.sk89q.worldguard.protection.flags.DefaultFlag; | ||
import com.sk89q.worldguard.protection.flags.RegionGroup; | ||
import com.sk89q.worldguard.protection.flags.StateFlag; | ||
import com.sk89q.worldguard.protection.managers.RegionManager; | ||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion; | ||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; | ||
import com.sk89q.worldguard.protection.regions.ProtectedRegion; | ||
|
||
public abstract class RegionEntryExitTest { | ||
static String ENTRY_ID = "entry_rg"; | ||
static String EXIT_ID = "exit_rg"; | ||
static String BUILDER_GROUP = "builder"; | ||
static String VIP_GROUP = "vip"; | ||
|
||
Vector inEntry = new Vector(5, 64, 5); | ||
Vector inExit = new Vector(-5, 65, -5); | ||
|
||
RegionManager manager; | ||
ProtectedRegion globalRegion; | ||
ProtectedRegion entryRegion; | ||
ProtectedRegion exitRegion; | ||
TestPlayer vip_player; | ||
TestPlayer builder_player; | ||
|
||
protected abstract RegionManager createRegionManager() throws Exception; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
setUpGlobalRegion(); | ||
|
||
manager = createRegionManager(); | ||
|
||
setUpPlayers(); | ||
setUpEntryRegion(); | ||
setUpExitRegion(); | ||
} | ||
|
||
void setUpPlayers() { | ||
vip_player = new TestPlayer("dudu"); | ||
vip_player.addGroup(VIP_GROUP); | ||
|
||
builder_player = new TestPlayer("esskay"); | ||
builder_player.addGroup(BUILDER_GROUP); | ||
|
||
// @Test | ||
// assertFalse(builderPlayer.wuvs(vip_player)); // causes test to fail | ||
} | ||
|
||
void setUpGlobalRegion() { | ||
globalRegion = new GlobalProtectedRegion("__global__"); | ||
} | ||
|
||
void setUpEntryRegion() { | ||
DefaultDomain domain = new DefaultDomain(); | ||
domain.addGroup(VIP_GROUP); | ||
|
||
ProtectedRegion region = new ProtectedCuboidRegion(ENTRY_ID, new BlockVector(1, 0, 1), new BlockVector(10, 255, 10)); | ||
|
||
region.setMembers(domain); | ||
manager.addRegion(region); | ||
|
||
entryRegion = region; | ||
// this is the way it's supposed to work | ||
// whatever the group flag is set to is the group that the flag APPLIES to | ||
// in this case, non members (esskay) should be DENIED entry | ||
entryRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY); | ||
entryRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); | ||
} | ||
|
||
void setUpExitRegion() throws Exception { | ||
DefaultDomain domain = new DefaultDomain(); | ||
domain.addGroup(BUILDER_GROUP); | ||
|
||
ProtectedRegion region = new ProtectedCuboidRegion(EXIT_ID, new BlockVector(-1, 0, -1), new BlockVector(-10, 255, -10)); | ||
|
||
region.setOwners(domain); | ||
manager.addRegion(region); | ||
|
||
entryRegion = region; | ||
// same as above | ||
entryRegion.setFlag(DefaultFlag.EXIT, StateFlag.State.DENY); | ||
entryRegion.setFlag(DefaultFlag.EXIT.getRegionGroupFlag(), RegionGroup.NON_OWNERS); | ||
} | ||
|
||
@Test | ||
public void testEntry() throws Exception { | ||
ApplicableRegionSet appl; | ||
|
||
appl = manager.getApplicableRegions(inEntry); | ||
// ProtectedRegion rg = appl.iterator().next(); | ||
// System.out.println("rg " + rg.getId()); | ||
// System.out.println("mem " + rg.getMembers().toGroupsString()); | ||
// System.out.println("flag " + appl.getFlag(DefaultFlag.ENTRY)); | ||
// System.out.println("grp " + appl.getFlag(DefaultFlag.ENTRY.getRegionGroupFlag())); | ||
// System.out.println("==="); | ||
assertTrue("Allowed Entry", appl.allows(DefaultFlag.ENTRY, vip_player)); | ||
assertFalse("Forbidden Entry", appl.allows(DefaultFlag.ENTRY, builder_player)); | ||
} | ||
|
||
@Test | ||
public void testExit() throws Exception { | ||
ApplicableRegionSet appl; | ||
|
||
appl = manager.getApplicableRegions(inExit); | ||
// ProtectedRegion rg = appl.iterator().next(); | ||
// System.out.println("rg " + rg.getId()); | ||
// System.out.println("own " + rg.getOwners().toGroupsString()); | ||
// System.out.println("flag " + appl.getFlag(DefaultFlag.EXIT)); | ||
// System.out.println("grp " + appl.getFlag(DefaultFlag.EXIT.getRegionGroupFlag())); | ||
// System.out.println("==="); | ||
assertTrue("Allowed Exit", appl.allows(DefaultFlag.EXIT, builder_player)); | ||
assertFalse("Forbidden Exit", appl.allows(DefaultFlag.EXIT, vip_player)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters