| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.layer;
|
|---|
| 3 |
|
|---|
| 4 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
|---|
| 5 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
|---|
| 6 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
|---|
| 7 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|---|
| 8 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
|---|
| 9 |
|
|---|
| 10 | import java.awt.Point;
|
|---|
| 11 | import java.util.Collection;
|
|---|
| 12 | import java.util.Map;
|
|---|
| 13 | import java.util.concurrent.atomic.AtomicBoolean;
|
|---|
| 14 |
|
|---|
| 15 | import org.junit.jupiter.api.BeforeEach;
|
|---|
| 16 | import org.junit.jupiter.api.Test;
|
|---|
| 17 | import org.openstreetmap.gui.jmapviewer.Coordinate;
|
|---|
| 18 | import org.openstreetmap.gui.jmapviewer.Projected;
|
|---|
| 19 | import org.openstreetmap.gui.jmapviewer.Tile;
|
|---|
| 20 | import org.openstreetmap.gui.jmapviewer.TileRange;
|
|---|
| 21 | import org.openstreetmap.gui.jmapviewer.TileXY;
|
|---|
| 22 | import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
|
|---|
| 23 | import org.openstreetmap.gui.jmapviewer.interfaces.IProjected;
|
|---|
| 24 | import org.openstreetmap.gui.jmapviewer.interfaces.TileCache;
|
|---|
| 25 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
|
|---|
| 26 | import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
|
|---|
| 27 | import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
|
|---|
| 28 | import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
|
|---|
| 29 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
|---|
| 30 | import org.openstreetmap.josm.data.imagery.TileLoaderFactory;
|
|---|
| 31 | import org.openstreetmap.josm.data.osm.DataSet;
|
|---|
| 32 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 33 | import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings;
|
|---|
| 34 | import org.openstreetmap.josm.testutils.annotations.Main;
|
|---|
| 35 | import org.openstreetmap.josm.testutils.annotations.Projection;
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Test of the base {@link AbstractTileSourceLayer} class
|
|---|
| 39 | */
|
|---|
| 40 | @Projection
|
|---|
| 41 | @Main
|
|---|
| 42 | class AbstractTileSourceLayerTest {
|
|---|
| 43 | private static final class TMSTileStubSource extends AbstractTMSTileSource {
|
|---|
| 44 | private TMSTileStubSource() {
|
|---|
| 45 | super(new TileSourceInfo());
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | @Override
|
|---|
| 49 | public double getDistance(double la1, double lo1, double la2, double lo2) {
|
|---|
| 50 | // TODO Auto-generated method stub
|
|---|
| 51 | return 0;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | @Override
|
|---|
| 55 | public Point latLonToXY(double lat, double lon, int zoom) {
|
|---|
| 56 | // TODO Auto-generated method stub
|
|---|
| 57 | return null;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | @Override
|
|---|
| 61 | public ICoordinate xyToLatLon(int x, int y, int zoom) {
|
|---|
| 62 | // TODO Auto-generated method stub
|
|---|
| 63 | return null;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | @Override
|
|---|
| 67 | public TileXY latLonToTileXY(double lat, double lon, int zoom) {
|
|---|
| 68 | return new TileXY(lon / 2, lat / 2);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | @Override
|
|---|
| 72 | public ICoordinate tileXYToLatLon(int x, int y, int zoom) {
|
|---|
| 73 | return new Coordinate(2*y, 2*x);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | @Override
|
|---|
| 77 | public IProjected tileXYtoProjected(int x, int y, int zoom) {
|
|---|
| 78 | return new Projected(2*x, 2*y);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | @Override
|
|---|
| 82 | public TileXY projectedToTileXY(IProjected p, int zoom) {
|
|---|
| 83 | return new TileXY(p.getEast() / 2, p.getNorth() / 2);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | @Override
|
|---|
| 87 | public boolean isInside(Tile inner, Tile outer) {
|
|---|
| 88 | // TODO Auto-generated method stub
|
|---|
| 89 | return false;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | @Override
|
|---|
| 93 | public TileRange getCoveringTileRange(Tile tile, int newZoom) {
|
|---|
| 94 | // TODO Auto-generated method stub
|
|---|
| 95 | return null;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | @Override
|
|---|
| 99 | public String getServerCRS() {
|
|---|
| 100 | return "EPSG:3857";
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | private static class TileSourceStubLayer extends AbstractTileSourceLayer<AbstractTMSTileSource> {
|
|---|
| 105 |
|
|---|
| 106 | TileSourceStubLayer() {
|
|---|
| 107 | super(new ImageryInfo());
|
|---|
| 108 | hookUpMapView();
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | @Override
|
|---|
| 112 | protected TileLoaderFactory getTileLoaderFactory() {
|
|---|
| 113 | return new TileLoaderFactory() {
|
|---|
| 114 | @Override
|
|---|
| 115 | public TileLoader makeTileLoader(TileLoaderListener listener, Map<String, String> headers,
|
|---|
| 116 | long minimumExpiryTime) {
|
|---|
| 117 | return null;
|
|---|
| 118 | }
|
|---|
| 119 | };
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | @Override
|
|---|
| 123 | public Collection<String> getNativeProjections() {
|
|---|
| 124 | return null;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | @Override
|
|---|
| 128 | protected AbstractTMSTileSource getTileSource() {
|
|---|
| 129 | return new TMSTileStubSource();
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | TileCache getTileCache() {
|
|---|
| 133 | return tileCache;
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | private TileSourceStubLayer testLayer;
|
|---|
| 138 | AtomicBoolean invalidated = new AtomicBoolean();
|
|---|
| 139 |
|
|---|
| 140 | /**
|
|---|
| 141 | * Create test layer
|
|---|
| 142 | */
|
|---|
| 143 | @BeforeEach
|
|---|
| 144 | public void setUp() {
|
|---|
| 145 | MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(), "", null));
|
|---|
| 146 | testLayer = new TileSourceStubLayer();
|
|---|
| 147 | testLayer.addInvalidationListener(l -> invalidated.set(true));
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | /**
|
|---|
| 151 | * Test {@link AbstractTileSourceLayer#filterChanged}
|
|---|
| 152 | */
|
|---|
| 153 | @Test
|
|---|
| 154 | void testFilterChanged() {
|
|---|
| 155 | try {
|
|---|
| 156 | ImageryFilterSettings filterSettings = new ImageryFilterSettings();
|
|---|
| 157 | filterSettings.addFilterChangeListener(testLayer);
|
|---|
| 158 | assertFalse(invalidated.get());
|
|---|
| 159 | filterSettings.setGamma(0.5);
|
|---|
| 160 | assertTrue(invalidated.get());
|
|---|
| 161 | } finally {
|
|---|
| 162 | invalidated.set(false);
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /**
|
|---|
| 167 | * Test {@link AbstractTileSourceLayer#clearTileCache}
|
|---|
| 168 | */
|
|---|
| 169 | @Test
|
|---|
| 170 | void testClearTileCache() {
|
|---|
| 171 | testLayer.loadAllTiles(true);
|
|---|
| 172 | assertTrue(testLayer.getTileCache().getTileCount() > 0);
|
|---|
| 173 | testLayer.clearTileCache();
|
|---|
| 174 | assertEquals(0, testLayer.getTileCache().getTileCount());
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | /**
|
|---|
| 178 | * Test {@link AbstractTileSourceLayer#getAdjustAction}
|
|---|
| 179 | */
|
|---|
| 180 | @Test
|
|---|
| 181 | void testGetAdjustAction() {
|
|---|
| 182 | assertNotNull(testLayer.getAdjustAction());
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | /**
|
|---|
| 186 | * Test {@link AbstractTileSourceLayer#getInfoComponent}
|
|---|
| 187 | */
|
|---|
| 188 | @Test
|
|---|
| 189 | void testGetInfoComponent() {
|
|---|
| 190 | assertNotNull(testLayer.getInfoComponent());
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | /**
|
|---|
| 194 | * Test {@link AbstractTileSourceLayer.TileSourceLayerPopup}
|
|---|
| 195 | */
|
|---|
| 196 | @Test
|
|---|
| 197 | void testTileSourceLayerPopup() {
|
|---|
| 198 | assertDoesNotThrow(() -> testLayer.new TileSourceLayerPopup(100, 100));
|
|---|
| 199 | }
|
|---|
| 200 | }
|
|---|