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

Last change on this file since 18690 was 18690, checked in by taylor.smock, 14 months ago

See #16567: Convert all assertion calls to JUnit 5 (patch by gaben, modified)

The modifications are as follows:

  • Merge DomainValidatorTest.testIDN and DomainValidatorTest.testIDNJava6OrLater
  • Update some tests to use @ParameterizedTest (DomainValidatorTest)
  • Replace various exception blocks with assertThrows. These typically looked like
        try {
            // Something that should throw an exception here
            fail("An exception should have been thrown");
        } catch (Exception e) {
            // Verify the exception matches expectations here
        }
    
  • Replace assertTrue(val instanceof Clazz) with assertInstanceOf
  • Replace JUnit 4 @Suite with JUnit 5 @Suite

Both the original patch and the modified patch fix various lint issues.

  • Property svn:eol-style set to native
File size: 5.5 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.PerformanceTestUtils;
21import org.openstreetmap.josm.data.Bounds;
22import org.openstreetmap.josm.data.osm.DataSet;
23import org.openstreetmap.josm.gui.NavigatableComponent;
24import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
25import org.openstreetmap.josm.io.Compression;
26import org.openstreetmap.josm.io.OsmReader;
27
28import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
29
30/**
31 * Abstract superclass of {@code StyledMapRendererPerformanceTest} and {@code WireframeMapRendererPerformanceTest}.
32 */
33@Timeout(value = 15, unit = TimeUnit.MINUTES)
34abstract class AbstractMapRendererPerformanceTestParent {
35
36 private static final int IMG_WIDTH = 1400;
37 private static final int IMG_HEIGHT = 1050;
38
39 @SuppressFBWarnings(value = "MS_PKGPROTECT")
40 protected static Graphics2D g;
41 @SuppressFBWarnings(value = "MS_PKGPROTECT")
42 protected static BufferedImage img;
43 @SuppressFBWarnings(value = "MS_PKGPROTECT")
44 protected static NavigatableComponent nc;
45 private static DataSet dsRestriction;
46 private static DataSet dsMultipolygon;
47 private static DataSet dsOverpass;
48 private static DataSet dsCity;
49
50 protected static void load() throws Exception {
51 JOSMFixture.createPerformanceTestFixture().init(true);
52 img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
53 g = (Graphics2D) img.getGraphics();
54 g.setClip(0, 0, IMG_WIDTH, IMG_HEIGHT);
55 g.setColor(Color.BLACK);
56 g.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT);
57 nc = new NavigatableComponent() {
58 {
59 setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
60 updateLocationState();
61 }
62
63 @Override
64 protected boolean isVisibleOnScreen() {
65 return true;
66 }
67
68 @Override
69 public Point getLocationOnScreen() {
70 return new Point(0, 0);
71 }
72 };
73
74 // Force reset of preferences
75 StyledMapRenderer.PREFERENCE_ANTIALIASING_USE.put(true);
76 StyledMapRenderer.PREFERENCE_TEXT_ANTIALIASING.put("gasp");
77
78 dsCity = PerformanceTestUtils.getNeubrandenburgDataSet();
79 try (InputStream fisR = Files.newInputStream(Paths.get("nodist/data/restriction.osm"));
80 InputStream fisM = Files.newInputStream(Paths.get("nodist/data/multipolygon.osm"));
81 InputStream fisO = Compression.getUncompressedFileInputStream(new File("nodist/data/overpass-download.osm.bz2"))) {
82 dsRestriction = OsmReader.parseDataSet(fisR, NullProgressMonitor.INSTANCE);
83 dsMultipolygon = OsmReader.parseDataSet(fisM, 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 /**
128 * Complex polygon (Lake Ontario) with small download area.
129 */
130 @Test
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.