Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 88678
Collapse All | Expand All

(-)src/org/eclipse/draw2d/test/CaretTests.java (-1 / +54 lines)
Lines 11-19 Link Here
11
11
12
package org.eclipse.draw2d.test;
12
package org.eclipse.draw2d.test;
13
13
14
import org.eclipse.draw2d.FigureCanvas;
15
import org.eclipse.draw2d.geometry.Point;
16
import org.eclipse.draw2d.text.CaretInfo;
17
import org.eclipse.swt.widgets.Shell;
18
14
/**
19
/**
15
 * @since 3.1
20
 * @since 3.1
16
 */
21
 */
17
public class CaretTests extends SimpleTextTest {
22
public class CaretTests extends SimpleTextTest {
18
23
	
24
	int trail[] = new int[1];
25
	int offset;
26
	Point offsetPoint;
27
	
28
	protected void setUp() throws Exception {
29
		super.setUp();
30
		flowpage.setFont(TAHOMA);
31
		
32
		// Necessary to call getNextOffset()
33
		sentence.setText(PHRASE + "\n" + PHRASE);
34
		
35
		// Necessary to create figure with size > 0
36
		Shell shell = new Shell();
37
		FigureCanvas fc = new FigureCanvas(shell);
38
		fc.setContents(flowpage);
39
		fc.pack();
40
	}
41
	
42
	public void testOffset() {
43
		offsetPoint = new Point(118, 7);
44
		offset = sentence.getOffset(offsetPoint, trail, null);
45
		assertEquals(offset, 23);
46
		assertEquals(trail[0], 0);
47
	}
48
	
49
	public void testNextOffset() {
50
		offsetPoint = new Point(129, 0);
51
		offset = sentence.getNextOffset(offsetPoint, true, null);
52
		assertEquals(offset, 72);
53
		assertEquals(trail[0], 0);
54
		
55
		offsetPoint = new Point(77, 18);
56
		offset = sentence.getNextOffset(offsetPoint, false, null);
57
		assertEquals(offset, 14);
58
		assertEquals(trail[0], 0);
59
	}
60
	
61
	public void testCaretPlacement() {
62
		offsetPoint = new Point(11, 21);
63
		offset = sentence.getOffset(offsetPoint, trail, null);
64
		CaretInfo info = sentence.getCaretPlacement(offset, trail[0] != 0);
65
		assertEquals(info.getBaseline(), 24);
66
		assertEquals(info.getHeight(), 13);
67
		assertEquals(info.getLineHeight(), 13);
68
		assertEquals(info.getLineY(), 13);
69
		assertEquals(info.getX(), 12);
70
		assertEquals(info.getY(), 13);
71
	}
19
}
72
}

Return to bug 88678