Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 17:27:16 GMT
  2. Package jalview.util

File PlatformTest.java

 

Code metrics

2
43
5
1
145
91
6
0.14
8.6
5
1.2

Classes

Class Line # Actions
PlatformTest 38 43 6
0.6666%
 

Contributing tests

This file is covered by 4 tests. .

Source view

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.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertNull;
26    import static org.testng.Assert.assertTrue;
27   
28    import jalview.gui.JvOptionPane;
29   
30    import java.awt.Button;
31    import java.awt.Toolkit;
32    import java.awt.event.InputEvent;
33    import java.awt.event.MouseEvent;
34   
35    import org.testng.annotations.BeforeClass;
36    import org.testng.annotations.Test;
37   
 
38    public class PlatformTest
39    {
40   
 
41  1 toggle @BeforeClass(alwaysRun = true)
42    public void setUpJvOptionPane()
43    {
44  1 JvOptionPane.setInteractiveMode(false);
45  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
46    }
47   
48    Button b = new Button();
49   
50    /**
51    * isControlDown for Mac should answer true for Meta-down, but not for right
52    * mouse (popup trigger)
53    */
 
54  1 toggle @Test(groups = "Functional")
55    public void testIsControlDown_mac()
56    {
57  1 String toolkit = Toolkit.getDefaultToolkit().getClass().getName();
58  1 if ("sun.awt.X11.XToolkit".equals(toolkit))
59    {
60    /*
61    * this toolkit on the build server fails these tests,
62    * because it returns 2, not 4, for getMenuShortcutKeyMask
63    */
64  1 return;
65    }
66   
67  0 int clickCount = 1;
68  0 boolean isPopupTrigger = false;
69  0 int buttonNo = MouseEvent.BUTTON1;
70  0 boolean mac = true;
71   
72  0 int mods = 0;
73    // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
74  0 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
75    0, 0, clickCount, isPopupTrigger, buttonNo), mac));
76   
77  0 mods = InputEvent.CTRL_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
78  0 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
79    0, 0, clickCount, isPopupTrigger, buttonNo), mac));
80   
81  0 mods = InputEvent.META_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
82  0 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
83    0, 0, clickCount, isPopupTrigger, buttonNo), mac));
84   
85  0 isPopupTrigger = true;
86  0 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
87    0, 0, clickCount, isPopupTrigger, buttonNo), mac));
88   
89  0 isPopupTrigger = false;
90  0 buttonNo = MouseEvent.BUTTON2;
91  0 mods = 0;
92  0 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
93    0, 0, clickCount, isPopupTrigger, buttonNo), mac));
94    }
95   
96    /**
97    * If not a Mac, we only care whether CTRL_MASK modifier is set on the mouse
98    * event
99    */
 
100  1 toggle @Test(groups = "Functional")
101    public void testIsControlDown_notMac()
102    {
103  1 int clickCount = 1;
104  1 boolean isPopupTrigger = false;
105  1 int buttonNo = MouseEvent.BUTTON1;
106  1 boolean mac = false;
107   
108  1 int mods = 0;
109    // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
110  1 assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
111    0, 0, clickCount, isPopupTrigger, buttonNo), mac));
112   
113  1 mods = InputEvent.CTRL_DOWN_MASK;
114  1 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
115    0, 0, clickCount, isPopupTrigger, buttonNo), mac));
116   
117  1 mods = InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK
118    | InputEvent.ALT_DOWN_MASK;
119  1 clickCount = 2;
120  1 buttonNo = 2;
121  1 isPopupTrigger = true;
122  1 assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
123    0, 0, clickCount, isPopupTrigger, buttonNo), mac));
124    }
125   
 
126  1 toggle @Test(groups = "Functional")
127    public void testPathEquals()
128    {
129  1 assertTrue(Platform.pathEquals(null, null));
130  1 assertFalse(Platform.pathEquals(null, "apath"));
131  1 assertFalse(Platform.pathEquals("apath", null));
132  1 assertFalse(Platform.pathEquals("apath", "APATH"));
133  1 assertTrue(Platform.pathEquals("apath", "apath"));
134  1 assertTrue(Platform.pathEquals("apath/a/b", "apath\\a\\b"));
135    }
136   
 
137  1 toggle @Test(groups = "Functional")
138    public void testEscapeBackslashes()
139    {
140  1 assertNull(Platform.escapeBackslashes(null));
141  1 assertEquals(Platform.escapeBackslashes("hello world"), "hello world");
142  1 assertEquals(Platform.escapeBackslashes("hello\\world"),
143    "hello\\\\world");
144    }
145    }