KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tax > FactoryTest


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.tax;
20
21 import java.util.Arrays JavaDoc;
22 import java.util.List JavaDoc;
23 import junit.textui.TestRunner;
24 import org.netbeans.tax.TreeElementDecl.ContentType;
25 import org.netbeans.tax.decl.*;
26
27 /**
28  *
29  * @author ms113234
30  */

31 public class FactoryTest extends AbstractFactoryTest {
32
33     /** Creates new CoreSettingsTest */
34     public FactoryTest(String JavaDoc testName) {
35         super(testName);
36     }
37
38     //==========================
39
// = = = T E S T S = = =
40
//==========================
41

42     public void testAttlistDecl() throws Exception JavaDoc {
43         createAttlistDecl("elementName", "<!ATTLIST elementName>");
44         
45         createAttlistDeclInvalid(null);
46     }
47     
48     public void testAttribute() throws Exception JavaDoc {
49         createAttribute("name", "value", "name=\"value\"");
50         //createAttribute("name", "C&lt;K", "name=\"C&lt;K\""); // issue #15785
51

52         createAttributeInvalid(null, null);
53         createAttributeInvalid("name", null);
54         createAttributeInvalid(null, "value");
55         createAttributeInvalid("na me", "value");
56         createAttributeInvalid("na;me", "value");
57         createAttributeInvalid("1name", "value");
58     }
59     
60     public void testCDATASection() throws Exception JavaDoc {
61         createCDATASection("<cdata ]] > &lt; &#x0; data>", "<![CDATA[<cdata ]] > &lt; &#x0; data>]]>");
62         
63         createCDATASectionInvalid(null);
64         createCDATASectionInvalid("aa ]]> bbb");
65     }
66     
67     public void testCharacterReference() throws Exception JavaDoc {
68         createCharacterReference("#35", "&#35;");
69         createCharacterReference("#x35", "&#x35;");
70         
71         createCharacterReferenceInvalid(null);
72         createCharacterReferenceInvalid("");
73         createCharacterReferenceInvalid("#");
74         createCharacterReferenceInvalid("#x");
75         createCharacterReferenceInvalid("#xg");
76         createCharacterReferenceInvalid("#;");
77         createCharacterReferenceInvalid("# ");
78     }
79     
80     public void testComment() throws Exception JavaDoc {
81         createComment("comment - comment", "<!--comment - comment-->");
82         createComment("", "<!---->");
83         
84         createCommentInvalid(null);
85         createCommentInvalid("bad--bad");
86     }
87     
88     public void testConditionalSection() throws Exception JavaDoc {
89         createConditionalSection(true, "<![ INCLUDE []]>");
90         createConditionalSection(false, "<![ IGNORE []]>");
91     }
92     
93     public void testDTD() throws Exception JavaDoc {
94         createDTD("1.0", "UTF-16", "<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
95         createDTD(null, "UTF-8", "<?xml encoding=\"UTF-8\"?>");
96         createDTD(null, null, "");
97         
98         createDTDInvalid(null, "encodig");
99         createDTDInvalid("version", null);
100         createDTDInvalid("1.0", "encodig");
101         createDTDInvalid("version", "UTF-16");
102     }
103     
104     public void testDocument() throws Exception JavaDoc {
105         createDocument(null, null, null, "");
106         createDocument("1.0", "ISO-8859-2", "no", "<?xml version=\"1.0\" encoding=\"ISO-8859-2\" standalone=\"no\"?>");
107         createDocument("1.0", null, "yes", "<?xml version=\"1.0\" standalone=\"yes\"?>");
108         createDocument("1.0", "ASCII", null, "<?xml version=\"1.0\" encoding=\"ASCII\"?>");
109         createDocument("1.0", null, null, "<?xml version=\"1.0\"?>");
110         
111         createDocumentInvalid("2.0", "ISO-8859-2", "no");
112         createDocumentInvalid("10", "ISO-8859-2", "no");
113         createDocumentInvalid("", "ISO-8859-2", "no");
114         createDocumentInvalid("2.0", null, "no");
115         createDocumentInvalid(".0", "ISO-8859-2", null);
116         createDocumentInvalid(null, "ISO-8859-2", "no");
117         createDocumentInvalid(null, null, "no");
118         createDocumentInvalid(null, "ISO-8859-2", null);
119     }
120     
121     public void testDocumentFragment() throws Exception JavaDoc {
122         createDocumentFragment(null, null, "");
123         createDocumentFragment("1.0", "ISO-8859-2", "<?xml version=\"1.0\" encoding=\"ISO-8859-2\"?>");
124         createDocumentFragment(null, "ISO-8859-2", "<?xml encoding=\"ISO-8859-2\"?>");
125         
126         createDocumentFragmentInvalid("1.0", null);
127         createDocumentFragmentInvalid("3.0", "UTF-8");
128         createDocumentFragmentInvalid("1.0", "UTF-80");
129     }
130     
131     public void testDocumentType() throws Exception JavaDoc {
132         createDocumentType("elementName", "<!DOCTYPE elementName>");
133         
134         createDocumentType("element", "pub_id", "sys_id", "<!DOCTYPE element PUBLIC \"pub_id\" \"sys_id\">");
135         createDocumentType("element", "pub_id", "", "<!DOCTYPE element PUBLIC \"pub_id\" \"\">");
136         createDocumentType("element", "pub_id", null, "<!DOCTYPE element PUBLIC \"pub_id\" \"\">");
137         createDocumentType("element", "", "sys_id", "<!DOCTYPE element PUBLIC \"\" \"sys_id\">");
138         createDocumentType("element", null, "sys_id", "<!DOCTYPE element SYSTEM \"sys_id\">");
139         
140         createDocumentTypeInvalid(null);
141         createDocumentTypeInvalid("");
142         createDocumentTypeInvalid("a c");
143         createDocumentTypeInvalid("a&gt;c");
144         createDocumentTypeInvalid("a&#37;c");
145         createDocumentTypeInvalid("a%ref;c");
146         
147         createDocumentTypeInvalid("", "pub_id", "sys_id");
148         createDocumentTypeInvalid(null, "pub_id", "sys_id");
149         createDocumentTypeInvalid("1element", "pub_id", "sys_id");
150         createDocumentTypeInvalid("ele ment", "pub_id", "sys_id");
151         createDocumentTypeInvalid("element", "pub_id", "\'\"");
152         //createDocumentTypeInvalid("element", "pub_id&", "sys_id"); // issue #18112
153

154         
155     }
156     
157     public void testElement() throws Exception JavaDoc {
158         createElement("element", "<element></element>");
159         createElement("ns:element", "<ns:element></ns:element>");
160         
161         createElementInvalid(null);
162         createElementInvalid("");
163         createElementInvalid("1a");
164         createElementInvalid("a b");
165         createElementInvalid("a&b");
166         createElementInvalid("a%b");
167     }
168     
169     public void testElementDecl() throws Exception JavaDoc {
170         List JavaDoc content;
171         ContentType type;
172         
173         createElementDecl("element", new ANYType(), "<!ELEMENT element ANY>");
174         createElementDecl("element", new EMPTYType(), "<!ELEMENT element EMPTY>");
175         
176         content = Arrays.asList(new Object JavaDoc[] {new NameType("ele1"), new NameType("ele2","")});
177         type = new SequenceType(content);
178         type.setMultiplicity("+");
179         createElementDecl("element", type, "<!ELEMENT element ( ele1, ele2 )+>");
180         
181         type = new ChoiceType(content);
182         type.setMultiplicity("*");
183         createElementDecl("element", type, "<!ELEMENT element ( ele1 | ele2 )*>");
184         
185         type = new MixedType(content);
186         type.setMultiplicity("+");
187         createElementDecl("element", type, "<!ELEMENT element ( #PCDATA | ele1 | ele2 )+>");
188         
189         //createElementDecl("books", "(product+, price?, image,custom? )+", "<!ELEMENT books ( product+, price?, image, custom? )+>");
190
//createElementDecl("dictionary-body", "(%div.mix;, %dict.mix;)*", "<!ELEMENT dictionary-body ( %div.mix;, %dict.mix; )*>");
191
//createElementDecl("%name.para;", "%content.para;", "<!ELEMENT %name.para; %content.para; >");
192
//createElementDecl("div", "( head, (p | list | note )*, div2* )", "<!ELEMENT div ( head, (p | list | note )*, div2* )>"); // issue #
193
//createElementDecl("div", "(p | list | note )*", "<!ELEMENT div ( p | list | note )*>"); // issue #
194
//createElementDecl("product", "(#PCDATA |descript)*", "<!ELEMENT product ( #PCDATA | descript )*>"); // issue #
195
//createElementDecl("descript", "(#PCDATA)", "<!ELEMENT descript ( #PCDATA )>"); // issue #
196

197         createElementDeclInvalid(null, (ContentType) null);
198     }
199     
200     public void testEntityDecl() throws Exception JavaDoc {
201         boolean parameter;
202         String JavaDoc name, text;
203         String JavaDoc publicId, systemId;
204         String JavaDoc notationName;
205         
206         // General Entity Decl
207
createEntityDecl("name", "text", "<!ENTITY name \"text\">");
208         createEntityDeclInvalid(null, null);
209         createEntityDeclInvalid("name", null);
210         createEntityDeclInvalid(null, "text");
211         
212         // Parametr Entity Decl
213
createEntityDecl(true, "name", "text", "<!ENTITY % name \"text\">");
214         
215         for (int i = 0; i < 8; i++) {
216             parameter = ((i & 1) == 0) ? false : true;
217             name = ((i & 2) == 0) ? null : "name";
218             text = ((i & 4) == 0) ? null : "text";
219             if (name == null || text == null) {
220                 createEntityDeclInvalid(parameter, name, text);
221             }
222         }
223         
224         // External Entity Decl
225
createEntityDecl("name", "publicId", "systemId", "<!ENTITY name PUBLIC \"publicId\" \"systemId\">");
226         createEntityDecl("name", null, "systemId", "<!ENTITY name SYSTEM \"systemId\">");
227         createEntityDecl(false, "name", "publicId", "systemId", "<!ENTITY name PUBLIC \"publicId\" \"systemId\">");
228         createEntityDecl(false, "name", null, "systemId", "<!ENTITY name SYSTEM \"systemId\">");
229         
230         for (int i = 0; i < 8; i++) {
231             name = ((i & 1) == 0) ? null : "name";
232             publicId = ((i & 2) == 0) ? null : "publicId";
233             systemId = ((i & 4) == 0) ? null : "systemId";
234             
235             if (name == null || systemId == null) {
236                 createEntityDeclInvalid(name, publicId, systemId);
237             }
238         }
239         
240         // Parametr External Entity Decl
241
createEntityDecl(true, "name", "publicId", "systemId", "<!ENTITY % name PUBLIC \"publicId\" \"systemId\">");
242         createEntityDecl(true, "name", null, "systemId", "<!ENTITY % name SYSTEM \"systemId\">");
243         
244         for (int i = 0; i < 16; i++) {
245             name = ((i & 1) == 0) ? null : "name";
246             publicId = ((i & 2) == 0) ? null : "publicId";
247             systemId = ((i & 4) == 0) ? null : "systemId";
248             parameter = ((i & 8) == 0) ? true : false;
249             
250             if (name == null || systemId == null) {
251                 createEntityDeclInvalid(parameter, name, publicId, systemId);
252             }
253         }
254         
255         // Unparsed Entity Decl
256
createEntityDecl("name", "publicId", "systemId", "notationName", "<!ENTITY name PUBLIC \"publicId\" \"systemId\" NDATA notationName>");
257         createEntityDecl("name", null, "systemId", "notationName", "<!ENTITY name SYSTEM \"systemId\" NDATA notationName>");
258         
259         for (int i = 0; i < 16; i++) {
260             name = ((i & 1) == 0) ? null : "name";
261             publicId = ((i & 2) == 0) ? null : "publicId";
262             systemId = ((i & 4) == 0) ? null : "systemId";
263             notationName = ((i & 8) == 0) ? null : "notationName";
264             
265             if (name == null || systemId == null || notationName == null) {
266                 createEntityDeclInvalid(name, publicId, systemId, notationName);
267             }
268         }
269     }
270     
271     public void testGeneralEntityReference() throws Exception JavaDoc {
272         createGeneralEntityReference(":g1e_r-e.f", "&:g1e_r-e.f;");
273         
274         createGeneralEntityReferenceInvalid(null);
275         createGeneralEntityReferenceInvalid("&");
276         createGeneralEntityReferenceInvalid(";");
277         createGeneralEntityReferenceInvalid("%");
278     }
279     
280     public void testNotationDecl() throws Exception JavaDoc {
281         String JavaDoc name;
282         String JavaDoc publicId;
283         String JavaDoc systemId;
284         TreeNotationDecl node;
285         
286         createNotationDecl("name", "publicId", "systemId", "<!NOTATION name PUBLIC \"publicId\" \"systemId\">");
287         createNotationDecl("name", null, "systemId", "<!NOTATION name SYSTEM \"systemId\">");
288         createNotationDecl("name", "publicId", null, "<!NOTATION name PUBLIC \"publicId\">");
289         
290         for (int i = 0; i < 8; i++) {
291             name = ((i & 1) == 0) ? null : "name";
292             publicId = ((i & 2) == 0) ? null : "publicId";
293             systemId = ((i & 4) == 0) ? null : "systemId";
294             
295             if (name == null || (systemId == null && publicId == null)) {
296                 createNotationDeclInvalid(name, publicId, systemId);
297             }
298         }
299     }
300     
301     public void testParameterEntityReference() throws Exception JavaDoc {
302         createParameterEntityReference(":p1e_r-e.f", "%:p1e_r-e.f;");
303         
304         createParameterEntityReferenceInvalid(null);
305         createParameterEntityReferenceInvalid("&");
306         createParameterEntityReferenceInvalid(";");
307         createParameterEntityReferenceInvalid("%");
308     }
309     
310     public void testProcessingInstruction() throws Exception JavaDoc {
311         createProcessingInstruction("target", "pi-data", "<?target pi-data?>");
312         createProcessingInstruction("target", "&%4;?<<>>]]>--> <!--", "<?target &%4;?<<>>]]>--> <!--?>");
313         
314         createProcessingInstructionInvalid(null, null);
315         createProcessingInstructionInvalid("target", null);
316         createProcessingInstructionInvalid("xml", "pi-data");
317         createProcessingInstructionInvalid("XmL", "pi-data");
318         createProcessingInstructionInvalid("&", "pi-data");
319     }
320     
321     public void testText() throws Exception JavaDoc {
322         createText(" text >--> % @ # $ ", " text >--> % @ # $ ");
323         createTextInvalid("<");
324         createTextInvalid("&");
325         //createTextInvalid("]]>"); // ISSUE #18445
326
}
327     
328     /**
329      * Performs this testsuite.
330      * @param args the command line arguments
331      */

332     public static void main(String JavaDoc args[]) {
333         TestRunner.run(FactoryTest.class);
334     }
335 }
336
Popular Tags