Package org.opengis.test.coverage.image
Class ImageWriterTestCase
Object
TestCase
ImageIOTestCase
ImageWriterTestCase
- All Implemented Interfaces:
Closeable,AutoCloseable
Base class for testing
The writer shall accept at least one of the following
output types, in preference order:
ImageWriter implementations. This test writes different regions
and bands of an image at different sub-sampling levels, then read back the images and compare
the sample values.
To use this test, subclasses need to set the writer field to a non-null value
in the prepareImageWriter(boolean) method. Example:
public class MyImageWriterTest extends ImageWriterTestCase {
@Override
protected void prepareImageWriter(boolean optionallySetOutput) throws IOException {
if (writer == null) {
writer = new MyImageWriter();
}
}
}
ImageOutputStream- mandatory according Image I/O specification.File- fallback if the writer doesn't supportImageOutputStream. This fallback exists becauseImageOutputStreamis hard to support when the writer is implemented by a native library.
- Since:
- 3.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ImageReaderThe reader to use for verifying the writer output.protected ImageWriterThe image writer to test.Fields inherited from class org.opengis.test.coverage.image.ImageIOTestCase
isSourceBandsSupported, isSubregionSupported, isSubsamplingOffsetSupported, isSubsamplingSupported, sampleToleranceThresholdFields inherited from class org.opengis.test.TestCase
configurationTip, units, validators -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new test case using a default random number generator.protectedImageWriterTestCase(long seed) Creates a new test case using a random number generator initialized to the given seed. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected voidcompleteImageMetadata(IIOMetadata metadata, RenderedImage image) Completes stream or image metadata to be given to the tested writer.protected abstract voidprepareImageWriter(boolean optionallySetOutput) Invoked when the image writer is about to be used for the first time.voidTests theImageWriter.writemethod for a single band of byte values.voidSame test astestOneByteBand(), but using the signeddoubletype.voidSame test astestOneByteBand(), but using the signedfloattype.voidSame test astestOneByteBand(), but using the signedinttype.voidSame test astestOneByteBand(), but using the signedshorttype.voidSame test astestOneByteBand(), but using the unsignedshorttype.voidSame test astestOneByteBand(), but using RGB values in three bands.Methods inherited from class org.opengis.test.TestCase
configuration, getEnabledFlags
-
Field Details
-
writer
The image writer to test. This field must be set by subclasses in theprepareImageWriter(boolean)method. -
reader
The reader to use for verifying the writer output. By default, this field isnulluntil a reader is first needed, in which case the field is assigned to a reader instance created byImageIO.getImageReader(ImageWriter). Subclasses can set explicitly a value to this field if they need the tests to use another reader instead.ImageWriterTestCasewill use only theImageReader.read(int)method. Consequently, this reader doesn't need to supportImageReadParamusage.
-
-
Constructor Details
-
ImageWriterTestCase
protected ImageWriterTestCase()Creates a new test case using a default random number generator. The sub-regions, sub-samplings and source bands will be different for every test execution. If reproducible subsetting sequences are needed, use theImageWriterTestCase(long)constructor instead. -
ImageWriterTestCase
Creates a new test case using a random number generator initialized to the given seed.- Parameters:
seed- the initial seed for the random numbers generator. Use a constant value if the tests need to be reproduced with the same sequence of image write parameters.
-
-
Method Details
-
prepareImageWriter
Invoked when the image writer is about to be used for the first time. Subclasses need to create a newImageWriterinstance if needed.If the
optionallySetOutputargument istrue, then subclasses can optionally set the output to a temporary file or other object suitable to the writer. This operation is optional: if no output has been explicitly set,ImageWriterTestCasewill automatically set the output to an in-memory stream or to a temporary file.Example:
This method may be invoked with a@Override protected void prepareImageWriter(boolean optionallySetOutput) throws IOException { if (writer == null) { writer = new MyImageWriter(); } if (optionallySetOutput) { writer.setOutput(output); // Optional operation. } }falseargument value when the methods to be tested do not need an output, for exampleImageWriter.canWriteRasters().- Parameters:
optionallySetOutput-trueif this method can set the writer output (optional operation), orfalseif this is not yet necessary.- Throws:
IOException- if an error occurred while preparing the writer.
-
completeImageMetadata
Completes stream or image metadata to be given to the tested writer. This method is invoked after the default metadata have been created, and before they are given to the tested image writer, as below:For stream metadata:
(param); if (metadata != null) { completeImageMetadata(metadata, null); }}IIOMetadata metadata = writer.getDefaultStreamMetadataFor image metadata:
The default implementation does nothing (note: this may change in a future version). Subclasses can override this method for providing custom metadata.IIOMetadata metadata = writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(image), param); if (metadata != null) { completeImageMetadata(metadata, image); }- Parameters:
metadata- the stream or image metadata to complete before to be given to the tested image writer.image- the image for which to create image metadata, ornullfor stream metadata.- Throws:
IOException- if the implementation needs to perform an I/O operation and that operation failed.- See Also:
-
testOneByteBand
Tests theImageWriter.writemethod for a single band of byte values. First, this method creates an single-banded image filled with random byte values. Then, this method invokes write the image an arbitrary amount of time for the following configurations (note: anyisXXXSupportedfield which was set tofalseprior the execution of this test will stayfalse):- Writes the full image once (all
isXXXSupportedfields set tofalse). - Writes various sub-regions (only
isSubregionSupportedmay betrue) - Writes at various sub-sampling (only
isSubsamplingSupportedmay betrue) - Reads various bands (only
isSourceBandsSupportedmay betrue) - A mix of sub-regions, sub-sampling and source bands
- Throws:
IOException- if an error occurred while writing the image or or reading it back.
- Writes the full image once (all
-
testThreeByteBands
Same test astestOneByteBand(), but using RGB values in three bands.- Throws:
IOException- if an error occurred while writing the image or or reading it back.
-
testOneShortBand
Same test astestOneByteBand(), but using the signedshorttype.- Throws:
IOException- if an error occurred while writing the image or or reading it back.
-
testOneUnsignedShortBand
Same test astestOneByteBand(), but using the unsignedshorttype.- Throws:
IOException- if an error occurred while writing the image or or reading it back.
-
testOneIntBand
Same test astestOneByteBand(), but using the signedinttype.- Throws:
IOException- if an error occurred while writing the image or or reading it back.
-
testOneFloatBand
Same test astestOneByteBand(), but using the signedfloattype.- Throws:
IOException- if an error occurred while writing the image or or reading it back.
-
testOneDoubleBand
Same test astestOneByteBand(), but using the signeddoubletype.- Throws:
IOException- if an error occurred while writing the image or or reading it back.
-
close
Disposes the reader and the writer (if non-null) after each test. The default implementation performs the following cleanup:- If the writer output is closeable, closes it.
- Invokes
ImageWriter.reset()for clearing the output and listeners. - Invokes
ImageWriter.dispose()for performing additional resource disposal, if any. - Sets the
writerfield tonullfor preventing accidental use. - Performs the same steps as above for the reader, if non-null.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an error occurred while closing the output stream.- See Also:
-