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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.test.syntax;
029:
030: import java.awt.event.KeyEvent;
031: import java.io.File;
032: import java.io.IOException;
033: import org.netbeans.editor.BaseDocument;
034: import org.netbeans.editor.Utilities;
035: import org.netbeans.jellytools.EditorOperator;
036: import org.netbeans.jellytools.JellyTestCase;
037: import org.netbeans.junit.ide.ProjectSupport;
038: import org.openide.cookies.EditorCookie;
039: import org.openide.filesystems.FileUtil;
040: import org.openide.loaders.DataObject;
041: import org.openide.loaders.DataObjectNotFoundException;
042:
043: /**
044: *
045: * @author Jindrich Sedek
046: */
047: public class IndentCasesTest extends JellyTestCase {
048:
049: private File projectDir;
050: private boolean debug = false;
051: private BaseDocument doc;
052:
053: public IndentCasesTest() {
054: super ("IndentationTesting");
055: }
056:
057: @Override
058: protected void setUp() throws Exception {
059: super .setUp();
060: File dataDir = getDataDir();
061: projectDir = new File(new File(dataDir,
062: "IndentationTestProjects"), "IndentationTest");
063: ProjectSupport.openProject(projectDir);
064: }
065:
066: public void testJSPFirstLineIndent() throws Exception {
067: testJSP(5, 1, 6, 1);
068: }
069:
070: public void testJSPTagEndLine() throws Exception {
071: testJSP(5, 7, 6, 5);
072: }
073:
074: public void testJSPAttribute() throws Exception {
075: testJSP(8, 15, 9, 13);
076: }
077:
078: public void testJSPAttribute2() throws Exception {
079: testJSP(8, 41, 9, 15);
080: }
081:
082: public void testJSPSmartEnter() throws Exception {
083: testJSP(22, 21, 23, 21);
084: }
085:
086: public void testJSPOpenTagIndent() throws Exception {
087: testJSP(23, 21, 24, 21);
088: }
089:
090: public void testJSPEmbeddedCSS1() throws Exception {
091: testJSP(10, 16, 11, 17);
092: }
093:
094: public void testJSPEmbeddedCSS2() throws Exception {
095: testJSP(11, 30, 12, 17);
096: }
097:
098: public void testJSPScriptletStart() throws Exception {
099: testJSP(29, 11, 30, 9);
100: }
101:
102: public void testJSPScriptletIfBlock() throws Exception {
103: testJSP(30, 19, 31, 13);
104: }
105:
106: public void testJSPScriptletForBlock() throws Exception {
107: testJSP(31, 44, 32, 17);
108: }
109:
110: public void testJSPScriptletClosingBracket() throws Exception {
111: testJSP(33, 14, 34, 13);
112: }
113:
114: public void testHTMLFirstLineIndent() throws Exception {
115: testHTML(1, 1, 2, 1);
116: }
117:
118: public void testHTMLTagEndLine() throws Exception {
119: testHTML(1, 7, 2, 5);
120: }
121:
122: public void testHTMLAttribute() throws Exception {
123: testHTML(4, 15, 5, 13);
124: }
125:
126: public void testHTMLAttribute2() throws Exception {
127: testHTML(4, 41, 5, 13);
128: }
129:
130: public void testHTMLSmartEnter() throws Exception {
131: testHTML(14, 21, 15, 21);
132: }
133:
134: public void testHTMLOpenTagIndent() throws Exception {
135: testHTML(19, 21, 20, 21);
136: }
137:
138: public void testHTMLEmbeddedCSS1() throws Exception {
139: testHTML(6, 16, 7, 17);
140: }
141:
142: public void testHTMLEmbeddedCSS2() throws Exception {
143: testHTML(7, 30, 8, 17);
144: }
145:
146: private void testJSP(int lineNum, int offset, int endLineNum,
147: int endOffset) throws Exception {
148: test("indentationTest.jsp", lineNum, offset, endLineNum,
149: endOffset);
150: }
151:
152: private void testHTML(int lineNum, int offset, int endLineNum,
153: int endOffset) throws Exception {
154: test("indentationTest.html", lineNum, offset, endLineNum,
155: endOffset);
156: }
157:
158: private void test(String fileName, int lineNum, int offset,
159: int endLineNum, int endOffset) throws Exception {
160: EditorOperator.closeDiscardAll();
161: EditorOperator op = openFile(fileName);
162: op.setCaretPositionToLine(lineNum);
163: op.setCaretPositionRelative(offset - 1);
164: if (debug) {
165: Thread.sleep(3000); // to be visible ;-)
166: }
167: op.pressKey(KeyEvent.VK_ENTER);
168: op.waitModified(true);
169: int newPossition = op.txtEditorPane().getCaretPosition();
170: int newLine = Utilities.getLineOffset(doc, newPossition) + 1;
171: int newOffset = newPossition
172: - Utilities.getRowStart(doc, newPossition);
173: if (debug) {
174: Thread.sleep(3000); // to be visible ;-)
175: }
176: assertEquals("FINAL POSSITION", endLineNum, newLine);
177: assertEquals("FINAL POSSITION", endOffset - 1, newOffset);
178: }
179:
180: private EditorOperator openFile(String fileName)
181: throws DataObjectNotFoundException, IOException {
182: File file = new File(new File(projectDir, "web"), fileName);
183: DataObject dataObj = DataObject.find(FileUtil
184: .toFileObject(file));
185: EditorCookie ed = dataObj.getCookie(EditorCookie.class);
186: doc = (BaseDocument) ed.openDocument();
187: ed.open();
188: EditorOperator operator = new EditorOperator(fileName);
189: return operator;
190: }
191:
192: public static void main(String[] args) throws Exception {
193: IndentCasesTest test = new IndentCasesTest();
194: test.projectDir = new File(
195: "/export/home/jindra/TRUNK/web/jspsyntax/test/qa-functional/data/IndentationTestProjects/IndentationTest");
196: }
197: }
|