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.geom;
021:
022: import java.util.NoSuchElementException;
023:
024: public class PathIteratorTestCase extends GeomTestCase {
025:
026: double dcoords[] = new double[6];
027: float fcoords[] = new float[6];
028:
029: public PathIteratorTestCase(String name) {
030: super (name);
031: }
032:
033: public void checkPathDone(PathIterator p, boolean last) {
034: if (last) {
035: assertTrue("Expected path completed", p.isDone());
036: try {
037: p.currentSegment(dcoords);
038: fail("Expected exception NoSuchElementException");
039: } catch (NoSuchElementException e) {
040: }
041: try {
042: p.currentSegment(fcoords);
043: fail("Expected exception NoSuchElementException");
044: } catch (NoSuchElementException e) {
045: }
046: } else {
047: assertFalse("Expected path continue", p.isDone());
048: }
049: }
050:
051: public void checkPathRule(PathIterator p, int rule) {
052: assertEquals("Rule", rule, p.getWindingRule());
053: }
054:
055: public void checkPathMove(PathIterator p, boolean last, double x1,
056: double y1, double delta) {
057: checkPathDone(p, false);
058: assertEquals("Segment type", PathIterator.SEG_MOVETO, p
059: .currentSegment(dcoords));
060: assertEquals("Coordinates", new double[] { x1, y1 }, dcoords,
061: 2, delta);
062: p.next();
063: checkPathDone(p, last);
064: }
065:
066: public void checkPathMove(PathIterator p, boolean last, float x1,
067: float y1, float delta) {
068: checkPathDone(p, false);
069: assertEquals("Segment type", PathIterator.SEG_MOVETO, p
070: .currentSegment(fcoords));
071: assertEquals("Coordinates", new float[] { x1, y1 }, fcoords, 2,
072: delta);
073: p.next();
074: checkPathDone(p, last);
075: }
076:
077: public void checkPathLine(PathIterator p, boolean last, double x1,
078: double y1, double delta) {
079: checkPathDone(p, false);
080: assertEquals("Segment type", PathIterator.SEG_LINETO, p
081: .currentSegment(dcoords));
082: assertEquals("Coordinates", new double[] { x1, y1 }, dcoords,
083: 2, delta);
084: p.next();
085: checkPathDone(p, last);
086: }
087:
088: public void checkPathLine(PathIterator p, boolean last, float x1,
089: float y1, float delta) {
090: checkPathDone(p, false);
091: assertEquals("Segment type", PathIterator.SEG_LINETO, p
092: .currentSegment(fcoords));
093: assertEquals("Coordinates", new float[] { x1, y1 }, fcoords, 2,
094: delta);
095: p.next();
096: checkPathDone(p, last);
097: }
098:
099: public void checkPathQuad(PathIterator p, boolean last, double x1,
100: double y1, double x2, double y2, double delta) {
101: checkPathDone(p, false);
102: assertEquals("Segment type", PathIterator.SEG_QUADTO, p
103: .currentSegment(dcoords));
104: assertEquals("Coordinates", new double[] { x1, y1, x2, y2 },
105: dcoords, 4, delta);
106: p.next();
107: checkPathDone(p, last);
108: }
109:
110: public void checkPathQuad(PathIterator p, boolean last, float x1,
111: float y1, float x2, float y2, float delta) {
112: checkPathDone(p, false);
113: assertEquals("Segment type", PathIterator.SEG_QUADTO, p
114: .currentSegment(fcoords));
115: assertEquals("Coordinates", new float[] { x1, y1, x2, y2 },
116: fcoords, 4, delta);
117: p.next();
118: checkPathDone(p, last);
119: }
120:
121: public void checkPathCubic(PathIterator p, boolean last, double x1,
122: double y1, double x2, double y2, double x3, double y3,
123: double delta) {
124: checkPathDone(p, false);
125: assertEquals("Segment type", PathIterator.SEG_CUBICTO, p
126: .currentSegment(dcoords));
127: assertEquals("Coordinates", new double[] { x1, y1, x2, y2, x3,
128: y3 }, dcoords, 6, delta);
129: p.next();
130: checkPathDone(p, last);
131: }
132:
133: public void checkPathCubic(PathIterator p, boolean last, float x1,
134: float y1, float x2, float y2, float x3, float y3,
135: float delta) {
136: checkPathDone(p, false);
137: assertEquals("Segment type", PathIterator.SEG_CUBICTO, p
138: .currentSegment(fcoords));
139: assertEquals("Coordinates", new float[] { x1, y1, x2, y2, x3,
140: y3 }, fcoords, 6, delta);
141: p.next();
142: checkPathDone(p, last);
143: }
144:
145: public void checkPathClose(PathIterator p, boolean last) {
146: checkPathDone(p, false);
147: assertEquals("Segment type", PathIterator.SEG_CLOSE, p
148: .currentSegment(dcoords));
149: p.next();
150: checkPathDone(p, last);
151: }
152:
153: }
|