01: package abbot.tester;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05: import junit.extensions.abbot.*;
06: import junit.framework.*;
07:
08: public class RobotAWTModeTest extends ComponentTestFixture {
09:
10: // avoid warning about no tests in the suite
11: public void testStub() {
12: }
13:
14: /** Wrap the standard robot tests in AWT mode. */
15: private static class AWTMode extends TestSuite {
16: public AWTMode(Class cls) {
17: super (cls);
18: }
19:
20: public void addTest(Test test) {
21: // ignore drag/drop tests, which won't work
22: if (test.toString().indexOf("Drag") == -1)
23: super .addTest(test);
24: }
25:
26: public void run(TestResult result) {
27: int lastMode = Robot.getEventMode();
28: Robot.setEventMode(Robot.EM_AWT);
29: try {
30: super .run(result);
31: } finally {
32: Robot.setEventMode(lastMode);
33: }
34: }
35: }
36:
37: public static Test suite() {
38: TestSuite suite = new TestSuite(RobotAWTModeTest.class);
39: // Only add in the AWT version of the basic robot tests if
40: // we're in robot mode; otherwise we're just duplicating effort.
41: if (Robot.getEventMode() == Robot.EM_ROBOT) {
42: suite.addTest(new AWTMode(RobotTest.class));
43: //suite.addTest(new AWTMode(RobotDragDropTest.class));
44: suite.addTest(new AWTMode(RobotAppletTest.class));
45: }
46: return suite;
47: }
48:
49: private int lastMode;
50:
51: /** All these tests run in AWT mode. */
52: protected void setUp() {
53: lastMode = Robot.getEventMode();
54: Robot.setEventMode(Robot.EM_AWT);
55: }
56:
57: /** Restore the robot event generation mode. */
58: protected void tearDown() {
59: Robot.setEventMode(lastMode);
60: }
61:
62: /** Provide for repetitive testing on individual tests. */
63: public static void main(String[] args) {
64: RepeatHelper.runTests(args, RobotAWTModeTest.class);
65: }
66: }
|