001: package org.geotools.renderer.lite;
002:
003: import java.awt.Color;
004:
005: import junit.framework.TestCase;
006:
007: import org.geotools.styling.Graphic;
008: import org.geotools.styling.PointSymbolizer;
009: import org.geotools.styling.Rule;
010: import org.geotools.styling.Style;
011: import org.geotools.styling.StyleBuilder;
012: import org.geotools.styling.Symbolizer;
013:
014: public class RenderingBufferExtractorTest extends TestCase {
015: StyleBuilder sb = new StyleBuilder();
016:
017: public void testNoStroke() {
018: Style style = sb.createStyle(sb.createTextSymbolizer());
019: MetaBufferEstimator rbe = new MetaBufferEstimator();
020: assertEquals(0, rbe.getBuffer());
021: assertTrue(rbe.isEstimateAccurate());
022: rbe.visit(style);
023: assertEquals(0, rbe.getBuffer());
024: assertTrue(rbe.isEstimateAccurate());
025: }
026:
027: public void testSimpleStroke() {
028: Style style = sb.createStyle(sb.createLineSymbolizer(sb
029: .createStroke(10.0)));
030: MetaBufferEstimator rbe = new MetaBufferEstimator();
031: rbe.visit(style);
032: assertEquals(10, rbe.getBuffer());
033: assertTrue(rbe.isEstimateAccurate());
034: }
035:
036: public void testSimpleGraphic() {
037: PointSymbolizer ps = sb.createPointSymbolizer(sb.createGraphic(
038: null, sb.createMark(sb.MARK_CIRCLE), null));
039: ps.getGraphic().setSize(sb.literalExpression(15));
040: Style style = sb.createStyle(ps);
041:
042: MetaBufferEstimator rbe = new MetaBufferEstimator();
043: rbe.visit(style);
044: assertEquals(15, rbe.getBuffer());
045: assertTrue(rbe.isEstimateAccurate());
046: }
047:
048: public void testNpePreventionGraphic() {
049: PointSymbolizer ps = sb.createPointSymbolizer(sb.createGraphic(
050: null, sb.createMark(sb.MARK_CIRCLE), null));
051: ps.getGraphic().setSize(sb.literalExpression(null));
052: Style style = sb.createStyle(ps);
053:
054: MetaBufferEstimator rbe = new MetaBufferEstimator();
055: rbe.visit(style);
056: assertEquals(0, rbe.getBuffer());
057: assertFalse(rbe.isEstimateAccurate());
058: }
059:
060: public void testNonIntegerStroke() {
061: Style style = sb.createStyle(sb.createLineSymbolizer(sb
062: .createStroke(10.8)));
063: MetaBufferEstimator rbe = new MetaBufferEstimator();
064: rbe.visit(style);
065: assertEquals(11, rbe.getBuffer());
066: assertTrue(rbe.isEstimateAccurate());
067: }
068:
069: public void testMultiSymbolizers() {
070: Symbolizer ls = sb.createLineSymbolizer(sb.createStroke(10.8));
071: Symbolizer ps = sb.createPolygonSymbolizer(sb.createStroke(12),
072: sb.createFill());
073: Rule r = sb.createRule(new Symbolizer[] { ls, ps });
074: MetaBufferEstimator rbe = new MetaBufferEstimator();
075: rbe.visit(r);
076: assertEquals(12, rbe.getBuffer());
077: assertTrue(rbe.isEstimateAccurate());
078: }
079:
080: public void testPropertyWidth() {
081: Symbolizer ls = sb.createLineSymbolizer(sb.createStroke(sb
082: .colorExpression(Color.BLACK), sb
083: .attributeExpression("gimbo")));
084: Symbolizer ps = sb.createPolygonSymbolizer(sb.createStroke(12),
085: sb.createFill());
086: Rule r = sb.createRule(new Symbolizer[] { ls, ps });
087: MetaBufferEstimator rbe = new MetaBufferEstimator();
088: rbe.visit(r);
089: assertEquals(12, rbe.getBuffer());
090: assertTrue(!rbe.isEstimateAccurate());
091: }
092:
093: public void testLiteralParseStroke() {
094: Style style = sb.createStyle(sb.createLineSymbolizer(sb
095: .createStroke(sb.colorExpression(Color.BLACK), sb
096: .literalExpression("10.0"))));
097: MetaBufferEstimator rbe = new MetaBufferEstimator();
098: rbe.visit(style);
099: assertEquals(10, rbe.getBuffer());
100: assertTrue(rbe.isEstimateAccurate());
101: }
102:
103: public void testNpePreventionStroke() {
104: Style style = sb.createStyle(sb.createLineSymbolizer(sb
105: .createStroke(sb.colorExpression(Color.BLACK), sb
106: .literalExpression(null))));
107: MetaBufferEstimator rbe = new MetaBufferEstimator();
108: rbe.visit(style);
109: assertEquals(0, rbe.getBuffer());
110: assertFalse(rbe.isEstimateAccurate());
111: }
112:
113: public void testLiteralParseGraphics() {
114: Graphic g = sb.createGraphic();
115: g.setSize(sb.literalExpression("10.0"));
116: MetaBufferEstimator rbe = new MetaBufferEstimator();
117: rbe.visit(g);
118: assertEquals(10, rbe.getBuffer());
119: assertTrue(rbe.isEstimateAccurate());
120: }
121: }
|