1 | package org.expeditee.gui;
|
---|
2 |
|
---|
3 | import java.awt.event.InputEvent;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.Map;
|
---|
7 |
|
---|
8 | import junit.framework.TestCase;
|
---|
9 |
|
---|
10 | import org.expeditee.items.Item;
|
---|
11 |
|
---|
12 | public class DisplayIOTest extends TestCase {
|
---|
13 | static Browser b;
|
---|
14 |
|
---|
15 | protected void setUp() throws Exception {
|
---|
16 | b = Browser.initializeForTesting();
|
---|
17 | super.setUp();
|
---|
18 | }
|
---|
19 |
|
---|
20 | public final void testToggleTwinFrames() {
|
---|
21 | DisplayIO.setCurrentFrame(FrameIO.LoadFrame("ExpediteeTest1"), true);
|
---|
22 | DisplayIO.ToggleTwinFrames();
|
---|
23 | assertTrue(DisplayIO.isTwinFramesOn());
|
---|
24 | DisplayIO.ToggleTwinFrames();
|
---|
25 | assertFalse(DisplayIO.isTwinFramesOn());
|
---|
26 | }
|
---|
27 |
|
---|
28 | public final void testMouse() throws Exception{
|
---|
29 | Frame testFrame = FrameIO.LoadFrame("ExpediteeTest1");
|
---|
30 | testFrame.clear(false);
|
---|
31 | DisplayIO.setCurrentFrame(testFrame, true);
|
---|
32 | //Draw a line
|
---|
33 | DisplayIO.setCursorPosition(100, 100);
|
---|
34 | Thread.sleep(1000);
|
---|
35 | DisplayIO.clickMouse(InputEvent.BUTTON2_MASK);
|
---|
36 | Thread.sleep(100);
|
---|
37 | DisplayIO.setCursorPosition(200, 200);
|
---|
38 | Thread.sleep(100);
|
---|
39 | DisplayIO.clickMouse(InputEvent.BUTTON2_MASK);
|
---|
40 | Thread.sleep(100);
|
---|
41 | //Draw a rectangle
|
---|
42 | DisplayIO.setCursorPosition(250, 250);
|
---|
43 | Thread.sleep(100);
|
---|
44 | DisplayIO.clickMouse(InputEvent.BUTTON3_MASK);
|
---|
45 | Thread.sleep(100);
|
---|
46 | DisplayIO.setCursorPosition(500, 500);
|
---|
47 | Thread.sleep(100);
|
---|
48 | DisplayIO.clickMouse(InputEvent.BUTTON3_MASK);
|
---|
49 | Thread.sleep(1000);
|
---|
50 | //Check that the line is there
|
---|
51 | Collection<Item> items = testFrame.getVisibleItems();
|
---|
52 | assertTrue(items.size() == 12);
|
---|
53 | Map<String, Integer> itemCounts = getItemCount(items);
|
---|
54 |
|
---|
55 | }
|
---|
56 |
|
---|
57 | private Map<String, Integer> getItemCount(Collection<Item> items) {
|
---|
58 | Map<String, Integer> itemCounts = new HashMap<String,Integer>();
|
---|
59 | for(Item i : items){
|
---|
60 | String className = i.getClass().toString();
|
---|
61 | if(itemCounts.containsKey(className)){
|
---|
62 | itemCounts.put(className, itemCounts.get(className)+1);
|
---|
63 | }else{
|
---|
64 | itemCounts.put(className, 1);
|
---|
65 | }
|
---|
66 |
|
---|
67 | }
|
---|
68 | return itemCounts;
|
---|
69 | }
|
---|
70 |
|
---|
71 | // public final void testReleaseMouse() {
|
---|
72 | // fail("Not yet implemented");
|
---|
73 | // }
|
---|
74 | //
|
---|
75 | // public final void testClickMouse() {
|
---|
76 | // fail("Not yet implemented");
|
---|
77 | // }
|
---|
78 |
|
---|
79 | }
|
---|