svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / test / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / TestISymbol.java @ 47476
History | View | Annotate | Download (14.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
25 |
|
26 |
import java.lang.reflect.Field; |
27 |
import java.util.ArrayList; |
28 |
import junit.framework.TestSuite; |
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
31 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
32 |
import org.gvsig.fmap.geom.GeometryLocator; |
33 |
import org.gvsig.fmap.geom.GeometryManager; |
34 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
35 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
36 |
import org.gvsig.fmap.geom.primitive.Line; |
37 |
import org.gvsig.fmap.geom.primitive.Point; |
38 |
import org.gvsig.fmap.geom.primitive.Surface; |
39 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
40 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
41 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
42 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
44 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
45 |
|
46 |
/**
|
47 |
* Integration test to ensure that the symbols follow the rules that follow the
|
48 |
* managing of them by the application.
|
49 |
*
|
50 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
51 |
*/
|
52 |
|
53 |
|
54 |
public class TestISymbol extends AbstractLibraryAutoInitTestCase { |
55 |
private static ArrayList classesToTest;//<AbstractSymbolTestCase> |
56 |
transient private ISymbol[] symbols; |
57 |
|
58 |
public static TestSuite suite() { |
59 |
TestSuite suite = new TestSuite("Integration test for com.iver.cit.gvsig.fmap.core.ISymbol"); |
60 |
suite.addTestSuite(TestISymbol.class); |
61 |
suite.addTestSuite(TestDrawMarkers.class); |
62 |
suite.addTestSuite(TestDrawLines.class); |
63 |
suite.addTestSuite(TestDrawFills.class); |
64 |
|
65 |
return suite;
|
66 |
} |
67 |
|
68 |
@Override
|
69 |
protected void doSetUp() throws Exception { |
70 |
addSymbols(); |
71 |
symbols = getNewSymbolInstances(); |
72 |
} |
73 |
|
74 |
public static void addSymbols() { |
75 |
addSymbolTest(new SimpleFillSymbolTest());
|
76 |
addSymbolTest(new SimpleLineSymbolTest());
|
77 |
addSymbolTest(new SimpleMarkerSymbolTest());
|
78 |
addSymbolTest(new SimpleTextSymbolTest());
|
79 |
} |
80 |
|
81 |
|
82 |
public static void addSymbolTest(AbstractSymbolTestCase symbolTestClass) { |
83 |
if (classesToTest == null) classesToTest = new ArrayList(); //<AbstractSymbolTestCase> |
84 |
|
85 |
classesToTest.add(symbolTestClass); |
86 |
} |
87 |
|
88 |
public static ISymbol[] getNewSymbolInstances() { |
89 |
ISymbol[] symbols = new ISymbol[classesToTest.size()]; |
90 |
for (int i = 0; i < symbols.length; i++) { |
91 |
symbols[i] = (ISymbol)((AbstractSymbolTestCase)classesToTest.get(i)).newInstance(); |
92 |
} |
93 |
return symbols;
|
94 |
} |
95 |
|
96 |
public void testPointSuitability() throws InstantiationException, IllegalAccessException, CreateGeometryException { |
97 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
98 |
Point point = (Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
99 |
final Geometry dummyPointGeom = point;
|
100 |
for (ISymbol symbol : symbols) {
|
101 |
// text symbols are suitable for everything
|
102 |
if (symbol instanceof ITextSymbol) { |
103 |
assertTrue(symbol.getClass().getName() + " should be suitable for " + dummyPointGeom, symbol.isSuitableFor(dummyPointGeom));
|
104 |
} else // marker symbols are suitable for points |
105 |
if (symbol instanceof IMarkerSymbol) { |
106 |
assertTrue(symbol.getClass().getName() + " should be suitable for " + dummyPointGeom, symbol.isSuitableFor(dummyPointGeom));
|
107 |
} else {
|
108 |
assertFalse(symbol.getClass().getName() + " should NOT be suitable for " + dummyPointGeom, symbol.isSuitableFor(dummyPointGeom));
|
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
public void testLineSuitability() throws InstantiationException, IllegalAccessException, CreateGeometryException { |
114 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
115 |
Line line = geomManager.createLine(SUBTYPES.GEOM2D);
|
116 |
line.setGeneralPath(new GeneralPathX());
|
117 |
final Geometry dummyLineGeom = line;
|
118 |
for (ISymbol symbol : symbols) {
|
119 |
// text symbols are suitable for everything
|
120 |
if (symbol instanceof ITextSymbol) { |
121 |
assertTrue(symbol.getClass().getName() + " should be suitable for " + dummyLineGeom, symbol.isSuitableFor(dummyLineGeom));
|
122 |
} else // line symbols are suitable for line |
123 |
if (symbol instanceof ILineSymbol) { |
124 |
assertTrue(symbol.getClass().getName() + " should be suitable for " + dummyLineGeom, symbol.isSuitableFor(dummyLineGeom));
|
125 |
} else {
|
126 |
assertFalse(symbol.getClass().getName() + " should NOT be suitable for " + dummyLineGeom, symbol.isSuitableFor(dummyLineGeom));
|
127 |
} |
128 |
} |
129 |
} |
130 |
|
131 |
public void testPolygonSuitability() throws InstantiationException, IllegalAccessException, CreateGeometryException { |
132 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
133 |
Surface surface = (Surface)geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
134 |
surface.setGeneralPath(new GeneralPathX());
|
135 |
final Geometry dummyPolygonGeom = surface;
|
136 |
for (ISymbol symbol : symbols) {
|
137 |
// text symbols are suitable for everything
|
138 |
if (symbol instanceof ITextSymbol) { |
139 |
assertTrue(symbol.getClass().getName() + " should be suitable for " + dummyPolygonGeom, symbol.isSuitableFor(dummyPolygonGeom));
|
140 |
} else // fill symbols are suitable for polygons |
141 |
if (symbol instanceof IFillSymbol) { |
142 |
assertTrue(symbol.getClass().getName() + " should be suitable for " + dummyPolygonGeom, symbol.isSuitableFor(dummyPolygonGeom));
|
143 |
} else {
|
144 |
assertFalse(symbol.getClass().getName() + " should NOT be suitable for " + dummyPolygonGeom, symbol.isSuitableFor(dummyPolygonGeom));
|
145 |
} |
146 |
} |
147 |
} |
148 |
|
149 |
/**
|
150 |
* tests whether the symbols were correctly configured to work with
|
151 |
* different kinds of shapes.
|
152 |
*/
|
153 |
public void testGeneralSuitability() { |
154 |
|
155 |
for (ISymbol symbol : symbols) {
|
156 |
// text symbols are suitable for everything
|
157 |
if (symbol instanceof ITextSymbol) { |
158 |
assertTrue(symbol.getClass().getName() + " should be suitable for " + null, symbol.isSuitableFor(null)); |
159 |
} else {
|
160 |
try {
|
161 |
symbol.isSuitableFor(null);
|
162 |
fail("Exception was not thrown");
|
163 |
}catch (NullPointerException npEx) { |
164 |
// this is correct!
|
165 |
} |
166 |
} |
167 |
} |
168 |
} |
169 |
|
170 |
/**
|
171 |
* ensures that symbols defined which can of FShape is the symbol
|
172 |
*/
|
173 |
public void testSymbolTypeDefinition() { |
174 |
for (int i = 0; i < symbols.length; i++) { |
175 |
assertFalse("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"'", |
176 |
symbols[i].getSymbolType() == 0);
|
177 |
|
178 |
} |
179 |
} |
180 |
|
181 |
/**
|
182 |
* ensures that any symbol that is suitable for markers declares its type
|
183 |
* as FShape.POINT or FShape.MULTI
|
184 |
*
|
185 |
*/
|
186 |
public void testMarkerSymbolTypeDefinition() { |
187 |
for (int i = 0; i < symbols.length; i++) { |
188 |
if (symbols[i] instanceof IMarkerSymbol) { |
189 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"'", |
190 |
symbols[i].getSymbolType() == Geometry.TYPES.POINT |
191 |
|| symbols[i].getSymbolType() == Geometry.TYPES.GEOMETRY); |
192 |
} |
193 |
} |
194 |
} |
195 |
|
196 |
/**
|
197 |
* ensures that any symbol that is suitable for lines declares its type
|
198 |
* as FShape.LINE or FShape.MULTI
|
199 |
*
|
200 |
*/
|
201 |
public void testLineSymbolTypeDefinition() { |
202 |
for (int i = 0; i < symbols.length; i++) { |
203 |
if (symbols[i] instanceof ILineSymbol) { |
204 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"'", |
205 |
symbols[i].getSymbolType() == Geometry.TYPES.CURVE |
206 |
|| symbols[i].getSymbolType() == Geometry.TYPES.GEOMETRY); |
207 |
} |
208 |
} |
209 |
} |
210 |
|
211 |
/**
|
212 |
* ensures that any symbol that is suitable for fills declares its type
|
213 |
* as POLYGON or Geometry.TYPES.GEOMETRY
|
214 |
*
|
215 |
*/
|
216 |
public void testFillSymbolTypeDefinition() { |
217 |
for (int i = 0; i < symbols.length; i++) { |
218 |
if (symbols[i] instanceof IFillSymbol) { |
219 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"'", |
220 |
symbols[i].getSymbolType() == Geometry.TYPES.SURFACE |
221 |
|| symbols[i].getSymbolType() == Geometry.TYPES.GEOMETRY); |
222 |
} |
223 |
} |
224 |
} |
225 |
|
226 |
// /**
|
227 |
// * ensures that any symbol has a description in its persistence
|
228 |
// * (very important)
|
229 |
// */
|
230 |
// public void testDescription() {
|
231 |
// for (int i = 0; i < symbols.length; i++) {
|
232 |
// try {
|
233 |
// assertTrue(symbols[i].getClass().getName() + " does not declare a description in its XMLEntity",
|
234 |
// symbols[i].getXMLEntity().contains("desc"));
|
235 |
// } catch (XMLException e) {
|
236 |
// // TODO Auto-generated catch block
|
237 |
// e.printStackTrace();
|
238 |
// }
|
239 |
// }
|
240 |
// }
|
241 |
|
242 |
// /**
|
243 |
// * ensures that any symbol has an isShapeVisible field in its persistence
|
244 |
// * (very important)
|
245 |
// */
|
246 |
// public void testIsShapeVisible() {
|
247 |
// for (int i = 0; i < symbols.length; i++) {
|
248 |
// try {
|
249 |
// assertTrue(symbols[i].getClass().getName() + " does not declare the isShapeVisible field in its XMLEntity",
|
250 |
// symbols[i].getXMLEntity().contains("isShapeVisible"));
|
251 |
// } catch (XMLException e) {
|
252 |
// // TODO Auto-generated catch block
|
253 |
// e.printStackTrace();
|
254 |
// }
|
255 |
// }
|
256 |
// }
|
257 |
|
258 |
/**
|
259 |
* ensures that the symbol is self-defining
|
260 |
* @throws Exception
|
261 |
*/
|
262 |
public void testSymbolSelfDefinition() throws Exception { |
263 |
for (ISymbol theSymbol : symbols) {
|
264 |
ISymbol cloneSymbol= (ISymbol) theSymbol.clone(); |
265 |
//cloneSymbol = SymbologyFactory.createSymbolFromXML(theSymbol.getXMLEntity(), null);
|
266 |
|
267 |
assertTrue(theSymbol.getClass().getName()+ " wrong class name declaration in getXMLEntity() ",
|
268 |
cloneSymbol.getClass().equals(theSymbol.getClass())); |
269 |
final Field[] theSymbolFields = theSymbol.getClass().getFields(); |
270 |
for (Field fi : theSymbolFields) { |
271 |
final boolean wasAccessible = fi.isAccessible(); |
272 |
fi.setAccessible(true);
|
273 |
|
274 |
try {
|
275 |
assertTrue(theSymbol.getClass().getName() + " fails or misses clonning the field " +fi.getName(),
|
276 |
fi.get(theSymbol).equals(fi.get(cloneSymbol))); |
277 |
} catch (Exception e) { |
278 |
fail(); |
279 |
} |
280 |
fi.setAccessible(wasAccessible); |
281 |
} |
282 |
} |
283 |
} |
284 |
|
285 |
// /**
|
286 |
// * Check one pixel acceleration consistency. Checks that the color returned
|
287 |
// * in RGB matches the color of the symbol set.
|
288 |
// *
|
289 |
// */
|
290 |
// public void testOnePointRGB() {
|
291 |
// Random random = new Random(System.currentTimeMillis());
|
292 |
//
|
293 |
// for (int i = 0; i < symbols.length; i++) {
|
294 |
// if (symbols[i] instanceof IMarkerSymbol) {
|
295 |
// IMarkerSymbol marker = (IMarkerSymbol) symbols[i];
|
296 |
// marker.setColor(new Color(random.nextInt()>>8));
|
297 |
// assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"' RGB value mismatch for getOnePointRBG() and getColor().getRGB()",
|
298 |
// symbols[i].getOnePointRgb() == marker.getColor().getRGB());
|
299 |
//
|
300 |
// }
|
301 |
//
|
302 |
// if (symbols[i] instanceof ILineSymbol) {
|
303 |
// ILineSymbol line = (ILineSymbol) symbols[i];
|
304 |
// line.setLineColor(new Color(random.nextInt()>>8));
|
305 |
// assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"' RGB value mismatch for getOnePointRBG() and getColor().getRGB()",
|
306 |
// symbols[i].getOnePointRgb() == line.getColor().getRGB());
|
307 |
// }
|
308 |
//
|
309 |
// if (symbols[i] instanceof IFillSymbol) {
|
310 |
// IFillSymbol fill = (IFillSymbol) symbols[i];
|
311 |
// boolean outlined = fill.getOutline() != null;
|
312 |
// if (!outlined)
|
313 |
// fill.setFillColor(new Color(random.nextInt()>>8));
|
314 |
// else
|
315 |
// fill.getOutline().setLineColor(new Color(random.nextInt()>>8));
|
316 |
// assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"' RGB value mismatch for getOnePointRBG() and getColor().getRGB()",
|
317 |
// symbols[i].getOnePointRgb() == ((outlined) ? fill.getOutline().getColor().getRGB() : fill.getFillColor().getRGB()));
|
318 |
// }
|
319 |
//
|
320 |
// if (symbols[i] instanceof ITextSymbol) {
|
321 |
// ITextSymbol text = (ITextSymbol) symbols[i];
|
322 |
// text.setTextColor(new Color(random.nextInt()>>8));
|
323 |
// assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"' RGB value mismatch for getOnePointRBG() and getColor().getRGB()",
|
324 |
// symbols[i].getOnePointRgb() == text.getTextColor().getRGB());
|
325 |
// }
|
326 |
//
|
327 |
// }
|
328 |
// }
|
329 |
|
330 |
/**
|
331 |
* ensures that any symbol provides a version of itself to use when the
|
332 |
* feature is selected
|
333 |
*
|
334 |
*/
|
335 |
public void testSymbolForSelection() { |
336 |
for (int i = 0; i < symbols.length; i++) { |
337 |
assertNotNull("Symbol no. "+i+" '"+symbols[i].getClass().getName()+" does not define any derived symbol for selection", symbols[i].getSymbolForSelection()); |
338 |
} |
339 |
} |
340 |
} |