JAL-3368 removed parsing web colours (now on a separate branch)
[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.gui.JvOptionPane;
27
28 import java.awt.Button;
29 import java.awt.Event;
30 import java.awt.Toolkit;
31 import java.awt.event.MouseEvent;
32
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.Test;
35
36 public class PlatformTest
37 {
38
39   @BeforeClass(alwaysRun = true)
40   public void setUpJvOptionPane()
41   {
42     JvOptionPane.setInteractiveMode(false);
43     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
44   }
45
46   Button b = new Button();
47
48   /**
49    * isControlDown for Mac should answer true for Meta-down, but not for right
50    * mouse (popup trigger)
51    */
52   @Test(groups = "Functional")
53   public void testIsControlDown_mac()
54   {
55     String toolkit = Toolkit.getDefaultToolkit().getClass().getName();
56     if (toolkit.endsWith("XToolkit") || toolkit.endsWith("WToolkit"))
57     {
58       /*
59        * this toolkit on the build server fails these tests,
60        * because it returns 2, not 4, for getMenuShortcutKeyMask
61        * 
62        * Same for windows, because the Platform test "mac" must match the 
63        * actual platform that is running the test. 
64        * 
65        * 
66        */
67       return;
68     }
69
70     int clickCount = 1;
71     boolean isPopupTrigger = false;
72     int buttonNo = MouseEvent.BUTTON1;
73     boolean mac = true;
74
75     int mods = 0;
76     // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
77     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
78             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
79
80     mods = Event.CTRL_MASK;
81     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
82             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
83
84     mods = Event.META_MASK;
85     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
86             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
87
88     isPopupTrigger = true;
89     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
90             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
91
92     isPopupTrigger = false;
93     buttonNo = MouseEvent.BUTTON2;
94     mods = 0;
95     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
96             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
97   }
98
99   /**
100    * If not a Mac, we only care whether CTRL_MASK modifier is set on the mouse
101    * event
102    */
103   @Test(groups = "Functional")
104   public void testIsControlDown_notMac()
105   {
106     int clickCount = 1;
107     boolean isPopupTrigger = false;
108     int buttonNo = MouseEvent.BUTTON1;
109     boolean mac = false;
110
111     int mods = 0;
112     // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
113     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
114             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
115
116     mods = Event.CTRL_MASK;
117     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
118             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
119
120     mods = Event.CTRL_MASK | Event.SHIFT_MASK | Event.ALT_MASK;
121     clickCount = 2;
122     buttonNo = 2;
123     isPopupTrigger = true;
124     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
125             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
126   }
127 }