48 private int eventCount3; |
49 private int eventCount3; |
49 |
50 |
50 /** |
51 /** |
51 * Constructor. |
52 * Constructor. |
52 */ |
53 */ |
53 public DynamicUpdateTest() { |
54 public DynamicUpdateTest() |
|
55 { |
54 } |
56 } |
55 |
57 |
56 /** |
58 /** |
57 * Constructor. |
59 * Constructor. |
58 * |
60 * |
59 * @param sTestName Test name. |
61 * @param sTestName Test name. |
60 * @param rTestMethod Test method. |
62 * @param rTestMethod Test method. |
61 */ |
63 */ |
62 public DynamicUpdateTest(String sTestName) { |
64 public DynamicUpdateTest(String sTestName) |
|
65 { |
63 super(sTestName); |
66 super(sTestName); |
64 } |
67 } |
65 |
68 |
66 public static Test suite() { |
69 public static Test suite() |
|
70 { |
67 TestSuite suite = new TestSuite(); |
71 TestSuite suite = new TestSuite(); |
68 |
72 |
69 java.util.Vector methodNames; |
73 java.util.Vector methodNames; |
70 java.util.Enumeration e; |
74 java.util.Enumeration e; |
71 |
75 |
72 // Add widget tests |
76 // Add widget tests |
73 methodNames = DynamicUpdateTest.methodNames(); |
77 methodNames = DynamicUpdateTest.methodNames(); |
74 e = methodNames.elements(); |
78 e = methodNames.elements(); |
75 while (e.hasMoreElements()) { |
79 while(e.hasMoreElements()) |
76 suite.addTest(new DynamicUpdateTest((String)e.nextElement())); |
80 { |
77 } |
81 suite.addTest(new DynamicUpdateTest((String)e.nextElement())); |
78 |
82 } |
|
83 |
79 return suite; |
84 return suite; |
80 } |
85 } |
81 |
86 |
82 public static java.util.Vector methodNames() { |
87 public static java.util.Vector methodNames() |
|
88 { |
83 java.util.Vector methodNames = new java.util.Vector(); |
89 java.util.Vector methodNames = new java.util.Vector(); |
84 methodNames.addElement("testAddAndRemoveManyCommands"); |
90 methodNames.addElement("testAddAndRemoveManyCommands"); |
85 methodNames.addElement("testCommandInEmptyForm"); |
91 methodNames.addElement("testCommandInEmptyForm"); |
86 methodNames.addElement("testAddCommandToManyDisplayables"); |
92 methodNames.addElement("testAddCommandToManyDisplayables"); |
87 methodNames.addElement("testManyCommandListeners"); |
93 methodNames.addElement("testManyCommandListeners"); |
88 return methodNames; |
94 return methodNames; |
89 } |
95 } |
90 |
96 |
91 public void runTest() throws Throwable { |
97 public void runTest() throws Throwable |
92 if (getName().equals("testAddAndRemoveManyCommands")) testAddAndRemoveManyCommands(); |
98 { |
93 else if (getName().equals("testCommandInEmptyForm")) testCommandInEmptyForm(); |
99 if(getName().equals("testAddAndRemoveManyCommands")) testAddAndRemoveManyCommands(); |
94 else if (getName().equals("testAddCommandToManyDisplayables")) testAddCommandToManyDisplayables(); |
100 else if(getName().equals("testCommandInEmptyForm")) testCommandInEmptyForm(); |
95 else if (getName().equals("testManyCommandListeners")) testManyCommandListeners(); |
101 else if(getName().equals("testAddCommandToManyDisplayables")) testAddCommandToManyDisplayables(); |
|
102 else if(getName().equals("testManyCommandListeners")) testManyCommandListeners(); |
96 else super.runTest(); |
103 else super.runTest(); |
97 } |
104 } |
98 |
105 |
99 |
106 |
100 /** |
107 /** |
101 * Adds and removes many kind of commands to displayable and makes sure that |
108 * Adds and removes many kind of commands to displayable and makes sure that |
102 * events occurs correctly all the time. |
109 * events occurs correctly all the time. |
103 */ |
110 */ |
104 public void testAddAndRemoveManyCommands() { |
111 public void testAddAndRemoveManyCommands() |
|
112 { |
105 boolean testPassed = true; |
113 boolean testPassed = true; |
106 String testMsg = ""; |
114 String testMsg = ""; |
107 latestCommand = null; |
115 latestCommand = null; |
108 latestDisplayable = null; |
116 latestDisplayable = null; |
109 |
117 |
110 TextBox textBox = new TextBox("title", "content", |
118 TextBox textBox = new TextBox("title", "content", |
111 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
119 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
112 |
120 |
113 Command item1 = new Command("item", "item", Command.ITEM, 0); |
121 Command item1 = new Command("item", "item", Command.ITEM, 0); |
114 Command item2 = new Command("item2", "item2", Command.ITEM, 1); |
122 Command item2 = new Command("item2", "item2", Command.ITEM, 1); |
115 Command item3 = new Command("item3", "item3", Command.ITEM, 2); |
123 Command item3 = new Command("item3", "item3", Command.ITEM, 2); |
116 Command exit1 = new Command("exit1", "exit1", Command.EXIT, 0); |
124 Command exit1 = new Command("exit1", "exit1", Command.EXIT, 0); |
184 key(Key.CBA1, 0); |
198 key(Key.CBA1, 0); |
185 key(Key.DownArrow, 0); |
199 key(Key.DownArrow, 0); |
186 key(Key.DownArrow, 0); |
200 key(Key.DownArrow, 0); |
187 key(Key.Select); |
201 key(Key.Select); |
188 |
202 |
189 if (latestCommand == null) { |
203 if(latestCommand == null) |
|
204 { |
190 testPassed = false; |
205 testPassed = false; |
191 testMsg = "no event from EXIT2-command."; |
206 testMsg = "no event from EXIT2-command."; |
192 } |
207 } |
193 else if (latestCommand != exit2) { |
208 else if(latestCommand != exit2) |
|
209 { |
194 testPassed = false; |
210 testPassed = false; |
195 testMsg = "not EXIT2-command in event."; |
211 testMsg = "not EXIT2-command in event."; |
196 } |
212 } |
197 else if (latestDisplayable != textBox) { |
213 else if(latestDisplayable != textBox) |
|
214 { |
198 testPassed = false; |
215 testPassed = false; |
199 testMsg = "unexpected displayable in event."; |
216 testMsg = "unexpected displayable in event."; |
200 } |
217 } |
201 |
218 |
202 // Next remove some of the commands and again click one in menu: |
219 // Next remove some of the commands and again click one in menu: |
209 key(Key.CBA1, 0); |
226 key(Key.CBA1, 0); |
210 key(Key.DownArrow, 0); |
227 key(Key.DownArrow, 0); |
211 key(Key.DownArrow, 0); |
228 key(Key.DownArrow, 0); |
212 key(Key.Select); |
229 key(Key.Select); |
213 |
230 |
214 if (latestCommand == null) { |
231 if(latestCommand == null) |
|
232 { |
215 testPassed = false; |
233 testPassed = false; |
216 testMsg = "no event from SCREEN1-command."; |
234 testMsg = "no event from SCREEN1-command."; |
217 } |
235 } |
218 else if (latestCommand != screen1) { |
236 else if(latestCommand != screen1) |
|
237 { |
219 testPassed = false; |
238 testPassed = false; |
220 testMsg = "not SCREEN1-command in event."; |
239 testMsg = "not SCREEN1-command in event."; |
221 } |
240 } |
222 else if (latestDisplayable != textBox) { |
241 else if(latestDisplayable != textBox) |
|
242 { |
223 testPassed = false; |
243 testPassed = false; |
224 testMsg = "unexpected displayable in event."; |
244 testMsg = "unexpected displayable in event."; |
225 } |
245 } |
226 |
246 |
227 // Finally remove all commands and verify the commands are really |
247 // Finally remove all commands and verify the commands are really |
244 |
264 |
245 key(Key.CBA1, 0); |
265 key(Key.CBA1, 0); |
246 key(Key.CBA2, 0); |
266 key(Key.CBA2, 0); |
247 key(Key.Select); |
267 key(Key.Select); |
248 |
268 |
249 if (latestCommand != null) { |
269 if(latestCommand != null) |
|
270 { |
250 testPassed = false; |
271 testPassed = false; |
251 testMsg = "Event occured without commands."; |
272 testMsg = "Event occured without commands."; |
252 } |
273 } |
253 |
274 |
254 assertTrue(getName() + " failed, " + testMsg, testPassed); |
275 assertTrue(getName() + " failed, " + testMsg, testPassed); |
255 } |
276 } |
256 |
277 |
257 /** |
278 /** |
258 * Test to add command to empty form and verify it works. |
279 * Test to add command to empty form and verify it works. |
259 */ |
280 */ |
260 public void testCommandInEmptyForm() { |
281 public void testCommandInEmptyForm() |
|
282 { |
261 latestCommand = null; |
283 latestCommand = null; |
262 latestDisplayable = null; |
284 latestDisplayable = null; |
263 |
285 |
264 Form form = new Form("form"); |
286 Form form = new Form("form"); |
265 Command ok = new Command("Ok", "", Command.ITEM, 0); |
287 Command ok = new Command("Ok", "", Command.ITEM, 0); |
271 // If there's only one command of type ITEM it's mapped to LSK. |
293 // If there's only one command of type ITEM it's mapped to LSK. |
272 // Click it: |
294 // Click it: |
273 key(Key.CBA1); |
295 key(Key.CBA1); |
274 |
296 |
275 assertEquals("Command not activated or not correct command.", |
297 assertEquals("Command not activated or not correct command.", |
276 ok, latestCommand); |
298 ok, latestCommand); |
277 assertEquals("Wrong displayable delivered to commandAction-method.", |
299 assertEquals("Wrong displayable delivered to commandAction-method.", |
278 form, latestDisplayable); |
300 form, latestDisplayable); |
279 } |
301 } |
280 |
302 |
281 /** |
303 /** |
282 * Tests that it's possible to add one command to many displayables and |
304 * Tests that it's possible to add one command to many displayables and |
283 * removing command from one displayable doesn't affect another displayable. |
305 * removing command from one displayable doesn't affect another displayable. |
284 */ |
306 */ |
285 public void testAddCommandToManyDisplayables() { |
307 public void testAddCommandToManyDisplayables() |
|
308 { |
286 boolean testPassed = true; |
309 boolean testPassed = true; |
287 String testMsg = ""; |
310 String testMsg = ""; |
288 latestCommand = null; |
311 latestCommand = null; |
289 latestDisplayable = null; |
312 latestDisplayable = null; |
290 |
313 |
291 TextBox textBox = new TextBox("title", "content", |
314 TextBox textBox = new TextBox("title", "content", |
292 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
315 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
293 TextBox textBox2 = new TextBox("title2", "content2", |
316 TextBox textBox2 = new TextBox("title2", "content2", |
294 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
317 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
295 |
318 |
296 Command item1 = new Command("item", "item", Command.ITEM, 0); |
319 Command item1 = new Command("item", "item", Command.ITEM, 0); |
297 |
320 |
298 textBox.setCommandListener(this); |
321 textBox.setCommandListener(this); |
299 textBox2.setCommandListener(this); |
322 textBox2.setCommandListener(this); |
326 latestDisplayable = null; |
352 latestDisplayable = null; |
327 setCurrent(textBox2); |
353 setCurrent(textBox2); |
328 |
354 |
329 key(Key.CBA1); |
355 key(Key.CBA1); |
330 |
356 |
331 if (latestCommand == null) { |
357 if(latestCommand == null) |
|
358 { |
332 testPassed = false; |
359 testPassed = false; |
333 testMsg = "no event from ITEM-command in second displayable."; |
360 testMsg = "no event from ITEM-command in second displayable."; |
334 } |
361 } |
335 else if (latestCommand != item1) { |
362 else if(latestCommand != item1) |
|
363 { |
336 testPassed = false; |
364 testPassed = false; |
337 testMsg = "not ITEM-command in event in second displayable."; |
365 testMsg = "not ITEM-command in event in second displayable."; |
338 } |
366 } |
339 else if (latestDisplayable != textBox2) { |
367 else if(latestDisplayable != textBox2) |
|
368 { |
340 testPassed = false; |
369 testPassed = false; |
341 testMsg = "unexpected displayable in event."; |
370 testMsg = "unexpected displayable in event."; |
342 } |
371 } |
343 |
372 |
344 // Remove command from first displayable and verify that it still works |
373 // Remove command from first displayable and verify that it still works |
347 latestDisplayable = null; |
376 latestDisplayable = null; |
348 textBox.removeCommand(item1); |
377 textBox.removeCommand(item1); |
349 |
378 |
350 key(Key.CBA1); |
379 key(Key.CBA1); |
351 |
380 |
352 if (latestCommand == null) { |
381 if(latestCommand == null) |
|
382 { |
353 testPassed = false; |
383 testPassed = false; |
354 testMsg = "no event from ITEM-command in second displayable."; |
384 testMsg = "no event from ITEM-command in second displayable."; |
355 } |
385 } |
356 else if (latestCommand != item1) { |
386 else if(latestCommand != item1) |
|
387 { |
357 testPassed = false; |
388 testPassed = false; |
358 testMsg = "not ITEM-command in event in second displayable."; |
389 testMsg = "not ITEM-command in event in second displayable."; |
359 } |
390 } |
360 else if (latestDisplayable != textBox2) { |
391 else if(latestDisplayable != textBox2) |
|
392 { |
361 testPassed = false; |
393 testPassed = false; |
362 testMsg = "unexpected displayable in event."; |
394 testMsg = "unexpected displayable in event."; |
363 } |
395 } |
364 |
396 |
365 // Add command again to first displayable, remove it from second one, |
397 // Add command again to first displayable, remove it from second one, |
404 eventCount3 = 0; |
440 eventCount3 = 0; |
405 |
441 |
406 // Create two Displayables and two CommandListeners and add |
442 // Create two Displayables and two CommandListeners and add |
407 // same Command to both Displayables: |
443 // same Command to both Displayables: |
408 TextBox textBox = new TextBox("title", "content", |
444 TextBox textBox = new TextBox("title", "content", |
409 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
445 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
410 TextBox textBox2 = new TextBox("title2", "content2", |
446 TextBox textBox2 = new TextBox("title2", "content2", |
411 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
447 MAX_NUM_OF_CHARS_IN_TEST_TEXTBOX, 0); |
412 Command item1 = new Command("item", "item", Command.ITEM, 0); |
448 Command item1 = new Command("item", "item", Command.ITEM, 0); |
413 |
449 |
414 textBox.setCommandListener(new CommandListener() { |
450 textBox.setCommandListener(new CommandListener() |
415 public void commandAction(Command c, Displayable d) { |
451 { |
|
452 public void commandAction(Command c, Displayable d) |
|
453 { |
416 latestCommand2 = c; |
454 latestCommand2 = c; |
417 latestDisplayable2 = d; |
455 latestDisplayable2 = d; |
418 eventCount2++; |
456 eventCount2++; |
419 } |
457 } |
420 }); |
458 }); |
421 |
459 |
422 textBox2.setCommandListener(new CommandListener() { |
460 textBox2.setCommandListener(new CommandListener() |
423 public void commandAction(Command c, Displayable d) { |
461 { |
|
462 public void commandAction(Command c, Displayable d) |
|
463 { |
424 latestCommand3 = c; |
464 latestCommand3 = c; |
425 latestDisplayable3 = d; |
465 latestDisplayable3 = d; |
426 eventCount3++; |
466 eventCount3++; |
427 } |
467 } |
428 }); |
468 }); |
433 // Set second displayable current and try to activate the command: |
473 // Set second displayable current and try to activate the command: |
434 setCurrent(textBox2); |
474 setCurrent(textBox2); |
435 |
475 |
436 key(Key.CBA1); |
476 key(Key.CBA1); |
437 |
477 |
438 if (latestCommand3 == null) { |
478 if(latestCommand3 == null) |
|
479 { |
439 testPassed = false; |
480 testPassed = false; |
440 testMsg = "no event in second displayable."; |
481 testMsg = "no event in second displayable."; |
441 } |
482 } |
442 else if (latestCommand3 != item1) { |
483 else if(latestCommand3 != item1) |
|
484 { |
443 testPassed = false; |
485 testPassed = false; |
444 testMsg = "wrong command in second displayable."; |
486 testMsg = "wrong command in second displayable."; |
445 } |
487 } |
446 else if (latestDisplayable3 != textBox2) { |
488 else if(latestDisplayable3 != textBox2) |
447 testPassed = false; |
489 { |
448 testMsg = "unexpected displayable in event."; |
490 testPassed = false; |
449 } |
491 testMsg = "unexpected displayable in event."; |
450 else if (eventCount3 != 1) { |
492 } |
|
493 else if(eventCount3 != 1) |
|
494 { |
451 testPassed = false; |
495 testPassed = false; |
452 testMsg = "Unexpected number of events: " + eventCount3; |
496 testMsg = "Unexpected number of events: " + eventCount3; |
453 } |
497 } |
454 |
498 |
455 // Switch to first displayable and try to activate the command: |
499 // Switch to first displayable and try to activate the command: |
456 setCurrent(textBox); |
500 setCurrent(textBox); |
457 |
501 |
458 key(Key.CBA1); |
502 key(Key.CBA1); |
459 |
503 |
460 if (latestCommand2 == null) { |
504 if(latestCommand2 == null) |
|
505 { |
461 testPassed = false; |
506 testPassed = false; |
462 testMsg = "no event in first displayable."; |
507 testMsg = "no event in first displayable."; |
463 } |
508 } |
464 else if (latestCommand2 != item1) { |
509 else if(latestCommand2 != item1) |
|
510 { |
465 testPassed = false; |
511 testPassed = false; |
466 testMsg = "wrong command in first displayable."; |
512 testMsg = "wrong command in first displayable."; |
467 } |
513 } |
468 else if (latestDisplayable2 != textBox) { |
514 else if(latestDisplayable2 != textBox) |
469 testPassed = false; |
515 { |
470 testMsg = "unexpected displayable in event."; |
516 testPassed = false; |
471 } |
517 testMsg = "unexpected displayable in event."; |
472 else if (eventCount2 != 1) { |
518 } |
|
519 else if(eventCount2 != 1) |
|
520 { |
473 testPassed = false; |
521 testPassed = false; |
474 testMsg = "Unexpected number of events: " + eventCount2; |
522 testMsg = "Unexpected number of events: " + eventCount2; |
475 } |
523 } |
476 else if (eventCount3 != 1) { |
524 else if(eventCount3 != 1) |
|
525 { |
477 testPassed = false; |
526 testPassed = false; |
478 testMsg = "Unexpected number of events in second displayable: " |
527 testMsg = "Unexpected number of events in second displayable: " |
479 + eventCount2; |
528 + eventCount2; |
480 } |
529 } |
481 |
530 |
482 // Clear counters, remove command from second displayable and |
531 // Clear counters, remove command from second displayable and |
483 // activate it in first displayable again: |
532 // activate it in first displayable again: |
484 latestCommand2 = null; |
533 latestCommand2 = null; |
490 |
539 |
491 textBox2.removeCommand(item1); |
540 textBox2.removeCommand(item1); |
492 |
541 |
493 key(Key.CBA1); |
542 key(Key.CBA1); |
494 |
543 |
495 if (latestCommand2 == null) { |
544 if(latestCommand2 == null) |
|
545 { |
496 testPassed = false; |
546 testPassed = false; |
497 testMsg = "no event in first displayable."; |
547 testMsg = "no event in first displayable."; |
498 } |
548 } |
499 else if (latestCommand2 != item1) { |
549 else if(latestCommand2 != item1) |
|
550 { |
500 testPassed = false; |
551 testPassed = false; |
501 testMsg = "wrong command in first displayable."; |
552 testMsg = "wrong command in first displayable."; |
502 } |
553 } |
503 else if (latestDisplayable2 != textBox) { |
554 else if(latestDisplayable2 != textBox) |
504 testPassed = false; |
555 { |
505 testMsg = "unexpected displayable in event."; |
556 testPassed = false; |
506 } |
557 testMsg = "unexpected displayable in event."; |
507 else if (eventCount2 != 1) { |
558 } |
|
559 else if(eventCount2 != 1) |
|
560 { |
508 testPassed = false; |
561 testPassed = false; |
509 testMsg = "Unexpected number of events: " + eventCount2; |
562 testMsg = "Unexpected number of events: " + eventCount2; |
510 } |
563 } |
511 else if (eventCount3 != 0) { |
564 else if(eventCount3 != 0) |
|
565 { |
512 testPassed = false; |
566 testPassed = false; |
513 testMsg = "Unexpected number of events in second displayable: " |
567 testMsg = "Unexpected number of events in second displayable: " |
514 + eventCount3; |
568 + eventCount3; |
515 } |
569 } |
516 else if (latestCommand3 != null) { |
570 else if(latestCommand3 != null) |
|
571 { |
517 testPassed = false; |
572 testPassed = false; |
518 testMsg = "Unexpected event in second displayable."; |
573 testMsg = "Unexpected event in second displayable."; |
519 } |
574 } |
520 |
575 |
521 assertTrue(getName() + " failed, " + testMsg, testPassed); |
576 assertTrue(getName() + " failed, " + testMsg, testPassed); |