001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.tax;
042:
043: import java.util.Arrays;
044: import java.util.List;
045: import junit.textui.TestRunner;
046: import org.netbeans.tax.TreeElementDecl.ContentType;
047: import org.netbeans.tax.decl.*;
048:
049: /**
050: *
051: * @author ms113234
052: */
053: public class FactoryTest extends AbstractFactoryTest {
054:
055: /** Creates new CoreSettingsTest */
056: public FactoryTest(String testName) {
057: super (testName);
058: }
059:
060: //==========================
061: // = = = T E S T S = = =
062: //==========================
063:
064: public void testAttlistDecl() throws Exception {
065: createAttlistDecl("elementName", "<!ATTLIST elementName>");
066:
067: createAttlistDeclInvalid(null);
068: }
069:
070: public void testAttribute() throws Exception {
071: createAttribute("name", "value", "name=\"value\"");
072: //createAttribute("name", "C<K", "name=\"C<K\""); // issue #15785
073:
074: createAttributeInvalid(null, null);
075: createAttributeInvalid("name", null);
076: createAttributeInvalid(null, "value");
077: createAttributeInvalid("na me", "value");
078: createAttributeInvalid("na;me", "value");
079: createAttributeInvalid("1name", "value");
080: }
081:
082: public void testCDATASection() throws Exception {
083: createCDATASection("<cdata ]] > < � data>",
084: "<![CDATA[<cdata ]] > < � data>]]>");
085:
086: createCDATASectionInvalid(null);
087: createCDATASectionInvalid("aa ]]> bbb");
088: }
089:
090: public void testCharacterReference() throws Exception {
091: createCharacterReference("#35", "#");
092: createCharacterReference("#x35", "5");
093:
094: createCharacterReferenceInvalid(null);
095: createCharacterReferenceInvalid("");
096: createCharacterReferenceInvalid("#");
097: createCharacterReferenceInvalid("#x");
098: createCharacterReferenceInvalid("#xg");
099: createCharacterReferenceInvalid("#;");
100: createCharacterReferenceInvalid("# ");
101: }
102:
103: public void testComment() throws Exception {
104: createComment("comment - comment", "<!--comment - comment-->");
105: createComment("", "<!---->");
106:
107: createCommentInvalid(null);
108: createCommentInvalid("bad--bad");
109: }
110:
111: public void testConditionalSection() throws Exception {
112: createConditionalSection(true, "<![ INCLUDE []]>");
113: createConditionalSection(false, "<![ IGNORE []]>");
114: }
115:
116: public void testDTD() throws Exception {
117: createDTD("1.0", "UTF-16",
118: "<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
119: createDTD(null, "UTF-8", "<?xml encoding=\"UTF-8\"?>");
120: createDTD(null, null, "");
121:
122: createDTDInvalid(null, "encodig");
123: createDTDInvalid("version", null);
124: createDTDInvalid("1.0", "encodig");
125: createDTDInvalid("version", "UTF-16");
126: }
127:
128: public void testDocument() throws Exception {
129: createDocument(null, null, null, "");
130: createDocument("1.0", "ISO-8859-2", "no",
131: "<?xml version=\"1.0\" encoding=\"ISO-8859-2\" standalone=\"no\"?>");
132: createDocument("1.0", null, "yes",
133: "<?xml version=\"1.0\" standalone=\"yes\"?>");
134: createDocument("1.0", "ASCII", null,
135: "<?xml version=\"1.0\" encoding=\"ASCII\"?>");
136: createDocument("1.0", null, null, "<?xml version=\"1.0\"?>");
137:
138: createDocumentInvalid("2.0", "ISO-8859-2", "no");
139: createDocumentInvalid("10", "ISO-8859-2", "no");
140: createDocumentInvalid("", "ISO-8859-2", "no");
141: createDocumentInvalid("2.0", null, "no");
142: createDocumentInvalid(".0", "ISO-8859-2", null);
143: createDocumentInvalid(null, "ISO-8859-2", "no");
144: createDocumentInvalid(null, null, "no");
145: createDocumentInvalid(null, "ISO-8859-2", null);
146: }
147:
148: public void testDocumentFragment() throws Exception {
149: createDocumentFragment(null, null, "");
150: createDocumentFragment("1.0", "ISO-8859-2",
151: "<?xml version=\"1.0\" encoding=\"ISO-8859-2\"?>");
152: createDocumentFragment(null, "ISO-8859-2",
153: "<?xml encoding=\"ISO-8859-2\"?>");
154:
155: createDocumentFragmentInvalid("1.0", null);
156: createDocumentFragmentInvalid("3.0", "UTF-8");
157: createDocumentFragmentInvalid("1.0", "UTF-80");
158: }
159:
160: public void testDocumentType() throws Exception {
161: createDocumentType("elementName", "<!DOCTYPE elementName>");
162:
163: createDocumentType("element", "pub_id", "sys_id",
164: "<!DOCTYPE element PUBLIC \"pub_id\" \"sys_id\">");
165: createDocumentType("element", "pub_id", "",
166: "<!DOCTYPE element PUBLIC \"pub_id\" \"\">");
167: createDocumentType("element", "pub_id", null,
168: "<!DOCTYPE element PUBLIC \"pub_id\" \"\">");
169: createDocumentType("element", "", "sys_id",
170: "<!DOCTYPE element PUBLIC \"\" \"sys_id\">");
171: createDocumentType("element", null, "sys_id",
172: "<!DOCTYPE element SYSTEM \"sys_id\">");
173:
174: createDocumentTypeInvalid(null);
175: createDocumentTypeInvalid("");
176: createDocumentTypeInvalid("a c");
177: createDocumentTypeInvalid("a>c");
178: createDocumentTypeInvalid("a%c");
179: createDocumentTypeInvalid("a%ref;c");
180:
181: createDocumentTypeInvalid("", "pub_id", "sys_id");
182: createDocumentTypeInvalid(null, "pub_id", "sys_id");
183: createDocumentTypeInvalid("1element", "pub_id", "sys_id");
184: createDocumentTypeInvalid("ele ment", "pub_id", "sys_id");
185: createDocumentTypeInvalid("element", "pub_id", "\'\"");
186: //createDocumentTypeInvalid("element", "pub_id&", "sys_id"); // issue #18112
187:
188: }
189:
190: public void testElement() throws Exception {
191: createElement("element", "<element></element>");
192: createElement("ns:element", "<ns:element></ns:element>");
193:
194: createElementInvalid(null);
195: createElementInvalid("");
196: createElementInvalid("1a");
197: createElementInvalid("a b");
198: createElementInvalid("a&b");
199: createElementInvalid("a%b");
200: }
201:
202: public void testElementDecl() throws Exception {
203: List content;
204: ContentType type;
205:
206: createElementDecl("element", new ANYType(),
207: "<!ELEMENT element ANY>");
208: createElementDecl("element", new EMPTYType(),
209: "<!ELEMENT element EMPTY>");
210:
211: content = Arrays.asList(new Object[] { new NameType("ele1"),
212: new NameType("ele2", "") });
213: type = new SequenceType(content);
214: type.setMultiplicity("+");
215: createElementDecl("element", type,
216: "<!ELEMENT element ( ele1, ele2 )+>");
217:
218: type = new ChoiceType(content);
219: type.setMultiplicity("*");
220: createElementDecl("element", type,
221: "<!ELEMENT element ( ele1 | ele2 )*>");
222:
223: type = new MixedType(content);
224: type.setMultiplicity("+");
225: createElementDecl("element", type,
226: "<!ELEMENT element ( #PCDATA | ele1 | ele2 )+>");
227:
228: //createElementDecl("books", "(product+, price?, image,custom? )+", "<!ELEMENT books ( product+, price?, image, custom? )+>");
229: //createElementDecl("dictionary-body", "(%div.mix;, %dict.mix;)*", "<!ELEMENT dictionary-body ( %div.mix;, %dict.mix; )*>");
230: //createElementDecl("%name.para;", "%content.para;", "<!ELEMENT %name.para; %content.para; >");
231: //createElementDecl("div", "( head, (p | list | note )*, div2* )", "<!ELEMENT div ( head, (p | list | note )*, div2* )>"); // issue #
232: //createElementDecl("div", "(p | list | note )*", "<!ELEMENT div ( p | list | note )*>"); // issue #
233: //createElementDecl("product", "(#PCDATA |descript)*", "<!ELEMENT product ( #PCDATA | descript )*>"); // issue #
234: //createElementDecl("descript", "(#PCDATA)", "<!ELEMENT descript ( #PCDATA )>"); // issue #
235:
236: createElementDeclInvalid(null, (ContentType) null);
237: }
238:
239: public void testEntityDecl() throws Exception {
240: boolean parameter;
241: String name, text;
242: String publicId, systemId;
243: String notationName;
244:
245: // General Entity Decl
246: createEntityDecl("name", "text", "<!ENTITY name \"text\">");
247: createEntityDeclInvalid(null, null);
248: createEntityDeclInvalid("name", null);
249: createEntityDeclInvalid(null, "text");
250:
251: // Parametr Entity Decl
252: createEntityDecl(true, "name", "text",
253: "<!ENTITY % name \"text\">");
254:
255: for (int i = 0; i < 8; i++) {
256: parameter = ((i & 1) == 0) ? false : true;
257: name = ((i & 2) == 0) ? null : "name";
258: text = ((i & 4) == 0) ? null : "text";
259: if (name == null || text == null) {
260: createEntityDeclInvalid(parameter, name, text);
261: }
262: }
263:
264: // External Entity Decl
265: createEntityDecl("name", "publicId", "systemId",
266: "<!ENTITY name PUBLIC \"publicId\" \"systemId\">");
267: createEntityDecl("name", null, "systemId",
268: "<!ENTITY name SYSTEM \"systemId\">");
269: createEntityDecl(false, "name", "publicId", "systemId",
270: "<!ENTITY name PUBLIC \"publicId\" \"systemId\">");
271: createEntityDecl(false, "name", null, "systemId",
272: "<!ENTITY name SYSTEM \"systemId\">");
273:
274: for (int i = 0; i < 8; i++) {
275: name = ((i & 1) == 0) ? null : "name";
276: publicId = ((i & 2) == 0) ? null : "publicId";
277: systemId = ((i & 4) == 0) ? null : "systemId";
278:
279: if (name == null || systemId == null) {
280: createEntityDeclInvalid(name, publicId, systemId);
281: }
282: }
283:
284: // Parametr External Entity Decl
285: createEntityDecl(true, "name", "publicId", "systemId",
286: "<!ENTITY % name PUBLIC \"publicId\" \"systemId\">");
287: createEntityDecl(true, "name", null, "systemId",
288: "<!ENTITY % name SYSTEM \"systemId\">");
289:
290: for (int i = 0; i < 16; i++) {
291: name = ((i & 1) == 0) ? null : "name";
292: publicId = ((i & 2) == 0) ? null : "publicId";
293: systemId = ((i & 4) == 0) ? null : "systemId";
294: parameter = ((i & 8) == 0) ? true : false;
295:
296: if (name == null || systemId == null) {
297: createEntityDeclInvalid(parameter, name, publicId,
298: systemId);
299: }
300: }
301:
302: // Unparsed Entity Decl
303: createEntityDecl("name", "publicId", "systemId",
304: "notationName",
305: "<!ENTITY name PUBLIC \"publicId\" \"systemId\" NDATA notationName>");
306: createEntityDecl("name", null, "systemId", "notationName",
307: "<!ENTITY name SYSTEM \"systemId\" NDATA notationName>");
308:
309: for (int i = 0; i < 16; i++) {
310: name = ((i & 1) == 0) ? null : "name";
311: publicId = ((i & 2) == 0) ? null : "publicId";
312: systemId = ((i & 4) == 0) ? null : "systemId";
313: notationName = ((i & 8) == 0) ? null : "notationName";
314:
315: if (name == null || systemId == null
316: || notationName == null) {
317: createEntityDeclInvalid(name, publicId, systemId,
318: notationName);
319: }
320: }
321: }
322:
323: public void testGeneralEntityReference() throws Exception {
324: createGeneralEntityReference(":g1e_r-e.f", "&:g1e_r-e.f;");
325:
326: createGeneralEntityReferenceInvalid(null);
327: createGeneralEntityReferenceInvalid("&");
328: createGeneralEntityReferenceInvalid(";");
329: createGeneralEntityReferenceInvalid("%");
330: }
331:
332: public void testNotationDecl() throws Exception {
333: String name;
334: String publicId;
335: String systemId;
336: TreeNotationDecl node;
337:
338: createNotationDecl("name", "publicId", "systemId",
339: "<!NOTATION name PUBLIC \"publicId\" \"systemId\">");
340: createNotationDecl("name", null, "systemId",
341: "<!NOTATION name SYSTEM \"systemId\">");
342: createNotationDecl("name", "publicId", null,
343: "<!NOTATION name PUBLIC \"publicId\">");
344:
345: for (int i = 0; i < 8; i++) {
346: name = ((i & 1) == 0) ? null : "name";
347: publicId = ((i & 2) == 0) ? null : "publicId";
348: systemId = ((i & 4) == 0) ? null : "systemId";
349:
350: if (name == null || (systemId == null && publicId == null)) {
351: createNotationDeclInvalid(name, publicId, systemId);
352: }
353: }
354: }
355:
356: public void testParameterEntityReference() throws Exception {
357: createParameterEntityReference(":p1e_r-e.f", "%:p1e_r-e.f;");
358:
359: createParameterEntityReferenceInvalid(null);
360: createParameterEntityReferenceInvalid("&");
361: createParameterEntityReferenceInvalid(";");
362: createParameterEntityReferenceInvalid("%");
363: }
364:
365: public void testProcessingInstruction() throws Exception {
366: createProcessingInstruction("target", "pi-data",
367: "<?target pi-data?>");
368: createProcessingInstruction("target", "&%4;?<<>>]]>--> <!--",
369: "<?target &%4;?<<>>]]>--> <!--?>");
370:
371: createProcessingInstructionInvalid(null, null);
372: createProcessingInstructionInvalid("target", null);
373: createProcessingInstructionInvalid("xml", "pi-data");
374: createProcessingInstructionInvalid("XmL", "pi-data");
375: createProcessingInstructionInvalid("&", "pi-data");
376: }
377:
378: public void testText() throws Exception {
379: createText(" text >--> % @ # $ ", " text >--> % @ # $ ");
380: createTextInvalid("<");
381: createTextInvalid("&");
382: //createTextInvalid("]]>"); // ISSUE #18445
383: }
384:
385: /**
386: * Performs this testsuite.
387: * @param args the command line arguments
388: */
389: public static void main(String args[]) {
390: TestRunner.run(FactoryTest.class);
391: }
392: }
|