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