Changeset 3367 in josm for trunk/test/unit
- Timestamp:
- 2010-07-08T08:41:20+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/osm/FilterTest.java
r3358 r3367 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import static org.junit.Assert.assertNotNull; 5 import static org.junit.Assert.assertTrue; 6 4 7 import java.io.FileInputStream; 5 8 import java.io.FileNotFoundException; 6 7 9 import java.util.Arrays; 8 10 import java.util.Collection; … … 11 13 import java.util.List; 12 14 13 import static org.junit.Assert.assertEquals;14 import static org.junit.Assert.assertNotNull;15 import static org.junit.Assert.assertTrue;16 15 import org.junit.BeforeClass; 17 16 import org.junit.Test; 18 19 17 import org.openstreetmap.josm.Main; 20 18 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode; … … 31 29 Main.proj = new Mercator(); 32 30 } 33 31 34 32 @Test 35 33 public void basic_test() throws ParseError { … … 40 38 n2.put("fixme", "continue"); 41 39 ds.addPrimitive(n1); 40 ds.addPrimitive(n2); 42 41 OsmPrimitive p = ds.getPrimitiveById(1,OsmPrimitiveType.NODE); 43 42 assertNotNull(p); … … 63 62 @Test 64 63 public void filter_test() throws ParseError, IllegalDataException, FileNotFoundException { 65 for (int i : new int [] {1,2,3, 11,12,13,14 }) {64 for (int i : new int [] {1,2,3, 11,12,13,14, 15}) { 66 65 DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/filterTests.osm"), NullProgressMonitor.INSTANCE); 67 66 68 67 List<Filter> filters = new LinkedList<Filter>(); 69 68 switch (i) { 70 case 1: { 71 Filter f1 = new Filter(); 72 f1.text = "power"; 73 f1.hiding = true; 74 filters.add(f1); 75 break; 76 } 77 case 2: { 78 Filter f1 = new Filter(); 79 f1.text = "highway"; 80 f1.inverted = true; 81 filters.add(f1); 82 break; 83 } 84 case 3: { 85 Filter f1 = new Filter(); 86 f1.text = "power"; 87 f1.inverted = true; 88 f1.hiding = true; 89 Filter f2 = new Filter(); 90 f2.text = "highway"; 91 filters.addAll(Arrays.asList(new Filter[] {f1, f2})); 92 break; 93 } 94 case 11: { 95 Filter f1 = new Filter(); 96 f1.text = "highway"; 97 f1.inverted = true; 98 f1.hiding = true; 99 filters.add(f1); 100 break; 101 } 102 case 12: { 103 Filter f1 = new Filter(); 104 f1.text = "highway"; 105 f1.inverted = true; 106 f1.hiding = true; 107 Filter f2 = new Filter(); 108 f2.text = "water"; 109 f2.mode = SearchMode.remove; 110 filters.addAll(Arrays.asList(new Filter[] {f1, f2})); 111 break; 112 } 113 case 13: { 114 Filter f1 = new Filter(); 115 f1.text = "highway"; 116 f1.inverted = true; 117 f1.hiding = true; 118 Filter f2 = new Filter(); 119 f2.text = "water"; 120 f2.mode = SearchMode.remove; 121 Filter f3 = new Filter(); 122 f3.text = "natural"; 123 filters.addAll(Arrays.asList(new Filter[] {f1, f2, f3})); 124 break; 125 } 126 case 14: { 127 /* show all highways and all water features, but not lakes 128 * except those that have a name */ 129 Filter f1 = new Filter(); 130 f1.text = "highway"; 131 f1.inverted = true; 132 f1.hiding = true; 133 Filter f2 = new Filter(); 134 f2.text = "water"; 135 f2.mode = SearchMode.remove; 136 Filter f3 = new Filter(); 137 f3.text = "natural"; 138 Filter f4 = new Filter(); 139 f4.text = "name"; 140 f4.mode = SearchMode.remove; 141 filters.addAll(Arrays.asList(new Filter[] {f1, f2, f3, f4})); 142 break; 143 } 69 case 1: { 70 Filter f1 = new Filter(); 71 f1.text = "power"; 72 f1.hiding = true; 73 filters.add(f1); 74 break; 75 } 76 case 2: { 77 Filter f1 = new Filter(); 78 f1.text = "highway"; 79 f1.inverted = true; 80 filters.add(f1); 81 break; 82 } 83 case 3: { 84 Filter f1 = new Filter(); 85 f1.text = "power"; 86 f1.inverted = true; 87 f1.hiding = true; 88 Filter f2 = new Filter(); 89 f2.text = "highway"; 90 filters.addAll(Arrays.asList(new Filter[] {f1, f2})); 91 break; 92 } 93 case 11: { 94 Filter f1 = new Filter(); 95 f1.text = "highway"; 96 f1.inverted = true; 97 f1.hiding = true; 98 filters.add(f1); 99 break; 100 } 101 case 12: { 102 Filter f1 = new Filter(); 103 f1.text = "highway"; 104 f1.inverted = true; 105 f1.hiding = true; 106 Filter f2 = new Filter(); 107 f2.text = "water"; 108 f2.mode = SearchMode.remove; 109 filters.addAll(Arrays.asList(new Filter[] {f1, f2})); 110 break; 111 } 112 case 13: { 113 Filter f1 = new Filter(); 114 f1.text = "highway"; 115 f1.inverted = true; 116 f1.hiding = true; 117 Filter f2 = new Filter(); 118 f2.text = "water"; 119 f2.mode = SearchMode.remove; 120 Filter f3 = new Filter(); 121 f3.text = "natural"; 122 filters.addAll(Arrays.asList(new Filter[] {f1, f2, f3})); 123 break; 124 } 125 case 14: { 126 /* show all highways and all water features, but not lakes 127 * except those that have a name */ 128 Filter f1 = new Filter(); 129 f1.text = "highway"; 130 f1.inverted = true; 131 f1.hiding = true; 132 Filter f2 = new Filter(); 133 f2.text = "water"; 134 f2.mode = SearchMode.remove; 135 Filter f3 = new Filter(); 136 f3.text = "natural"; 137 Filter f4 = new Filter(); 138 f4.text = "name"; 139 f4.mode = SearchMode.remove; 140 filters.addAll(Arrays.asList(new Filter[] {f1, f2, f3, f4})); 141 break; 142 } 143 case 15: { 144 Filter f1 = new Filter(); 145 f1.text = "highway"; 146 f1.inverted = true; 147 f1.hiding = true; 148 Filter f2 = new Filter(); 149 f2.text = "water"; 150 f2.mode = SearchMode.remove; 151 f2.hiding = true; // Remove only hide flag so water should stay disabled 152 filters.addAll(Arrays.asList(new Filter[] {f1, f2})); 153 break; 154 } 144 155 } 145 156 … … 151 162 boolean foundAtLeastOne = false; 152 163 System.err.println("Run #"+i); 164 StringBuilder failedPrimitives = new StringBuilder(); 153 165 for (OsmPrimitive osm : ds.allPrimitives()) { 154 166 String key = "source:RESULT"+i; // use key that counts as untagged 155 167 if (osm.hasKey(key)) { 156 168 foundAtLeastOne = true; 157 // System.err.println("osm "+osm.getId()+" "+filterCode(osm)+" "+osm.get(key)); 158 assertEquals(String.format("Run #%d Object %s", i,osm.toString()), filterCode(osm), osm.get(key)); 169 if (!osm.get(key).equals(filterCode(osm))) { 170 failedPrimitives.append(String.format("Object %s. Expected [%s] but was [%s]\n", osm.toString(), osm.get(key), filterCode(osm))); 171 } 159 172 } 160 173 } 161 174 assertTrue(foundAtLeastOne); 175 if (failedPrimitives.length() != 0) 176 throw new AssertionError(String.format("Run #%d\n%s", i, failedPrimitives.toString())); 162 177 } 163 178 }
Note:
See TracChangeset
for help on using the changeset viewer.