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 Roman I. Chernyatchik
019: * @version $Revision$
020: */package javax.swing.text;
021:
022: import javax.swing.BasicSwingTestCase;
023: import junit.framework.TestCase;
024:
025: public class TabStopTest extends TestCase {
026: private TabStop tabStop;
027:
028: public TabStopTest(final String name) {
029: super (name);
030: }
031:
032: public void testEquals() throws Exception {
033: TabStop tabStop1;
034: TabStop tabStop2;
035: tabStop1 = new TabStop(0f, TabStop.ALIGN_LEFT,
036: TabStop.LEAD_NONE);
037: tabStop2 = new TabStop(0f, TabStop.ALIGN_LEFT,
038: TabStop.LEAD_NONE);
039: assertEquals(tabStop1, tabStop2);
040: tabStop1 = new TabStop(-12.11f, 3, -5);
041: tabStop2 = new TabStop(-12.11f, 3, -5);
042: assertEquals(tabStop1, tabStop2);
043: tabStop1 = new TabStop(0f, TabStop.ALIGN_LEFT,
044: TabStop.LEAD_NONE);
045: tabStop2 = new TabStop(1f, TabStop.ALIGN_CENTER,
046: TabStop.LEAD_EQUALS);
047: assertFalse(tabStop1.equals(tabStop2));
048: tabStop1 = new TabStop(-12.11f, TabStop.ALIGN_LEFT, -5);
049: tabStop2 = new TabStop(-12.1099999f, TabStop.ALIGN_LEFT, -5);
050: assertEquals(tabStop1, tabStop2);
051: tabStop1 = new TabStop(-12.11f, 3, -6);
052: tabStop2 = new TabStop(-12.12f, 3, -5);
053: assertFalse(tabStop1.equals(tabStop2));
054: tabStop1 = new TabStop(-12.1f, TabStop.ALIGN_LEFT,
055: TabStop.LEAD_EQUALS);
056: assertFalse(tabStop1.equals("test"));
057: }
058:
059: public void testToString() throws Exception {
060: tabStop = new TabStop(1024f, TabStop.ALIGN_BAR,
061: TabStop.LEAD_DOTS);
062: assertEquals("bar tab @1024.0 (w/leaders)", tabStop.toString());
063: tabStop = new TabStop(-15f, TabStop.ALIGN_CENTER,
064: TabStop.LEAD_EQUALS);
065: assertEquals("center tab @-15.0 (w/leaders)", tabStop
066: .toString());
067: tabStop = new TabStop(-5f, TabStop.ALIGN_DECIMAL,
068: TabStop.LEAD_HYPHENS);
069: assertEquals("decimal tab @-5.0 (w/leaders)", tabStop
070: .toString());
071: tabStop = new TabStop(0f, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
072: assertEquals("tab @0.0", tabStop.toString());
073: tabStop = new TabStop(12.11f, TabStop.ALIGN_RIGHT,
074: TabStop.LEAD_THICKLINE);
075: assertEquals("right tab @12.11 (w/leaders)", tabStop.toString());
076: tabStop = new TabStop(12.11f, 20, TabStop.LEAD_UNDERLINE);
077: assertEquals("tab @12.11 (w/leaders)", tabStop.toString());
078: tabStop = new TabStop(12.11f);
079: assertEquals("tab @12.11", tabStop.toString());
080: tabStop = new TabStop(12.11f, -23, 50);
081: assertEquals("tab @12.11 (w/leaders)", tabStop.toString());
082: }
083:
084: public void testHashCode() throws Exception {
085: assertEquals(new TabStop(3f, TabStop.ALIGN_RIGHT,
086: TabStop.LEAD_HYPHENS).hashCode(), new TabStop(3f,
087: TabStop.ALIGN_RIGHT, TabStop.LEAD_HYPHENS).hashCode());
088: assertEquals(new TabStop(Float.MAX_VALUE, TabStop.ALIGN_RIGHT,
089: TabStop.LEAD_DOTS).hashCode(),
090: new TabStop(Float.MAX_VALUE, TabStop.ALIGN_RIGHT,
091: TabStop.LEAD_DOTS).hashCode());
092: assertEquals(new TabStop(Float.MIN_VALUE, -3, 7).hashCode(),
093: new TabStop(Float.MIN_VALUE, -3, 7).hashCode());
094: int hashCode1 = new TabStop(3, TabStop.ALIGN_RIGHT,
095: TabStop.LEAD_HYPHENS).hashCode();
096: int hashCode2 = new TabStop(1, TabStop.ALIGN_RIGHT,
097: TabStop.LEAD_HYPHENS).hashCode();
098: assertTrue(hashCode1 != hashCode2);
099: }
100:
101: public void testGetLeader() throws Exception {
102: tabStop = new TabStop(2.11f, 0, TabStop.LEAD_EQUALS);
103: assertEquals(TabStop.LEAD_EQUALS, tabStop.getLeader());
104: tabStop = new TabStop(20f, 3, TabStop.LEAD_UNDERLINE);
105: assertEquals(TabStop.LEAD_UNDERLINE, tabStop.getLeader());
106: tabStop = new TabStop(12.11f, -23, 50);
107: assertEquals(50, tabStop.getLeader());
108: }
109:
110: public void testGetPosition() throws Exception {
111: tabStop = new TabStop(0f, TabStop.ALIGN_CENTER,
112: TabStop.LEAD_DOTS);
113: assertEquals(0, tabStop.getPosition(), 0.0001);
114: tabStop = new TabStop(-2.5f, TabStop.ALIGN_CENTER,
115: TabStop.LEAD_DOTS);
116: assertEquals(-2.5, tabStop.getPosition(), 0.0001);
117: tabStop = new TabStop(13554111f, TabStop.ALIGN_CENTER,
118: TabStop.LEAD_DOTS);
119: assertEquals(13554111, tabStop.getPosition(), 0.0001);
120: tabStop = new TabStop(-13554111f, TabStop.ALIGN_CENTER,
121: TabStop.LEAD_DOTS);
122: assertEquals(-13554111, tabStop.getPosition(), 0.0001);
123: }
124:
125: public void testGetAlignmet() throws Exception {
126: tabStop = new TabStop(2.5f, TabStop.ALIGN_DECIMAL,
127: TabStop.LEAD_DOTS);
128: assertEquals(TabStop.ALIGN_DECIMAL, tabStop.getAlignment());
129: tabStop = new TabStop(0f, 3, TabStop.LEAD_DOTS);
130: assertEquals(3, tabStop.getAlignment());
131: tabStop = new TabStop(-1f, -3, 7);
132: assertEquals(-3, tabStop.getAlignment());
133: }
134:
135: public void testSerializable() throws Exception {
136: tabStop = new TabStop(10f, TabStop.ALIGN_CENTER,
137: TabStop.LEAD_HYPHENS);
138: tabStop = (TabStop) BasicSwingTestCase.serializeObject(tabStop);
139: assertEquals(10f, tabStop.getPosition(), 0.0001);
140: assertEquals(TabStop.ALIGN_CENTER, tabStop.getAlignment());
141: assertEquals(TabStop.LEAD_HYPHENS, tabStop.getLeader());
142: }
143: }
|