001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Evgeniya G. Maenkova
019: * @version $Revision$
020: */package javax.swing.text.html.parser;
021:
022: import junit.framework.TestCase;
023:
024: public class EntityTest extends TestCase {
025: public void testEntity() {
026: String name = "first";
027: int type = 26;
028: String data = "firstData";
029: Entity entity = new Entity(name, type, data.toCharArray());
030: Utils.checkEntity(entity, name, type, data, false, false);
031:
032: name = "second";
033: type = 106;
034: data = "secondData";
035: entity = new Entity(name, type, data.toCharArray());
036: Utils.checkEntity(entity, name, type, data, false, false);
037:
038: name = null;
039: type = 0;
040: data = "";
041: entity = new Entity(name, type, data.toCharArray());
042: Utils.checkEntity(entity, name, type, data, false, false);
043: }
044:
045: //TODO Investigate how is it defined.
046: public void testIsGeneral() throws Exception {
047: Entity entity2 = new Entity(
048: "name", DTDConstants.GENERAL, new char[0]); //$NON-NLS-1$
049: assertTrue(entity2.isGeneral());
050:
051: entity2 = new Entity(
052: "name", DTDConstants.GENERAL | DTDConstants.CDATA, new char[0]); //$NON-NLS-1$
053: assertTrue(entity2.isGeneral());
054:
055: entity2 = new Entity("name", DTDConstants.CDATA, new char[0]); //$NON-NLS-1$
056: assertFalse(entity2.isGeneral());
057: }
058:
059: //TODO Investigate how is it defined.
060: public void testIsParameter() throws Exception {
061: //regression for HARMONY-1349
062: Entity entity2 = new Entity(
063: "name", DTDConstants.PARAMETER, new char[0]); //$NON-NLS-1$
064: assertTrue(entity2.isParameter());
065:
066: entity2 = new Entity(
067: "name", DTDConstants.PARAMETER | DTDConstants.CDATA, new char[0]); //$NON-NLS-1$
068: assertTrue(entity2.isParameter());
069:
070: entity2 = new Entity("name", DTDConstants.CDATA, new char[0]); //$NON-NLS-1$
071: assertFalse(entity2.isParameter());
072: }
073:
074: public void testName2type() {
075: String[] names = Utils.getDTDConstantsNames();
076: for (int i = 0; i < names.length; i++) {
077: String key = names[i];
078: int value = Entity.name2type(key);
079: if (key.equals("PUBLIC")) {
080: assertEquals(DTDConstants.PUBLIC, value);
081: } else if (key.equals("SDATA")) {
082: assertEquals(DTDConstants.SDATA, value);
083: } else if (key.equals("PI")) {
084: assertEquals(DTDConstants.PI, value);
085: } else if (key.equals("STARTTAG")) {
086: assertEquals(DTDConstants.STARTTAG, value);
087: } else if (key.equals("ENDTAG")) {
088: assertEquals(DTDConstants.ENDTAG, value);
089: } else if (key.equals("MS")) {
090: assertEquals(DTDConstants.MS, value);
091: } else if (key.equals("MD")) {
092: assertEquals(DTDConstants.MD, value);
093: } else if (key.equals("SYSTEM")) {
094: assertEquals(DTDConstants.SYSTEM, value);
095: } else {
096: assertEquals(DTDConstants.CDATA, value);
097: }
098: }
099: }
100:
101: /**
102: * @test javax.swing.text.html.parser.Entity#getType()
103: */
104: public void testType() throws Exception {
105: //regression for HARMONY-1349
106: DTD dtd = DTD.getDTD("dummy"); //$NON-NLS-1$
107: Entity space = dtd.getEntity("#SPACE"); //$NON-NLS-1$
108: assertEquals(65536, space.type);
109: assertEquals(0, space.getType());
110: }
111: }
|