001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.generation.asciiart;
018:
019: import java.text.NumberFormat;
020: import java.util.Iterator;
021: import java.util.Locale;
022:
023: import junit.framework.TestCase;
024: import junit.textui.TestRunner;
025:
026: /**
027: * A Simple testcase of the AsciiArtPad.
028: *
029: * @author huber.at.apache.org
030: * @since 18. December 2002
031: * @version CVS $Id: AsciiArtPadTestCase.java 433543 2006-08-22 06:22:54Z crossley $
032: */
033: public class AsciiArtPadTestCase extends TestCase {
034:
035: private AsciiArtPad asciiArtPad;
036:
037: /**
038: *Constructor for the AsciiArtPadTestCase object
039: *
040: *@param name Description of Parameter
041: *@since
042: */
043: public AsciiArtPadTestCase(String name) {
044: super (name);
045: }
046:
047: /**
048: * The main program for the AsciiArtPadTestCase class
049: *
050: *@param args The command line arguments
051: *@exception Exception Description of the Exception
052: */
053: public static void main(final String[] args) throws Exception {
054: final String[] testCaseName = { AsciiArtPadTestCase.class
055: .getName() };
056: TestRunner.main(testCaseName);
057: }
058:
059: /**
060: * A unit test for JUnit
061: */
062: public void test0() {
063: }
064:
065: /**
066: * A unit test for JUnit
067: *
068: *@exception Exception Description of the Exception
069: */
070: public void test1() throws Exception {
071: System.out.println("test1()");
072: String[] asciiArt = new String[] {
073: // 1
074: //01234567890123456789
075: "= =", " +--------------+ ",
076: " | 1st quarter | ", " +------------+-+ ",
077: " | 2nd | ", " +-----+------+ ",
078: " | 3rd | ", " +-----+ ",
079: "= =", " +-------------+ ",
080: " | container | ", " | | ",
081: " | +-------+ | ", " | | part | | ",
082: " | +-------+ | ", " | | ",
083: " +-------------+ ", "= =",
084: " +==============+ ", " | Mail_Header | ",
085: " | +========+ | ", " | | Body | | ",
086: " | +========+ | ", " | |a |a |a | | ",
087: " | |1 |2 |3 | | ", " | +========+ | ",
088: " +==============+ ", "= =",
089: " +----------------+", " | header |",
090: " +----------------+", " + c | col2 | c +",
091: " + o | | o +", " + l | | l +",
092: " + 1 | | 3 +", " +----------------+",
093: " | footer |", " +----------------+",
094: "= =", " +---stylesheets ",
095: " +---docs ", " | +---top_col_1 ",
096: " | +---mid_col_1 ", " | +---mid_col_2 ",
097: " | +---mid_col_3 ", " | +---mid_col_4 ",
098: " | \\---bottom_col_1", " \\---resources",
099: " |---styles", " \\---images", };
100:
101: asciiArtPad = new AsciiArtPad();
102: asciiArtPad.setXGrid(10);
103: asciiArtPad.setYGrid(12);
104: AsciiArtPad.AsciiArtPadBuilder aapb = new AsciiArtPad.AsciiArtPadBuilder(
105: asciiArtPad);
106: aapb.build(asciiArt);
107:
108: Iterator i = asciiArtPad.iterator();
109: NumberFormat nf = NumberFormat.getInstance(Locale.US);
110: StringBuffer svg_lines = new StringBuffer();
111: StringBuffer svg_text = new StringBuffer();
112: while (i.hasNext()) {
113: Object o = i.next();
114: double x;
115: double y;
116: if (o instanceof AsciiArtPad.AsciiArtLine) {
117: AsciiArtPad.AsciiArtLine aal = (AsciiArtPad.AsciiArtLine) o;
118: x = aal.getXStart();
119: y = aal.getYStart();
120: svg_lines.append("<path d=\"");
121: svg_lines.append("M " + nf.format(x) + " "
122: + nf.format(y));
123:
124: x = aal.getXEnd();
125: y = aal.getYEnd();
126: svg_lines.append("L " + nf.format(x) + " "
127: + nf.format(y));
128: svg_lines.append("\"/>\n");
129:
130: } else if (o instanceof AsciiArtPad.AsciiArtString) {
131: AsciiArtPad.AsciiArtString aas = (AsciiArtPad.AsciiArtString) o;
132: x = aas.getX();
133: y = aas.getY();
134: svg_text.append("<text ");
135: svg_text.append("x=\"" + nf.format(x) + "\" y=\""
136: + nf.format(y) + "\">");
137: svg_text.append("<![CDATA[" + aas.getS() + "]]>");
138: svg_text.append("</text>\n");
139:
140: } else {
141: System.out.println("o " + o.toString());
142: }
143: }
144: System.out.println("<!-- lines --> ");
145: System.out.println(svg_lines.toString());
146: System.out.println("<!-- text --> ");
147: System.out.println(svg_text.toString());
148: }
149:
150: /**
151: *The JUnit setup method
152: *
153: *@exception Exception Description of Exception
154: *@since
155: */
156: protected void setUp() throws Exception {
157: super .setUp();
158: asciiArtPad = null;
159: }
160:
161: /**
162: * The teardown method for JUnit
163: *
164: *@exception Exception Description of the Exception
165: */
166: protected void tearDown() throws Exception {
167: super.tearDown();
168: asciiArtPad = null;
169: }
170: }
|