This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 131091fdaacd840d921595e76891c43e58b32d27 Author: Martin Desruisseaux <[email protected]> AuthorDate: Tue Jan 28 10:38:40 2020 +0100 Add a test application for manual testing of GridView. --- application/sis-javafx/pom.xml | 9 +++ .../org/apache/sis/gui/coverage/GridError.java | 4 +- .../org/apache/sis/gui/coverage/GridViewApp.java | 94 ++++++++++++++++++++++ .../java/org/apache/sis/image/TiledImageMock.java | 43 +++++++++- 4 files changed, 148 insertions(+), 2 deletions(-) diff --git a/application/sis-javafx/pom.xml b/application/sis-javafx/pom.xml index b019d9b..f5765ef 100644 --- a/application/sis-javafx/pom.xml +++ b/application/sis-javafx/pom.xml @@ -142,6 +142,15 @@ <version>${project.version}</version> <scope>runtime</scope> </dependency> + + <!-- Test dependencies --> + <dependency> + <groupId>org.apache.sis.core</groupId> + <artifactId>sis-feature</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridError.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridError.java index 294cd20..27431b6 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridError.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridError.java @@ -85,8 +85,10 @@ final class GridError extends VBox { buttons.setPrefRows(1); buttons.setPrefColumns(2); buttons.setAlignment(Pos.CENTER); - details.setMaxWidth(100); // Arbitrary limit, width enough for allowing TilePane to resize. + details.setMaxWidth(100); // Arbitrary limit, width enough for allowing TilePane to resize. retry .setMaxWidth(100); + details.setFocusTraversable(false); // For avoiding confusing behavior (would be in random order anyway). + retry .setFocusTraversable(false); final String t = exception.getLocalizedMessage(); message = new Label((t == null) ? header : header + System.lineSeparator() + t); diff --git a/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/GridViewApp.java b/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/GridViewApp.java new file mode 100644 index 0000000..81508eb --- /dev/null +++ b/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/GridViewApp.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.gui.coverage; + +import java.util.Random; +import java.awt.image.DataBuffer; +import javafx.application.Application; +import javafx.scene.layout.BorderPane; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.apache.sis.image.TiledImageMock; + + +/** + * Shows {@link GridView} with random data. The image will have small tiles of size + * {@value #TILE_WIDTH}×{@value #TILE_HEIGHT}. The image will artificially fails to + * provide some tiles in order to test error controls. + * + * @author Martin Desruisseaux (Geomatys) + * @version 1.1 + * @since 1.1 + * @module + */ +public final strictfp class GridViewApp extends Application { + /** + * Size of the artificial tiles. Should be small enough so we can have many of them. + * Width and height should be different in order to increase the chance to see bugs + * if some code confused them. + */ + private static final int TILE_WIDTH = 10, TILE_HEIGHT = 15; + + /** + * Starts the test application. + * + * @param args ignored. + */ + public static void main(final String[] args) { + launch(args); + } + + /** + * Creates and starts the test application. + * + * @param window where to show the application. + */ + @Override + public void start(final Stage window) { + final GridView view = new GridView(); + final BorderPane pane = new BorderPane(); + pane.setCenter(view); + window.setTitle("GridView Test"); + window.setScene(new Scene(pane)); + window.setWidth (400); + window.setHeight(500); + window.show(); + view.setImage(createImage()); + } + + /** + * Creates a dummy image for testing purpose. Some tiles will + * have artificial errors in order to see the error controls. + */ + private static TiledImageMock createImage() { + final Random random = new Random(); + final TiledImageMock image = new TiledImageMock( + DataBuffer.TYPE_USHORT, 1, + -50, // minX + 70, // minY + TILE_WIDTH * 30, // width + TILE_HEIGHT * 25, // height + TILE_WIDTH, + TILE_HEIGHT, + 3, // minTileX + -5); // minTileY + image.validate(); + image.initializeAllTiles(0); + image.failRandomly(new Random()); + return image; + } +} diff --git a/core/sis-feature/src/test/java/org/apache/sis/image/TiledImageMock.java b/core/sis-feature/src/test/java/org/apache/sis/image/TiledImageMock.java index 0df0cf8..b96c187 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/image/TiledImageMock.java +++ b/core/sis-feature/src/test/java/org/apache/sis/image/TiledImageMock.java @@ -18,6 +18,7 @@ package org.apache.sis.image; import java.awt.Point; import java.awt.image.ColorModel; +import java.awt.image.ImagingOpException; import java.awt.image.PixelInterleavedSampleModel; import java.awt.image.Raster; import java.awt.image.RasterFormatException; @@ -25,6 +26,8 @@ import java.awt.image.SampleModel; import java.awt.image.TileObserver; import java.awt.image.WritableRaster; import java.awt.image.WritableRenderedImage; +import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.sis.internal.util.Numerics; import org.apache.sis.util.ArraysExt; @@ -92,6 +95,24 @@ public final strictfp class TiledImageMock extends PlanarImage implements Writab private boolean isTileAcquired; /** + * If some tiles should fail randomly, the random number generator to use for deciding if a + * {@link #getTile(int, int)} invocation should fail. Note that two consecutive invocations + * of {@code getTile(…)} may give different result. + * + * @see #failRandomly(Random) + */ + private Random randomFailures; + + /** + * Sequential number for use in production of error messages, to differentiate them. + * Since {@link #getTile(int, int)} may be invoked in background threads, this field + * should be safe to concurrent threads. + * + * @see #failRandomly(Random) + */ + private AtomicInteger errorSequence; + + /** * Creates a new tiled image. Testers should invoke {@link #validate()} after construction. * * @param dataType sample data type as one of the {@link java.awt.image.DataBuffer} constants. @@ -157,11 +178,27 @@ public final strictfp class TiledImageMock extends PlanarImage implements Writab } /** + * Causes some {@link #getTile(int, int)} and {@link #getWritableTile(int, int)} calls to fail. + * Note that two consecutive invocations of {@code getTile(…)} may give different result. + * + * @param random the random number generator to use for deciding if a tile request should fail. + */ + public void failRandomly(final Random random) { + randomFailures = random; + errorSequence = new AtomicInteger(); + } + + /** * Sets a sample value at the given location in pixel coordinates. * This is a helper method for testing purpose on small images only, * since invoking this method in a loop is inefficient. + * + * @param x column index of the pixel to set. + * @param y row index of the pixel to set. + * @param b band index of the sample value to set. + * @param value the new value. */ - final void setSample(final int x, final int y, final int b, final double value) { + public void setSample(final int x, final int y, final int b, final double value) { final int ox = x - minX; final int oy = y - minY; if (ox < 0 || ox >= width || oy < 0 || oy >= height) { @@ -238,6 +275,10 @@ public final strictfp class TiledImageMock extends PlanarImage implements Writab { throw new IndexOutOfBoundsException(); } + if (randomFailures != null && randomFailures.nextInt(10) == 0) { + throw new ImagingOpException("Artificial error #" + errorSequence.incrementAndGet() + + " on tile (" + tileX + ", " + tileY + ")."); + } final int i = tileY * numXTiles + tileX; WritableRaster raster = tiles[i]; if (raster == null) {
