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 Oleg V. Khaschansky
019: * @version $Revision$
020: */
021:
022: package java.awt.font;
023:
024: import junit.framework.Test;
025: import junit.framework.TestSuite;
026: import junit.framework.TestCase;
027:
028: public class TextHitInfoTest extends TestCase {
029:
030: private TextHitInfo l4, t3, tm1;
031:
032: public TextHitInfoTest(String name) {
033: super (name);
034: }
035:
036: @Override
037: public void setUp() throws Exception {
038: super .setUp();
039: l4 = TextHitInfo.leading(4);
040: t3 = TextHitInfo.trailing(3);
041: tm1 = TextHitInfo.trailing(-1);
042: }
043:
044: @Override
045: public void tearDown() throws Exception {
046: super .tearDown();
047: }
048:
049: public void testToString() throws Exception {
050: l4.toString();
051: tm1.toString();
052: }
053:
054: public void testEquals() throws Exception {
055: assertEquals(t3, TextHitInfo.trailing(3));
056: }
057:
058: public void testEquals1() throws Exception {
059: assertNotSame(t3, new String("q"));
060: }
061:
062: public void testGetOffsetHit() throws Exception {
063: TextHitInfo i1 = t3.getOffsetHit(2);
064: assertEquals(TextHitInfo.trailing(5), i1);
065: TextHitInfo i2 = l4.getOffsetHit(-2);
066: assertEquals(TextHitInfo.leading(2), i2);
067: TextHitInfo i3 = tm1.getOffsetHit(-1);
068: assertEquals(TextHitInfo.trailing(-2), i3);
069: }
070:
071: public void testGetOtherHit() throws Exception {
072: TextHitInfo i1 = t3.getOtherHit();
073: assertEquals(l4, i1);
074:
075: TextHitInfo i2 = l4.getOtherHit();
076: assertEquals(t3, i2);
077: }
078:
079: public void testIsLeadingEdge() throws Exception {
080: assertFalse(t3.isLeadingEdge());
081: assertTrue(l4.isLeadingEdge());
082: }
083:
084: public void testHashCode() throws Exception {
085: assertEquals(TextHitInfo.trailing(3).hashCode(), t3.hashCode());
086: assertTrue(t3.hashCode() != l4.hashCode());
087: assertTrue(TextHitInfo.leading(3).hashCode() != t3.hashCode());
088: }
089:
090: public void testGetInsertionIndex() throws Exception {
091: assertEquals(4, t3.getInsertionIndex());
092: assertEquals(4, l4.getInsertionIndex());
093: }
094:
095: public void testGetCharIndex() throws Exception {
096: assertEquals(3, t3.getCharIndex());
097: assertEquals(4, l4.getCharIndex());
098: }
099:
100: public void testTrailing() throws Exception {
101: assertEquals(4, TextHitInfo.trailing(4).getCharIndex());
102: assertFalse(TextHitInfo.trailing(-1).isLeadingEdge());
103: }
104:
105: public void testLeading() throws Exception {
106: assertEquals(4, TextHitInfo.leading(4).getCharIndex());
107: assertTrue(TextHitInfo.leading(1).isLeadingEdge());
108: }
109:
110: public void testBeforeOffset() throws Exception {
111: assertEquals(t3, TextHitInfo.beforeOffset(4));
112: }
113:
114: public void testAfterOffset() throws Exception {
115: assertEquals(l4, TextHitInfo.afterOffset(4));
116: }
117:
118: public static Test suite() {
119: return new TestSuite(TextHitInfoTest.class);
120: }
121: }
|