Changeset 11215 in josm for trunk/test/functional/org
- Timestamp:
- 2016-11-04T01:16:28+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/functional/org/openstreetmap/josm/gui/mappaint/StyleCacheTest.java
r9770 r11215 9 9 import java.io.File; 10 10 import java.io.InputStream; 11 import java.util.IdentityHashMap; 11 12 13 import org.junit.Assert; 12 14 import org.junit.BeforeClass; 13 15 import org.junit.Test; … … 16 18 import org.openstreetmap.josm.data.Bounds; 17 19 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 21 import org.openstreetmap.josm.data.osm.visitor.paint.Rendering; 19 22 import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer; … … 22 25 import org.openstreetmap.josm.io.Compression; 23 26 import org.openstreetmap.josm.io.OsmReader; 27 import org.openstreetmap.josm.tools.Pair; 24 28 25 29 /** 26 30 * Test {@link StyleCache}. 27 *28 * Verifies, that the intern pool is not growing when repeatedly rendering the29 * same set of primitives (and clearing the calculated styles each time).30 *31 * If it grows, this is an indication that the {@code equals} and {@code hashCode}32 * implementation is broken and two identical objects are not recognized as equal33 * or produce different hash codes.34 *35 * The opposite problem (different objects are mistaken as equal) has more visible36 * consequences for the user (wrong rendering on the map) and is not recognized by37 * this test.38 31 */ 39 32 public class StyleCacheTest { … … 46 39 private static NavigatableComponent nc; 47 40 private static DataSet dsCity; 41 private static DataSet dsCity2; 48 42 49 43 @BeforeClass … … 64 58 dsCity = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE); 65 59 } 60 try ( 61 InputStream fisC = Compression.getUncompressedFileInputStream(new File("data_nodist/neubrandenburg.osm.bz2")); 62 ) { 63 dsCity2 = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE); 64 } 66 65 } 67 66 67 /** 68 * Verifies, that the intern pool is not growing when repeatedly rendering the 69 * same set of primitives (and clearing the calculated styles each time). 70 * 71 * If it grows, this is an indication that the {@code equals} and {@code hashCode} 72 * implementation is broken and two identical objects are not recognized as equal 73 * or produce different hash codes. 74 * 75 * The opposite problem (different objects are mistaken as equal) has more visible 76 * consequences for the user (wrong rendering on the map) and is not recognized by 77 * this test. 78 */ 68 79 @Test 69 public void testStyleCacheInternPool() throws Exception{80 public void testStyleCacheInternPool() { 70 81 Bounds bounds = new Bounds(53.56, 13.25, 53.57, 13.26); 71 82 Rendering visitor = new StyledMapRenderer(g, nc, false); … … 83 94 } 84 95 } 96 97 /** 98 * Verifies, that the number of {@code StyleElementList} instances stored 99 * for all the rendered primitives is actually low (as intended). 100 * 101 * Two primitives with the same style should share one {@code StyleElementList} 102 * instance for the cached style elements. This is verified by counting all 103 * the instances using {@code A == B} identity. 104 */ 105 @Test 106 public void testStyleCacheInternPool2() { 107 Bounds bounds = new Bounds(53.56, 13.25, 53.57, 13.26); 108 Rendering visitor = new StyledMapRenderer(g, nc, false); 109 nc.zoomTo(bounds); 110 visitor.render(dsCity2, true, bounds); 111 112 IdentityHashMap<StyleElementList, Integer> counter = new IdentityHashMap<>(); 113 int noPrimitives = 0; 114 for (OsmPrimitive osm : dsCity2.allPrimitives()) { 115 // primitives, that have been rendered, should have the cache populated 116 if (osm.mappaintStyle != null) { 117 noPrimitives++; 118 Pair<StyleElementList, Range> p = osm.mappaintStyle.getWithRange(nc.getDist100Pixel(), false); 119 StyleElementList sel = p.a; 120 Assert.assertNotNull(sel); 121 Integer k = counter.get(sel); 122 if (k == null) { 123 k = 0; 124 } 125 counter.put(sel, k + 1); 126 } 127 } 128 int EXPECTED_NO_PRIMITIVES = 4298; // needs to be updated if data file or bbox changes 129 Assert.assertEquals( 130 "The number of rendered primitives should be " + EXPECTED_NO_PRIMITIVES, 131 EXPECTED_NO_PRIMITIVES, noPrimitives); 132 Assert.assertTrue( 133 "Too many StyleElementList instances, they should be shared using the StyleCache", 134 counter.size() < 100); 135 } 85 136 }
Note:
See TracChangeset
for help on using the changeset viewer.