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 = Browser._theBrowser;
|
---|
14 |
|
---|
15 | protected void setUp() throws Exception {
|
---|
16 | if (b == null) {
|
---|
17 | Browser.main(null);
|
---|
18 | while (!Browser.isInitComplete()) {
|
---|
19 | Thread.sleep(10);
|
---|
20 | }
|
---|
21 | b = Browser._theBrowser;
|
---|
22 | }
|
---|
23 | super.setUp();
|
---|
24 | }
|
---|
25 |
|
---|
26 | public final void testToggleTwinFrames() {
|
---|
27 | DisplayIO.setCurrentFrame(FrameIO.LoadFrame("ExpediteeTest1"), true);
|
---|
28 | DisplayIO.ToggleTwinFrames();
|
---|
29 | assertTrue(DisplayIO.isTwinFramesOn());
|
---|
30 | DisplayIO.ToggleTwinFrames();
|
---|
31 | assertFalse(DisplayIO.isTwinFramesOn());
|
---|
32 | }
|
---|
33 |
|
---|
34 | public final void testMouse() throws Exception{
|
---|
35 | Frame testFrame = FrameIO.LoadFrame("ExpediteeTest1");
|
---|
36 | testFrame.clear(false);
|
---|
37 | DisplayIO.setCurrentFrame(testFrame, true);
|
---|
38 | //Draw a line
|
---|
39 | DisplayIO.setCursorPosition(100, 100);
|
---|
40 | Thread.sleep(1000);
|
---|
41 | DisplayIO.clickMouse(InputEvent.BUTTON2_MASK);
|
---|
42 | Thread.sleep(100);
|
---|
43 | DisplayIO.setCursorPosition(200, 200);
|
---|
44 | Thread.sleep(100);
|
---|
45 | DisplayIO.clickMouse(InputEvent.BUTTON2_MASK);
|
---|
46 | Thread.sleep(100);
|
---|
47 | //Draw a rectangle
|
---|
48 | DisplayIO.setCursorPosition(250, 250);
|
---|
49 | Thread.sleep(100);
|
---|
50 | DisplayIO.clickMouse(InputEvent.BUTTON3_MASK);
|
---|
51 | Thread.sleep(100);
|
---|
52 | DisplayIO.setCursorPosition(500, 500);
|
---|
53 | Thread.sleep(100);
|
---|
54 | DisplayIO.clickMouse(InputEvent.BUTTON3_MASK);
|
---|
55 | Thread.sleep(1000);
|
---|
56 | //Check that the line is there
|
---|
57 | Collection<Item> items = testFrame.getVisibleItems();
|
---|
58 | assertTrue(items.size() == 12);
|
---|
59 | Map<String, Integer> itemCounts = getItemCount(items);
|
---|
60 |
|
---|
61 | }
|
---|
62 |
|
---|
63 | private Map<String, Integer> getItemCount(Collection<Item> items) {
|
---|
64 | Map<String, Integer> itemCounts = new HashMap<String,Integer>();
|
---|
65 | for(Item i : items){
|
---|
66 | String className = i.getClass().toString();
|
---|
67 | if(itemCounts.containsKey(className)){
|
---|
68 | itemCounts.put(className, itemCounts.get(className)+1);
|
---|
69 | }else{
|
---|
70 | itemCounts.put(className, 1);
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|
74 | return itemCounts;
|
---|
75 | }
|
---|
76 |
|
---|
77 | // public final void testReleaseMouse() {
|
---|
78 | // fail("Not yet implemented");
|
---|
79 | // }
|
---|
80 | //
|
---|
81 | // public final void testClickMouse() {
|
---|
82 | // fail("Not yet implemented");
|
---|
83 | // }
|
---|
84 |
|
---|
85 | }
|
---|