Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.util

File PlatformTest.java

 

Code metrics

2
49
6
1
159
104
7
0.14
8.17
6
1.17

Classes

Class Line # Actions
PlatformTest 39 49 7
0.701754470.2%
 

Contributing tests

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