1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.layout.gle2; 18 19 import org.eclipse.swt.events.MouseEvent; 20 21 public class ControlPointTest extends PointTestCases { 22 public void testCreateFromMouseEvent() throws Exception { 23 MouseEvent mouseEvent = canvasMouseEvent(10, 20, 0); 24 25 ControlPoint point = ControlPoint.create(mCanvas, mouseEvent); 26 assertEquals(10, point.x); 27 assertEquals(20, point.y); 28 } 29 30 public void testCreateFromCoordinates() throws Exception { 31 ControlPoint point = ControlPoint.create(mCanvas, 10, 20); 32 assertEquals(10, point.x); 33 assertEquals(20, point.y); 34 } 35 36 public void testConvertToLayout() throws Exception { 37 ControlPoint point = ControlPoint.create(new TestLayoutCanvas(), 10, 20); 38 assertEquals(10, point.x); 39 assertEquals(20, point.y); 40 41 LayoutPoint layoutPoint = point.toLayout(); 42 assertNotNull(layoutPoint); 43 assertEquals(40, layoutPoint.x); 44 assertEquals(60, layoutPoint.y); 45 46 // For sanity let's also convert back and verify 47 ControlPoint controlPoint = layoutPoint.toControl(); 48 assertNotNull(controlPoint); 49 assertNotSame(controlPoint, point); 50 assertEquals(point, controlPoint); 51 assertEquals(10, controlPoint.x); 52 assertEquals(20, controlPoint.y); 53 } 54 55 public void testEquals() throws Exception { 56 ControlPoint point1 = ControlPoint.create(mCanvas, 1, 1); 57 ControlPoint point2 = ControlPoint.create(mCanvas, 1, 2); 58 ControlPoint point3 = ControlPoint.create(mCanvas, 2, 1); 59 ControlPoint point2b = ControlPoint.create(mCanvas, 1, 2); 60 61 assertFalse(point2.equals(null)); 62 63 assertEquals(point2, point2); 64 assertEquals(point2, point2b); 65 assertEquals(point2.hashCode(), point2b.hashCode()); 66 assertNotSame(point2, point2b); 67 68 assertFalse(point1.equals(point2)); 69 assertFalse(point1.equals(point3)); 70 assertFalse(point2.equals(point3)); 71 assertFalse(point1.equals(point2)); 72 } 73 } 74