|
| 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 PopupMenuTest extends TestCase { |
| 25 | + |
| 26 | + /* |
| 27 | + * Test popup for the normal condition |
| 28 | + */ |
| 29 | + public void testMenuPopupNormal() { |
| 30 | + Rectangle rect = new Rectangle(10, 10, 0, 0); |
| 31 | + Rectangle bounds = new Rectangle(0, 0, 640, 480); |
| 32 | + int width = 200; |
| 33 | + int height = 40; |
| 34 | + Rectangle pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 35 | + assertEquals(pos, new Rectangle(10, 10, 200, 40)); |
| 36 | + } |
| 37 | + |
| 38 | + /* |
| 39 | + * Test popup when it's necessary to popup above the given |
| 40 | + * rectangle. |
| 41 | + */ |
| 42 | + public void testMenuPopupAboveOrBefore() { |
| 43 | + Rectangle rect = new Rectangle(10, 420, 0, 0); |
| 44 | + Rectangle bounds = new Rectangle(0, 0, 640, 480); |
| 45 | + int width = 200; |
| 46 | + int height = 60; |
| 47 | + Rectangle pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 48 | + assertEquals(pos, new Rectangle(10, 420, 200, 60)); |
| 49 | + |
| 50 | + rect = new Rectangle(10, 421, 0, 0); |
| 51 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 52 | + height = 60; |
| 53 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 54 | + assertEquals(pos, new Rectangle(10, 361, 200, 60)); |
| 55 | + |
| 56 | + rect = new Rectangle(440, 420, 0, 0); |
| 57 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 58 | + height = 60; |
| 59 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 60 | + assertEquals(pos, new Rectangle(440, 420, 200, 60)); |
| 61 | + |
| 62 | + rect = new Rectangle(441, 420, 0, 0); |
| 63 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 64 | + height = 60; |
| 65 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 66 | + assertEquals(pos, new Rectangle(241, 420, 200, 60)); |
| 67 | + |
| 68 | + rect = new Rectangle(441, 421, 0, 0); |
| 69 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 70 | + height = 60; |
| 71 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 72 | + assertEquals(pos, new Rectangle(241, 361, 200, 60)); |
| 73 | + } |
| 74 | + |
| 75 | + /* |
| 76 | + * Test popup when it's necessary to popup override the given |
| 77 | + * rectangle. |
| 78 | + */ |
| 79 | + public void testMenuPopupOver() { |
| 80 | + Rectangle rect = new Rectangle(10, 300, 0, 0); |
| 81 | + Rectangle bounds = new Rectangle(0, 0, 480, 640); |
| 82 | + int width = 200; |
| 83 | + int height = 340; |
| 84 | + Rectangle pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 85 | + assertEquals(pos, new Rectangle(10, 300, 200, 340)); |
| 86 | + |
| 87 | + rect = new Rectangle(10, 300, 0, 0); |
| 88 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 89 | + height = 360; |
| 90 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 91 | + assertEquals(pos, new Rectangle(10, 280, 200, 360)); |
| 92 | + |
| 93 | + rect = new Rectangle(10, 300, 0, 0); |
| 94 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 95 | + height = 640; |
| 96 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 97 | + assertEquals(pos, new Rectangle(10, 0, 200, 640)); |
| 98 | + |
| 99 | + rect = new Rectangle(10, 300, 0, 0); |
| 100 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 101 | + height = 650; |
| 102 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 103 | + assertEquals(pos, new Rectangle(10, 0, 200, 640)); |
| 104 | + |
| 105 | + // x |
| 106 | + rect = new Rectangle(280, 300, 0, 0); |
| 107 | + bounds = new Rectangle(0, 0, 480, 640); |
| 108 | + width = 200; |
| 109 | + height = 340; |
| 110 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 111 | + assertEquals(pos, new Rectangle(280, 300, 200, 340)); |
| 112 | + |
| 113 | + rect = new Rectangle(120, 300, 0, 0); |
| 114 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 115 | + width = 380; |
| 116 | + height = 360; |
| 117 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 118 | + assertEquals(pos, new Rectangle(100, 280, 380, 360)); |
| 119 | + |
| 120 | + rect = new Rectangle(10, 300, 0, 0); |
| 121 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 122 | + width = 480; |
| 123 | + height = 640; |
| 124 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 125 | + assertEquals(pos, new Rectangle(0, 0, 480, 640)); |
| 126 | + |
| 127 | + rect = new Rectangle(10, 300, 0, 0); |
| 128 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 129 | + width = 500; |
| 130 | + height = 650; |
| 131 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 132 | + assertEquals(pos, new Rectangle(0, 0, 480, 640)); |
| 133 | + } |
| 134 | + |
| 135 | + public void testMenuPopupUpOrDown() { |
| 136 | + Rectangle rect = new Rectangle(10, 300, 0, 0); |
| 137 | + Rectangle bounds = new Rectangle(0, 0, 480, 640); |
| 138 | + int width = 200; |
| 139 | + int height = 0; |
| 140 | + Rectangle pos = null; |
| 141 | + |
| 142 | + rect = new Rectangle(10, 300, 0, 0); |
| 143 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 144 | + height = 440; |
| 145 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 146 | + assertEquals(pos, new Rectangle(10, 200, 200, 440)); |
| 147 | + |
| 148 | + rect = new Rectangle(10, 360, 0, 0); |
| 149 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 150 | + height = 440; |
| 151 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 152 | + assertEquals(pos, new Rectangle(10, 0, 200, 440)); |
| 153 | + |
| 154 | + rect = new Rectangle(10, 320, 0, 0); |
| 155 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 156 | + height = 440; |
| 157 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 158 | + assertEquals(pos, new Rectangle(10, 200, 200, 440)); |
| 159 | + |
| 160 | + rect = new Rectangle(10, 321, 0, 0); |
| 161 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 162 | + height = 440; |
| 163 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 164 | + assertEquals(pos, new Rectangle(10, 0, 200, 440)); |
| 165 | + |
| 166 | + rect = new Rectangle(10, 319, 0, 0); |
| 167 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 168 | + height = 440; |
| 169 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 170 | + assertEquals(pos, new Rectangle(10, 200, 200, 440)); |
| 171 | + |
| 172 | + // x |
| 173 | + rect = new Rectangle(200, 300, 0, 0); |
| 174 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 175 | + width = 360; |
| 176 | + height = 440; |
| 177 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 178 | + assertEquals(pos, new Rectangle(120, 200, 360, 440)); |
| 179 | + |
| 180 | + rect = new Rectangle(280, 360, 0, 0); |
| 181 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 182 | + height = 440; |
| 183 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 184 | + assertEquals(pos, new Rectangle(0, 0, 360, 440)); |
| 185 | + |
| 186 | + rect = new Rectangle(240, 320, 0, 0); |
| 187 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 188 | + height = 440; |
| 189 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 190 | + assertEquals(pos, new Rectangle(120, 200, 360, 440)); |
| 191 | + |
| 192 | + rect = new Rectangle(241, 321, 0, 0); |
| 193 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 194 | + height = 440; |
| 195 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 196 | + assertEquals(pos, new Rectangle(0, 0, 360, 440)); |
| 197 | + |
| 198 | + rect = new Rectangle(239, 319, 0, 0); |
| 199 | + //bounds = new Rectangle(0, 0, 640, 480); |
| 200 | + height = 440; |
| 201 | + pos = Popup.popupMenu(bounds, rect, width, height, 0); |
| 202 | + assertEquals(pos, new Rectangle(120, 200, 360, 440)); |
| 203 | + |
| 204 | + } |
| 205 | +} |
0 commit comments