[Schmitzm-commits] r1144 - trunk/src_junit/schmitzm/swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Oct 17 02:53:35 CEST 2010


Author: alfonx
Date: 2010-10-17 02:53:34 +0200 (Sun, 17 Oct 2010)
New Revision: 1144

Modified:
   trunk/src_junit/schmitzm/swing/SwingUtilTest.java
   trunk/src_junit/schmitzm/swing/TestingUtil.java
Log:


Modified: trunk/src_junit/schmitzm/swing/SwingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/swing/SwingUtilTest.java	2010-10-17 00:14:45 UTC (rev 1143)
+++ trunk/src_junit/schmitzm/swing/SwingUtilTest.java	2010-10-17 00:53:34 UTC (rev 1144)
@@ -14,6 +14,22 @@
 public class SwingUtilTest {
 
     @Test
+	public void testConvertColorToHexColor() {
+		assertEquals("#0000ff", SwingUtil.convertColorToHex(Color.BLUE));
+	}
+  
+  
+	@Test
+	public void testConvertColorToHexColorBooleanBoolean() {
+		assertEquals("#ff0000ff", SwingUtil.convertColorToHex(Color.RED, true,
+				true));
+		assertEquals("#00ff00", SwingUtil.convertColorToHex(Color.GREEN, false,
+				true));
+		assertEquals("0000ff", SwingUtil.convertColorToHex(Color.BLUE, false,
+				false));
+	}
+
+	@Test
     public void testPasswortInputOption() {
       if ( !TestingUtil.isInteractive() )
         return;
@@ -32,20 +48,4 @@
       else
         System.out.println("Passwort was: "+ new String((char[])values[0]));
     }
-  
-  
-	@Test
-	public void testConvertColorToHexColorBooleanBoolean() {
-		assertEquals("#ff0000ff", SwingUtil.convertColorToHex(Color.RED, true,
-				true));
-		assertEquals("#00ff00", SwingUtil.convertColorToHex(Color.GREEN, false,
-				true));
-		assertEquals("0000ff", SwingUtil.convertColorToHex(Color.BLUE, false,
-				false));
-	}
-
-	@Test
-	public void testConvertColorToHexColor() {
-		assertEquals("#0000ff", SwingUtil.convertColorToHex(Color.BLUE));
-	}
 }
\ No newline at end of file

Modified: trunk/src_junit/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src_junit/schmitzm/swing/TestingUtil.java	2010-10-17 00:14:45 UTC (rev 1143)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java	2010-10-17 00:53:34 UTC (rev 1144)
@@ -46,19 +46,19 @@
 import schmitzm.lang.LangUtil;
 
 /**
- * Helpers to test Swing applications in general.
+ * Helpers to test Swing applications in general. <br/>
+ * If not set to @Ignore, HUDSON will complain
+ * "java.lang.Exception: No runnable methods"
  */
 
 @Ignore
-// If not Ignored, HUDSON will complain
-// "java.lang.Exception: No runnable methods"
 public class TestingUtil {
 
 	/**
 	 * List of available test datasets
 	 */
 	public static enum TestDatasets {
-		kreise, arabicInHeader;
+		arabicInHeader, kreise;
 
 		public URL getUrl() {
 			switch (this) {
@@ -73,97 +73,36 @@
 	}
 
 	/**
-	 * Number of seconds to wait until a GUI should be closed by default. Can be
-	 * set to -1 to always wait forever.
-	 */
-	private static final int WAIT_MAX_DEFAULT = 3;
-	/**
 	 * All these GUI-initiating testGui(...) methods are only executed if the
 	 * system is not running in headless mode.
 	 */
 	public static final boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
+	final static String resLocation_ArabicHeader = "/schmitzm/geotools/feature/arabicShapefiles/arabicwitharabicinheader.shp";
 
+	final static String resLocation_Kreise = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
+
 	/**
-	 * Opens a {@link JFrame} and shows the passed {@link JComponent}. If a
-	 * {@link ExceptionDialog} is opens in the GUI, an exception is thrown.<br/>
-	 * The test is skipped if the JVM is running headless.
-	 * 
-	 * @param gui
-	 * @param title
-	 *            can be used to explain the tests what to check
-	 * @param waitMax
-	 *            Maximum seconds to wait until the GUI should automatically
-	 *            close, set -1 for unlimieted
+	 * Number of seconds to wait until a GUI should be closed by default. Can be
+	 * set to -1 to always wait forever.
 	 */
-	public static void testGui(Component gui, String title, int waitMax)
-			throws Throwable {
+	private static final int WAIT_MAX_DEFAULT = 3;
 
-		if (GraphicsEnvironment.isHeadless())
-			return;
+	private static boolean checkPixel(BufferedImage bi, int x, int y,
+			Color expected) {
+		final int rgb = bi.getRGB(x, y);
 
-		final AtomicBoolean stopFlag = new AtomicBoolean(false);
+		final Color found = new Color(rgb, true);
 
-		final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
+		final boolean equals = expected.equals(found);
 
-		ExceptionDialog.addListener(new ActionListener() {
-
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				err.set((Throwable) e.getSource());
-				stopFlag.set(true);
-			}
-		});
-
-		Window w = null;
-		if (gui instanceof Window) {
-			w = (Window) gui;
-		} else if (gui instanceof JComponent) {
-			JFrame f = new JFrame(title);
-			f.setContentPane((JComponent) gui);
-			f.pack();
-			w = f;
+		if (!equals) {
+			System.err.println("At pixel (" + x + "/" + y + ") expected "
+					+ expected + " but found " + found);
 		}
 
-		// If it is a modal dialog, unmodalize it
-		w.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
-
-		if (w instanceof JDialog) {
-			// JDialog.setModal must be unset additionally.
-			JDialog d = (JDialog) w;
-			d.setModal(false);
-		}
-
-		w.setVisible(true);
-		int countWait = 0;
-		while (w.isVisible() && !stopFlag.get()) {
-			LangUtil.sleepExceptionless(100);
-			if (waitMax >= 0 && countWait++ > waitMax * 10) {
-				// waitMax < 0 will never brake the waiting and never increase
-				// the countWait
-				break;
-			}
-		}
-		w.dispose();
-
-		if (stopFlag.get()) {
-			throw err.get();
-		}
-
+		return equals;
 	}
 
-	public static void testGui(Component gui, int waitMax) throws Throwable {
-		testGui(gui, gui.getClass().getSimpleName(), waitMax);
-	}
-
-	public static void testGui(Image image, int waitMax) throws Throwable {
-
-		if (GraphicsEnvironment.isHeadless())
-			return;
-
-		JLabel imgLabel = new JLabel(new ImageIcon(image));
-		testGui(imgLabel, imgLabel.getClass().getSimpleName(), waitMax);
-	}
-
 	/**
 	 * Checks whether an image has a specific color/transparency at a special
 	 * pixel position.
@@ -178,22 +117,6 @@
 
 	}
 
-	private static boolean checkPixel(BufferedImage bi, int x, int y,
-			Color expected) {
-		final int rgb = bi.getRGB(x, y);
-
-		final Color found = new Color(rgb, true);
-
-		final boolean equals = expected.equals(found);
-
-		if (!equals) {
-			System.err.println("At pixel (" + x + "/" + y + ") expected "
-					+ expected + " but found " + found);
-		}
-
-		return equals;
-	}
-
 	public static boolean checkPixel(BufferedImage bi, int x, int y,
 			int... colorParts) {
 
@@ -210,36 +133,6 @@
 		return checkPixel(bi, x, y, expectedColor);
 	}
 
-	public static void testGui(JPanel jPanel, String title) throws Throwable {
-		testGui(jPanel, title, 3);
-	}
-
-	public static void testGui(Component gui) throws Throwable {
-		testGui(gui, WAIT_MAX_DEFAULT);
-	}
-
-	public static BufferedImage visualize(DefaultMapLayer dml) throws Throwable {
-		DefaultMapContext mc = new DefaultMapContext(dml.getFeatureSource()
-				.getSchema().getCoordinateReferenceSystem());
-
-		mc.addLayer(dml);
-
-		StreamingRenderer sr = new StreamingRenderer();
-		sr.setContext(mc);
-
-		final BufferedImage bi = new BufferedImage(100, 100,
-				BufferedImage.TYPE_4BYTE_ABGR);
-		Graphics2D g2d = bi.createGraphics();
-		ReferencedEnvelope geoArea = new ReferencedEnvelope(dml
-				.getFeatureSource().getBounds());
-		sr.paint(g2d, new Rectangle(100, 100), geoArea);
-		g2d.dispose();
-
-		TestingUtil.testGui(bi, 1);
-
-		return bi;
-	}
-
 	/**
 	 * Takes a URL to a shapefile, that may be inside a jar. The retuned UTL
 	 * points to a version of the shapefile copied to the tmp dir.
@@ -291,9 +184,31 @@
 		return DataUtilities.fileToURL(new File(tempDir, fileName));
 	}
 
-	final static String resLocation_Kreise = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
-	final static String resLocation_ArabicHeader = "/schmitzm/geotools/feature/arabicShapefiles/arabicwitharabicinheader.shp";
+	/**
+	 * Returns the percentage of the possible maximum head size used (0 to 100)
+	 */
+	public static double getHeapUsedPercentageOfMax() {
 
+		// Get current size of heap in bytes
+		long heapSize = Runtime.getRuntime().totalMemory();
+
+		// Get maximum size of heap in bytes. The heap cannot grow beyond this
+		// size.
+		// Any attempt will result in an OutOfMemoryException.
+		long heapMaxSize = Runtime.getRuntime().maxMemory();
+
+		// Get amount of free memory within the heap in bytes. This size will
+		// increase
+		// after garbage collection and decrease as new objects are created.
+		long heapFreeSize = Runtime.getRuntime().freeMemory();
+
+		long used = (heapSize - heapFreeSize);
+
+		double perc = (used * 100. / heapMaxSize);
+
+		return perc;
+	}
+
 	/**
 	 * Stellt Test-Features zur Verfügung, WENN die Anwendung im maven scope
 	 * <code>test</code> läuft.
@@ -356,6 +271,94 @@
 		return fs;
 	}
 
+	public static boolean isInteractive() {
+		return INTERACTIVE;
+	}
+
+	public static void testGui(Component gui) throws Throwable {
+		testGui(gui, WAIT_MAX_DEFAULT);
+	}
+
+	public static void testGui(Component gui, int waitMax) throws Throwable {
+		testGui(gui, gui.getClass().getSimpleName(), waitMax);
+	}
+
+	/**
+	 * Opens a {@link JFrame} and shows the passed {@link JComponent}. If a
+	 * {@link ExceptionDialog} is opens in the GUI, an exception is thrown.<br/>
+	 * The test is skipped if the JVM is running headless.
+	 * 
+	 * @param gui
+	 * @param title
+	 *            can be used to explain the tests what to check
+	 * @param waitMax
+	 *            Maximum seconds to wait until the GUI should automatically
+	 *            close, set -1 for unlimieted
+	 */
+	public static void testGui(Component gui, String title, int waitMax)
+			throws Throwable {
+
+		if (GraphicsEnvironment.isHeadless())
+			return;
+
+		final AtomicBoolean stopFlag = new AtomicBoolean(false);
+
+		final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
+
+		ExceptionDialog.addListener(new ActionListener() {
+
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				err.set((Throwable) e.getSource());
+				stopFlag.set(true);
+			}
+		});
+
+		Window w = null;
+		if (gui instanceof Window) {
+			w = (Window) gui;
+		} else if (gui instanceof JComponent) {
+			JFrame f = new JFrame(title);
+			f.setContentPane((JComponent) gui);
+			f.pack();
+			w = f;
+		}
+
+		// If it is a modal dialog, unmodalize it
+		w.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
+
+		if (w instanceof JDialog) {
+			// JDialog.setModal must be unset additionally.
+			JDialog d = (JDialog) w;
+			d.setModal(false);
+		}
+
+		w.setVisible(true);
+		int countWait = 0;
+		while (w.isVisible() && !stopFlag.get()) {
+			LangUtil.sleepExceptionless(100);
+			if (waitMax >= 0 && countWait++ > waitMax * 10) {
+				// waitMax < 0 will never brake the waiting and never increase
+				// the countWait
+				break;
+			}
+		}
+		w.dispose();
+
+		if (stopFlag.get()) {
+			throw err.get();
+		}
+	}
+
+	public static void testGui(Image image, int waitMax) throws Throwable {
+
+		if (GraphicsEnvironment.isHeadless())
+			return;
+
+		JLabel imgLabel = new JLabel(new ImageIcon(image));
+		testGui(imgLabel, imgLabel.getClass().getSimpleName(), waitMax);
+	}
+
 	public static void testGui(JFreeChart chart, String frameTitle)
 			throws Throwable {
 		testGui(chart, frameTitle, WAIT_MAX_DEFAULT);
@@ -371,33 +374,30 @@
 		}
 	}
 
-	/**
-	 * Returns the percentage of the possible maximum head size used (0 to 100)
-	 */
-	public static double getHeapUsedPercentageOfMax() {
+	public static void testGui(JPanel jPanel, String title) throws Throwable {
+		testGui(jPanel, title, 3);
+	}
 
-		// Get current size of heap in bytes
-		long heapSize = Runtime.getRuntime().totalMemory();
+	public static BufferedImage visualize(DefaultMapLayer dml) throws Throwable {
+		DefaultMapContext mc = new DefaultMapContext(dml.getFeatureSource()
+				.getSchema().getCoordinateReferenceSystem());
 
-		// Get maximum size of heap in bytes. The heap cannot grow beyond this
-		// size.
-		// Any attempt will result in an OutOfMemoryException.
-		long heapMaxSize = Runtime.getRuntime().maxMemory();
+		mc.addLayer(dml);
 
-		// Get amount of free memory within the heap in bytes. This size will
-		// increase
-		// after garbage collection and decrease as new objects are created.
-		long heapFreeSize = Runtime.getRuntime().freeMemory();
+		StreamingRenderer sr = new StreamingRenderer();
+		sr.setContext(mc);
 
-		long used = (heapSize - heapFreeSize);
+		final BufferedImage bi = new BufferedImage(100, 100,
+				BufferedImage.TYPE_4BYTE_ABGR);
+		Graphics2D g2d = bi.createGraphics();
+		ReferencedEnvelope geoArea = new ReferencedEnvelope(dml
+				.getFeatureSource().getBounds());
+		sr.paint(g2d, new Rectangle(100, 100), geoArea);
+		g2d.dispose();
 
-		double perc = (used * 100. / heapMaxSize);
+		TestingUtil.testGui(bi, 1);
 
-		return perc;
+		return bi;
 	}
 
-	public static boolean isInteractive() {
-		return INTERACTIVE;
-	}
-
 }



More information about the Schmitzm-commits mailing list