JAL-2325 apply license to new source files
[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 java.awt.Button;
27 import java.awt.Event;
28 import java.awt.event.MouseEvent;
29
30 import org.testng.annotations.Test;
31
32 public class PlatformTest
33 {
34   Button b = new Button();
35
36   /**
37    * isControlDown for Mac should answer true for Meta-down, but not for right
38    * mouse (popup trigger)
39    */
40   @Test(groups = "Functional")
41   public void testIsControlDown_mac()
42   {
43     int clickCount = 1;
44     boolean isPopupTrigger = false;
45     int buttonNo = MouseEvent.BUTTON1;
46     boolean mac = true;
47
48     int mods = 0;
49     // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
50     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
51             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
52
53     mods = Event.CTRL_MASK;
54     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
55             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
56
57     mods = Event.META_MASK;
58     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
59             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
60
61     isPopupTrigger = true;
62     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
63             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
64
65     isPopupTrigger = false;
66     buttonNo = MouseEvent.BUTTON2;
67     mods = 0;
68     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
69             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
70   }
71
72   /**
73    * If not a Mac, we only care whether CTRL_MASK modifier is set on the mouse
74    * event
75    */
76   @Test(groups = "Functional")
77   public void testIsControlDown_notMac()
78   {
79     int clickCount = 1;
80     boolean isPopupTrigger = false;
81     int buttonNo = MouseEvent.BUTTON1;
82     boolean mac = false;
83
84     int mods = 0;
85     // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
86     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
87             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
88
89     mods = Event.CTRL_MASK;
90     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
91             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
92
93     mods = Event.CTRL_MASK | Event.SHIFT_MASK | Event.ALT_MASK;
94     clickCount = 2;
95     buttonNo = 2;
96     isPopupTrigger = true;
97     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
98             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
99   }
100 }