01: package abbot.editor.recorder;
02:
03: import java.awt.*;
04: import java.io.*;
05:
06: import junit.extensions.abbot.RepeatHelper;
07: import abbot.Platform;
08: import abbot.script.*;
09: import abbot.tester.FileDialogTester;
10:
11: /**
12: * Unit test to verify proper capture of user semantic events on a FileDialog.
13: */
14: public class FileDialogRecorderTest extends
15: AbstractSemanticRecorderFixture {
16:
17: private FileDialog dialog;
18: private FileDialogTester tester;
19:
20: public void testCaptureFile() {
21: String fn = "blahblahblah";
22: startRecording();
23: showWindow(dialog);
24: tester.actionSetFile(dialog, fn);
25: tester.actionAccept(dialog);
26: Step step = getStep();
27: assertTrue("Expected a sequence", step instanceof Sequence);
28: Sequence seq = (Sequence) step;
29: assertStepCount(2, seq);
30: assertStep("SetFile\\(.*," + fn + "\\)", seq.getStep(0));
31: assertStep("Accept\\(.*\\)", seq.getStep(1));
32: }
33:
34: public void testCaptureDirectoryChange() throws IOException {
35: File file = File.createTempFile(getName(), ".test");
36: String dn = file.getParent();
37: String fn = "blah";
38: startRecording();
39: showWindow(dialog);
40: tester.actionSetDirectory(dialog, dn);
41: tester.actionSetFile(dialog, fn);
42: tester.actionAccept(dialog);
43: Step step = getStep();
44: assertTrue("Expected a sequence", step instanceof Sequence);
45: Sequence seq = (Sequence) step;
46: assertStepCount(3, seq);
47: assertStep(
48: "SetDirectory\\(.*," + dn.replace('\\', '.') + "\\)",
49: seq.getStep(0));
50: assertStep("SetFile\\(.*," + fn + "\\)", seq.getStep(1));
51: assertStep("Accept\\(.*\\)", seq.getStep(2));
52: }
53:
54: public void testCaptureCancel() {
55: String fn = "foo";
56: startRecording();
57: showWindow(dialog);
58: tester.actionSetFile(dialog, fn);
59: tester.actionCancel(dialog);
60: assertStep("Cancel\\(.*\\)");
61: }
62:
63: protected void setUp() {
64: Frame frame = new Frame(getName());
65: // Workaround for w32 bug
66: if (Platform.isWindows())
67: showWindow(frame);
68: dialog = new FileDialog(frame, getName(), FileDialog.SAVE);
69: tester = new FileDialogTester();
70: }
71:
72: public FileDialogRecorderTest(String name) {
73: super (name);
74: }
75:
76: protected SemanticRecorder createSemanticRecorder(Resolver r) {
77: return new FileDialogRecorder(r);
78: }
79:
80: public static void main(String[] args) {
81: RepeatHelper.runTests(args, FileDialogRecorderTest.class);
82: }
83: }
|