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.SWT; 20 import org.eclipse.swt.events.MouseEvent; 21 import org.eclipse.swt.widgets.Event; 22 import org.eclipse.swt.widgets.List; 23 import org.eclipse.swt.widgets.ScrollBar; 24 import org.eclipse.swt.widgets.Shell; 25 26 import junit.framework.TestCase; 27 28 /** 29 * Common utilities for the point tests {@link LayoutPointTest} and 30 * {@link ControlPointTest} 31 */ 32 public class PointTestCases extends TestCase { 33 LayoutCanvas mCanvas = new TestLayoutCanvas(); 34 canvasMouseEvent(int x, int y, int stateMask)35 protected MouseEvent canvasMouseEvent(int x, int y, int stateMask) { 36 Event event = new Event(); 37 event.x = x; 38 event.y = y; 39 event.stateMask = stateMask; 40 event.widget = mCanvas; 41 MouseEvent mouseEvent = new MouseEvent(event); 42 return mouseEvent; 43 } 44 45 /** Mock implementation of LayoutCanvas */ 46 protected static class TestLayoutCanvas extends LayoutCanvas { 47 float mScaleX; 48 49 float mScaleY; 50 51 float mTranslateX; 52 53 float mTranslateY; 54 TestLayoutCanvas(float scaleX, float scaleY, float translateX, float translateY)55 public TestLayoutCanvas(float scaleX, float scaleY, float translateX, float translateY) { 56 super(null, null, new Shell(), 0); 57 58 this.mScaleX = scaleX; 59 this.mScaleY = scaleY; 60 this.mTranslateX = translateX; 61 this.mTranslateY = translateY; 62 } 63 TestLayoutCanvas()64 public TestLayoutCanvas() { 65 this(2.0f, 2.0f, 20.0f, 20.0f); 66 } 67 68 @Override getHorizontalTransform()69 CanvasTransform getHorizontalTransform() { 70 ScrollBar scrollBar = new List(this, SWT.V_SCROLL|SWT.H_SCROLL).getHorizontalBar(); 71 return new TestCanvasTransform(scrollBar, mScaleX, mTranslateX); 72 } 73 74 @Override getVerticalTransform()75 CanvasTransform getVerticalTransform() { 76 ScrollBar scrollBar = new List(this, SWT.V_SCROLL|SWT.H_SCROLL).getVerticalBar(); 77 return new TestCanvasTransform(scrollBar, mScaleY, mTranslateY); 78 } 79 } 80 81 static class TestCanvasTransform extends CanvasTransform { 82 float mScale; 83 84 float mTranslate; 85 TestCanvasTransform(ScrollBar scrollBar, float scale, float translate)86 public TestCanvasTransform(ScrollBar scrollBar, float scale, float translate) { 87 super(null, scrollBar); 88 this.mScale = scale; 89 this.mTranslate = translate; 90 } 91 92 @Override translate(int value)93 public int translate(int value) { 94 return (int) ((value - mTranslate) / mScale); 95 } 96 97 @Override inverseTranslate(int value)98 public int inverseTranslate(int value) { 99 return (int) (value * mScale + mTranslate); 100 } 101 } 102 testDummy()103 public void testDummy() { 104 // To avoid JUnit warning that this class contains no tests, even though 105 // this is an abstract class and JUnit shouldn't try 106 } 107 } 108