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