alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.tax;

import java.util.Arrays;
import java.util.List;
import junit.textui.TestRunner;
import org.netbeans.tax.TreeElementDecl.ContentType;
import org.netbeans.tax.decl.*;

/**
 *
 * @author  ms113234
 */
public class FactoryTest extends AbstractFactoryTest {
    
    /** Creates new CoreSettingsTest */
    public FactoryTest(String testName) {
        super(testName);
    }
    
    //==========================
    // = = =   T E S T S   = = =
    //==========================
    
    public void testAttlistDecl() throws Exception {
        createAttlistDecl("elementName", "");
        
        createAttlistDeclInvalid(null);
    }
    
    public void testAttribute() throws Exception {
        createAttribute("name", "value", "name=\"value\"");
        //createAttribute("name", "C<K", "name=\"C<K\""); // issue #15785
        
        createAttributeInvalid(null, null);
        createAttributeInvalid("name", null);
        createAttributeInvalid(null, "value");
        createAttributeInvalid("na me", "value");
        createAttributeInvalid("na;me", "value");
        createAttributeInvalid("1name", "value");
    }
    
    public void testCDATASection() throws Exception {
        createCDATASection(" < � data>", " < � data>]]>");
        
        createCDATASectionInvalid(null);
        createCDATASectionInvalid("aa ]]> bbb");
    }
    
    public void testCharacterReference() throws Exception {
        createCharacterReference("#35", "#");
        createCharacterReference("#x35", "5");
        
        createCharacterReferenceInvalid(null);
        createCharacterReferenceInvalid("");
        createCharacterReferenceInvalid("#");
        createCharacterReferenceInvalid("#x");
        createCharacterReferenceInvalid("#xg");
        createCharacterReferenceInvalid("#;");
        createCharacterReferenceInvalid("# ");
    }
    
    public void testComment() throws Exception {
        createComment("comment - comment", "");
        createComment("", "");
        
        createCommentInvalid(null);
        createCommentInvalid("bad--bad");
    }
    
    public void testConditionalSection() throws Exception {
        createConditionalSection(true, "");
        createConditionalSection(false, "");
    }
    
    public void testDTD() throws Exception {
        createDTD("1.0", "UTF-16", "");
        createDTD(null, "UTF-8", "");
        createDTD(null, null, "");
        
        createDTDInvalid(null, "encodig");
        createDTDInvalid("version", null);
        createDTDInvalid("1.0", "encodig");
        createDTDInvalid("version", "UTF-16");
    }
    
    public void testDocument() throws Exception {
        createDocument(null, null, null, "");
        createDocument("1.0", "ISO-8859-2", "no", "");
        createDocument("1.0", null, "yes", "");
        createDocument("1.0", "ASCII", null, "");
        createDocument("1.0", null, null, "");
        
        createDocumentInvalid("2.0", "ISO-8859-2", "no");
        createDocumentInvalid("10", "ISO-8859-2", "no");
        createDocumentInvalid("", "ISO-8859-2", "no");
        createDocumentInvalid("2.0", null, "no");
        createDocumentInvalid(".0", "ISO-8859-2", null);
        createDocumentInvalid(null, "ISO-8859-2", "no");
        createDocumentInvalid(null, null, "no");
        createDocumentInvalid(null, "ISO-8859-2", null);
    }
    
    public void testDocumentFragment() throws Exception {
        createDocumentFragment(null, null, "");
        createDocumentFragment("1.0", "ISO-8859-2", "");
        createDocumentFragment(null, "ISO-8859-2", "");
        
        createDocumentFragmentInvalid("1.0", null);
        createDocumentFragmentInvalid("3.0", "UTF-8");
        createDocumentFragmentInvalid("1.0", "UTF-80");
    }
    
    public void testDocumentType() throws Exception {
        createDocumentType("elementName", "");
        
        createDocumentType("element", "pub_id", "sys_id", "");
        createDocumentType("element", "pub_id", "", "");
        createDocumentType("element", "pub_id", null, "");
        createDocumentType("element", "", "sys_id", "");
        createDocumentType("element", null, "sys_id", "");
        
        createDocumentTypeInvalid(null);
        createDocumentTypeInvalid("");
        createDocumentTypeInvalid("a c");
        createDocumentTypeInvalid("a>c");
        createDocumentTypeInvalid("a%c");
        createDocumentTypeInvalid("a%ref;c");
        
        createDocumentTypeInvalid("", "pub_id", "sys_id");
        createDocumentTypeInvalid(null, "pub_id", "sys_id");
        createDocumentTypeInvalid("1element", "pub_id", "sys_id");
        createDocumentTypeInvalid("ele ment", "pub_id", "sys_id");
        createDocumentTypeInvalid("element", "pub_id", "\'\"");
        //createDocumentTypeInvalid("element", "pub_id&", "sys_id"); // issue #18112
        
        
    }
    
    public void testElement() throws Exception {
        createElement("element", "");
        createElement("ns:element", "");
        
        createElementInvalid(null);
        createElementInvalid("");
        createElementInvalid("1a");
        createElementInvalid("a b");
        createElementInvalid("a&b");
        createElementInvalid("a%b");
    }
    
    public void testElementDecl() throws Exception {
        List content;
        ContentType type;
        
        createElementDecl("element", new ANYType(), "");
        createElementDecl("element", new EMPTYType(), "");
        
        content = Arrays.asList(new Object[] {new NameType("ele1"), new NameType("ele2","")});
        type = new SequenceType(content);
        type.setMultiplicity("+");
        createElementDecl("element", type, "");
        
        type = new ChoiceType(content);
        type.setMultiplicity("*");
        createElementDecl("element", type, "");
        
        type = new MixedType(content);
        type.setMultiplicity("+");
        createElementDecl("element", type, "");
        
        //createElementDecl("books", "(product+, price?, image,custom? )+", "");
        //createElementDecl("dictionary-body", "(%div.mix;, %dict.mix;)*", "");
        //createElementDecl("%name.para;", "%content.para;", "");
        //createElementDecl("div", "( head, (p | list | note )*, div2* )", ""); // issue #
        //createElementDecl("div", "(p | list | note )*", ""); // issue #
        //createElementDecl("product", "(#PCDATA |descript)*", ""); // issue #
        //createElementDecl("descript", "(#PCDATA)", ""); // issue #
        
        createElementDeclInvalid(null, (ContentType) null);
    }
    
    public void testEntityDecl() throws Exception {
        boolean parameter;
        String name, text;
        String publicId, systemId;
        String notationName;
        
        // General Entity Decl
        createEntityDecl("name", "text", "");
        createEntityDeclInvalid(null, null);
        createEntityDeclInvalid("name", null);
        createEntityDeclInvalid(null, "text");
        
        // Parametr Entity Decl
        createEntityDecl(true, "name", "text", "");
        
        for (int i = 0; i < 8; i++) {
            parameter = ((i & 1) == 0) ? false : true;
            name = ((i & 2) == 0) ? null : "name";
            text = ((i & 4) == 0) ? null : "text";
            if (name == null || text == null) {
                createEntityDeclInvalid(parameter, name, text);
            }
        }
        
        // External Entity Decl
        createEntityDecl("name", "publicId", "systemId", "");
        createEntityDecl("name", null, "systemId", "");
        createEntityDecl(false, "name", "publicId", "systemId", "");
        createEntityDecl(false, "name", null, "systemId", "");
        
        for (int i = 0; i < 8; i++) {
            name = ((i & 1) == 0) ? null : "name";
            publicId = ((i & 2) == 0) ? null : "publicId";
            systemId = ((i & 4) == 0) ? null : "systemId";
            
            if (name == null || systemId == null) {
                createEntityDeclInvalid(name, publicId, systemId);
            }
        }
        
        // Parametr External Entity Decl
        createEntityDecl(true, "name", "publicId", "systemId",  "");
        createEntityDecl(true, "name", null, "systemId",  "");
        
        for (int i = 0; i < 16; i++) {
            name = ((i & 1) == 0) ? null : "name";
            publicId = ((i & 2) == 0) ? null : "publicId";
            systemId = ((i & 4) == 0) ? null : "systemId";
            parameter = ((i & 8) == 0) ? true : false;
            
            if (name == null || systemId == null) {
                createEntityDeclInvalid(parameter, name, publicId, systemId);
            }
        }
        
        // Unparsed Entity Decl
        createEntityDecl("name", "publicId", "systemId", "notationName", "");
        createEntityDecl("name", null, "systemId", "notationName",  "");
        
        for (int i = 0; i < 16; i++) {
            name = ((i & 1) == 0) ? null : "name";
            publicId = ((i & 2) == 0) ? null : "publicId";
            systemId = ((i & 4) == 0) ? null : "systemId";
            notationName = ((i & 8) == 0) ? null : "notationName";
            
            if (name == null || systemId == null || notationName == null) {
                createEntityDeclInvalid(name, publicId, systemId, notationName);
            }
        }
    }
    
    public void testGeneralEntityReference() throws Exception {
        createGeneralEntityReference(":g1e_r-e.f", "&:g1e_r-e.f;");
        
        createGeneralEntityReferenceInvalid(null);
        createGeneralEntityReferenceInvalid("&");
        createGeneralEntityReferenceInvalid(";");
        createGeneralEntityReferenceInvalid("%");
    }
    
    public void testNotationDecl() throws Exception {
        String name;
        String publicId;
        String systemId;
        TreeNotationDecl node;
        
        createNotationDecl("name", "publicId", "systemId", "");
        createNotationDecl("name", null, "systemId", "");
        createNotationDecl("name", "publicId", null, "");
        
        for (int i = 0; i < 8; i++) {
            name = ((i & 1) == 0) ? null : "name";
            publicId = ((i & 2) == 0) ? null : "publicId";
            systemId = ((i & 4) == 0) ? null : "systemId";
            
            if (name == null || (systemId == null && publicId == null)) {
                createNotationDeclInvalid(name, publicId, systemId);
            }
        }
    }
    
    public void testParameterEntityReference() throws Exception {
        createParameterEntityReference(":p1e_r-e.f", "%:p1e_r-e.f;");
        
        createParameterEntityReferenceInvalid(null);
        createParameterEntityReferenceInvalid("&");
        createParameterEntityReferenceInvalid(";");
        createParameterEntityReferenceInvalid("%");
    }
    
    public void testProcessingInstruction() throws Exception {
        createProcessingInstruction("target", "pi-data", "");
        createProcessingInstruction("target", "&%4;?<<>>]]>-->   % @ # $ ", " text >--> % @ # $ ");
        createTextInvalid("<");
        createTextInvalid("&");
        //createTextInvalid("]]>"); // ISSUE #18445
    }
    
    /**
     * Performs this testsuite.
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        TestRunner.run(FactoryTest.class);
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.