Revision 34226
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/README.txt | ||
---|---|---|
1 |
For each class you are going to test, create one Test class with the same |
|
2 |
name as the class to test, ending with Test. |
|
3 |
|
|
4 |
For example, the unit tests of the "ExampleExtension" class are performed |
|
5 |
by the "ExampleExtensionTest" class. |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/AbstractSymbolTestCase.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import junit.framework.TestCase; |
|
44 |
|
|
45 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
46 |
|
|
47 |
|
|
48 |
public abstract class AbstractSymbolTestCase extends TestCase { |
|
49 |
protected Class symClazz; |
|
50 |
|
|
51 |
public AbstractSymbolTestCase(Class symClazz) { |
|
52 |
this.symClazz = symClazz; |
|
53 |
} |
|
54 |
|
|
55 |
public ISymbol newInstance() { |
|
56 |
try { |
|
57 |
return (ISymbol) symClazz.newInstance(); |
|
58 |
} catch (Exception e) { |
|
59 |
fail("Failed installing symbol to test "+symClazz.getName()); |
|
60 |
return null; |
|
61 |
} |
|
62 |
} |
|
63 |
} |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleFillSymbolTest.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol; |
|
44 |
|
|
45 |
public class SimpleFillSymbolTest extends AbstractSymbolTestCase{ |
|
46 |
public SimpleFillSymbolTest() { |
|
47 |
super(SimpleFillSymbol.class); |
|
48 |
} |
|
49 |
} |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleLineSymbolTest.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol; |
|
44 |
|
|
45 |
public class SimpleLineSymbolTest extends AbstractSymbolTestCase{ |
|
46 |
public SimpleLineSymbolTest() { |
|
47 |
super(SimpleLineSymbol.class); |
|
48 |
} |
|
49 |
} |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestDrawFills.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import java.awt.Dimension; |
|
44 |
import java.awt.Graphics2D; |
|
45 |
import java.awt.geom.AffineTransform; |
|
46 |
import java.awt.geom.Point2D; |
|
47 |
import java.awt.image.BufferedImage; |
|
48 |
import java.io.File; |
|
49 |
import java.io.IOException; |
|
50 |
import java.util.ArrayList; |
|
51 |
|
|
52 |
import javax.imageio.ImageIO; |
|
53 |
|
|
54 |
import junit.framework.TestCase; |
|
55 |
|
|
56 |
import org.gvsig.compat.CompatLocator; |
|
57 |
import org.gvsig.fmap.geom.Geometry; |
|
58 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
59 |
import org.gvsig.fmap.geom.GeometryManager; |
|
60 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
61 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
62 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
63 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
64 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
65 |
import org.gvsig.symbology.fmap.mapcontext.rendering.AllTests; |
|
66 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
67 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
68 |
import org.slf4j.Logger; |
|
69 |
import org.slf4j.LoggerFactory; |
|
70 |
|
|
71 |
|
|
72 |
/** |
|
73 |
* Integration test to test that Fill symbols always draw in the same |
|
74 |
* place respecting size constraints. |
|
75 |
* |
|
76 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
77 |
*/ |
|
78 |
public class TestDrawFills extends AbstractLibraryAutoInitTestCase { |
|
79 |
private GeometryManager geomManager; |
|
80 |
private static final Logger logger = LoggerFactory.getLogger(TestDrawFills.class); |
|
81 |
private final Dimension sz = new Dimension(400, 400); |
|
82 |
private org.gvsig.fmap.geom.primitive.Point centerP = null; |
|
83 |
private static final int OUTTER_TOLERANCE = 1; |
|
84 |
private static final int INNER_TOLERANCE = 1; |
|
85 |
private IFillSymbol[] symbols; |
|
86 |
private IDrawFillSymbol[] drawFillSymbols; |
|
87 |
private static ArrayList classesToTest; |
|
88 |
|
|
89 |
private static final double sizes[] = new double[] { |
|
90 |
200, |
|
91 |
100, |
|
92 |
50, |
|
93 |
30, |
|
94 |
16, |
|
95 |
5, |
|
96 |
3, |
|
97 |
2, |
|
98 |
// smaller sizes don't make any sense |
|
99 |
|
|
100 |
}; |
|
101 |
|
|
102 |
|
|
103 |
private static ArrayList getClassesToTest() { |
|
104 |
if (classesToTest == null) { |
|
105 |
classesToTest = new ArrayList(); |
|
106 |
// TestDrawFills.addSymbolToTest(DrawLineFillSymbol.class); |
|
107 |
// TestDrawFills.addSymbolToTest(DrawPictureFillSymbol.class); |
|
108 |
} |
|
109 |
|
|
110 |
return classesToTest; |
|
111 |
} |
|
112 |
|
|
113 |
public static void addSymbolToTest(Class symbolClass) { |
|
114 |
try { |
|
115 |
IDrawFillSymbol sym = (IDrawFillSymbol) symbolClass.newInstance(); |
|
116 |
} catch (InstantiationException e) { |
|
117 |
// TODO Auto-generated catch block |
|
118 |
fail("Instantiating class, cannot test a non-instantiable symbol"); |
|
119 |
} catch (IllegalAccessException e) { |
|
120 |
// TODO Auto-generated catch block |
|
121 |
fail("Class not instantiable"); |
|
122 |
} catch (ClassCastException ccEx) { |
|
123 |
fail("Cannot test a non symbol class"); |
|
124 |
} |
|
125 |
getClassesToTest().add(symbolClass); |
|
126 |
} |
|
127 |
|
|
128 |
protected void doSetUp() throws Exception { |
|
129 |
geomManager = GeometryLocator.getGeometryManager(); |
|
130 |
centerP = geomManager.createPoint(sz.width/2, sz.height/2, SUBTYPES.GEOM2D); |
|
131 |
|
|
132 |
this.drawFillSymbols = new IDrawFillSymbol[getClassesToTest().size()]; |
|
133 |
|
|
134 |
for (int i = 0; i < drawFillSymbols.length; i++) { |
|
135 |
drawFillSymbols[i] = (IDrawFillSymbol) ((Class) getClassesToTest().get(i)).newInstance(); |
|
136 |
} |
|
137 |
|
|
138 |
TestISymbol.addSymbols(); |
|
139 |
ISymbol[] allSymbols = TestISymbol.getNewSymbolInstances(); |
|
140 |
// Filter the marker ones |
|
141 |
ArrayList symbols = new ArrayList(); |
|
142 |
|
|
143 |
for (int i = 0; i < allSymbols.length; i++) { |
|
144 |
if (allSymbols[i] instanceof IFillSymbol) { |
|
145 |
IFillSymbol sym = (IFillSymbol) allSymbols[i]; |
|
146 |
symbols.add(sym); |
|
147 |
|
|
148 |
} |
|
149 |
} |
|
150 |
this.symbols = (IFillSymbol[]) symbols.toArray(new IFillSymbol[symbols.size()]); |
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
} |
|
155 |
|
|
156 |
public void testDraw() { |
|
157 |
MapContext mc = AllTests.newMapContext(AllTests.TEST_DEFAULT_MERCATOR_PROJECTION); |
|
158 |
|
|
159 |
} |
|
160 |
|
|
161 |
|
|
162 |
public final void testNullColorAvoidsFilling() throws CreateGeometryException { |
|
163 |
|
|
164 |
for (int i = 0; i < symbols.length; i++) { |
|
165 |
|
|
166 |
for (int s = 0; s < sizes.length; s++) { |
|
167 |
|
|
168 |
BufferedImage bi = CompatLocator.getGraphicsUtils().createBufferedImage(sz.width,sz.height, BufferedImage.TYPE_INT_ARGB); |
|
169 |
// the graphics for the image, so we can draw onto the buffered image |
|
170 |
Graphics2D g = bi.createGraphics(); |
|
171 |
|
|
172 |
IFillSymbol newSymbol = symbols[i]; |
|
173 |
newSymbol.setFillColor(null); |
|
174 |
newSymbol.setOutline(null); |
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
String name = newSymbol.getClass().getName().substring( |
|
180 |
newSymbol.getClass().getName().lastIndexOf('.')+1, |
|
181 |
newSymbol.getClass().getName().length()); |
|
182 |
|
|
183 |
|
|
184 |
Point2D firstPoint = new Point2D.Float((float)(centerP.getX()-sizes[s]/2-3),(float)(centerP.getY()-sizes[s]/2-3)); |
|
185 |
Point2D lastPoint = new Point2D.Float((float)(centerP.getX()+sizes[s]/2+3),(float)(centerP.getY()+sizes[s]/2+3)); |
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
GeneralPathX gpx = new GeneralPathX(); |
|
190 |
|
|
191 |
gpx.moveTo((float)firstPoint.getX(),(float) firstPoint.getY()); |
|
192 |
gpx.lineTo((float)lastPoint.getX(),(float) firstPoint.getY()); |
|
193 |
gpx.lineTo((float)lastPoint.getX(),(float) lastPoint.getY()); |
|
194 |
gpx.lineTo((float)firstPoint.getX(),(float) lastPoint.getY()); |
|
195 |
gpx.lineTo((float)firstPoint.getX(), (float)firstPoint.getY()); |
|
196 |
gpx.closePath(); |
|
197 |
|
|
198 |
|
|
199 |
for (int j = 0; j < drawFillSymbols.length; j++) { |
|
200 |
if (drawFillSymbols[j].isSuitableFor(newSymbol)) { |
|
201 |
newSymbol = drawFillSymbols[j].makeSymbolTransparent(newSymbol); |
|
202 |
break; |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
|
|
207 |
newSymbol.draw(g, new AffineTransform(), geomManager.createSurface(gpx, SUBTYPES.GEOM2D), null, null); |
|
208 |
|
|
209 |
try { |
|
210 |
|
|
211 |
File dstDir = new File (System.getProperty("java.io.tmpdir")+"/prova-imatges/"); |
|
212 |
if (!dstDir.exists()) dstDir.mkdir(); |
|
213 |
ImageIO.write(bi, "png", |
|
214 |
new File(dstDir.getAbsoluteFile()+File.separator+ |
|
215 |
name+"_size_"+sizes[s] |
|
216 |
+".png")); |
|
217 |
} catch (IOException e) { |
|
218 |
e.printStackTrace(); |
|
219 |
fail(); |
|
220 |
} |
|
221 |
|
|
222 |
for (int j = 0; j < bi.getWidth(); j++) { |
|
223 |
for (int k = 0; k < bi.getHeight(); k++) { |
|
224 |
if (isInsideShape(geomManager.createSurface(gpx, SUBTYPES.GEOM2D), j, k)) { |
|
225 |
assertEquals("Failed, the fill is being painted when the color is null",bi.getRGB(j, k),0); |
|
226 |
|
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
|
|
236 |
private boolean isInsideShape(Geometry geom, int x, int y) { |
|
237 |
Point2D p = new Point2D.Float(x,y); |
|
238 |
if(geom.contains(p))return true; |
|
239 |
return false; |
|
240 |
} |
|
241 |
|
|
242 |
|
|
243 |
} |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestDrawLines.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import java.awt.Color; |
|
44 |
import java.awt.Dimension; |
|
45 |
import java.awt.Graphics2D; |
|
46 |
import java.awt.geom.AffineTransform; |
|
47 |
import java.awt.geom.Point2D; |
|
48 |
import java.awt.image.BufferedImage; |
|
49 |
import java.util.ArrayList; |
|
50 |
|
|
51 |
import junit.framework.TestCase; |
|
52 |
|
|
53 |
import org.gvsig.compat.CompatLocator; |
|
54 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
55 |
import org.gvsig.fmap.geom.GeometryManager; |
|
56 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
57 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
58 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
59 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
60 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
61 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
62 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
63 |
import org.slf4j.Logger; |
|
64 |
import org.slf4j.LoggerFactory; |
|
65 |
|
|
66 |
/** |
|
67 |
* Integration test to test that Line symbols always draw in the same |
|
68 |
* place respecting size constraints. |
|
69 |
* |
|
70 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
71 |
*/ |
|
72 |
public class TestDrawLines extends AbstractLibraryAutoInitTestCase { |
|
73 |
private GeometryManager geomManager; |
|
74 |
private static final Logger logger = LoggerFactory.getLogger(TestDrawLines.class); |
|
75 |
private ILineSymbol[] symbols; |
|
76 |
private final Dimension sz = new Dimension(401, 401); |
|
77 |
private Curve centerL; |
|
78 |
|
|
79 |
protected void doSetUp() throws Exception { |
|
80 |
geomManager = GeometryLocator.getGeometryManager(); |
|
81 |
|
|
82 |
GeneralPathX gp = new GeneralPathX(); |
|
83 |
gp.moveTo(0, sz.height / 2 ); |
|
84 |
gp.lineTo(sz.width, sz.height /2 ); |
|
85 |
|
|
86 |
try { |
|
87 |
centerL = geomManager.createCurve(gp, SUBTYPES.GEOM2D); |
|
88 |
} catch (CreateGeometryException e) { |
|
89 |
e.printStackTrace(); |
|
90 |
} |
|
91 |
|
|
92 |
ISymbol[] allSymbols = TestISymbol.getNewSymbolInstances(); |
|
93 |
// Filter the marker ones |
|
94 |
ArrayList symbols = new ArrayList(); |
|
95 |
|
|
96 |
for (int i = 0; i < allSymbols.length; i++) { |
|
97 |
if (allSymbols[i] instanceof ILineSymbol) { |
|
98 |
ILineSymbol sym = (ILineSymbol) allSymbols[i]; |
|
99 |
symbols.add(sym); |
|
100 |
|
|
101 |
} |
|
102 |
} |
|
103 |
this.symbols = (ILineSymbol[]) symbols.toArray(new ILineSymbol[symbols.size()]); |
|
104 |
} |
|
105 |
private static final double sizes[] = new double[] { |
|
106 |
300, |
|
107 |
250, |
|
108 |
225, |
|
109 |
200, |
|
110 |
100, |
|
111 |
50, |
|
112 |
30, |
|
113 |
15, |
|
114 |
5, |
|
115 |
3, |
|
116 |
2, |
|
117 |
1, |
|
118 |
// smaller sizes don't make any sense |
|
119 |
}; |
|
120 |
|
|
121 |
private static final float INNER_TOLERANCE = 1F; |
|
122 |
private static final float OUTTER_TOLERANCE = 1F; |
|
123 |
|
|
124 |
public void testDrawingSize() { |
|
125 |
for (int i = 0; i < symbols.length; i++) { |
|
126 |
for (int j = 0; j < sizes.length; j++) { |
|
127 |
// new blank buffered image |
|
128 |
|
|
129 |
BufferedImage bi = CompatLocator.getGraphicsUtils().createBufferedImage(sz.width, sz.height, BufferedImage.TYPE_INT_ARGB); |
|
130 |
|
|
131 |
// the graphics for the image, so we can draw onto the buffered image |
|
132 |
Graphics2D g = bi.createGraphics(); |
|
133 |
|
|
134 |
ILineSymbol testSymbol = symbols[i]; |
|
135 |
testSymbol.setLineColor(Color.YELLOW); |
|
136 |
testSymbol.setLineWidth(sizes[j]); |
|
137 |
String name = testSymbol.getClass().getName().substring( |
|
138 |
testSymbol.getClass().getName().lastIndexOf('.')+1, |
|
139 |
testSymbol.getClass().getName().length()); |
|
140 |
|
|
141 |
Point2D upperP1 = new Point2D.Double(0, centerL.getBounds().getY() - sizes[j]*0.5); |
|
142 |
Point2D upperP2 = new Point2D.Double(centerL.getBounds().getWidth(), centerL.getBounds().getY() - sizes[j]*0.5); |
|
143 |
GeneralPathX gpUp = new GeneralPathX(); |
|
144 |
gpUp.moveTo(upperP1.getX(), upperP1.getY()); |
|
145 |
gpUp.lineTo(upperP2.getX(), upperP2.getY()); |
|
146 |
|
|
147 |
|
|
148 |
GeneralPathX gpDown = new GeneralPathX(); |
|
149 |
Point2D lowerP1 = new Point2D.Double(0, centerL.getBounds().getY() + sizes[j]*0.5); |
|
150 |
Point2D lowerP2 = new Point2D.Double(centerL.getBounds().getWidth(), centerL.getBounds().getY() + sizes[j]*0.5); |
|
151 |
gpDown.moveTo(lowerP1.getX(), lowerP1.getY()); |
|
152 |
gpDown.lineTo(lowerP2.getX(), lowerP2.getY()); |
|
153 |
|
|
154 |
|
|
155 |
testSymbol.draw(g, new AffineTransform(), centerL, null, null); |
|
156 |
|
|
157 |
/// per a borrar |
|
158 |
// g.setStroke(new BasicStroke()); |
|
159 |
// g.setColor(Color.RED); |
|
160 |
// |
|
161 |
// g.draw(gpUp); |
|
162 |
// |
|
163 |
// g.setColor(Color.BLUE); |
|
164 |
// g.draw(gpDown); |
|
165 |
// |
|
166 |
// try { |
|
167 |
// |
|
168 |
// File dstDir = new File (System.getProperty("java.io.tmpdir")+"/prova-imatges/"); |
|
169 |
// if (!dstDir.exists()) dstDir.mkdir(); |
|
170 |
// ImageIO.write(bi, "png", |
|
171 |
// new File(dstDir.getAbsoluteFile()+File.separator+ |
|
172 |
// name+"_size_"+sizes[j] |
|
173 |
// +".png")); |
|
174 |
// } catch (IOException e) { |
|
175 |
// e.printStackTrace(); |
|
176 |
// fail(); |
|
177 |
// } |
|
178 |
/// fi per a borrar |
|
179 |
assertFalse("fails sizing line, too big ("+name+", "+sizes[j]+"px)", isOutsideRect(bi, upperP1, lowerP1, OUTTER_TOLERANCE )); |
|
180 |
assertTrue("fails sizing line, too small ("+name+", "+sizes[j]+"px) \n" + |
|
181 |
"\t - forgot to enable ANTIALIASING?", fitsInsideRect(bi, upperP1, lowerP1, INNER_TOLERANCE)); |
|
182 |
|
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
private boolean isOutsideRect(BufferedImage bi, Point2D upper, Point2D lower, float outterTolerance) { |
|
188 |
for (int i = 0; i < bi.getWidth(); i++) { |
|
189 |
for (int j = 0; j < bi.getHeight(); j++) { |
|
190 |
if (j<upper.getY()-outterTolerance && j>lower.getY()+outterTolerance) |
|
191 |
if (bi.getRGB(i,j) != 0) { |
|
192 |
System.out.println("too big In pixel ("+i+", "+j+")"); |
|
193 |
return true; |
|
194 |
} |
|
195 |
|
|
196 |
} |
|
197 |
} |
|
198 |
return false; |
|
199 |
} |
|
200 |
|
|
201 |
private boolean fitsInsideRect(BufferedImage bi,Point2D upper, Point2D lower , float innerTolerance) { |
|
202 |
for (int i = 0; i < bi.getWidth(); i++) { |
|
203 |
for (int j = 0; j < bi.getHeight(); j++) { |
|
204 |
if (j<upper.getY()+innerTolerance && j>lower.getY()-innerTolerance) |
|
205 |
if (bi.getRGB(i,j) == 0) { |
|
206 |
System.out.println("does not fit big In pixel ("+i+", "+j+")"); |
|
207 |
return false; |
|
208 |
} |
|
209 |
|
|
210 |
} |
|
211 |
} |
|
212 |
return true; |
|
213 |
} |
|
214 |
|
|
215 |
} |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestMultiLayerSymbol.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import java.util.Random; |
|
44 |
|
|
45 |
import junit.framework.TestCase; |
|
46 |
|
|
47 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
48 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
49 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol; |
|
50 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol; |
|
51 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
52 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.MultiLayerLineSymbol; |
|
53 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol; |
|
54 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
55 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.MultiLayerMarkerSymbol; |
|
56 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
|
57 |
|
|
58 |
/** |
|
59 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
60 |
*/ |
|
61 |
public class TestMultiLayerSymbol extends TestCase { |
|
62 |
ISymbol[] symbols; |
|
63 |
|
|
64 |
public void setUp() { |
|
65 |
symbols = TestISymbol.getNewSymbolInstances(); |
|
66 |
} |
|
67 |
|
|
68 |
public void testLayerTypeAdditionFor_MARKERS() { |
|
69 |
MultiLayerMarkerSymbol multiLayer = new MultiLayerMarkerSymbol(); |
|
70 |
for (int i = 0; i < symbols.length; i++) { |
|
71 |
if (symbols[i] instanceof IMarkerSymbol) { |
|
72 |
try { |
|
73 |
IMarkerSymbol marker = (IMarkerSymbol) symbols[i]; |
|
74 |
multiLayer.addLayer(marker); |
|
75 |
} catch (Exception e) { |
|
76 |
fail("MultiLayerMarkerSymbol failed adding a '"+symbols[i].getClass().getName()); |
|
77 |
} |
|
78 |
} else { |
|
79 |
try { |
|
80 |
multiLayer.addLayer(symbols[i]); |
|
81 |
fail("MultiLayerMarkerSymbol should not accept '"+symbols[i].getClass().getName()+"' symbols"); |
|
82 |
} catch (ClassCastException ccEx){ |
|
83 |
// this is right |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
public void testLayerTypeAdditionFor_LINES() { |
|
90 |
MultiLayerLineSymbol multiLayer = new MultiLayerLineSymbol(); |
|
91 |
for (int i = 0; i < symbols.length; i++) { |
|
92 |
if (symbols[i] instanceof ILineSymbol) { |
|
93 |
try { |
|
94 |
ILineSymbol line = (ILineSymbol) symbols[i]; |
|
95 |
multiLayer.addLayer(line); |
|
96 |
} catch (Exception e) { |
|
97 |
fail("MultiLayerLineSymbol failed adding a '"+symbols[i].getClass().getName()); |
|
98 |
} |
|
99 |
} else { |
|
100 |
try { |
|
101 |
multiLayer.addLayer(symbols[i]); |
|
102 |
fail("MultiLayerLineSymbol should not accept '"+symbols[i].getClass().getName()+"' symbols"); |
|
103 |
} catch (ClassCastException ccEx){ |
|
104 |
// this is right |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
public void testLayerTypeAdditionFor_FILL() { |
|
111 |
MultiLayerFillSymbol multiLayer = new MultiLayerFillSymbol(); |
|
112 |
for (int i = 0; i < symbols.length; i++) { |
|
113 |
if (symbols[i] instanceof IFillSymbol) { |
|
114 |
try { |
|
115 |
IFillSymbol fill = (IFillSymbol) symbols[i]; |
|
116 |
multiLayer.addLayer(fill); |
|
117 |
} catch (Exception e) { |
|
118 |
fail("MultiLayerLineSymbol failed adding a '"+symbols[i].getClass().getName()); |
|
119 |
} |
|
120 |
} else { |
|
121 |
try { |
|
122 |
multiLayer.addLayer(symbols[i]); |
|
123 |
fail("MultiLayerLineSymbol should not accept '"+symbols[i].getClass().getName()+"' symbols"); |
|
124 |
} catch (ClassCastException ccEx){ |
|
125 |
// this is right |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
public void testLayerAdditionPositionConsistencyMultiLayer_MARKER_Symbol() { |
|
132 |
MultiLayerMarkerSymbol multiLayer = new MultiLayerMarkerSymbol(); |
|
133 |
IMarkerSymbol sym1 = new SimpleMarkerSymbol(); |
|
134 |
IMarkerSymbol sym2 = new SimpleMarkerSymbol(); |
|
135 |
sym1.setDescription("sym1"); |
|
136 |
sym2.setDescription("sym2"); |
|
137 |
try { |
|
138 |
multiLayer.addLayer(sym1, 0); |
|
139 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
140 |
fail("MultiLayer should always accept adding at index 0, even when it is empty"); |
|
141 |
} |
|
142 |
|
|
143 |
try { |
|
144 |
multiLayer.addLayer(sym2, 3); |
|
145 |
fail("MultiLayer cannot accept adding at an index larger than the amount of layers already contained"); |
|
146 |
} catch (IndexOutOfBoundsException ioobEx){ |
|
147 |
// this is right |
|
148 |
} |
|
149 |
|
|
150 |
try { |
|
151 |
multiLayer.addLayer(sym1, multiLayer.getLayerCount()); |
|
152 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
153 |
fail("MultiLayer should accept adding at index less or equal to the layer count"); |
|
154 |
} |
|
155 |
|
|
156 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(1).getDescription().equals("sym2")); |
|
157 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(0).getDescription().equals("sym1")); |
|
158 |
} |
|
159 |
|
|
160 |
public void testLayerAdditionPositionConsistencyMultiLayer_LINE_Symbol() { |
|
161 |
MultiLayerLineSymbol multiLayer = new MultiLayerLineSymbol(); |
|
162 |
ILineSymbol layer1 = new SimpleLineSymbol(); |
|
163 |
ILineSymbol layer2 = new SimpleLineSymbol(); |
|
164 |
layer1.setDescription("layer1"); |
|
165 |
layer2.setDescription("layer2"); |
|
166 |
|
|
167 |
try { |
|
168 |
multiLayer.addLayer(layer1, 0); |
|
169 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
170 |
fail("MultiLayer should always accept adding at index 0, even when it is empty"); |
|
171 |
} |
|
172 |
|
|
173 |
try { |
|
174 |
multiLayer.addLayer(layer2, 3); |
|
175 |
fail("MultiLayer cannot accept adding at an index larger than the amount of layers already contained"); |
|
176 |
} catch (IndexOutOfBoundsException ioobEx){ |
|
177 |
// this is right |
|
178 |
} |
|
179 |
|
|
180 |
try { |
|
181 |
multiLayer.addLayer(layer2, multiLayer.getLayerCount()); |
|
182 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
183 |
fail("MultiLayer should accept adding at index less or equal to the layer count"); |
|
184 |
} |
|
185 |
|
|
186 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(1).getDescription().equals("layer2")); |
|
187 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(0).getDescription().equals("layer1")); |
|
188 |
} |
|
189 |
|
|
190 |
public void testLayerAdditionPositionConsistencyMultiLayer_FILL_Symbol() { |
|
191 |
MultiLayerFillSymbol multiLayer = new MultiLayerFillSymbol(); |
|
192 |
IFillSymbol layer1 = new SimpleFillSymbol(); |
|
193 |
IFillSymbol layer2 = new SimpleFillSymbol(); |
|
194 |
layer1.setDescription("layer1"); |
|
195 |
layer2.setDescription("layer2"); |
|
196 |
|
|
197 |
try { |
|
198 |
multiLayer.addLayer(layer1, 0); |
|
199 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
200 |
fail("MultiLayer should always accept adding at index 0, even when it is empty"); |
|
201 |
} |
|
202 |
|
|
203 |
try { |
|
204 |
multiLayer.addLayer(layer2, 3); |
|
205 |
fail("MultiLayer cannot accept adding at an index larger than the amount of layers already contained"); |
|
206 |
} catch (IndexOutOfBoundsException ioobEx){ |
|
207 |
// this is right |
|
208 |
} |
|
209 |
|
|
210 |
try { |
|
211 |
multiLayer.addLayer(layer2, multiLayer.getLayerCount()); |
|
212 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
213 |
fail("MultiLayer should accept adding at index less or equal to the layer count"); |
|
214 |
} |
|
215 |
|
|
216 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(1).getDescription().equals("layer2")); |
|
217 |
assertTrue("layer returned does not correspond with the index provided", multiLayer.getLayer(0).getDescription().equals("layer1")); |
|
218 |
} |
|
219 |
|
|
220 |
public void testMultiLayer_MARKER_SymbolLayerSwapping() { |
|
221 |
MultiLayerMarkerSymbol multiLayer = new MultiLayerMarkerSymbol(); |
|
222 |
IMarkerSymbol layer1 = new SimpleMarkerSymbol(); |
|
223 |
IMarkerSymbol layer2 = new SimpleMarkerSymbol(); |
|
224 |
IMarkerSymbol layer3 = new SimpleMarkerSymbol(); |
|
225 |
layer1.setDescription("layer1"); |
|
226 |
layer2.setDescription("layer2"); |
|
227 |
layer3.setDescription("layer3"); |
|
228 |
|
|
229 |
multiLayer.addLayer(layer1); |
|
230 |
multiLayer.addLayer(layer2); |
|
231 |
multiLayer.addLayer(layer3); |
|
232 |
|
|
233 |
multiLayer.swapLayers(1,0); |
|
234 |
assertTrue("failed swapping layers 0 and 1", |
|
235 |
multiLayer.getLayer(0).getDescription().equals("layer2") |
|
236 |
&& multiLayer.getLayer(1).getDescription().equals("layer1")); |
|
237 |
|
|
238 |
multiLayer.swapLayers(1,2); |
|
239 |
assertTrue("failed swapping layers 0 and 1", |
|
240 |
multiLayer.getLayer(2).getDescription().equals("layer1") |
|
241 |
&& multiLayer.getLayer(1).getDescription().equals("layer3")); |
|
242 |
|
|
243 |
Random random = new Random(System.currentTimeMillis()); |
|
244 |
int numTries = 50; |
|
245 |
for (int i = 0; i < numTries; i++) { |
|
246 |
int n = random.nextInt(multiLayer.getLayerCount()); |
|
247 |
int m = random.nextInt(multiLayer.getLayerCount()); |
|
248 |
|
|
249 |
ISymbol aLayer = multiLayer.getLayer(n); |
|
250 |
multiLayer.swapLayers(n, m); |
|
251 |
ISymbol otherLayer = multiLayer.getLayer(m); |
|
252 |
assertEquals("failed swapping layers "+n+" and "+m, aLayer, otherLayer); |
|
253 |
} |
|
254 |
|
|
255 |
} |
|
256 |
|
|
257 |
public void testMultiLayer_LINE_SymbolLayerSwapping() { |
|
258 |
MultiLayerLineSymbol multiLayer = new MultiLayerLineSymbol(); |
|
259 |
ILineSymbol layer1 = new SimpleLineSymbol(); |
|
260 |
ILineSymbol layer2 = new SimpleLineSymbol(); |
|
261 |
ILineSymbol layer3 = new SimpleLineSymbol(); |
|
262 |
layer1.setDescription("layer1"); |
|
263 |
layer2.setDescription("layer2"); |
|
264 |
layer3.setDescription("layer3"); |
|
265 |
|
|
266 |
multiLayer.addLayer(layer1); |
|
267 |
multiLayer.addLayer(layer2); |
|
268 |
multiLayer.addLayer(layer3); |
|
269 |
|
|
270 |
multiLayer.swapLayers(1,0); |
|
271 |
assertTrue("failed swapping layers 0 and 1", |
|
272 |
multiLayer.getLayer(0).getDescription().equals("layer2") |
|
273 |
&& multiLayer.getLayer(1).getDescription().equals("layer1")); |
|
274 |
|
|
275 |
multiLayer.swapLayers(1,2); |
|
276 |
assertTrue("failed swapping layers 0 and 1", |
|
277 |
multiLayer.getLayer(2).getDescription().equals("layer1") |
|
278 |
&& multiLayer.getLayer(1).getDescription().equals("layer3")); |
|
279 |
|
|
280 |
Random random = new Random(System.currentTimeMillis()); |
|
281 |
int numTries = 50; |
|
282 |
for (int i = 0; i < numTries; i++) { |
|
283 |
int n = random.nextInt(multiLayer.getLayerCount()); |
|
284 |
int m = random.nextInt(multiLayer.getLayerCount()); |
|
285 |
|
|
286 |
ISymbol aLayer = multiLayer.getLayer(n); |
|
287 |
multiLayer.swapLayers(n, m); |
|
288 |
ISymbol otherLayer = multiLayer.getLayer(m); |
|
289 |
assertEquals("failed swapping layers "+n+" and "+m, aLayer, otherLayer); |
|
290 |
} |
|
291 |
|
|
292 |
} |
|
293 |
|
|
294 |
public void testMultiLayer_FILL_SymbolLayerSwapping() { |
|
295 |
MultiLayerFillSymbol multiLayer = new MultiLayerFillSymbol(); |
|
296 |
IFillSymbol layer1 = new SimpleFillSymbol(); |
|
297 |
IFillSymbol layer2 = new SimpleFillSymbol(); |
|
298 |
IFillSymbol layer3 = new SimpleFillSymbol(); |
|
299 |
layer1.setDescription("layer1"); |
|
300 |
layer2.setDescription("layer2"); |
|
301 |
layer3.setDescription("layer3"); |
|
302 |
|
|
303 |
multiLayer.addLayer(layer1); |
|
304 |
multiLayer.addLayer(layer2); |
|
305 |
multiLayer.addLayer(layer3); |
|
306 |
|
|
307 |
multiLayer.swapLayers(1,0); |
|
308 |
assertTrue("failed swapping layers 0 and 1", |
|
309 |
multiLayer.getLayer(0).getDescription().equals("layer2") |
|
310 |
&& multiLayer.getLayer(1).getDescription().equals("layer1")); |
|
311 |
|
|
312 |
multiLayer.swapLayers(1,2); |
|
313 |
assertTrue("failed swapping layers 0 and 1", |
|
314 |
multiLayer.getLayer(2).getDescription().equals("layer1") |
|
315 |
&& multiLayer.getLayer(1).getDescription().equals("layer3")); |
|
316 |
|
|
317 |
Random random = new Random(System.currentTimeMillis()); |
|
318 |
int numTries = 50; |
|
319 |
for (int i = 0; i < numTries; i++) { |
|
320 |
int n = random.nextInt(multiLayer.getLayerCount()); |
|
321 |
int m = random.nextInt(multiLayer.getLayerCount()); |
|
322 |
|
|
323 |
ISymbol aLayer = multiLayer.getLayer(n); |
|
324 |
multiLayer.swapLayers(n, m); |
|
325 |
ISymbol otherLayer = multiLayer.getLayer(m); |
|
326 |
assertEquals("failed swapping layers "+n+" and "+m, aLayer, otherLayer); |
|
327 |
} |
|
328 |
} |
|
329 |
|
|
330 |
public void testMultiLayer_MARKER_IndexOutOfBounds() { |
|
331 |
MultiLayerMarkerSymbol multiLayer = new MultiLayerMarkerSymbol(); |
|
332 |
IMarkerSymbol layer1 = new SimpleMarkerSymbol(); |
|
333 |
IMarkerSymbol layer2 = new SimpleMarkerSymbol(); |
|
334 |
IMarkerSymbol layer3 = new SimpleMarkerSymbol(); |
|
335 |
layer1.setDescription("layer1"); |
|
336 |
layer2.setDescription("layer2"); |
|
337 |
layer3.setDescription("layer3"); |
|
338 |
|
|
339 |
multiLayer.addLayer(layer1); |
|
340 |
multiLayer.addLayer(layer2); |
|
341 |
multiLayer.addLayer(layer3); |
|
342 |
|
|
343 |
for (int i = -4; i < multiLayer.getLayerCount()+4; i++) { |
|
344 |
if (i<0 || i>=multiLayer.getLayerCount()) { |
|
345 |
try { |
|
346 |
multiLayer.getLayer(i); |
|
347 |
fail("MultiLayerMarkerSymbol should throw an IndexOutOfBoundsException when accessing a layer at index "+i+", because layer count is "+multiLayer.getLayerCount()); |
|
348 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
349 |
// this is correct; |
|
350 |
} |
|
351 |
} else { |
|
352 |
try { |
|
353 |
multiLayer.getLayer(i); |
|
354 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
355 |
fail("MultiLayerMarkerSymbol threw an IndexOutOfBoundsException, but it has "+multiLayer.getLayerCount()+" layers"); |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
} |
|
360 |
|
|
361 |
public void testMultiLayer_LINE_IndexOutOfBounds() { |
|
362 |
MultiLayerLineSymbol multiLayer = new MultiLayerLineSymbol(); |
|
363 |
ILineSymbol layer1 = new SimpleLineSymbol(); |
|
364 |
ILineSymbol layer2 = new SimpleLineSymbol(); |
|
365 |
ILineSymbol layer3 = new SimpleLineSymbol(); |
|
366 |
layer1.setDescription("layer1"); |
|
367 |
layer2.setDescription("layer2"); |
|
368 |
layer3.setDescription("layer3"); |
|
369 |
|
|
370 |
multiLayer.addLayer(layer1); |
|
371 |
multiLayer.addLayer(layer2); |
|
372 |
multiLayer.addLayer(layer3); |
|
373 |
|
|
374 |
for (int i = -4; i < multiLayer.getLayerCount()+4; i++) { |
|
375 |
if (i<0 || i>=multiLayer.getLayerCount()) { |
|
376 |
try { |
|
377 |
multiLayer.getLayer(i); |
|
378 |
fail("MultiLayerLineSymbol should throw an IndexOutOfBoundsException when accessing a layer at index "+i+", because layer count is "+multiLayer.getLayerCount()); |
|
379 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
380 |
// this is correct; |
|
381 |
} |
|
382 |
} else { |
|
383 |
try { |
|
384 |
multiLayer.getLayer(i); |
|
385 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
386 |
fail("MultiLayerLineSymbol threw an IndexOutOfBoundsException, but it has "+multiLayer.getLayerCount()+" layers"); |
|
387 |
} |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
|
|
392 |
public void testMultiLayer_FILL_IndexOutOfBounds() { |
|
393 |
MultiLayerFillSymbol multiLayer = new MultiLayerFillSymbol(); |
|
394 |
IFillSymbol layer1 = new SimpleFillSymbol(); |
|
395 |
IFillSymbol layer2 = new SimpleFillSymbol(); |
|
396 |
IFillSymbol layer3 = new SimpleFillSymbol(); |
|
397 |
layer1.setDescription("layer1"); |
|
398 |
layer2.setDescription("layer2"); |
|
399 |
layer3.setDescription("layer3"); |
|
400 |
|
|
401 |
multiLayer.addLayer(layer1); |
|
402 |
multiLayer.addLayer(layer2); |
|
403 |
multiLayer.addLayer(layer3); |
|
404 |
for (int i = -4; i < multiLayer.getLayerCount()+4; i++) { |
|
405 |
if (i<0 || i>=multiLayer.getLayerCount()) { |
|
406 |
try { |
|
407 |
multiLayer.getLayer(i); |
|
408 |
fail("MultiLayerFillSymbol should throw an IndexOutOfBoundsException when accessing a layer at index "+i+", because layer count is "+multiLayer.getLayerCount()); |
|
409 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
410 |
// this is correct; |
|
411 |
} |
|
412 |
} else { |
|
413 |
try { |
|
414 |
multiLayer.getLayer(i); |
|
415 |
} catch (IndexOutOfBoundsException ioobEx) { |
|
416 |
fail("MultiLayerFillSymbol threw an IndexOutOfBoundsException, but it has "+multiLayer.getLayerCount()+" layers"); |
|
417 |
} |
|
418 |
} |
|
419 |
} |
|
420 |
|
|
421 |
} |
|
422 |
} |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestISymbol.java | ||
---|---|---|
1 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.lang.reflect.Field; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Random; |
|
7 |
|
|
8 |
import junit.framework.TestSuite; |
|
9 |
|
|
10 |
import org.gvsig.fmap.geom.Geometry; |
|
11 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
12 |
import org.gvsig.fmap.geom.GeometryManager; |
|
13 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
14 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
15 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
16 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
17 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
18 |
import org.gvsig.fmap.geom.primitive.Point; |
|
19 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
20 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
21 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
|
22 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
23 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
24 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
25 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
26 |
|
|
27 |
/** |
|
28 |
* Integration test to ensure that the symbols follow the rules that follow the |
|
29 |
* managing of them by the application. |
|
30 |
* |
|
31 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
32 |
*/ |
|
33 |
|
|
34 |
|
|
35 |
public class TestISymbol extends AbstractLibraryAutoInitTestCase { |
|
36 |
private static ArrayList classesToTest;//<AbstractSymbolTestCase> |
|
37 |
transient private ISymbol[] symbols; |
|
38 |
|
|
39 |
public static TestSuite suite() { |
|
40 |
TestSuite suite = new TestSuite("Integration test for com.iver.cit.gvsig.fmap.core.ISymbol"); |
|
41 |
suite.addTestSuite(TestISymbol.class); |
|
42 |
suite.addTestSuite(TestDrawMarkers.class); |
|
43 |
suite.addTestSuite(TestDrawLines.class); |
|
44 |
suite.addTestSuite(TestDrawFills.class); |
|
45 |
|
|
46 |
return suite; |
|
47 |
} |
|
48 |
|
|
49 |
protected void doSetUp() throws Exception { |
|
50 |
addSymbols(); |
|
51 |
symbols = getNewSymbolInstances(); |
|
52 |
} |
|
53 |
|
|
54 |
public static void addSymbols() { |
|
55 |
addSymbolTest(new SimpleFillSymbolTest()); |
|
56 |
addSymbolTest(new SimpleLineSymbolTest()); |
|
57 |
addSymbolTest(new SimpleMarkerSymbolTest()); |
|
58 |
addSymbolTest(new SimpleTextSymbolTest()); |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
public static void addSymbolTest(AbstractSymbolTestCase symbolTestClass) { |
|
63 |
if (classesToTest == null) classesToTest = new ArrayList(); //<AbstractSymbolTestCase> |
|
64 |
|
|
65 |
classesToTest.add(symbolTestClass); |
|
66 |
} |
|
67 |
|
|
68 |
public static ISymbol[] getNewSymbolInstances() { |
|
69 |
ISymbol[] symbols = new ISymbol[classesToTest.size()]; |
|
70 |
for (int i = 0; i < symbols.length; i++) { |
|
71 |
symbols[i] = (ISymbol)((AbstractSymbolTestCase)classesToTest.get(i)).newInstance(); |
|
72 |
} |
|
73 |
return symbols; |
|
74 |
} |
|
75 |
|
|
76 |
public void testPointSuitability() throws InstantiationException, IllegalAccessException, CreateGeometryException { |
|
77 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
78 |
Point point = (Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
|
79 |
final Geometry dummyPointGeom = point; |
|
80 |
for (int i = 0; i < symbols.length; i++) { |
|
81 |
// text symbols are suitable for everything |
|
82 |
if (symbols[i] instanceof ITextSymbol) { |
|
83 |
assertTrue(symbols[i].getClass().getName()+" should be suitable for "+dummyPointGeom, |
|
84 |
symbols[i].isSuitableFor(dummyPointGeom)); |
|
85 |
} else |
|
86 |
|
|
87 |
// marker symbols are suitable for points |
|
88 |
if (symbols[i] instanceof IMarkerSymbol) { |
|
89 |
assertTrue(symbols[i].getClass().getName()+" should be suitable for "+dummyPointGeom, |
|
90 |
symbols[i].isSuitableFor(dummyPointGeom)); |
|
91 |
} else { |
|
92 |
assertFalse(symbols[i].getClass().getName()+" should NOT be suitable for "+dummyPointGeom, |
|
93 |
symbols[i].isSuitableFor(dummyPointGeom)); |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
public void testLineSuitability() throws InstantiationException, IllegalAccessException, CreateGeometryException { |
|
99 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
100 |
Curve curve = (Curve)geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D); |
|
101 |
curve.setGeneralPath(new GeneralPathX()); |
|
102 |
final Geometry dummyLineGeom = curve; |
|
103 |
for (int i = 0; i < symbols.length; i++) { |
|
104 |
// text symbols are suitable for everything |
|
105 |
if (symbols[i] instanceof ITextSymbol) { |
|
106 |
assertTrue(symbols[i].getClass().getName()+" should be suitable for "+dummyLineGeom, |
|
107 |
symbols[i].isSuitableFor(dummyLineGeom)); |
|
108 |
} else |
|
109 |
|
|
110 |
// line symbols are suitable for line |
|
111 |
if (symbols[i] instanceof ILineSymbol) { |
|
112 |
assertTrue(symbols[i].getClass().getName()+" should be suitable for "+dummyLineGeom, |
|
113 |
symbols[i].isSuitableFor(dummyLineGeom)); |
|
114 |
} else { |
|
115 |
assertFalse(symbols[i].getClass().getName()+" should NOT be suitable for "+dummyLineGeom, |
|
116 |
symbols[i].isSuitableFor(dummyLineGeom)); |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
public void testPolygonSuitability() throws InstantiationException, IllegalAccessException, CreateGeometryException { |
|
122 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
123 |
Surface surface = (Surface)geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
|
124 |
surface.setGeneralPath(new GeneralPathX()); |
|
125 |
final Geometry dummyPolygonGeom = surface; |
|
126 |
for (int i = 0; i < symbols.length; i++) { |
|
127 |
|
|
128 |
// text symbols are suitable for everything |
|
129 |
if (symbols[i] instanceof ITextSymbol) { |
|
130 |
assertTrue(symbols[i].getClass().getName()+" should be suitable for "+dummyPolygonGeom, |
|
131 |
symbols[i].isSuitableFor(dummyPolygonGeom)); |
|
132 |
} else |
|
133 |
|
|
134 |
// fill symbols are suitable for polygons |
|
135 |
if (symbols[i] instanceof IFillSymbol) { |
|
136 |
assertTrue(symbols[i].getClass().getName()+" should be suitable for "+dummyPolygonGeom, |
|
137 |
symbols[i].isSuitableFor(dummyPolygonGeom)); |
|
138 |
} else { |
|
139 |
assertFalse(symbols[i].getClass().getName()+" should NOT be suitable for "+dummyPolygonGeom, |
|
140 |
symbols[i].isSuitableFor(dummyPolygonGeom)); |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* tests whether the symbols were correctly configured to work with |
|
147 |
* different kinds of shapes. |
|
148 |
*/ |
|
149 |
public void testGeneralSuitability() { |
|
150 |
|
|
151 |
for (int i = 0; i < symbols.length; i++) { |
|
152 |
// text symbols are suitable for everything |
|
153 |
if (symbols[i] instanceof ITextSymbol) { |
|
154 |
assertTrue(symbols[i].getClass().getName()+" should be suitable for "+null, |
|
155 |
symbols[i].isSuitableFor(null)); |
|
156 |
} else { |
|
157 |
try { |
|
158 |
symbols[i].isSuitableFor(null); |
|
159 |
fail("Exception was not thrown"); |
|
160 |
|
|
161 |
} catch (NullPointerException npEx) { |
|
162 |
// this is correct! |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* ensures that symbols defined which can of FShape is the symbol |
|
170 |
*/ |
|
171 |
public void testSymbolTypeDefinition() { |
|
172 |
for (int i = 0; i < symbols.length; i++) { |
|
173 |
assertFalse("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"'", |
|
174 |
symbols[i].getSymbolType() == 0); |
|
175 |
|
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* ensures that any symbol that is suitable for markers declares its type |
|
181 |
* as FShape.POINT or FShape.MULTI |
|
182 |
* |
|
183 |
*/ |
|
184 |
public void testMarkerSymbolTypeDefinition() { |
|
185 |
for (int i = 0; i < symbols.length; i++) { |
|
186 |
if (symbols[i] instanceof IMarkerSymbol) { |
|
187 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"'", |
|
188 |
symbols[i].getSymbolType() == Geometry.TYPES.POINT |
|
189 |
|| symbols[i].getSymbolType() == Geometry.TYPES.GEOMETRY); |
|
190 |
} |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* ensures that any symbol that is suitable for lines declares its type |
|
196 |
* as FShape.LINE or FShape.MULTI |
|
197 |
* |
|
198 |
*/ |
|
199 |
public void testLineSymbolTypeDefinition() { |
|
200 |
for (int i = 0; i < symbols.length; i++) { |
|
201 |
if (symbols[i] instanceof ILineSymbol) { |
|
202 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"'", |
|
203 |
symbols[i].getSymbolType() == Geometry.TYPES.CURVE |
|
204 |
|| symbols[i].getSymbolType() == Geometry.TYPES.GEOMETRY); |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* ensures that any symbol that is suitable for fills declares its type |
|
211 |
* as POLYGON or Geometry.TYPES.GEOMETRY |
|
212 |
* |
|
213 |
*/ |
|
214 |
public void testFillSymbolTypeDefinition() { |
|
215 |
for (int i = 0; i < symbols.length; i++) { |
|
216 |
if (symbols[i] instanceof IFillSymbol) { |
|
217 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"'", |
|
218 |
symbols[i].getSymbolType() == Geometry.TYPES.SURFACE |
|
219 |
|| symbols[i].getSymbolType() == Geometry.TYPES.GEOMETRY); |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
|
|
224 |
// /** |
|
225 |
// * ensures that any symbol has a description in its persistence |
|
226 |
// * (very important) |
|
227 |
// */ |
|
228 |
// public void testDescription() { |
|
229 |
// for (int i = 0; i < symbols.length; i++) { |
|
230 |
// try { |
|
231 |
// assertTrue(symbols[i].getClass().getName() + " does not declare a description in its XMLEntity", |
|
232 |
// symbols[i].getXMLEntity().contains("desc")); |
|
233 |
// } catch (XMLException e) { |
|
234 |
// // TODO Auto-generated catch block |
|
235 |
// e.printStackTrace(); |
|
236 |
// } |
|
237 |
// } |
|
238 |
// } |
|
239 |
|
|
240 |
// /** |
|
241 |
// * ensures that any symbol has an isShapeVisible field in its persistence |
|
242 |
// * (very important) |
|
243 |
// */ |
|
244 |
// public void testIsShapeVisible() { |
|
245 |
// for (int i = 0; i < symbols.length; i++) { |
|
246 |
// try { |
|
247 |
// assertTrue(symbols[i].getClass().getName() + " does not declare the isShapeVisible field in its XMLEntity", |
|
248 |
// symbols[i].getXMLEntity().contains("isShapeVisible")); |
|
249 |
// } catch (XMLException e) { |
|
250 |
// // TODO Auto-generated catch block |
|
251 |
// e.printStackTrace(); |
|
252 |
// } |
|
253 |
// } |
|
254 |
// } |
|
255 |
|
|
256 |
/** |
|
257 |
* ensures that the symbol is self-defining |
|
258 |
* @throws Exception |
|
259 |
*/ |
|
260 |
public void testSymbolSelfDefinition() throws Exception { |
|
261 |
for (int i = 0; i < symbols.length; i++) { |
|
262 |
final ISymbol theSymbol = symbols[i]; |
|
263 |
ISymbol cloneSymbol= (ISymbol) theSymbol.clone(); |
|
264 |
//cloneSymbol = SymbologyFactory.createSymbolFromXML(theSymbol.getXMLEntity(), null); |
|
265 |
|
|
266 |
assertTrue(theSymbol.getClass().getName()+ " wrong class name declaration in getXMLEntity() ", |
|
267 |
cloneSymbol.getClass().equals(theSymbol.getClass())); |
|
268 |
final Field[] theSymbolFields = theSymbol.getClass().getFields(); |
|
269 |
for (int j = 0; j < theSymbolFields.length; j++) { |
|
270 |
final Field fi = theSymbolFields[j]; |
|
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 (IllegalArgumentException e) { |
|
278 |
fail(); |
|
279 |
} catch (IllegalAccessException e) { |
|
280 |
fail(); |
|
281 |
} |
|
282 |
fi.setAccessible(wasAccessible); |
|
283 |
} |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* Check one pixel acceleration consistency. Checks that the color returned |
|
289 |
* in RGB matches the color of the symbol set. |
|
290 |
* |
|
291 |
*/ |
|
292 |
public void testOnePointRGB() { |
|
293 |
Random random = new Random(System.currentTimeMillis()); |
|
294 |
|
|
295 |
for (int i = 0; i < symbols.length; i++) { |
|
296 |
if (symbols[i] instanceof IMarkerSymbol) { |
|
297 |
IMarkerSymbol marker = (IMarkerSymbol) symbols[i]; |
|
298 |
marker.setColor(new Color(random.nextInt()>>8)); |
|
299 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"' RGB value mismatch for getOnePointRBG() and getColor().getRGB()", |
|
300 |
symbols[i].getOnePointRgb() == marker.getColor().getRGB()); |
|
301 |
|
|
302 |
} |
|
303 |
|
|
304 |
if (symbols[i] instanceof ILineSymbol) { |
|
305 |
ILineSymbol line = (ILineSymbol) symbols[i]; |
|
306 |
line.setLineColor(new Color(random.nextInt()>>8)); |
|
307 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"' RGB value mismatch for getOnePointRBG() and getColor().getRGB()", |
|
308 |
symbols[i].getOnePointRgb() == line.getColor().getRGB()); |
|
309 |
} |
|
310 |
|
|
311 |
if (symbols[i] instanceof IFillSymbol) { |
|
312 |
IFillSymbol fill = (IFillSymbol) symbols[i]; |
|
313 |
boolean outlined = fill.getOutline() != null; |
|
314 |
if (!outlined) |
|
315 |
fill.setFillColor(new Color(random.nextInt()>>8)); |
|
316 |
else |
|
317 |
fill.getOutline().setLineColor(new Color(random.nextInt()>>8)); |
|
318 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"' RGB value mismatch for getOnePointRBG() and getColor().getRGB()", |
|
319 |
symbols[i].getOnePointRgb() == ((outlined) ? fill.getOutline().getColor().getRGB() : fill.getFillColor().getRGB())); |
|
320 |
} |
|
321 |
|
|
322 |
if (symbols[i] instanceof ITextSymbol) { |
|
323 |
ITextSymbol text = (ITextSymbol) symbols[i]; |
|
324 |
text.setTextColor(new Color(random.nextInt()>>8)); |
|
325 |
assertTrue("Symbol no. "+i+" '"+symbols[i].getClass().getName()+"' RGB value mismatch for getOnePointRBG() and getColor().getRGB()", |
|
326 |
symbols[i].getOnePointRgb() == text.getTextColor().getRGB()); |
|
327 |
} |
|
328 |
|
|
329 |
} |
|
330 |
} |
|
331 |
|
|
332 |
/** |
|
333 |
* ensures that any symbol provides a version of itself to use when the |
|
334 |
* feature is selected |
|
335 |
* |
|
336 |
*/ |
|
337 |
public void testSymbolForSelection() { |
|
338 |
for (int i = 0; i < symbols.length; i++) { |
|
339 |
assertNotNull("Symbol no. "+i+" '"+symbols[i].getClass().getName()+" does not define any derived symbol for selection", symbols[i].getSymbolForSelection()); |
|
340 |
} |
|
341 |
} |
|
342 |
} |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/SimpleMarkerSymbolTest.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol; |
|
42 |
|
|
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
|
44 |
|
|
45 |
public class SimpleMarkerSymbolTest extends AbstractSymbolTestCase{ |
|
46 |
public SimpleMarkerSymbolTest() { |
|
47 |
super(SimpleMarkerSymbol.class); |
|
48 |
} |
|
49 |
} |
tags/v2_0_0_Build_2022/extensions/org.gvsig.symbology/src/test/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/TestDrawMarkers.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
Also available in: Unified diff