KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > search_replace > SearchAndReplaceTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package search_replace;
21
22 import java.awt.event.KeyEvent JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.io.PrintStream JavaDoc;
28 import java.util.Hashtable JavaDoc;
29 import javax.swing.SwingUtilities JavaDoc;
30 import javax.swing.text.BadLocationException JavaDoc;
31 import javax.swing.text.Document JavaDoc;
32 import org.netbeans.jellytools.EditorOperator;
33 import org.netbeans.jellytools.actions.FindAction;
34 import org.netbeans.jellytools.modules.editor.Find;
35 import org.netbeans.jemmy.operators.JEditorPaneOperator;
36
37 /**
38  * Basic Editor Find and Replace Tests
39  *
40  * @author Martin Roskanin
41  */

42
43
44 public class SearchAndReplaceTest extends lib.EditorTestCase{
45     
46     // private PrintStream wrapper for System.out
47
private PrintStream JavaDoc systemOutPSWrapper = new PrintStream JavaDoc(System.out);
48     private int index = 0;
49     private EditorOperator editor;
50     private JEditorPaneOperator txtOper;
51     private int WAIT_MAX_MILIS_FOR_FIND_OPERATION = 5000;
52     
53     public static final int NO_OPERATION = 0x00000000;
54     public static final int MATCH_CASE = 0x00000001;
55     public static final int WHOLE_WORDS = 0x00000002;
56     public static final int REGULAR_EXPRESSIONS = 0x00000004;
57     public static final int HIGHLIGHT_RESULTS = 0x00000008;
58     public static final int WRAP_AROUND = 0x00000010;
59     public static final int SEARCH_SELECTION = 0x00000020;
60     public static final int SEARCH_BACKWARDS = 0x00000040;
61     public static final int INCREMENTAL_SEARCH = 0x00000080;
62     public static final int ALL_UNCHECKED = 0x10000000;
63     public static final int NO_RESET = 0x20000000;
64     public static final int NO_RESET_SEARCH_SELECTION = 0x40000000;
65     
66     /** Creates a new instance of Main */
67     public SearchAndReplaceTest(String JavaDoc testMethodName) {
68         super(testMethodName);
69     }
70     
71     private String JavaDoc getIndexAsString(){
72         String JavaDoc ret = String.valueOf(index);
73         if (ret.length() == 1) ret = "0" + ret;
74         return ret;
75     }
76     
77     private String JavaDoc getRefFileName(){
78         return this.getName()+getIndexAsString()+".ref"; //NOI18N
79
}
80     
81     private String JavaDoc getGoldenFileName(){
82         return this.getName()+getIndexAsString()+".pass"; //NOI18N
83
}
84     
85     private String JavaDoc getDiffFileName(){
86         return this.getName()+getIndexAsString()+".diff"; //NOI18N
87
}
88     
89     // hashtable holding all already used logs and correspondig printstreams
90
private Hashtable JavaDoc logStreamTable = null;
91     
92     private PrintStream JavaDoc getFileLog(String JavaDoc logName) throws IOException JavaDoc {
93         OutputStream JavaDoc outputStream;
94         FileOutputStream JavaDoc fileOutputStream;
95         
96         if ((logStreamTable == null)|(hasTestMethodChanged())) {
97             // we haven't used logging capability - create hashtables
98
logStreamTable = new Hashtable JavaDoc();
99             //System.out.println("Created new hashtable");
100
} else {
101             if (logStreamTable.containsKey(logName)) {
102                 //System.out.println("Getting stream from cache:"+logName);
103
return (PrintStream JavaDoc)logStreamTable.get(logName);
104             }
105         }
106         // we didn't used this log, so let's create it
107
FileOutputStream JavaDoc fileLog = new FileOutputStream JavaDoc(new File JavaDoc(getWorkDir(),logName));
108         PrintStream JavaDoc printStreamLog = new PrintStream JavaDoc(fileLog,true);
109         logStreamTable.put(logName,printStreamLog);
110         //System.out.println("Created new stream:"+logName);
111
return printStreamLog;
112     }
113     
114     private String JavaDoc lastTestMethod=null;
115     
116     private boolean hasTestMethodChanged() {
117         if (!this.getName().equals(lastTestMethod)) {
118             lastTestMethod=this.getName();
119             return true;
120         } else {
121             return false;
122         }
123     }
124     
125     public PrintStream JavaDoc getRef() {
126         String JavaDoc refFilename = getRefFileName();
127         try {
128             return getFileLog(refFilename);
129         } catch (IOException JavaDoc ioe) {
130             // canot get ref file - return system.out
131
//System.err.println("Test method "+this.getName()+" - cannot open ref file:"+refFilename
132
// +" - defaulting to System.out and failing test");
133
fail("Could not open reference file: "+refFilename);
134             return systemOutPSWrapper;
135         }
136     }
137     
138     protected void compareToGoldenFile(Document JavaDoc testDoc){
139         try {
140             ref(testDoc.getText(0, testDoc.getLength()));
141             compareReferenceFiles(getRefFileName(), getGoldenFileName(), getDiffFileName());
142             index++;
143         } catch (BadLocationException JavaDoc e) {
144             e.printStackTrace(getLog());
145             fail();
146         }
147     }
148     
149     private void resetFindProperties(Find find, boolean resetSearchSelection){
150         find.cbMatchCase().setSelected(false);
151         find.cbMatchWholeWordsOnly().setSelected(false);
152         find.cbRegularExpressions().setSelected(false);
153         find.cbHighlightSearch().setSelected(false);
154         find.cbWrapSearch().setSelected(false);
155         if (resetSearchSelection) {
156             find.cbBlockSearch().setSelected(false);
157         }
158         find.cbBackwardSearch().setSelected(false);
159         find.cbIncrementalSearch().setSelected(false);
160         find.cboFindWhat().clearText();
161     }
162     
163     protected Find openFindDialog(String JavaDoc text, int modifiers){
164         new FindAction().perform();
165         Find find = new Find();
166         if (modifiers != 0 && (modifiers & NO_RESET) == 0) {
167             resetFindProperties(find, (modifiers & NO_RESET_SEARCH_SELECTION) == 0);
168         }
169         if ((modifiers & MATCH_CASE) != 0){
170             find.cbMatchCase().setSelected(true);
171         }
172         if ((modifiers & WHOLE_WORDS) != 0){
173             find.cbMatchWholeWordsOnly().setSelected(true);
174         }
175         if ((modifiers & REGULAR_EXPRESSIONS) != 0){
176             find.cbRegularExpressions().setSelected(true);
177         }
178         if ((modifiers & HIGHLIGHT_RESULTS) != 0){
179             find.cbHighlightSearch().setSelected(true);
180         }
181         if ((modifiers & WRAP_AROUND) != 0){
182             find.cbWrapSearch().setSelected(true);
183         }
184         if ((modifiers & SEARCH_SELECTION) != 0){
185             find.cbBlockSearch().setSelected(true);
186         }
187         if ((modifiers & SEARCH_BACKWARDS) != 0){
188             find.cbBackwardSearch().setSelected(true);
189         }
190         if ((modifiers & INCREMENTAL_SEARCH) != 0){
191             find.cbIncrementalSearch().setSelected(true);
192         }
193         find.cboFindWhat().clearText();
194         if (text != null){
195             find.cboFindWhat().typeText(text);
196         }
197         return find;
198     }
199     
200     private ValueResolver getSelectionResolver(final JEditorPaneOperator txtOper, final int startEtalon, final int endEtalon){
201         
202         ValueResolver clipboardValueResolver = new ValueResolver(){
203             public Object JavaDoc getValue(){
204                 int selectionStart = txtOper.getSelectionStart();
205                 int selectionEnd = txtOper.getSelectionEnd();
206                 if (selectionStart == selectionEnd){
207                     selectionStart = -1;
208                     selectionEnd = -1;
209                 }
210                 if (selectionStart != startEtalon || selectionEnd != endEtalon){
211                     return Boolean.FALSE;
212                 } else {
213                     return Boolean.TRUE;
214                 }
215             }
216         };
217         
218         return clipboardValueResolver;
219     }
220     
221     private ValueResolver getIncFindResolver(final JEditorPaneOperator txtOper, final int startEtalon, final int endEtalon){
222         
223         ValueResolver clipboardValueResolver = new ValueResolver(){
224             public Object JavaDoc getValue(){
225                 org.netbeans.editor.BaseTextUI ui = (org.netbeans.editor.BaseTextUI)txtOper.getUI();
226                 org.netbeans.editor.EditorUI editorUI = ui.getEditorUI();
227                 org.netbeans.editor.DrawLayerFactory.IncSearchLayer incLayer
228                         = (org.netbeans.editor.DrawLayerFactory.IncSearchLayer)editorUI.findLayer(
229                         org.netbeans.editor.DrawLayerFactory.INC_SEARCH_LAYER_NAME);
230                 int selectionStart = -1;
231                 int selectionEnd = -1;
232                 if (incLayer == null) {
233                     return Boolean.FALSE;
234                 } else {
235                     if (incLayer.isEnabled()) {
236                         selectionStart = incLayer.getOffset();
237                         selectionEnd = selectionStart + incLayer.getLength();
238                     }
239                 }
240                 if (selectionStart == selectionEnd){
241                     selectionStart = -1;
242                     selectionEnd = -1;
243                 }
244                 if (selectionStart != startEtalon || selectionEnd != endEtalon){
245                     return Boolean.FALSE;
246                 } else {
247                     return Boolean.TRUE;
248                 }
249             }
250         };
251         
252         return clipboardValueResolver;
253     }
254     
255     
256     protected boolean find(String JavaDoc text, int modifiers, int startEtalon, int endEtalon, int setCaretPos){
257         if (setCaretPos > -1){
258             txtOper.setCaretPosition(setCaretPos);
259         }
260         Find find = openFindDialog(text, modifiers);
261         find.find();
262         waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION, getSelectionResolver(txtOper, startEtalon, endEtalon), Boolean.TRUE);
263         int selectionStart = txtOper.getSelectionStart();
264         int selectionEnd = txtOper.getSelectionEnd();
265         if (selectionStart == selectionEnd){
266             selectionEnd = -1;
267             selectionStart = -1;
268         }
269         if (selectionStart != startEtalon || selectionEnd != endEtalon){
270             log("--------------------------------------------------");
271             log("Find operation failed. Selected text: "+selectionStart+" - "+selectionEnd+" >>> Expected values: "+startEtalon+" - "+endEtalon);
272             log("find dialog find what combo value:"+find.cboFindWhat().getEditor().getItem());
273             log("checkboxes:"+
274                     "\n cbBackwardSearch:"+find.cbBackwardSearch().isSelected()+
275                     "\n cbBlockSearch:"+find.cbBlockSearch().isSelected()+
276                     "\n cbHighlightSearch:"+find.cbHighlightSearch().isSelected()+
277                     "\n cbIncrementalSearch:"+find.cbIncrementalSearch().isSelected()+
278                     "\n cbMatchCase:"+find.cbMatchCase().isSelected()+
279                     "\n cbMatchWholeWordsOnly:"+find.cbMatchWholeWordsOnly().isSelected()+
280                     "\n cbRegularExpressions:"+find.cbRegularExpressions().isSelected()+
281                     "\n cbWrapSearch:"+find.cbWrapSearch().isSelected()
282                     );
283             log("--------------------------------------------------");
284             fail("Find operation failed. Selected text: "+selectionStart+" - "+selectionEnd+" >>> Expected values: "+startEtalon+" - "+endEtalon); //NOI18N
285
find.close();
286             return false;
287         }
288         find.close();
289         return true;
290     }
291     
292     private void checkIncrementalSearch(Find find, String JavaDoc s, int startEtalon, int endEtalon){
293         // Checking Disabled - the new highlighting SPI will be used so the draw layer's data should not be checked directly.
294
if (true)
295             return;
296         
297         find.cboFindWhat().typeText(s);
298         
299         waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION, getIncFindResolver(txtOper, startEtalon, endEtalon), Boolean.TRUE);
300         
301         int selectionStart = -1;
302         int selectionEnd = -1;
303         
304         org.netbeans.editor.BaseTextUI ui = (org.netbeans.editor.BaseTextUI)txtOper.getUI();
305         org.netbeans.editor.EditorUI editorUI = ui.getEditorUI();
306         org.netbeans.editor.DrawLayerFactory.IncSearchLayer incLayer
307                 = (org.netbeans.editor.DrawLayerFactory.IncSearchLayer)editorUI.findLayer(
308                 org.netbeans.editor.DrawLayerFactory.INC_SEARCH_LAYER_NAME);
309         if (incLayer == null) {
310             System.out.println("fail: layer not initialized");
311         } else {
312             if (incLayer.isEnabled()) {
313                 selectionStart = incLayer.getOffset();
314                 selectionEnd = selectionStart + incLayer.getLength();
315             }
316         }
317         
318         if (selectionStart == selectionEnd){
319             selectionEnd = -1;
320             selectionStart = -1;
321         }
322         if (selectionStart != startEtalon || selectionEnd != endEtalon){
323             fail("Incremental find operation failed. Selected text: "+selectionStart+" - "+selectionEnd+" >>> Expected values: "+startEtalon+" - "+endEtalon); //NOI18N
324
}
325     }
326     
327     private void preselect(JEditorPaneOperator txtOper, int start, int end){
328         txtOper.setSelectionStart(start);
329         txtOper.setSelectionEnd(end);
330     }
331     
332     private void checkSelection(JEditorPaneOperator txtOper, int startEtalon, int endEtalon, String JavaDoc errorMessage){
333         waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION, getSelectionResolver(txtOper, startEtalon, endEtalon), Boolean.TRUE);
334         int selectionStart = txtOper.getSelectionStart();
335         int selectionEnd = txtOper.getSelectionEnd();
336         if (selectionStart == selectionEnd){
337             selectionStart = -1;
338             selectionEnd = -1;
339         }
340         if (selectionStart != startEtalon || selectionEnd != endEtalon){
341             fail(errorMessage+" Selected text: "+selectionStart+" - "+selectionEnd+" >>> Expected values: "+startEtalon+" - "+endEtalon); //NOI18N
342
}
343     }
344     
345     public void testSearch(){
346         openDefaultProject();
347         openDefaultSampleFile();
348         try {
349             editor = getDefaultSampleEditorOperator();
350             txtOper = editor.txtEditorPane();
351             
352             find("searchText", ALL_UNCHECKED, 161, 171, 0);
353             find("SeArCHText", MATCH_CASE, 175, 185, 0);
354             find("SeArCHText", WHOLE_WORDS, 275, 285, 206);
355             find("SeArCHText", MATCH_CASE | WHOLE_WORDS, 289, 299, 206);
356             find("SeArCHText", SEARCH_BACKWARDS, 341, 351, 352);
357             find("SeArCHText", SEARCH_BACKWARDS | MATCH_CASE, 289, 299, 352);
358             find("search", SEARCH_BACKWARDS | WHOLE_WORDS, 318, 324, 352);
359             find("search", SEARCH_BACKWARDS | MATCH_CASE | WHOLE_WORDS, 311, 317, 352);
360             find("insert", SEARCH_BACKWARDS | WRAP_AROUND, 86, 92, 86);
361             find("insert", SEARCH_BACKWARDS, -1, -1, 86);
362             
363             //incremental search
364
txtOper.setCaretPosition(328);
365             Find find = openFindDialog(null, INCREMENTAL_SEARCH);
366             checkIncrementalSearch(find, "t", 328, 329);
367             checkIncrementalSearch(find, "e", 330, 332);
368             checkIncrementalSearch(find, "x", 330, 333);
369             checkIncrementalSearch(find, "t", 330, 334);
370             checkIncrementalSearch(find, "x", 429, 434);
371             checkIncrementalSearch(find, "y", -1, -1); // inc should fail
372
find.close();
373             
374             //incremental search backwards + Match case
375
txtOper.setCaretPosition(328);
376             find = openFindDialog(null, INCREMENTAL_SEARCH | MATCH_CASE | SEARCH_BACKWARDS);
377             checkIncrementalSearch(find, "s", 311, 312);
378             checkIncrementalSearch(find, "e", 311, 313);
379             checkIncrementalSearch(find, "a", 311, 314);
380             checkIncrementalSearch(find, "r", 311, 315);
381             checkIncrementalSearch(find, "c", 311, 316);
382             checkIncrementalSearch(find, "h", 311, 317);
383             checkIncrementalSearch(find, "T", 275, 282);
384             checkIncrementalSearch(find, "e", 275, 283);
385             checkIncrementalSearch(find, "x", 275, 284);
386             checkIncrementalSearch(find, "T", -1, -1);
387             find.close();
388             
389             //#53536 - CTRL-F & friends cancel selection
390
txtOper.setSelectionStart(1);
391             txtOper.setSelectionEnd(100);
392             // NO_OPERATION - no check box reset, no checkbox set by default.
393
final Find blockFind = openFindDialog(null, NO_OPERATION);
394             
395             // check if the "search selection" checkbox was checked
396
waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION, new ValueResolver(){
397                 public Object JavaDoc getValue(){
398                     return Boolean.valueOf(blockFind.cbBlockSearch().isSelected());
399                 }
400             }, Boolean.TRUE);
401             if (!blockFind.cbBlockSearch().isSelected()){
402                 fail("Search Selection checkbox was not checked automaticaly after invoking " +
403                         "Find dialog over selected text"); //NOI18N
404
}
405             
406             blockFind.close();
407             // Selection made before Find dialog invocation gets lost.
408
// Either a searched text was found and the found text gets selected
409
// or the searched text is not found and then no selection is done.
410
// The selection is only retained in case there was nothing typed into the "find what" field
411

412             //checkSelection(txtOper, 1, 100, "Issue #53536 testing failed!");
413

414             //test find in selection
415
find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
416
find.close();
417             preselect(txtOper, 46, 132);
418             // make sure that text outside the selection is not found
419
find("searchText", NO_OPERATION, -1, -1, -1);
420             
421             // selection begins at ublic. 'p' is not selected. Next public
422
// should be found
423
preselect(txtOper, 47, 123);
424             find("public", NO_RESET, 105, 111, -1);
425             
426             preselect(txtOper, 161, 544);
427             find("SeArCHText", NO_RESET_SEARCH_SELECTION | MATCH_CASE, 175, 185, -1);
428             preselect(txtOper, 206, 544);
429             find("SeArCHText", NO_RESET_SEARCH_SELECTION | WHOLE_WORDS, 275, 285, -1);
430             preselect(txtOper, 206, 544);
431             find("SeArCHText", NO_RESET_SEARCH_SELECTION | MATCH_CASE | WHOLE_WORDS, 289, 299, -1);
432             preselect(txtOper, 161, 544);
433             find("searchText", NO_RESET_SEARCH_SELECTION | SEARCH_BACKWARDS, 469, 479, -1);
434             preselect(txtOper, 161, 544);
435             find("searchText", NO_RESET_SEARCH_SELECTION | SEARCH_BACKWARDS | MATCH_CASE, 455, 465, -1);
436             preselect(txtOper, 161, 544);
437             find("search", NO_RESET_SEARCH_SELECTION | SEARCH_BACKWARDS | WHOLE_WORDS, 318, 324, -1);
438             preselect(txtOper, 161, 544);
439             find("search", NO_RESET_SEARCH_SELECTION | SEARCH_BACKWARDS | MATCH_CASE | WHOLE_WORDS, 311, 317, -1);
440             
441             // wrap around block forwardSearch testing
442
find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
443
find.close();
444             preselect(txtOper, 409, 465);
445             find = openFindDialog("searchText", NO_OPERATION); // search selection should be checked automatically
446
find.find();
447             checkSelection(txtOper, 410, 420, "Wrap around block testing failed!");
448             find.find();
449             checkSelection(txtOper, 423, 433, "Wrap around block testing failed!");
450             find.find();
451             checkSelection(txtOper, 455, 465, "Wrap around block testing failed!");
452             find.find();
453             checkSelection(txtOper, -1, -1, "Wrap around block testing failed!"); // should find, because wrap around is not checked yet
454
find.cbWrapSearch().setSelected(true);
455             find.find();
456             checkSelection(txtOper, 410, 420, "Wrap around block testing failed!");
457             find.close();
458             
459             // wrap around block bacwardSearch testing
460
find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
461
find.close();
462             preselect(txtOper, 409, 465);
463             find = openFindDialog("searchText", NO_RESET_SEARCH_SELECTION | SEARCH_BACKWARDS);
464             find.find();
465             checkSelection(txtOper, 455, 465, "Wrap around block testing failed!");
466             find.find();
467             checkSelection(txtOper, 423, 433, "Wrap around block testing failed!");
468             find.find();
469             checkSelection(txtOper, 410, 420, "Wrap around block testing failed!");
470             find.find();
471             checkSelection(txtOper, -1, -1, "Wrap around block testing failed!"); // should find, because wrap around is not checked yet
472
find.cbWrapSearch().setSelected(true);
473             find.find();
474             checkSelection(txtOper, 455, 465, "Wrap around block testing failed!");
475             find.close();
476             
477             //incremental search in selected block
478
find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
479
find.close();
480             preselect(txtOper, 325, 360);
481             find = openFindDialog(null, NO_RESET_SEARCH_SELECTION | INCREMENTAL_SEARCH);
482             checkIncrementalSearch(find, "t", 325, 326);
483             checkIncrementalSearch(find, "e", 325, 327);
484             checkIncrementalSearch(find, "x", 325, 328);
485             checkIncrementalSearch(find, "t", 325, 329);
486             checkIncrementalSearch(find, "x", -1, -1); // inc should fail
487
find.close();
488             
489             //incremental search backwards + Match case in selected block
490
find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
491
find.close();
492             preselect(txtOper, 251 , 350);
493             find = openFindDialog(null, NO_RESET_SEARCH_SELECTION | INCREMENTAL_SEARCH | MATCH_CASE | SEARCH_BACKWARDS);
494             checkIncrementalSearch(find, "T", 347, 348);
495             checkIncrementalSearch(find, "e", 347, 349);
496             checkIncrementalSearch(find, "x", 347, 350);
497             checkIncrementalSearch(find, "t", 295, 299);
498             checkIncrementalSearch(find, "X", -1, -1); // fails - behind selected area
499
find.close();
500         } finally {
501             closeFileWithDiscard();
502         }
503     }
504     
505     public void testSearch2(){
506         openDefaultProject();
507         openDefaultSampleFile();
508         Find find;
509         try {
510             editor = getDefaultSampleEditorOperator();
511             txtOper = editor.txtEditorPane();
512             
513             //#52115
514
// firstly try CTRL+V
515
editor.setCaretPosition(16, 9); //word "search"
516
txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK);
517             cutCopyViaStrokes(txtOper, KeyEvent.VK_C, KeyEvent.CTRL_MASK);
518             editor.setCaretPosition(1, 1);
519             find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
520
find.cboFindWhat().requestFocus(); // [temp] failing tests on SunOS & Linux
521
waitForAWTThread();
522             pasteViaStrokes(find, KeyEvent.VK_V, KeyEvent.CTRL_MASK, null);
523             waitForAWTThread();
524             find.btFind().requestFocus();
525             waitForAWTThread();
526             log("Searching for: "+find.cboFindWhat().getTextField().getText());
527             find.find();
528             find.close();
529             checkSelection(txtOper, 8, 14, "Issue #52115 testing failed on CTRL+V!");
530             // then Shift+Insert
531
editor.setCaretPosition(327); //word "text"
532
txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK);
533             cutCopyViaStrokes(txtOper, KeyEvent.VK_C, KeyEvent.CTRL_MASK);
534             editor.setCaretPosition(1, 1);
535             find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
536
find.cboFindWhat().requestFocus(); // [temp] failing tests on SunOS & Linux
537
waitForAWTThread();
538             pasteViaStrokes(find, KeyEvent.VK_INSERT, KeyEvent.SHIFT_DOWN_MASK, null);
539             waitForAWTThread();
540             find.btFind().requestFocus();
541             waitForAWTThread();
542             log("Searching for: "+find.cboFindWhat().getTextField().getText());
543             find.find();
544             find.close();
545             checkSelection(txtOper, 167, 171, "Issue #52115 testing failed on Shift+Insert!");
546         } finally {
547             closeFileWithDiscard();
548         }
549         
550     }
551     public void waitForAWTThread() {
552         try {
553             SwingUtilities.invokeAndWait(new Runnable JavaDoc() {
554                 public void run() {
555                     log("Stop waiting");
556                 }
557             });
558         } catch (Exception JavaDoc e) {
559             //ignored
560
}
561     }
562     
563     public void testRegExSearch(){
564         openDefaultProject();
565         openDefaultSampleFile();
566         try {
567             editor = getDefaultSampleEditorOperator();
568             txtOper = editor.txtEditorPane();
569             
570             //test whether the "Whole Words" and "Incremental Search" are disabled during regEx
571
final Find findRegEx = openFindDialog(null, REGULAR_EXPRESSIONS);
572             waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION, new ValueResolver(){
573                 public Object JavaDoc getValue(){
574                     return Boolean.valueOf(
575                             findRegEx.cbMatchWholeWordsOnly().isEnabled() &&
576                             findRegEx.cbIncrementalSearch().isEnabled());
577                 }
578             }, Boolean.FALSE);
579             if (findRegEx.cbMatchWholeWordsOnly().isEnabled() || findRegEx.cbIncrementalSearch().isEnabled()){
580                 fail("Items disabling failed. \"Whole Words\" and \"Incremental Search\" should be disabled during regEx! " + //NOI18N
581
"(\"Whole Words\" = "+findRegEx.cbMatchWholeWordsOnly().isEnabled()+ //NOI18N
582
", \"Incremental Search\" = "+findRegEx.cbIncrementalSearch().isEnabled()+")"); //NOI18N
583
}
584             findRegEx.close();
585             
586             
587             find("teest", REGULAR_EXPRESSIONS, 309, 314, 0);
588             find("t.*st", REGULAR_EXPRESSIONS, 325, 337, 314);// find next teee...st
589
find("t.*st", REGULAR_EXPRESSIONS, 348, 356, 326);// find next Teee...st, caret is just behind t
590
find("T.*st", REGULAR_EXPRESSIONS | MATCH_CASE, 348, 356, 309);// find case sensitively Teee...st, skipping teee...st
591
find("t.*st", REGULAR_EXPRESSIONS | SEARCH_BACKWARDS, 348, 356, 356);
592             find("t.*st", REGULAR_EXPRESSIONS | SEARCH_BACKWARDS | MATCH_CASE, 325, 337, 356);
593             
594             // find one line strings + Wrap Search Testing
595
String JavaDoc lineStringsExp = "\"[^\"\\r\\n]*\"";
596             editor.setCaretPosition(225);
597             Find find = openFindDialog(lineStringsExp, REGULAR_EXPRESSIONS);
598             find.find();
599             checkSelection(txtOper, 267, 286, "Line string search failed.");
600             find.find();
601             checkSelection(txtOper, 417, 430, "Line string search failed.");
602             find.find();
603             checkSelection(txtOper, -1, -1, "Line string search failed.");
604             find.cbWrapSearch().setSelected(true);
605             find.find();
606             checkSelection(txtOper, 224, 237, "Line string wrap search failed.");
607             find.close();
608             
609             // find one line strings + Wrap Search Testing + BACKWARD
610
editor.setCaretPosition(429);
611             find = openFindDialog(lineStringsExp, REGULAR_EXPRESSIONS | SEARCH_BACKWARDS);
612             find.find();
613             checkSelection(txtOper, 267, 286, "Line string BWD search failed.");
614             find.find();
615             checkSelection(txtOper, 224, 237, "Line string BWV search failed.");
616             find.find();
617             checkSelection(txtOper, -1, -1, "Line string BWV search failed.");
618             find.cbWrapSearch().setSelected(true);
619             find.find();
620             checkSelection(txtOper, 417, 430, "Line string BWV wrap search failed.");
621             find.close();
622             
623             //multiline strings
624
find("\"[^\"]*\"", REGULAR_EXPRESSIONS, 456, 510, 432);
625             
626             // wrap around block forwardRegExSearch testing
627
find = openFindDialog(null, REGULAR_EXPRESSIONS); // reset find dialog checkboxes
628
find.close();
629             preselect(txtOper, 326, 389);
630             find = openFindDialog("T.*st", NO_OPERATION); // search selection should be checked automatically
631
find.find();
632             checkSelection(txtOper, 348, 356, "Wrap around block regEx testing failed!");
633             find.find();
634             checkSelection(txtOper, 367, 373, "Wrap around block regEx testing failed!");
635             find.find();
636             checkSelection(txtOper, -1, -1, "Wrap around block regEx testing failed!"); // should find, because wrap around is not checked yet
637
find.cbWrapSearch().setSelected(true);
638             find.find();
639             checkSelection(txtOper, 348, 356, "Wrap around block regEx testing failed!");
640             find.close();
641             
642             // wrap around block backward RegExSearch testing + match case
643
find = openFindDialog(null, REGULAR_EXPRESSIONS | SEARCH_BACKWARDS | MATCH_CASE); // reset find dialog checkboxes
644
find.close();
645             preselect(txtOper, 252, 369);
646             find = openFindDialog("t.*st", NO_OPERATION); // search selection should be checked automatically
647
find.find();
648             checkSelection(txtOper, 325, 337, "Wrap around block BWD regEx testing failed!");
649             find.find();
650             checkSelection(txtOper, 309, 314, "Wrap around block BWD regEx testing failed!");
651             find.find();
652             checkSelection(txtOper, -1, -1, "Wrap around block BWV regEx testing failed!"); // should find, because wrap around is not checked yet
653
find.cbWrapSearch().setSelected(true);
654             find.find();
655             checkSelection(txtOper, 325, 337, "Wrap around block BWV regEx testing failed!");
656             find.close();
657             
658             // find end line whitespaces
659
String JavaDoc lineEndWhitespaces = "[ \\t]+$";
660             editor.setCaretPosition(1);
661             find = openFindDialog(lineEndWhitespaces, REGULAR_EXPRESSIONS);
662             find.find();
663             checkSelection(txtOper, 104, 108, "Find end line whitespaces testing failed!");
664             find.find();
665             checkSelection(txtOper, 443, 444, "Find end line whitespaces testing failed!");
666             find.find();
667             checkSelection(txtOper, 510, 511, "Find end line whitespaces testing failed!");
668             find.find();
669             checkSelection(txtOper, 599, 607, "Find end line whitespaces testing failed!");
670             find.close();
671             
672             
673         } finally {
674             closeFileWithDiscard();
675         }
676     }
677     
678 }
Popular Tags