1   /*
2    *  Java HTML Tidy - JTidy
3    *  HTML parser and pretty printer
4    *
5    *  Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
6    *  Institute of Technology, Institut National de Recherche en
7    *  Informatique et en Automatique, Keio University). All Rights
8    *  Reserved.
9    *
10   *  Contributing Author(s):
11   *
12   *     Dave Raggett <dsr@w3.org>
13   *     Andy Quick <ac.quick@sympatico.ca> (translation to Java)
14   *     Gary L Peskin <garyp@firstech.com> (Java development)
15   *     Sami Lempinen <sami@lempinen.net> (release management)
16   *     Fabrizio Giustina <fgiust at users.sourceforge.net>
17   *
18   *  The contributing author(s) would like to thank all those who
19   *  helped with testing, bug fixes, and patience.  This wouldn't
20   *  have been possible without all of you.
21   *
22   *  COPYRIGHT NOTICE:
23   *
24   *  This software and documentation is provided "as is," and
25   *  the copyright holders and contributing author(s) make no
26   *  representations or warranties, express or implied, including
27   *  but not limited to, warranties of merchantability or fitness
28   *  for any particular purpose or that the use of the software or
29   *  documentation will not infringe any third party patents,
30   *  copyrights, trademarks or other rights.
31   *
32   *  The copyright holders and contributing author(s) will not be
33   *  liable for any direct, indirect, special or consequential damages
34   *  arising out of any use of the software or documentation, even if
35   *  advised of the possibility of such damage.
36   *
37   *  Permission is hereby granted to use, copy, modify, and distribute
38   *  this source code, or portions hereof, documentation and executables,
39   *  for any purpose, without fee, subject to the following restrictions:
40   *
41   *  1. The origin of this source code must not be misrepresented.
42   *  2. Altered versions must be plainly marked as such and must
43   *     not be misrepresented as being the original source.
44   *  3. This Copyright notice may not be removed or altered from any
45   *     source or altered source distribution.
46   *
47   *  The copyright holders and contributing author(s) specifically
48   *  permit, without fee, and encourage the use of this source code
49   *  as a component for supporting the Hypertext Markup Language in
50   *  commercial products. If you use this source code in a product,
51   *  acknowledgment is not required but would be appreciated.
52   *
53   */
54  package org.w3c.tidy;
55  
56  import java.io.StringWriter;
57  
58  import junit.framework.TestCase;
59  
60  import org.apache.commons.logging.Log;
61  import org.apache.commons.logging.LogFactory;
62  
63  
64  /**
65   * @author Fabrizio Giustina
66   * @version $Revision: 807 $ ($Author: fgiust $)
67   */
68  public class ConfigurationTest extends TestCase
69  {
70  
71      /**
72       * logger.
73       */
74      private static Log log = LogFactory.getLog(ConfigurationTest.class);
75  
76      /**
77       * Test for -help-config.
78       * @throws Exception any exception thrown during test
79       */
80      public void testPrintConfig() throws Exception
81      {
82          Tidy tidy = new Tidy();
83          Configuration configuration = tidy.getConfiguration();
84          StringWriter writer = new StringWriter();
85          configuration.printConfigOptions(writer, false);
86          String result = writer.toString();
87          // just test that no exception occurred and that something was printed
88          assertTrue(result.length() > 200);
89          log.debug(result);
90      }
91  
92      /**
93       * Test for -show-config.
94       * @throws Exception any exception thrown during test
95       */
96      public void testPrintActualConfig() throws Exception
97      {
98          Tidy tidy = new Tidy();
99          tidy.getConfiguration().tt.defineTag(Dict.TAGTYPE_INLINE, "something");
100         tidy.getConfiguration().tt.defineTag(Dict.TAGTYPE_INLINE, "second");
101         Configuration configuration = tidy.getConfiguration();
102         StringWriter writer = new StringWriter();
103         configuration.printConfigOptions(writer, true);
104         String result = writer.toString();
105         // just test that no exception occurred and that something was printed
106         assertTrue(result.length() > 200);
107         log.debug(result);
108     }
109 
110     /**
111      * Test for configuration getters and setters.
112      * @throws Exception any exception thrown during test
113      */
114     public void testGetSet() throws Exception
115     {
116         Tidy tidy = new Tidy();
117 
118         tidy.setAltText("alt");
119         assertEquals("alt", tidy.getAltText());
120 
121         tidy.setAsciiChars(false);
122         assertEquals(false, tidy.getAsciiChars());
123 
124         tidy.setBreakBeforeBR(true);
125         assertEquals(true, tidy.getBreakBeforeBR());
126 
127         tidy.setBurstSlides(true);
128         assertEquals(true, tidy.getBurstSlides());
129 
130         tidy.setDropEmptyParas(false);
131         assertEquals(false, tidy.getDropEmptyParas());
132 
133         tidy.setDropFontTags(true);
134         assertEquals(true, tidy.getDropFontTags());
135 
136         tidy.setDropProprietaryAttributes(true);
137         assertEquals(true, tidy.getDropProprietaryAttributes());
138 
139         tidy.setEmacs(true);
140         assertEquals(true, tidy.getEmacs());
141 
142         tidy.setEncloseBlockText(true);
143         assertEquals(true, tidy.getEncloseBlockText());
144 
145         tidy.setEncloseText(true);
146         assertEquals(true, tidy.getEncloseText());
147 
148         tidy.setEscapeCdata(true);
149         assertEquals(true, tidy.getEscapeCdata());
150 
151         tidy.setFixBackslash(true);
152         assertEquals(true, tidy.getFixBackslash());
153 
154         tidy.setFixComments(true);
155         assertEquals(true, tidy.getFixComments());
156 
157         tidy.setFixUri(true);
158         assertEquals(true, tidy.getFixUri());
159 
160         tidy.setForceOutput(true);
161         assertEquals(true, tidy.getForceOutput());
162 
163         tidy.setHideComments(true);
164         assertEquals(true, tidy.getHideComments());
165 
166         tidy.setHideEndTags(true);
167         assertEquals(true, tidy.getHideEndTags());
168 
169         tidy.setIndentAttributes(true);
170         assertEquals(true, tidy.getIndentAttributes());
171 
172         tidy.setIndentCdata(true);
173         assertEquals(true, tidy.getIndentCdata());
174 
175         tidy.setIndentContent(true);
176         assertEquals(true, tidy.getIndentContent());
177 
178         tidy.setJoinClasses(true);
179         assertEquals(true, tidy.getJoinClasses());
180 
181         tidy.setJoinStyles(true);
182         assertEquals(true, tidy.getJoinStyles());
183 
184         tidy.setKeepFileTimes(true);
185         assertEquals(true, tidy.getKeepFileTimes());
186 
187         tidy.setLiteralAttribs(true);
188         assertEquals(true, tidy.getLiteralAttribs());
189 
190         tidy.setLogicalEmphasis(true);
191         assertEquals(true, tidy.getLogicalEmphasis());
192 
193         tidy.setLowerLiterals(true);
194         assertEquals(true, tidy.getLowerLiterals());
195 
196         tidy.setMakeBare(true);
197         assertEquals(true, tidy.getMakeBare());
198 
199         tidy.setMakeClean(true);
200         assertEquals(true, tidy.getMakeClean());
201 
202         tidy.setNumEntities(true);
203         assertEquals(true, tidy.getNumEntities());
204 
205         tidy.setOnlyErrors(true);
206         assertEquals(true, tidy.getOnlyErrors());
207 
208         tidy.setPrintBodyOnly(true);
209         assertEquals(true, tidy.getPrintBodyOnly());
210 
211         tidy.setQuiet(true);
212         assertEquals(true, tidy.getQuiet());
213 
214         tidy.setQuoteAmpersand(true);
215         assertEquals(true, tidy.getQuoteAmpersand());
216 
217         tidy.setQuoteMarks(true);
218         assertEquals(true, tidy.getQuoteMarks());
219 
220         tidy.setQuoteNbsp(true);
221         assertEquals(true, tidy.getQuoteNbsp());
222 
223         tidy.setRawOut(true);
224         assertEquals(true, tidy.getRawOut());
225 
226         tidy.setReplaceColor(true);
227         assertEquals(true, tidy.getReplaceColor());
228 
229         tidy.setShowWarnings(true);
230         assertEquals(true, tidy.getShowWarnings());
231 
232         tidy.setSmartIndent(true);
233         assertEquals(true, tidy.getSmartIndent());
234 
235         tidy.setTidyMark(true);
236         assertEquals(true, tidy.getTidyMark());
237 
238         tidy.setTrimEmptyElements(true);
239         assertEquals(true, tidy.getTrimEmptyElements());
240 
241         tidy.setUpperCaseAttrs(true);
242         assertEquals(true, tidy.getUpperCaseAttrs());
243 
244         tidy.setUpperCaseTags(true);
245         assertEquals(true, tidy.getUpperCaseTags());
246 
247         tidy.setWord2000(true);
248         assertEquals(true, tidy.getWord2000());
249 
250         tidy.setWrapAsp(true);
251         assertEquals(true, tidy.getWrapAsp());
252 
253         tidy.setWrapAttVals(true);
254         assertEquals(true, tidy.getWrapAttVals());
255 
256         tidy.setWrapJste(true);
257         assertEquals(true, tidy.getWrapJste());
258 
259         tidy.setWrapPhp(true);
260         assertEquals(true, tidy.getWrapPhp());
261 
262         tidy.setWrapScriptlets(true);
263         assertEquals(true, tidy.getWrapScriptlets());
264 
265         tidy.setWrapSection(true);
266         assertEquals(true, tidy.getWrapSection());
267 
268         tidy.setWraplen(5);
269         assertEquals(5, tidy.getWraplen());
270 
271         tidy.setWriteback(true);
272         assertEquals(true, tidy.getWriteback());
273 
274         tidy.setXHTML(true);
275         assertEquals(true, tidy.getXHTML());
276 
277         tidy.setXmlOut(true);
278         assertEquals(true, tidy.getXmlOut());
279 
280         tidy.setXmlPi(true);
281         assertEquals(true, tidy.getXmlPi());
282 
283         tidy.setXmlPIs(true);
284         assertEquals(true, tidy.getXmlPIs());
285 
286         tidy.setXmlSpace(true);
287         assertEquals(true, tidy.getXmlSpace());
288 
289         tidy.setXmlTags(true);
290         assertEquals(true, tidy.getXmlTags());
291 
292         tidy.setTabsize(5);
293         assertEquals(5, tidy.getTabsize());
294 
295         tidy.setOutputEncoding("UTF8");
296         assertEquals("UTF8", tidy.getOutputEncoding());
297 
298         tidy.setInputEncoding("UTF8");
299         assertEquals("UTF8", tidy.getInputEncoding());
300 
301         tidy.setRepeatedAttributes(Configuration.KEEP_FIRST);
302         assertEquals(Configuration.KEEP_FIRST, tidy.getRepeatedAttributes());
303 
304         tidy.setShowErrors(10);
305         assertEquals(10, tidy.getShowErrors());
306 
307         tidy.setDocType("strict");
308         assertEquals("strict", tidy.getDocType());
309 
310         tidy.setErrfile("errfile");
311         assertEquals("errfile", tidy.getErrfile());
312 
313         tidy.setSpaces(5);
314         assertEquals(5, tidy.getSpaces());
315 
316         tidy.setInputStreamName("inputname");
317         assertEquals("inputname", tidy.getInputStreamName());
318 
319     }
320 }