You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by me...@apache.org on 2012/07/26 11:33:20 UTC
svn commit: r1365925 [1/2] - in
/xmlgraphics/commons/branches/Temp_URI_Resolution: ./
src/java/org/apache/xmlgraphics/ps/ test/java/org/apache/xmlgraphics/
test/java/org/apache/xmlgraphics/fonts/
test/java/org/apache/xmlgraphics/image/codec/png/ test/j...
Author: mehdi
Date: Thu Jul 26 09:33:18 2012
New Revision: 1365925
URL: http://svn.apache.org/viewvc?rev=1365925&view=rev
Log:
Merged in trunk@1365922.
Added:
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/fonts/GlyphsTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/fonts/GlyphsTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/codec/png/CodecResourcesTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/codec/png/CodecResourcesTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/codec/png/PNGEncoderTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/codec/png/PNGEncoderTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistryTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistryTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/color/ColorConverterTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/color/ColorConverterTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternativesTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternativesTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/ClasspathResourceTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ClasspathResourceTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/ServiceTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/ServiceTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/xmp/XMPParserTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPParserTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTestCase.java
- copied unchanged from r1365922, xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTestCase.java
Removed:
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/fonts/GlyphsTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/codec/png/CodecResourcesTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/codec/png/PNGEncoderTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/writer/ImageWriterRegistryTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/color/ColorConverterTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/color/ColorWithAlternativesTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/ClasspathResourceTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/DoubleFormatUtilTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/ServiceTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/io/Base64Test.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/xmp/XMPParserTest.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/xmp/XMPPropertyTest.java
Modified:
xmlgraphics/commons/branches/Temp_URI_Resolution/ (props changed)
xmlgraphics/commons/branches/Temp_URI_Resolution/build.xml
xmlgraphics/commons/branches/Temp_URI_Resolution/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java
xmlgraphics/commons/branches/Temp_URI_Resolution/status.xml
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/StandardTestSuite.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePreloaderTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageSessionContextTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageUtilTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ObservableStream.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PenaltyTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PipelineFactoryTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/SimpleURIResolverBasedImageSessionContext.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/DefaultExpirationPolicyTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawCCITTFaxTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/mocks/MockImageLoaderFactoryTIFF.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/HexUtil.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/io/SubInputStreamTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/uri/CommonURIResolverTestCase.java
xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java
Propchange: xmlgraphics/commons/branches/Temp_URI_Resolution/
------------------------------------------------------------------------------
Merged /xmlgraphics/commons/trunk:r1365078-1365922
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/build.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/build.xml?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/build.xml (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/build.xml Thu Jul 26 09:33:18 2012
@@ -52,6 +52,7 @@
<property name="build.dir" value="${basedir}/build"/>
<property name="build.classes.dir" value="${build.dir}/classes"/>
<property name="build.javadocs.dir" value="${build.dir}/javadocs"/>
+ <property name="build.unit.tests.dir" value="${basedir}/test/java"/>
<property name="dist.bin.dir" value="${basedir}/dist-bin"/>
<property name="dist.src.dir" value="${basedir}/dist-src"/>
@@ -293,7 +294,7 @@
debug="${javac.debug}" deprecation="${javac.deprecation}"
optimize="${javac.optimize}" source="${javac.source}"
target="${javac.target}" includeAntRuntime="true">
- <src path="${basedir}/test/java"/>
+ <src path="${build.unit.tests.dir}"/>
<patternset refid="compile-pattern"/>
<classpath>
<path refid="libs-build-classpath"/>
@@ -304,7 +305,7 @@
</javac>
<copy todir="${build.dir}/test-classes" includeEmptyDirs="false">
<fileset dir="${basedir}/test/resources"/>
- <fileset dir="${basedir}/test/java">
+ <fileset dir="${build.unit.tests.dir}">
<exclude name="**/*.java"/>
<exclude name="**/*.html"/>
</fileset>
@@ -327,7 +328,7 @@
</fileset>
</classpath>
<batchtest fork="${junit.fork}" todir="${build.dir}/test-reports">
- <fileset dir="${basedir}/test/java">
+ <fileset dir="${build.unit.tests.dir}">
<include name="**/*Test*.java"/>
<exclude name="**/*TestSuite.java"/>
<exclude name="**/image/writer/internal/TIFFImageWriter*.java" if="internal-codecs.eff.disabled"/>
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java Thu Jul 26 09:33:18 2012
@@ -20,10 +20,12 @@
package org.apache.xmlgraphics.ps;
import java.awt.color.ColorSpace;
+import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
+import java.awt.image.DirectColorModel;
import java.awt.image.IndexColorModel;
import java.awt.image.PixelInterleavedSampleModel;
import java.awt.image.Raster;
@@ -31,6 +33,7 @@ import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
import org.apache.xmlgraphics.image.GraphicsUtil;
@@ -111,6 +114,10 @@ public class ImageEncodingHelper {
}
private void writeRGBTo(OutputStream out) throws IOException {
+ boolean encoded = encodeRenderedImageWithDirectColorModelAsRGB(image, out);
+ if (encoded) {
+ return;
+ }
encodeRenderedImageAsRGB(image, out);
}
@@ -122,7 +129,7 @@ public class ImageEncodingHelper {
*/
public static void encodeRenderedImageAsRGB(RenderedImage image, OutputStream out)
throws IOException {
- Raster raster = image.getData();
+ Raster raster = getRaster(image);
Object data;
int nbands = raster.getNumBands();
int dataType = raster.getDataBuffer().getDataType();
@@ -143,13 +150,13 @@ public class ImageEncodingHelper {
data = new double[nbands];
break;
default:
- throw new IllegalArgumentException("Unknown data buffer type: "
- + dataType);
+ throw new IllegalArgumentException("Unknown data buffer type: " + dataType);
}
ColorModel colorModel = image.getColorModel();
int w = image.getWidth();
int h = image.getHeight();
+
byte[] buf = new byte[w * 3];
for (int y = 0; y < h; y++) {
int idx = -1;
@@ -164,6 +171,67 @@ public class ImageEncodingHelper {
}
/**
+ * Writes a RenderedImage to an OutputStream. This method optimizes the encoding
+ * of the {@link DirectColorModel} as it is returned by {@link ColorModel#getRGBdefault}.
+ * @param image the image
+ * @param out the OutputStream to write the pixels to
+ * @return true if this method encoded this image, false if the image is incompatible
+ * @throws IOException if an I/O error occurs
+ */
+ public static boolean encodeRenderedImageWithDirectColorModelAsRGB(
+ RenderedImage image, OutputStream out) throws IOException {
+ ColorModel cm = image.getColorModel();
+ if (cm.getColorSpace() != ColorSpace.getInstance(ColorSpace.CS_sRGB)) {
+ return false; //Need to go through color management
+ }
+ if (!(cm instanceof DirectColorModel)) {
+ return false; //Only DirectColorModel is supported here
+ }
+ DirectColorModel dcm = (DirectColorModel)cm;
+ final int[] templateMasks = new int[]
+ {0x00ff0000 /*R*/, 0x0000ff00 /*G*/, 0x000000ff /*B*/, 0xff000000 /*A*/};
+ int[] masks = dcm.getMasks();
+ if (!Arrays.equals(templateMasks, masks)) {
+ return false; //no flexibility here right now, might never be used anyway
+ }
+
+ Raster raster = getRaster(image);
+ int dataType = raster.getDataBuffer().getDataType();
+ if (dataType != DataBuffer.TYPE_INT) {
+ return false; //not supported
+ }
+
+ int w = image.getWidth();
+ int h = image.getHeight();
+
+ int[] data = new int[w];
+ byte[] buf = new byte[w * 3];
+ for (int y = 0; y < h; y++) {
+ int idx = -1;
+ raster.getDataElements(0, y, w, 1, data);
+ for (int x = 0; x < w; x++) {
+ int rgb = data[x];
+ buf[++idx] = (byte)(rgb >> 16);
+ buf[++idx] = (byte)(rgb >> 8);
+ buf[++idx] = (byte)(rgb);
+ }
+ out.write(buf);
+ }
+
+ return true;
+ }
+
+ private static Raster getRaster(RenderedImage image) {
+ if (image instanceof BufferedImage) {
+ return ((BufferedImage)image).getRaster();
+ } else {
+ //Note: this copies the image data (double memory consumption)
+ //TODO Investigate encoding in stripes: RenderedImage.copyData(WritableRaster)
+ return image.getData();
+ }
+ }
+
+ /**
* Converts a byte array containing 24 bit RGB image data to a grayscale
* image.
*
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/status.xml?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/status.xml (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/status.xml Thu Jul 26 09:33:18 2012
@@ -27,6 +27,7 @@
<person name="Adrian Cumiskey" email="acumiskey@apache.org" id="AC"/>
<person name="Christian Geisert" email="chrisg@apache.org" id="CG"/>
<person name="Vincent Hennebert" email="vhennebert@apache.org" id="VH"/>
+ <person name="Mehdi Houshmand" email="mehdi@apache.org" id="MH"/>
<person name="Clay Leeds" email="clay@apache.org" id="CL"/>
<person name="Jeremias Märki" email="jeremias@apache.org" id="JM"/>
<person name="Cameron McCormack" email="cam@apache.org" id="CM"/>
@@ -41,6 +42,12 @@
</contexts>
<changes>
<release version="Trunk" date="n/a">
+ <action context="Code" dev="MH" type="update">
+ Updated the JUnit tests to JUnit v4.
+ </action>
+ <action context="Code" dev="MH" type="fix" fixes-bug="53599" due-to="JM and MH collaboration">
+ Performance improvement of DirectColorMode bitmap images
+ </action>
<action context="Code" dev="MH" type="fix" fixes-bug="53570" due-to="Robert Meyer">
Set the systemID of the StreamSource within the DataURIResolver
</action>
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/StandardTestSuite.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/StandardTestSuite.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/StandardTestSuite.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/StandardTestSuite.java Thu Jul 26 09:33:18 2012
@@ -19,46 +19,40 @@
package org.apache.xmlgraphics;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-import org.apache.xmlgraphics.image.codec.png.PNGEncoderTest;
+import org.apache.xmlgraphics.image.codec.png.PNGEncoderTestCase;
+import org.apache.xmlgraphics.ps.ImageEncodingHelperTestCase;
import org.apache.xmlgraphics.ps.PSEscapeTestCase;
import org.apache.xmlgraphics.ps.dsc.ListenerTestCase;
import org.apache.xmlgraphics.ps.dsc.events.DSCValueParserTestCase;
import org.apache.xmlgraphics.ps.dsc.tools.DSCToolsTestCase;
-import org.apache.xmlgraphics.util.ClasspathResourceTest;
-import org.apache.xmlgraphics.util.ServiceTest;
+import org.apache.xmlgraphics.util.ClasspathResourceTestCase;
+import org.apache.xmlgraphics.util.ServiceTestCase;
import org.apache.xmlgraphics.util.UnitConvTestCase;
import org.apache.xmlgraphics.util.io.ASCII85InputStreamTestCase;
import org.apache.xmlgraphics.util.io.ASCII85OutputStreamTestCase;
-import org.apache.xmlgraphics.util.io.Base64Test;
+import org.apache.xmlgraphics.util.io.Base64TestCase;
/**
* Test suite for basic functionality of XML Graphics Commons.
*/
+@RunWith(Suite.class)
+@SuiteClasses({
+ Base64TestCase.class,
+ ASCII85InputStreamTestCase.class,
+ ASCII85OutputStreamTestCase.class,
+ PNGEncoderTestCase.class,
+ ServiceTestCase.class,
+ ClasspathResourceTestCase.class,
+ PSEscapeTestCase.class,
+ ImageEncodingHelperTestCase.class,
+ DSCValueParserTestCase.class,
+ DSCToolsTestCase.class,
+ ListenerTestCase.class,
+ UnitConvTestCase.class
+})
public class StandardTestSuite {
-
- /**
- * Builds the test suite
- * @return the test suite
- */
- public static Test suite() {
- TestSuite suite = new TestSuite(
- "Basic functionality test suite for XML Graphics Commons");
- //$JUnit-BEGIN$
- suite.addTest(new TestSuite(Base64Test.class));
- suite.addTest(new TestSuite(ASCII85InputStreamTestCase.class));
- suite.addTest(new TestSuite(ASCII85OutputStreamTestCase.class));
- suite.addTest(new TestSuite(PNGEncoderTest.class));
- suite.addTest(new TestSuite(ServiceTest.class));
- suite.addTest(new TestSuite(ClasspathResourceTest.class));
- suite.addTest(new TestSuite(PSEscapeTestCase.class));
- suite.addTest(new TestSuite(DSCValueParserTestCase.class));
- suite.addTest(new TestSuite(DSCToolsTestCase.class));
- suite.addTest(new TestSuite(ListenerTestCase.class));
- suite.addTest(new TestSuite(UnitConvTestCase.class));
- //$JUnit-END$
- return suite;
- }
}
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/CorruptImagesTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,19 +19,19 @@
package org.apache.xmlgraphics.image.loader;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
/**
* Tests for error behaviour with corrupt images.
*/
-public class CorruptImagesTestCase extends TestCase {
+public class CorruptImagesTestCase {
private MockImageContext imageContext = MockImageContext.getInstance();
- public CorruptImagesTestCase(String name) {
- super(name);
- }
-
+ @Test
public void testCorruptPNG() throws Exception {
String uri = "corrupt-image.png";
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageFlavorTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,17 +19,24 @@
package org.apache.xmlgraphics.image.loader;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.apache.xmlgraphics.util.MimeConstants;
/**
* Tests for image flavors.
*/
-public class ImageFlavorTestCase extends TestCase {
+public class ImageFlavorTestCase {
+ @Test
public void testBasicFlavors() throws Exception {
- ImageFlavor f1, f2;
+ ImageFlavor f1;
+ ImageFlavor f2;
f1 = ImageFlavor.RAW_JPEG;
f2 = ImageFlavor.RAW_PNG;
@@ -46,8 +53,10 @@ public class ImageFlavorTestCase extends
assertNull(f1.getNamespace());
}
+ @Test
public void testRefinedFlavors() throws Exception {
- ImageFlavor f1, f2;
+ ImageFlavor f1;
+ ImageFlavor f2;
f1 = ImageFlavor.RENDERED_IMAGE;
f2 = ImageFlavor.BUFFERED_IMAGE;
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java Thu Jul 26 09:33:18 2012
@@ -31,7 +31,11 @@ import javax.imageio.stream.ImageInputSt
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
import org.apache.commons.io.IOUtils;
@@ -46,18 +50,15 @@ import org.apache.xmlgraphics.image.load
/**
* Tests for bundled ImageLoader implementations.
*/
-public class ImageLoaderTestCase extends TestCase {
+public class ImageLoaderTestCase {
private MockImageContext imageContext = MockImageContext.getInstance();
- public ImageLoaderTestCase(String name) {
- super(name);
- }
-
private MyImageSessionContext createImageSessionContext() {
return new MyImageSessionContext(imageContext);
}
+ @Test
public void testPNG() throws Exception {
String uri = "asf-logo.png";
@@ -70,7 +71,7 @@ public class ImageLoaderTestCase extends
Image img = manager.getImage(info, ImageFlavor.RENDERED_IMAGE, sessionContext);
assertNotNull("Image must not be null", img);
assertEquals(ImageFlavor.RENDERED_IMAGE, img.getFlavor());
- ImageRendered imgRed = (ImageRendered)img;
+ ImageRendered imgRed = (ImageRendered) img;
assertNotNull(imgRed.getRenderedImage());
assertEquals(169, imgRed.getRenderedImage().getWidth());
assertEquals(51, imgRed.getRenderedImage().getHeight());
@@ -81,6 +82,7 @@ public class ImageLoaderTestCase extends
sessionContext.checkAllStreamsClosed();
}
+ @Test
public void testGIF() throws Exception {
String uri = "bgimg72dpi.gif";
@@ -93,7 +95,7 @@ public class ImageLoaderTestCase extends
Image img = manager.getImage(info, ImageFlavor.RENDERED_IMAGE, sessionContext);
assertNotNull("Image must not be null", img);
assertEquals(ImageFlavor.RENDERED_IMAGE, img.getFlavor());
- ImageRendered imgRed = (ImageRendered)img;
+ ImageRendered imgRed = (ImageRendered) img;
assertNotNull(imgRed.getRenderedImage());
assertEquals(192, imgRed.getRenderedImage().getWidth());
assertEquals(192, imgRed.getRenderedImage().getHeight());
@@ -104,6 +106,7 @@ public class ImageLoaderTestCase extends
sessionContext.checkAllStreamsClosed();
}
+ @Test
public void testEPSASCII() throws Exception {
String uri = "barcode.eps";
@@ -116,7 +119,7 @@ public class ImageLoaderTestCase extends
Image img = manager.getImage(info, ImageFlavor.RAW_EPS, sessionContext);
assertNotNull("Image must not be null", img);
assertEquals(ImageFlavor.RAW_EPS, img.getFlavor());
- ImageRawStream imgEPS = (ImageRawStream)img;
+ ImageRawStream imgEPS = (ImageRawStream) img;
InputStream in = imgEPS.createInputStream();
try {
assertNotNull(in);
@@ -133,6 +136,7 @@ public class ImageLoaderTestCase extends
sessionContext.checkAllStreamsClosed();
}
+ @Test
public void testEPSBinary() throws Exception {
String uri = "img-with-tiff-preview.eps";
@@ -145,7 +149,7 @@ public class ImageLoaderTestCase extends
Image img = manager.getImage(info, ImageFlavor.RAW_EPS, sessionContext);
assertNotNull("Image must not be null", img);
assertEquals(ImageFlavor.RAW_EPS, img.getFlavor());
- ImageRawStream imgEPS = (ImageRawStream)img;
+ ImageRawStream imgEPS = (ImageRawStream) img;
InputStream in = imgEPS.createInputStream();
try {
assertNotNull(in);
@@ -162,19 +166,20 @@ public class ImageLoaderTestCase extends
sessionContext.checkAllStreamsClosed();
}
+ @Test
public void testICCProfiles() throws Exception {
MyImageSessionContext sessionContext = createImageSessionContext();
- List/* <ICC_Profile> */profiles = new ArrayList();
+ List<ICC_Profile> profiles = new ArrayList<ICC_Profile>();
runReaders(profiles, sessionContext, "iccTest.png", "image/png",
ImageFlavor.RAW_PNG);
runReaders(profiles, sessionContext, "iccTest.jpg", "image/jpeg",
ImageFlavor.RAW_JPEG);
- ICC_Profile first = (ICC_Profile) profiles.get(0);
+ ICC_Profile first = profiles.get(0);
byte[] firstData = first.getData();
for (int i = 1; i < profiles.size(); i++) {
- ICC_Profile icc = (ICC_Profile) profiles.get(i);
+ ICC_Profile icc = profiles.get(i);
byte[] data = icc.getData();
assertEquals("Embedded ICC Profiles are not the same size!",
firstData.length, data.length);
@@ -184,10 +189,10 @@ public class ImageLoaderTestCase extends
}
}
}
-
- private void runReaders(List profiles, ImageSessionContext isc, String uri,
+
+ private void runReaders(List<ICC_Profile> profiles, ImageSessionContext isc, String uri,
String mime, ImageFlavor rawFlavor) throws Exception {
- ImageLoaderFactory ilfs[] = ImageImplRegistry.getDefaultInstance()
+ ImageLoaderFactory[] ilfs = ImageImplRegistry.getDefaultInstance()
.getImageLoaderFactories(mime);
if (ilfs != null) {
for (int i = 0; i < ilfs.length; i++) {
@@ -222,6 +227,7 @@ public class ImageLoaderTestCase extends
}
}
+ @Test
public void testBrokenIccPng() throws Exception {
String uri = "corrupt-icc.png";
@@ -234,7 +240,7 @@ public class ImageLoaderTestCase extends
Image img = manager.getImage(info, ImageFlavor.RENDERED_IMAGE, sessionContext);
assertNotNull("Image must not be null", img);
assertEquals(ImageFlavor.RENDERED_IMAGE, img.getFlavor());
- ImageRendered imgRed = (ImageRendered)img;
+ ImageRendered imgRed = (ImageRendered) img;
assertNotNull(imgRed.getRenderedImage());
assertEquals(400, imgRed.getRenderedImage().getWidth());
assertEquals(300, imgRed.getRenderedImage().getHeight());
@@ -253,7 +259,7 @@ public class ImageLoaderTestCase extends
public Source newSource(String uri) {
Source src = super.newSource(uri);
if (src instanceof ImageSource) {
- ImageSource is = (ImageSource)src;
+ ImageSource is = (ImageSource) src;
ImageInputStream in = is.getImageInputStream();
//in = new ObservableImageInputStream(in, is.getSystemId());
in = ObservableStream.Factory.observe(in, is.getSystemId());
@@ -267,7 +273,7 @@ public class ImageLoaderTestCase extends
protected Source resolveURI(String uri) {
Source src = super.resolveURI(uri);
if (src instanceof StreamSource) {
- StreamSource ss = (StreamSource)src;
+ StreamSource ss = (StreamSource) src;
if (ss.getInputStream() != null) {
InputStream in = new ObservableInputStream(
ss.getInputStream(), ss.getSystemId());
@@ -281,7 +287,7 @@ public class ImageLoaderTestCase extends
public void checkAllStreamsClosed() {
Iterator iter = streams.iterator();
while (iter.hasNext()) {
- ObservableStream stream = (ObservableStream)iter.next();
+ ObservableStream stream = (ObservableStream) iter.next();
iter.remove();
if (!stream.isClosed()) {
fail(stream.getClass().getName() + " is NOT closed: " + stream.getSystemID());
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePipelineTestCase.java Thu Jul 26 09:33:18 2012
@@ -21,7 +21,12 @@ package org.apache.xmlgraphics.image.loa
import java.awt.Dimension;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.apache.xmlgraphics.image.loader.impl.ImageConverterBuffered2Rendered;
import org.apache.xmlgraphics.image.loader.impl.ImageConverterG2D2Bitmap;
@@ -37,14 +42,11 @@ import org.apache.xmlgraphics.util.MimeC
/**
* Tests for the image pipeline functionality.
*/
-public class ImagePipelineTestCase extends TestCase {
+public class ImagePipelineTestCase {
private MockImageContext imageContext = MockImageContext.getInstance();
- public ImagePipelineTestCase(String name) {
- super(name);
- }
-
+ @Test
public void testPipelineWithLoader() throws Exception {
String uri = "bgimg72dpi.gif";
@@ -68,6 +70,7 @@ public class ImagePipelineTestCase exten
assertEquals(MimeConstants.MIME_PNG, img.getFlavor().getMimeType());
}
+ @Test
public void testPipelineWithoutLoader() throws Exception {
ImageSessionContext sessionContext = imageContext.newSessionContext();
@@ -107,6 +110,7 @@ public class ImagePipelineTestCase exten
return g2dImage;
}
+ @Test
public void testPipelineFromURIThroughManager() throws Exception {
String uri = "asf-logo.png";
@@ -126,6 +130,7 @@ public class ImagePipelineTestCase exten
assertTrue(img instanceof ImageRawStream);
}
+ @Test
public void testPipelineWithoutURIThroughManager() throws Exception {
ImageManager manager = imageContext.getImageManager();
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePreloaderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePreloaderTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePreloaderTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImagePreloaderTestCase.java Thu Jul 26 09:33:18 2012
@@ -28,24 +28,24 @@ import javax.xml.transform.TransformerEx
import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXSource;
-import junit.framework.TestCase;
-
+import org.junit.Test;
import org.xml.sax.InputSource;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
import org.apache.xmlgraphics.image.loader.spi.ImageLoaderFactory;
import org.apache.xmlgraphics.util.MimeConstants;
/**
* Tests for bundled Imagepreloader implementations.
*/
-public class ImagePreloaderTestCase extends TestCase {
+public class ImagePreloaderTestCase {
private MockImageContext imageContext = MockImageContext.getInstance();
- public ImagePreloaderTestCase(String name) {
- super(name);
- }
-
+ @Test
public void testImageLoaderFactory() throws Exception {
ImageManager manager = imageContext.getImageManager();
ImageInfo info = new ImageInfo(null, MimeConstants.MIME_PNG);
@@ -54,19 +54,21 @@ public class ImagePreloaderTestCase exte
assertNotNull(ilf);
}
+ @Test
public void testFileNotFound() throws Exception {
String uri = "doesnotexistanywhere.png";
ImageSessionContext sessionContext = imageContext.newSessionContext();
ImageManager manager = imageContext.getImageManager();
try {
- ImageInfo info = manager.preloadImage(uri, sessionContext);
+ manager.preloadImage(uri, sessionContext);
fail("Expected a FileNotFoundException!");
} catch (FileNotFoundException e) {
//expected!
}
}
+ @Test
public void testPNG() throws Exception {
String uri = "asf-logo.png";
@@ -84,6 +86,7 @@ public class ImagePreloaderTestCase exte
assertEquals(38245, info.getSize().getHeightMpt());
}
+ @Test
public void testPNGNoResolution() throws Exception {
String uri = "no-resolution.png";
//This file contains a pHYs chunk but the resolution is set to zero.
@@ -104,6 +107,7 @@ public class ImagePreloaderTestCase exte
assertEquals(24000, info.getSize().getHeightMpt());
}
+ @Test
public void testTIFF() throws Exception {
String uri = "tiff_group4.tif";
@@ -121,6 +125,7 @@ public class ImagePreloaderTestCase exte
assertEquals(66706, info.getSize().getHeightMpt());
}
+ @Test
public void testTIFFNoResolution() throws Exception {
String uri = "no-resolution.tif";
@@ -138,6 +143,7 @@ public class ImagePreloaderTestCase exte
assertEquals(24000, info.getSize().getHeightMpt());
}
+ @Test
public void testGIF() throws Exception {
String uri = "bgimg72dpi.gif";
@@ -155,6 +161,7 @@ public class ImagePreloaderTestCase exte
assertEquals(192000, info.getSize().getHeightMpt());
}
+ @Test
public void testEMF() throws Exception {
String uri = "img.emf";
@@ -172,6 +179,7 @@ public class ImagePreloaderTestCase exte
assertEquals(56665, info.getSize().getHeightMpt());
}
+ @Test
public void testJPEG1() throws Exception {
String uri = "bgimg300dpi.jpg";
@@ -189,6 +197,7 @@ public class ImagePreloaderTestCase exte
assertEquals(46080, info.getSize().getHeightMpt());
}
+ @Test
public void testJPEG2() throws Exception {
String uri = "cmyk.jpg";
@@ -206,6 +215,7 @@ public class ImagePreloaderTestCase exte
assertEquals(35000, info.getSize().getHeightMpt());
}
+ @Test
public void testJPEG3() throws Exception {
String uri = "cmyk-pxcm.jpg"; //Contains resolution as pixels per centimeter
@@ -223,6 +233,7 @@ public class ImagePreloaderTestCase exte
assertEquals(35433, info.getSize().getHeightMpt());
}
+ @Test
public void testBMP() throws Exception {
String uri = "bgimg300dpi.bmp";
@@ -240,6 +251,7 @@ public class ImagePreloaderTestCase exte
assertEquals(46092, info.getSize().getHeightMpt());
}
+ @Test
public void testBMPNoResolution() throws Exception {
String uri = "no-resolution.bmp";
@@ -257,6 +269,7 @@ public class ImagePreloaderTestCase exte
assertEquals(50000, info.getSize().getHeightMpt());
}
+ @Test
public void testEPSAscii() throws Exception {
String uri = "barcode.eps";
@@ -274,6 +287,7 @@ public class ImagePreloaderTestCase exte
assertEquals(42525, info.getSize().getHeightMpt());
}
+ @Test
public void testEPSBinary() throws Exception {
String uri = "img-with-tiff-preview.eps";
@@ -291,6 +305,7 @@ public class ImagePreloaderTestCase exte
assertEquals(17000, info.getSize().getHeightMpt());
}
+ @Test
public void testSAXSourceWithSystemID() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -306,6 +321,7 @@ public class ImagePreloaderTestCase exte
checkImageFound("img:asf-logo.png", resolver);
}
+ @Test
public void testSAXSourceWithInputStream() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageSessionContextTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageSessionContextTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageSessionContextTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageSessionContextTestCase.java Thu Jul 26 09:33:18 2012
@@ -34,24 +34,24 @@ import javax.xml.transform.dom.DOMSource
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
-import junit.framework.TestCase;
-
+import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import org.apache.xmlgraphics.image.loader.util.ImageUtil;
/**
* Tests for AbstractImageSessionContext.
*/
-public class ImageSessionContextTestCase extends TestCase {
+public class ImageSessionContextTestCase {
private MockImageContext imageContext = MockImageContext.getInstance();
- public ImageSessionContextTestCase(String name) {
- super(name);
- }
-
+ @Test
public void testStreamSourceWithSystemID() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -69,6 +69,7 @@ public class ImageSessionContextTestCase
assertTrue(imgSrc.isFastSource()); //Access through local file system
}
+ @Test
public void testStreamSourceWithInputStream() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -92,6 +93,7 @@ public class ImageSessionContextTestCase
assertTrue(!imgSrc.isFastSource());
}
+ @Test
public void testStreamSourceWithFile() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -110,6 +112,7 @@ public class ImageSessionContextTestCase
assertTrue(imgSrc.isFastSource()); //Accessed through the local file system
}
+ @Test
public void testStreamSourceWithInputStreamAndSystemID() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -135,6 +138,7 @@ public class ImageSessionContextTestCase
//being passed through by the URIResolver)
}
+ @Test
public void testStreamSourceWithReader() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -157,7 +161,7 @@ public class ImageSessionContextTestCase
Source src = resolve(uri, resolver);
assertNotNull("Source must not be null", src);
assertTrue("Source must be an ImageSource", src instanceof ImageSource);
- ImageSource imgSrc = (ImageSource)src;
+ ImageSource imgSrc = (ImageSource) src;
assertTrue(ImageUtil.hasImageInputStream(imgSrc));
return imgSrc;
}
@@ -169,6 +173,7 @@ public class ImageSessionContextTestCase
return src;
}
+ @Test
public void testSAXSourceWithSystemID() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -187,6 +192,7 @@ public class ImageSessionContextTestCase
assertTrue(imgSrc.isFastSource());
}
+ @Test
public void testSAXSourceWithInputStream() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -210,6 +216,7 @@ public class ImageSessionContextTestCase
checkImageInputStreamAvailable(uri, resolver);
}
+ @Test
public void testSAXSourceWithReader() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -232,6 +239,7 @@ public class ImageSessionContextTestCase
private static final String SOME_XML = "<root><child id='1'>Hello World!</child></root>";
+ @Test
public void testSAXSourceWithXMLReader() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -248,11 +256,12 @@ public class ImageSessionContextTestCase
Source src = resolve(uri, resolver);
assertTrue(src instanceof SAXSource); //Source remains unchanged
- SAXSource saxSrc = (SAXSource)src;
+ SAXSource saxSrc = (SAXSource) src;
assertNotNull(saxSrc.getXMLReader());
assertNotNull(saxSrc.getInputSource());
}
+ @Test
public void testDOMSource() throws Exception {
URIResolver resolver = new URIResolver() {
public Source resolve(String href, String base) throws TransformerException {
@@ -276,7 +285,7 @@ public class ImageSessionContextTestCase
Source src = resolve(uri, resolver);
assertTrue(src instanceof DOMSource); //Source remains unchanged
- DOMSource domSrc = (DOMSource)src;
+ DOMSource domSrc = (DOMSource) src;
assertNotNull(domSrc.getNode());
}
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageUtilTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageUtilTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageUtilTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ImageUtilTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,19 +19,24 @@
package org.apache.xmlgraphics.image.loader;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
import org.apache.xmlgraphics.image.loader.util.ImageUtil;
/**
* Tests for the ImageUtil class.
*/
-public class ImageUtilTestCase extends TestCase {
+public class ImageUtilTestCase {
/**
* Tests {@link ImageUtil.needPageIndexFromURI(String)}.
* @throws Exception if an error occurs
*/
+ @Test
public void testNeedPageIndex() throws Exception {
int pageIndex;
@@ -66,6 +71,7 @@ public class ImageUtilTestCase extends T
* Tests {@link ImageUtil.getPageIndexFromURI(String)}.
* @throws Exception if an error occurs
*/
+ @Test
public void testGetPageIndex() throws Exception {
Integer pageIndex;
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ObservableStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ObservableStream.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ObservableStream.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/ObservableStream.java Thu Jul 26 09:33:18 2012
@@ -49,7 +49,7 @@ public interface ObservableStream {
public static class Factory {
public static ImageInputStream observe(ImageInputStream iin, String systemID) {
- return (ImageInputStream)Proxy.newProxyInstance(
+ return (ImageInputStream) Proxy.newProxyInstance(
Factory.class.getClassLoader(),
new Class[] {ImageInputStream.class, ObservableStream.class},
new ObservingImageInputStreamInvocationHandler(iin, systemID));
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PenaltyTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PenaltyTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PenaltyTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PenaltyTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,19 +19,23 @@
package org.apache.xmlgraphics.image.loader;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import org.apache.xmlgraphics.image.loader.util.Penalty;
/**
* Tests for the {@link Penalty}.
*/
-public class PenaltyTestCase extends TestCase {
+public class PenaltyTestCase {
/**
* Tests for penalty handling.
* @throws Exception if an error occurs
*/
+ @Test
public void testTruncatePenalty() throws Exception {
assertEquals(0, Penalty.truncate(0));
long penalty = Integer.MAX_VALUE;
@@ -41,7 +45,7 @@ public class PenaltyTestCase extends Tes
penalty++;
assertEquals(Integer.MAX_VALUE, Penalty.truncate(penalty));
//For comparison, normal casting does this
- assertEquals(Integer.MIN_VALUE, (int)penalty);
+ assertEquals(Integer.MIN_VALUE, (int) penalty);
//Now on the other end of the spectrum...
penalty = Integer.MIN_VALUE;
@@ -51,13 +55,14 @@ public class PenaltyTestCase extends Tes
penalty -= 500;
assertEquals(Integer.MIN_VALUE, Penalty.truncate(penalty));
//For comparison, normal casting does this
- assertEquals(Integer.MAX_VALUE - 499, (int)penalty);
+ assertEquals(Integer.MAX_VALUE - 499, (int) penalty);
}
/**
* Tests for the {@link Penalty} class.
* @throws Exception if an error occurs
*/
+ @Test
public void testPenalty() throws Exception {
Penalty p1 = Penalty.toPenalty(100);
assertEquals(100, p1.getValue());
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PipelineFactoryTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PipelineFactoryTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PipelineFactoryTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/PipelineFactoryTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,7 +19,11 @@
package org.apache.xmlgraphics.image.loader;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
import org.apache.xmlgraphics.image.loader.impl.ImageLoaderRawCCITTFax;
@@ -32,12 +36,13 @@ import org.apache.xmlgraphics.image.load
/**
* Tests the pipeline factory.
*/
-public class PipelineFactoryTestCase extends TestCase {
+public class PipelineFactoryTestCase {
/**
* Tests the pipeline factory by checking to load a TIFF image.
* @throws Exception if an error occurs
*/
+ @Test
public void testPipelineFactoryPlain() throws Exception {
MockImageContext imageContext = MockImageContext.newSafeInstance();
ImageManager manager = imageContext.getImageManager();
@@ -96,6 +101,7 @@ public class PipelineFactoryTestCase ext
* Similar test as above but here we take raw CCITT loading into consideration, too.
* @throws Exception if an error occurs
*/
+ @Test
public void testPipelineFactoryImageInfoDependency() throws Exception {
MockImageContext imageContext = MockImageContext.newSafeInstance();
ImageManager manager = imageContext.getImageManager();
@@ -149,6 +155,7 @@ public class PipelineFactoryTestCase ext
* Similar test as above but now we're playing with additional penalties in the registry.
* @throws Exception if an error occurs
*/
+ @Test
public void testPipelineFactoryAdditionalPenalty() throws Exception {
MockImageContext imageContext = MockImageContext.newSafeInstance();
ImageManager manager = imageContext.getImageManager();
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/SimpleURIResolverBasedImageSessionContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/SimpleURIResolverBasedImageSessionContext.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/SimpleURIResolverBasedImageSessionContext.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/SimpleURIResolverBasedImageSessionContext.java Thu Jul 26 09:33:18 2012
@@ -56,5 +56,4 @@ public class SimpleURIResolverBasedImage
return null;
}
}
-
-}
\ No newline at end of file
+}
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/DefaultExpirationPolicyTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/DefaultExpirationPolicyTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/DefaultExpirationPolicyTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/DefaultExpirationPolicyTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,17 +19,22 @@
package org.apache.xmlgraphics.image.loader.cache;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
/**
* Tests {@link DefaultExpirationPolicy}.
*/
-public class DefaultExpirationPolicyTestCase extends TestCase {
+public class DefaultExpirationPolicyTestCase {
/**
* Never expire.
* @throws Exception if an error occurs
*/
+ @Test
public void testNeverExpire() throws Exception {
ExpirationPolicy policy;
policy = new DefaultExpirationPolicy(DefaultExpirationPolicy.EXPIRATION_NEVER);
@@ -46,6 +51,7 @@ public class DefaultExpirationPolicyTest
* Normal expiration
* @throws Exception if an error occurs
*/
+ @Test
public void testNormalExpiration() throws Exception {
ExpirationPolicy policy;
policy = new DefaultExpirationPolicy(2);
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/cache/ImageCacheTestCase.java Thu Jul 26 09:33:18 2012
@@ -21,7 +21,14 @@ package org.apache.xmlgraphics.image.loa
import java.io.FileNotFoundException;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.apache.xmlgraphics.image.loader.ImageFlavor;
import org.apache.xmlgraphics.image.loader.ImageInfo;
@@ -33,7 +40,7 @@ import org.apache.xmlgraphics.image.load
/**
* Tests for bundled ImageLoader implementations.
*/
-public class ImageCacheTestCase extends TestCase {
+public class ImageCacheTestCase {
private static final boolean DEBUG = false;
@@ -44,9 +51,8 @@ public class ImageCacheTestCase extends
? new ImageCacheLoggingStatistics(true) : new ImageCacheStatistics(true));
/** {@inheritDoc} */
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUp() throws Exception {
manager.getCache().clearCache();
statistics.reset();
manager.getCache().setCacheListener(statistics);
@@ -56,6 +62,7 @@ public class ImageCacheTestCase extends
* Tests the ImageInfo cache.
* @throws Exception if an error occurs
*/
+ @Test
public void testImageInfoCache() throws Exception {
String invalid1 = "invalid1.jpg";
String invalid2 = "invalid2.jpg";
@@ -63,7 +70,8 @@ public class ImageCacheTestCase extends
String valid2 = "big-image.png";
- ImageInfo info1, info2;
+ ImageInfo info1;
+ ImageInfo info2;
info1 = manager.getImageInfo(valid1, sessionContext);
assertNotNull(info1);
assertEquals(valid1, info1.getOriginalURI());
@@ -113,6 +121,7 @@ public class ImageCacheTestCase extends
statistics.reset();
}
+ @Test
public void testInvalidURIExpiration() throws Exception {
MockTimeStampProvider provider = new MockTimeStampProvider();
ImageCache cache = new ImageCache(provider, new DefaultExpirationPolicy(2));
@@ -155,18 +164,19 @@ public class ImageCacheTestCase extends
* Tests the image cache reusing a cacheable Image created by the ImageLoader.
* @throws Exception if an error occurs
*/
+ @Test
public void testImageCache1() throws Exception {
String valid1 = "bgimg72dpi.gif";
ImageInfo info = manager.getImageInfo(valid1, sessionContext);
assertNotNull(info);
- ImageBuffered img1 = (ImageBuffered)manager.getImage(
+ ImageBuffered img1 = (ImageBuffered) manager.getImage(
info, ImageFlavor.BUFFERED_IMAGE, sessionContext);
assertNotNull(img1);
assertNotNull(img1.getBufferedImage());
- ImageBuffered img2 = (ImageBuffered)manager.getImage(
+ ImageBuffered img2 = (ImageBuffered) manager.getImage(
info, ImageFlavor.BUFFERED_IMAGE, sessionContext);
//ImageBuffered does not have to be the same instance but we want at least the
//BufferedImage to be reused.
@@ -177,11 +187,12 @@ public class ImageCacheTestCase extends
assertEquals(1, statistics.getImageCacheMisses());
}
-
+
/**
* Test to check if doInvalidURIHouseKeeping() throws a
* ConcurrentModificationException.
*/
+ @Test
public void testImageCacheHouseKeeping() {
ImageCache imageCache = new ImageCache(new TimeStampProvider(),
new DefaultExpirationPolicy(1));
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,14 +19,13 @@
package org.apache.xmlgraphics.image.loader.impl;
-import static org.junit.Assert.assertTrue;
-
import java.net.URL;
-import junit.framework.Assert;
-
import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import org.apache.xmlgraphics.image.loader.Image;
import org.apache.xmlgraphics.image.loader.ImageContext;
import org.apache.xmlgraphics.image.loader.ImageFlavor;
@@ -50,7 +49,7 @@ public class ImageLoaderImageIOTestCase
@Test
public void testGrayPNGWithCMYKProfile() throws Exception {
URL imageURL = getClass().getResource("gray-vs-cmyk-profile.png");
- Assert.assertNotNull(imageURL);
+ assertNotNull(imageURL);
String uri = imageURL.toURI().toASCIIString();
ImageLoaderImageIO loader = new ImageLoaderImageIO(ImageFlavor.RENDERED_IMAGE);
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawCCITTFaxTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawCCITTFaxTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawCCITTFaxTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawCCITTFaxTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,7 +19,9 @@
package org.apache.xmlgraphics.image.loader.impl;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
import org.apache.xmlgraphics.image.loader.ImageContext;
import org.apache.xmlgraphics.image.loader.ImageInfo;
@@ -30,11 +32,12 @@ import org.apache.xmlgraphics.image.load
import org.apache.xmlgraphics.util.MimeConstants;
/**
- * Test case for {@link ImageLoaderRawCCITTFax}.
+ * Test case for {@link ImageLoaderRawCCITTFax}.
*/
-public class ImageLoaderRawCCITTFaxTestCase extends TestCase {
+public class ImageLoaderRawCCITTFaxTestCase {
private ImageLoaderRawCCITTFax sut;
+ @Test
public void testLoadImage() throws Exception {
ImageContext context = MockImageContext.newSafeInstance();
ImageSessionContext session = new MockImageSessionContext(context);
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/mocks/MockImageLoaderFactoryTIFF.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/mocks/MockImageLoaderFactoryTIFF.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/mocks/MockImageLoaderFactoryTIFF.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/image/loader/mocks/MockImageLoaderFactoryTIFF.java Thu Jul 26 09:33:18 2012
@@ -22,7 +22,7 @@ package org.apache.xmlgraphics.image.loa
import java.io.IOException;
import java.util.Map;
-import junit.framework.Assert;
+import static org.junit.Assert.assertTrue;
import org.apache.xmlgraphics.image.loader.Image;
import org.apache.xmlgraphics.image.loader.ImageException;
@@ -57,7 +57,7 @@ public class MockImageLoaderFactoryTIFF
break;
}
}
- Assert.assertTrue(found);
+ assertTrue(found);
}
/** {@inheritDoc} */
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java Thu Jul 26 09:33:18 2012
@@ -26,21 +26,21 @@ import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
-import org.apache.xmlgraphics.java2d.GraphicContext;
-import org.apache.xmlgraphics.ps.PSGenerator;
-import org.apache.xmlgraphics.ps.PSState;
-
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.PSState;
+
public class PSGraphics2DTestCase {
private PSGenerator gen;
private PSGraphics2D gfx2d;
- private final AffineTransform TRANSFORM = new AffineTransform(1, 0, 0, -1, 0, 792);
+ private final AffineTransform transform = new AffineTransform(1, 0, 0, -1, 0, 792);
@Before
public void setup() {
@@ -53,13 +53,13 @@ public class PSGraphics2DTestCase {
private void createGraphics2D() {
gfx2d = new PSGraphics2D(false, gen);
gfx2d.setGraphicContext(new GraphicContext());
- gfx2d.setTransform(TRANSFORM);
+ gfx2d.setTransform(transform);
}
@Test
public void draw() throws IOException {
- assertEquals(gfx2d.getTransform(), TRANSFORM);
+ assertEquals(gfx2d.getTransform(), transform);
gfx2d.draw(new Rectangle(10, 10, 100, 100));
- verify(gen, times(1)).concatMatrix(TRANSFORM);
+ verify(gen, times(1)).concatMatrix(transform);
}
}
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java Thu Jul 26 09:33:18 2012
@@ -23,14 +23,25 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
+import java.awt.image.DataBuffer;
+import java.awt.image.DirectColorModel;
+import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.Arrays;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import org.apache.commons.io.output.ByteArrayOutputStream;
-public class ImageEncodingHelperTestCase extends TestCase {
+public class ImageEncodingHelperTestCase {
private BufferedImage prepareImage(BufferedImage image) {
Graphics2D ig = image.createGraphics();
@@ -52,11 +63,34 @@ public class ImageEncodingHelperTestCase
}
/**
- * Tests a BGR versus RBG image. Debugging shows the BGR follows the optimizeWriteTo() (which is intended).
- * The bytes are compared with the RBG image, which happens to follow the writeRGBTo().
- *
+ * Tests encodeRenderedImageWithDirectColorModeAsRGB(). Tests the optimised method against the
+ * non-optimised method(encodeRenderedImageAsRGB) to ensure the BufferedImage produced are the
+ * same.
+ * @throws IOException if an I/O error occurs.
+ */
+ @Test
+ public void testEncodeRenderedImageWithDirectColorModelAsRGB() throws IOException {
+ BufferedImage image = new BufferedImage(100, 75, BufferedImage.TYPE_INT_ARGB);
+ image = prepareImage(image);
+
+ ByteArrayOutputStream optimized = new ByteArrayOutputStream();
+ ImageEncodingHelper.encodeRenderedImageWithDirectColorModelAsRGB(image, optimized);
+
+ ByteArrayOutputStream nonoptimized = new ByteArrayOutputStream();
+ ImageEncodingHelper.encodeRenderedImageAsRGB(image, nonoptimized);
+
+ assertTrue(Arrays.equals(nonoptimized.toByteArray(), optimized.toByteArray()));
+
+ }
+
+ /**
+ * Tests a BGR versus RBG image. Debugging shows the BGR follows the optimizeWriteTo() (which
+ * is intended). The bytes are compared with the RBG image, which happens to follow the
+ * writeRGBTo().
+ *
* @throws IOException
*/
+ @Test
public void testRGBAndBGRImages() throws IOException {
BufferedImage imageBGR = new BufferedImage(100, 75, BufferedImage.TYPE_3BYTE_BGR);
imageBGR = prepareImage(imageBGR);
@@ -75,4 +109,45 @@ public class ImageEncodingHelperTestCase
assertTrue(Arrays.equals(baosBGR.toByteArray(), baosRGB.toByteArray()));
}
+ /**
+ * Tests encodeRenderedImageWithDirectColorModeAsRGB(). Uses mocking to test the method
+ * implementation.
+ * @throws IOException if an I/O error occurs.
+ */
+ @Test
+ public void testMockedEncodeRenderedImageWithDirectColorModelAsRGB() throws IOException {
+ BufferedImage image = mock(BufferedImage.class);
+ final int[] templateMasks = new int[] {0x00ff0000 /*R*/, 0x0000ff00 /*G*/,
+ 0x000000ff /*B*/, 0xff000000 /*A*/};
+ DirectColorModel dcm = new DirectColorModel(255, templateMasks[0], templateMasks[1],
+ templateMasks[2], templateMasks[3]);
+
+ WritableRaster raster = mock(WritableRaster.class);
+ DataBuffer buffer = mock(DataBuffer.class);
+
+ when(image.getColorModel()).thenReturn(dcm);
+ when(image.getRaster()).thenReturn(raster);
+ when(raster.getDataBuffer()).thenReturn(buffer);
+ when(buffer.getDataType()).thenReturn(DataBuffer.TYPE_INT);
+ when(image.getWidth()).thenReturn(3);
+ when(image.getHeight()).thenReturn(3);
+ final int expectedValue = 1 + 2 << 8 + 3 << 16;
+ Answer<Object> ans = new Answer<Object>() {
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ int[] data = (int[]) args[4];
+ Arrays.fill(data, expectedValue);
+ return null;
+ }
+ };
+ when(raster.getDataElements(anyInt(), anyInt(), anyInt(), anyInt(), anyObject()))
+ .thenAnswer(ans);
+
+ ByteArrayOutputStream optimized = new ByteArrayOutputStream();
+ ImageEncodingHelper.encodeRenderedImageWithDirectColorModelAsRGB(image, optimized);
+
+ byte[] expectedByteArray = new byte[27];
+ Arrays.fill(expectedByteArray, (byte) expectedValue);
+ assertTrue(Arrays.equals(expectedByteArray, optimized.toByteArray()));
+ }
}
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/PSEscapeTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,15 +19,16 @@
package org.apache.xmlgraphics.ps;
-import org.apache.xmlgraphics.ps.PSGenerator;
+import org.junit.Test;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
/**
* Tests literal text string escaping.
*/
-public class PSEscapeTestCase extends TestCase {
+public class PSEscapeTestCase {
+ @Test
public void testBasics() throws Exception {
StringBuffer sb = new StringBuffer();
@@ -50,6 +51,7 @@ public class PSEscapeTestCase extends Te
assertEquals("0\\t\\(x\\)\\n\\036\\344?", sb.toString());
}
+ @Test
public void testStringToDSC() throws Exception {
String escaped;
escaped = PSGenerator.convertStringToDSC("0\t(x)\n\u001E\u00E4\u20AC");
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java Thu Jul 26 09:33:18 2012
@@ -23,7 +23,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import org.apache.commons.io.IOUtils;
@@ -35,12 +38,13 @@ import org.apache.xmlgraphics.ps.dsc.eve
/**
* Tests the listener functionality on the DSC parser.
*/
-public class ListenerTestCase extends TestCase {
+public class ListenerTestCase {
/**
* Tests {@link DSCParser#setFilter(DSCFilter)}.
* @throws Exception if an error occurs
*/
+ @Test
public void testFilter() throws Exception {
InputStream in = getClass().getResourceAsStream("test1.txt");
try {
@@ -69,6 +73,7 @@ public class ListenerTestCase extends Te
* Tests listeners on DSCParser.
* @throws Exception if an error occurs
*/
+ @Test
public void testListeners() throws Exception {
InputStream in = getClass().getResourceAsStream("test1.txt");
try {
@@ -104,7 +109,7 @@ public class ListenerTestCase extends Te
public void processEvent(DSCEvent event, DSCParser parser)
throws IOException, DSCException {
if (event instanceof DSCCommentLanguageLevel) {
- DSCCommentLanguageLevel level = (DSCCommentLanguageLevel)event;
+ DSCCommentLanguageLevel level = (DSCCommentLanguageLevel) event;
results.put("level", new Integer(level.getLanguageLevel()));
}
}
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCCommentBoundingBoxTestCase.java Thu Jul 26 09:33:18 2012
@@ -22,28 +22,31 @@ package org.apache.xmlgraphics.ps.dsc.ev
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
import org.apache.xmlgraphics.ps.dsc.DSCCommentFactory;
-public class DSCCommentBoundingBoxTestCase extends TestCase {
+public class DSCCommentBoundingBoxTestCase {
+ @Test
public void testBoundingBox() throws Exception {
DSCComment comment = DSCCommentFactory.createDSCCommentFor("BoundingBox");
- DSCCommentBoundingBox bbox = (DSCCommentBoundingBox)comment;
+ DSCCommentBoundingBox bbox = (DSCCommentBoundingBox) comment;
bbox.parseValue("289 412 306 429");
Rectangle refRect = new Rectangle(289, 412, 306 - 289, 429 - 412);
assertEquals(refRect, bbox.getBoundingBox());
comment = DSCCommentFactory.createDSCCommentFor("BoundingBox");
- bbox = (DSCCommentBoundingBox)comment;
+ bbox = (DSCCommentBoundingBox) comment;
bbox.parseValue("289.12 412.2 306.777 429.11");
Rectangle2D refRect2D = new Rectangle2D.Double(
289.12, 412.2, 306.777 - 289.12, 429.11 - 412.2);
assertEquals(refRect2D, bbox.getBoundingBox());
comment = DSCCommentFactory.createDSCCommentFor("HiResBoundingBox");
- bbox = (DSCCommentHiResBoundingBox)comment;
+ bbox = (DSCCommentHiResBoundingBox) comment;
bbox.parseValue("289.12 412.2 306.777 429.11");
refRect2D = new Rectangle2D.Double(
289.12, 412.2, 306.777 - 289.12, 429.11 - 412.2);
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/events/DSCValueParserTestCase.java Thu Jul 26 09:33:18 2012
@@ -21,16 +21,17 @@ package org.apache.xmlgraphics.ps.dsc.ev
import java.util.List;
-import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBeginResource;
+import org.junit.Test;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class DSCValueParserTestCase extends TestCase {
+public class DSCValueParserTestCase {
private String[] toArray(List params) {
- return (String[])params.toArray(new String[params.size()]);
+ return (String[]) params.toArray(new String[params.size()]);
}
+ @Test
public void testText() throws Exception {
DSCCommentBeginResource obj = new DSCCommentBeginResource();
String[] res = toArray(obj.splitParams("procset Test"));
@@ -44,6 +45,7 @@ public class DSCValueParserTestCase exte
assertEquals("Test", res[1]);
}
+ @Test
public void testParentheseText() throws Exception {
DSCCommentBeginResource obj = new DSCCommentBeginResource();
String[] res = toArray(obj.splitParams("procset (Hello World!)"));
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/ps/dsc/tools/DSCToolsTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,16 +19,20 @@
package org.apache.xmlgraphics.ps.dsc.tools;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.apache.xmlgraphics.ps.dsc.events.DSCCommentEndComments;
import org.apache.xmlgraphics.ps.dsc.events.DSCCommentPages;
import org.apache.xmlgraphics.ps.dsc.events.DSCEvent;
import org.apache.xmlgraphics.ps.dsc.events.PostScriptComment;
import org.apache.xmlgraphics.ps.dsc.events.PostScriptLine;
-import junit.framework.TestCase;
-
-public class DSCToolsTestCase extends TestCase {
+public class DSCToolsTestCase {
+ @Test
public void testEndComment() throws Exception {
DSCEvent event;
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/DateFormatUtilTestCase.java Thu Jul 26 09:33:18 2012
@@ -24,19 +24,23 @@ import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
-import org.apache.xmlgraphics.xmp.XMPSchemaAdapter;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import org.apache.xmlgraphics.xmp.XMPSchemaAdapter;
/**
* Tests date formatting for XMP.
*/
-public class DateFormatUtilTestCase extends TestCase {
+public class DateFormatUtilTestCase {
/**
* Checks date formatting for XMP.
* @throws Exception if an error occurs
*/
+ @Test
public void testDateFormattingISO8601() throws Exception {
Date dt = createTestDate();
@@ -69,6 +73,7 @@ public class DateFormatUtilTestCase exte
return dt;
}
+ @Test
public void testDateFormattingPDF() throws Exception {
Date dt = createTestDate();
@@ -88,14 +93,17 @@ public class DateFormatUtilTestCase exte
assertEquals("D:20080207041107-11'00'", s);
}
+ @Test
public void testParseInvalidDateNoColonUTC() {
testInvalidDate("2008-02-07T151107Z");
}
+ @Test
public void testParseInvalidDateNoColonLocal() {
testInvalidDate("2008-02-07T151107+0000");
}
+ @Test
public void testParseInvalidDateColonLast() {
testInvalidDate("2008-02-07T151107Z:");
}
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/HexUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/HexUtil.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/HexUtil.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/HexUtil.java Thu Jul 26 09:33:18 2012
@@ -22,7 +22,10 @@ package org.apache.xmlgraphics.util;
/**
* Provides helper functions for converting hexadecimal strings.
*/
-public class HexUtil {
+public final class HexUtil {
+
+ private HexUtil() {
+ }
private static final char[] DIGITS =
{'0', '1', '2', '3', '4', '5', '6', '7',
@@ -33,7 +36,7 @@ public class HexUtil {
* @param data the data to encode
* @return String the resulting String
*/
- public static final String toHex(byte[] data) {
+ public static String toHex(byte[] data) {
final StringBuffer sb = new StringBuffer(data.length * 2);
for (int i = 0; i < data.length; i++) {
sb.append(DIGITS[(data[i] >>> 4) & 0x0F]);
Modified: xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java?rev=1365925&r1=1365924&r2=1365925&view=diff
==============================================================================
--- xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java (original)
+++ xmlgraphics/commons/branches/Temp_URI_Resolution/test/java/org/apache/xmlgraphics/util/UnitConvTestCase.java Thu Jul 26 09:33:18 2012
@@ -19,19 +19,20 @@
package org.apache.xmlgraphics.util;
-import org.apache.xmlgraphics.util.UnitConv;
+import org.junit.Test;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
/**
* Test class for UnitConv.
*/
-public class UnitConvTestCase extends TestCase {
+public class UnitConvTestCase {
/**
* Test all kinds of unit conversions.
* @throws Exception if the test fails
*/
+ @Test
public void testConversions() throws Exception {
assertEquals("in2mm", 25.4, UnitConv.in2mm(1), 0.00001);
assertEquals("mm2in", 1.0, UnitConv.mm2in(25.4), 0.00001);
@@ -44,5 +45,4 @@ public class UnitConvTestCase extends Te
assertEquals("mm2px/72dpi", 841.8897764234434, UnitConv.mm2px(297.0, 72), 0);
assertEquals("mm2px/300dpi", 3507.8740684310146, UnitConv.mm2px(297.0, 300), 0);
}
-
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org