001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 2008 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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.cnd.editor.cplusplus;
041:
042: import javax.swing.text.BadLocationException;
043: import org.netbeans.modules.cnd.editor.api.CodeStyle;
044: import org.netbeans.modules.cnd.editor.options.EditorOptions;
045: import org.netbeans.modules.cnd.editor.reformat.Reformatter;
046:
047: /**
048: *
049: * @author as204739
050: */
051: public class CCNewFormatterSingleTestCase extends
052: CCFormatterBaseUnitTestCase {
053:
054: public CCNewFormatterSingleTestCase(String testMethodName) {
055: super (testMethodName);
056: }
057:
058: /**
059: * Perform reformatting of the whole document's text.
060: */
061: @Override
062: protected void reformat() {
063: Reformatter f = new Reformatter(getDocument(), CodeStyle
064: .getDefault(getDocument()));
065: try {
066: f.reformat();
067: } catch (BadLocationException e) {
068: e.printStackTrace(getLog());
069: fail(e.getMessage());
070: }
071: }
072:
073: private void setDefaultsOptions() {
074: EditorOptions.resetToDefault(CodeStyle
075: .getDefault(CodeStyle.Language.CPP));
076: }
077:
078: // public void testIdentMultyConstructor3() {
079: // setDefaultsOptions();
080: // setLoadDocumentText(
081: // "class IndexReader : LUCENE_BASE\n" +
082: // "{\n" +
083: // "public:\n" +
084: // "class IndexReaderCommitLockWith : \n" +
085: // "public CL_NS(store)::LuceneLockWith\n" +
086: // "{\n" +
087: // "private:\n" +
088: // "IndexReader* reader;\n" +
089: // "};\n" +
090: // "};\n"
091: // );
092: // reformat();
093: // assertDocumentText("Incorrect identing multyline constructor",
094: // "class IndexReader : LUCENE_BASE\n" +
095: // "{\n" +
096: // "public:\n" +
097: // " class IndexReaderCommitLockWith :\n" +
098: // " public CL_NS(store)::LuceneLockWith\n" +
099: // " {\n" +
100: // " private:\n" +
101: // " IndexReader* reader;\n" +
102: // " };\n" +
103: // "};\n"
104: // );
105: // }
106:
107: // public void testCaseIndentAftePreprocessor() {
108: // setDefaultsOptions();
109: // setLoadDocumentText(
110: // " C_MODE_START\n" +
111: // "# include <decimal.h>\n" +
112: // " C_MODE_END\n" +
113: // "\n" +
114: // "# define DECIMAL_LONGLONG_DIGITS 22\n" +
115: // "\n" +
116: // "\n" +
117: // " /* maximum length of buffer in our big digits (uint32) */\n" +
118: // "# define DECIMAL_BUFF_LENGTH 9\n" +
119: // " /*\n" +
120: // " point on the border of our big digits))\n" +
121: // "*/\n" +
122: // "# define DECIMAL_MAX_PRECISION ((DECIMAL_BUFF_LENGTH * 9) - 8*2)\n" +
123: // "\n"
124: // );
125: // reformat();
126: // assertDocumentText("Incorrect identing case after preprocessor",
127: // "C_MODE_START\n" +
128: // "#include <decimal.h>\n" +
129: // "C_MODE_END\n" +
130: // "\n" +
131: // "#define DECIMAL_LONGLONG_DIGITS 22\n" +
132: // "\n" +
133: // "\n" +
134: // "/* maximum length of buffer in our big digits (uint32) */\n" +
135: // "#define DECIMAL_BUFF_LENGTH 9\n" +
136: // "/*\n" +
137: // "point on the border of our big digits))\n" +
138: // "*/\n" +
139: // "#define DECIMAL_MAX_PRECISION ((DECIMAL_BUFF_LENGTH * 9) - 8*2)\n" +
140: // "\n"
141: // );
142: // }
143: //
144:
145: public void testIdentFunctionDefinition2() {
146: setDefaultsOptions();
147: setLoadDocumentText("getcmdline(int firstc)\n" + "{\n"
148: + " if (firstc == '/')\n" + " {\n"
149: + "#ifdef USE_IM_CONTROL\n"
150: + " im_set_active(*b_im_ptr == B_IMODE_IM);\n"
151: + "#endif\n" + " }\n" + "#ifdef USE_IM_CONTROL\n"
152: + " else if (p_imcmdline)\n"
153: + " im_set_active(TRUE);\n" + "#endif\n" + "}\n");
154: reformat();
155: assertDocumentText(
156: "Incorrect identing function definition",
157: "getcmdline(int firstc)\n"
158: + "{\n"
159: + " if (firstc == '/') {\n"
160: + "#ifdef USE_IM_CONTROL\n"
161: + " im_set_active(*b_im_ptr == B_IMODE_IM);\n"
162: + "#endif\n" + " }\n"
163: + "#ifdef USE_IM_CONTROL\n"
164: + " else if (p_imcmdline)\n"
165: + " im_set_active(TRUE);\n" + "#endif\n"
166: + "}\n");
167: }
168:
169: }
|