File: getAWTKeyStroke.java

package info (click to toggle)
mauve 20161030-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 44,628 kB
  • ctags: 35,425
  • sloc: java: 336,555; sh: 2,834; xml: 208; makefile: 72
file content (158 lines) | stat: -rw-r--r-- 5,661 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Tags: JDK1.4

// Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com)

// This file is part of Mauve.

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.java.awt.AWTKeyStroke;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

import java.awt.AWTKeyStroke;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

/**
 * Some checks for the getAWTKeyStroke() methods.
 */
public class getAWTKeyStroke
  implements Testlet
{
  /**
   * Confirm that two lines with the same end points are NOT considered equal.
   */
  public void test(TestHarness harness)
  {
    testMethod1(harness);
    testMethod2(harness);
    testMethod3(harness);
    testMethod4(harness);
    testMethod5(harness);
  }
  
  private void testMethod1(TestHarness harness) 
  {
    harness.checkPoint("(char)");    
    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke('s');
    harness.check(ks.getKeyEventType(), KeyEvent.KEY_TYPED);
    harness.check(ks.getKeyChar(), 's');
    harness.check(ks.getModifiers(), 0);
    harness.check(ks.isOnKeyRelease(), false);
  }

  private void testMethod2(TestHarness harness) 
  {
    harness.checkPoint("(Character, int)");    
    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke(new Character('s'), InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
    harness.check(ks.getKeyEventType(), KeyEvent.KEY_TYPED);
    harness.check(ks.getKeyChar(), 's');
    harness.check(ks.getModifiers(), InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK);
    harness.check(ks.isOnKeyRelease(), false);

    // check for IllegalArgumentException for null argument
    try
    {
      ks = AWTKeyStroke.getAWTKeyStroke(null, 0);
      harness.check(false);
    }
    catch (IllegalArgumentException e) 
    {
      harness.check(true);
    }
  }

  private void testMethod3(TestHarness harness) 
  {
    harness.checkPoint("(int, int)");    
    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
    harness.check(ks.getKeyEventType(), KeyEvent.KEY_PRESSED);
    harness.check(ks.getKeyChar(), KeyEvent.CHAR_UNDEFINED);
    harness.check(ks.getModifiers(), InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK);
    harness.check(ks.isOnKeyRelease(), false);
  }

  private void testMethod4(TestHarness harness) 
  {
    harness.checkPoint("(int, int, boolean)");    
    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true);
    harness.check(ks.getKeyEventType(), KeyEvent.KEY_RELEASED);
    harness.check(ks.getKeyChar(), KeyEvent.CHAR_UNDEFINED);
    harness.check(ks.getModifiers(), InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK);
    harness.check(ks.isOnKeyRelease(), true);
  }

  private void testMethod5(TestHarness harness) 
  {
    harness.checkPoint("(String)");    
    
    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke("INSERT");
    AWTKeyStroke expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_INSERT, 0);
    harness.check(ks, expected);
    
    ks = AWTKeyStroke.getAWTKeyStroke("control DELETE");
    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_DOWN_MASK);
    harness.check(ks, expected);
    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK);
    harness.check(ks, expected);

    ks = AWTKeyStroke.getAWTKeyStroke("alt shift X");
    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
    harness.check(ks, expected);
    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK);
    harness.check(ks, expected);
  
    ks = AWTKeyStroke.getAWTKeyStroke("alt shift released X");
    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true);
    harness.check(ks, expected);
    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true);
    harness.check(ks, expected);
    
    ks = AWTKeyStroke.getAWTKeyStroke("typed a");
    expected = AWTKeyStroke.getAWTKeyStroke('a');
    harness.check(ks, expected);
    
    // check for IllegalArgumentException for null argument
    harness.checkPoint("null (String) argument");
    try
    {
      ks = AWTKeyStroke.getAWTKeyStroke(null);
      harness.check(false);
    }
    catch (IllegalArgumentException e) 
    {
      harness.check(true);
    }
    catch (Throwable e)
    {
      harness.check(false);
    }
    
    // check for IllegalArgumentException for bad string
    harness.checkPoint("bad string");
    try
    {
      ks = AWTKeyStroke.getAWTKeyStroke("bad");
      harness.check(false);
    }
    catch (IllegalArgumentException e) 
    {
      harness.check(true);
    }
  }
}