Revision 10674
trunk/libraries/libFMap/src-test/com/iver/cit/gvsig/fmap/core/symbols/TestISymbol.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.core.symbols; |
|
2 |
|
|
3 |
import junit.swingui.*; |
|
4 |
import java.io.File; |
|
5 |
import java.lang.reflect.Field; |
|
6 |
|
|
7 |
import junit.framework.TestCase; |
|
8 |
|
|
9 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
10 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
11 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
12 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
13 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
|
14 |
|
|
15 |
public class TestISymbol extends TestCase { |
|
16 |
transient private ISymbol[] symbols; |
|
17 |
|
|
18 |
protected void setUp() throws Exception { |
|
19 |
ISymbol marker1; |
|
20 |
ISymbol marker2; |
|
21 |
ISymbol marker3; |
|
22 |
|
|
23 |
ISymbol fill1; |
|
24 |
ISymbol fill2; |
|
25 |
ISymbol fill3; |
|
26 |
|
|
27 |
ISymbol line1; |
|
28 |
|
|
29 |
ISymbol text1; |
|
30 |
ISymbol text2; |
|
31 |
|
|
32 |
IMultiLayerSymbol lineMultiLayer; |
|
33 |
IMultiLayerSymbol markerMultiLayer; |
|
34 |
IMultiLayerSymbol fillMultiLayer; |
|
35 |
|
|
36 |
marker1 = new SimpleMarkerSymbol(); |
|
37 |
marker2 = new CharacterMarkerSymbol(); |
|
38 |
marker3 = new PictureMarkerSymbol(new File("src/com/iver/cit/gvsig/fmap/images/Hand.gif")); |
|
39 |
fill1 = new DotDensityFillSymbol(); |
|
40 |
fill2 = new MarkerFillSymbol(); |
|
41 |
fill3 = new SimpleFillSymbol(); |
|
42 |
line1 = new SimpleLineSymbol(); |
|
43 |
text1 = new SimpleTextSymbol(); |
|
44 |
text2 = new SmartTextSymbol(); |
|
45 |
|
|
46 |
markerMultiLayer = new MultiLayerMarkerSymbol(); |
|
47 |
markerMultiLayer.addLayer(marker1); |
|
48 |
markerMultiLayer.addLayer(marker2); |
|
49 |
markerMultiLayer.addLayer(marker3); |
|
50 |
|
|
51 |
fillMultiLayer = new MultiLayerFillSymbol(); |
|
52 |
fillMultiLayer.addLayer(fill1); |
|
53 |
fillMultiLayer.addLayer(fill2); |
|
54 |
fillMultiLayer.addLayer(fill3); |
|
55 |
|
|
56 |
lineMultiLayer = new MultiLayerLineSymbol(); |
|
57 |
lineMultiLayer.addLayer(line1); |
|
58 |
|
|
59 |
|
|
60 |
symbols = new ISymbol[] { |
|
61 |
marker1, marker2, marker3, |
|
62 |
fill1, fill2, fill3, |
|
63 |
line1, |
|
64 |
text1, text2, |
|
65 |
markerMultiLayer, |
|
66 |
fillMultiLayer, |
|
67 |
lineMultiLayer, |
|
68 |
}; |
|
69 |
|
|
70 |
} |
|
71 |
|
|
72 |
public void testPointSuitability() { |
|
73 |
final IGeometry dummyPointGeom = ShapeFactory.createPoint2D(new FPoint2D()); |
|
74 |
for (int i = 0; i < symbols.length; i++) { |
|
75 |
// text symbols are suitable for everything |
|
76 |
if (symbols[i] instanceof ITextSymbol) { |
|
77 |
assertTrue(symbols[i].getClassName()+" should be suitable for "+dummyPointGeom, |
|
78 |
symbols[i].isSuitableFor(dummyPointGeom)); |
|
79 |
} else |
|
80 |
|
|
81 |
// marker symbols are suitable for points |
|
82 |
if (symbols[i] instanceof IMarkerSymbol) { |
|
83 |
assertTrue(symbols[i].getClassName()+" should be suitable for "+dummyPointGeom, |
|
84 |
symbols[i].isSuitableFor(dummyPointGeom)); |
|
85 |
} else { |
|
86 |
assertFalse(symbols[i].getClassName()+" should NOT be suitable for "+dummyPointGeom, |
|
87 |
symbols[i].isSuitableFor(dummyPointGeom)); |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
public void testLineSuitability() { |
|
93 |
final IGeometry dummyLineGeom = ShapeFactory.createPolyline2D(new GeneralPathX()); |
|
94 |
for (int i = 0; i < symbols.length; i++) { |
|
95 |
// text symbols are suitable for everything |
|
96 |
if (symbols[i] instanceof ITextSymbol) { |
|
97 |
assertTrue(symbols[i].getClassName()+" should be suitable for "+dummyLineGeom, |
|
98 |
symbols[i].isSuitableFor(dummyLineGeom)); |
|
99 |
} else |
|
100 |
|
|
101 |
// line symbols are suitable for line |
|
102 |
if (symbols[i] instanceof ILineSymbol) { |
|
103 |
assertTrue(symbols[i].getClassName()+" should be suitable for "+dummyLineGeom, |
|
104 |
symbols[i].isSuitableFor(dummyLineGeom)); |
|
105 |
} else { |
|
106 |
assertFalse(symbols[i].getClassName()+" should NOT be suitable for "+dummyLineGeom, |
|
107 |
symbols[i].isSuitableFor(dummyLineGeom)); |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
public void testPolygonSuitability() { |
|
113 |
final IGeometry dummyPolygonGeom = ShapeFactory.createPolygon2D(new GeneralPathX()); |
|
114 |
for (int i = 0; i < symbols.length; i++) { |
|
115 |
|
|
116 |
// text symbols are suitable for everything |
|
117 |
if (symbols[i] instanceof ITextSymbol) { |
|
118 |
assertTrue(symbols[i].getClassName()+" should be suitable for "+dummyPolygonGeom, |
|
119 |
symbols[i].isSuitableFor(dummyPolygonGeom)); |
|
120 |
} else |
|
121 |
|
|
122 |
// fill symbols are suitable for polygons |
|
123 |
if (symbols[i] instanceof IFillSymbol) { |
|
124 |
assertTrue(symbols[i].getClassName()+" should be suitable for "+dummyPolygonGeom, |
|
125 |
symbols[i].isSuitableFor(dummyPolygonGeom)); |
|
126 |
} else { |
|
127 |
assertFalse(symbols[i].getClassName()+" should NOT be suitable for "+dummyPolygonGeom, |
|
128 |
symbols[i].isSuitableFor(dummyPolygonGeom)); |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* tests whether the symbols were correctly configured to work with |
|
135 |
* different kinds of shapes. |
|
136 |
*/ |
|
137 |
public void testGeneralSuitability() { |
|
138 |
|
|
139 |
for (int i = 0; i < symbols.length; i++) { |
|
140 |
// text symbols are suitable for everything |
|
141 |
if (symbols[i] instanceof ITextSymbol) { |
|
142 |
assertTrue(symbols[i].getClassName()+" should be suitable for "+null, |
|
143 |
symbols[i].isSuitableFor(null)); |
|
144 |
} else { |
|
145 |
try { |
|
146 |
symbols[i].isSuitableFor(null); |
|
147 |
fail("Exception was not thrown"); |
|
148 |
|
|
149 |
} catch (NullPointerException npEx) { |
|
150 |
// this is correct! |
|
151 |
} |
|
152 |
} |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
/** |
|
157 |
* ensures that symbols defined which can of FShape is the symbol |
|
158 |
*/ |
|
159 |
public void testSymbolTypeDefinition() { |
|
160 |
for (int i = 0; i < symbols.length; i++) { |
|
161 |
assertFalse("Symbol no. "+i+" '"+symbols[i].getClassName()+"'", |
|
162 |
symbols[i].getSymbolType() == 0); |
|
163 |
|
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* ensures that any symbol has a description in its persistence |
|
169 |
* (very important) |
|
170 |
*/ |
|
171 |
public void testDescription() { |
|
172 |
for (int i = 0; i < symbols.length; i++) { |
|
173 |
assertTrue(symbols[i].getClassName() + " does not declare a description in its XMLEntity", |
|
174 |
symbols[i].getXMLEntity().contains("desc")); |
|
175 |
} |
|
176 |
|
|
177 |
} |
|
178 |
/** |
|
179 |
* ensures that the symbol is self-defining |
|
180 |
*/ |
|
181 |
public void testSymbolSelfDefinition() { |
|
182 |
for (int i = 0; i < symbols.length; i++) { |
|
183 |
final ISymbol theSymbol = symbols[i]; |
|
184 |
final ISymbol cloneSymbol = SymbologyFactory.createSymbolFromXML(theSymbol.getXMLEntity(), null); |
|
185 |
assertTrue(theSymbol.getClassName()+ " wrong class name declaration in getXMLEntity() ", |
|
186 |
cloneSymbol.getClass().equals(theSymbol.getClass())); |
|
187 |
final Field[] theSymbolFields = theSymbol.getClass().getFields(); |
|
188 |
for (int j = 0; j < theSymbolFields.length; j++) { |
|
189 |
final Field fi = theSymbolFields[j]; |
|
190 |
final boolean wasAccessible = fi.isAccessible(); |
|
191 |
fi.setAccessible(true); |
|
192 |
|
|
193 |
try { |
|
194 |
assertTrue(theSymbol.getClassName() + " fails or misses clonning the field " +fi.getName(), |
|
195 |
fi.get(theSymbol).equals(fi.get(cloneSymbol))); |
|
196 |
} catch (IllegalArgumentException e) { |
|
197 |
fail(); |
|
198 |
} catch (IllegalAccessException e) { |
|
199 |
fail(); |
|
200 |
} |
|
201 |
fi.setAccessible(wasAccessible); |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
205 |
// TODO test for rendering |
|
206 |
|
|
207 |
public void testDraw() { |
|
208 |
|
|
209 |
} |
|
210 |
|
|
211 |
public void testDrawInsideRectangle() { |
|
212 |
|
|
213 |
} |
|
214 |
// TODO test for printing |
|
215 |
|
|
216 |
} |
|
0 | 217 |
Also available in: Unified diff