KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > awt > HtmlRendererTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.awt;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.image.BufferedImage JavaDoc;
26 import junit.framework.TestCase;
27
28 /**
29  *
30  * @author mkleint
31  */

32 public class HtmlRendererTest extends TestCase {
33
34     private Graphics JavaDoc graphic;
35     public HtmlRendererTest(String JavaDoc testName) {
36         super(testName);
37     }
38
39     protected void setUp() throws Exception JavaDoc {
40         BufferedImage JavaDoc waitingForPaintDummyImage = new BufferedImage JavaDoc(1, 1, BufferedImage.TYPE_INT_RGB);
41         graphic = waitingForPaintDummyImage.getGraphics();
42         
43     }
44     
45     /**
46      * Test of renderHTML method, of class org.openide.awt.HtmlRenderer.
47      */

48     public void testRenderHTML() throws Exception JavaDoc {
49         doTestRender("<html>text</html>");
50         doTestRender("<html>text</html");
51         doTestRender("<html>text</h");
52         doTestRender("<html>text</");
53         doTestRender("<html>text<");
54         doTestRender("<html>text");
55         doTestRender("<html>text</html<html/>");
56         doTestRender("<html>text</h</html>");
57         doTestRender("<html>text</</html>");
58         doTestRender("<html>text<</html>");
59         doTestRender("<html>text<</html>&");
60         doTestRender55310();
61     }
62     
63     private void doTestRender(String JavaDoc text) {
64         try {
65             HtmlRenderer.renderHTML(text, graphic, 0, 0, 1000, 1000,
66                     Font.getFont("Dialog"), Color.RED, HtmlRenderer.STYLE_TRUNCATE, true);
67         } catch (IllegalArgumentException JavaDoc arg) {
68             // argument exception is ok..
69
if (arg.getMessage().startsWith("HTML rendering failed on string")) {
70                 System.err.println("throwing illegal argument for " + text);
71             } else {
72                 throw arg;
73             }
74         }
75     }
76     
77     /**
78      * Test issue #55310: AIOOBE from HtmlRenderer.
79      *
80      * @see http://www.netbeans.org/issues/show_bug.cgi?id=55310
81      */

82     private void doTestRender55310() {
83         doTestRender("<html><b>a </b></html> ");
84     }
85 }
86
Popular Tags