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 Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing.text.html;
021:
022: import javax.swing.text.AbstractDocument_LeafElementTest;
023: import javax.swing.text.StyleConstants;
024: import javax.swing.text.AbstractDocument.AbstractElement;
025: import javax.swing.text.AbstractDocument.BranchElement;
026: import javax.swing.text.html.HTMLDocument.RunElement;
027: import javax.swing.text.html.HTMLDocument_BlockElementTest.LockableHTMLDocument;
028:
029: public class HTMLDocument_RunElementTest extends
030: AbstractDocument_LeafElementTest {
031:
032: protected LockableHTMLDocument htmlDoc;
033:
034: protected void setUp() throws Exception {
035: super .setUp();
036:
037: htmlDoc = new LockableHTMLDocument();
038: doc = htmlDoc;
039:
040: doc.insertString(0, "0123456789", as[0]);
041:
042: htmlDoc.lockWrite();
043: BranchElement branch = doc.new BranchElement(null, as[1]);
044: leaf1 = doc.new LeafElement(null, as[2], 0, 3);
045: leaf2 = doc.new LeafElement(branch, as[2], 5, 8);
046: htmlDoc.unlockWrite();
047: }
048:
049: protected void tearDown() throws Exception {
050: htmlDoc = null;
051: super .tearDown();
052: }
053:
054: public void testGetName() {
055: AbstractElement run = htmlDoc.new RunElement(null, null, 0, 0);
056: assertEquals("content", run.getName());
057: htmlDoc.lockWrite();
058:
059: final String name = "asddsa";
060: run = htmlDoc.new RunElement(null, null, 0, 0);
061: run.addAttribute(StyleConstants.NameAttribute, name);
062: assertEquals(name, run.getName());
063: }
064:
065: public void testGetResolveParent() {
066: AbstractElement parent = htmlDoc.new RunElement(null, null, 0,
067: 0);
068: AbstractElement block = htmlDoc.new RunElement(parent, null, 0,
069: 0);
070: assertNull(parent.getResolveParent());
071: assertNull(block.getResolveParent());
072: }
073:
074: public void testLeafElement() {
075: }
076:
077: public void testRunElement() {
078: htmlDoc.lockWrite();
079:
080: RunElement run = htmlDoc.new RunElement(leaf1, as[2], 3, 9);
081:
082: assertSame(leaf1, run.getParent());
083: assertSame(leaf1, run.getParentElement());
084: assertSame(run, run.getAttributes());
085: assertEquals(as[2].getAttributeCount(), run.getAttributeCount());
086: assertEquals(3, run.getStartOffset());
087: assertEquals(9, run.getEndOffset());
088:
089: int[] start = { -1, 3, 3, 3 }; // start offset
090: int[] expStart = { 0, 3, 3, 3 }; // expectations for start offset
091: int[] end = { 9, -1, 1, 20 }; // end offset
092: int[] expEnd = { 9, 0, 1, 20 }; // expectations for end offset
093: int[] intEnd = { 9, 3, 3, 20 }; // expectations for DRL's end offset
094: for (int i = 0; i < start.length; i++) {
095: run = htmlDoc.new RunElement(null, null, start[i], end[i]);
096: assertEquals("Start (" + i + ")", expStart[i], run
097: .getStartOffset());
098: assertEquals("End (" + i + ")", isHarmony() ? intEnd[i]
099: : expEnd[i], run.getEndOffset());
100: }
101:
102: htmlDoc.unlockWrite();
103: }
104: }
|