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

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

test cleanup

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