KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > text > syntax > ColoringTest


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 package org.netbeans.modules.xml.text.syntax;
20
21 import org.openide.execution.NbfsURLConnection;
22 import org.openide.loaders.DataFolder;
23 import org.netbeans.tax.*;
24 import org.netbeans.modules.xml.core.DTDDataObject;
25 import org.openide.cookies.SaveCookie;
26 import org.openide.cookies.EditorCookie;
27
28 import org.netbeans.modules.xml.core.XMLDataObject;
29 import org.openide.nodes.CookieSet;
30 import javax.swing.text.Document JavaDoc;
31 import org.netbeans.modules.editor.NbEditorDocument;
32 import org.netbeans.editor.SyntaxSupport;
33 import org.netbeans.modules.xml.text.syntax.XMLSyntaxSupport;
34 import org.netbeans.editor.TokenID;
35 import org.netbeans.editor.BaseDocument;
36 import org.netbeans.editor.ext.ExtSyntaxSupport;
37 import org.netbeans.editor.TokenItem;
38 import org.netbeans.tests.xml.XTest;
39 import org.openide.loaders.DataObject;
40
41 /**
42  * <P>
43  * <P>
44  * <FONT COLOR="#CC3333" FACE="Courier New, Monospaced" SIZE="+1">
45  * <B>
46  * <BR> XML Module API Test: CreateSimpleXML
47  * </B>
48  * </FONT>
49  * <BR><BR><B>What it tests:</B><BR>
50  *
51  * This test creates simple XML document with DTD and writes it into output.
52  *
53  * <BR><BR><B>How it works:</B><BR>
54  *
55  * 1) create empty XML document from template<BR>
56  * 2) create new Document Type and add it into document<BR>
57  * 3) append XML elements<BR>
58  * 4) write the document into output<BR>
59  *
60  * <BR><BR><B>Settings:</B><BR>
61  * none<BR>
62  *
63  * <BR><BR><B>Output (Golden file):</B><BR>
64  * XML document with DTD.<BR>
65  *
66  * <BR><B>To Do:</B><BR>
67  * none<BR>
68  *
69  * <P>Created on December 20, 2000, 12:33 PM
70  * <P>
71  */

72 public class ColoringTest extends XTest {
73     private static String JavaDoc XML_TEMPLATE = "XML/XMLwithDTD.xml";
74     private static String JavaDoc DOCUMENT_NAME = "Books";
75     private static String JavaDoc DTD_SYS_ID = "simple.dtd";
76     private static String JavaDoc INTERNAL_DTD = "internalDTD.dtd";
77     private static int TREE_LEVELS = 3;
78     
79     /** Creates new CoreSettingsTest */
80     public ColoringTest(String JavaDoc testName) {
81         super(testName);
82     }
83     
84     // TESTS ///////////////////////////////////////////////////////////////////
85

86     public void testXMLColoring() throws Exception JavaDoc {
87         dumpTokens("XMLColoring", "xml");
88     }
89     
90     public void testDTDColoring() throws Exception JavaDoc {
91         dumpTokens("DTDColoring", "dtd");
92     }
93     
94     public void testCSSColoring() throws Exception JavaDoc {
95         dumpTokens("CSSColoring", "css");
96     }
97     
98     // LIBS ////////////////////////////////////////////////////////////////////
99

100     public void dumpTokens(String JavaDoc fileName, String JavaDoc ext) throws Exception JavaDoc {
101         String JavaDoc pkgName = getClass().getPackage().getName();
102         DataObject obj = TestUtil.THIS.findDataObject(pkgName + ".data", fileName, ext);
103         EditorCookie ed = (EditorCookie) obj.getCookie(EditorCookie.class);
104         BaseDocument doc = (BaseDocument) ed.openDocument();
105         ExtSyntaxSupport ess = (ExtSyntaxSupport) doc.getSyntaxSupport();
106         TokenItem token = ess.getTokenChain(0, doc.getLength());
107         
108         while (token != null) {
109             TokenID tokenID = token.getTokenID();
110             ref(tokenID.getName()+ ": " + token.getImage());
111             token = token.getNext();
112         }
113         compareReferenceFiles();
114     }
115     
116     // MAIN ////////////////////////////////////////////////////////////////////
117

118     /**
119      * Performs this testsuite.
120      * @param args the command line arguments
121      */

122     public static void main(String JavaDoc args[]) {
123         junit.textui.TestRunner.run(ColoringTest.class);
124     }
125 }
126
Popular Tags