source: josm/trunk/test/performance/org/openstreetmap/josm/data/osm/visitor/paint/AbstractMapRendererPerformanceTestParent.java@ 17275

Last change on this file since 17275 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 5.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm.visitor.paint;
3
4import java.awt.Color;
5import java.awt.Graphics2D;
6import java.awt.Point;
7import java.awt.image.BufferedImage;
8import java.io.File;
9import java.io.IOException;
10import java.io.InputStream;
11import java.nio.file.Files;
12import java.nio.file.Paths;
13import java.util.concurrent.TimeUnit;
14
15import javax.imageio.ImageIO;
16
17import org.junit.jupiter.api.Test;
18import org.junit.jupiter.api.Timeout;
19import org.openstreetmap.josm.JOSMFixture;
20import org.openstreetmap.josm.data.Bounds;
21import org.openstreetmap.josm.data.osm.DataSet;
22import org.openstreetmap.josm.gui.NavigatableComponent;
23import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
24import org.openstreetmap.josm.io.Compression;
25import org.openstreetmap.josm.io.OsmReader;
26
27import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
28
29/**
30 * Abstract superclass of {@code StyledMapRendererPerformanceTest} and {@code WireframeMapRendererPerformanceTest}.
31 */
32@Timeout(value = 15*60, unit = TimeUnit.SECONDS)
33abstract class AbstractMapRendererPerformanceTestParent {
34
35 private static final int IMG_WIDTH = 1400;
36 private static final int IMG_HEIGHT = 1050;
37
38 @SuppressFBWarnings(value = "MS_PKGPROTECT")
39 protected static Graphics2D g;
40 @SuppressFBWarnings(value = "MS_PKGPROTECT")
41 protected static BufferedImage img;
42 @SuppressFBWarnings(value = "MS_PKGPROTECT")
43 protected static NavigatableComponent nc;
44 private static DataSet dsRestriction;
45 private static DataSet dsMultipolygon;
46 private static DataSet dsOverpass;
47 private static DataSet dsCity;
48
49 protected static void load() throws Exception {
50 JOSMFixture.createPerformanceTestFixture().init(true);
51 img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
52 g = (Graphics2D) img.getGraphics();
53 g.setClip(0, 0, IMG_WIDTH, IMG_HEIGHT);
54 g.setColor(Color.BLACK);
55 g.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT);
56 nc = new NavigatableComponent() {
57 {
58 setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
59 updateLocationState();
60 }
61
62 @Override
63 protected boolean isVisibleOnScreen() {
64 return true;
65 }
66
67 @Override
68 public Point getLocationOnScreen() {
69 return new Point(0, 0);
70 }
71 };
72
73 // Force reset of preferences
74 StyledMapRenderer.PREFERENCE_ANTIALIASING_USE.put(true);
75 StyledMapRenderer.PREFERENCE_TEXT_ANTIALIASING.put("gasp");
76
77 try (InputStream fisR = Files.newInputStream(Paths.get("nodist/data/restriction.osm"));
78 InputStream fisM = Files.newInputStream(Paths.get("nodist/data/multipolygon.osm"));
79 InputStream fisC = Compression.getUncompressedFileInputStream(new File("nodist/data/neubrandenburg.osm.bz2"));
80 InputStream fisO = Compression.getUncompressedFileInputStream(new File("nodist/data/overpass-download.osm.bz2"));) {
81 dsRestriction = OsmReader.parseDataSet(fisR, NullProgressMonitor.INSTANCE);
82 dsMultipolygon = OsmReader.parseDataSet(fisM, NullProgressMonitor.INSTANCE);
83 dsCity = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE);
84 dsOverpass = OsmReader.parseDataSet(fisO, NullProgressMonitor.INSTANCE);
85 }
86 }
87
88 protected static void clean() throws Exception {
89 g = null;
90 img = null;
91 nc = null;
92 dsRestriction = null;
93 dsMultipolygon = null;
94 dsCity = null;
95 }
96
97 protected abstract Rendering buildRenderer();
98
99 protected final void test(int iterations, DataSet ds, Bounds bounds) throws Exception {
100 nc.zoomTo(bounds);
101 Rendering visitor = buildRenderer();
102 for (int i = 0; i < iterations; i++) {
103 visitor.render(ds, true, bounds);
104 }
105 }
106
107 @Test
108 void testRestriction() throws Exception {
109 test(700, dsRestriction, new Bounds(51.12, 14.147472381591795, 51.128, 14.162492752075195));
110 }
111
112 @Test
113 void testRestrictionSmall() throws Exception {
114 test(1500, dsRestriction, new Bounds(51.125, 14.147, 51.128, 14.152));
115 }
116
117 @Test
118 void testMultipolygon() throws Exception {
119 test(400, dsMultipolygon, new Bounds(60, -180, 85, -122));
120 }
121
122 @Test
123 void testMultipolygonSmall() throws Exception {
124 test(850, dsMultipolygon, new Bounds(-90, -180, 90, 180));
125 }
126
127 @Test
128 /**
129 * Complex polygon (Lake Ontario) with small download area.
130 */
131 void testOverpassDownload() throws Exception {
132 test(20, dsOverpass, new Bounds(43.4510496, -76.536684, 43.4643202, -76.4954853));
133 }
134
135 @Test
136 void testCity() throws Exception {
137 test(50, dsCity, new Bounds(53.51, 13.20, 53.59, 13.34));
138 }
139
140 @Test
141 void testCitySmall() throws Exception {
142 test(70, dsCity, new Bounds(52, 11, 55, 14));
143 }
144
145 @Test
146 void testCityPart1() throws Exception {
147 test(250, dsCity, new Bounds(53.56, 13.25, 53.57, 13.26));
148 }
149
150 @Test
151 void testCityPart2() throws Exception {
152 test(200, dsCity, new Bounds(53.55, 13.29, 53.57, 13.30));
153 }
154
155 @Test
156 void testCitySmallPart2() throws Exception {
157 test(200, dsCity, new Bounds(53.56, 13.295, 53.57, 13.30));
158 }
159
160 /**
161 * run this manually to verify that the rendering is set up properly
162 * @throws IOException if any I/O error occurs
163 */
164 @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD")
165 private void dumpRenderedImage() throws IOException {
166 ImageIO.write(img, "png", new File("test-neubrandenburg.png"));
167 }
168}
Note: See TracBrowser for help on using the repository browser.