2021-12-23 10:42:24 +00:00
|
|
|
package com.onthegomap.planetiler.mbtiles;
|
2021-10-20 01:57:47 +00:00
|
|
|
|
2021-12-23 10:42:24 +00:00
|
|
|
import static com.onthegomap.planetiler.TestUtils.newPolygon;
|
|
|
|
import static com.onthegomap.planetiler.geo.GeoUtils.point;
|
|
|
|
import static com.onthegomap.planetiler.util.Gzip.gzip;
|
2021-10-20 01:57:47 +00:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
2021-12-23 10:42:24 +00:00
|
|
|
import com.onthegomap.planetiler.VectorTile;
|
2023-02-05 19:16:05 +00:00
|
|
|
import com.onthegomap.planetiler.archive.TileEncodingResult;
|
2021-12-23 10:42:24 +00:00
|
|
|
import com.onthegomap.planetiler.geo.TileCoord;
|
2021-10-20 01:57:47 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2022-06-04 00:44:49 +00:00
|
|
|
import java.util.OptionalLong;
|
2021-10-20 01:57:47 +00:00
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
2022-04-23 10:36:24 +00:00
|
|
|
class VerifyTest {
|
2021-10-20 01:57:47 +00:00
|
|
|
|
|
|
|
private Mbtiles mbtiles;
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
public void setup() {
|
|
|
|
mbtiles = Mbtiles.newInMemoryDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
@AfterEach
|
|
|
|
public void teardown() throws IOException {
|
|
|
|
mbtiles.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2022-04-23 10:36:24 +00:00
|
|
|
void testEmptyFileInvalid() {
|
2021-10-20 01:57:47 +00:00
|
|
|
assertInvalid(mbtiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2022-04-23 10:36:24 +00:00
|
|
|
void testEmptyTablesInvalid() {
|
2022-06-02 01:29:59 +00:00
|
|
|
mbtiles.createTablesWithIndexes();
|
2021-10-20 01:57:47 +00:00
|
|
|
assertInvalid(mbtiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2022-04-23 10:36:24 +00:00
|
|
|
void testValidWithNameAndOneTile() throws IOException {
|
2022-06-02 01:29:59 +00:00
|
|
|
mbtiles.createTablesWithIndexes();
|
2021-10-20 01:57:47 +00:00
|
|
|
mbtiles.metadata().setName("name");
|
2023-01-17 12:05:45 +00:00
|
|
|
try (var writer = mbtiles.newTileWriter()) {
|
2021-10-20 01:57:47 +00:00
|
|
|
VectorTile tile = new VectorTile();
|
|
|
|
tile.addLayerFeatures("layer", List.of(new VectorTile.Feature(
|
|
|
|
"layer",
|
|
|
|
1,
|
|
|
|
VectorTile.encodeGeometry(point(0, 0)),
|
|
|
|
Map.of()
|
|
|
|
)));
|
2022-06-04 00:44:49 +00:00
|
|
|
writer.write(new TileEncodingResult(TileCoord.ofXYZ(0, 0, 0), gzip(tile.encode()), OptionalLong.empty()));
|
2021-10-20 01:57:47 +00:00
|
|
|
}
|
|
|
|
assertValid(mbtiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2022-04-23 10:36:24 +00:00
|
|
|
void testInvalidGeometry() throws IOException {
|
2022-06-02 01:29:59 +00:00
|
|
|
mbtiles.createTablesWithIndexes();
|
2021-10-20 01:57:47 +00:00
|
|
|
mbtiles.metadata().setName("name");
|
2023-01-17 12:05:45 +00:00
|
|
|
try (var writer = mbtiles.newTileWriter()) {
|
2021-10-20 01:57:47 +00:00
|
|
|
VectorTile tile = new VectorTile();
|
|
|
|
tile.addLayerFeatures("layer", List.of(new VectorTile.Feature(
|
|
|
|
"layer",
|
|
|
|
1,
|
|
|
|
// self-intersecting bow-tie shape
|
|
|
|
VectorTile.encodeGeometry(newPolygon(
|
|
|
|
0, 0,
|
|
|
|
10, 0,
|
|
|
|
0, 10,
|
|
|
|
10, 10,
|
|
|
|
0, 0
|
|
|
|
)),
|
|
|
|
Map.of()
|
|
|
|
)));
|
2022-06-04 00:44:49 +00:00
|
|
|
writer.write(new TileEncodingResult(TileCoord.ofXYZ(0, 0, 0), gzip(tile.encode()), OptionalLong.empty()));
|
2021-10-20 01:57:47 +00:00
|
|
|
}
|
|
|
|
assertInvalid(mbtiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertInvalid(Mbtiles mbtiles) {
|
|
|
|
assertTrue(Verify.verify(mbtiles).numErrors() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertValid(Mbtiles mbtiles) {
|
|
|
|
assertEquals(0, Verify.verify(mbtiles).numErrors());
|
|
|
|
}
|
|
|
|
}
|