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_BranchElementTest;
023: import javax.swing.text.BadLocationException;
024: import javax.swing.text.StyleConstants;
025: import javax.swing.text.AbstractDocument.AbstractElement;
026: import javax.swing.text.AbstractDocument.BranchElement;
027: import javax.swing.text.AbstractDocument.LeafElement;
028: import javax.swing.text.html.HTMLDocument.BlockElement;
029:
030: public class HTMLDocument_BlockElementTest extends
031: AbstractDocument_BranchElementTest {
032:
033: public static class LockableHTMLDocument extends HTMLDocument {
034: public void lockWrite() {
035: writeLock();
036: }
037:
038: public void unlockWrite() {
039: writeUnlock();
040: }
041: }
042:
043: protected LockableHTMLDocument htmlDoc;
044:
045: protected void setUp() throws Exception {
046: super .setUp();
047:
048: htmlDoc = new LockableHTMLDocument();
049: doc = htmlDoc;
050:
051: doc.insertString(0, LTR + RTL + LTR + RTL + "\n01234", as[0]);
052:
053: bidi = (BranchElement) doc.getBidiRootElement();
054: leaf1 = (LeafElement) bidi.getElement(0).getElement(0);
055: par = (BranchElement) doc.getDefaultRootElement();
056: leaf2 = par != null ? par.getElement(0) : null;
057: leaf3 = leaf2;
058: }
059:
060: protected void tearDown() throws Exception {
061: htmlDoc = null;
062: super .tearDown();
063: }
064:
065: public void testGetElementCount() {
066: assertEquals(5, bidi.getElementCount());
067: assertEquals(1, par.getElementCount());
068: }
069:
070: public void testToString() {
071: assertEquals("BranchElement(bidi root) 0,15\n", bidi.toString());
072: assertEquals("BranchElement(html) 0,15\n", par.toString());
073: }
074:
075: public void testGetName() {
076: AbstractElement block = htmlDoc.new BlockElement(null, null);
077: assertEquals("paragraph", block.getName());
078: htmlDoc.lockWrite();
079:
080: final String name = "asddsa";
081: block = htmlDoc.new BlockElement(null, null);
082: block.addAttribute(StyleConstants.NameAttribute, name);
083: assertEquals(name, block.getName());
084: }
085:
086: public void testGetElement() {
087: if (isHarmony()) {
088: assertNull(par.getElement(-1));
089: }
090: assertEquals(leaf2, par.getElement(0));
091: assertNull(par.getElement(1));
092: assertNull(par.getElement(2));
093: }
094:
095: public void testGetElementIndex01() {
096: assertEquals(0, par.getElementIndex(-1));
097: assertEquals(0, par.getElementIndex(7));
098: assertEquals(0, par.getElementIndex(8));
099: assertEquals(0, par.getElementIndex(9));
100: assertEquals(0, par.getElementIndex(10));
101: assertEquals(0, par.getElementIndex(11));
102: assertEquals(0, par.getElementIndex(20));
103: }
104:
105: public void testBranchElement() {
106: }
107:
108: public void testGetResolveParent() {
109: htmlDoc.lockWrite();
110: AbstractElement parent = htmlDoc.new BlockElement(null, null);
111: AbstractElement block = htmlDoc.new BlockElement(parent, null);
112: assertNull(parent.getResolveParent());
113: assertNull(block.getResolveParent());
114:
115: block.setResolveParent(parent);
116: assertNull(block.getResolveParent());
117: }
118:
119: public void testBlockElement() throws BadLocationException {
120: htmlDoc.lockWrite();
121: htmlDoc.remove(0, htmlDoc.getLength());
122: BlockElement block = htmlDoc.new BlockElement(par, as[0]);
123: assertSame(par, block.getParentElement());
124: assertNull(block.getResolveParent());
125: assertEquals(0, block.getElementCount());
126: }
127: }
|