source: josm/trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSPerformanceTest.groovy @ 7535

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

fix unit test

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import static org.junit.Assert.*
5
6import java.awt.Graphics2D
7import java.awt.image.BufferedImage
8
9import org.junit.*
10import org.openstreetmap.josm.JOSMFixture
11import org.openstreetmap.josm.data.Bounds
12import org.openstreetmap.josm.data.osm.DataSet
13import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer
14import org.openstreetmap.josm.gui.NavigatableComponent
15import org.openstreetmap.josm.gui.mappaint.MapPaintStyles
16import org.openstreetmap.josm.gui.preferences.SourceEntry
17import org.openstreetmap.josm.io.Compression
18import org.openstreetmap.josm.io.OsmReader
19
20/**
21 * This performance test measures the time for a full run of MapPaintVisitor.visitAll()
22 * against a test data set using a test style.
23 *
24 */
25class MapCSSPerformanceTest {
26
27    /* ------------------------ configuration section  ---------------------------- */
28    /**
29     * The path to the style file used for rendering.
30     */
31    def static STYLE_FILE="styles/standard/elemstyles.mapcss"
32
33    /**
34     * The data file to be rendered
35     */
36    def static DATA_FILE = "data_nodist/neubrandenburg.osm.bz2"
37    /* ------------------------ / configuration section  ---------------------------- */
38
39    def DataSet ds
40
41    def static boolean checkTestEnvironment() {
42          File f = new File(STYLE_FILE);
43          if ( !f.isFile() || ! f.exists()) {
44              fail("STYLE_FILE refers to '${STYLE_FILE}. This is either not a file or doesn't exist.\nPlease update configuration settings in the unit test file.")
45          }
46    }
47
48    @BeforeClass
49    public static void createJOSMFixture() {
50        JOSMFixture.createPerformanceTestFixture().init(true);
51    }
52
53    def timed(Closure c){
54        long before = System.currentTimeMillis()
55        c()
56        long after = System.currentTimeMillis()
57        return after - before
58    }
59
60    def loadStyle() {
61        print "Loading style '$STYLE_FILE' ..."
62        MapCSSStyleSource source = new MapCSSStyleSource(
63            new SourceEntry(
64                STYLE_FILE,
65                "test style",
66                "a test style",
67                true // active
68            )
69        )
70        source.loadStyleSource()
71        if (!source.errors.isEmpty()) {
72            fail("Failed to load style file ''${STYLE_FILE}''. Errors: ${source.errors}")
73        }
74        MapPaintStyles.getStyles().clear()
75        MapPaintStyles.getStyles().add(source)
76        println "DONE"
77    }
78
79    def loadData() {
80        print "Loading data file '$DATA_FILE' ..."
81        ds = OsmReader.parseDataSet(Compression.getUncompressedFileInputStream(new File(DATA_FILE)), null);
82        println "DONE"
83    }
84
85    @Test
86    public void measureTimeForStylePreparation() {
87        loadStyle()
88        loadData()
89
90        NavigatableComponent mv = new NavigatableComponent();
91        mv.setBounds(0, 0, 1024, 768)
92        BufferedImage img = new BufferedImage(mv.getWidth(), mv.getHeight(), BufferedImage.TYPE_3BYTE_BGR)
93        Graphics2D g = img.createGraphics()
94        g.setClip(0,0, mv.getWidth(), mv.getHeight())
95        StyledMapRenderer visitor = new StyledMapRenderer(g, mv, false)
96
97        print "Rendering ..."
98        long time = timed {
99            visitor.render(ds, false, new Bounds(-90,-180,90,180))
100        }
101        println "DONE"
102        println "data file : ${DATA_FILE}"
103        println "style file: ${STYLE_FILE}"
104        println ""
105        println "Rendering took $time ms."
106    }
107}
Note: See TracBrowser for help on using the repository browser.