Source Code Cross Referenced for TestStackBugs.java in  » Test-Coverage » Hansel » org » hanseltest » 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 » Test Coverage » Hansel » org.hanseltest 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.hanseltest;
002:
003:        import java.io.InputStream;
004:
005:        import junit.framework.TestCase;
006:
007:        import org.hansel.HanselFrame;
008:        import org.hansel.HanselInterpreter;
009:        import org.objectweb.asm.ClassReader;
010:        import org.objectweb.asm.tree.ClassNode;
011:        import org.objectweb.asm.tree.MethodNode;
012:        import org.objectweb.asm.tree.analysis.Analyzer;
013:        import org.objectweb.asm.tree.analysis.AnalyzerException;
014:        import org.objectweb.asm.tree.analysis.Frame;
015:
016:        /**
017:         * This is a combined testcase for bugs 755796, 755797, 755768, 755798 
018:         * and RFE 744114.
019:         */
020:        public class TestStackBugs extends TestCase {
021:
022:            private ClassNode classNode;
023:
024:            public TestStackBugs(String name) {
025:                super (name);
026:            }
027:
028:            public void setUp() throws Exception {
029:                InputStream resourceAsStream = getClass().getResourceAsStream(
030:                        "TestStackBugs$Example.class");
031:                ClassReader cr = new ClassReader(resourceAsStream);
032:
033:                classNode = new ClassNode();
034:                cr.accept(classNode, 0);
035:            }
036:
037:            private String getResultToString(String methodName, int relIndex)
038:                    throws AnalyzerException {
039:                for (Object method : classNode.methods) {
040:                    MethodNode methodNode = (MethodNode) method;
041:
042:                    if (methodNode.name.equals(methodName)) {
043:                        Analyzer analyzer = new Analyzer(new HanselInterpreter(
044:                                methodNode.localVariables)) {
045:                            protected Frame newFrame(final int nLocals,
046:                                    final int nStack) {
047:                                return new HanselFrame(nLocals, nStack);
048:                            }
049:
050:                            protected Frame newFrame(final Frame src) {
051:                                return new HanselFrame((HanselFrame) src);
052:                            }
053:                        };
054:
055:                        Frame[] frames = analyzer.analyze(classNode.name,
056:                                methodNode);
057:                        HanselFrame[] hanselFrames = new HanselFrame[frames.length];
058:                        for (int i = 0; i < frames.length; i++) {
059:                            hanselFrames[i] = (HanselFrame) frames[i];
060:                        }
061:
062:                        for (int i = hanselFrames.length - 2; i > 0; i--) {
063:                            if (hanselFrames[i].getStackSize() > 0) {
064:                                return hanselFrames[i].pop().toString();
065:                            }
066:
067:                        }
068:                        throw new IllegalStateException("Didn't find result: "
069:                                + methodName);
070:                    }
071:                }
072:
073:                throw new IllegalArgumentException("Unknown method: "
074:                        + methodName);
075:            }
076:
077:            public void testBug755796() throws AnalyzerException {
078:                assertEquals("\"testString\"",
079:                        getResultToString("bug755796", 0));
080:            }
081:
082:            public void testBug755797() throws AnalyzerException {
083:                assertEquals("!(a | b)", getResultToString("bug755797", 1));
084:                assertEquals("!a", getResultToString("bug755797a", 1));
085:                assertEquals("!(a & b)", getResultToString("bug755797b", 1));
086:                assertEquals("!(a && b)", getResultToString("bug755797c", 1));
087:                assertEquals("!(a || b)", getResultToString("bug755797d", 1));
088:                assertEquals("a | b", getResultToString("bug755797e", 1));
089:                assertEquals("a", getResultToString("bug755797f", 1));
090:                assertEquals("a & b", getResultToString("bug755797g", 1));
091:                assertEquals("a && b", getResultToString("bug755797h", 1));
092:                assertEquals("a || b", getResultToString("bug755797i", 1));
093:            }
094:
095:            public void testBug755768() throws AnalyzerException {
096:                assertEquals("obj1 != obj2", getResultToString("bug755768", 1));
097:                assertEquals("obj1 == obj2", getResultToString("bug755768a", 1));
098:                assertEquals("a >= b", getResultToString("bug755768b", 1));
099:                assertEquals("a <= b", getResultToString("bug755768c", 1));
100:                assertEquals("a > b", getResultToString("bug755768d", 1));
101:                assertEquals("a < b", getResultToString("bug755768e", 1));
102:            }
103:
104:            public void testBug755798() throws AnalyzerException {
105:                assertEquals(
106:                        "c1.getName().length() == 123 == c2.getName().length() == 234",
107:                        getResultToString("bug755798", 1));
108:            }
109:
110:            public void testRFE744114() throws AnalyzerException {
111:                assertEquals("this.testMethod(true)", getResultToString(
112:                        "rfe744114", 1));
113:                assertEquals("this.testMethod(false)", getResultToString(
114:                        "rfe744114a", 1));
115:            }
116:
117:            public static class Example {
118:                private boolean boolVar;
119:
120:                public String bug755796() {
121:                    /* Code:
122:                     *  0:   ldc     #2; //String testString
123:                     *  2:   areturn
124:                     */
125:                    return "testString";
126:                }
127:
128:                public void bug755797(boolean a, boolean b) {
129:                    boolVar = !(a | b);
130:                }
131:
132:                public void bug755797a(boolean a) {
133:                    boolVar = !a;
134:                }
135:
136:                public void bug755797b(boolean a, boolean b) {
137:                    boolVar = !(a & b);
138:                }
139:
140:                public void bug755797c(boolean a, boolean b) {
141:                    boolVar = !(a && b);
142:                }
143:
144:                public void bug755797c1(boolean a, boolean b) {
145:                    boolVar = !a || (a && !b);
146:                }
147:
148:                public void bug755797d(boolean a, boolean b) {
149:                    boolVar = !(a || b);
150:                }
151:
152:                public void bug755797e(boolean a, boolean b) {
153:                    boolVar = (a | b);
154:                }
155:
156:                public void bug755797f(boolean a) {
157:                    boolVar = a;
158:                }
159:
160:                public void bug755797g(boolean a, boolean b) {
161:                    boolVar = (a & b);
162:                }
163:
164:                public void bug755797h(boolean a, boolean b) {
165:                    boolVar = (a && b);
166:                }
167:
168:                public void bug755797i(boolean a, boolean b) {
169:                    boolVar = (a || b);
170:                }
171:
172:                public void bug755768(Object obj1, Object obj2) {
173:                    boolVar = obj1 != obj2;
174:                }
175:
176:                public void bug755768a(Object obj1, Object obj2) {
177:                    boolVar = obj1 == obj2;
178:                }
179:
180:                public void bug755768b(int a, int b) {
181:                    boolVar = a >= b;
182:                }
183:
184:                public void bug755768c(int a, int b) {
185:                    boolVar = a <= b;
186:                }
187:
188:                public void bug755768d(int a, int b) {
189:                    boolVar = a > b;
190:                }
191:
192:                public void bug755768e(int a, int b) {
193:                    boolVar = a < b;
194:                }
195:
196:                public void bug755798(Class c1, Class c2) {
197:                    boolVar = (c1.getName().length() == 123) == (c2.getName()
198:                            .length() == 234);
199:                }
200:
201:                private boolean testMethod(boolean param) {
202:                    return param;
203:                }
204:
205:                public void rfe744114() {
206:                    boolVar = testMethod(true);
207:                }
208:
209:                public void rfe744114a() {
210:                    boolVar = testMethod(false);
211:                }
212:
213:                public boolean getResult() {
214:                    return boolVar;
215:                }
216:            }
217:
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.