Skip to main content
summaryrefslogtreecommitdiffstats
blob: cf0a17a7a039902e7f4d581c6daab4a17f68c657 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*****************************************************************************
 * Copyright (c) 2009 Atos Origin.
 *
 *    
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Atos Origin - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.canonical;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.LifelineXYLayoutEditPolicy;
import org.junit.Test;

public class LifelineXYLayoutEditPolicyTest {

	@Test
	public void testAdaptSizeDeltaToMaxHeight() {
		Figure figure = new Figure();
		figure.setBounds(new Rectangle(1, 2, 10, 20));
		figure.setMaximumSize(new Dimension(100, 200));
		figure.setMinimumSize(new Dimension(0, 30));

		Dimension sizeDelta = new Dimension(30, 40);
		Dimension newSizeDelta = LifelineXYLayoutEditPolicy.adaptSizeDeltaToMaxHeight(figure, sizeDelta);
		assertFalse("Original dimension modified", sizeDelta == newSizeDelta);
		assertEquals("Width can't change", 30, newSizeDelta.width);
		assertEquals("Height change", 40, newSizeDelta.height);

		sizeDelta = new Dimension(30, 190);
		newSizeDelta = LifelineXYLayoutEditPolicy.adaptSizeDeltaToMaxHeight(figure, sizeDelta);
		assertFalse("Original dimension modified", sizeDelta == newSizeDelta);
		assertEquals("Width can't change", 30, newSizeDelta.width);
		assertEquals("Height don't change", 180, newSizeDelta.height);

		sizeDelta = new Dimension(30, 0);
		newSizeDelta = LifelineXYLayoutEditPolicy.adaptSizeDeltaToMaxHeight(figure, sizeDelta);
		assertFalse("Original dimension modified", sizeDelta == newSizeDelta);
		assertEquals("Width can't change", 30, newSizeDelta.width);
		assertEquals("Height don't change", 10, newSizeDelta.height);
	}

	@Test
	public void testIsAffixedToRight() {
		Rectangle leftFigure = new Rectangle(10, 10, 10, 10);
		Rectangle rightFigure = new Rectangle(15, 15, 10, 10);
		assertTrue("Left figure is not on the left of the right figure", LifelineXYLayoutEditPolicy.isAffixedToRight(leftFigure, rightFigure));
		assertFalse("Right figure is on the left of the left figure", LifelineXYLayoutEditPolicy.isAffixedToRight(rightFigure, leftFigure));
	}

	@Test
	public void testGetRealMoveDelta() {
		Rectangle oldRelativeBounds = new Rectangle(10, 10, 10, 10);
		Rectangle newRelativeBounds = new Rectangle(15, 20, 25, 30);
		Rectangle absoluteBounds = LifelineXYLayoutEditPolicy.getRealMoveDelta(oldRelativeBounds, newRelativeBounds);
		assertEquals("Wrong x", 5, absoluteBounds.x);
		assertEquals("Wrong y", 10, absoluteBounds.y);
		assertEquals("Wrong width", 15, absoluteBounds.width);
		assertEquals("Wrong height", 20, absoluteBounds.height);
	}

	@Test
	public void testGetRelativeBounds() {
		Figure parentFigure = new Figure();
		parentFigure.setBounds(new Rectangle(10, 20, 100, 100));

		Figure childFigure = new Figure();
		childFigure.setBounds(new Rectangle(20, 30, 50, 50));
		childFigure.setParent(parentFigure);

		Rectangle absoluteChild = LifelineXYLayoutEditPolicy.getRelativeBounds(childFigure);
		assertEquals("Wrong x", 10, absoluteChild.x);
		assertEquals("Wrong y", 10, absoluteChild.y);
		assertEquals("Wrong width", 50, absoluteChild.width);
		assertEquals("Wrong height", 50, absoluteChild.height);
	}

}

Back to the top