[Picross-commit] SF.net SVN: picross: [40] trunk
Status: Pre-Alpha
Brought to you by:
yvan_norsa
From: <yva...@us...> - 2007-06-15 19:57:57
|
Revision: 40 http://picross.svn.sourceforge.net/picross/?rev=40&view=rev Author: yvan_norsa Date: 2007-06-15 12:57:57 -0700 (Fri, 15 Jun 2007) Log Message: ----------- javadoc generation, unit tests Modified Paths: -------------- trunk/bugsFilter.xml trunk/build.xml trunk/src/picross/Picross.java trunk/src/picross/PicrossGrid.java trunk/src/picross/app/MainMenuAppUI.java trunk/src/picross/applet/MainMenuAppletUI.java trunk/src/picross/game/GameMediator.java trunk/src/picross/game/random/RandomGameMediator.java trunk/src/picross/game/simple/SimpleGameMediator.java trunk/src/picross/game/simple/XBMModel.java trunk/src/picross/grid/Box.java trunk/src/picross/grid/GridMediator.java trunk/src/picross/grid/GridUI.java trunk/src/picross/menus/MainMenuUI.java Added Paths: ----------- trunk/lib/junit.jar trunk/src/picross/game/random/RandomPicrossModelTest.java trunk/src/picross/game/simple/package.html trunk/src/picross/tests/ trunk/src/picross/tests/AbstractPicrossGridTest.java trunk/src/picross/tests/PicrossTest.java trunk/src/picross/tests/package.html Modified: trunk/bugsFilter.xml =================================================================== --- trunk/bugsFilter.xml 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/bugsFilter.xml 2007-06-15 19:57:57 UTC (rev 40) @@ -1,5 +1,5 @@ <FindBugsFilter> <Match classregex=".*"> - <Bug pattern="DM_CONVERT_CASE,LSC_LITERAL_STRING_COMPARISON,CLI_CONSTANT_LIST_INDEX,S508C_SET_COMP_COLOR,S508C_NO_SETLABELFOR" /> + <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> </FindBugsFilter> Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/build.xml 2007-06-15 19:57:57 UTC (rev 40) @@ -7,6 +7,8 @@ value="build" /> <property name="dist.dir" value="dist" /> + <property name="doc.dir" + value="doc" /> <property name="lib.dir" value="lib" /> <property name="src.dir" @@ -17,15 +19,18 @@ <property name="bundleHelper.jar" value="${lib.dir}/bundleHelper.jar" /> + <property name="junit.jar" + value="${lib.dir}/junit.jar" /> + <property name="log4j.jar" + value="${lib.dir}/log4j.jar" /> <property name="mmvcs.jar" value="${lib.dir}/mmvcs.jar" /> - <property name="log4j.jar" - value="${lib.dir}/log4j.jar" /> <target name="-init" depends="-setmode"> <mkdir dir="${build.dir}" /> <mkdir dir="${dist.dir}" /> + <mkdir dir="${doc.dir}" /> </target> <target name="release"> @@ -52,6 +57,7 @@ <pathelement location="${build.dir}" /> <pathelement location="${bundleHelper.jar}" /> + <pathelement location="${junit.jar}" /> <pathelement location="${log4j.jar}" /> <pathelement location="${mmvcs.jar}" /> </path> @@ -103,9 +109,32 @@ </java> </target> + <target name="test" + depends="dist"> + <junit haltonfailure="yes" + filtertrace="off" + showoutput="on" + printsummary="withOutAndErr"> + <formatter type="plain" + usefile="false" /> + + <batchtest fork="yes" + filtertrace="on" + haltonfailure="yes"> + <fileset dir="${src.dir}"> + <include name="**/*Test.java" /> + <exclude name="**/Abstract*Test.java" /> + </fileset> + </batchtest> + + <classpath refid="classpath" /> + </junit> + </target> + <target name="clean"> <delete dir="${build.dir}" /> <delete dir="${dist.dir}" /> + <delete dir="${doc.dir}" /> <delete> <fileset dir="." @@ -117,6 +146,21 @@ <target name="rebuild" depends="clean, dist" /> + <target name="doc" + depends="compile"> + <!-- FIXME test classes which are *not* in a "tests" subpackage + are included in the Javadoc --> + <javadoc destdir="${doc.dir}" + link="http://java.sun.com/j2se/1.5.0/docs/api"> + <packageset dir="${src.dir}" + defaultexcludes="yes"> + <exclude name="**/tests/**" /> + </packageset> + + <classpath refid="classpath" /> + </javadoc> + </target> + <property file="checkstyle.properties" /> <target name="-check-checkstyle"> @@ -137,9 +181,9 @@ <formatter type="xml" tofile="checkstyle.xml" /> - <!-- Pour tous les fichiers source sauf les tests --> <fileset dir="${src.dir}" - includes="**/*.java" /> + includes="**/*.java" + excludes="**/tests/" /> </checkstyle> <xslt in="checkstyle.xml" Added: trunk/lib/junit.jar =================================================================== (Binary files differ) Property changes on: trunk/lib/junit.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Name: svn:keywords + Id Modified: trunk/src/picross/Picross.java =================================================================== --- trunk/src/picross/Picross.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/Picross.java 2007-06-15 19:57:57 UTC (rev 40) @@ -33,9 +33,12 @@ package picross; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.URL; + import java.util.Locale; import javax.swing.ImageIcon; @@ -53,6 +56,7 @@ /** Images directory. */ private static final String IMAGES_DIR = "/picross/images/"; + /** Data directory. */ private static final String DATA_DIR = "/picross/data/"; /** Images directory corresponding to the default locale. */ @@ -72,13 +76,33 @@ /*** Static methods ***/ /** + * Loads a file. + * + * @param path file path + * @return URL of the file + * @throws FileNotFoundException if the file can't be found + */ + private static URL getFile(String path) throws FileNotFoundException { + URL fileUrl = Picross.class.getResource(path); + + if (fileUrl == null) { + throw new FileNotFoundException("\"" + path + "\" can't be found"); + } + + return fileUrl; + } + + /** * Loads an image. * * @param path path of the image * @return the image + * @throws FileNotFoundException if the file can't be found */ - private static ImageIcon loadImage(String path) { - return new ImageIcon(Picross.class.getResource(path)); + private static ImageIcon loadImage(String path) + throws FileNotFoundException { + + return new ImageIcon(Picross.getFile(path)); } /** @@ -86,8 +110,17 @@ * * @param name image filename * @return the image + * @throws IllegalArgumentException if <code>name</code> + * is <code>null</code> or empty + * @throws FileNotFoundException if the file can't be found */ - public static ImageIcon getImage(String name) { + public static ImageIcon getImage(String name) + throws IllegalArgumentException, FileNotFoundException { + + if (name == null || name.equals("")) { + throw new IllegalArgumentException("name can't be null or empty"); + } + return Picross.loadImage(Picross.IMAGES_DIR + name); } @@ -96,15 +129,37 @@ * * @param name image filename * @return the image + * @throws IllegalArgumentException if <code>name</code> + * is <code>null</code> or empty + * @throws FileNotFoundException if the file can't be found */ - public static ImageIcon getLocalizedImage(String name) { + public static ImageIcon getLocalizedImage(String name) + throws IllegalArgumentException, FileNotFoundException { + + if (name == null || name.equals("")) { + throw new IllegalArgumentException("name can't be null or empty"); + } + return Picross.loadImage(Picross.LOCAL_IMAGES_PATH + name); } + /** + * Loads a data file. + * + * @param name filename + * @return a stream containing the loaded file + * @throws IllegalArgumentException if <code>name</code> + * is <code>null</code> or empty + * @throws IOException if there is a problem while opening the file + */ public static InputStream loadDataFile(String name) - throws IOException { + throws IllegalArgumentException, IOException { - return Picross.class.getResource(Picross.DATA_DIR + name).openStream(); + if (name == null || name.equals("")) { + throw new IllegalArgumentException("name can't be null or empty"); + } + + return Picross.getFile(Picross.DATA_DIR + name).openStream(); } } Modified: trunk/src/picross/PicrossGrid.java =================================================================== --- trunk/src/picross/PicrossGrid.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/PicrossGrid.java 2007-06-15 19:57:57 UTC (rev 40) @@ -42,21 +42,21 @@ /** * Returns the width. * - * @return grid width + * @return grid width (always > 0) */ int getWidth(); /** * Returns the height. * - * @return grid height + * @return grid height (always > 0) */ int getHeight(); /** * Returns the content. * - * @return grid content + * @return grid content (of size width * height) */ boolean[][] getData(); } Modified: trunk/src/picross/app/MainMenuAppUI.java =================================================================== --- trunk/src/picross/app/MainMenuAppUI.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/app/MainMenuAppUI.java 2007-06-15 19:57:57 UTC (rev 40) @@ -35,6 +35,8 @@ import java.awt.event.ActionListener; +import java.io.FileNotFoundException; + import javax.swing.ImageIcon; import javax.swing.JButton; @@ -75,8 +77,11 @@ * Constructor. * * @param controller controller for the buttons + * @throws FileNotFoundException if a button image can't be found */ - public MainMenuAppUI(ActionListener controller) { + public MainMenuAppUI(ActionListener controller) + throws FileNotFoundException { + super(controller); ImageIcon exitIcon = Modified: trunk/src/picross/applet/MainMenuAppletUI.java =================================================================== --- trunk/src/picross/applet/MainMenuAppletUI.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/applet/MainMenuAppletUI.java 2007-06-15 19:57:57 UTC (rev 40) @@ -37,6 +37,8 @@ import java.awt.event.ActionListener; +import java.io.FileNotFoundException; + import picross.menus.MainMenuUI; /** @@ -62,8 +64,11 @@ * Constructor. * * @param controller controller for the buttons + * @throws FileNotFoundException if a button image can't be found */ - public MainMenuAppletUI(ActionListener controller) { + public MainMenuAppletUI(ActionListener controller) + throws FileNotFoundException { + super(controller); this.setBackground(Color.WHITE); Modified: trunk/src/picross/game/GameMediator.java =================================================================== --- trunk/src/picross/game/GameMediator.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/game/GameMediator.java 2007-06-15 19:57:57 UTC (rev 40) @@ -63,7 +63,12 @@ /*** Constructor ***/ - /** Constructor. */ + /** + * Constructor. + * + * @throws PicrossException if there is a problem loading the grid model + * or building the view + */ public GameMediator() throws PicrossException { PicrossGrid model = this.initModel(); @@ -95,6 +100,7 @@ * Creates the model. * * @return grid model + * @throws PicrossException if there is a problem */ protected abstract PicrossGrid initModel() throws PicrossException; Modified: trunk/src/picross/game/random/RandomGameMediator.java =================================================================== --- trunk/src/picross/game/random/RandomGameMediator.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/game/random/RandomGameMediator.java 2007-06-15 19:57:57 UTC (rev 40) @@ -57,6 +57,14 @@ /** The class' logger. */ //private static Logger log = Logger.getLogger(RandomGameMediator.class); + /*** Constructor ***/ + + /** + * Constructor. + * + * @throws PicrossException if there is a problem loading the grid model + * or building the view + */ RandomGameMediator() throws PicrossException { super(); } Added: trunk/src/picross/game/random/RandomPicrossModelTest.java =================================================================== --- trunk/src/picross/game/random/RandomPicrossModelTest.java (rev 0) +++ trunk/src/picross/game/random/RandomPicrossModelTest.java 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,59 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * 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 org.apache.log4j.PropertyConfigurator; + +import picross.PicrossGrid; + +import picross.tests.AbstractPicrossGridTest; + +/** + * 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} */ + protected PicrossGrid getPicrossGrid() { + return new RandomPicrossModel(); + } +} Property changes on: trunk/src/picross/game/random/RandomPicrossModelTest.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/game/simple/SimpleGameMediator.java =================================================================== --- trunk/src/picross/game/simple/SimpleGameMediator.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/game/simple/SimpleGameMediator.java 2007-06-15 19:57:57 UTC (rev 40) @@ -35,8 +35,6 @@ import java.io.IOException; -import javax.swing.JPanel; - import picross.Picross; import picross.PicrossException; import picross.PicrossGrid; @@ -44,26 +42,26 @@ import picross.game.GameMediator; /** + * Mediator for a classic game. + * * @author Y. Norsa */ public final class SimpleGameMediator extends GameMediator { - /*** Constante ***/ + /*** Constructor ***/ - /*** Champ statique ***/ - - /*** Champ ***/ - - /*** Constructeur ***/ - /** - * Constructeur. + * Constructor. + * + * @throws PicrossException if there is a problem loading the grid model + * or building the view */ public SimpleGameMediator() throws PicrossException { super(); } - /*** M\xE9thode ***/ + /*** Method overloaded from the class GameMediator ***/ + /** {@inheritDoc} */ protected PicrossGrid initModel() throws PicrossException { try { return new XBMModel(Picross.loadDataFile("halloween.xbm")); Modified: trunk/src/picross/game/simple/XBMModel.java =================================================================== --- trunk/src/picross/game/simple/XBMModel.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/game/simple/XBMModel.java 2007-06-15 19:57:57 UTC (rev 40) @@ -34,9 +34,9 @@ package picross.game.simple; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -46,21 +46,23 @@ import picross.AbstractPicrossModel; /** + * Class loading a XBM file. + * * @author Y. Norsa */ final class XBMModel extends AbstractPicrossModel { - /*** Constante ***/ + /*** Static field ***/ - /*** Champ statique ***/ - + /** The class' logger. */ private static Logger log = Logger.getLogger(XBMModel.class); - /*** Champ ***/ + /*** Constructor ***/ - /*** Constructeur ***/ - /** - * Constructeur. + * Constructor. + * + * @param input XBM file input stream + * @throws IOException if there is a problem while reading the file */ XBMModel(InputStream input) throws IOException { super(); @@ -130,7 +132,7 @@ while (binaryStr.length() < 8) { binaryStr = "0" + binaryStr; } - + //XBMModel.log.debug(binaryStr); for (int j = 8 - 1; j >= 0; j--) { Added: trunk/src/picross/game/simple/package.html =================================================================== --- trunk/src/picross/game/simple/package.html (rev 0) +++ trunk/src/picross/game/simple/package.html 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,12 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> + <head> + <!-- + $Id$ + --> + </head> + + <body bgcolor="white"> + Simple game mode. + </body> +</html> Property changes on: trunk/src/picross/game/simple/package.html ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/src/picross/grid/Box.java =================================================================== --- trunk/src/picross/grid/Box.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/grid/Box.java 2007-06-15 19:57:57 UTC (rev 40) @@ -35,6 +35,8 @@ import java.awt.Rectangle; +import java.io.FileNotFoundException; + import java.util.HashMap; import java.util.Map; import java.util.Random; @@ -113,17 +115,21 @@ */ Box.images = new HashMap<Box.BoxState, ImageIcon[]>(7); - for (Box.BoxState state : Box.BoxState.values()) { - ImageIcon[] img = new ImageIcon[2]; + try { + for (Box.BoxState state : Box.BoxState.values()) { + ImageIcon[] img = new ImageIcon[2]; - String stateImageName = state.toString().toLowerCase(); - img[Box.ICON_INDEX] = Picross.getImage(stateImageName + String stateImageName = state.toString().toLowerCase(); + img[Box.ICON_INDEX] = Picross.getImage(stateImageName + Box.IMAGES_EXT); - img[Box.ROLLOVER_ICON_INDEX] = - Picross.getImage(stateImageName + Box.ROLLOVER_NAME - + Box.IMAGES_EXT); + img[Box.ROLLOVER_ICON_INDEX] = + Picross.getImage(stateImageName + Box.ROLLOVER_NAME + + Box.IMAGES_EXT); - Box.images.put(state, img); + Box.images.put(state, img); + } + } catch (FileNotFoundException fileEx) { + throw new ExceptionInInitializerError(fileEx); } } Modified: trunk/src/picross/grid/GridMediator.java =================================================================== --- trunk/src/picross/grid/GridMediator.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/grid/GridMediator.java 2007-06-15 19:57:57 UTC (rev 40) @@ -36,10 +36,14 @@ import fr.cle.mmvcs.Mediateur; import fr.cle.mmvcs.SimpleEvent; +import java.io.FileNotFoundException; + import javax.swing.JPanel; //import org.apache.log4j.Logger; +import picross.PicrossException; + /** * Picross grid mediator. * @@ -67,20 +71,27 @@ * @param width grid width * @param height grid height * @param data grid content + * @throws PicrossException if there is a probleme while building the view */ - public GridMediator(int width, int height, boolean[][] data) { + public GridMediator(int width, int height, boolean[][] data) + throws PicrossException { + this.model = new GridModel(this, data); GridController controller = new GridController(); controller.addSimpleListener(this); this.addSimpleListener(controller); - this.view = new GridUI(width, height, - this.model.getBoxes(), - this.model.getColData(), - this.model.getRowData(), - this.model.getCompletedHints(), - controller); + try { + this.view = new GridUI(width, height, + this.model.getBoxes(), + this.model.getColData(), + this.model.getRowData(), + this.model.getCompletedHints(), + controller); + } catch (FileNotFoundException fileEx) { + throw new PicrossException(fileEx); + } controller.setView(this.view); } Modified: trunk/src/picross/grid/GridUI.java =================================================================== --- trunk/src/picross/grid/GridUI.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/grid/GridUI.java 2007-06-15 19:57:57 UTC (rev 40) @@ -48,6 +48,8 @@ import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; + import java.util.ArrayList; import java.util.List; @@ -212,13 +214,14 @@ * @param rowData rows hints * @param completedHints list of completed hints * @param controller controller for the grid + * @throws FileNotFoundException if an image is missing */ GridUI(int width, int height, Box[][] boxes, int[][] colData, int[][] rowData, CompletedHints completedHints, - GridController controller) { + GridController controller) throws FileNotFoundException { super(true); this.controller = controller; Modified: trunk/src/picross/menus/MainMenuUI.java =================================================================== --- trunk/src/picross/menus/MainMenuUI.java 2007-06-14 13:51:01 UTC (rev 39) +++ trunk/src/picross/menus/MainMenuUI.java 2007-06-15 19:57:57 UTC (rev 40) @@ -39,6 +39,8 @@ import java.awt.event.ActionListener; +import java.io.FileNotFoundException; + import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JPanel; @@ -74,8 +76,9 @@ * Constructor. * * @param controller controller for the buttons + * @throws FileNotFoundException if a button image can't be found */ - public MainMenuUI(ActionListener controller) { + public MainMenuUI(ActionListener controller) throws FileNotFoundException { ImageIcon icon = Picross.getImage(MainMenuUI.BACKGROUND_IMAGE); this.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); @@ -90,7 +93,8 @@ playButton.addActionListener(controller); playButton.setBorder(null); playButton.setBounds(this.getPlayButtonX(), this.getPlayButtonY(), - playIcon.getIconWidth(), playIcon.getIconHeight()); + playIcon.getIconWidth(), + playIcon.getIconHeight()); this.add(playButton); } Added: trunk/src/picross/tests/AbstractPicrossGridTest.java =================================================================== --- trunk/src/picross/tests/AbstractPicrossGridTest.java (rev 0) +++ trunk/src/picross/tests/AbstractPicrossGridTest.java 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,101 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * 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.tests; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import picross.PicrossGrid; + +/** + * 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(); + + /*** Methods ***/ + + /** Performs the instance initialisation. */ + @Before + public void setUp() { + 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); + } + } +} Property changes on: trunk/src/picross/tests/AbstractPicrossGridTest.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/tests/PicrossTest.java =================================================================== --- trunk/src/picross/tests/PicrossTest.java (rev 0) +++ trunk/src/picross/tests/PicrossTest.java 2007-06-15 19:57:57 UTC (rev 40) @@ -0,0 +1,152 @@ +/* + * $Id$ + * + * Copyright (c) 2007 + * + * 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.tests; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import javax.swing.ImageIcon; + +import org.junit.Assert; +import org.junit.Test; + +import picross.Picross; + +/** + * 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 FileNotFoundException if a file loading fails. + */ + @Test + public void testGetImage() throws FileNotFoundException { + 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 (FileNotFoundException fileEx) { } + + ImageIcon icon = Picross.getImage("empty.png"); + PicrossTest.testIcon(icon, 25, 25); + } + + /** + * Tests the method getLocalizedImage(). + * + * @throws FileNotFoundException if a file loading fails. + */ + @Test + public void getLocalizedImage() throws FileNotFoundException { + 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 (FileNotFoundException fileEx) { } + + 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("blarg.xbm"); + Assert.assertNotNull("in = null", in); + in.close(); + } +} Property changes on: trunk/src/picross/tests/PicrossTest.java ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/picross/tests/package.html =================================================================== --- trunk/src/picross/tests/package.html (rev 0) +++ trunk/src/picross/tests/package.html 2007-06-15 19:57:57 UTC (rev 40) @@ -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> Property changes on: trunk/src/picross/tests/package.html ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |