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 Denis M. Kishenko
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.Point;
023:
024: public class PointTest extends SerializeTestCase {
025:
026: static {
027: SERIALIZATION_TEST = true;
028: }
029:
030: public PointTest(String name) {
031: super (name);
032: }
033:
034: @Override
035: protected void setUp() throws Exception {
036: super .setUp();
037: }
038:
039: @Override
040: protected void tearDown() throws Exception {
041: super .tearDown();
042: }
043:
044: public void testCreate1() {
045: assertEquals(new Point(0, 0), new Point());
046: }
047:
048: public void testCreate2() {
049: assertEquals(new Point(1, 2), new Point(new Point(1, 2)));
050: }
051:
052: public void testGetX() {
053: assertEquals(1, (int) new Point(1, 2).getX());
054: }
055:
056: public void testGetY() {
057: assertEquals(2, (int) new Point(1, 2).getY());
058: }
059:
060: public void testGetLocation() {
061: assertEquals(new Point(1, 2), new Point(1, 2).getLocation());
062: }
063:
064: public void testSetLocationInt() {
065: Point p = new Point(1, 2);
066: p.setLocation(3, 4);
067: assertEquals(new Point(3, 4), p);
068: }
069:
070: public void testSetLocationDouble1() {
071: Point p = new Point(1, 2);
072: p.setLocation(3.0, 4.0);
073: assertEquals(new Point(3, 4), p);
074: }
075:
076: public void testSetLocationDouble2() {
077: Point p = new Point(1, 2);
078: p.setLocation(5.3, 6.7);
079: assertEquals(new Point(5, 7), p);
080: }
081:
082: public void testSetLocationDouble3() {
083: Point p = new Point(1, 2);
084: p.setLocation(7.5, 8.5);
085: assertEquals(new Point(8, 9), p);
086: }
087:
088: public void testSetLocationDouble4() {
089: // Regression test HARMONY-1878
090: Point p = new Point(1, 2);
091: double x = (double) Integer.MAX_VALUE + (double) 1;
092: double y = (double) Integer.MIN_VALUE - (double) 1;
093: p.setLocation(x, y);
094: assertEquals(new Point(Integer.MAX_VALUE, Integer.MIN_VALUE), p);
095: }
096:
097: public void testSetLocationDouble5() {
098: // Regression test HARMONY-1878
099: Point p = new Point(1, 2);
100: p.setLocation(Double.POSITIVE_INFINITY,
101: Double.NEGATIVE_INFINITY);
102: assertEquals(new Point(Integer.MAX_VALUE, Integer.MIN_VALUE), p);
103: }
104:
105: public void testSetLocationPoint() {
106: Point p = new Point(1, 2);
107: p.setLocation(new Point(3, 4));
108: assertEquals(new Point(3, 4), p);
109: }
110:
111: public void testMove() {
112: Point p = new Point(1, 2);
113: p.move(3, 4);
114: assertEquals(new Point(3, 4), p);
115: }
116:
117: public void testTranslate() {
118: Point p = new Point(1, 2);
119: p.translate(3, 4);
120: assertEquals(new Point(4, 6), p);
121: }
122:
123: public void testToString() {
124: assertEquals("java.awt.Point[x=1,y=2]", new Point(1, 2)
125: .toString());
126: }
127:
128: public void testEquals() {
129: assertTrue(new Point(1, 2).equals(new Point(1, 2)));
130: assertFalse(new Point(3, 2).equals(new Point(1, 2)));
131: assertFalse(new Point(1, 3).equals(new Point(1, 2)));
132: assertFalse(new Point(3, 3).equals(new Point(1, 2)));
133: }
134:
135: public void testSerializeRead1() {
136: checkRead(new Point());
137: }
138:
139: public void testSerializeRead2() {
140: checkRead(new Point(1, 2));
141: }
142:
143: public void testSerializeWrite1() {
144: checkWrite(new Point());
145: }
146:
147: public void testSerializeWrite2() {
148: checkWrite(new Point(1, 2));
149: }
150:
151: public void createSerializeTemplates() {
152: saveSerialized(new Point());
153: saveSerialized(new Point(1, 2));
154: }
155:
156: public static void main(String[] args) {
157: // new PointTest("").createSerializeTemplates();
158: junit.textui.TestRunner.run(PointTest.class);
159: }
160:
161: }
|