sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] 01/01: Add test case breaking source domain expansion
Date Fri, 11 Sep 2020 12:54:25 GMT
This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch fix/sourceExpansion
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 53b168a8e2f754fe680cc596cf3b3239027ad7b3
Author: jsorel <johann.sorel@geomatys.com>
AuthorDate: Fri Sep 11 14:53:57 2020 +0200

    Add test case breaking source domain expansion
---
 .../internal/storage/query/CoverageQueryTest.java  | 33 ++++----
 .../internal/storage/query/MockGridResource.java   | 90 ++++++++++++++++++++++
 2 files changed, 110 insertions(+), 13 deletions(-)

diff --git a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/CoverageQueryTest.java
b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/CoverageQueryTest.java
index 16362b0..478f47d 100644
--- a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/CoverageQueryTest.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/CoverageQueryTest.java
@@ -16,7 +16,7 @@
  */
 package org.apache.sis.internal.storage.query;
 
-import java.awt.image.BufferedImage;
+import java.awt.image.RenderedImage;
 import org.opengis.metadata.spatial.DimensionNameType;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.datum.PixelInCell;
@@ -25,7 +25,6 @@ import org.apache.sis.coverage.grid.GridCoverage2D;
 import org.apache.sis.coverage.grid.GridExtent;
 import org.apache.sis.coverage.grid.GridGeometry;
 import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
-import org.apache.sis.internal.storage.MemoryGridResource;
 import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.GridCoverageResource;
@@ -67,8 +66,7 @@ public final strictfp class CoverageQueryTest extends TestCase {
         final int width  = 32;
         final int height = 37;
         final GridGeometry grid = new GridGeometry(new GridExtent(width, height), PixelInCell.CELL_CENTER,
gridToCRS, crs);
-        final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
-        resource = new MemoryGridResource(null, new GridCoverage2D(grid, null, image));
+        resource = new MockGridResource(grid);
     }
 
     /**
@@ -127,6 +125,14 @@ public final strictfp class CoverageQueryTest extends TestCase {
         final GridCoverageResource subset = resource.subset(query);
         assertEquals(createSubGrid(3), subset.getGridGeometry());
         verifyRead(subset);
+
+        /*
+        Current implementation returns the full image
+        but still, the expansion should be visible in the image offset
+        */
+        GridCoverage coverage = subset.read(null);
+        RenderedImage image = coverage.render(null);
+        System.out.println(image);
     }
 
     /**
@@ -135,15 +141,16 @@ public final strictfp class CoverageQueryTest extends TestCase {
      * {@link GridCoverage2D} returns a larger area then requested.
      */
     private void verifyRead(final GridCoverageResource subset) throws DataStoreException
{
-        final GridGeometry request  = createSubGrid(-4);
-        final GridCoverage coverage = subset.read(request);
-        /*
-         * PENDING_JDK_FIX: replace following lines by new tests
-         * after https://bugs.openjdk.java.net/browse/JDK-8166038 is fixed.
-         */
-        if (coverage.render(null) instanceof BufferedImage) {
-            final GridGeometry expected = resource.getGridGeometry();
-            assertEquals(expected, coverage.getGridGeometry());
+
+        { //must be the same as subset grid geometry
+            final GridCoverage coverage = subset.read(null);
+            assertEquals(subset.getGridGeometry(), coverage.getGridGeometry());
+        }
+
+        {
+            final GridGeometry request  = createSubGrid(-4);
+            final GridCoverage coverage = subset.read(request);
+            assertEquals(request, coverage.getGridGeometry());
         }
     }
 }
diff --git a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/MockGridResource.java
b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/MockGridResource.java
new file mode 100644
index 0000000..3b8421b
--- /dev/null
+++ b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/MockGridResource.java
@@ -0,0 +1,90 @@
+/*
+ * 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.internal.storage.query;
+
+import java.awt.image.BufferedImage;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.sis.coverage.SampleDimension;
+import org.apache.sis.coverage.grid.GridCoverage;
+import org.apache.sis.coverage.grid.GridCoverageBuilder;
+import org.apache.sis.coverage.grid.GridGeometry;
+import org.apache.sis.coverage.grid.GridRoundingMode;
+import org.apache.sis.internal.storage.AbstractGridResource;
+import org.apache.sis.storage.DataStoreException;
+
+/**
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.1
+ * @since   1.1
+ */
+final class MockGridResource extends AbstractGridResource{
+
+    private final GridGeometry gridGeometry;
+    private final List<SampleDimension> sampleDimensions;
+
+    MockGridResource(GridGeometry gridGeometry) {
+        super(null);
+        this.gridGeometry = gridGeometry;
+        this.sampleDimensions = Arrays.asList(new SampleDimension.Builder().setName(0).build());
+    }
+
+    @Override
+    public GridGeometry getGridGeometry() throws DataStoreException {
+        return gridGeometry;
+    }
+
+    @Override
+    public List<SampleDimension> getSampleDimensions() throws DataStoreException {
+        return sampleDimensions;
+    }
+
+    @Override
+    public GridCoverage read(GridGeometry domain, int... range) throws DataStoreException
{
+        if (domain == null) {
+            domain = gridGeometry;
+        }
+
+        GridGeometry newGrid = gridGeometry.derive()
+                .rounding(GridRoundingMode.ENCLOSING)
+                .subgrid(domain)
+                .build();
+
+        List<SampleDimension> bands = getSampleDimensions();
+        if (range != null && range.length > 0) {
+            final List<SampleDimension> valids = new ArrayList<>(range.length);
+            for (int i : range) {
+                valids.add(bands.get(i));
+            }
+            bands = valids;
+        }
+
+        BufferedImage img = new BufferedImage(
+                (int) newGrid.getExtent().getSize(0),
+                (int) newGrid.getExtent().getSize(1),
+                BufferedImage.TYPE_BYTE_GRAY);
+
+        final GridCoverageBuilder gcb = new GridCoverageBuilder();
+        gcb.setValues(img);
+        gcb.setDomain(newGrid);
+        gcb.setRanges(bands.get(0));
+        return gcb.build();
+    }
+
+}


Mime
View raw message