[Picross-commit] SF.net SVN: picross:[90] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2011-06-16 11:11:19
|
Revision: 90 http://picross.svn.sourceforge.net/picross/?rev=90&view=rev Author: yvan_norsa Date: 2011-06-16 11:11:11 +0000 (Thu, 16 Jun 2011) Log Message: ----------- reorganisation Modified Paths: -------------- trunk/bugsFilter.xml trunk/build.xml Added Paths: ----------- trunk/lib/easymock.jar trunk/test/ trunk/test/picross/ trunk/test/picross/AbstractPicrossGridTest.java trunk/test/picross/PicrossTest.java trunk/test/picross/game/ trunk/test/picross/game/random/ trunk/test/picross/game/random/RandomPicrossModelTest.java trunk/test/picross/game/simple/ trunk/test/picross/game/simple/XBMModelTest.java trunk/test/picross/grid/ trunk/test/picross/grid/BoxTest.java trunk/test/picross/grid/CompletedHintsTest.java trunk/test/picross/grid/FillCommandTest.java trunk/test/picross/grid/GridModelTest.java trunk/test/picross/grid/IGridMediatorStub.java trunk/test/picross/grid/PaintCommandTest.java trunk/test/picross/package.html Removed Paths: ------------- trunk/src/picross/game/random/tests/ trunk/src/picross/game/simple/tests/ trunk/src/picross/grid/tests/ trunk/src/picross/tests/ Modified: trunk/bugsFilter.xml =================================================================== --- trunk/bugsFilter.xml 2011-06-07 12:58:50 UTC (rev 89) +++ trunk/bugsFilter.xml 2011-06-16 11:11:11 UTC (rev 90) @@ -1,8 +1,4 @@ <FindBugsFilter> - <Match> - <Package name="~.*\.tests" /> - </Match> - <Match classregex=".*"> <Bug pattern="DM_CONVERT_CASE,LSC_LITERAL_STRING_COMPARISON,CLI_CONSTANT_LIST_INDEX,S508C_SET_COMP_COLOR,S508C_NO_SETLABELFOR,DRE_DECLARED_RUNTIME_EXCEPTION" /> </Match> Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2011-06-07 12:58:50 UTC (rev 89) +++ trunk/build.xml 2011-06-16 11:11:11 UTC (rev 90) @@ -13,6 +13,8 @@ value="lib" /> <property name="src.dir" value="src" /> + <property name="test.dir" + value="test" /> <property name="jar.name" value="${dist.dir}/${ant.project.name}.jar" /> @@ -21,6 +23,8 @@ value="${lib.dir}/bundleHelper.jar" /> <property name="debug.jar" value="${lib.dir}/debug.jar" /> + <property name="easymock.jar" + value="${lib.dir}/easymock.jar" /> <property name="junit.jar" value="${lib.dir}/junit.jar" /> <property name="log4j.jar" @@ -63,6 +67,7 @@ <pathelement location="${build.dir}" /> <pathelement location="${bundleHelper.jar}" /> + <pathelement location="${easymock.jar}" /> <pathelement location="${junit.jar}" /> <pathelement location="${log4j.jar}" /> <pathelement location="${mmvcs.jar}" /> @@ -83,6 +88,19 @@ </javac> </target> + <target name="compile-test" + depends="compile"> + <javac srcdir="${test.dir}" + destdir="${build.dir}" + deprecation="on" + debug="on" + optimize="off"> + <compilerarg value="-Xlint:all" /> + + <classpath refid="classpath" /> + </javac> + </target> + <target name="dist" depends="compile"> <copy todir="${build.dir}/picross/properties" @@ -140,7 +158,7 @@ </target> <target name="test" - depends="dist"> + depends="dist,compile-test"> <junit haltonfailure="yes" filtertrace="off" showoutput="on" @@ -151,7 +169,7 @@ <batchtest fork="yes" filtertrace="on" haltonfailure="yes"> - <fileset dir="${src.dir}"> + <fileset dir="${test.dir}"> <include name="**/*Test.java" /> <exclude name="**/Abstract*Test.java" /> </fileset> @@ -178,14 +196,10 @@ <target name="doc" depends="compile"> - <!-- FIXME test classes which are not in a "tests" subpackage - shouldn't be included in the generated Javadoc --> <javadoc destdir="${doc.dir}" access="private" link="http://java.sun.com/j2se/1.5.0/docs/api"> <packageset dir="${src.dir}" - defaultexcludes="yes"> - <exclude name="**/tests/**" /> - </packageset> + defaultexcludes="yes" /> <classpath refid="classpath" /> </javadoc> @@ -212,8 +226,7 @@ tofile="checkstyle.xml" /> <fileset dir="${src.dir}" - includes="**/*.java" - excludes="**/tests/" /> + includes="**/*.java" /> </checkstyle> <xslt in="checkstyle.xml" Added: trunk/lib/easymock.jar =================================================================== (Binary files differ) Property changes on: trunk/lib/easymock.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Copied: trunk/test/picross/AbstractPicrossGridTest.java (from rev 88, trunk/src/picross/tests/AbstractPicrossGridTest.java) =================================================================== --- trunk/test/picross/AbstractPicrossGridTest.java (rev 0) +++ trunk/test/picross/AbstractPicrossGridTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,112 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Abstract test class for the PicrossGrid interface. + * + * @author Y. Norsa + */ +public abstract class AbstractPicrossGridTest { + /*** Field ***/ + + /** The instance to test. */ + private PicrossGrid picrossGrid = null; + + /*** Abstract method ***/ + + /** + * Returns an instance. + * + * @return instance to test + */ + protected abstract PicrossGrid getPicrossGrid() throws Throwable; + + /*** Methods ***/ + + /** Performs the instance initialisation. */ + @Before + public void setUp() throws Throwable { + this.picrossGrid = this.getPicrossGrid(); + } + + /** Tests the method getWidth(). */ + @Test + public void testGetWidth() { + int width = this.picrossGrid.getWidth(); + Assert.assertTrue("width = " + width, (width > 0)); + } + + /** Tests the method getHeight(). */ + @Test + public void testGetHeight() { + int height = this.picrossGrid.getHeight(); + Assert.assertTrue("height = " + height, (height > 0)); + } + + /** Tests the method getData(). */ + @Test + public void testGetData() { + boolean[][] data = this.picrossGrid.getData(); + Assert.assertNotNull("data = null", data); + + int width = this.picrossGrid.getWidth(); + int height = this.picrossGrid.getHeight(); + + Assert.assertEquals("data.length = " + data.length, + width, data.length); + + for (int i = 0; i < width; i++) { + Assert.assertEquals("data[" + i + "].length = " + data[i].length, + height, data[i].length); + } + + boolean atLeastOneCheckedBox = false; + + for (int i = 0; i < width; i++) { + for (int j = 0; j < height; j++) { + if (data[i][j]) { + atLeastOneCheckedBox = true; + break; + } + } + } + + Assert.assertTrue("Empty grid", atLeastOneCheckedBox); + } +} Copied: trunk/test/picross/PicrossTest.java (from rev 88, trunk/src/picross/tests/PicrossTest.java) =================================================================== --- trunk/test/picross/PicrossTest.java (rev 0) +++ trunk/test/picross/PicrossTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,150 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import javax.swing.ImageIcon; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests for the static methods of the Picross class. + * + * @author Y. Norsa + */ +public class PicrossTest { + /*** Static method ***/ + + /** + * Helper method to test a loaded icon. + * + * @param icon the icon to test + * @param width the expected icon width + * @param height the expected icon height + */ + private static void testIcon(ImageIcon icon, int width, int height) { + Assert.assertNotNull("icon = null", icon); + + int iconWidth = icon.getIconWidth(); + Assert.assertEquals("width = " + iconWidth, width, iconWidth); + + int iconHeight = icon.getIconHeight(); + Assert.assertEquals("height = " + iconHeight, height, iconHeight); + } + + /*** Methods ***/ + + /** + * Tests the method getImage(). + * + * @throws MissingImageException if a file loading fails. + */ + @Test + public void testGetImage() { + try { + Picross.getImage(null); + Assert.fail("name = null"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.getImage(""); + Assert.fail("name is empty"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.getImage("fakeFile"); + Assert.fail("Fake file"); + } catch (MissingImageException imageEx) { } + + ImageIcon icon = Picross.getImage("empty.png"); + PicrossTest.testIcon(icon, 25, 25); + } + + /** + * Tests the method getLocalizedImage(). + * + * @throws MissingImageException if a file loading fails. + */ + @Test + public void getLocalizedImage() { + try { + Picross.getLocalizedImage(null); + Assert.fail("name = null"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.getLocalizedImage(""); + Assert.fail("name is empty"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.getImage("fakeFile"); + Assert.fail("Fake file"); + } catch (MissingImageException imageEx) { } + + ImageIcon icon = Picross.getLocalizedImage("button-play.png"); + PicrossTest.testIcon(icon, 150, 50); + } + + /** + * Tests the method loadDataFile(). + * + * @throws IOException if there is a problem loading the file + */ + @Test + public void testLoadDataFile() throws IOException { + try { + Picross.loadDataFile(null); + Assert.fail("name = null"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.loadDataFile(""); + Assert.fail("name is empty"); + } catch (IllegalArgumentException argEx) { } + + try { + Picross.loadDataFile("fakeFile"); + Assert.fail("Fake file"); + } catch (FileNotFoundException fileEx) { } + + InputStream in = Picross.loadDataFile("asterix.xbm"); + Assert.assertNotNull("in = null", in); + in.close(); + } +} Copied: trunk/test/picross/game/random/RandomPicrossModelTest.java (from rev 88, trunk/src/picross/game/random/tests/RandomPicrossModelTest.java) =================================================================== --- trunk/test/picross/game/random/RandomPicrossModelTest.java (rev 0) +++ trunk/test/picross/game/random/RandomPicrossModelTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,65 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.random; + +import fr.cle.tests.TestsHelper; + +import org.apache.log4j.PropertyConfigurator; + +import org.junit.Test; + +import picross.AbstractPicrossGridTest; +import picross.PicrossGrid; + +/** + * Test class for the random model. + * + * @author Y. Norsa + */ +public class RandomPicrossModelTest extends AbstractPicrossGridTest { + /** Static block. */ + static { + PropertyConfigurator.configure("log4j.properties"); + } + + /*** Overloaded method from the class AbstractPicrossGridTest ***/ + + /** {@inheritDoc} */ + @Override + protected PicrossGrid getPicrossGrid() throws Throwable { + //return new RandomPicrossModel(); + + return (PicrossGrid) TestsHelper.getInstance("picross.game.random.RandomPicrossModel"); + } +} Copied: trunk/test/picross/game/simple/XBMModelTest.java (from rev 88, trunk/src/picross/game/simple/tests/XBMModelTest.java) =================================================================== --- trunk/test/picross/game/simple/XBMModelTest.java (rev 0) +++ trunk/test/picross/game/simple/XBMModelTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,123 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.game.simple; + +import fr.cle.tests.TestsHelper; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.log4j.PropertyConfigurator; + +import org.junit.Assert; +import org.junit.Test; + +import picross.AbstractPicrossGridTest; +import picross.Picross; +import picross.PicrossException; +import picross.PicrossGrid; + +/** + * Unit tests for XBMModel. + * + * @author Y. Norsa + */ +public final class XBMModelTest extends AbstractPicrossGridTest { + /*** Static field ***/ + + /** Valid XBM model. */ + private static PicrossGrid realModel; + + /*** Static initialisation block. Loads a valid XBM file. ***/ + static { + PropertyConfigurator.configure("log4j.properties"); + + try { + XBMModelTest.realModel = + //new XBMModel(Picross.loadDataFile("asterix.xbm")); + XBMModelTest.newXBMModel(Picross.loadDataFile("asterix.xbm")); + } catch (IOException ioEx) { + throw new ExceptionInInitializerError(ioEx); + } catch (PicrossException xbmEx) { + throw new ExceptionInInitializerError(xbmEx); + } + } + + /*** Method overloaded from the class AbstractPicrossGridTest ***/ + + /** {@inheritDoc} */ + protected PicrossGrid getPicrossGrid() { + return XBMModelTest.realModel; + } + + /** + * Tests the XBMModel constructor. + * + * @throws IOException if there is a problem with a stream loading + * @throws XBMException if a file isn't valid + */ + @Test + public void testXBMModel() throws IOException, PicrossException { + try { + //new XBMModel(null); + XBMModelTest.newXBMModel(null); + Assert.fail("Tried to load a null model"); + } catch (IllegalArgumentException argEx) { } + + try { + //new XBMModel(new ByteArrayInputStream("".getBytes())); + XBMModelTest.newXBMModel(new ByteArrayInputStream("".getBytes())); + Assert.fail("Empty file"); + } catch (PicrossException xbmEx) { } + } + + private static PicrossGrid newXBMModel(InputStream in) throws IOException, PicrossException { + try { + return (PicrossGrid) TestsHelper.getInstance("picross.game.simple.XBMModel", in); + } catch (Throwable throwable) { + if (throwable instanceof IOException) { + throw (IOException) throwable; + } + + if (throwable instanceof PicrossException) { + throw (PicrossException) throwable; + } + + //if (throwable instanceof RuntimeException) { + throw (RuntimeException) throwable; + //} + } + } +} Copied: trunk/test/picross/grid/BoxTest.java (from rev 88, trunk/src/picross/grid/tests/BoxTest.java) =================================================================== --- trunk/test/picross/grid/BoxTest.java (rev 0) +++ trunk/test/picross/grid/BoxTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,192 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.tests.TestsHelper; + +import javax.swing.ImageIcon; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class BoxTest { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + private Object box = null; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + BoxTest() { + } + */ + /*** M\xE9thode ***/ + + @Before + public void setUp() throws Throwable { + this.box = BoxTest.getBox(); + } + + @Test + public void testCheck() throws Throwable { + BoxTest.checkBox(this.box); + Assert.assertTrue("box unchecked", BoxTest.isBoxChecked(this.box)); + } + + @Test + public void testCross() throws Throwable { + BoxTest.crossBox(this.box); + Assert.assertTrue("box not crossed", BoxTest.isBoxCrossed(this.box)); + } + + @Test + public void testEmpty() throws Throwable { + TestsHelper.invoke(this.box, "empty"); + Assert.assertTrue("box not empty", BoxTest.isBoxEmpty(this.box)); + } + + @Test + public void testEquals() throws Throwable { + Assert.assertFalse("this.box = null", this.box.equals(null)); + Assert.assertTrue("box != box", this.box.equals(this.box)); + + BoxTest.checkBox(this.box); + + Object box2 = BoxTest.getBox(); + Assert.assertFalse("box = box2", this.box.equals(box2)); + + BoxTest.checkBox(box2); + + Assert.assertTrue("box != box2", this.box.equals(box2)); + } + + @Test + public void testgetIcon() throws Throwable { + Assert.assertNotNull("empty icon = null", BoxTest.getBoxIcon(this.box)); + + BoxTest.checkBox(this.box); + Assert.assertNotNull("checked icon = null", BoxTest.getBoxIcon(this.box)); + + BoxTest.crossBox(this.box); + Assert.assertNotNull("crossed icon = null", BoxTest.getBoxIcon(this.box)); + } + + @Test + public void testGetRolloverIcon() throws Throwable { + Assert.assertNotNull("rollover empty icon = null", + BoxTest.getBoxRolloverIcon(this.box)); + + BoxTest.checkBox(this.box); + Assert.assertNotNull("rollover checked icon = null", + BoxTest.getBoxRolloverIcon(this.box)); + + BoxTest.crossBox(this.box); + Assert.assertNotNull("rollover crossed icon = null", + BoxTest.getBoxRolloverIcon(this.box)); + } + + @Test + public void testIsChecked() throws Throwable { + BoxTest.checkBox(this.box); + + Assert.assertFalse("box crossed AND checked", BoxTest.isBoxCrossed(this.box)); + Assert.assertFalse("box empty AND checked", BoxTest.isBoxEmpty(this.box)); + } + + @Test + public void testIsCrossed() throws Throwable { + BoxTest.crossBox(this.box); + + Assert.assertFalse("box checked AND crossed", BoxTest.isBoxChecked(this.box)); + Assert.assertFalse("box empty AND crossed", BoxTest.isBoxEmpty(this.box)); + } + + @Test + public void testIsEmpty() throws Throwable { + Assert.assertFalse("box checked AND empty", BoxTest.isBoxChecked(this.box)); + Assert.assertFalse("box crossed AND empty", BoxTest.isBoxCrossed(this.box)); + } + + @Test + public void testSetRect() throws Throwable { + try { + TestsHelper.invoke(this.box, "setRect", null); + Assert.fail("box.setRect(null)"); + } catch (IllegalArgumentException argEx) { } + } + + private static Object getBox() throws Throwable { + return TestsHelper.getInstance("picross.grid.Box"); + } + + private static void checkBox(Object box) throws Throwable { + TestsHelper.invoke(box, "check"); + } + + private static void crossBox(Object box) throws Throwable { + TestsHelper.invoke(box, "cross"); + } + + private static ImageIcon getBoxIcon(Object box) throws Throwable { + return (ImageIcon) TestsHelper.invoke(box, "getIcon"); + } + + private static ImageIcon getBoxRolloverIcon(Object box) throws Throwable { + return (ImageIcon) TestsHelper.invoke(box, "getRolloverIcon"); + } + + private static boolean isBoxCrossed(Object box) throws Throwable { + return ((Boolean) TestsHelper.invoke(box, "isCrossed")).booleanValue(); + } + + private static boolean isBoxEmpty(Object box) throws Throwable { + return ((Boolean) TestsHelper.invoke(box, "isEmpty")).booleanValue(); + } + + private static boolean isBoxChecked(Object box) throws Throwable { + return ((Boolean) TestsHelper.invoke(box, "isChecked")).booleanValue(); + } +} + Copied: trunk/test/picross/grid/CompletedHintsTest.java (from rev 88, trunk/src/picross/grid/tests/CompletedHintsTest.java) =================================================================== --- trunk/test/picross/grid/CompletedHintsTest.java (rev 0) +++ trunk/test/picross/grid/CompletedHintsTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,235 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.tests.TestsHelper; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class CompletedHintsTest { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + Object hints = null; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + CompletedHintsTest() { + } + */ + /*** M\xE9thode ***/ + + @Before + public void setUp() throws Throwable { + this.hints = CompletedHintsTest.getCompletedHints(10, 10, 10, 10); + } + + @Test + public void testCompletedHints() throws Throwable { + try { + CompletedHintsTest.getCompletedHints(-1, -1, -1, -1); + Assert.fail("colsHintsWidth = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompletedHints(0, -1, -1, -1); + Assert.fail("colsHintsWidth = 0"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompletedHints(1, -1, -1, -1); + Assert.fail("colsHintsHeight = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompletedHints(1, 0, -1, -1); + Assert.fail("colsHintsHeight = 0"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompletedHints(1, 1, -1, -1); + Assert.fail("rowsHintsWidth = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompletedHints(1, 1, 0, -1); + Assert.fail("rowsHintsWidth = 0"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompletedHints(1, 1, 1, -1); + Assert.fail("rowsHintsHeight = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompletedHints(1, 1, 1, 0); + Assert.fail("rowsHintsHeight = 0"); + } catch (IllegalArgumentException argEx) { } + } + + @Test + public void testClearColHint() throws Throwable { + CompletedHintsTest.setCompleteColHint(this.hints, 3, 4); + TestsHelper.invoke(this.hints, "clearColHint", 3, 4); + Assert.assertFalse(CompletedHintsTest.isColHintComplete(this.hints, 3, 4)); + } + + @Test + public void testClearRowHint() throws Throwable { + CompletedHintsTest.setCompleteRowHint(this.hints, 8, 2); + TestsHelper.invoke(this.hints, "clearRowHint", 8, 2); + Assert.assertFalse(CompletedHintsTest.isRowHintComplete(this.hints, 8, 2)); + } + + @Test + public void testGetCompleteColHints() throws Throwable { + try { + CompletedHintsTest.getCompleteColHints(this.hints, -1); + Assert.fail("column = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompleteColHints(this.hints, 42); + Assert.fail("column = 42"); + } catch (IllegalArgumentException argEx) { } + + List<Integer> complete = CompletedHintsTest.getCompleteColHints(this.hints, 4); + Assert.assertNotNull("complete = null", complete); + int size = complete.size(); + Assert.assertTrue("size = " + size, (size == 0)); + + CompletedHintsTest.setCompleteColHint(this.hints, 4, 0); + CompletedHintsTest.setCompleteColHint(this.hints, 4, 9); + + complete = CompletedHintsTest.getCompleteColHints(this.hints, 4); + Assert.assertNotNull("complete = null", complete); + size = complete.size(); + Assert.assertTrue("size = " + size, (size == 2)); + + int nb1 = complete.get(0); + Assert.assertTrue("nb1 = " + nb1, (nb1 == 0)); + + int nb2 = complete.get(1); + Assert.assertTrue("nb2 = " + nb2, (nb2 == 9)); + } + + @Test + public void testGetCompleteRowHints() throws Throwable { + try { + CompletedHintsTest.getCompleteRowHints(this.hints, -1); + Assert.fail("row = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + CompletedHintsTest.getCompleteRowHints(this.hints, 42); + Assert.fail("row = 42"); + } catch (IllegalArgumentException argEx) { } + + List<Integer> complete = CompletedHintsTest.getCompleteRowHints(this.hints, 9); + Assert.assertNotNull("complete = null", complete); + int size = complete.size(); + Assert.assertTrue("size = " + size, (size == 0)); + + CompletedHintsTest.setCompleteRowHint(this.hints, 9, 3); + CompletedHintsTest.setCompleteRowHint(this.hints, 9, 6); + + complete = CompletedHintsTest.getCompleteRowHints(this.hints, 9); + Assert.assertNotNull("complete = null", complete); + size = complete.size(); + Assert.assertTrue("size = " + size, (size == 2)); + + int nb1 = complete.get(0); + Assert.assertTrue("nb1 = " + nb1, (nb1 == 3)); + + int nb2 = complete.get(1); + Assert.assertTrue("nb2 = " + nb2, (nb2 == 6)); + } + + @Test + public void testIsColHintCompleteAndSetCompleteColHint() throws Throwable { + Assert.assertFalse(CompletedHintsTest.isColHintComplete(this.hints, 0, 0)); + CompletedHintsTest.setCompleteColHint(this.hints, 0, 0); + Assert.assertTrue(CompletedHintsTest.isColHintComplete(this.hints, 0, 0)); + } + + @Test + public void testIsRowHintCompleteAndSetCompleteRowHint() throws Throwable { + Assert.assertFalse(CompletedHintsTest.isRowHintComplete(this.hints, 5, 5)); + CompletedHintsTest.setCompleteRowHint(this.hints, 5, 5); + Assert.assertTrue(CompletedHintsTest.isRowHintComplete(this.hints, 5, 5)); + } + + private static Object getCompletedHints(int colHintsWidth, int colHintsHeight, int rowHintsWidth, int rowHintsHeight) throws Throwable { + return TestsHelper.getInstance("picross.grid.CompletedHints", colHintsWidth, colHintsHeight, rowHintsWidth, rowHintsHeight); + } + + private static void setCompleteColHint(Object hints, int col, int index) throws Throwable { + TestsHelper.invoke(hints, "setCompleteColHint", col, index); + } + + private static boolean isColHintComplete(Object hints, int x, int y) throws Throwable { + return ((Boolean) TestsHelper.invoke(hints, "isColHintComplete", x, y)).booleanValue(); + } + + private static void setCompleteRowHint(Object hints, int row, int index) throws Throwable { + TestsHelper.invoke(hints, "setCompleteRowHint", row, index); + } + + private static boolean isRowHintComplete(Object hints, int x, int y) throws Throwable { + return ((Boolean) TestsHelper.invoke(hints, "isRowHintComplete", x, y)).booleanValue(); + } + + private static List<Integer> getCompleteColHints(Object hints, int column) throws Throwable { + return (List<Integer>) TestsHelper.invoke(hints, "getCompleteColHints", column); + } + + private static List<Integer> getCompleteRowHints(Object hints, int row) throws Throwable { + return (List<Integer>) TestsHelper.invoke(hints, "getCompleteRowHints", row); + } +} + Copied: trunk/test/picross/grid/FillCommandTest.java (from rev 88, trunk/src/picross/grid/tests/FillCommandTest.java) =================================================================== --- trunk/test/picross/grid/FillCommandTest.java (rev 0) +++ trunk/test/picross/grid/FillCommandTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,82 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class FillCommandTest { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + FillCommandTest() { + } + */ + /*** M\xE9thode ***/ + + @Test + public void testFillCommand() { + /* try { + new FillCommand(-1, -1, GridAction.UNKNOWN); + Assert.fail("row = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new FillCommand(0, -1, GridAction.UNKNOWN); + Assert.fail("column = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + new FillCommand(0, 0, GridAction.UNKNOWN); + Assert.fail("UNKNOWN type"); + } catch (IllegalArgumentException argEx) { } + + new FillCommand(0, 0, GridAction.CHECK); + */ + } + +} + Copied: trunk/test/picross/grid/GridModelTest.java (from rev 88, trunk/src/picross/grid/tests/GridModelTest.java) =================================================================== --- trunk/test/picross/grid/GridModelTest.java (rev 0) +++ trunk/test/picross/grid/GridModelTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,122 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.tests.TestsHelper; + +import org.easymock.EasyMock; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class GridModelTest { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + private Object model = null; + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + GridModelTest() { + }*/ + + /*** M\xE9thode ***/ + + @Before + public void setUp() throws Throwable { + this.model = GridModelTest.getGridModel(new IGridMediatorStub(), new boolean[3][5]); + } + + @Test + public void testGridModel() throws Throwable { + try { + GridModelTest.getGridModel(null, null); + Assert.fail("mediator = null"); + } catch (IllegalArgumentException argEx) { } + + IGridMediator stub = new IGridMediatorStub(); + + try { + GridModelTest.getGridModel(stub, null); + Assert.fail("data = null"); + } catch (IllegalArgumentException argEx) { } + + try { + GridModelTest.getGridModel(stub, new boolean[0][0]); + Assert.fail("empty data"); + } catch (IllegalArgumentException argEx) { } + + try { + GridModelTest.getGridModel(stub, new boolean[1][0]); + Assert.fail("empty data"); + } catch (IllegalArgumentException argEx) { } + } + + /* + @Test + public void testActOnBox() { + try { + GridModelTest.actOnBox(this.model, -1, -1, GridAction.CHECK); + Assert.fail("row = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + GridModelTest.actOnBox(this.model, 0, -1, GridAction.CHECK); + Assert.fail("column = -1"); + } catch (IllegalArgumentException argEx) { } + + GridModelTest.actOnBox(this.model, 0, 0, GridAction.CHECK); + } + */ + private static Object getGridModel(IGridMediator mediator, boolean[][] data) throws Throwable { + return TestsHelper.getInstance("picross.grid.GridModel", mediator, data); + } + /* + private static void actOnBox(Object gridModel, int row, int column, Object action) { + TestsHelper.invoke(gridModel, "actOnBox", row, colum, action); + } + */ +} + Copied: trunk/test/picross/grid/IGridMediatorStub.java (from rev 88, trunk/src/picross/grid/tests/IGridMediatorStub.java) =================================================================== --- trunk/test/picross/grid/IGridMediatorStub.java (rev 0) +++ trunk/test/picross/grid/IGridMediatorStub.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,82 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.mmvcs.SimpleEvent; +import fr.cle.mmvcs.SimpleListener; + +/** + * @author Y. Norsa + */ +public class IGridMediatorStub implements IGridMediator { + /*** Constante ***/ + + /*** Champ statique ***/ + + /*** Champ ***/ + + /*** Constructeur ***/ + + /** + * Constructeur. + */ + /* + IGridMediatorStub() { + } + */ + + /*** M\xE9thode ***/ + + public void repaint(int row, int column) { } + + public void repaintColHints(int col) { } + + public void repaintRowHints(int row) { } + + public void congratulations() { } + + public void setEraseMode() { } + + public GridView getView() { + return null; + } + + public void eventPerformed(SimpleEvent e) { + } + + public void addSimpleListener(SimpleListener listener) { } + + public void removeSimpleListener(SimpleListener listener) { } +} + Copied: trunk/test/picross/grid/PaintCommandTest.java (from rev 88, trunk/src/picross/grid/tests/PaintCommandTest.java) =================================================================== --- trunk/test/picross/grid/PaintCommandTest.java (rev 0) +++ trunk/test/picross/grid/PaintCommandTest.java 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,64 @@ +/* + * $Id$ + * + * Copyright (c) 2007-2008 + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + + +package picross.grid; + +import fr.cle.tests.TestsHelper; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Y. Norsa + */ +public class PaintCommandTest { + @Test + public void testPaintCommand() throws Throwable { + try { + PaintCommandTest.getPaintCommand(-1, -1); + Assert.fail("row = -1"); + } catch (IllegalArgumentException argEx) { } + + try { + PaintCommandTest.getPaintCommand(0, -1); + Assert.fail("column = -1"); + } catch (IllegalArgumentException argEx) { } + + PaintCommandTest.getPaintCommand(0, 0); + } + + private static Object getPaintCommand(int row, int column) throws Throwable { + return TestsHelper.getInstance("picross.grid.PaintCommand", row, column); + } +} + Copied: trunk/test/picross/package.html (from rev 88, trunk/src/picross/tests/package.html) =================================================================== --- trunk/test/picross/package.html (rev 0) +++ trunk/test/picross/package.html 2011-06-16 11:11:11 UTC (rev 90) @@ -0,0 +1,12 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <!-- + $Id$ + --> + </head> + + <body bgcolor="white"> + Unit tests for package picross. + </body> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |