sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Add the possibility to run `SelfConsistencyTest` on an arbitrary image put in the test data directory.
Date Tue, 06 Jul 2021 16:19:53 GMT
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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 9df65c0  Add the possibility to run `SelfConsistencyTest` on an arbitrary image put
in the test data directory.
9df65c0 is described below

commit 9df65c0793fc37df8430d3c0e7f94f3f8e87c6dd
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jul 6 18:17:54 2021 +0200

    Add the possibility to run `SelfConsistencyTest` on an arbitrary image put in the test
data directory.
---
 .../java/org/apache/sis/test/OptionalTestData.java | 31 +++++---
 storage/sis-geotiff/pom.xml                        |  7 ++
 .../sis/storage/geotiff/SelfConsistencyTest.java   | 85 ++++++++++++++++++++++
 .../apache/sis/test/suite/GeoTiffTestSuite.java    |  5 +-
 4 files changed, 114 insertions(+), 14 deletions(-)

diff --git a/core/sis-utility/src/test/java/org/apache/sis/test/OptionalTestData.java b/core/sis-utility/src/test/java/org/apache/sis/test/OptionalTestData.java
index 176a297..9f7307b 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/test/OptionalTestData.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/test/OptionalTestData.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.test;
 
+import java.util.Optional;
 import java.io.LineNumberReader;
 import java.io.IOException;
 import java.io.InputStream;
@@ -24,7 +25,7 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import org.apache.sis.internal.system.DataDirectory;
 
-import static org.junit.Assume.assumeNotNull;
+import static org.junit.Assume.assumeTrue;
 
 
 /**
@@ -33,7 +34,7 @@ import static org.junit.Assume.assumeNotNull;
  * order to enable the tests requiring those data.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   1.0
  * @module
  */
@@ -94,7 +95,13 @@ public enum OptionalTestData {
      *   <li>S₁₂ — the area between the geodesic and the equator (m²)</li>
      * </ol>
      */
-    GEODESIC("GeodTest.dat");
+    GEODESIC("GeodTest.dat"),
+
+    /**
+     * Any GeoTIFF image supported by Apache SIS, without any particular expectation on data.
+     * This is used for self-consistency tests.
+     */
+    GEOTIFF("AnyGeoTIFF.tiff");
 
     /**
      * The filename in {@code $SIS_DATA/Tests} directory.
@@ -109,19 +116,19 @@ public enum OptionalTestData {
     }
 
     /**
-     * Returns the path to the test file if {@code $SIS_DATA} is defined an the file exists,
or {@code null} otherwise.
+     * Returns the path to the test file if {@code $SIS_DATA} is defined an the file exists.
      *
-     * @return path to the test file, or {@code null} if none.
+     * @return path to the test file, or an empty optional if none.
      */
-    private Path path() {
+    public Optional<Path> path() {
         Path path = DataDirectory.TESTS.getDirectory();
         if (path != null) {
             path = path.resolve(filename);
             if (Files.isRegularFile(path)) {
-                return path;
+                return Optional.of(path);
             }
         }
-        return null;
+        return Optional.empty();
     }
 
     /**
@@ -132,10 +139,10 @@ public enum OptionalTestData {
      * @return an input stream for the test file represented by this enumeration.
      * @throws IOException if an error occurred while opening the test file.
      */
-    public InputStream open() throws IOException {
-        final Path path = path();
-        assumeNotNull("File “$SIS_DATA/Tests/" + filename + "” has not been found.",
path);
-        return Files.newInputStream(path);
+    private InputStream open() throws IOException {
+        final Optional<Path> path = path();
+        assumeTrue("File “$SIS_DATA/Tests/" + filename + "” has not been found.", path.isPresent());
+        return Files.newInputStream(path.get());
     }
 
     /**
diff --git a/storage/sis-geotiff/pom.xml b/storage/sis-geotiff/pom.xml
index 007e204..5cb9a4f 100644
--- a/storage/sis-geotiff/pom.xml
+++ b/storage/sis-geotiff/pom.xml
@@ -125,6 +125,13 @@
       <artifactId>sis-storage</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.sis.storage</groupId>
+      <artifactId>sis-storage</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>
diff --git a/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/SelfConsistencyTest.java
b/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/SelfConsistencyTest.java
new file mode 100644
index 0000000..92e0723
--- /dev/null
+++ b/storage/sis-geotiff/src/test/java/org/apache/sis/storage/geotiff/SelfConsistencyTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.storage.geotiff;
+
+import java.util.Optional;
+import java.nio.file.Path;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.test.OptionalTestData;
+import org.apache.sis.test.storage.CoverageReadConsistency;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import static org.junit.Assume.assumeNotNull;
+
+
+/**
+ * Test consistency of read operations in random domains.
+ * Assuming that the code reading the full extent is correct, this class can detect some
bugs
+ * in the code reading sub-regions or applying sub-sampling. This assumption is reasonable
if
+ * we consider that the code reading the full extent is usually simpler than the code reading
+ * a subset of data.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.1
+ * @since   1.1
+ * @module
+ */
+public final strictfp class SelfConsistencyTest extends CoverageReadConsistency {
+    /**
+     * The file used for the test, opened only once.
+     */
+    private static GeoTiffStore store;
+
+    /**
+     * Opens the test file to be used for all tests.
+     *
+     * @throws DataStoreException if an error occurred while opening the file.
+     */
+    @BeforeClass
+    public static void openFile() throws DataStoreException {
+        final Optional<Path> path = OptionalTestData.GEOTIFF.path();
+        if (path.isPresent()) {
+            store = new GeoTiffStore(null, new StorageConnector(path.get()));
+        }
+        assumeNotNull(store);
+    }
+
+    /**
+     * Closes the test file to be used for all tests.
+     *
+     * @throws DataStoreException if an error occurred while closing the file.
+     */
+    @AfterClass
+    public static void closeFile() throws DataStoreException {
+        final GeoTiffStore s = store;
+        if (s != null) {
+            store = null;       // Clear first in case of failure.
+            s.close();
+        }
+    }
+
+    /**
+     * Creates a new test case.
+     *
+     * @throws DataStoreException if an error occurred while fetching the first image.
+     */
+    public SelfConsistencyTest() throws DataStoreException {
+        super(store.components().iterator().next());
+    }
+}
diff --git a/storage/sis-geotiff/src/test/java/org/apache/sis/test/suite/GeoTiffTestSuite.java
b/storage/sis-geotiff/src/test/java/org/apache/sis/test/suite/GeoTiffTestSuite.java
index 5c25f9f..02c55ff 100644
--- a/storage/sis-geotiff/src/test/java/org/apache/sis/test/suite/GeoTiffTestSuite.java
+++ b/storage/sis-geotiff/src/test/java/org/apache/sis/test/suite/GeoTiffTestSuite.java
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
  * All tests from the {@code sis-geotiff} module, in rough dependency order.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @version 1.1
  * @since   0.8
  * @module
  */
@@ -33,7 +33,8 @@ import org.junit.BeforeClass;
     org.apache.sis.storage.geotiff.TypeTest.class,
     org.apache.sis.storage.geotiff.CompressionTest.class,
     org.apache.sis.storage.geotiff.GeoKeysTest.class,
-    org.apache.sis.storage.geotiff.CRSBuilderTest.class
+    org.apache.sis.storage.geotiff.CRSBuilderTest.class,
+    org.apache.sis.storage.geotiff.SelfConsistencyTest.class
 })
 public final strictfp class GeoTiffTestSuite extends TestSuite {
     /**

Mime
View raw message