Source Code Cross Referenced for UnitTests.java in  » Parser » Rats-Parser-Generators » xtc » lang » jeannie » 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 » Parser » Rats Parser Generators » xtc.lang.jeannie 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * xtc - The eXTensible Compiler
0003:         * Copyright (C) 2007 IBM Corp.
0004:         *
0005:         * This program is free software; you can redistribute it and/or
0006:         * modify it under the terms of the GNU General Public License
0007:         * version 2 as published by the Free Software Foundation.
0008:         *
0009:         * This program is distributed in the hope that it will be useful,
0010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012:         * GNU General Public License for more details.
0013:         *
0014:         * You should have received a copy of the GNU General Public License
0015:         * along with this program; if not, write to the Free Software
0016:         * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
0017:         * USA.
0018:         */
0019:        package xtc.lang.jeannie;
0020:
0021:        import java.io.StringWriter;
0022:
0023:        import junit.framework.Test;
0024:        import junit.framework.TestCase;
0025:        import junit.framework.TestSuite;
0026:        import xtc.lang.JavaEntities;
0027:        import xtc.lang.JavaUnitTests;
0028:        import xtc.tree.GNode;
0029:        import xtc.tree.Node;
0030:        import xtc.tree.Printer;
0031:        import xtc.type.Type;
0032:        import xtc.util.Runtime;
0033:        import xtc.util.SymbolTable;
0034:
0035:        /**
0036:         * JUnit tests for classes in package xtc.lang.jeannie.
0037:         * 
0038:         * This class is a good place to quickly try a method on some simple
0039:         * inputs. The test cases also document how to use certain API and
0040:         * what it does.
0041:         * 
0042:         * To run from the console, set your CLASSPATH to include
0043:         * $JAVA_DEV_ROOT/classes and junit.jar, then run
0044:         * 
0045:         *   java -ea junit.textui.TestRunner xtc.lang.jeannie.UnitTests
0046:         *
0047:         * Or, to run from within eclipse, Run -> Run ... -> JUnit -> New, and
0048:         * specify xtc.lang.jeannie.UnitTests.
0049:         * 
0050:         * @author Martin Hirzel
0051:         * @version $Revision: 1.28 $
0052:         */
0053:        public final class UnitTests extends TestCase {
0054:            static final class JeannieAnalyzerTestError extends
0055:                    JavaUnitTests.IgnorableTest {
0056:                private final String _expected;
0057:                private final String _input;
0058:                private final String _language;
0059:                private final String _production;
0060:
0061:                JeannieAnalyzerTestError(final boolean ignore,
0062:                        final String production, final String language,
0063:                        final String input, final String expected) {
0064:                    super (ignore);
0065:                    _expected = expected;
0066:                    _input = input;
0067:                    _language = language;
0068:                    _production = production;
0069:                }
0070:
0071:                public void runTestIgnorable() throws Exception {
0072:                    final Analyzer ana = new Analyzer(Utilities.newRuntime(),
0073:                            new SymbolTable(), _language);
0074:                    if (!"File".equals(_production)
0075:                            && !"CompilationUnit".equals(_production)
0076:                            && !"TranslationUnit".equals(_production))
0077:                        JavaUnitTests.enterPackageFile(ana._table, "",
0078:                                "<input>");
0079:                    UnitTests.jeannieAnalyzerTestError(_production, _language,
0080:                            _input, _expected, ana);
0081:                }
0082:            }
0083:
0084:            static final class JeannieCodeGeneratorTest extends
0085:                    JavaUnitTests.IgnorableTest {
0086:                private final String _cExpected;
0087:                private final String _input;
0088:                private final String _javaExpected;
0089:                private final String _language;
0090:                private final String _production;
0091:
0092:                JeannieCodeGeneratorTest(final boolean ignore,
0093:                        final String production, final String language,
0094:                        final String input) {
0095:                    super (ignore);
0096:                    _cExpected = null;
0097:                    _input = input;
0098:                    _javaExpected = null;
0099:                    _language = language;
0100:                    _production = production;
0101:                }
0102:
0103:                JeannieCodeGeneratorTest(final boolean ignore,
0104:                        final String production, final String language,
0105:                        final String input, final String cExpected,
0106:                        final String javaExpected) {
0107:                    super (ignore);
0108:                    _cExpected = cExpected;
0109:                    _input = input;
0110:                    _javaExpected = javaExpected;
0111:                    _language = language;
0112:                    _production = production;
0113:                }
0114:
0115:                public void runTestIgnorable() throws Exception {
0116:                    final GNode ast = Utilities.jeannieStringToAst(_production,
0117:                            _language, _input);
0118:                    final Runtime runtime = Utilities.newRuntime();
0119:                    final SymbolTable tab = new SymbolTable();
0120:                    final Analyzer ana = new Analyzer(runtime, tab, _language);
0121:                    ana.dispatch(ast);
0122:                    final CodeGenerator codeGenerator = new CodeGenerator(
0123:                            runtime, tab);
0124:                    final CodeGenerator.Out out = (CodeGenerator.Out) codeGenerator
0125:                            .dispatch(ast);
0126:                    assertTrue(null == out._cExternalDeclarations
0127:                            && null == out._cMembers
0128:                            && null == out._javaMembers);
0129:                    final String cCode = Utilities.cAstToString(out._cNode);
0130:                    final String javaCode = Utilities
0131:                            .javaAstToString(out._javaNode);
0132:                    assrtEquals(_cExpected, cCode);
0133:                    assrtEquals(_javaExpected, javaCode);
0134:                }
0135:            }
0136:
0137:            static final class JeannieDebuggerAnalyzerTest extends
0138:                    JavaUnitTests.IgnorableTest {
0139:                private final String _expected;
0140:                private final String _input;
0141:                private final String _language;
0142:
0143:                JeannieDebuggerAnalyzerTest(final boolean ignore,
0144:                        final String language, final String input,
0145:                        final String expected) {
0146:                    super (ignore);
0147:                    _expected = expected;
0148:                    _input = input;
0149:                    _language = language;
0150:                }
0151:
0152:                public void runTestIgnorable() throws Exception {
0153:                    final DebuggerAstAnalyzer ana = new DebuggerAstAnalyzer(
0154:                            Utilities.newRuntime(), Utilities
0155:                                    .debuggerNewSymbolMapper());
0156:                    UnitTests.debuggerAnalyzerTestError(_language, _input,
0157:                            _expected, ana);
0158:                }
0159:            }
0160:
0161:            static final class JeannieDebuggerParserTest extends
0162:                    JavaUnitTests.IgnorableTest {
0163:                private final String _expected;
0164:                private final String _input;
0165:                private final String _language;
0166:
0167:                JeannieDebuggerParserTest(final boolean ignore,
0168:                        final String language, final String input) {
0169:                    super (ignore);
0170:                    _expected = input;
0171:                    _input = input;
0172:                    _language = language;
0173:                }
0174:
0175:                public void runTestIgnorable() throws Exception {
0176:                    if (null == _language) {
0177:                        UnitTests.debuggerParserTestRoundTrip("C", _input,
0178:                                _expected);
0179:                        UnitTests.debuggerParserTestRoundTrip("Java", _input,
0180:                                _expected);
0181:                    } else {
0182:                        UnitTests.debuggerParserTestRoundTrip(_language,
0183:                                _input, _expected);
0184:                    }
0185:                }
0186:            }
0187:
0188:            static class JeannieParserTest extends JavaUnitTests.IgnorableTest {
0189:                private final String _expected;
0190:                private final String _input;
0191:                private final String _language;
0192:                private final String _production;
0193:
0194:                JeannieParserTest(final boolean ignore,
0195:                        final String production, final String language,
0196:                        final String input) {
0197:                    super (ignore);
0198:                    _expected = input;
0199:                    _input = input;
0200:                    _language = language;
0201:                    _production = production;
0202:                }
0203:
0204:                public void runTestIgnorable() throws Exception {
0205:                    UnitTests.jeannieParserTestRoundTrip(_production,
0206:                            _language, _input, _expected, false);
0207:                    UnitTests.jeannieParserTestRoundTrip(_production,
0208:                            _language, _input, _expected, true);
0209:                }
0210:            }
0211:
0212:            static void assrtEquals(final String expected, final String actual) {
0213:                if (null == expected)
0214:                    return;
0215:                final String e = JavaUnitTests.contractSpace(expected);
0216:                final String a = JavaUnitTests.contractSpace(actual);
0217:                if (e.equals(a))
0218:                    return;
0219:                assertEquals(e, a);
0220:            }
0221:
0222:            static void debuggerAnalyzerTestError(final String language,
0223:                    final String input, final String expected,
0224:                    final DebuggerAstAnalyzer ana) throws Exception {
0225:                final Object astOrMsg = Utilities.debuggerParseAndAnalyze(
0226:                        language, input, Utilities.debuggerNewSymbolMapper());
0227:                final String msg = astOrMsg instanceof  Node ? ""
0228:                        : trimAnalyzerOutput((String) astOrMsg);
0229:                assrtEquals(expected, msg);
0230:            }
0231:
0232:            static void debuggerParserTestRoundTrip(final String language,
0233:                    final String input, final String expected) throws Exception {
0234:                final GNode ast = Utilities
0235:                        .debuggerStringToAst(language, input);
0236:                final String result = Utilities.debuggerAstToString(ast);
0237:                assrtEquals(expected, result);
0238:            }
0239:
0240:            static void jeannieAnalyzerTestError(final String production,
0241:                    final String language, final String input,
0242:                    final String expected, final Analyzer ana) throws Exception {
0243:                final StringWriter stringWriter = new StringWriter();
0244:                ana._runtime.setErrConsole(new Printer(stringWriter));
0245:                final GNode ast = Utilities.jeannieStringToAst(production,
0246:                        language, input);
0247:                ana.dispatch(ast);
0248:                final String output = trimAnalyzerOutput(stringWriter
0249:                        .toString());
0250:                assrtEquals(expected, output);
0251:            }
0252:
0253:            static String trimAnalyzerOutput(String output) {
0254:                output = JavaUnitTests.stripPrefix(output, "error:");
0255:                final int warningPos = output.indexOf("warning:");
0256:                if (-1 != warningPos)
0257:                    output = output.substring(warningPos);
0258:                output = JavaUnitTests.stripSuffix(output, "\n");
0259:                output = output.trim();
0260:                return output;
0261:            }
0262:
0263:            static void jeannieParserTestRoundTrip(final String production,
0264:                    final String language, final String input,
0265:                    final String expected, final boolean simple)
0266:                    throws Exception {
0267:                final String unescaped = JavaEntities.unicodeUnescape(input);
0268:                final GNode ast = Utilities.jeannieStringToAst(production,
0269:                        language, unescaped, simple);
0270:                final String result = Utilities.jeannieAstToString(ast,
0271:                        language);
0272:                final String exp = JavaUnitTests.contractSpace(JavaEntities
0273:                        .unicodeUnescape(expected));
0274:                assrtEquals(exp, result);
0275:            }
0276:
0277:            private static TestSuite makeSuiteDebugger() {
0278:                final TestSuite s = new TestSuite();
0279:                s.addTest(new JeannieDebuggerAnalyzerTest(false, null,
0280:                        "gdbb break foo.c:10", "break class command expected"));
0281:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0282:                        "print known", ""));
0283:                s.addTest(new JeannieDebuggerAnalyzerTest(false, null,
0284:                        "gdb break foo.c:10", ""));
0285:                s.addTest(new JeannieDebuggerParserTest(false, null,
0286:                        "gdb break foo.c:10"));
0287:                s.addTest(new JeannieDebuggerParserTest(false, null,
0288:                        "jdb stop at foo.c:10"));
0289:                s.addTest(new JeannieDebuggerParserTest(false, null, "initj"));
0290:                s.addTest(new JeannieDebuggerParserTest(false, null,
0291:                        "   stat   "));
0292:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C", "next",
0293:                        ""));
0294:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0295:                        "print $metaVar = f()", ""));
0296:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0297:                        "print $metaVariable", ""));
0298:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0299:                        "print &x", ""));
0300:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0301:                        "print (*x).f", ""));
0302:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0303:                        "print cVar = f()", ""));
0304:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0305:                        "print x + `.Java this.f($mv) + &z", ""));
0306:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0307:                        "print x + `this.f($mv)", ""));
0308:                s
0309:                        .addTest(new JeannieDebuggerAnalyzerTest(false, "C",
0310:                                "print x->f",
0311:                                "the Jeannie debugger does not support the IndirectComponentSelection feature"));
0312:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "Java",
0313:                        "next", ""));
0314:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "Java",
0315:                        "print $metaVar = f()", ""));
0316:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "Java",
0317:                        "print &x", "expected"));
0318:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "Java",
0319:                        "print `&x", ""));
0320:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "Java",
0321:                        "print javaVar = f()", ""));
0322:                s
0323:                        .addTest(new JeannieDebuggerAnalyzerTest(false, "Java",
0324:                                "print new Object()",
0325:                                "the Jeannie debugger does not support the NewClassExpression feature"));
0326:                s.addTest(new JeannieDebuggerAnalyzerTest(false, "Java",
0327:                        "watch all a.b.c.d.e.f", ""));
0328:                s
0329:                        .addTest(new JeannieDebuggerAnalyzerTest(false, null,
0330:                                "break file name.jni:123",
0331:                                "symbol characters expected"));
0332:                s.addTest(new JeannieDebuggerAnalyzerTest(false, null,
0333:                        "break file/name.jni:123", ""));
0334:                s.addTest(new JeannieDebuggerAnalyzerTest(false, null, "n",
0335:                        "break class command expected"));
0336:                s.addTest(new JeannieDebuggerAnalyzerTest(false, null, "next",
0337:                        ""));
0338:                s.addTest(new JeannieDebuggerAnalyzerTest(false, null,
0339:                        "stop at my.pack.Clazz:123", ""));
0340:                s
0341:                        .addTest(new JeannieDebuggerParserTest(false, "C",
0342:                                "delete 42"));
0343:                s.addTest(new JeannieDebuggerParserTest(false, "C",
0344:                        "print $metaVariable"));
0345:                s
0346:                        .addTest(new JeannieDebuggerParserTest(false, "C",
0347:                                "print &x"));
0348:                s.addTest(new JeannieDebuggerParserTest(false, "C",
0349:                        "print x + `this.f($mv)"));
0350:                s.addTest(new JeannieDebuggerParserTest(false, "C",
0351:                        "print x + `this.f()"));
0352:                s.addTest(new JeannieDebuggerParserTest(false, "C",
0353:                        "watch x[0]"));
0354:                s.addTest(new JeannieDebuggerParserTest(false, "Java",
0355:                        "delete 42"));
0356:                s.addTest(new JeannieDebuggerParserTest(false, "Java",
0357:                        "print $metaVariable"));
0358:                s.addTest(new JeannieDebuggerParserTest(false, "Java",
0359:                        "print `&x + y"));
0360:                s.addTest(new JeannieDebuggerParserTest(false, "Java",
0361:                        "print my.pack.Clazz.staticField"));
0362:                s.addTest(new JeannieDebuggerParserTest(false, "Java",
0363:                        "watch access y.g"));
0364:                s.addTest(new JeannieDebuggerParserTest(false, "Java",
0365:                        "watch all a.b.c.d.e.f"));
0366:                s.addTest(new JeannieDebuggerParserTest(false, "Java",
0367:                        "watch my.pack.Clazz.h"));
0368:                s.addTest(new JeannieDebuggerParserTest(false, null,
0369:                        " stop at my . pack . Clazz : 123 "));
0370:                s.addTest(new JeannieDebuggerParserTest(false, null,
0371:                        "break file/name.jni:123"));
0372:                s
0373:                        .addTest(new JeannieDebuggerParserTest(false, null,
0374:                                "continue"));
0375:                s.addTest(new JeannieDebuggerParserTest(false, null,
0376:                        "delete 42"));
0377:                s.addTest(new JeannieDebuggerParserTest(false, null, "down 3"));
0378:                s.addTest(new JeannieDebuggerParserTest(false, null, "exit"));
0379:                s.addTest(new JeannieDebuggerParserTest(false, null, "help"));
0380:                s.addTest(new JeannieDebuggerParserTest(false, null,
0381:                        "info break"));
0382:                s.addTest(new JeannieDebuggerParserTest(false, null,
0383:                        "info watch"));
0384:                s.addTest(new JeannieDebuggerParserTest(false, null, "list"));
0385:                s.addTest(new JeannieDebuggerParserTest(false, null, "locals"));
0386:                s.addTest(new JeannieDebuggerParserTest(false, null, "next"));
0387:                s.addTest(new JeannieDebuggerParserTest(false, null, "step"));
0388:                s.addTest(new JeannieDebuggerParserTest(false, null,
0389:                        "stop at Clazz:1"));
0390:                s.addTest(new JeannieDebuggerParserTest(false, null,
0391:                        "stop at my.pack.Clazz:123"));
0392:                s.addTest(new JeannieDebuggerParserTest(false, null, "up 0"));
0393:                s.addTest(new JeannieDebuggerParserTest(false, null, "where"));
0394:                return s;
0395:            }
0396:
0397:            private static TestSuite makeSuiteJeannieAnalyzerError() {
0398:                final TestSuite s = new TestSuite();
0399:                s
0400:                        .addTest(new JeannieAnalyzerTestError(
0401:                                false,
0402:                                "File",
0403:                                null,
0404:                                "`.C{typedef int JNIEnv;typedef void* jstring;}class A{native void f()`{jstring s=_newJavaString(\"hi\");}}",
0405:                                ""));
0406:                s
0407:                        .addTest(new JeannieAnalyzerTestError(
0408:                                false,
0409:                                "File",
0410:                                null,
0411:                                "`.C{typedef int JNIEnv;typedef void* jstring;}class A{native void f()`{jstring s=_newJavaString(123);}}",
0412:                                "expected pointer to char, `byte, or `char"));
0413:                s.addTest(new JeannieAnalyzerTestError(false, "File", null, "",
0414:                        ""));
0415:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0416:                        "`Exception e;", ""));
0417:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0418:                        "`.C{double y; }class A{int x=`y;}",
0419:                        "initializer type mismatch"));
0420:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0421:                        "`.C{enum e{a,b}y; }class A{int x=`y;}",
0422:                        "initializer type mismatch"));
0423:                s
0424:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0425:                                null, "`.C{enum e{a,b}y; }class A{long x=`y;}",
0426:                                "warning: converting C type 'annotated(enum e)' to Java type 'long'"));
0427:                s
0428:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0429:                                null, "`.C{float y;}class A{double x=`y;}",
0430:                                "warning: converting C type 'annotated(float)' to Java type 'double'"));
0431:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0432:                        "`.C{float y;}class A{float x=`y;}",
0433:                        "initializer type mismatch"));
0434:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0435:                        "`.C{float y;}class A{int x=`y;}",
0436:                        "initializer type mismatch"));
0437:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0438:                        "`.C{int i=0;}", ""));
0439:                s
0440:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0441:                                null, "`.C{int i=\"s\";}",
0442:                                "initializer for 'i' makes integer from pointer without a cast"));
0443:                s
0444:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0445:                                null, "`.C{int y;}class A{int x=`&y;}",
0446:                                "illegal C type 'annotated(pointer(int))' in Java expression"));
0447:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0448:                        "`.C{int y;}class A{int x=`y;}",
0449:                        "initializer type mismatch"));
0450:                s
0451:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0452:                                null, "`.C{int y;}class A{long x=`y;}",
0453:                                "warning: converting C type 'annotated(int)' to Java type 'long'"));
0454:                s
0455:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0456:                                null, "`.C{int y[5];}class A{int x=`y;}",
0457:                                "illegal C type 'annotated(array(int, 5))' in Java expression"));
0458:                s
0459:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0460:                                null, "`.C{int* y;}class A{int x=`y;}",
0461:                                "illegal C type 'annotated(pointer(int))' in Java expression"));
0462:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0463:                        "`.C{long double y;}class A{int x=`y;}",
0464:                        "initializer type mismatch"));
0465:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0466:                        "`.C{long long y;}class A{int x=`y;}",
0467:                        "initializer type mismatch"));
0468:                s
0469:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0470:                                null, "`.C{struct s{}y;}class A{int x=`y;}",
0471:                                "illegal C type 'annotated(struct s)' in Java expression"));
0472:                s
0473:                        .addTest(new JeannieAnalyzerTestError(
0474:                                false,
0475:                                "File",
0476:                                null,
0477:                                "`.C{typedef float jfloat; float y; }class A{float x=`y;}",
0478:                                "warning: converting C type 'annotated(float)' to Java type 'float'"));
0479:                s
0480:                        .addTest(new JeannieAnalyzerTestError(
0481:                                false,
0482:                                "File",
0483:                                null,
0484:                                "`.C{typedef float jfloat; jfloat y; }class A{float x=`y;}",
0485:                                ""));
0486:                s
0487:                        .addTest(new JeannieAnalyzerTestError(
0488:                                false,
0489:                                "File",
0490:                                null,
0491:                                "`.C{typedef int JNIEnv;}class A{int f(){int i;return `i;}}",
0492:                                "cannot use Java entity 'i' in C context"));
0493:                s
0494:                        .addTest(new JeannieAnalyzerTestError(
0495:                                false,
0496:                                "File",
0497:                                null,
0498:                                "`.C{typedef int JNIEnv;}class A{int f(){return env;}}",
0499:                                "cannot use C entity 'env' in Java context"));
0500:                s
0501:                        .addTest(new JeannieAnalyzerTestError(
0502:                                false,
0503:                                "File",
0504:                                null,
0505:                                "`.C{typedef int JNIEnv;}class A{int f(int i){return `i;}}",
0506:                                "cannot use Java entity 'i' in C context"));
0507:                s
0508:                        .addTest(new JeannieAnalyzerTestError(
0509:                                false,
0510:                                "File",
0511:                                null,
0512:                                "`.C{typedef int JNIEnv;}class A{int i;int f(){return `i;}}",
0513:                                "cannot use Java entity 'i' in C context"));
0514:                s
0515:                        .addTest(new JeannieAnalyzerTestError(
0516:                                false,
0517:                                "File",
0518:                                null,
0519:                                "`.C{typedef int JNIEnv;}class A{native void f()`{JNIEnv* e=env;}}",
0520:                                ""));
0521:                s
0522:                        .addTest(new JeannieAnalyzerTestError(
0523:                                false,
0524:                                "File",
0525:                                null,
0526:                                "`.C{typedef int JNIEnv;}class A{native void f(int env)`{}}",
0527:                                "formal parameter declaration of 'env' conflicts with implicit JNIEnv pointer"));
0528:                s
0529:                        .addTest(new JeannieAnalyzerTestError(
0530:                                false,
0531:                                "File",
0532:                                null,
0533:                                "`.C{typedef int JNIEnv;typedef char jbyte;typedef int jint;extern int printf(__const char*__restrict __format,...);}class Main{public static void main(String[]args){String js=\"abc\";`{jbyte*bs;_with(bs=`js){printf(\"%*s\\n\",bs,`js.length());}}}}",
0534:                                ""));
0535:                s
0536:                        .addTest(new JeannieAnalyzerTestError(
0537:                                false,
0538:                                "File",
0539:                                null,
0540:                                "`.C{typedef int JNIEnv;typedef int jintArray;}class A{native int[]f()`{jintArray a;return a;}}",
0541:                                ""));
0542:                s
0543:                        .addTest(new JeannieAnalyzerTestError(
0544:                                false,
0545:                                "File",
0546:                                null,
0547:                                "`.C{typedef int JNIEnv;void printf(char*);void fflush(int);int stdout;void f(JNIEnv*env){printf(\"f 1\\n\");fflush(stdout);`p.Main.g();printf(\"f 2\\n\");fflush(stdout);}}package p;public class Main{public static void g(){System.out.println(\"Main.g\");System.out.flush();}public static void main(String[]args){System.out.println(\"Main.main 1\");System.out.flush();`f(env);System.out.println(\"Main.main 2\");System.out.flush();}}",
0548:                                ""));
0549:                s
0550:                        .addTest(new JeannieAnalyzerTestError(
0551:                                false,
0552:                                "File",
0553:                                null,
0554:                                "`.C{typedef int jint; int y; }class A{int x=`y;}",
0555:                                ""));
0556:                s
0557:                        .addTest(new JeannieAnalyzerTestError(
0558:                                false,
0559:                                "File",
0560:                                null,
0561:                                "`.C{typedef int jint; jint i=0; typedef void* JNIEnv;} class A { int f(){return `i;} } ",
0562:                                ""));
0563:                s
0564:                        .addTest(new JeannieAnalyzerTestError(
0565:                                false,
0566:                                "File",
0567:                                null,
0568:                                "`.C{typedef int jint; long y; }class A{long x=`y;}",
0569:                                "warning: converting C type 'annotated(long)' to Java type 'long'"));
0570:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0571:                        "`.C{typedef long jint; long y; }class A{int x=`y;}",
0572:                        ""));
0573:                s
0574:                        .addTest(new JeannieAnalyzerTestError(
0575:                                false,
0576:                                "File",
0577:                                null,
0578:                                "`.C{typedef unsigned char jboolean;jboolean b;}class A{boolean x=`b;} ",
0579:                                ""));
0580:                s
0581:                        .addTest(new JeannieAnalyzerTestError(
0582:                                false,
0583:                                "File",
0584:                                null,
0585:                                "`.C{typedef unsigned char jboolean;}class A{boolean x=`((jboolean)(2<3));} ",
0586:                                ""));
0587:                s
0588:                        .addTest(new JeannieAnalyzerTestError(
0589:                                false,
0590:                                "File",
0591:                                null,
0592:                                "`.C{typedef unsigned char jboolean;}class A{boolean x=`(2<3);} ",
0593:                                "initializer type mismatch"));
0594:                s
0595:                        .addTest(new JeannieAnalyzerTestError(
0596:                                false,
0597:                                "File",
0598:                                null,
0599:                                "`.C{typedef void(*FP)(int);void g(FP fp){}void h(int i){}void f(){g(h);}}class A{}",
0600:                                ""));
0601:                s
0602:                        .addTest(new JeannieAnalyzerTestError(
0603:                                false,
0604:                                "File",
0605:                                null,
0606:                                "`.C{typedef void* JNIEnv;typedef int jint;}class A{int f(){return `((jint)env);}}",
0607:                                ""));
0608:                s
0609:                        .addTest(new JeannieAnalyzerTestError(
0610:                                false,
0611:                                "File",
0612:                                null,
0613:                                "`.C{typedef void* JNIEnv;}class A{native Exception f()`{return 123;}}",
0614:                                "return type mismatch"));
0615:                s
0616:                        .addTest(new JeannieAnalyzerTestError(
0617:                                false,
0618:                                "File",
0619:                                null,
0620:                                "`.C{typedef void* JNIEnv;}class A{native int f()`{return;}}",
0621:                                "'return' with no value, in method returning non-void"));
0622:                s
0623:                        .addTest(new JeannieAnalyzerTestError(
0624:                                false,
0625:                                "File",
0626:                                null,
0627:                                "`.C{typedef void* JNIEnv;}class A{native void f()`{}}",
0628:                                ""));
0629:                s
0630:                        .addTest(new JeannieAnalyzerTestError(
0631:                                false,
0632:                                "File",
0633:                                null,
0634:                                "`.C{typedef void* JNIEnv;}class A{void f(){if(true)`{int*p=0;}}}",
0635:                                ""));
0636:                s
0637:                        .addTest(new JeannieAnalyzerTestError(
0638:                                false,
0639:                                "File",
0640:                                null,
0641:                                "`.C{typedef void* JNIEnv;}class A{void f(){if(true)`{int*p=3;}}}",
0642:                                "initializer for 'p' makes pointer from integer without a cast"));
0643:                s
0644:                        .addTest(new JeannieAnalyzerTestError(
0645:                                false,
0646:                                "File",
0647:                                null,
0648:                                "`.C{typedef void*JNIEnv;typedef int jint;extern int printf(__const char* __restrict __format, ...);}class A{static native void f()`{jint a=0,b=0;b=`(1+`((jint)(a=1)));printf(\"%d,%d\\\\n\",a,b);}public static void main(String[]args){f();}}",
0649:                                ""));
0650:                s
0651:                        .addTest(new JeannieAnalyzerTestError(
0652:                                false,
0653:                                "File",
0654:                                null,
0655:                                "`.C{typedef void*JNIEnv;typedef int jint;}class A{native int f()`{return (jint)1000;}}",
0656:                                ""));
0657:                s
0658:                        .addTest(new JeannieAnalyzerTestError(
0659:                                false,
0660:                                "File",
0661:                                null,
0662:                                "`.C{typedef void*JNIEnv;typedef int jint;}class A{public static void main(String args[]){int a=0,b=0;b=`((jint)(1+`(a=1)));System.out.println(a+\",\"+b);}}",
0663:                                ""));
0664:                s
0665:                        .addTest(new JeannieAnalyzerTestError(
0666:                                false,
0667:                                "File",
0668:                                null,
0669:                                "`.C{typedef void*JNIEnv;}class Main{native void f()`{int a[1]={3+5};}}",
0670:                                ""));
0671:                s
0672:                        .addTest(new JeannieAnalyzerTestError(
0673:                                false,
0674:                                "File",
0675:                                null,
0676:                                "`.C{typedef void*JNIEnv;}class Main{native void f()`{int a[1]={3};}}",
0677:                                ""));
0678:                s
0679:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0680:                                null, "`.C{union u{}y;}class A{int x=`y;}",
0681:                                "illegal C type 'annotated(union u)' in Java expression"));
0682:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0683:                        "`.C{unsigned y;}class A{int x=`y;}",
0684:                        "initializer type mismatch"));
0685:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0686:                        "`.C{}class A extends B {}",
0687:                        "unknown class or interface B"));
0688:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0689:                        "`.C{}class A{native void f();}",
0690:                        "methods should be abstract iff they have no body"));
0691:                s
0692:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0693:                                null, "`.C{}class A{native void f()`{}}",
0694:                                "C typedef for 'JNIEnv' missing; did you forget to #include <jni.h>?"));
0695:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0696:                        "`.C{}class A{native void f(){}}",
0697:                        "methods should be native iff their body is in C"));
0698:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0699:                        "`.C{}class A{static{String b=\"x\";b=\"y\";}}", ""));
0700:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0701:                        "`.C{}class A{}", ""));
0702:                s
0703:                        .addTest(new JeannieAnalyzerTestError(
0704:                                false,
0705:                                "File",
0706:                                null,
0707:                                "`.Java{import java.util.*;}typedef void* jobject;jobject f(){return `((Vector)null);}",
0708:                                ""));
0709:                s
0710:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0711:                                null,
0712:                                "`.Java{import java.util.Vector;}int i=`0;",
0713:                                "C typedef for 'jint' missing; did you forget to #include <jni.h>?"));
0714:                s
0715:                        .addTest(new JeannieAnalyzerTestError(
0716:                                false,
0717:                                "File",
0718:                                null,
0719:                                "`.Java{import java.util.Vector;}typedef int jint;int f(){return `0;}",
0720:                                ""));
0721:                s
0722:                        .addTest(new JeannieAnalyzerTestError(
0723:                                false,
0724:                                "File",
0725:                                null,
0726:                                "`.Java{import java.util.Vector;}typedef void* jobject;jobject f(){return `((Vector)null);}",
0727:                                ""));
0728:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0729:                        "int f(){return 123;}", ""));
0730:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0731:                        "int i;void f(){_cancel i;}",
0732:                        "no enclosing _with statement for 'i'"));
0733:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0734:                        "int i;void f(){_commit i;}",
0735:                        "no enclosing _with statement for 'i'"));
0736:                s
0737:                        .addTest(new JeannieAnalyzerTestError(
0738:                                false,
0739:                                "File",
0740:                                null,
0741:                                "typedef char jboolean;typedef int jintArray;void f(){jboolean* ca;_with(ca=`new int[5]){}}",
0742:                                "type 'jint*' expected"));
0743:                s
0744:                        .addTest(new JeannieAnalyzerTestError(
0745:                                false,
0746:                                "File",
0747:                                null,
0748:                                "typedef double jdouble;jdouble f(){return `1.5;}",
0749:                                ""));
0750:                s
0751:                        .addTest(new JeannieAnalyzerTestError(
0752:                                false,
0753:                                "File",
0754:                                null,
0755:                                "typedef int jboolean;typedef int jbooleanArray;void f(){jboolean* ca;_with(ca=`new boolean[5]){}}",
0756:                                ""));
0757:                s
0758:                        .addTest(new JeannieAnalyzerTestError(
0759:                                false,
0760:                                "File",
0761:                                null,
0762:                                "typedef int jboolean;typedef int jobjectArray;void f(){jboolean* ca;_with(ca=`new String[5]){}}",
0763:                                "type 'jobject*' expected"));
0764:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0765:                        "typedef int jint;int f()`{return 123;}", ""));
0766:                s
0767:                        .addTest(new JeannieAnalyzerTestError(
0768:                                false,
0769:                                "File",
0770:                                null,
0771:                                "typedef int jint;typedef void* jintArray;void f(){jint* ca;_copyFromJava(ca, 0, `new int[5], 0, 3);}",
0772:                                ""));
0773:                s
0774:                        .addTest(new JeannieAnalyzerTestError(
0775:                                false,
0776:                                "File",
0777:                                null,
0778:                                "typedef int jint;typedef void* jintArray;void f(){jint* ca;_copyFromJava(ca, 0, `new int[5], 3-1, 2);}",
0779:                                ""));
0780:                s
0781:                        .addTest(new JeannieAnalyzerTestError(
0782:                                false,
0783:                                "File",
0784:                                null,
0785:                                "typedef int jint;typedef void* jintArray;void f(){jint* ca;_copyFromJava(ca, 0, `new int[5], 3.1, 3);}",
0786:                                "invalid operand where integer required"));
0787:                s
0788:                        .addTest(new JeannieAnalyzerTestError(
0789:                                false,
0790:                                "File",
0791:                                null,
0792:                                "typedef int jint;typedef void* jintArray;void f(){jint* ca;_with(ca=`new int[5]){_cancel ca;}}",
0793:                                ""));
0794:                s
0795:                        .addTest(new JeannieAnalyzerTestError(
0796:                                false,
0797:                                "File",
0798:                                null,
0799:                                "typedef int jint;typedef void* jintArray;void f(){jint* ca;_with(ca=`new int[5]){_commit ca;}}",
0800:                                ""));
0801:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0802:                        "typedef void* jobject;int f(){return `null;}", ""));
0803:                s
0804:                        .addTest(new JeannieAnalyzerTestError(
0805:                                false,
0806:                                "File",
0807:                                null,
0808:                                "typedef void* jobject;jobject f(){return `((Vector)null);}",
0809:                                "unknown class or interface Vector"));
0810:                s
0811:                        .addTest(new JeannieAnalyzerTestError(
0812:                                false,
0813:                                "File",
0814:                                null,
0815:                                "typedef void* jobject;jobject f(){return `null;}",
0816:                                ""));
0817:                s
0818:                        .addTest(new JeannieAnalyzerTestError(
0819:                                false,
0820:                                "File",
0821:                                null,
0822:                                "typedef void* jobject;typedef jobject jthrowable;jobject f(){return `new Exception();}",
0823:                                ""));
0824:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0825:                        "typedef void* jstring;jstring f(){return `\"hi\";}",
0826:                        ""));
0827:                s
0828:                        .addTest(new JeannieAnalyzerTestError(
0829:                                false,
0830:                                "File",
0831:                                null,
0832:                                "typedef void* jstring;jstring f(){return `new String(1,2,3,4,5);}",
0833:                                "could not find constructor"));
0834:                s
0835:                        .addTest(new JeannieAnalyzerTestError(
0836:                                false,
0837:                                "File",
0838:                                null,
0839:                                "typedef void* jstring;typedef char jbyte;void f(){jbyte* ca;_with(ca=`\"abc\"){}}",
0840:                                ""));
0841:                s
0842:                        .addTest(new JeannieAnalyzerTestError(
0843:                                false,
0844:                                "File",
0845:                                null,
0846:                                "typedef void* jstring;typedef int jchar;typedef int jint;void f(){jchar* ca;_copyFromJava(ca, 0, `\"abc\", 0, 3);}",
0847:                                ""));
0848:                s
0849:                        .addTest(new JeannieAnalyzerTestError(
0850:                                false,
0851:                                "File",
0852:                                null,
0853:                                "typedef void* jstring;typedef int jchar;void f(){jchar* ca;_copyToJava(`\"abc\", 0, ca, 0, 3);}",
0854:                                "_copyToJava target must not be String"));
0855:                s
0856:                        .addTest(new JeannieAnalyzerTestError(
0857:                                false,
0858:                                "File",
0859:                                null,
0860:                                "typedef void* jstring;typedef int jchar;void f(){jchar* ca;_with(ca=`\"abc\"){}}",
0861:                                ""));
0862:                s
0863:                        .addTest(new JeannieAnalyzerTestError(
0864:                                false,
0865:                                "File",
0866:                                null,
0867:                                "typedef void* jstring;typedef int jchar;void f(){jchar* ca;_with(ca=`'a'){}}",
0868:                                "string or primitive array expected"));
0869:                s
0870:                        .addTest(new JeannieAnalyzerTestError(
0871:                                false,
0872:                                "File",
0873:                                null,
0874:                                "typedef void* jstring;typedef int jchar;void f(){jchar* ca;_with(ca=`(new Object().toString())){}}",
0875:                                ""));
0876:                s
0877:                        .addTest(new JeannieAnalyzerTestError(
0878:                                false,
0879:                                "File",
0880:                                null,
0881:                                "typedef void* jstring;void f(){int* ca;_with(ca=`\"abc\"){}}",
0882:                                "type 'jchar*' or 'jbyte*' expected"));
0883:                s
0884:                        .addTest(new JeannieAnalyzerTestError(
0885:                                false,
0886:                                "File",
0887:                                null,
0888:                                "typedef void* jstring;void f(jstring s)`{throw new Error(`s);}",
0889:                                ""));
0890:                s
0891:                        .addTest(new JeannieAnalyzerTestError(
0892:                                false,
0893:                                "File",
0894:                                null,
0895:                                "typedef void* jthrowable;jthrowable f(){return `((Exception)null);}",
0896:                                ""));
0897:                s
0898:                        .addTest(new JeannieAnalyzerTestError(
0899:                                false,
0900:                                "File",
0901:                                null,
0902:                                "typedef void* jthrowable;jthrowable f(){return `new Exception();}",
0903:                                ""));
0904:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0905:                        "void f()`throws Exception{`throw new Exception();}",
0906:                        ""));
0907:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0908:                        "void f()`throws Exception{}", ""));
0909:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0910:                        "void f()`throws Exception{}void g(){f();}",
0911:                        "uncaught exception"));
0912:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0913:                        "void f()`throws Object{}", "throwable expected"));
0914:                s
0915:                        .addTest(new JeannieAnalyzerTestError(
0916:                                false,
0917:                                "File",
0918:                                null,
0919:                                "void f()`throws RuntimeException{}void g(){f();}",
0920:                                ""));
0921:                s
0922:                        .addTest(new JeannieAnalyzerTestError(
0923:                                false,
0924:                                "File",
0925:                                null,
0926:                                "void f()`throws java.io.FileNotFoundException, java.io.EOFException{}",
0927:                                ""));
0928:                s
0929:                        .addTest(new JeannieAnalyzerTestError(
0930:                                false,
0931:                                "File",
0932:                                null,
0933:                                "void f()`throws java.io.IOException{}void g()`throws Exception{f();}",
0934:                                ""));
0935:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0936:                        "void f()`{throw new Error();}", ""));
0937:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0938:                        "void f(){`throw new Exception();}",
0939:                        "uncaught exception"));
0940:                s
0941:                        .addTest(new JeannieAnalyzerTestError(
0942:                                false,
0943:                                "File",
0944:                                null,
0945:                                "void f(){`try`{`throw new Exception();}catch(Exception e){}}",
0946:                                ""));
0947:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0948:                        "void f(){`{String s=\"hi\";}}", ""));
0949:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0950:                        "void f(){int* x;`Object y;`{y=x;}}",
0951:                        "cannot use C entity 'y' in Java context"));
0952:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0953:                        "void g(){`Exception x,y;x=y;}", ""));
0954:                s.addTest(new JeannieAnalyzerTestError(false, "File", null,
0955:                        "void g(){`Object x;`Exception y;x=y;}", ""));
0956:                s
0957:                        .addTest(new JeannieAnalyzerTestError(false, "File",
0958:                                null, "void g(){`Object x;`Exception y;y=x;}",
0959:                                "illegal C assignment to Java type 'java.lang.Exception'"));
0960:                return s;
0961:            }
0962:
0963:            private static TestSuite makeSuiteJeannieCodeGenerator() {
0964:                final TestSuite s = new TestSuite();
0965:                s
0966:                        .addTest(new JeannieCodeGeneratorTest(false, "File",
0967:                                null,
0968:                                "`.C{typedef int JNIEnv;void f(JNIEnv*env){`{int i;i=1;}}}class A{}"));
0969:                s
0970:                        .addTest(new JeannieCodeGeneratorTest(
0971:                                false,
0972:                                "File",
0973:                                null,
0974:                                "`.C{typedef int JNIEnv;typedef int jstring;}class A{void f(){throw new Error(`_newJavaString(\"boo\"));}}"));
0975:                s
0976:                        .addTest(new JeannieCodeGeneratorTest(
0977:                                false,
0978:                                "File",
0979:                                null,
0980:                                "`.C{typedef int JNIEnv;typedef void* jstring;}class A{native void f()`{jstring s=_newJavaString(\"hi\");}}"));
0981:                s
0982:                        .addTest(new JeannieCodeGeneratorTest(false, "File",
0983:                                null,
0984:                                "`.C{typedef int JNIEnv;void f(JNIEnv*env){`{int i;i=1;}}}class A{}"));
0985:                s
0986:                        .addTest(new JeannieCodeGeneratorTest(
0987:                                false,
0988:                                "File",
0989:                                null,
0990:                                "`.C{typedef int JNIEnv;typedef char jbyte;typedef int jint;typedef void* jstring;typedef char jboolean;extern int printf(__const char*__restrict __format,...);}class Main{public static void main(String[]args){String js=\"abc\";`{jbyte*bs;_with(bs=`js){printf(\"%*s\\n\",bs,`js.length());}}}}"));
0991:                s
0992:                        .addTest(new JeannieCodeGeneratorTest(
0993:                                false,
0994:                                "File",
0995:                                null,
0996:                                "`.C{typedef int JNIEnv;typedef int jlong;}class A{native int f()`{switch(0){case 0:``((jlong)1);}}}"));
0997:                s
0998:                        .addTest(new JeannieCodeGeneratorTest(
0999:                                false,
1000:                                "File",
1001:                                null,
1002:                                "`.C{typedef int JNIEnv;void printf(char*);void fflush(int);int stdout;void f(JNIEnv*env){printf(\"f 1\\n\");fflush(stdout);`p.Main.g();printf(\"f 2\\n\");fflush(stdout);}}package p;public class Main{public static void g(){System.out.println(\"Main.g\");System.out.flush();}public static void main(String[]args){System.out.println(\"Main.main 1\");System.out.flush();`f(env);System.out.println(\"Main.main 2\");System.out.flush();}}"));
1003:                s
1004:                        .addTest(new JeannieCodeGeneratorTest(
1005:                                false,
1006:                                "File", /* 027 C function */
1007:                                null,
1008:                                "`.C{typedef void* JNIEnv;struct L{struct L* x;};}class A{native void f()`{struct L* y=0;}}"));
1009:                s
1010:                        .addTest(new JeannieCodeGeneratorTest(
1011:                                false,
1012:                                "File", /* 013 _with */
1013:                                null,
1014:                                "`.C{typedef void* JNIEnv;typedef int jint;typedef char jboolean;typedef void* jintArray;}class Main{static native int sum(int[] ja)`{int i,n;jint* ca,s;n=`ja.length;s=0;_with(ca=`ja){for(i=0;i<n;i++)s+=ca[i];_cancel ca;}return s;}public static void main(String[] args){int[] a ={3,1,4};System.out.println(\"expected 8,got \" + sum(a));}}"));
1015:                s
1016:                        .addTest(new JeannieCodeGeneratorTest(
1017:                                false,
1018:                                "File",
1019:                                null,
1020:                                "`.C{typedef int jint;jint i=42;typedef void* JNIEnv;}class A{void f(){int j=0;j=`i;}}"));
1021:                s
1022:                        .addTest(new JeannieCodeGeneratorTest(
1023:                                false,
1024:                                "File" /* 000 hello world */,
1025:                                null,
1026:                                "`.C{typedef void* JNIEnv;extern int printf(__const char *__restrict __format,...);}class Main{static native void sayHi()`{printf(\"Hello world!\\n\");}public static void main(String[]args){sayHi();}}"));
1027:                s
1028:                        .addTest(new JeannieCodeGeneratorTest(
1029:                                false,
1030:                                "File",/* 002 callStatic */
1031:                                null,
1032:                                "`.C{typedef void* JNIEnv;typedef int jint;extern int printf(__const char *__restrict __format,...);}class Main{native static void foo()`{int y;y=`Math.max(123,456);printf(\"return value: %d\\n\",y);}public static void main(String[]args){foo();}}"));
1033:                s.addTest(new JeannieCodeGeneratorTest(false, "File", null,
1034:                        "`.C{typedef void* JNIEnv;}class A{void f(){}}",
1035:                        "typedef void* JNIEnv;", "class A{void f(){}}"));
1036:                s.addTest(new JeannieCodeGeneratorTest(false, "File", null,
1037:                        "`.C{}class A{}", "", "class A{}"));
1038:                return s;
1039:            }
1040:
1041:            private static TestSuite makeSuiteJeannieParser() {
1042:                final TestSuite s = new TestSuite();
1043:                s.addTest(new JeannieParserTest(false, "Block", "Java",
1044:                        "`{int i = &a; someCFunction(i);}"));
1045:                s.addTest(new JeannieParserTest(false, "Block", "Java",
1046:                        "{int i = a >>> 3; someJavaMethod(i);}"));
1047:                s.addTest(new JeannieParserTest(false, "CompoundStatement",
1048:                        "C", "`{int i = a >>> 3; someJavaMethod(i);}"));
1049:                s.addTest(new JeannieParserTest(false, "CompoundStatement",
1050:                        "C", "{int i = &a; someCFunction(i);}"));
1051:                s.addTest(new JeannieParserTest(false,
1052:                        "JeannieC$ConditionalExpression", "C", "1+2"));
1053:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1054:                        "C", "_cancel a;"));
1055:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1056:                        "C", "_commit a;"));
1057:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1058:                        "C", "_copyFromJava(ca, 0, `ja, 0, 2);"));
1059:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1060:                        "C", "_copyToJava(`ja, 0, ca, 0, `ja.length-1);"));
1061:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1062:                        "C", "_with(ca=`new int[123]){}"));
1063:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1064:                        "C", "_with(ca=ja){ca[0]=3;}"));
1065:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1066:                        "C", "_with(ca=ja){}"));
1067:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1068:                        "C", "_with(ca=`ja){}"));
1069:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1070:                        "C", "`synchronized(m){}"));
1071:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1072:                        "C", "`throw new E();"));
1073:                s.addTest(new JeannieParserTest(false, "JeannieC$Statement",
1074:                        "C", "`try{}catch(E e){}"));
1075:                s.addTest(new JeannieParserTest(false,
1076:                        "JeannieC$UnaryExpression", "C", "`(x >>> 3)"));
1077:                s.addTest(new JeannieParserTest(false,
1078:                        "JeannieC$UnaryExpression", "C", "`x"));
1079:                s
1080:                        .addTest(new JeannieParserTest(
1081:                                false,
1082:                                "File" /* 000 hello world */,
1083:                                null,
1084:                                "`.C{extern int printf(__const char *__restrict __format, ...);}class Main{static native void sayHi() `{printf(\"Hello world!\\n\");}public static void main(String[]args){sayHi();}}"));
1085:                s
1086:                        .addTest(new JeannieParserTest(
1087:                                false,
1088:                                "File" /* 001 pure Java hello world */,
1089:                                null,
1090:                                "`.C{}class Main{public static void main(String[]args){System.out.println(\"Hello, world\");}}"));
1091:                s
1092:                        .addTest(new JeannieParserTest(
1093:                                false,
1094:                                "File" /* 002 callStatic */,
1095:                                null,
1096:                                "`.C{extern int printf(__const char *__restrict __format, ...);}class Main{native static void foo() `{int y; y = `Math.max(123, 456); printf(\"return value: %d\\n\", y);}public static void main(String[] args){foo();}}"));
1097:                s.addTest(new JeannieParserTest(false, "File", null, ""));
1098:                s.addTest(new JeannieParserTest(false, "File", null,
1099:                        "`.Java{import java.util.Vector;}int f(){}"));
1100:                s
1101:                        .addTest(new JeannieParserTest(false, "File", null,
1102:                                "`.Java{}"));
1103:                s.addTest(new JeannieParserTest(false, "File", null,
1104:                        "`.Java{}`java.lang.Integer i;"));
1105:                s.addTest(new JeannieParserTest(false, "File", null,
1106:                        "`.Java{}const `java.lang.Integer *i[10];"));
1107:                s.addTest(new JeannieParserTest(false, "File", null,
1108:                        "`.Java{}int f()`throws E{}"));
1109:                s
1110:                        .addTest(new JeannieParserTest(
1111:                                false,
1112:                                "File",
1113:                                null,
1114:                                "`.C{extern int printf(__const char*__restrict __format,...);}class Main{static native void f(int[]ja)throws Exception`{int i;jint*ca;_with(ca=`ja){for(i=0;i<3;i++){if(ca[i]==4)`throw new Exception();printf(\"p0 (%d:%d)\\n\",i,ca[i]);}printf(\"p1\\n\");_commit ca;}printf(\"p2\\n\");}public static void main(String[]args){int[]a={3,1,4};try{f(a);System.out.println(\"p3\");}catch(Exception e){System.out.println(\"p4\");}}}"));
1115:                s
1116:                        .addTest(new JeannieParserTest(false, "File", null,
1117:                                "`.C{typedef int jint; jint i=0;}class A{int f(){return `&i;}}"));
1118:                s
1119:                        .addTest(new JeannieParserTest(false, "File", null,
1120:                                "`.C{typedef int jint; jint i=0;}class A{int f(){return `((jint)&i);}}"));
1121:                s
1122:                        .addTest(new JeannieParserTest(false, "File", null,
1123:                                "`.C{typedef int jint; jint i=0;}class A{int f(){return `(i+2);}}"));
1124:                s
1125:                        .addTest(new JeannieParserTest(
1126:                                false,
1127:                                "File",
1128:                                null,
1129:                                "`.C{typedef int jint;}class Main{static native int sum(int[] ja)`{jint *ca,s;int i,n;s=0;n=`ja.length;_with(ca=`ja){for(i=0;i<n;i++)s+=ca[i];_cancel ca;}return s;}public static void main(String[]args){int[] a={3,1,4};System.out.println(\"expected 8, got \"+sum(a));}}"));
1130:                s.addTest(new JeannieParserTest(false, "File", null,
1131:                        "`.C{} class A{int f(){return `(1+2);}}"));
1132:                s.addTest(new JeannieParserTest(false, "File", null,
1133:                        "`.C{} class A{void f(){int x=0;}}"));
1134:                s.addTest(new JeannieParserTest(false, "File", null,
1135:                        "`.C{} class A{} "));
1136:                s.addTest(new JeannieParserTest(false, "File", null,
1137:                        "`.C{}class A{native void f()`{}}"));
1138:                s.addTest(new JeannieParserTest(false,
1139:                        "JeannieJava$Declaration", "Java", "A b(C d,E[]f){}"));
1140:                s.addTest(new JeannieParserTest(false,
1141:                        "JeannieJava$Expression", "Java",
1142:                        "(a==++b.c(1)[d.e()][2].f&g)-h"));
1143:                s.addTest(new JeannieParserTest(false,
1144:                        "JeannieJava$Expression", "Java", "`&x"));
1145:                s.addTest(new JeannieParserTest(false,
1146:                        "JeannieJava$Expression", "Java", "`(1?2:3)"));
1147:                s.addTest(new JeannieParserTest(false,
1148:                        "JeannieJava$Expression", "Java",
1149:                        "new A[][]{{b,c},{d,e}}"));
1150:                return s;
1151:            }
1152:
1153:            public static Test suite() {
1154:                final TestSuite s = new TestSuite();
1155:                if (false) { //TD 00 quick test-bed
1156:                    s
1157:                            .addTest(new JeannieCodeGeneratorTest(
1158:                                    false,
1159:                                    "File",
1160:                                    null,
1161:                                    "`.C{typedef int JNIEnv;typedef int jint;int f(JNIEnv*env)`{return 0;}}class A{}"));
1162:                    //s.addTest(new JeannieAnalyzerTestError(false, "File", null, "`.C{typedef int JNIEnv;}class A{}", ""));
1163:                    //s.addTest(new JeannieCodeGeneratorTest(false, "File", null, "`.C{typedef int JNIEnv;}class A{}"));
1164:                } else {
1165:                    s.addTestSuite(xtc.lang.jeannie.UnitTests.class);
1166:                    s.addTest(makeSuiteDebugger());
1167:                    s.addTest(makeSuiteJeannieCodeGenerator());
1168:                    s.addTest(makeSuiteJeannieAnalyzerError());
1169:                    s.addTest(makeSuiteJeannieParser());
1170:                    s.addTest(JavaUnitTests.suite());
1171:                }
1172:                return s;
1173:            }
1174:
1175:            private void addJniTypedefs(final Runtime runtime,
1176:                    final SymbolTable tab) {
1177:                final StringBuffer defs = new StringBuffer();
1178:                defs.append("typedef int jint;");
1179:                defs.append("typedef long jlong;");
1180:                defs.append("typedef void* jobject;");
1181:                defs.append("typedef jobject jintArray;");
1182:                defs.append("typedef jobject jobjectArray;");
1183:                final GNode builtins = Utilities
1184:                        .jeannieStringToAst("CompilationUnit", "Java", "`.C{"
1185:                                + defs + "}class A{}");
1186:                new Analyzer(runtime, tab, null).dispatch(builtins);
1187:            }
1188:
1189:            public final void testJeannieParser_pFile() throws Exception {
1190:                final GNode ast = Utilities.jeannieStringToAst("File", null,
1191:                        "`.C{} class A { }", false);
1192:                final String out = Utilities.jeannieAstToString(ast, null);
1193:                if (false)
1194:                    System.out.println(out);
1195:            }
1196:
1197:            public final void testJeannieUtil_cAstToString() throws Exception {
1198:                for (final String s : new String[] { "{}",
1199:                        "{int*i,j=2+2,(*k)[5];}" }) {
1200:                    final GNode ast = Utilities.cStringToAst(
1201:                            "CompoundStatement", s);
1202:                    assertEquals(s, JavaUnitTests.contractSpace(Utilities
1203:                            .cAstToString(ast)));
1204:                }
1205:            }
1206:
1207:            public final void testJeannieUtil_containsCCode() throws Exception {
1208:                assertFalse(Utilities.containsJavaToCTransition(Utilities
1209:                        .jeannieStringToAst("JavaInJavaBlock", "java", "{}")));
1210:                assertTrue(Utilities
1211:                        .containsJavaToCTransition(Utilities
1212:                                .jeannieStringToAst("JavaInJavaBlock", "java",
1213:                                        "{`{}}")));
1214:                assertFalse(Utilities.containsJavaToCTransition(Utilities
1215:                        .jeannieStringToAst("JavaInJavaBlock", "java",
1216:                                "{int i = 2;}")));
1217:                assertTrue(Utilities.containsJavaToCTransition(Utilities
1218:                        .jeannieStringToAst("JavaInJavaBlock", "java",
1219:                                "{int i = 3.5 * `(2 + 2);}")));
1220:            }
1221:
1222:            public final void testJeannieUtil_cTypeToJavaType()
1223:                    throws Exception {
1224:                final Runtime runtime = Utilities.newRuntime();
1225:                final SymbolTable tab = new SymbolTable();
1226:                addJniTypedefs(runtime, tab);
1227:                assertEquals("int", JavaEntities.javaTypeToString(tab,
1228:                        Utilities.cTypeToJavaType(tab, runtime, null, Utilities
1229:                                .cStringToType("char"))));
1230:                assertEquals("long", JavaEntities.javaTypeToString(tab,
1231:                        Utilities.cTypeToJavaType(tab, runtime, null, Utilities
1232:                                .cStringToType("long"))));
1233:            }
1234:
1235:            public final void testJeannieUtil_cTypeToString() throws Exception {
1236:                for (final String s : new String[] { "int", "int*", "int[]",
1237:                        "int(*)[3]", "struct s***" }) {
1238:                    final Type type = Utilities.cStringToType(s);
1239:                    assertEquals(s, JavaUnitTests.contractSpace(Utilities
1240:                            .cTypeToString(type)));
1241:                }
1242:                assertEquals("struct t", JavaUnitTests.contractSpace(Utilities
1243:                        .cTypeToString(Utilities
1244:                                .cStringToType("struct t{int i;}"))));
1245:                assertEquals("int(*p)[3]", JavaUnitTests
1246:                        .contractSpace(Utilities.cTypeToString(Utilities
1247:                                .cStringToType("int(*)[3]"), "p")));
1248:            }
1249:
1250:            public final void testJeannieUtil_javaTypeToApiType() {
1251:                assertEquals("int", Utilities.javaTypeToApiType(JavaEntities
1252:                        .javaStringToType("int")));
1253:                assertEquals("Object", Utilities.javaTypeToApiType(JavaEntities
1254:                        .javaStringToType("int[][]")));
1255:                assertEquals("intArray", Utilities
1256:                        .javaTypeToApiType(JavaEntities
1257:                                .javaStringToType("int[]")));
1258:                assertEquals("boolean", Utilities
1259:                        .javaTypeToApiType(JavaEntities
1260:                                .javaStringToType("boolean")));
1261:                assertEquals("Object", Utilities.javaTypeToApiType(JavaEntities
1262:                        .javaStringToType("String")));
1263:            }
1264:
1265:            public final void testJeannieUtil_javaTypeToCType()
1266:                    throws Exception {
1267:                final Runtime runtime = Utilities.newRuntime();
1268:                final SymbolTable tab = new SymbolTable();
1269:                addJniTypedefs(runtime, tab);
1270:                assertEquals("jint", Utilities.cTypeToString(Utilities
1271:                        .javaTypeToCType(tab, runtime, null, JavaEntities
1272:                                .javaStringToType("int"), false)));
1273:                assertEquals("jintArray", Utilities.cTypeToString(Utilities
1274:                        .javaTypeToCType(tab, runtime, null, JavaEntities
1275:                                .javaStringToType("int[]"), false)));
1276:                assertEquals("jobjectArray", Utilities.cTypeToString(Utilities
1277:                        .javaTypeToCType(tab, runtime, null, JavaEntities
1278:                                .javaStringToType("int[][]"), false)));
1279:                assertEquals("jobject", Utilities.cTypeToString(Utilities
1280:                        .javaTypeToCType(tab, runtime, null, JavaEntities
1281:                                .javaStringToType("Object"), false)));
1282:            }
1283:
1284:            public final void testJeannieUtil_javaTypeToString() {
1285:                for (final String s : new String[] { "int", "int[][]",
1286:                        "java.lang.Object", "java.io.Writer[]" }) {
1287:                    final Type type = JavaEntities.javaStringToType(s);
1288:                    assertEquals(s, JavaEntities.javaTypeToString(null, type));
1289:                }
1290:                assertEquals("java.lang.Object", JavaEntities.javaTypeToString(
1291:                        null, JavaEntities.javaStringToType("Object")));
1292:            }
1293:
1294:            public final void testJeannieUtil_jniMangledName() {
1295:                assertEquals("a_b_C", Utilities.jniMangledName("a.b.C"));
1296:                assertEquals("C_1x", Utilities.jniMangledName("C_x"));
1297:                assertEquals("java_lang_Object", Utilities
1298:                        .jniMangledName("java.lang.Object"));
1299:                assertEquals("java_lang_String", Utilities.jniMangledName(null,
1300:                        JavaEntities.javaStringToType("java.lang.String")));
1301:            }
1302:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.