001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package search_replace;
043:
044: import java.awt.event.KeyEvent;
045: import java.io.File;
046: import java.io.FileOutputStream;
047: import java.io.IOException;
048: import java.io.OutputStream;
049: import java.io.PrintStream;
050: import java.util.Hashtable;
051: import javax.swing.SwingUtilities;
052: import javax.swing.text.BadLocationException;
053: import javax.swing.text.Document;
054: import org.netbeans.jellytools.EditorOperator;
055: import org.netbeans.jellytools.actions.FindAction;
056: import org.netbeans.jellytools.modules.editor.Find;
057: import org.netbeans.jemmy.TimeoutExpiredException;
058: import org.netbeans.jemmy.operators.JEditorPaneOperator;
059:
060: /**
061: * Basic Editor Find and Replace Tests
062: *
063: * @author Martin Roskanin
064: */
065:
066: public class SearchAndReplaceTest extends lib.EditorTestCase {
067:
068: // private PrintStream wrapper for System.out
069: private PrintStream systemOutPSWrapper = new PrintStream(System.out);
070: private int index = 0;
071: private EditorOperator editor;
072: private JEditorPaneOperator txtOper;
073: private int WAIT_MAX_MILIS_FOR_FIND_OPERATION = 5000;
074:
075: public static final int NO_OPERATION = 0x00000000;
076: public static final int MATCH_CASE = 0x00000001;
077: public static final int WHOLE_WORDS = 0x00000002;
078: public static final int REGULAR_EXPRESSIONS = 0x00000004;
079: public static final int HIGHLIGHT_RESULTS = 0x00000008;
080: public static final int WRAP_AROUND = 0x00000010;
081: public static final int SEARCH_SELECTION = 0x00000020;
082: public static final int SEARCH_BACKWARDS = 0x00000040;
083: public static final int INCREMENTAL_SEARCH = 0x00000080;
084: public static final int ALL_UNCHECKED = 0x10000000;
085: public static final int NO_RESET = 0x20000000;
086: public static final int NO_RESET_SEARCH_SELECTION = 0x40000000;
087:
088: /** Creates a new instance of Main */
089: public SearchAndReplaceTest(String testMethodName) {
090: super (testMethodName);
091: }
092:
093: private String getIndexAsString() {
094: String ret = String.valueOf(index);
095: if (ret.length() == 1)
096: ret = "0" + ret;
097: return ret;
098: }
099:
100: private String getRefFileName() {
101: return this .getName() + getIndexAsString() + ".ref"; //NOI18N
102: }
103:
104: private String getGoldenFileName() {
105: return this .getName() + getIndexAsString() + ".pass"; //NOI18N
106: }
107:
108: private String getDiffFileName() {
109: return this .getName() + getIndexAsString() + ".diff"; //NOI18N
110: }
111:
112: // hashtable holding all already used logs and correspondig printstreams
113: private Hashtable logStreamTable = null;
114:
115: private PrintStream getFileLog(String logName) throws IOException {
116: OutputStream outputStream;
117: FileOutputStream fileOutputStream;
118:
119: if ((logStreamTable == null) | (hasTestMethodChanged())) {
120: // we haven't used logging capability - create hashtables
121: logStreamTable = new Hashtable();
122: //System.out.println("Created new hashtable");
123: } else {
124: if (logStreamTable.containsKey(logName)) {
125: //System.out.println("Getting stream from cache:"+logName);
126: return (PrintStream) logStreamTable.get(logName);
127: }
128: }
129: // we didn't used this log, so let's create it
130: FileOutputStream fileLog = new FileOutputStream(new File(
131: getWorkDir(), logName));
132: PrintStream printStreamLog = new PrintStream(fileLog, true);
133: logStreamTable.put(logName, printStreamLog);
134: //System.out.println("Created new stream:"+logName);
135: return printStreamLog;
136: }
137:
138: private String lastTestMethod = null;
139:
140: private boolean hasTestMethodChanged() {
141: if (!this .getName().equals(lastTestMethod)) {
142: lastTestMethod = this .getName();
143: return true;
144: } else {
145: return false;
146: }
147: }
148:
149: public PrintStream getRef() {
150: String refFilename = getRefFileName();
151: try {
152: return getFileLog(refFilename);
153: } catch (IOException ioe) {
154: // canot get ref file - return system.out
155: //System.err.println("Test method "+this.getName()+" - cannot open ref file:"+refFilename
156: // +" - defaulting to System.out and failing test");
157: fail("Could not open reference file: " + refFilename);
158: return systemOutPSWrapper;
159: }
160: }
161:
162: protected void compareToGoldenFile(Document testDoc) {
163: try {
164: ref(testDoc.getText(0, testDoc.getLength()));
165: compareReferenceFiles(getRefFileName(),
166: getGoldenFileName(), getDiffFileName());
167: index++;
168: } catch (BadLocationException e) {
169: e.printStackTrace(getLog());
170: fail();
171: }
172: }
173:
174: private void resetFindProperties(Find find,
175: boolean resetSearchSelection) {
176: find.cbMatchCase().setSelected(false);
177: find.cbMatchWholeWordsOnly().setSelected(false);
178: find.cbRegularExpressions().setSelected(false);
179: find.cbHighlightSearch().setSelected(false);
180: find.cbWrapSearch().setSelected(false);
181: if (resetSearchSelection) {
182: find.cbBlockSearch().setSelected(false);
183: }
184: find.cbBackwardSearch().setSelected(false);
185: find.cbIncrementalSearch().setSelected(false);
186: find.cboFindWhat().clearText();
187: }
188:
189: protected Find openFindDialog(String text, int modifiers) {
190: new FindAction().performMenu();
191: Find find = null;
192: try {
193: find = new Find();
194: } catch (TimeoutExpiredException tee) {
195: log("Find dialog not opened, one more try");
196: new FindAction().performMenu();
197: find = new Find();
198: }
199: if (modifiers != 0 && (modifiers & NO_RESET) == 0) {
200: resetFindProperties(find,
201: (modifiers & NO_RESET_SEARCH_SELECTION) == 0);
202: }
203: if ((modifiers & MATCH_CASE) != 0) {
204: find.cbMatchCase().setSelected(true);
205: }
206: if ((modifiers & WHOLE_WORDS) != 0) {
207: find.cbMatchWholeWordsOnly().setSelected(true);
208: }
209: if ((modifiers & REGULAR_EXPRESSIONS) != 0) {
210: find.cbRegularExpressions().setSelected(true);
211: }
212: if ((modifiers & HIGHLIGHT_RESULTS) != 0) {
213: find.cbHighlightSearch().setSelected(true);
214: }
215: if ((modifiers & WRAP_AROUND) != 0) {
216: find.cbWrapSearch().setSelected(true);
217: }
218: if ((modifiers & SEARCH_SELECTION) != 0) {
219: find.cbBlockSearch().setSelected(true);
220: }
221: if ((modifiers & SEARCH_BACKWARDS) != 0) {
222: find.cbBackwardSearch().setSelected(true);
223: }
224: if ((modifiers & INCREMENTAL_SEARCH) != 0) {
225: find.cbIncrementalSearch().setSelected(true);
226: }
227: find.cboFindWhat().clearText();
228: if (text != null) {
229: find.cboFindWhat().typeText(text);
230: }
231: return find;
232: }
233:
234: private ValueResolver getSelectionResolver(
235: final JEditorPaneOperator txtOper, final int startEtalon,
236: final int endEtalon) {
237:
238: ValueResolver clipboardValueResolver = new ValueResolver() {
239: public Object getValue() {
240: int selectionStart = txtOper.getSelectionStart();
241: int selectionEnd = txtOper.getSelectionEnd();
242: if (selectionStart == selectionEnd) {
243: selectionStart = -1;
244: selectionEnd = -1;
245: }
246: if (selectionStart != startEtalon
247: || selectionEnd != endEtalon) {
248: return Boolean.FALSE;
249: } else {
250: return Boolean.TRUE;
251: }
252: }
253: };
254:
255: return clipboardValueResolver;
256: }
257:
258: private ValueResolver getIncFindResolver(
259: final JEditorPaneOperator txtOper, final int startEtalon,
260: final int endEtalon) {
261:
262: ValueResolver clipboardValueResolver = new ValueResolver() {
263: public Object getValue() {
264: org.netbeans.editor.BaseTextUI ui = (org.netbeans.editor.BaseTextUI) txtOper
265: .getUI();
266: org.netbeans.editor.EditorUI editorUI = ui
267: .getEditorUI();
268: org.netbeans.editor.DrawLayerFactory.IncSearchLayer incLayer = (org.netbeans.editor.DrawLayerFactory.IncSearchLayer) editorUI
269: .findLayer(org.netbeans.editor.DrawLayerFactory.INC_SEARCH_LAYER_NAME);
270: int selectionStart = -1;
271: int selectionEnd = -1;
272: if (incLayer == null) {
273: return Boolean.FALSE;
274: } else {
275: if (incLayer.isEnabled()) {
276: selectionStart = incLayer.getOffset();
277: selectionEnd = selectionStart
278: + incLayer.getLength();
279: }
280: }
281: if (selectionStart == selectionEnd) {
282: selectionStart = -1;
283: selectionEnd = -1;
284: }
285: if (selectionStart != startEtalon
286: || selectionEnd != endEtalon) {
287: return Boolean.FALSE;
288: } else {
289: return Boolean.TRUE;
290: }
291: }
292: };
293:
294: return clipboardValueResolver;
295: }
296:
297: protected boolean find(String text, int modifiers, int startEtalon,
298: int endEtalon, int setCaretPos) {
299: if (setCaretPos > -1) {
300: txtOper.setCaretPosition(setCaretPos);
301: }
302: Find find = openFindDialog(text, modifiers);
303: find.find();
304: waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION,
305: getSelectionResolver(txtOper, startEtalon, endEtalon),
306: Boolean.TRUE);
307: int selectionStart = txtOper.getSelectionStart();
308: int selectionEnd = txtOper.getSelectionEnd();
309: if (selectionStart == selectionEnd) {
310: selectionEnd = -1;
311: selectionStart = -1;
312: }
313: if (selectionStart != startEtalon || selectionEnd != endEtalon) {
314: log("--------------------------------------------------");
315: log("Find operation failed. Selected text: "
316: + selectionStart + " - " + selectionEnd
317: + " >>> Expected values: " + startEtalon + " - "
318: + endEtalon);
319: log("find dialog find what combo value:"
320: + find.cboFindWhat().getEditor().getItem());
321: log("checkboxes:" + "\n cbBackwardSearch:"
322: + find.cbBackwardSearch().isSelected()
323: + "\n cbBlockSearch:"
324: + find.cbBlockSearch().isSelected()
325: + "\n cbHighlightSearch:"
326: + find.cbHighlightSearch().isSelected()
327: + "\n cbIncrementalSearch:"
328: + find.cbIncrementalSearch().isSelected()
329: + "\n cbMatchCase:"
330: + find.cbMatchCase().isSelected()
331: + "\n cbMatchWholeWordsOnly:"
332: + find.cbMatchWholeWordsOnly().isSelected()
333: + "\n cbRegularExpressions:"
334: + find.cbRegularExpressions().isSelected()
335: + "\n cbWrapSearch:"
336: + find.cbWrapSearch().isSelected());
337: log("--------------------------------------------------");
338: fail("Find operation failed. Selected text: "
339: + selectionStart + " - " + selectionEnd
340: + " >>> Expected values: " + startEtalon + " - "
341: + endEtalon); //NOI18N
342: find.close();
343: return false;
344: }
345: find.close();
346: return true;
347: }
348:
349: private void checkIncrementalSearch(Find find, String s,
350: int startEtalon, int endEtalon) {
351: // Checking Disabled - the new highlighting SPI will be used so the draw layer's data should not be checked directly.
352: if (true)
353: return;
354:
355: find.cboFindWhat().typeText(s);
356:
357: waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION,
358: getIncFindResolver(txtOper, startEtalon, endEtalon),
359: Boolean.TRUE);
360:
361: int selectionStart = -1;
362: int selectionEnd = -1;
363:
364: org.netbeans.editor.BaseTextUI ui = (org.netbeans.editor.BaseTextUI) txtOper
365: .getUI();
366: org.netbeans.editor.EditorUI editorUI = ui.getEditorUI();
367: org.netbeans.editor.DrawLayerFactory.IncSearchLayer incLayer = (org.netbeans.editor.DrawLayerFactory.IncSearchLayer) editorUI
368: .findLayer(org.netbeans.editor.DrawLayerFactory.INC_SEARCH_LAYER_NAME);
369: if (incLayer == null) {
370: System.out.println("fail: layer not initialized");
371: } else {
372: if (incLayer.isEnabled()) {
373: selectionStart = incLayer.getOffset();
374: selectionEnd = selectionStart + incLayer.getLength();
375: }
376: }
377:
378: if (selectionStart == selectionEnd) {
379: selectionEnd = -1;
380: selectionStart = -1;
381: }
382: if (selectionStart != startEtalon || selectionEnd != endEtalon) {
383: fail("Incremental find operation failed. Selected text: "
384: + selectionStart + " - " + selectionEnd
385: + " >>> Expected values: " + startEtalon + " - "
386: + endEtalon); //NOI18N
387: }
388: }
389:
390: private void preselect(JEditorPaneOperator txtOper, int start,
391: int end) {
392: txtOper.setSelectionStart(start);
393: txtOper.setSelectionEnd(end);
394: }
395:
396: private void checkSelection(JEditorPaneOperator txtOper,
397: int startEtalon, int endEtalon, String errorMessage) {
398: waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION,
399: getSelectionResolver(txtOper, startEtalon, endEtalon),
400: Boolean.TRUE);
401: int selectionStart = txtOper.getSelectionStart();
402: int selectionEnd = txtOper.getSelectionEnd();
403: if (selectionStart == selectionEnd) {
404: selectionStart = -1;
405: selectionEnd = -1;
406: }
407: if (selectionStart != startEtalon || selectionEnd != endEtalon) {
408: fail(errorMessage + " Selected text: " + selectionStart
409: + " - " + selectionEnd + " >>> Expected values: "
410: + startEtalon + " - " + endEtalon); //NOI18N
411: }
412: }
413:
414: public void testSearch() {
415: openDefaultProject();
416: openDefaultSampleFile();
417: try {
418: editor = getDefaultSampleEditorOperator();
419: txtOper = editor.txtEditorPane();
420:
421: find("searchText", ALL_UNCHECKED, 161, 171, 0);
422: find("SeArCHText", MATCH_CASE, 175, 185, 0);
423: find("SeArCHText", WHOLE_WORDS, 275, 285, 206);
424: find("SeArCHText", MATCH_CASE | WHOLE_WORDS, 289, 299, 206);
425: find("SeArCHText", SEARCH_BACKWARDS, 341, 351, 352);
426: find("SeArCHText", SEARCH_BACKWARDS | MATCH_CASE, 289, 299,
427: 352);
428: find("search", SEARCH_BACKWARDS | WHOLE_WORDS, 318, 324,
429: 352);
430: find("search", SEARCH_BACKWARDS | MATCH_CASE | WHOLE_WORDS,
431: 311, 317, 352);
432: find("insert", SEARCH_BACKWARDS | WRAP_AROUND, 86, 92, 86);
433: find("insert", SEARCH_BACKWARDS, -1, -1, 86);
434:
435: //incremental search
436: txtOper.setCaretPosition(328);
437: Find find = openFindDialog(null, INCREMENTAL_SEARCH);
438: checkIncrementalSearch(find, "t", 328, 329);
439: checkIncrementalSearch(find, "e", 330, 332);
440: checkIncrementalSearch(find, "x", 330, 333);
441: checkIncrementalSearch(find, "t", 330, 334);
442: checkIncrementalSearch(find, "x", 429, 434);
443: checkIncrementalSearch(find, "y", -1, -1); // inc should fail
444: find.close();
445:
446: //incremental search backwards + Match case
447: txtOper.setCaretPosition(328);
448: find = openFindDialog(null, INCREMENTAL_SEARCH | MATCH_CASE
449: | SEARCH_BACKWARDS);
450: checkIncrementalSearch(find, "s", 311, 312);
451: checkIncrementalSearch(find, "e", 311, 313);
452: checkIncrementalSearch(find, "a", 311, 314);
453: checkIncrementalSearch(find, "r", 311, 315);
454: checkIncrementalSearch(find, "c", 311, 316);
455: checkIncrementalSearch(find, "h", 311, 317);
456: checkIncrementalSearch(find, "T", 275, 282);
457: checkIncrementalSearch(find, "e", 275, 283);
458: checkIncrementalSearch(find, "x", 275, 284);
459: checkIncrementalSearch(find, "T", -1, -1);
460: find.close();
461:
462: //#53536 - CTRL-F & friends cancel selection
463: txtOper.setSelectionStart(1);
464: txtOper.setSelectionEnd(100);
465: // NO_OPERATION - no check box reset, no checkbox set by default.
466: final Find blockFind = openFindDialog(null, NO_OPERATION);
467:
468: // check if the "search selection" checkbox was checked
469: waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION,
470: new ValueResolver() {
471: public Object getValue() {
472: return Boolean.valueOf(blockFind
473: .cbBlockSearch().isSelected());
474: }
475: }, Boolean.TRUE);
476: if (!blockFind.cbBlockSearch().isSelected()) {
477: fail("Search Selection checkbox was not checked automaticaly after invoking "
478: + "Find dialog over selected text"); //NOI18N
479: }
480:
481: blockFind.close();
482: // Selection made before Find dialog invocation gets lost.
483: // Either a searched text was found and the found text gets selected
484: // or the searched text is not found and then no selection is done.
485: // The selection is only retained in case there was nothing typed into the "find what" field
486:
487: //checkSelection(txtOper, 1, 100, "Issue #53536 testing failed!");
488:
489: //test find in selection
490: find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
491: find.close();
492: preselect(txtOper, 46, 132);
493: // make sure that text outside the selection is not found
494: find("searchText", NO_OPERATION, -1, -1, -1);
495:
496: // selection begins at ublic. 'p' is not selected. Next public
497: // should be found
498: preselect(txtOper, 47, 123);
499: find("public", NO_RESET, 105, 111, -1);
500:
501: preselect(txtOper, 161, 544);
502: find("SeArCHText", NO_RESET_SEARCH_SELECTION | MATCH_CASE,
503: 175, 185, -1);
504: preselect(txtOper, 206, 544);
505: find("SeArCHText", NO_RESET_SEARCH_SELECTION | WHOLE_WORDS,
506: 275, 285, -1);
507: preselect(txtOper, 206, 544);
508: find("SeArCHText", NO_RESET_SEARCH_SELECTION | MATCH_CASE
509: | WHOLE_WORDS, 289, 299, -1);
510: preselect(txtOper, 161, 544);
511: find("searchText", NO_RESET_SEARCH_SELECTION
512: | SEARCH_BACKWARDS, 469, 479, -1);
513: preselect(txtOper, 161, 544);
514: find("searchText", NO_RESET_SEARCH_SELECTION
515: | SEARCH_BACKWARDS | MATCH_CASE, 455, 465, -1);
516: preselect(txtOper, 161, 544);
517: find("search", NO_RESET_SEARCH_SELECTION | SEARCH_BACKWARDS
518: | WHOLE_WORDS, 318, 324, -1);
519: preselect(txtOper, 161, 544);
520: find("search", NO_RESET_SEARCH_SELECTION | SEARCH_BACKWARDS
521: | MATCH_CASE | WHOLE_WORDS, 311, 317, -1);
522:
523: // wrap around block forwardSearch testing
524: find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
525: find.close();
526: preselect(txtOper, 409, 465);
527: find = openFindDialog("searchText", NO_OPERATION); // search selection should be checked automatically
528: find.find();
529: checkSelection(txtOper, 410, 420,
530: "Wrap around block testing failed!");
531: find.find();
532: checkSelection(txtOper, 423, 433,
533: "Wrap around block testing failed!");
534: find.find();
535: checkSelection(txtOper, 455, 465,
536: "Wrap around block testing failed!");
537: find.find();
538: checkSelection(txtOper, -1, -1,
539: "Wrap around block testing failed!"); // should find, because wrap around is not checked yet
540: find.cbWrapSearch().setSelected(true);
541: find.find();
542: checkSelection(txtOper, 410, 420,
543: "Wrap around block testing failed!");
544: find.close();
545:
546: // wrap around block bacwardSearch testing
547: find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
548: find.close();
549: preselect(txtOper, 409, 465);
550: find = openFindDialog("searchText",
551: NO_RESET_SEARCH_SELECTION | SEARCH_BACKWARDS);
552: find.find();
553: checkSelection(txtOper, 455, 465,
554: "Wrap around block testing failed!");
555: find.find();
556: checkSelection(txtOper, 423, 433,
557: "Wrap around block testing failed!");
558: find.find();
559: checkSelection(txtOper, 410, 420,
560: "Wrap around block testing failed!");
561: find.find();
562: checkSelection(txtOper, -1, -1,
563: "Wrap around block testing failed!"); // should find, because wrap around is not checked yet
564: find.cbWrapSearch().setSelected(true);
565: find.find();
566: checkSelection(txtOper, 455, 465,
567: "Wrap around block testing failed!");
568: find.close();
569:
570: //incremental search in selected block
571: find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
572: find.close();
573: preselect(txtOper, 325, 360);
574: find = openFindDialog(null, NO_RESET_SEARCH_SELECTION
575: | INCREMENTAL_SEARCH);
576: checkIncrementalSearch(find, "t", 325, 326);
577: checkIncrementalSearch(find, "e", 325, 327);
578: checkIncrementalSearch(find, "x", 325, 328);
579: checkIncrementalSearch(find, "t", 325, 329);
580: checkIncrementalSearch(find, "x", -1, -1); // inc should fail
581: find.close();
582:
583: //incremental search backwards + Match case in selected block
584: find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
585: find.close();
586: preselect(txtOper, 251, 350);
587: find = openFindDialog(null, NO_RESET_SEARCH_SELECTION
588: | INCREMENTAL_SEARCH | MATCH_CASE
589: | SEARCH_BACKWARDS);
590: checkIncrementalSearch(find, "T", 347, 348);
591: checkIncrementalSearch(find, "e", 347, 349);
592: checkIncrementalSearch(find, "x", 347, 350);
593: checkIncrementalSearch(find, "t", 295, 299);
594: checkIncrementalSearch(find, "X", -1, -1); // fails - behind selected area
595: find.close();
596: } finally {
597: closeFileWithDiscard();
598: }
599: }
600:
601: public void testSearch2() {
602: openDefaultProject();
603: openDefaultSampleFile();
604: Find find;
605: try {
606: editor = getDefaultSampleEditorOperator();
607: txtOper = editor.txtEditorPane();
608:
609: //#52115
610: // firstly try CTRL+V
611: editor.requestFocus();
612: editor.setCaretPosition(16, 9); //word "search"
613: txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK);
614: cutCopyViaStrokes(txtOper, KeyEvent.VK_C,
615: KeyEvent.CTRL_DOWN_MASK);
616: editor.setCaretPosition(1, 1);
617: find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
618: find.cboFindWhat().requestFocus(); // [temp] failing tests on SunOS & Linux
619: waitForAWTThread();
620: pasteViaStrokes(find, KeyEvent.VK_V, KeyEvent.CTRL_MASK,
621: null);
622: waitForAWTThread();
623: find.btFind().requestFocus();
624: waitForAWTThread();
625: log("Searching for: "
626: + find.cboFindWhat().getTextField().getText());
627: find.find();
628: find.close();
629: checkSelection(txtOper, 8, 14,
630: "Issue #52115 testing failed on CTRL+V!");
631:
632: log("Copy paste with Ctrl-V done");
633:
634: // then Shift+Insert
635: editor.requestFocus();
636: editor.setCaretPosition(16, 27); //word "text"
637: txtOper.pushKey(KeyEvent.VK_J, KeyEvent.ALT_DOWN_MASK);
638: cutCopyViaStrokes(txtOper, KeyEvent.VK_C,
639: KeyEvent.CTRL_DOWN_MASK);
640: editor.setCaretPosition(1, 1);
641: find = openFindDialog(null, ALL_UNCHECKED); // reset find dialog checkboxes
642: find.cboFindWhat().requestFocus(); // [temp] failing tests on SunOS & Linux
643: waitForAWTThread();
644: pasteViaStrokes(find, KeyEvent.VK_INSERT,
645: KeyEvent.SHIFT_DOWN_MASK, null);
646: waitForAWTThread();
647: find.btFind().requestFocus();
648: waitForAWTThread();
649: log("Searching for: "
650: + find.cboFindWhat().getTextField().getText());
651: find.find();
652: find.close();
653: checkSelection(txtOper, 167, 171,
654: "Issue #52115 testing failed on Shift+Insert!");
655: } finally {
656: closeFileWithDiscard();
657: }
658:
659: }
660:
661: public void waitForAWTThread() {
662: try {
663: SwingUtilities.invokeAndWait(new Runnable() {
664: public void run() {
665: log("Stop waiting");
666: }
667: });
668: } catch (Exception e) {
669: //ignored
670: }
671: }
672:
673: public void testRegExSearch() {
674: openDefaultProject();
675: openDefaultSampleFile();
676: try {
677: editor = getDefaultSampleEditorOperator();
678: txtOper = editor.txtEditorPane();
679:
680: //test whether the "Whole Words" and "Incremental Search" are disabled during regEx
681: final Find findRegEx = openFindDialog(null,
682: REGULAR_EXPRESSIONS);
683: waitMaxMilisForValue(WAIT_MAX_MILIS_FOR_FIND_OPERATION,
684: new ValueResolver() {
685: public Object getValue() {
686: return Boolean.valueOf(findRegEx
687: .cbMatchWholeWordsOnly()
688: .isEnabled()
689: && findRegEx.cbIncrementalSearch()
690: .isEnabled());
691: }
692: }, Boolean.FALSE);
693: if (findRegEx.cbMatchWholeWordsOnly().isEnabled()
694: || findRegEx.cbIncrementalSearch().isEnabled()) {
695: fail("Items disabling failed. \"Whole Words\" and \"Incremental Search\" should be disabled during regEx! "
696: + //NOI18N
697: "(\"Whole Words\" = "
698: + findRegEx.cbMatchWholeWordsOnly().isEnabled()
699: + //NOI18N
700: ", \"Incremental Search\" = "
701: + findRegEx.cbIncrementalSearch().isEnabled()
702: + ")"); //NOI18N
703: }
704: findRegEx.close();
705:
706: find("teest", REGULAR_EXPRESSIONS, 309, 314, 0);
707: find("t.*st", REGULAR_EXPRESSIONS, 325, 337, 314);// find next teee...st
708: find("t.*st", REGULAR_EXPRESSIONS, 348, 356, 326);// find next Teee...st, caret is just behind t
709: find("T.*st", REGULAR_EXPRESSIONS | MATCH_CASE, 348, 356,
710: 309);// find case sensitively Teee...st, skipping teee...st
711: find("t.*st", REGULAR_EXPRESSIONS | SEARCH_BACKWARDS, 348,
712: 356, 356);
713: find("t.*st", REGULAR_EXPRESSIONS | SEARCH_BACKWARDS
714: | MATCH_CASE, 325, 337, 356);
715:
716: // find one line strings + Wrap Search Testing
717: String lineStringsExp = "\"[^\"\\r\\n]*\"";
718: editor.setCaretPosition(225);
719: Find find = openFindDialog(lineStringsExp,
720: REGULAR_EXPRESSIONS);
721: find.find();
722: checkSelection(txtOper, 267, 286,
723: "Line string search failed.");
724: find.find();
725: checkSelection(txtOper, 417, 430,
726: "Line string search failed.");
727: find.find();
728: checkSelection(txtOper, -1, -1,
729: "Line string search failed.");
730: find.cbWrapSearch().setSelected(true);
731: find.find();
732: checkSelection(txtOper, 224, 237,
733: "Line string wrap search failed.");
734: find.close();
735:
736: // find one line strings + Wrap Search Testing + BACKWARD
737: editor.setCaretPosition(429);
738: find = openFindDialog(lineStringsExp, REGULAR_EXPRESSIONS
739: | SEARCH_BACKWARDS);
740: find.find();
741: checkSelection(txtOper, 267, 286,
742: "Line string BWD search failed.");
743: find.find();
744: checkSelection(txtOper, 224, 237,
745: "Line string BWV search failed.");
746: find.find();
747: checkSelection(txtOper, -1, -1,
748: "Line string BWV search failed.");
749: find.cbWrapSearch().setSelected(true);
750: find.find();
751: checkSelection(txtOper, 417, 430,
752: "Line string BWV wrap search failed.");
753: find.close();
754:
755: //multiline strings
756: find("\"[^\"]*\"", REGULAR_EXPRESSIONS, 456, 510, 432);
757:
758: // wrap around block forwardRegExSearch testing
759: find = openFindDialog(null, REGULAR_EXPRESSIONS); // reset find dialog checkboxes
760: find.close();
761: preselect(txtOper, 326, 389);
762: find = openFindDialog("T.*st", NO_OPERATION); // search selection should be checked automatically
763: find.find();
764: checkSelection(txtOper, 348, 356,
765: "Wrap around block regEx testing failed!");
766: find.find();
767: checkSelection(txtOper, 367, 373,
768: "Wrap around block regEx testing failed!");
769: find.find();
770: checkSelection(txtOper, -1, -1,
771: "Wrap around block regEx testing failed!"); // should find, because wrap around is not checked yet
772: find.cbWrapSearch().setSelected(true);
773: find.find();
774: checkSelection(txtOper, 348, 356,
775: "Wrap around block regEx testing failed!");
776: find.close();
777:
778: // wrap around block backward RegExSearch testing + match case
779: find = openFindDialog(null, REGULAR_EXPRESSIONS
780: | SEARCH_BACKWARDS | MATCH_CASE); // reset find dialog checkboxes
781: find.close();
782: preselect(txtOper, 252, 369);
783: find = openFindDialog("t.*st", NO_OPERATION); // search selection should be checked automatically
784: find.find();
785: checkSelection(txtOper, 325, 337,
786: "Wrap around block BWD regEx testing failed!");
787: find.find();
788: checkSelection(txtOper, 309, 314,
789: "Wrap around block BWD regEx testing failed!");
790: find.find();
791: checkSelection(txtOper, -1, -1,
792: "Wrap around block BWV regEx testing failed!"); // should find, because wrap around is not checked yet
793: find.cbWrapSearch().setSelected(true);
794: find.find();
795: checkSelection(txtOper, 325, 337,
796: "Wrap around block BWV regEx testing failed!");
797: find.close();
798:
799: // find end line whitespaces
800: String lineEndWhitespaces = "[ \\t]+$";
801: editor.setCaretPosition(1);
802: find = openFindDialog(lineEndWhitespaces,
803: REGULAR_EXPRESSIONS);
804: find.find();
805: checkSelection(txtOper, 104, 108,
806: "Find end line whitespaces testing failed!");
807: find.find();
808: checkSelection(txtOper, 443, 444,
809: "Find end line whitespaces testing failed!");
810: find.find();
811: checkSelection(txtOper, 510, 511,
812: "Find end line whitespaces testing failed!");
813: find.find();
814: checkSelection(txtOper, 599, 607,
815: "Find end line whitespaces testing failed!");
816: find.close();
817:
818: } finally {
819: closeFileWithDiscard();
820: }
821: }
822:
823: }
|