source: trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/temporalrelation/DefaultTextInputReductionRuleTest.java @ 445

Last change on this file since 445 was 445, checked in by pharms, 12 years ago

Initial import.

File size: 17.8 KB
Line 
1//-------------------------------------------------------------------------------------------------
2// Module    : $RCSfile: DefaultIterationDetectionRuleTest.java,v $
3// Version   : $Revision: 0.0 $  $Author: patrick $  $Date: 28.04.2012 $
4// Project   : TaskTreeTemporalRelationship
5// Creation  : 2012 by patrick
6// Copyright : Patrick Harms, 2012
7//-------------------------------------------------------------------------------------------------
8package de.ugoe.cs.quest.tasktrees.temporalrelation;
9
10import org.junit.Test;
11
12import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement;
13import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker;
14import de.ugoe.cs.tasktree.guimodel.GUIElement;
15import de.ugoe.cs.tasktree.guimodel.TextField;
16import de.ugoe.cs.tasktree.keyboardmaps.VirtualKey;
17import de.ugoe.cs.tasktree.userinteraction.KeyPressed;
18import de.ugoe.cs.tasktree.userinteraction.KeyReleased;
19
20//-------------------------------------------------------------------------------------------------
21/**
22 * TODO comment
23 *
24 * @version $Revision: $ $Date: 28.04.2012$
25 * @author 2012, last modified by $Author: patrick$
26 */
27//-------------------------------------------------------------------------------------------------
28public class DefaultTextInputReductionRuleTest extends AbstractTemporalRelationshipTC
29{
30
31  //-----------------------------------------------------------------------------------------------
32  /**
33   *
34   */
35  //-----------------------------------------------------------------------------------------------
36  @Test
37  public void testSimpleTextEntry()
38  {
39    GUIElement element1 = new DummyTextField("elem1");
40    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A));
41    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A));
42    new TaskTreeChecker(true).assertTaskMap
43      ("Sequence sequence0 {" +
44       "  TextInputInteraction TextInput a {" +
45       "    Interaction KeyPressed LETTER_A {}" +
46       "    Interaction KeyReleased LETTER_A {}" +
47       "  }" +
48       "}", getTaskTree().getTaskMap());   
49
50    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_B));
51    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_B));
52    new TaskTreeChecker().assertTaskMap
53      ("Sequence sequence0 {" +
54       "  TextInputInteraction TextInput ab {" +
55       "    Interaction KeyPressed LETTER_A {}" +
56       "    Interaction KeyReleased LETTER_A {}" +
57       "    Interaction KeyPressed LETTER_B {}" +
58       "    Interaction KeyReleased LETTER_B {}" +
59       "  }" +
60       "}", getTaskTree().getTaskMap());   
61
62    simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT));
63    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C));
64    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C));
65    simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT));
66    new TaskTreeChecker().assertTaskMap
67      ("Sequence sequence0 {" +
68       "  TextInputInteraction TextInput abC {" +
69       "    Interaction KeyPressed LETTER_A {}" +
70       "    Interaction KeyReleased LETTER_A {}" +
71       "    Interaction KeyPressed LETTER_B {}" +
72       "    Interaction KeyReleased LETTER_B {}" +
73       "    Interaction KeyPressed SHIFT {}" +
74       "    Interaction KeyPressed LETTER_C {}" +
75       "    Interaction KeyReleased LETTER_C {}" +
76       "    Interaction KeyReleased SHIFT {}" +
77       "  }" +
78       "}", getTaskTree().getTaskMap());   
79
80    simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT));
81    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_D));
82    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_D));
83    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_E));
84    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_E));
85    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_F));
86    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_F));
87    simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT));
88    new TaskTreeChecker().assertTaskMap
89      ("Sequence sequence0 {" +
90       "  TextInputInteraction TextInput abCDEF {" +
91       "    Interaction KeyPressed LETTER_A {}" +
92       "    Interaction KeyReleased LETTER_A {}" +
93       "    Interaction KeyPressed LETTER_B {}" +
94       "    Interaction KeyReleased LETTER_B {}" +
95       "    Interaction KeyPressed SHIFT {}" +
96       "    Interaction KeyPressed LETTER_C {}" +
97       "    Interaction KeyReleased LETTER_C {}" +
98       "    Interaction KeyReleased SHIFT {}" +
99       "    Interaction KeyPressed SHIFT {}" +
100       "    Interaction KeyPressed LETTER_D {}" +
101       "    Interaction KeyReleased LETTER_D {}" +
102       "    Interaction KeyPressed LETTER_E {}" +
103       "    Interaction KeyReleased LETTER_E {}" +
104       "    Interaction KeyPressed LETTER_F {}" +
105       "    Interaction KeyReleased LETTER_F {}" +
106       "    Interaction KeyReleased SHIFT {}" +
107       "  }" +
108       "}", getTaskTree().getTaskMap());   
109
110
111    simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT));
112    simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT));
113    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_G));
114    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_G));
115    simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT));
116    simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT));
117    new TaskTreeChecker().assertTaskMap
118      ("Sequence sequence0 {" +
119       "  TextInputInteraction TextInput abCDEFg {" +
120       "    Interaction KeyPressed LETTER_A {}" +
121       "    Interaction KeyReleased LETTER_A {}" +
122       "    Interaction KeyPressed LETTER_B {}" +
123       "    Interaction KeyReleased LETTER_B {}" +
124       "    Interaction KeyPressed SHIFT {}" +
125       "    Interaction KeyPressed LETTER_C {}" +
126       "    Interaction KeyReleased LETTER_C {}" +
127       "    Interaction KeyReleased SHIFT {}" +
128       "    Interaction KeyPressed SHIFT {}" +
129       "    Interaction KeyPressed LETTER_D {}" +
130       "    Interaction KeyReleased LETTER_D {}" +
131       "    Interaction KeyPressed LETTER_E {}" +
132       "    Interaction KeyReleased LETTER_E {}" +
133       "    Interaction KeyPressed LETTER_F {}" +
134       "    Interaction KeyReleased LETTER_F {}" +
135       "    Interaction KeyReleased SHIFT {}" +
136       "    Interaction KeyPressed SHIFT {}" +
137       "    Interaction KeyPressed SHIFT {}" +
138       "    Interaction KeyPressed LETTER_G {}" +
139       "    Interaction KeyReleased LETTER_G {}" +
140       "    Interaction KeyReleased SHIFT {}" +
141       "    Interaction KeyReleased SHIFT {}" +
142       "  }" +
143       "}", getTaskTree().getTaskMap());   
144
145  }
146 
147  //-----------------------------------------------------------------------------------------------
148  /**
149   *
150   */
151  //-----------------------------------------------------------------------------------------------
152  @Test
153  public void testTextEntryOnDifferentGuiElements()
154  {
155    GUIElement element1 = new DummyTextField("elem1");
156    GUIElement element2 = new DummyTextField("elem2");
157    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A));
158    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A));
159    new TaskTreeChecker().assertTaskMap
160      ("Sequence sequence0 {" +
161       "  TextInputInteraction TextInput a {" +
162       "    Interaction KeyPressed LETTER_A {}" +
163       "    Interaction KeyReleased LETTER_A {}" +
164       "  }" +
165       "}", getTaskTree().getTaskMap());   
166
167    simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_B));
168    simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_B));
169    new TaskTreeChecker().assertTaskMap
170      ("Sequence sequence0 {" +
171       "  Sequence sequence1 {" +
172       "    TextInputInteraction TextInput a {" +
173       "      Interaction KeyPressed LETTER_A {}" +
174       "      Interaction KeyReleased LETTER_A {}" +
175       "    }" +
176       "  }" +
177       "  Sequence sequence2 {" +
178       "    TextInputInteraction TextInput b {" +
179       "      Interaction KeyPressed LETTER_B {}" +
180       "      Interaction KeyReleased LETTER_B {}" +
181       "    }" +
182       "  }" +
183       "}", getTaskTree().getTaskMap());   
184
185    simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT));
186    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C));
187    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C));
188    simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT));
189    new TaskTreeChecker().assertTaskMap
190      ("Sequence sequence0 {" +
191       "  Sequence sequence1 {" +
192       "    TextInputInteraction TextInput a {" +
193       "      Interaction KeyPressed LETTER_A {}" +
194       "      Interaction KeyReleased LETTER_A {}" +
195       "    }" +
196       "  }" +
197       "  Sequence sequence2 {" +
198       "    TextInputInteraction TextInput b {" +
199       "      Interaction KeyPressed LETTER_B {}" +
200       "      Interaction KeyReleased LETTER_B {}" +
201       "    }" +
202       "  }" +
203       "  Sequence sequence3 {" +
204       "    TextInputInteraction TextInput C {" +
205       "      Interaction KeyPressed SHIFT {}" +
206       "      Interaction KeyPressed LETTER_C {}" +
207       "      Interaction KeyReleased LETTER_C {}" +
208       "      Interaction KeyReleased SHIFT {}" +
209       "    }" +
210       "  }" +
211       "}", getTaskTree().getTaskMap());   
212
213    simulateInteraction(element2, new KeyPressed(VirtualKey.SHIFT));
214    simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_D));
215    simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_D));
216    simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_E));
217    simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_E));
218    simulateInteraction(element2, new KeyPressed(VirtualKey.LETTER_F));
219    simulateInteraction(element2, new KeyReleased(VirtualKey.LETTER_F));
220    simulateInteraction(element2, new KeyReleased(VirtualKey.SHIFT));
221    new TaskTreeChecker().assertTaskMap
222      ("Sequence sequence0 {" +
223       "  Sequence sequence1 {" +
224       "    TextInputInteraction TextInput a {" +
225       "      Interaction KeyPressed LETTER_A {}" +
226       "      Interaction KeyReleased LETTER_A {}" +
227       "    }" +
228       "  }" +
229       "  Sequence sequence2 {" +
230       "    TextInputInteraction TextInput b {" +
231       "      Interaction KeyPressed LETTER_B {}" +
232       "      Interaction KeyReleased LETTER_B {}" +
233       "    }" +
234       "  }" +
235       "  Sequence sequence3 {" +
236       "    TextInputInteraction TextInput C {" +
237       "      Interaction KeyPressed SHIFT {}" +
238       "      Interaction KeyPressed LETTER_C {}" +
239       "      Interaction KeyReleased LETTER_C {}" +
240       "      Interaction KeyReleased SHIFT {}" +
241       "    }" +
242       "  }" +
243       "  Sequence sequence4 {" +
244       "    TextInputInteraction TextInput DEF {" +
245       "      Interaction KeyPressed SHIFT {}" +
246       "      Interaction KeyPressed LETTER_D {}" +
247       "      Interaction KeyReleased LETTER_D {}" +
248       "      Interaction KeyPressed LETTER_E {}" +
249       "      Interaction KeyReleased LETTER_E {}" +
250       "      Interaction KeyPressed LETTER_F {}" +
251       "      Interaction KeyReleased LETTER_F {}" +
252       "      Interaction KeyReleased SHIFT {}" +
253       "    }" +
254       "  }" +
255       "}", getTaskTree().getTaskMap());   
256
257
258    simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT));
259    simulateInteraction(element1, new KeyPressed(VirtualKey.SHIFT));
260    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_G));
261    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_G));
262    simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT));
263    simulateInteraction(element1, new KeyReleased(VirtualKey.SHIFT));
264    new TaskTreeChecker().assertTaskMap
265      ("Sequence sequence0 {" +
266       "  Sequence sequence1 {" +
267       "    TextInputInteraction TextInput a {" +
268       "      Interaction KeyPressed LETTER_A {}" +
269       "      Interaction KeyReleased LETTER_A {}" +
270       "    }" +
271       "  }" +
272       "  Sequence sequence2 {" +
273       "    TextInputInteraction TextInput b {" +
274       "      Interaction KeyPressed LETTER_B {}" +
275       "      Interaction KeyReleased LETTER_B {}" +
276       "    }" +
277       "  }" +
278       "  Sequence sequence3 {" +
279       "    TextInputInteraction TextInput C {" +
280       "      Interaction KeyPressed SHIFT {}" +
281       "      Interaction KeyPressed LETTER_C {}" +
282       "      Interaction KeyReleased LETTER_C {}" +
283       "      Interaction KeyReleased SHIFT {}" +
284       "    }" +
285       "  }" +
286       "  Sequence sequence4 {" +
287       "    TextInputInteraction TextInput DEF {" +
288       "      Interaction KeyPressed SHIFT {}" +
289       "      Interaction KeyPressed LETTER_D {}" +
290       "      Interaction KeyReleased LETTER_D {}" +
291       "      Interaction KeyPressed LETTER_E {}" +
292       "      Interaction KeyReleased LETTER_E {}" +
293       "      Interaction KeyPressed LETTER_F {}" +
294       "      Interaction KeyReleased LETTER_F {}" +
295       "      Interaction KeyReleased SHIFT {}" +
296       "    }" +
297       "  }" +
298       "  Sequence sequence5 {" +
299       "    TextInputInteraction TextInput g {" +
300       "      Interaction KeyPressed SHIFT {}" +
301       "      Interaction KeyPressed SHIFT {}" +
302       "      Interaction KeyPressed LETTER_G {}" +
303       "      Interaction KeyReleased LETTER_G {}" +
304       "      Interaction KeyReleased SHIFT {}" +
305       "      Interaction KeyReleased SHIFT {}" +
306       "    }" +
307       "  }" +
308       "}", getTaskTree().getTaskMap());   
309
310  }
311 
312  //-----------------------------------------------------------------------------------------------
313  /**
314   *
315   */
316  //-----------------------------------------------------------------------------------------------
317  @Test
318  public void testUsageOfBackspace()
319  {
320    GUIElement element1 = new DummyTextField("elem1");
321    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_A));
322    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_A));
323    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_B));
324    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_B));
325    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_C));
326    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_C));
327    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_D));
328    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_D));
329    simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE));
330    simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE));
331    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_E));
332    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_E));
333    simulateInteraction(element1, new KeyPressed(VirtualKey.LETTER_F));
334    simulateInteraction(element1, new KeyReleased(VirtualKey.LETTER_F));
335    new TaskTreeChecker().assertTaskMap
336      ("Sequence sequence0 {" +
337       "  TextInputInteraction TextInput abcef {" +
338       "    Interaction KeyPressed LETTER_A {}" +
339       "    Interaction KeyReleased LETTER_A {}" +
340       "    Interaction KeyPressed LETTER_B {}" +
341       "    Interaction KeyReleased LETTER_B {}" +
342       "    Interaction KeyPressed LETTER_C {}" +
343       "    Interaction KeyReleased LETTER_C {}" +
344       "    Interaction KeyPressed LETTER_D {}" +
345       "    Interaction KeyReleased LETTER_D {}" +
346       "    Interaction KeyPressed BACK_SPACE {}" +
347       "    Interaction KeyReleased BACK_SPACE {}" +
348       "    Interaction KeyPressed LETTER_E {}" +
349       "    Interaction KeyReleased LETTER_E {}" +
350       "    Interaction KeyPressed LETTER_F {}" +
351       "    Interaction KeyReleased LETTER_F {}" +
352       "  }" +
353       "}", getTaskTree().getTaskMap());   
354
355    simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE));
356    simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE));
357    simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE));
358    simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE));
359    simulateInteraction(element1, new KeyPressed(VirtualKey.BACK_SPACE));
360    simulateInteraction(element1, new KeyReleased(VirtualKey.BACK_SPACE));
361    new TaskTreeChecker().assertTaskMap
362      ("Sequence sequence0 {" +
363       "  TextInputInteraction TextInput ab {" +
364       "    Interaction KeyPressed LETTER_A {}" +
365       "    Interaction KeyReleased LETTER_A {}" +
366       "    Interaction KeyPressed LETTER_B {}" +
367       "    Interaction KeyReleased LETTER_B {}" +
368       "    Interaction KeyPressed LETTER_C {}" +
369       "    Interaction KeyReleased LETTER_C {}" +
370       "    Interaction KeyPressed LETTER_D {}" +
371       "    Interaction KeyReleased LETTER_D {}" +
372       "    Interaction KeyPressed BACK_SPACE {}" +
373       "    Interaction KeyReleased BACK_SPACE {}" +
374       "    Interaction KeyPressed LETTER_E {}" +
375       "    Interaction KeyReleased LETTER_E {}" +
376       "    Interaction KeyPressed LETTER_F {}" +
377       "    Interaction KeyReleased LETTER_F {}" +
378       "    Interaction KeyPressed BACK_SPACE {}" +
379       "    Interaction KeyReleased BACK_SPACE {}" +
380       "    Interaction KeyPressed BACK_SPACE {}" +
381       "    Interaction KeyReleased BACK_SPACE {}" +
382       "    Interaction KeyPressed BACK_SPACE {}" +
383       "    Interaction KeyReleased BACK_SPACE {}" +
384       "  }" +
385       "}", getTaskTree().getTaskMap());   
386
387  }
388 
389  //-----------------------------------------------------------------------------------------------
390  /**
391   *
392   */
393  //-----------------------------------------------------------------------------------------------
394  private static class DummyTextField extends DummyGUIElement implements TextField
395  {
396
397    //---------------------------------------------------------------------------------------------
398    /**
399     * TODO: comment
400     *
401     * @param name
402     */
403    //---------------------------------------------------------------------------------------------
404    public DummyTextField(String name)
405    {
406      super(name);
407    }
408
409  }
410
411}
Note: See TracBrowser for help on using the repository browser.