|
| 1 | +/******************************************************************************* |
| 2 | + * Java2Script Pacemaker (http://j2s.sourceforge.net) |
| 3 | + * |
| 4 | + * Copyright (c) 2006 ognize.com and others. |
| 5 | + * All rights reserved. This program and the accompanying materials |
| 6 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 7 | + * which accompanies this distribution, and is available at |
| 8 | + * http://www.eclipse.org/legal/epl-v10.html |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * ognize.com - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | + |
| 14 | +package net.sf.j2s.test.swt.os; |
| 15 | + |
| 16 | +import org.eclipse.swt.graphics.Rectangle; |
| 17 | +import junit.framework.TestCase; |
| 18 | + |
| 19 | +/** |
| 20 | + * @author josson smith |
| 21 | + * |
| 22 | + * 2006-9-12 |
| 23 | + */ |
| 24 | +public class PopupTest extends TestCase { |
| 25 | + |
| 26 | + /* |
| 27 | + * Test popup for the normal condition |
| 28 | + */ |
| 29 | + public void testComboPopupNormal() { |
| 30 | + Rectangle rect = new Rectangle(10, 10, 200, 20); |
| 31 | + Rectangle bounds = new Rectangle(0, 0, 640, 480); |
| 32 | + int height = 40; |
| 33 | + Rectangle pos = Popup.popupList(bounds, rect, height); |
| 34 | + assertEquals(pos, new Rectangle(10, 30, 200, 40)); |
| 35 | + } |
| 36 | + |
| 37 | + /* |
| 38 | + * Test popup when it's necessary to popup above the given |
| 39 | + * rectangle. |
| 40 | + */ |
| 41 | + public void testComboPopupAbove() { |
| 42 | + Rectangle rect = new Rectangle(10, 420, 200, 20); |
| 43 | + Rectangle bounds = new Rectangle(0, 0, 640, 480); |
| 44 | + int height = 40; |
| 45 | + Rectangle pos = Popup.popupList(bounds, rect, height); |
| 46 | + assertEquals(pos, new Rectangle(10, 440, 200, 40)); |
| 47 | + |
| 48 | + rect = new Rectangle(10, 421, 200, 20); |
| 49 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 50 | + height = 40; |
| 51 | + pos = Popup.popupList(bounds, rect, height); |
| 52 | + assertEquals(pos, new Rectangle(10, 381, 200, 40)); |
| 53 | + } |
| 54 | + |
| 55 | + /* |
| 56 | + * Test popup when it's necessary to popup override the given |
| 57 | + * rectangle. |
| 58 | + */ |
| 59 | + public void testComboPopupOver() { |
| 60 | + Rectangle rect = new Rectangle(10, 300, 200, 20); |
| 61 | + Rectangle bounds = new Rectangle(0, 0, 480, 640); |
| 62 | + int height = 320; |
| 63 | + Rectangle pos = Popup.popupList(bounds, rect, height); |
| 64 | + assertEquals(pos, new Rectangle(10, 320, 200, 320)); |
| 65 | + |
| 66 | + rect = new Rectangle(10, 300, 200, 20); |
| 67 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 68 | + height = 340; |
| 69 | + pos = Popup.popupList(bounds, rect, height); |
| 70 | + assertEquals(pos, new Rectangle(10, 300, 200, 340)); |
| 71 | + |
| 72 | + rect = new Rectangle(10, 300, 200, 20); |
| 73 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 74 | + height = 640; |
| 75 | + pos = Popup.popupList(bounds, rect, height); |
| 76 | + assertEquals(pos, new Rectangle(10, 0, 200, 640)); |
| 77 | + |
| 78 | + rect = new Rectangle(10, 300, 200, 20); |
| 79 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 80 | + height = 650; |
| 81 | + pos = Popup.popupList(bounds, rect, height); |
| 82 | + assertEquals(pos, new Rectangle(10, 0, 200, 640)); |
| 83 | + } |
| 84 | + |
| 85 | + public void testComboPopupUpOrDown() { |
| 86 | + Rectangle rect = new Rectangle(10, 300, 200, 20); |
| 87 | + Rectangle bounds = new Rectangle(0, 0, 480, 640); |
| 88 | + int height = 0; |
| 89 | + Rectangle pos = null; |
| 90 | + |
| 91 | + rect = new Rectangle(10, 300, 200, 20); |
| 92 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 93 | + height = 440; |
| 94 | + pos = Popup.popupList(bounds, rect, height); |
| 95 | + assertEquals(pos, new Rectangle(10, 200, 200, 440)); |
| 96 | + |
| 97 | + rect = new Rectangle(10, 360, 200, 20); |
| 98 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 99 | + height = 440; |
| 100 | + pos = Popup.popupList(bounds, rect, height); |
| 101 | + assertEquals(pos, new Rectangle(10, 0, 200, 440)); |
| 102 | + |
| 103 | + rect = new Rectangle(10, 310, 200, 20); |
| 104 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 105 | + height = 440; |
| 106 | + pos = Popup.popupList(bounds, rect, height); |
| 107 | + assertEquals(pos, new Rectangle(10, 200, 200, 440)); |
| 108 | + |
| 109 | + rect = new Rectangle(10, 311, 200, 20); |
| 110 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 111 | + height = 440; |
| 112 | + pos = Popup.popupList(bounds, rect, height); |
| 113 | + assertEquals(pos, new Rectangle(10, 0, 200, 440)); |
| 114 | + |
| 115 | + rect = new Rectangle(10, 309, 200, 20); |
| 116 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 117 | + height = 440; |
| 118 | + pos = Popup.popupList(bounds, rect, height); |
| 119 | + assertEquals(pos, new Rectangle(10, 200, 200, 440)); |
| 120 | + } |
| 121 | +} |
0 commit comments