From: <jde...@us...> - 2007-02-06 10:44:50
|
Revision: 2122 http://svn.sourceforge.net/pcgen/?rev=2122&view=rev Author: jdempsey Date: 2007-02-06 02:44:49 -0800 (Tue, 06 Feb 2007) Log Message: ----------- Fix bug#1649398 - !PRE not recognised as a prereq in SA - Moved all prereq identification into a single place in PreParserFactory Added Paths: ----------- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreRuleTest.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreRuleParserTest.java Added: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreRuleTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreRuleTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreRuleTest.java 2007-02-06 10:44:49 UTC (rev 2122) @@ -0,0 +1,142 @@ +/* + * PreRuleTest.java + * Copyright 2007 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on February 6, 2007 + * + * Current Ver: $Revision: 1777 $ + * Last Editor: $Author: jdempsey $ + * Last Edited: $Date: 2006-12-17 15:36:01 +1100 (Sun, 17 Dec 2006) $ + * + */ +package pcgen.core.prereq; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import pcgen.AbstractCharacterTestCase; +import pcgen.core.GameMode; +import pcgen.core.Globals; +import pcgen.core.RuleCheck; +import pcgen.core.SettingsHandler; +import plugin.pretokens.parser.PreRuleParser; + +/** + * <code>PreRuleTest</code> checks the fucntion of the rule + * prereq tester. + * + * Last Editor: $Author: $ + * Last Edited: $Date: $ + * + * @author James Dempsey <jde...@us...> + * @version $Revision: $ + */ +public class PreRuleTest extends AbstractCharacterTestCase +{ + /** + * Runs the test. + * @param args + */ + public static void main(final String[] args) + { + TestRunner.run(PreRuleTest.class); + } + + /* (non-Javadoc) + * @see pcgen.PCGenTestCase#setUp() + */ + @Override + protected void setUp() throws Exception + { + // TODO Auto-generated method stub + super.setUp(); + RuleCheck preRule = new RuleCheck(); + preRule.setName("PRERULE"); + preRule.setDefault("N"); + GameMode gameMode = SettingsHandler.getGame(); + gameMode.addRule(preRule); + + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception + { + // TODO Auto-generated method stub + super.tearDown(); + } + + /** + * Returns a TestSuite consisting of all the tests in this class. + * + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreRuleTest.class); + } + + /** + * Test to ensure that we return false when races don't match. + * + * @throws Exception + */ + public void testRuleDisabled() throws Exception + { + assertFalse("Our rule should start as false", Globals + .checkRule("PRERULE")); + + PreRuleParser parser = new PreRuleParser(); + Prerequisite prereq = parser.parse("RULE", "PRERULE", false, false); + + boolean passes = PrereqHandler.passes(prereq, getCharacter(), null); + assertFalse("PreRule should fail when rule is disabled.", passes); + + prereq = parser.parse("RULE", "PRERULE", true, false); + passes = PrereqHandler.passes(prereq, getCharacter(), null); + assertTrue("!PreRule should pass when rule is disabled.", passes); + } + + /** + * Test to ensure that we return false when races don't match. + * + * @throws Exception + */ + public void testRuleEnabled() throws Exception + { + RuleCheck preRule = new RuleCheck(); + preRule.setName("PRERULE"); + preRule.setDefault("Y"); + GameMode gameMode = SettingsHandler.getGame(); + gameMode.addRule(preRule); + + assertTrue("Our rule should now be true", Globals + .checkRule("PRERULE")); + + PreRuleParser parser = new PreRuleParser(); + Prerequisite prereq = parser.parse("RULE", "PRERULE", false, false); + + boolean passes = PrereqHandler.passes(prereq, getCharacter(), null); + assertTrue("PreRule should pass when rule is enabled.", passes); + + prereq = parser.parse("RULE", "PRERULE", true, false); + passes = PrereqHandler.passes(prereq, getCharacter(), null); + assertFalse("!PreRule should fail when rule is enabled.", passes); + } +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreRuleTest.java ___________________________________________________________________ Name: keywords + Author Revision Date Id Name: svn:eol-style + native Added: Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreRuleParserTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreRuleParserTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreRuleParserTest.java 2007-02-06 10:44:49 UTC (rev 2122) @@ -0,0 +1,90 @@ +/* + * PreRuleParserTest.java + * Copyright 2007 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on February 6, 2007 + * + * Current Ver: $Revision: 1777 $ + * Last Editor: $Author: jdempsey $ + * Last Edited: $Date: 2006-12-17 15:36:01 +1100 (Sun, 17 Dec 2006) $ + * + */ +package pcgen.persistence.lst.prereq; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import pcgen.core.prereq.Prerequisite; +import plugin.pretokens.parser.PreRuleParser; + +/** + * <code>PreRuleParserTest</code> is ... + * + * Last Editor: $Author: $ + * Last Edited: $Date: $ + * + * @author James Dempsey <jde...@us...> + * @version $Revision: $ + */ +public class PreRuleParserTest extends TestCase +{ + + /** + * Main + * @param args + */ + public static void main(String args[]) + { + TestRunner.run(PreRuleParserTest.class); + } + + /** + * @return Test + */ + public static Test suite() + { + return new TestSuite(PreRuleParserTest.class); + } + + /** + * @throws Exception + */ + public void testPositive() throws Exception + { + PreRuleParser parser = new PreRuleParser(); + Prerequisite prereq = parser.parse("RULE", "DISPLAYTYPETRAITS", false, false); + + assertEquals( + "<prereq kind=\"rule\" key=\"DISPLAYTYPETRAITS\" operator=\"gteq\" operand=\"1\" >\n</prereq>\n", + prereq.toString()); + } + + /** + * @throws Exception + */ + public void testNegative() throws Exception + { + PreRuleParser parser = new PreRuleParser(); + Prerequisite prereq = parser.parse("RULE", "DISPLAYTYPETRAITS", true, false); + + assertEquals( + "<prereq kind=\"rule\" key=\"DISPLAYTYPETRAITS\" operator=\"lt\" operand=\"1\" >\n</prereq>\n", + prereq.toString()); + } + +} Property changes on: Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreRuleParserTest.java ___________________________________________________________________ Name: keywords + Author Revision Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |