a9ddfbb0aa4bedb23d192078064462b1615c6d0f
[jalview.git] / test / jalview / util / PlatformTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.util;
22
23 import static org.testng.Assert.assertFalse;
24 import static org.testng.Assert.assertTrue;
25
26 import jalview.bin.Jalview;
27 import jalview.gui.JvOptionPane;
28
29 import java.awt.Button;
30 import java.awt.Event;
31 import java.awt.Toolkit;
32 import java.awt.event.MouseEvent;
33
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
36
37 public class PlatformTest
38 {
39
40   @BeforeClass(alwaysRun = true)
41   public void setUpJvOptionPane()
42   {
43     JvOptionPane.setInteractiveMode(false);
44     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45   }
46
47   Button b = new Button();
48
49   /**
50    * isControlDown for Mac should answer true for Meta-down, but not for right
51    * mouse (popup trigger)
52    */
53   @Test(groups = "Functional")
54   public void testIsControlDown_mac()
55   {
56     int clickCount = 1;
57     boolean isPopupTrigger = false;
58     int buttonNo = MouseEvent.BUTTON1;
59     boolean mac = true;
60
61     assertFalse(Jalview.isHeadlessMode());
62     Toolkit toolkit = Toolkit.getDefaultToolkit();
63     System.err.println("Toolkit is " + toolkit.getClass().getName());
64     System.err.println("getMenuShortcutKeyMask is "
65             + toolkit.getMenuShortcutKeyMask());
66
67     int mods = 0;
68     // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
69     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
70             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
71
72     mods = Event.CTRL_MASK;
73     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
74             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
75
76     mods = Event.META_MASK;
77     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
78             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
79
80     isPopupTrigger = true;
81     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
82             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
83
84     isPopupTrigger = false;
85     buttonNo = MouseEvent.BUTTON2;
86     mods = 0;
87     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
88             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
89   }
90
91   /**
92    * If not a Mac, we only care whether CTRL_MASK modifier is set on the mouse
93    * event
94    */
95   @Test(groups = "Functional")
96   public void testIsControlDown_notMac()
97   {
98     int clickCount = 1;
99     boolean isPopupTrigger = false;
100     int buttonNo = MouseEvent.BUTTON1;
101     boolean mac = false;
102
103     int mods = 0;
104     // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
105     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
106             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
107
108     mods = Event.CTRL_MASK;
109     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
110             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
111
112     mods = Event.CTRL_MASK | Event.SHIFT_MASK | Event.ALT_MASK;
113     clickCount = 2;
114     buttonNo = 2;
115     isPopupTrigger = true;
116     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
117             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
118   }
119 }