Source Code Cross Referenced for CCFormatterUnitTestCase.java in  » IDE-Netbeans » cnd » org » netbeans » modules » cnd » editor » cplusplus » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » cnd » org.netbeans.modules.cnd.editor.cplusplus 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:
029:        package org.netbeans.modules.cnd.editor.cplusplus;
030:
031:        import org.netbeans.modules.cnd.editor.api.CodeStyle;
032:        import org.netbeans.modules.cnd.editor.options.EditorOptions;
033:
034:        /**
035:         * Class was taken from java
036:         * Links point to java IZ.
037:         * C/C++ specific tests begin from testReformatSimpleClass
038:         *
039:         * @author Alexander Simon
040:         */
041:        public class CCFormatterUnitTestCase extends
042:                CCFormatterBaseUnitTestCase {
043:
044:            public CCFormatterUnitTestCase(String testMethodName) {
045:                super (testMethodName);
046:            }
047:
048:            // -------- Reformat tests -----------
049:
050:            public void testReformatMultiLineSystemOutPrintln() {
051:                setLoadDocumentText("void m() {\n" + "    printf(\n"
052:                        + "    \"haf\");\n" + "}\n");
053:                reformat();
054:                assertDocumentText("Incorrect new-line indent", "void m()\n"
055:                        + "{\n" + "    printf(\n" + "            \"haf\");\n"
056:                        + "}\n");
057:            }
058:
059:            public void testReformatMultiLineSystemOutPrintln2() {
060:                EditorOptions.getPreferences(
061:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
062:                        EditorOptions.newLineBeforeBraceDeclaration,
063:                        CodeStyle.BracePlacement.SAME_LINE.name());
064:                try {
065:                    setLoadDocumentText("void m() {\n" + "    printf(\n"
066:                            + "    \"haf\");\n" + "}\n");
067:                    reformat();
068:                    assertDocumentText("Incorrect new-line indent",
069:                            "void m() {\n" + "    printf(\n"
070:                                    + "            \"haf\");\n" + "}\n");
071:                } finally {
072:                    EditorOptions.getPreferences(
073:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
074:                            EditorOptions.newLineBeforeBraceDeclaration,
075:                            CodeStyle.BracePlacement.NEW_LINE.name());
076:                }
077:            }
078:
079:            //    public void testReformatMultiLineClassDeclaration() {
080:            //        setLoadDocumentText(
081:            //                "public class C\n"
082:            //                + ": public Runnable {\n"
083:            //                + "int printf(int);\n"
084:            //                + "};\n"
085:            //                );
086:            //        reformat();
087:            //        assertDocumentText("Incorrect new-line indent",
088:            //                "public class C\n"
089:            //                + "        : public Runnable {\n"
090:            //                + "    int printf(int);\n"
091:            //                + "};\n"
092:            //                );
093:            //        
094:            //    }
095:
096:            // tests for regressions
097:
098:            /**
099:             * Tests reformatting of new on two lines
100:             * @see http://www.netbeans.org/issues/show_bug.cgi?id6065
101:             */
102:            public void testReformatNewOnTwoLines() {
103:                setLoadDocumentText("javax::swing::JPanel* panel =\n"
104:                        + "new java::swing::JPanel();");
105:                reformat();
106:                assertDocumentText("Incorrect new on two lines reformating",
107:                        "javax::swing::JPanel* panel =\n"
108:                                + "        new java::swing::JPanel();");
109:            }
110:
111:            /**
112:             * Tests reformatting of ternary conditional operators on multiple lines
113:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=23508
114:             */
115:            public void testReformatTernaryConditionalOperator() {
116:                setLoadDocumentText("something = (someComplicatedExpression != null) ?\n"
117:                        + "(aComplexCalculation) :\n"
118:                        + "(anotherComplexCalculation);");
119:                reformat();
120:                assertDocumentText(
121:                        "Incorrect ternary conditional operator reformatting",
122:                        "something = (someComplicatedExpression != null) ?\n"
123:                                + "    (aComplexCalculation) :\n"
124:                                + "    (anotherComplexCalculation);");
125:            }
126:
127:            /**
128:             * Test reformatting of array initializer with newlines on
129:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=47069
130:             */
131:            public void testReformatArrayInitializerWithNewline() {
132:                setLoadDocumentText("int[] foo = new int[] {1, 2, 3};");
133:                reformat();
134:                assertDocumentText(
135:                        "Incorrect array initializer with newline reformatting",
136:                        "int[] foo = new int[] {1, 2, 3};");
137:            }
138:
139:            /**
140:             * Test reformatting of newline braces to normal ones
141:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=48926
142:             */
143:            public void testReformatNewlineBracesToNormalOnes() {
144:                setLoadDocumentText("try\n" + "{\n" + "printf(\"test\");\n"
145:                        + "}\n" + "catch (Exception e)\n" + "{\n"
146:                        + "printf(\"exception\");\n" + "}");
147:                reformat();
148:                assertDocumentText(
149:                        "Incorrect array initializer with newline reformatting",
150:                        "try {\n" + "    printf(\"test\");\n" + "}\n"
151:                                + "catch (Exception e) {\n"
152:                                + "    printf(\"exception\");\n" + "}");
153:            }
154:
155:            /**
156:             * Test reformatting of multiline constructors
157:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=49450
158:             */
159:            public void testReformatMultilineConstructor() {
160:                EditorOptions.getPreferences(
161:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
162:                        EditorOptions.newLineBeforeBraceDeclaration,
163:                        CodeStyle.BracePlacement.SAME_LINE.name());
164:                try {
165:                    setLoadDocumentText("class Test {\n" + "Test(int one,\n"
166:                            + "int two,\n" + "int three,\n" + "int four) {\n"
167:                            + "this.one = one;\n" + "}\n" + "};");
168:                    reformat();
169:                    assertDocumentText(
170:                            "Incorrect multiline constructor reformatting",
171:                            "class Test {\n" + "    Test(int one,\n"
172:                                    + "            int two,\n"
173:                                    + "            int three,\n"
174:                                    + "            int four) {\n"
175:                                    + "        this.one = one;\n" + "    }\n"
176:                                    + "};");
177:                } finally {
178:                    EditorOptions.getPreferences(
179:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
180:                            EditorOptions.newLineBeforeBraceDeclaration,
181:                            CodeStyle.BracePlacement.NEW_LINE.name());
182:                }
183:            }
184:
185:            /**
186:             * Test reformatting of multiline constructors
187:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=49450
188:             */
189:            public void testReformatMultilineConstructor2() {
190:                setLoadDocumentText("class Test {\n" + "Test(int one,\n"
191:                        + "int two,\n" + "int three,\n" + "int four) {\n"
192:                        + "this.one = one;\n" + "}\n" + "};");
193:                reformat();
194:                assertDocumentText(
195:                        "Incorrect multiline constructor reformatting",
196:                        "class Test\n" + "{\n" + "    Test(int one,\n"
197:                                + "            int two,\n"
198:                                + "            int three,\n"
199:                                + "            int four)\n" + "    {\n"
200:                                + "        this.one = one;\n" + "    }\n"
201:                                + "};");
202:            }
203:
204:            /**
205:             * Test reformatting of if else without brackets
206:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
207:             */
208:            public void testReformatIfElseWithoutBrackets() {
209:                setLoadDocumentText("if (count == 0)\n" + "return 0.0f;\n"
210:                        + "else\n" + "return performanceSum / getCount()");
211:                reformat();
212:                assertDocumentText(
213:                        "Incorrect reformatting of if-else without brackets",
214:                        "if (count == 0)\n" + "    return 0.0f;\n" + "else\n"
215:                                + "    return performanceSum / getCount()");
216:            }
217:
218:            /**
219:             * Test reformatting of class
220:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=97544
221:             */
222:            public void testReformatSimpleClass() {
223:                EditorOptions.getPreferences(
224:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
225:                        EditorOptions.newLineBeforeBraceDeclaration,
226:                        CodeStyle.BracePlacement.SAME_LINE.name());
227:                try {
228:                    setLoadDocumentText("class C {\n" + "protected:\n"
229:                            + "int i;\n" + "int foo();\n" + "private:\n"
230:                            + "int j;\n" + "public:\n" + "int k;\n" + "};\n");
231:                    reformat();
232:                    assertDocumentText(
233:                            "Incorrect reformatting of simple class",
234:                            "class C {\n" + "protected:\n" + "    int i;\n"
235:                                    + "    int foo();\n" + "private:\n"
236:                                    + "    int j;\n" + "public:\n"
237:                                    + "    int k;\n" + "};\n");
238:                } finally {
239:                    EditorOptions.getPreferences(
240:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
241:                            EditorOptions.newLineBeforeBraceDeclaration,
242:                            CodeStyle.BracePlacement.NEW_LINE.name());
243:                }
244:            }
245:
246:            /**
247:             * Test reformatting of class
248:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=97544
249:             */
250:            public void testReformatSimpleClass2() {
251:                setLoadDocumentText("class C {\n" + "protected:\n" + "int i;\n"
252:                        + "int foo();\n" + "private:\n" + "int j;\n"
253:                        + "public:\n" + "int k;\n" + "};\n");
254:                reformat();
255:                assertDocumentText("Incorrect reformatting of simple class",
256:                        "class C\n" + "{\n" + "protected:\n" + "    int i;\n"
257:                                + "    int foo();\n" + "private:\n"
258:                                + "    int j;\n" + "public:\n" + "    int k;\n"
259:                                + "};\n");
260:            }
261:
262:            /**
263:             * Test reformatting of For without braces
264:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=98475
265:             */
266:            public void testReformatForWithoutBraces() {
267:                setLoadDocumentText("for (i = 0; i < MAXBUCKET; i++) {\n"
268:                        + "for (j = 0; j < MAXBUCKET; j++)\n"
269:                        + "if (i != j) {\n" + "if (isempty()) {\n"
270:                        + "pour(current, i, j);\n" + "insCnf(current);\n"
271:                        + "}\n" + "}\n" + "}\n");
272:                reformat();
273:                assertDocumentText(
274:                        "Incorrect reformatting of For without braces",
275:                        "for (i = 0; i < MAXBUCKET; i++) {\n"
276:                                + "    for (j = 0; j < MAXBUCKET; j++)\n"
277:                                + "        if (i != j) {\n"
278:                                + "            if (isempty()) {\n"
279:                                + "                pour(current, i, j);\n"
280:                                + "                insCnf(current);\n"
281:                                + "            }\n" + "        }\n" + "}\n");
282:            }
283:
284:            /**
285:             * Test reformatting for preprocessors directives
286:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=100665
287:             */
288:            public void testReformatPreprocessorsDirectives() {
289:                EditorOptions.getPreferences(
290:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
291:                        EditorOptions.newLineBeforeBraceDeclaration,
292:                        CodeStyle.BracePlacement.SAME_LINE.name());
293:                try {
294:                    setLoadDocumentText("main() {\n" + "#define AAA 1\n"
295:                            + "int aaa;\n" + "#define BBB 2\n" + "long bbb;\n"
296:                            + "int ccc;\n" + "int ddd;\n" + "}\n");
297:                    reformat();
298:                    assertDocumentText(
299:                            "Incorrect reformatting for preprocessors directives",
300:                            "main() {\n" + "#define AAA 1\n" + "    int aaa;\n"
301:                                    + "#define BBB 2\n" + "    long bbb;\n"
302:                                    + "    int ccc;\n" + "    int ddd;\n"
303:                                    + "}\n");
304:                } finally {
305:                    EditorOptions.getPreferences(
306:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
307:                            EditorOptions.newLineBeforeBraceDeclaration,
308:                            CodeStyle.BracePlacement.NEW_LINE.name());
309:                }
310:            }
311:
312:            /**
313:             * Test reformatting for preprocessors directives
314:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=100665
315:             */
316:            public void testReformatPreprocessorsDirectives2() {
317:                setLoadDocumentText("main() {\n" + "#define AAA 1\n"
318:                        + "int aaa;\n" + "#define BBB 2\n" + "long bbb;\n"
319:                        + "int ccc;\n" + "int ddd;\n" + "}\n");
320:                reformat();
321:                assertDocumentText(
322:                        "Incorrect reformatting for preprocessors directives",
323:                        "main()\n" + "{\n" + "#define AAA 1\n"
324:                                + "    int aaa;\n" + "#define BBB 2\n"
325:                                + "    long bbb;\n" + "    int ccc;\n"
326:                                + "    int ddd;\n" + "}\n");
327:            }
328:
329:            //    /**
330:            //     * Test reformatting of function arguments list
331:            //     * @see http://www.netbeans.org/issues/show_bug.cgi?id=115628
332:            //     */
333:            //    public void testReformatFunctionArguments() {
334:            //        setLoadDocumentText(
335:            //            "z = myfoo(a,\n" +
336:            //            "b,\n" +
337:            //            "c);\n");
338:            //        reformat();
339:            //        assertDocumentText("Incorrect reformatting of function arguments list",
340:            //            "z = myfoo(a,\n" +
341:            //            "          b,\n" +
342:            //            "          c);\n");
343:            //    }
344:
345:            /**
346:             * Test reformatting of constructor initializer
347:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
348:             */
349:            public void testReformatConstructorInitializer() {
350:                EditorOptions.getPreferences(
351:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
352:                        EditorOptions.newLineBeforeBraceDeclaration,
353:                        CodeStyle.BracePlacement.SAME_LINE.name());
354:                try {
355:                    setLoadDocumentText("Cpu::Cpu(int type, int architecture, int units) :\n"
356:                            + "Module(\"CPU\", \"generic\", type, architecture, units) {\n"
357:                            + "ComputeSupportMetric();\n" + "}\n");
358:                    reformat();
359:                    assertDocumentText(
360:                            "Incorrect reformatting of constructor initializer",
361:                            "Cpu::Cpu(int type, int architecture, int units) :\n"
362:                                    + "Module(\"CPU\", \"generic\", type, architecture, units) {\n"
363:                                    + "    ComputeSupportMetric();\n" + "}\n");
364:                } finally {
365:                    EditorOptions.getPreferences(
366:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
367:                            EditorOptions.newLineBeforeBraceDeclaration,
368:                            CodeStyle.BracePlacement.NEW_LINE.name());
369:                }
370:            }
371:
372:            /**
373:             * Test reformatting of constructor initializer
374:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
375:             */
376:            public void testReformatConstructorInitializer2() {
377:                setLoadDocumentText("Cpu::Cpu(int type, int architecture, int units) :\n"
378:                        + "Module(\"CPU\", \"generic\", type, architecture, units) {\n"
379:                        + "ComputeSupportMetric();\n" + "}\n");
380:                reformat();
381:                assertDocumentText(
382:                        "Incorrect reformatting of constructor initializer",
383:                        "Cpu::Cpu(int type, int architecture, int units) :\n"
384:                                + "Module(\"CPU\", \"generic\", type, architecture, units)\n"
385:                                + "{\n" + "    ComputeSupportMetric();\n"
386:                                + "}\n");
387:            }
388:
389:            /**
390:             * Test reformatting of constructor initializer
391:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
392:             */
393:            public void testReformatMultilineMainDefinition() {
394:                EditorOptions.getPreferences(
395:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
396:                        EditorOptions.newLineBeforeBraceDeclaration,
397:                        CodeStyle.BracePlacement.SAME_LINE.name());
398:                try {
399:                    setLoadDocumentText("int\n"
400:                            + "main(int argc, char** argv) {\n"
401:                            + "return (EXIT_SUCCESS);\n" + "};\n");
402:                    reformat();
403:                    assertDocumentText(
404:                            "Incorrect reformatting of multi line main definition",
405:                            "int\n" + "main(int argc, char** argv) {\n"
406:                                    + "    return (EXIT_SUCCESS);\n" + "};\n");
407:                } finally {
408:                    EditorOptions.getPreferences(
409:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
410:                            EditorOptions.newLineBeforeBraceDeclaration,
411:                            CodeStyle.BracePlacement.NEW_LINE.name());
412:                }
413:            }
414:
415:            /**
416:             * Test reformatting of constructor initializer
417:             * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
418:             */
419:            public void testReformatMultilineMainDefinition2() {
420:                setLoadDocumentText("int\n" + "main(int argc, char** argv) {\n"
421:                        + "return (EXIT_SUCCESS);\n" + "};\n");
422:                reformat();
423:                assertDocumentText(
424:                        "Incorrect reformatting of multi line main definition",
425:                        "int\n" + "main(int argc, char** argv)\n" + "{\n"
426:                                + "    return (EXIT_SUCCESS);\n" + "};\n");
427:            }
428:
429:            //    /**
430:            //     * Test reformatting of unbalanced braces
431:            //     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561
432:            //     */
433:            //    public void testReformatUnbalancedBraces() {
434:            //        setLoadDocumentText(
435:            //            "void foo() {\n" +
436:            //            "#if A\n" +
437:            //            "if (0) {\n" +
438:            //            "#else\n" +
439:            //            "if (1) {\n" +
440:            //            "#endif\n" +
441:            //            "}\n" +
442:            //            "}\n");
443:            //        reformat();
444:            //        assertDocumentText("Incorrect reformatting of unbalanced braces",
445:            //            "void foo() {\n" +
446:            //            "#if A\n" +
447:            //            "    if (0) {\n" +
448:            //            "#else\n" +
449:            //            "    if (1) {\n" +
450:            //            "#endif\n" +
451:            //            "    }\n" +
452:            //            "}\n");
453:            //    }
454:
455:            public void testIdentInnerEnum() {
456:                EditorOptions.getPreferences(
457:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
458:                        EditorOptions.newLineBeforeBraceDeclaration,
459:                        CodeStyle.BracePlacement.SAME_LINE.name());
460:                try {
461:                    setLoadDocumentText("class NdbTransaction {\n"
462:                            + "#ifndef D\n" + "friend class Ndb;\n"
463:                            + "#endif\n" + "\n" + "public:\n" + "\n"
464:                            + "enum AbortOption {\n" + "#ifndef D\n"
465:                            + "AbortOnError=::AbortOnError,\n" + "#endif\n"
466:                            + "AO_IgnoreError=::AO_IgnoreError,\n"
467:                            + "AO_SkipError\n" + "};\n" + "};\n");
468:                    reformat();
469:                    assertDocumentText(
470:                            "Incorrect identing of inner enum",
471:                            "class NdbTransaction {\n"
472:                                    + "#ifndef D\n"
473:                                    + "    friend class Ndb;\n"
474:                                    + "#endif\n"
475:                                    + "    \n"
476:                                    + "public:\n"
477:                                    + "    \n"
478:                                    + "    enum AbortOption {\n"
479:                                    + "#ifndef D\n"
480:                                    + "        AbortOnError=::AbortOnError,\n"
481:                                    + "#endif\n"
482:                                    + "        AO_IgnoreError=::AO_IgnoreError,\n"
483:                                    + "        AO_SkipError\n" + "    };\n"
484:                                    + "};\n");
485:                } finally {
486:                    EditorOptions.getPreferences(
487:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
488:                            EditorOptions.newLineBeforeBraceDeclaration,
489:                            CodeStyle.BracePlacement.NEW_LINE.name());
490:                }
491:            }
492:
493:            public void testIdentInnerEnum2() {
494:                setLoadDocumentText("class NdbTransaction {\n" + "#ifndef D\n"
495:                        + "friend class Ndb;\n" + "#endif\n" + "\n"
496:                        + "public:\n" + "\n" + "enum AbortOption {\n"
497:                        + "#ifndef D\n" + "AbortOnError=::AbortOnError,\n"
498:                        + "#endif\n" + "AO_IgnoreError=::AO_IgnoreError,\n"
499:                        + "AO_SkipError\n" + "};\n" + "};\n");
500:                reformat();
501:                assertDocumentText("Incorrect identing of inner enum",
502:                        "class NdbTransaction\n" + "{\n" + "#ifndef D\n"
503:                                + "    friend class Ndb;\n" + "#endif\n"
504:                                + "    \n" + "public:\n" + "    \n"
505:                                + "    enum AbortOption\n" + "    {\n"
506:                                + "#ifndef D\n"
507:                                + "        AbortOnError=::AbortOnError,\n"
508:                                + "#endif\n"
509:                                + "        AO_IgnoreError=::AO_IgnoreError,\n"
510:                                + "        AO_SkipError\n" + "    };\n"
511:                                + "};\n");
512:            }
513:
514:            public void testTemplate() {
515:                EditorOptions.getPreferences(
516:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
517:                        EditorOptions.newLineBeforeBraceDeclaration,
518:                        CodeStyle.BracePlacement.SAME_LINE.name());
519:                try {
520:                    setLoadDocumentText("template <class T, class U>\n"
521:                            + "class KeyTable2 : public DLHashTable2<T, U> {\n"
522:                            + "public:\n" + "KeyTable2(ArrayPool<U>& pool) :\n"
523:                            + "DLHashTable2<T, U>(pool) {\n" + "}\n" + "\n"
524:                            + "bool find(Ptr<T>& ptr, const T& rec) const {\n"
525:                            + "return DLHashTable2<T, U>::find(ptr, rec);\n"
526:                            + "}\n" + "};\n");
527:                    reformat();
528:                    assertDocumentText(
529:                            "Incorrect identing of template class",
530:                            "template <class T, class U>\n"
531:                                    + "class KeyTable2 : public DLHashTable2<T, U> {\n"
532:                                    + "public:\n"
533:                                    + "    KeyTable2(ArrayPool<U>& pool) :\n"
534:                                    + "    DLHashTable2<T, U>(pool) {\n"
535:                                    + "    }\n"
536:                                    + "    \n"
537:                                    + "    bool find(Ptr<T>& ptr, const T& rec) const {\n"
538:                                    + "        return DLHashTable2<T, U>::find(ptr, rec);\n"
539:                                    + "    }\n" + "};\n");
540:                } finally {
541:                    EditorOptions.getPreferences(
542:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
543:                            EditorOptions.newLineBeforeBraceDeclaration,
544:                            CodeStyle.BracePlacement.NEW_LINE.name());
545:                }
546:            }
547:
548:            public void testTemplate2() {
549:                setLoadDocumentText("template <class T, class U>\n"
550:                        + "class KeyTable2 : public DLHashTable2<T, U> {\n"
551:                        + "public:\n" + "KeyTable2(ArrayPool<U>& pool) :\n"
552:                        + "DLHashTable2<T, U>(pool) {\n" + "}\n" + "\n"
553:                        + "bool find(Ptr<T>& ptr, const T& rec) const {\n"
554:                        + "return DLHashTable2<T, U>::find(ptr, rec);\n"
555:                        + "}\n" + "};\n");
556:                reformat();
557:                assertDocumentText(
558:                        "Incorrect identing of template class",
559:                        "template <class T, class U>\n"
560:                                + "class KeyTable2 : public DLHashTable2<T, U>\n"
561:                                + "{\n"
562:                                + "public:\n"
563:                                + "    KeyTable2(ArrayPool<U>& pool) :\n"
564:                                + "    DLHashTable2<T, U>(pool)\n"
565:                                + "    {\n"
566:                                + "    }\n"
567:                                + "    \n"
568:                                + "    bool find(Ptr<T>& ptr, const T& rec) const\n"
569:                                + "    {\n"
570:                                + "        return DLHashTable2<T, U>::find(ptr, rec);\n"
571:                                + "    }\n" + "};\n");
572:            }
573:
574:            public void testIdentPreprocessorElase() {
575:                setLoadDocumentText("#if defined(USE_MB)\n"
576:                        + "if (use_mb(cs)) {\n"
577:                        + "result_state = IDENT_QUOTED;\n" + "}\n" + "#endif\n"
578:                        + "{\n" + "}\n");
579:                reformat();
580:                assertDocumentText("Incorrect identing of preprocessor else",
581:                        "#if defined(USE_MB)\n" + "if (use_mb(cs)) {\n"
582:                                + "    result_state = IDENT_QUOTED;\n" + "}\n"
583:                                + "#endif\n" + "{\n" + "}\n");
584:            };
585:
586:            public void testIdentDefine() {
587:                setLoadDocumentText("int\n" + "main() {\n" + "int z;\n"
588:                        + "#define X \\\n" + "        a+\\\n"
589:                        + "        b+ \\\n" + "        c \n" + "z++;\n" + "}\n");
590:                reformat();
591:                assertDocumentText("Incorrect identing of preprocessor else",
592:                        "int\n" + "main()\n" + "{\n" + "    int z;\n"
593:                                + "#define X \\\n" + "        a+\\\n"
594:                                + "        b+ \\\n" + "        c\n"
595:                                + "    z++;\n" + "}\n");
596:            };
597:
598:            public void testIdentMultyLineMain() {
599:                EditorOptions.getPreferences(
600:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
601:                        EditorOptions.newLineBeforeBraceDeclaration,
602:                        CodeStyle.BracePlacement.SAME_LINE.name());
603:                try {
604:                    setLoadDocumentText("long z;\n" + "int\n" + "main() {\n"
605:                            + "short a;\n" + "}\n");
606:                    reformat();
607:                    assertDocumentText("Incorrect identing multyline main",
608:                            "long z;\n" + "int\n" + "main() {\n"
609:                                    + "    short a;\n" + "}\n");
610:                } finally {
611:                    EditorOptions.getPreferences(
612:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
613:                            EditorOptions.newLineBeforeBraceDeclaration,
614:                            CodeStyle.BracePlacement.NEW_LINE.name());
615:                }
616:            };
617:
618:            public void testIdentMultyLineMain2() {
619:                setLoadDocumentText("long z;\n" + "int\n" + "main() {\n"
620:                        + "short a;\n" + "}\n");
621:                reformat();
622:                assertDocumentText("Incorrect identing multyline main",
623:                        "long z;\n" + "int\n" + "main()\n" + "{\n"
624:                                + "    short a;\n" + "}\n");
625:            };
626:
627:            public void testIdentMultyConstructor() {
628:                EditorOptions.getPreferences(
629:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
630:                        EditorOptions.newLineBeforeBraceDeclaration,
631:                        CodeStyle.BracePlacement.SAME_LINE.name());
632:                try {
633:                    setLoadDocumentText("Log_event::Log_event(uint flags_arg, bool using_trans)\n"
634:                            + "        :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg)\n"
635:                            + "        {\n"
636:                            + "                server_id=thd->server_id;\n"
637:                            + "        }\n");
638:                    reformat();
639:                    assertDocumentText(
640:                            "Incorrect identing multyline constructor",
641:                            "Log_event::Log_event(uint flags_arg, bool using_trans)\n"
642:                                    + ":log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg) {\n"
643:                                    + "    server_id=thd->server_id;\n" + "}\n");
644:                } finally {
645:                    EditorOptions.getPreferences(
646:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
647:                            EditorOptions.newLineBeforeBraceDeclaration,
648:                            CodeStyle.BracePlacement.NEW_LINE.name());
649:                }
650:            };
651:
652:            public void testIdentMultyConstructor2() {
653:                setLoadDocumentText("Log_event::Log_event(const char* buf,\n"
654:                        + "        const Format_description_log_event* description_event)\n"
655:                        + "        :temp_buf(0), cache_stmt(0)\n"
656:                        + "        {\n"
657:                        + "                server_id=thd->server_id;\n"
658:                        + "        }\n");
659:                reformat();
660:                assertDocumentText(
661:                        "Incorrect identing multyline constructor",
662:                        "Log_event::Log_event(const char* buf,\n"
663:                                + "        const Format_description_log_event* description_event)\n"
664:                                + ":temp_buf(0), cache_stmt(0)\n" + "{\n"
665:                                + "    server_id=thd->server_id;\n" + "}\n");
666:            };
667:
668:            public void testIdentDefineBrace() {
669:                setLoadDocumentText("#define BRACE {\n" + "int main() {\n"
670:                        + "if (a){\n" + "}\n" + "}\n");
671:                reformat();
672:                assertDocumentText("Incorrect identing define brace",
673:                        "#define BRACE {\n" + "int main()\n" + "{\n"
674:                                + "    if (a){\n" + "    }\n" + "}\n");
675:            };
676:
677:            public void testIdentDefineBrace2() {
678:                setLoadDocumentText("#define BRACE }\n" + "int main() {\n"
679:                        + "if (a){\n" + "}\n" + "}\n");
680:                reformat();
681:                assertDocumentText("Incorrect identing define brace",
682:                        "#define BRACE }\n" + "int main()\n" + "{\n"
683:                                + "    if (a){\n" + "    }\n" + "}\n");
684:            };
685:
686:            //    public void testIdentMultyConstructor3() {
687:            //        setLoadDocumentText(
688:            //            "Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,\n" +
689:            //            "        ulong query_length, bool using_trans,\n" +
690:            //            "        bool suppress_use)\n" +
691:            //            ":Log_event(thd_arg,\n" +
692:            //            "        ((thd_arg->tmp_table_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0)\n" +
693:            //            "        & (suppress_use          ? LOG_EVENT_SUPPRESS_USE_F    : 0)),\n" +
694:            //            "                using_trans),\n" +
695:            //            "                data_buf(0), query(query_arg), catalog(thd_arg->catalog),\n" +
696:            //            "                db(thd_arg->db), q_len((uint32) query_length),\n" +
697:            //            "                error_code((thd_arg->killed != THD::NOT_KILLED) ?\n" +
698:            //            "                    ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ?\n" +
699:            //            "                        0 : thd->killed_errno()) : thd_arg->net.last_errno),\n" +
700:            //            "                                thread_id(thd_arg->thread_id),\n" +
701:            //            "                                /* save the original thread id; we already know the server id */\n" +
702:            //            "                                slave_proxy_id(thd_arg->variables.pseudo_thread_id),\n" +
703:            //            "                                flags2_inited(1), sql_mode_inited(1), charset_inited(1),\n" +
704:            //            "                                sql_mode(thd_arg->variables.sql_mode),\n" +
705:            //            "                                auto_increment_increment(thd_arg->variables.auto_increment_increment),\n" +
706:            //            "                                auto_increment_offset(thd_arg->variables.auto_increment_offset)\n" +
707:            //            "                        {\n" +
708:            //            "                            time_t end_time;\n" +
709:            //            "                        }\n"
710:            //            );
711:            //        reformat();
712:            //        assertDocumentText("Incorrect identing multyline constructor",
713:            //            "Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,\n" +
714:            //            "        ulong query_length, bool using_trans,\n" +
715:            //            "        bool suppress_use)\n" +
716:            //            ":Log_event(thd_arg,\n" +
717:            //            "        ((thd_arg->tmp_table_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0)\n" +
718:            //            "& (suppress_use          ? LOG_EVENT_SUPPRESS_USE_F    : 0)),\n" +
719:            //            "        using_trans),\n" +
720:            //            "        data_buf(0), query(query_arg), catalog(thd_arg->catalog),\n" +
721:            //            "        db(thd_arg->db), q_len((uint32) query_length),\n" +
722:            //            "        error_code((thd_arg->killed != THD::NOT_KILLED) ?\n" +
723:            //            "            ((thd_arg->system_thread & SYSTEM_THREAD_DELAYED_INSERT) ?\n" +
724:            //            "                 0 : thd->killed_errno()) : thd_arg->net.last_errno),\n" +
725:            //            "        thread_id(thd_arg->thread_id),\n" +
726:            //            "        /* save the original thread id; we already know the server id */\n" +
727:            //            "        slave_proxy_id(thd_arg->variables.pseudo_thread_id),\n" +
728:            //            "        flags2_inited(1), sql_mode_inited(1), charset_inited(1),\n" +
729:            //            "        sql_mode(thd_arg->variables.sql_mode),\n" +
730:            //            "        auto_increment_increment(thd_arg->variables.auto_increment_increment),\n" +
731:            //            "        auto_increment_offset(thd_arg->variables.auto_increment_offset) {\n" +
732:            //            "    time_t end_time;\n" +
733:            //            "}\n"
734:            //        );
735:            //    };
736:
737:            public void testMacroDefineWithBrace() {
738:                setLoadDocumentText("#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
739:                reformat();
740:                assertDocumentText(
741:                        "Incorrect formatting for macro define with brace",
742:                        "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
743:            };
744:
745:            public void testMacroDefineWithBrace1() {
746:                setLoadDocumentText("\n"
747:                        + "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
748:                reformat();
749:                assertDocumentText(
750:                        "Incorrect formatting for macro define with brace",
751:                        "\n"
752:                                + "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
753:            };
754:
755:            public void testMacroDefineWithBrace2() {
756:                EditorOptions.getPreferences(
757:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
758:                        EditorOptions.newLineBeforeBrace,
759:                        CodeStyle.BracePlacement.NEW_LINE.name());
760:                try {
761:                    setLoadDocumentText("#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
762:                    reformat();
763:                    assertDocumentText(
764:                            "Incorrect formatting for macro define with brace",
765:                            "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
766:                } finally {
767:                    EditorOptions.getPreferences(
768:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
769:                            EditorOptions.newLineBeforeBrace,
770:                            CodeStyle.BracePlacement.SAME_LINE.name());
771:                }
772:            }
773:
774:            public void testMacroDefineWithBrace3() {
775:                EditorOptions.getPreferences(
776:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
777:                        EditorOptions.newLineBeforeBrace,
778:                        CodeStyle.BracePlacement.NEW_LINE.name());
779:                try {
780:                    setLoadDocumentText("\n"
781:                            + "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
782:                    reformat();
783:                    assertDocumentText(
784:                            "Incorrect formatting for macro define with brace",
785:                            "\n"
786:                                    + "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
787:                } finally {
788:                    EditorOptions.getPreferences(
789:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
790:                            EditorOptions.newLineBeforeBrace,
791:                            CodeStyle.BracePlacement.SAME_LINE.name());
792:                }
793:            }
794:
795:            public void testMacroDefineWithParen() {
796:                EditorOptions.getPreferences(
797:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
798:                        EditorOptions.newLineBeforeBraceDeclaration,
799:                        CodeStyle.BracePlacement.SAME_LINE.name());
800:                try {
801:                    setLoadDocumentText("#include <stdio.h>\n"
802:                            + "#define M(x) puts(#x)\n" + "int main() {\n"
803:                            + "M(\"test\");\n" + "return 0;\n" + "}\n");
804:                    reformat();
805:                    assertDocumentText(
806:                            "Incorrect formatting for macro define with paren",
807:                            "#include <stdio.h>\n" + "#define M(x) puts(#x)\n"
808:                                    + "int main() {\n" + "    M(\"test\");\n"
809:                                    + "    return 0;\n" + "}\n");
810:                } finally {
811:                    EditorOptions.getPreferences(
812:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
813:                            EditorOptions.newLineBeforeBraceDeclaration,
814:                            CodeStyle.BracePlacement.NEW_LINE.name());
815:                }
816:            }
817:
818:            public void testMacroDefineWithParen11() {
819:                setLoadDocumentText("#include <stdio.h>\n"
820:                        + "#define M(x) puts(#x)\n" + "int main() {\n"
821:                        + "M(\"test\");\n" + "return 0;\n" + "}\n");
822:                reformat();
823:                assertDocumentText(
824:                        "Incorrect formatting for macro define with paren",
825:                        "#include <stdio.h>\n" + "#define M(x) puts(#x)\n"
826:                                + "int main()\n" + "{\n" + "    M(\"test\");\n"
827:                                + "    return 0;\n" + "}\n");
828:            }
829:
830:            public void testMacroDefineWithParen2() {
831:                EditorOptions.getPreferences(
832:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
833:                        .putBoolean(EditorOptions.spaceBeforeMethodCallParen,
834:                                true);
835:                EditorOptions.getPreferences(
836:                        CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
837:                        EditorOptions.newLineBeforeBraceDeclaration,
838:                        CodeStyle.BracePlacement.SAME_LINE.name());
839:                try {
840:                    setLoadDocumentText("#include <stdio.h>\n"
841:                            + "#define M(x) puts(#x)\n" + "int main() {\n"
842:                            + "    M(\"test\");\n" + "    return 0;\n" + "}\n");
843:                    reformat();
844:                    assertDocumentText(
845:                            "Incorrect formatting for macro define with paren",
846:                            "#include <stdio.h>\n" + "#define M(x) puts(#x)\n"
847:                                    + "int main () {\n" + "    M (\"test\");\n"
848:                                    + "    return 0;\n" + "}\n");
849:                } finally {
850:                    EditorOptions.getPreferences(
851:                            CodeStyle.getDefault(CodeStyle.Language.CPP))
852:                            .putBoolean(
853:                                    EditorOptions.spaceBeforeMethodCallParen,
854:                                    false);
855:                    EditorOptions.getPreferences(
856:                            CodeStyle.getDefault(CodeStyle.Language.CPP)).put(
857:                            EditorOptions.newLineBeforeBraceDeclaration,
858:                            CodeStyle.BracePlacement.NEW_LINE.name());
859:                }
860:            }
861:
862:            public void testMacroDefineWithParen21() {
863:                EditorOptions.getPreferences(
864:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
865:                        .putBoolean(EditorOptions.spaceBeforeMethodCallParen,
866:                                true);
867:                try {
868:                    setLoadDocumentText("#include <stdio.h>\n"
869:                            + "#define M(x) puts(#x)\n" + "int main() {\n"
870:                            + "    M(\"test\");\n" + "    return 0;\n" + "}\n");
871:                    reformat();
872:                    assertDocumentText(
873:                            "Incorrect formatting for macro define with paren",
874:                            "#include <stdio.h>\n" + "#define M(x) puts(#x)\n"
875:                                    + "int main ()\n" + "{\n"
876:                                    + "    M (\"test\");\n" + "    return 0;\n"
877:                                    + "}\n");
878:                } finally {
879:                    EditorOptions.getPreferences(
880:                            CodeStyle.getDefault(CodeStyle.Language.CPP))
881:                            .putBoolean(
882:                                    EditorOptions.spaceBeforeMethodCallParen,
883:                                    false);
884:                }
885:            }
886:
887:            public void testSwitchFormatting() {
888:                setLoadDocumentText("switch (GetTypeID()){\n" + "case FAST:\n"
889:                        + "metric += 100;\n" + "break;\n" + "case ULTRA:\n"
890:                        + "case SLOW:\n" + "metric += 200;\n" + "break;\n"
891:                        + "default:\n" + "break;\n" + "}\n");
892:                reformat();
893:                assertDocumentText(
894:                        "Incorrect formatting for macro define with paren",
895:                        "switch (GetTypeID()){\n" + "    case FAST:\n"
896:                                + "        metric += 100;\n"
897:                                + "        break;\n" + "    case ULTRA:\n"
898:                                + "    case SLOW:\n"
899:                                + "        metric += 200;\n"
900:                                + "        break;\n" + "    default:\n"
901:                                + "        break;\n" + "}\n");
902:            }
903:
904:            public void testSwitchFormatting2() {
905:                EditorOptions.getPreferences(
906:                        CodeStyle.getDefault(CodeStyle.Language.CPP))
907:                        .putBoolean(EditorOptions.indentCasesFromSwitch, false);
908:                try {
909:                    setLoadDocumentText("switch (GetTypeID()){\n"
910:                            + "case FAST:\n" + "metric += 100;\n" + "break;\n"
911:                            + "case ULTRA:\n" + "case SLOW:\n"
912:                            + "metric += 200;\n" + "break;\n" + "default:\n"
913:                            + "break;\n" + "}\n");
914:                    reformat();
915:                    assertDocumentText(
916:                            "Incorrect formatting for macro define with paren",
917:                            "switch (GetTypeID()){\n" + "case FAST:\n"
918:                                    + "    metric += 100;\n" + "    break;\n"
919:                                    + "case ULTRA:\n" + "case SLOW:\n"
920:                                    + "    metric += 200;\n" + "    break;\n"
921:                                    + "default:\n" + "    break;\n" + "}\n");
922:                } finally {
923:                    EditorOptions.getPreferences(
924:                            CodeStyle.getDefault(CodeStyle.Language.CPP))
925:                            .putBoolean(EditorOptions.indentCasesFromSwitch,
926:                                    true);
927:                }
928:            }
929:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.