Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
967 lines (794 loc) · 39 KB

File metadata and controls

967 lines (794 loc) · 39 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
/*BEGIN_COPYRIGHT_BLOCK
*
* Copyright (c) 2001-2015, JavaPLT group at Rice University (drjava@rice.edu)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names of DrJava, DrScala, the JavaPLT group, Rice University, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software is Open Source Initiative approved Open Source Software.
* Open Source Initative Approved is a trademark of the Open Source Initiative.
*
* This file is part of DrScala. Download the current version of this project
* from http://www.drscala.org/.
*
* END_COPYRIGHT_BLOCK*/
package edu.rice.cs.drjava.ui;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.event.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.Toolkit;
import javax.swing.*;
import javax.swing.text.*;
import java.io.*;
import java.util.List;
import edu.rice.cs.drjava.model.*;
import edu.rice.cs.drjava.model.repl.*;
import edu.rice.cs.drjava.model.repl.InteractionsDocumentTest.TestBeep;
import edu.rice.cs.drjava.config.OptionConstants;
import edu.rice.cs.plt.io.IOUtil;
import edu.rice.cs.util.FileOpenSelector;
import edu.rice.cs.util.*;
import edu.rice.cs.util.text.*;
import edu.rice.cs.util.swing.Utilities;
import edu.rice.cs.drjava.model.compiler.CompilerListener;
/** Test functions of MainFrame.
* @version $Id: MainFrameTest.java 5594 2012-06-21 11:23:40Z rcartwright $
*/
public final class MainFrameTest extends MultiThreadedTestCase {
private volatile MainFrame _frame;
/** A temporary directory */
private volatile File _tempDir;
/* Flag and lock for signalling when file has been opened and active document changed. */
protected volatile boolean _openDone;
protected final Object _openLock = new Object();
/* Flag and lock for signalling when file has been closed. */
protected volatile boolean _closeDone;
protected final Object _closeLock = new Object();
/* Flag and lock for signalling when compilation is done. */
protected volatile boolean _compileDone;
protected final Object _compileLock = new Object();
private final static Log _log = new Log("MainFrameTest.txt", false);
/** Setup method for each JUnit test case. */
public void setUp() throws Exception {
super.setUp();
// Perform ainFrame initialization in the event thread because the event thread is ALREADY running
Utilities.invokeAndWait(new Runnable() {
public void run() {
// _log.log("super.setUp() for next test completed");
_frame = new MainFrame();
// _log.log("new MainFrame() for next test completed");
EventQueue.invokeLater(new Runnable() { public void run() { _frame.pack(); } });
// _log.log("setUp complete for next test");
}
});
}
public void tearDown() throws Exception {
// Utilities.invokeLater(new Runnable() {
// public void run() {
_frame.dispose();
_frame = null;
/* try { */ MainFrameTest.super.tearDown(); /* } */
// catch(Exception e) { throw new UnexpectedException(e); }
// }
// });
super.tearDown();
}
JButton _but;
/** Tests that the returned JButton of <code>createManualToolBarButton</code>:
* 1. Is disabled upon return.
* 2. Inherits the tooltip of the Action parameter <code>a</code>.
*/
public void testCreateManualToolbarButton() {
final Action a = new AbstractAction("Test Action") { public void actionPerformed(ActionEvent ae) { } };
a.putValue(Action.LONG_DESCRIPTION, "test tooltip");
Utilities.invokeAndWait(new Runnable() { public void run() { _but = _frame._createManualToolBarButton(a); } });
assertTrue("Returned JButton is enabled.", ! _but.isEnabled());
assertEquals("Tooltip text not set.", "test tooltip", _but.getToolTipText());
_log.log("testCreateManualToobarButton completed");
}
/** Tests that the current location of a document is equal to the caret Position after switching to another document and back. */
public void testDocLocationAfterSwitch() throws BadLocationException {
final DefinitionsPane pane = _frame.getCurrentDefPane();
final OpenDefinitionsDocument doc = pane.getOpenDefDocument();
setDocText(doc.getDocument(), "abcd");
Utilities.invokeAndWait(new Runnable() {
public void run() {
doc.setCurrentLocation(3);
pane.setCaretPosition(3); // The caret is not affected by setCurrentLocation
}
});
assertEquals("Location of old doc before switch", 3, doc.getCurrentLocation());
assertEquals("Location of cursor in old document", 3, pane.getCaretPosition());
// Create a new file
SingleDisplayModel model = _frame.getModel();
final OpenDefinitionsDocument oldDoc = doc;
final DefinitionsPane oldPane = pane;
final OpenDefinitionsDocument newDoc = model.newFile();
// Current pane should be new doc, pos 0
DefinitionsPane curPane;
OpenDefinitionsDocument curDoc;
curPane = _frame.getCurrentDefPane();
curDoc = curPane.getOpenDefDocument();//.getDocument();
assertEquals("New curr DefPane's document", newDoc, curDoc);
assertEquals("Location in new document", 0, newDoc.getCurrentLocation());
// Switch back to old document
model.setActiveNextDocument();
Utilities.clearEventQueue();
assertEquals("Next active doc", oldDoc, model.getActiveDocument());
// Current pane should be old doc, pos 3
curPane = _frame.getCurrentDefPane();
curDoc = curPane.getOpenDefDocument();//.getDocument();
assertEquals("Next active pane", oldPane, curPane);
assertEquals("Current document is old document", oldDoc, curDoc);
assertEquals("Location of caret in old document", 3, curPane.getCaretPosition());
_log.log("testDocLocationAfterSwitch completed");
}
private String _data;
/** Tests that the clipboard is unmodified after a "clear line" action. */
public void testClearLine() throws BadLocationException, UnsupportedFlavorException, IOException {
// First, copy some data out of the main document.
final DefinitionsPane pane = _frame.getCurrentDefPane();
final OpenDefinitionsDocument doc = pane.getOpenDefDocument();
final String clipString = "***Clipboard***";
// _frame.setVisible(true);
Utilities.invokeAndWait(new Runnable() {
public void run() {
try {
doc.insertString(0, "abcdefg", null);
pane.setCaretPosition(5);
// ActionMap actionMap = _pane.getActionMap();
// String selString = DefaultEditorKit.selectionEndLineAction;
// actionMap.get(selString).actionPerformed(new ActionEvent(this, 0, "SelectionEndLine"));
// _frame.cutAction.actionPerformed(new ActionEvent(this, 0, "Cut"));
_frame.validate();
// _frame.paint(_frame.getGraphics());
// ActionMap actionMap = _pane.getActionMap();
// String selString = DefaultEditorKit.selectionEndLineAction;
// actionMap.get(selString).actionPerformed(new ActionEvent(this, 0, "SelectionEndLine"));
// pane.setSelectionStart(2);
// pane.setSelectionEnd(7);
// Get a copy of the current clipboard.
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
// Insert valid string in clipboars.
clip.setContents(new StringSelection(clipString), _frame);
Transferable contents = clip.getContents(_frame);
// Trigger the Clear Line action from a new position.
pane.setCaretPosition(2);
_frame.validate();
// _frame.paint(_frame.getGraphics());
_frame._clearLineAction.actionPerformed(new ActionEvent(pane, 0, "Clear Line"));
// _frame.paint(_frame.getGraphics());
_frame.validate();
// Verify that the clipboard contents are still the same.
contents = clip.getContents(null);
_data = (String) contents.getTransferData(DataFlavor.stringFlavor);
}
catch(Throwable t) { listenerFail(t.getMessage()); }
}
});
Utilities.clearEventQueue();
assertEquals("Clipboard contents should be unchanged after Clear Line.", clipString, _data);
// Verify that the document text is what we expect.
assertEquals("Current line of text should be truncated by Clear Line.", "ab", doc.getText());
_log.log("testClearLine completed");
}
/** Tests that the clipboard is modified after a "cut line" action.
* NOTE: Commented out for commit because of failures, despite proper behavior in GUI.
* This may not work unless ActionEvents are dropped in the event queue
*/
public void testCutLine() throws BadLocationException {
// First, copy some data out of the main document.
final DefinitionsPane pane = _frame.getCurrentDefPane();
final OpenDefinitionsDocument doc = pane.getOpenDefDocument();
// _frame.setVisible(true);
Utilities.invokeAndWait(new Runnable() {
public void run() {
try {
doc.insertString(0, "abcdefg", null);
pane.setCaretPosition(5);
_frame.validate();
// _frame.paint(_frame.getGraphics());
// ActionMap actionMap = _pane.getActionMap();
// String selString = DefaultEditorKit.selectionEndLineAction;
// actionMap.get(selString).actionPerformed(new ActionEvent(pane, 0, "SelectionEndLine"));
pane.setSelectionStart(2);
pane.setSelectionEnd(7);
_frame.validate();
pane.cut();
// _frame.cutAction.actionPerformed(new ActionEvent(pane, 0, "Cut"));
// Get a copy of the current clipboard.
// Trigger the Cut Line action from a new position.
// _pane.setCaretPosition(2);
_frame.validate();
// _frame.paint(_frame.getGraphics());
// _frame._cutLineAction.actionPerformed(new ActionEvent(this, 0, "Cut Line"));
// _frame.dispatchEvent(new ActionEvent(this, 0, "Cut Line"));
// Verify that the clipboard contents are what we expect.
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clip.getContents(null);
_data = (String) contents.getTransferData(DataFlavor.stringFlavor);
}
catch(Throwable t) { listenerFail(t.getMessage()); }
}
});
Utilities.clearEventQueue();
assertEquals("Clipboard contents should be changed after Cut Line.", "cdefg", _data);
// Verify that the document text is what we expect.
assertEquals("Current line of text should be truncated by Cut Line.", "ab", doc.getText());
_log.log("testCutLine completed");
}
/** Make sure that the InteractionsPane is displaying the correct InteractionsDocument. (SourceForge bug #681547)
* Also make sure this document cannot be edited before the prompt.
*/
public void testCorrectInteractionsDocument() throws EditDocumentException {
InteractionsPane pane = _frame.getInteractionsPane();
final SingleDisplayModel model = _frame.getModel();
InteractionsDJDocument doc = model.getSwingInteractionsDocument();
// Make the test silent
Utilities.invokeAndWait(new Runnable() {
public void run() {
model.getInteractionsModel().getDocument().setBeep(new TestBeep());
}
});
Utilities.clearEventQueue();
// Test for strict == equality
assertTrue("UI's int. doc. should equals Model's int. doc.", pane.getDocument() == doc);
int origLength = doc.getLength();
doc.insertText(1, "typed text", InteractionsDocument.DEFAULT_STYLE);
Utilities.clearEventQueue();
assertEquals("Document should not have changed.", origLength, doc.getLength());
_log.log("testCorrectInteractionsDocument completed");
}
/** Tests that undoing/redoing a multi-line indent will restore the caret position. */
public void testMultilineIndentAfterScroll() throws BadLocationException, InterruptedException {
final String text =
"public class stuff {\n" +
"private int _int;\n" +
"private Bar _bar;\n" +
"public void foo() {\n" +
"_bar.baz(_int);\n" +
"}\n" +
"}\n";
final String indented =
"public class stuff {\n" +
" private int _int;\n" +
" private Bar _bar;\n" +
" public void foo() {\n" +
" _bar.baz(_int);\n" +
" }\n" +
"}\n";
final int newPos = 20;
final DefinitionsPane pane = _frame.getCurrentDefPane();
final OpenDefinitionsDocument doc = pane.getOpenDefDocument();
setConfigSetting(OptionConstants.INDENT_INC, Integer.valueOf(2));
Utilities.invokeAndWait(new Runnable() {
public void run() {
doc.append(text, null);
pane.setCaretPosition(0);
pane.endCompoundEdit();
}
});
Utilities.clearEventQueue();
assertEquals("Should have inserted correctly.", text, doc.getText());
Utilities.invokeAndWait(new Runnable() {
public void run() { doc.indentLines(0, doc.getLength()); }
});
assertEquals("Should have indented.", indented, doc.getText());
Utilities.invokeAndWait(new Runnable() {
public void run() {
doc.getUndoManager().undo();
// System.err.println("New position is: " + pane.getCaretPosition());
}
});
assertEquals("Should have undone.", text, doc.getText());
// int rePos = doc.getCurrentLocation();
// System.err.println("Restored position is: " + rePos);
// cursor will be located at beginning of first line that is changed
// assertEquals("Undo should have restored cursor position.", oldPos, rePos);
Utilities.invokeAndWait(new Runnable() {
public void run() {
pane.setCaretPosition(newPos);
doc.getUndoManager().redo();
}
});
Utilities.clearEventQueue();
assertEquals("redo",indented, doc.getText());
// assertEquals("redo restores caret position", oldPos, pane.getCaretPosition());
_log.log("testMultilineIndentAfterScroll completed");
}
JScrollPane _pane1, _pane2;
DefinitionsPane _defPane1, _defPane2;
/** Ensure that a document's editable status is set appropriately throughout the compile process. Since the behavior
* is interesting only when the model changes its active document, that's what this test looks most like.
*/
public void testGlassPaneEditableState() {
SingleDisplayModel model = _frame.getModel();
final OpenDefinitionsDocument doc1 = model.newFile();
final OpenDefinitionsDocument doc2 = model.newFile();
// doc2 is now active
Utilities.invokeAndWait(new Runnable() {
public void run() {
_pane1 = _frame._createDefScrollPane(doc1);
_pane2 = _frame._createDefScrollPane(doc2);
_defPane1 = (DefinitionsPane) _pane1.getViewport().getView();
_defPane2 = (DefinitionsPane) _pane2.getViewport().getView();
_frame._switchDefScrollPane();
}
});
Utilities.clearEventQueue(); // Execute all pending asynchronous tasks;
assertTrue("Start: defPane1", _defPane1.isEditable());
assertTrue("Start: defPane2", _defPane2.isEditable());
Utilities.invokeAndWait(new Runnable() { public void run() { _frame.hourglassOn(); } });
Utilities.clearEventQueue();
assertTrue("Glass on: defPane1", _defPane1.isEditable());
assertTrue("Glass on: defPane2",(! _defPane2.isEditable()));
model.setActiveDocument(doc1);
Utilities.invokeAndWait(new Runnable() { public void run() { _frame._switchDefScrollPane(); } });
Utilities.clearEventQueue();
assertTrue("Doc Switch: defPane1",(! _defPane1.isEditable()));
assertTrue("Doc Switch: defPane2", _defPane2.isEditable());
Utilities.invokeAndWait(new Runnable() { public void run() { _frame.hourglassOff(); } });
Utilities.clearEventQueue();
assertTrue("End: defPane1", _defPane1.isEditable());
assertTrue("End: defPane2", _defPane2.isEditable());
_log.log("testGlassPaneEditableState completed");
}
private KeyEvent makeFindKeyEvent(Component c, long when) {
return new KeyEvent(c, KeyEvent.KEY_PRESSED, when, KeyEvent.CTRL_MASK, KeyEvent.VK_F, 'F');
}
/** Ensure that all key events are disabled when the glass pane is up. */
public void testGlassPaneHidesKeyEvents() {
SingleDisplayModel model = _frame.getModel();
final OpenDefinitionsDocument doc1 = model.newFile();
final OpenDefinitionsDocument doc2 = model.newFile();
// doc2 is now active
Utilities.invokeAndWait(new Runnable() {
public void run() {
_pane1 = _frame._createDefScrollPane(doc1);
_pane2 = _frame._createDefScrollPane(doc2);
_defPane1 = (DefinitionsPane) _pane1.getViewport().getView();
_defPane2 = (DefinitionsPane) _pane2.getViewport().getView();
_frame.validate();
_frame.hourglassOn();
_defPane1.processKeyEvent(makeFindKeyEvent(_defPane1, 70));
_frame.validate();
}
});
Utilities.clearEventQueue();
assertTrue("the find replace dialog should not come up", ! _frame.getFindReplaceDialog().isDisplayed());
Utilities.invokeAndWait(new Runnable() {
public void run() {
_frame.getInteractionsPane().processKeyEvent(makeFindKeyEvent(_frame.getInteractionsPane(), 0));
_frame.validate();
}
});
Utilities.clearEventQueue();
assertTrue("the find replace dialog should not come up", ! _frame.getFindReplaceDialog().isDisplayed());
Utilities.invokeAndWait(new Runnable() { public void run() { _frame.hourglassOff(); } });
_log.log("testGlassPaneHidesKeyEvents completed");
}
/** Tests that the save button does not set itself as enabled immediately after opening a file. */
public void testSaveButtonEnabled() throws IOException {
String user = System.getProperty("user.name");
_tempDir = IOUtil.createAndMarkTempDirectory("DrScala-test-" + user, "");
File forceOpenClass1_file = new File(_tempDir, "ForceOpenClass1.scala");
String forceOpenClass1_string =
"class ForceOpenClass1 {\n" +
" var class2: ForceOpenClass2 = null \n" +
" var class3: ForceOpenClass3 = null \n" +
" def ForceOpenClass1() {\n" +
" class2 = new ForceOpenClass2()\n" +
" class3 = new ForceOpenClass3()\n" +
" }\n" +
"}";
IOUtil.writeStringToFile(forceOpenClass1_file, forceOpenClass1_string);
forceOpenClass1_file.deleteOnExit();
//_frame.setVisible(true);
Utilities.invokeAndWait(new Runnable() {
public void run() {
_frame.pack();
_frame.open(new FileOpenSelector() {
public File[] getFiles() {
File[] return_me = new File[1];
return_me[0] = new File(_tempDir, "ForceOpenClass1.scala");
return return_me;
}
});
}
});
Utilities.clearEventQueue();
assertTrue("the save button should not be enabled after opening a document", !_frame.isSaveEnabled());
_log.log("testSaveButtonEnabled completed");
}
/** A Test to guarantee that the Dancing UI bug will not rear its ugly head again.
* Basically, add a component listener to the leftComponent of _docSplitPane and
* make certain its size does not change while compiling a class which depends on
* another class.
*/
public void testDancingUIFileOpened() throws IOException {
//System.out.println("DEBUG: Entering messed up test");
/** Maybe this sequence of calls should be incorporated into one function createTestDir(), which would get
* the username and create the temporary directory. Only sticky part is deciding where to put it, in FileOps
* maybe?
*/
_log.log("Starting testingDancingUIFileOpened");
final GlobalModel _model = _frame.getModel();
String user = System.getProperty("user.name");
_tempDir = IOUtil.createAndMarkTempDirectory("DrScala-test-" + user, "");
File forceOpenClass1_file = new File(_tempDir, "ForceOpenClass1.scala");
String forceOpenClass1_string =
"class ForceOpenClass1 {\n" +
" var class2: ForceOpenClass2 = null\n" +
" var class3: ForceOpenClass3 = null\n" +
" def ForceOpenClass1() {\n" +
" class2 = new ForceOpenClass2()\n" +
" class3 = new ForceOpenClass3()\n" +
" }\n" +
"}";
File forceOpenClass2_file = new File(_tempDir, "ForceOpenClass2.scala");
String forceOpenClass2_string =
"class ForceOpenClass2 {\n" +
" var x:inx = 4\n" +
"}";
File forceOpenClass3_file = new File(_tempDir, "ForceOpenClass3.java");
String forceOpenClass3_string =
"class ForceOpenClass3 {\n" +
" var s:String = \"asf\"\n" +
"}";
IOUtil.writeStringToFile(forceOpenClass1_file, forceOpenClass1_string);
IOUtil.writeStringToFile(forceOpenClass2_file, forceOpenClass2_string);
IOUtil.writeStringToFile(forceOpenClass3_file, forceOpenClass3_string);
forceOpenClass1_file.deleteOnExit();
forceOpenClass2_file.deleteOnExit();
forceOpenClass3_file.deleteOnExit();
_log.log("DancingUIFileOpened Set Up");
//_frame.setVisible(true);
// set up listeners and signal flags
final ComponentAdapter listener = new ComponentAdapter() {
public void componentResized(ComponentEvent event) {
_testFailed = true;
fail("testDancingUI: Open Documents List danced!");
}
};
final SingleDisplayModelFileOpenedListener openListener = new SingleDisplayModelFileOpenedListener();
final SingleDisplayModelCompileListener compileListener = new SingleDisplayModelCompileListener();
_openDone = false;
Utilities.invokeAndWait(new Runnable() {
public void run() {
// _frame.setVisible(true);
_frame.pack();
_frame.addComponentListenerToOpenDocumentsList(listener);
}
});
Utilities.clearEventQueue();
_model.addListener(openListener);
_log.log("opening file");
Utilities.invokeLater(new Runnable() {
public void run() {
_frame.open(new FileOpenSelector() {
public File[] getFiles() {
File[] return_me = new File[1];
return_me[0] = new File(_tempDir, "ForceOpenClass1.scala");
return return_me;
}
});
}
});
Utilities.clearEventQueue();
/* wait until file has been open and active document changed. */
synchronized(_openLock) {
try { while (! _openDone) _openLock.wait(); }
catch(InterruptedException e) { fail(e.toString()); }
}
_model.removeListener(openListener);
_log.log("File opened");
_compileDone = false;
_model.addListener(compileListener);
// save and compile the new file asynchronously
Utilities.invokeLater(new Runnable() {
public void run() {
_log.log("saving all files");
_frame._saveAll();
_log.log("invoking compileAll action");
_frame.getCompileAllButton().doClick();
}
});
Utilities.clearEventQueue();
synchronized(_compileLock) {
try { while (! _compileDone) _compileLock.wait(); }
catch(InterruptedException e) { fail(e.toString()); }
}
_log.log("File saved and compiled");
if (! IOUtil.deleteRecursively(_tempDir))
System.out.println("Couldn't fully delete directory " + _tempDir.getAbsolutePath() + "\nDo it by hand.\n");
_log.log("testDancingUIFileOpened completed");
}
/** A Test to guarantee that the Dancing UI bug will not rear its ugly head again. Basically, add a component listener
* to the leftComponent of _docSplitPane and make certain its size does not change while closing an
* OpenDefinitionsDocument outside the event thread.
*/
public void testDancingUIFileClosed() throws IOException {
/** Maybe this sequence of calls should be incorporated into one function createTestDir(), which would get the
* username and create the temporary directory. Only sticky part is deciding where to put it, in FileOps maybe?
*/
String user = System.getProperty("user.name");
_tempDir = IOUtil.createAndMarkTempDirectory("DrScala-test-" + user, "");
File forceOpenClass1_file = new File(_tempDir, "ForceOpenClass1.scala");
String forceOpenClass1_string =
"class ForceOpenClass1 {\n" +
" var class2: ForceOpenClass2 = null\n" +
" var class3: ForceOpenClass3 = null\n" +
" def ForceOpenClass1() {\n" +
" var class2 = new ForceOpenClass2()\n" +
" var class3 = new ForceOpenClass3()\n" +
" }\n" +
"}";
IOUtil.writeStringToFile(forceOpenClass1_file, forceOpenClass1_string);
forceOpenClass1_file.deleteOnExit();
final ComponentAdapter listener = new ComponentAdapter() {
public void componentResized(ComponentEvent event) {
_testFailed = true;
fail("testDancingUI: Open Documents List danced!");
}
};
final SingleDisplayModelFileClosedListener closeListener = new SingleDisplayModelFileClosedListener();
_closeDone = false;
Utilities.invokeAndWait(new Runnable() {
public void run() {
// _frame.setVisible(true);
_frame.pack();
_frame.addComponentListenerToOpenDocumentsList(listener);
_frame.open(new FileOpenSelector() {
public File[] getFiles() {
File[] return_me = new File[1];
return_me[0] = new File(_tempDir, "ForceOpenClass1.scala");
return return_me;
}
});
_frame.getModel().addListener(closeListener);
}
});
Utilities.clearEventQueue();
/* Asynchronously close the file */
Utilities.invokeLater(new Runnable() {
public void run() { _frame.getCloseButton().doClick(); }
});
_log.log("Waiting for file closing");
synchronized(_closeLock) {
try { while (! _closeDone) _closeLock.wait(); }
catch(InterruptedException e) { fail(e.toString()); }
}
if (! IOUtil.deleteRecursively(_tempDir)) {
System.out.println("Couldn't fully delete directory " + _tempDir.getAbsolutePath() + "\nDo it by hand.\n");
}
_log.log("testDancingUIFileClosed completed");
}
/** A CompileListener for SingleDisplayModel (instead of GlobalModel) */
class SingleDisplayModelCompileListener extends GlobalModelTestCase.TestListener implements GlobalModelListener {
@Override public void compileStarted() { }
/** Just notify when the compile has ended */
@Override public void compileEnded(File workDir, List<? extends File> excludedFiles) {
synchronized(_compileLock) {
_compileDone = true;
_compileLock.notify();
}
}
@Override public void fileOpened(OpenDefinitionsDocument doc) { }
@Override public void activeDocumentChanged(OpenDefinitionsDocument active) { }
}
/** A FileClosedListener for SingleDisplayModel (instead of GlobalModel) */
class SingleDisplayModelFileOpenedListener extends GlobalModelTestCase.TestListener implements GlobalModelListener {
@Override public void fileClosed(OpenDefinitionsDocument doc) { }
@Override public void fileOpened(OpenDefinitionsDocument doc) { }
@Override public void newFileCreated(OpenDefinitionsDocument doc) { }
@Override public void activeDocumentChanged(OpenDefinitionsDocument doc) {
synchronized(_openLock) {
_openDone = true;
_openLock.notify();
}
}
}
/** A FileClosedListener for SingleDisplayModel (instead of GlobalModel) */
class SingleDisplayModelFileClosedListener extends GlobalModelTestCase.TestListener implements GlobalModelListener {
@Override public void fileClosed(OpenDefinitionsDocument doc) {
synchronized(_closeLock) {
_closeDone = true;
_closeLock.notify();
}
}
@Override public void fileOpened(OpenDefinitionsDocument doc) { }
@Override public void newFileCreated(OpenDefinitionsDocument doc) { }
@Override public void activeDocumentChanged(OpenDefinitionsDocument active) { }
}
/** Create a new temporary file in _tempDir. */
protected File tempFile(String fileName) throws IOException {
File f = File.createTempFile(fileName, ".scala", _tempDir).getCanonicalFile();
f.deleteOnExit();
return f;
}
/** Tests that "go to file under cursor" works if unique. */
public void testGotoFileUnderCursor() throws IOException {
// Utilities.show("Running testGotoFileUnderCursor");
String user = System.getProperty("user.name");
_tempDir = IOUtil.createAndMarkTempDirectory("DrScala-test-" + user, "");
final File goto1_file = new File(_tempDir, "GotoFileUnderCursor1.scala");
final String goto1_string = "GotoFileUnderCursorTest";
IOUtil.writeStringToFile(goto1_file, goto1_string);
goto1_file.deleteOnExit();
final File goto2_file = new File(_tempDir, "GotoFileUnderCursorTest.scala");
String goto2_string = "GotoFileUnderCursor1";
IOUtil.writeStringToFile(goto2_file, goto2_string);
goto2_file.deleteOnExit();
Utilities.invokeAndWait(new Runnable() {
public void run() {
_frame.pack();
_frame.open(new FileOpenSelector() {
public File[] getFiles() { return new File[] { goto1_file, goto2_file }; }
});
}
});
Utilities.invokeAndWait(new Runnable() {
public void run() {
_frame.initGotoFileDialog();
_frame._gotoFileDialog.addWindowListener(new WindowListener() {
public void windowActivated(WindowEvent e) { throw new RuntimeException("Should not activate _gotoFileDialog"); }
public void windowClosed(WindowEvent e) { throw new RuntimeException("Should not close _gotoFileDialog"); }
public void windowClosing(WindowEvent e) { throw new RuntimeException("Should not be closing _gotoFileDialog"); }
public void windowDeactivated(WindowEvent e) { throw new RuntimeException("Should not deactivate _gotoFileDialog"); }
public void windowDeiconified(WindowEvent e) { throw new RuntimeException("Should not deiconify _gotoFileDialog"); }
public void windowIconified(WindowEvent e) { throw new RuntimeException("Should not iconify _gotoFileDialog"); }
public void windowOpened(WindowEvent e) { throw new RuntimeException("Should not open _gotoFileDialog"); }
});
}});
Utilities.clearEventQueue();
Utilities.invokeAndWait(new Runnable() { public void run() {
SingleDisplayModel model = _frame.getModel();
try {
OpenDefinitionsDocument goto1_doc = model.getDocumentForFile(goto1_file);
OpenDefinitionsDocument goto2_doc = model.getDocumentForFile(goto2_file);
model.setActiveDocument(model.getDocumentForFile(goto1_file));
assertEquals("Document contains the incorrect text", goto1_string, model.getActiveDocument().getText());
_frame._gotoFileUnderCursor();
assertEquals("Incorrect active document; did not go to?", goto2_doc, model.getActiveDocument());
_frame._gotoFileUnderCursor();
assertEquals("Incorrect active document; did not go to?", goto1_doc, model.getActiveDocument());
}
catch(IOException ioe) { throw new UnexpectedException(ioe); }
} });
_log.log("gotoFileUnderCursor completed");
}
/** Tests that "go to file under cursor" works if unique after appending ".scala" */
public void testGotoFileUnderCursorAppendJava() throws IOException {
String user = System.getProperty("user.name");
_tempDir = IOUtil.createAndMarkTempDirectory("DrScala-test-" + user, "");
final File goto1_file = new File(_tempDir, "GotoFileUnderCursor2Test.scala");
final String goto1_string = "GotoFileUnderCursor2";
IOUtil.writeStringToFile(goto1_file, goto1_string);
goto1_file.deleteOnExit();
final File goto2_file = new File(_tempDir, "GotoFileUnderCursor2.scala");
String goto2_string = "GotoFileUnderCursor2Test";
IOUtil.writeStringToFile(goto2_file, goto2_string);
goto2_file.deleteOnExit();
Utilities.invokeAndWait(new Runnable() {
public void run() {
_frame.pack();
_frame.open(new FileOpenSelector() {
public File[] getFiles() {
return new File[] { goto1_file, goto2_file };
}
});
}
});
Utilities.clearEventQueue();
Utilities.invokeAndWait(new Runnable() {
public void run() {
_frame.initGotoFileDialog();
_frame._gotoFileDialog.addWindowListener(new WindowListener() {
public void windowActivated(WindowEvent e) { throw new RuntimeException("Should not activate _gotoFileDialog"); }
public void windowClosed(WindowEvent e) { throw new RuntimeException("Should not close _gotoFileDialog"); }
public void windowClosing(WindowEvent e) { throw new RuntimeException("Should not be closing _gotoFileDialog"); }
public void windowDeactivated(WindowEvent e) { throw new RuntimeException("Should not deactivate _gotoFileDialog"); }
public void windowDeiconified(WindowEvent e) { throw new RuntimeException("Should not deiconify _gotoFileDialog"); }
public void windowIconified(WindowEvent e) { throw new RuntimeException("Should not iconify _gotoFileDialog"); }
public void windowOpened(WindowEvent e) { throw new RuntimeException("Should not open _gotoFileDialog"); }
});
}});
Utilities.clearEventQueue();
Utilities.invokeAndWait(new Runnable() { public void run() {
SingleDisplayModel model = _frame.getModel();
try {
OpenDefinitionsDocument goto1_doc = model.getDocumentForFile(goto1_file);
OpenDefinitionsDocument goto2_doc = model.getDocumentForFile(goto2_file);
model.setActiveDocument(model.getDocumentForFile(goto1_file));
assertEquals("Document contains the incorrect text", goto1_string, model.getActiveDocument().getText());
_frame._gotoFileUnderCursor();
assertEquals("Incorrect active document; did not go to?", goto2_doc, model.getActiveDocument());
_frame._gotoFileUnderCursor();
assertEquals("Incorrect active document; did not go to?", goto1_doc, model.getActiveDocument());
}
catch(IOException ioe) { throw new UnexpectedException(ioe); }
} });
_log.log("gotoFileUnderCursorAppendJava completed");
}
/** Tests that "go to file under cursor" displays the dialog if choice is not unique */
public void testGotoFileUnderCursorShowDialog() throws IOException {
// Utilities.show("Running testGotoFileUnderCursorShowDialog()");
String user = System.getProperty("user.name");
_tempDir = IOUtil.createAndMarkTempDirectory("DrScala-test-" + user, "");
final File goto1_file = new File(_tempDir, "GotoFileUnderCursor3.scala");
final String goto1_string = "GotoFileUnderCursor";
IOUtil.writeStringToFile(goto1_file, goto1_string);
goto1_file.deleteOnExit();
final File goto2_file = new File(_tempDir, "GotoFileUnderCursor4.scala");
String goto2_string = "GotoFileUnderCursor3";
IOUtil.writeStringToFile(goto2_file, goto2_string);
goto2_file.deleteOnExit();
Utilities.invokeAndWait(new Runnable() {
public void run() {
_frame.pack();
_frame.open(new FileOpenSelector() {
public File[] getFiles() { return new File[] { goto1_file, goto2_file }; }
});
}
});
final int[] count = new int[2];
Utilities.invokeAndWait(new Runnable() {
public void run() {
_frame.initGotoFileDialog();
_frame._gotoFileDialog.addWindowListener(new WindowListener() {
public void windowActivated(WindowEvent e) { ++count[0]; }
public void windowClosed(WindowEvent e) { throw new RuntimeException("Should not close _gotoFileDialog"); }
public void windowClosing(WindowEvent e) { throw new RuntimeException("Should not be closing _gotoFileDialog"); }
public void windowDeactivated(WindowEvent e) { /* throw new RuntimeException("Should not deactivate _gotoFileDialog"); */ }
public void windowDeiconified(WindowEvent e) { throw new RuntimeException("Should not deiconify _gotoFileDialog"); }
public void windowIconified(WindowEvent e) { throw new RuntimeException("Should not iconify _gotoFileDialog"); }
public void windowOpened(WindowEvent e) { ++count[1]; }
});
}
});
Utilities.clearEventQueue();
Utilities.invokeAndWait(new Runnable() { public void run() {
SingleDisplayModel model = _frame.getModel();
try {
model.setActiveDocument(model.getDocumentForFile(goto1_file));
assertEquals("Document contains the incorrect text", goto1_string, model.getActiveDocument().getText());
}
catch(IOException ioe) { throw new UnexpectedException(ioe); }
} });
Utilities.invokeAndWait(new Runnable() { public void run() { _frame._gotoFileUnderCursor(); } });
Utilities.clearEventQueue(); // wait for any asynchronous actions to complete
/* The following test was commented out before test following it was. It presumably fails even if
* the "MainFrame.this.isVisible()" test mentioned below is removed from _gotoFileUnderCursor */
// assertEquals("Did not activate _gotoFileDialog", 1, count[0]);
/* The following test was commented out after suppressing this display when _frame is not visible. If it is
* uncommented, then the "MainFrame.this.isVisible()" test in _gotoFileDialog must be removed. */
// assertEquals("Did not open _gotoFileDialog", 1, count[1]);
_log.log("gotoFileUnderCursorShowDialog completed");
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.