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

Last change on this file since 7141 was 7141, checked in by bastiK, 10 years ago

see #9691 - fix unit test

  • Property svn:eol-style set to native
File size: 3.9 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.Main
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.MainApplication
15import org.openstreetmap.josm.gui.layer.OsmDataLayer
16import org.openstreetmap.josm.gui.mappaint.MapPaintStyles
17import org.openstreetmap.josm.gui.preferences.SourceEntry
18import org.openstreetmap.josm.io.Compression
19import org.openstreetmap.josm.io.OsmReader
20
21/**
22 * This performance test measures the time for a full run of MapPaintVisitor.visitAll()
23 * against a test data set using a test style.
24 *
25 */
26class MapCSSPerformanceTest {
27
28 /* ------------------------ configuration section ---------------------------- */
29 /**
30 * The path to the JOSM home environment
31 */
32 def static JOSM_HOME="test/config/performance-josm.home"
33
34 /**
35 * The path to the style file used for rendering.
36 */
37 def static STYLE_FILE="styles/standard/elemstyles.mapcss"
38
39 /**
40 * The data file to be rendered
41 */
42 def static DATA_FILE = "data_nodist/neubrandenburg.osm.bz2"
43 /* ------------------------ / configuration section ---------------------------- */
44
45 def DataSet ds
46
47 def static boolean checkTestEnvironment() {
48 File f = new File(JOSM_HOME)
49 if (!f.isDirectory() || !f.exists()) {
50 fail("JOSM_HOME refers to '${JOSM_HOME}. This is either not a directory or doesn't exist.\nPlease update configuration settings in the unit test file.")
51 }
52
53 f = new File(STYLE_FILE);
54 if ( !f.isFile() || ! f.exists()) {
55 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.")
56 }
57 }
58
59 @BeforeClass
60 public static void createJOSMFixture(){
61 checkTestEnvironment()
62 System.setProperty("josm.home", JOSM_HOME)
63 MainApplication.main(new String[0])
64 }
65
66 def timed(Closure c){
67 long before = System.currentTimeMillis()
68 c()
69 long after = System.currentTimeMillis()
70 return after - before
71 }
72
73 def loadStyle() {
74 print "Loading style '$STYLE_FILE' ..."
75 MapCSSStyleSource source = new MapCSSStyleSource(
76 new SourceEntry(
77 STYLE_FILE,
78 "test style",
79 "a test style",
80 true // active
81 )
82 )
83 source.loadStyleSource()
84 if (!source.errors.isEmpty()) {
85 fail("Failed to load style file ''${STYLE_FILE}''. Errors: ${source.errors}")
86 }
87 MapPaintStyles.getStyles().clear()
88 MapPaintStyles.getStyles().add(source)
89 println "DONE"
90 }
91
92 def loadData() {
93 print "Loading data file '$DATA_FILE' ..."
94 ds = OsmReader.parseDataSet(Compression.getUncompressedFileInputStream(new File(DATA_FILE)), null);
95 Main.main.addLayer(new OsmDataLayer(ds,"test layer",null /* no file */));
96 println "DONE"
97 }
98
99 @Test
100 public void measureTimeForStylePreparation() {
101 loadStyle()
102 loadData()
103
104 def mv = Main.map.mapView
105
106 BufferedImage img = new BufferedImage(mv.getWidth(), mv.getHeight(), BufferedImage.TYPE_3BYTE_BGR)
107 Graphics2D g = img.createGraphics()
108 g.setClip(0,0, mv.getWidth(), mv.getHeight())
109 def visitor = new StyledMapRenderer(g, Main.map.mapView, false)
110
111 print "Rendering ..."
112 long time = timed {
113 visitor.render(ds, false, new Bounds(-90,-180,90,180))
114 }
115 println "DONE"
116 println "data file : ${DATA_FILE}"
117 println "style file: ${STYLE_FILE}"
118 println ""
119 println "Rendering took $time ms."
120 }
121}
Note: See TracBrowser for help on using the repository browser.