Source Code Cross Referenced for TestGraphTransformer.java in  » Test-Coverage » Quilt » org » quilt » cl » 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 » Quilt » org.quilt.cl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* TestGraphTransformer.java */
002:        package org.quilt.cl;
003:
004:        import java.util.List;
005:        import java.util.Vector;
006:        import junit.framework.*;
007:        import org.apache.bcel.classfile.Method;
008:        import org.apache.bcel.generic.*;
009:
010:        import org.quilt.graph.*;
011:
012:        /**
013:         * Test GraphTransformer using runTest methods from classes synthesized
014:         * by ClassFactory.
015:         *
016:         * @author <a href="jddixon@users.sourceforge.net">Jim Dixon</a>
017:         */
018:        public class TestGraphTransformer extends TestCase {
019:
020:            private ClassFactory factory = ClassFactory.getInstance();
021:
022:            private ClassGen clazz;
023:
024:            private GraphTransformer xformer;
025:
026:            private GraphSpy spy;
027:
028:            private GraphTalker talker;
029:
030:            private ControlFlowGraph theGraph;
031:
032:            public TestGraphTransformer(String name) {
033:                super (name);
034:                GraphSpy.setName("the spy");
035:            }
036:
037:            public void setUp() {
038:                List gxf = new Vector();
039:                spy = new GraphSpy();
040:                talker = new GraphTalker();
041:                gxf.add(spy);
042:                // uncomment if things stop working
043:                //      gxf.add ( talker );
044:                xformer = new GraphTransformer(gxf);
045:            }
046:
047:            private MethodGen loadAndExtractRunTest(String name) {
048:                clazz = factory.makeClass(name, name);
049:                Method[] methods = clazz.getMethods();
050:                for (int i = 0; i < methods.length; i++) {
051:                    if (methods[i].getName().equals("runTest")) {
052:                        return new MethodGen(methods[i], clazz.getClassName(),
053:                                clazz.getConstantPool());
054:                    }
055:                }
056:                return null; // not found
057:            }
058:
059:            public void testDefault() {
060:                MethodGen mgDefault = loadAndExtractRunTest("test.data.TestDefault");
061:                assertNotNull("extracted method is null", mgDefault);
062:
063:                // build the graph, get the instruction list from it
064:                mgDefault.setInstructionList(xformer.xform(clazz, mgDefault));
065:                mgDefault.removeNOPs();
066:                InstructionList ilist = mgDefault.getInstructionList();
067:                Instruction[] inst = ilist.getInstructions();
068:                assertEquals("wrong number of instructions", 2, ilist
069:                        .getLength());
070:                assertTrue("", inst[0] instanceof  ICONST);
071:                assertTrue("", inst[1] instanceof  IRETURN);
072:
073:                theGraph = GraphSpy.getTheGraph();
074:                // DEBUG
075:                //GraphTalker talker = new GraphTalker();
076:                //talker.xform (null, null, theGraph);
077:                // END
078:                assertNotNull("failed to get reference to method CFG", theGraph);
079:                assertNotNull("graph exit vertex is null", theGraph.getExit());
080:                assertEquals("TestDefault graph has wrong size", 3, theGraph
081:                        .size());
082:            }
083:
084:            public void testIfThen() {
085:                MethodGen mgIfThen = loadAndExtractRunTest("test.data.TestIfThen");
086:                assertNotNull("extracted method is null", mgIfThen);
087:
088:                // build the graph, get the instruction list from it
089:                InstructionList ilist = xformer.xform(clazz, mgIfThen);
090:                assertEquals("wrong number of instructions", 6, ilist
091:                        .getLength());
092:                Instruction[] inst = ilist.getInstructions();
093:                assertTrue("should be ILOAD: " + inst[0],
094:                        inst[0] instanceof  ILOAD);
095:                assertTrue("should be IFGT:  " + inst[1],
096:                        inst[1] instanceof  IFGT);
097:                assertTrue("should be ICONST:  " + inst[2],
098:                        inst[2] instanceof  ICONST);
099:                assertTrue("should be IRETURN:  " + inst[3],
100:                        inst[3] instanceof  IRETURN);
101:                assertTrue("should be ICONST:  " + inst[4],
102:                        inst[4] instanceof  ICONST);
103:                assertTrue("should be IRETURN:  " + inst[5],
104:                        inst[5] instanceof  IRETURN);
105:
106:                // EXAMINE GRAPH
107:                theGraph = GraphSpy.getTheGraph();
108:                assertNotNull("failed to get reference to method CFG", theGraph);
109:                assertNotNull("graph exit vertex is null", theGraph.getExit());
110:                assertEquals("TestIfThen graph has wrong size", 5, theGraph
111:                        .size());
112:            }
113:
114:            public void testWhile() {
115:                MethodGen mgWhile = loadAndExtractRunTest("test.data.TestWhile");
116:                assertNotNull("extracted method is null", mgWhile);
117:
118:                // build the graph, get the instruction list from it
119:                mgWhile.setInstructionList(xformer.xform(clazz, mgWhile));
120:                mgWhile.removeNOPs();
121:                InstructionList ilist = mgWhile.getInstructionList();
122:                assertEquals("wrong number of instructions", 7, ilist
123:                        .getLength());
124:                Instruction[] inst = ilist.getInstructions();
125:                assertTrue("", inst[0] instanceof  ILOAD);
126:                assertTrue("", inst[1] instanceof  DUP);
127:                assertTrue("", inst[2] instanceof  IFLE);
128:                assertTrue("", inst[3] instanceof  ICONST);
129:                assertTrue("", inst[4] instanceof  ISUB);
130:                assertTrue("", inst[5] instanceof  GOTO);
131:                assertTrue("", inst[6] instanceof  IRETURN);
132:
133:                // EXAMINE GRAPH
134:                theGraph = GraphSpy.getTheGraph();
135:                assertNotNull("failed to get reference to method CFG", theGraph);
136:                assertNotNull("graph exit vertex is null", theGraph.getExit());
137:                assertEquals("TestWhile graph has wrong size", 6, theGraph
138:                        .size());
139:            } // GEEP
140:
141:            private void dumpInstructions(Instruction[] ilist) {
142:                System.out.println("Instructions returned:");
143:                for (int i = 0; i < ilist.length; i++) {
144:                    System.out.println("    " + ilist[i]);
145:                }
146:            }
147:
148:            public void testNPEWithCatch() {
149:                MethodGen mgNPEWithCatch = loadAndExtractRunTest("test.data.TestNPEWithCatch");
150:                assertNotNull("extracted method is null", mgNPEWithCatch);
151:
152:                // build the graph, get the instruction list from it
153:                mgNPEWithCatch.setInstructionList(xformer.xform(clazz,
154:                        mgNPEWithCatch));
155:                mgNPEWithCatch.removeNOPs();
156:                InstructionList ilist = mgNPEWithCatch.getInstructionList();
157:                Instruction[] inst = ilist.getInstructions();
158:
159:                theGraph = GraphSpy.getTheGraph();
160:                // talker.xform (null, null, theGraph);
161:
162:                assertNotNull("failed to get reference to method CFG", theGraph);
163:                assertNotNull("graph exit vertex is null", theGraph.getExit());
164:                assertEquals("TestNPEWithCatch graph has wrong size", 8,
165:                        theGraph.size());
166:
167:                assertEquals("wrong number of instructions", 7, ilist
168:                        .getLength());
169:                assertTrue("expected ACONST_NULL",
170:                        inst[0] instanceof  ACONST_NULL);
171:                assertTrue("expected ICONST", inst[1] instanceof  ICONST);
172:                assertTrue("expected INVOKEVIRTUAL",
173:                        inst[2] instanceof  INVOKEVIRTUAL);
174:                assertTrue("expected ICONST", inst[3] instanceof  ICONST);
175:                assertTrue("expected IRETURN", inst[4] instanceof  IRETURN);
176:                assertTrue("expected ICONST", inst[5] instanceof  ICONST);
177:                assertTrue("expected IRETURN", inst[6] instanceof  IRETURN);
178:            }
179:
180:            public void testNPENoCatch() {
181:                MethodGen mgNPENoCatch = loadAndExtractRunTest("test.data.TestNPENoCatch");
182:                assertNotNull("extracted method is null", mgNPENoCatch);
183:
184:                // build the graph, get the instruction list from it
185:                InstructionList ilist = xformer.xform(clazz, mgNPENoCatch);
186:                assertEquals("wrong number of instructions", 5, ilist
187:                        .getLength());
188:                Instruction[] inst = ilist.getInstructions();
189:                assertTrue("expected ACONST_NULL",
190:                        inst[0] instanceof  ACONST_NULL);
191:                assertTrue("expected ICONST", inst[1] instanceof  ICONST);
192:                assertTrue("expected INVOKEVIRTUAL",
193:                        inst[2] instanceof  INVOKEVIRTUAL);
194:                assertTrue("expected ICONST", inst[3] instanceof  ICONST);
195:                assertTrue("expected IRETURN", inst[4] instanceof  IRETURN);
196:
197:                theGraph = GraphSpy.getTheGraph();
198:                // DEBUG
199:                //GraphTalker talker = new GraphTalker();
200:                //talker.xform (null, null, theGraph);
201:                // END
202:                assertNotNull("failed to get reference to method CFG", theGraph);
203:                assertNotNull("graph exit vertex is null", theGraph.getExit());
204:                assertEquals("TestNPENoCatch graph has wrong size", 4, theGraph
205:                        .size());
206:            }
207:
208:            public void testSelect() {
209:                MethodGen mgSelect = loadAndExtractRunTest("test.data.TestSelect");
210:                assertNotNull("extracted method is null", mgSelect);
211:
212:                // build the graph, get the instruction list from it
213:                mgSelect.setInstructionList(xformer.xform(clazz, mgSelect));
214:                mgSelect.removeNOPs();
215:                InstructionList ilist = mgSelect.getInstructionList();
216:                Instruction[] inst = ilist.getInstructions();
217:                // DEBUG
218:                //dumpInstructions(inst);
219:                // END
220:                assertEquals("wrong number of instructions", 10, inst.length);
221:                assertTrue("expected ILOAD", inst[0] instanceof  ILOAD);
222:                assertTrue("expected LOOKUPSWITCH",
223:                        inst[1] instanceof  LOOKUPSWITCH);
224:                assertTrue("expected SIPUSH", inst[2] instanceof  SIPUSH);
225:                assertTrue("expected IRETURN", inst[3] instanceof  IRETURN);
226:                assertTrue("expected SIPUSH", inst[4] instanceof  SIPUSH);
227:                assertTrue("expected IRETURN", inst[5] instanceof  IRETURN);
228:                assertTrue("expected SIPUSH", inst[6] instanceof  SIPUSH);
229:                assertTrue("expected IRETURN", inst[7] instanceof  IRETURN);
230:                assertTrue("expected SIPUSH", inst[8] instanceof  SIPUSH);
231:                assertTrue("expected IRETURN", inst[9] instanceof  IRETURN);
232:
233:                theGraph = GraphSpy.getTheGraph();
234:                // DEBUG
235:                //GraphTalker talker = new GraphTalker();
236:                //talker.xform (null, null, theGraph);
237:                // END
238:                assertNotNull("failed to get reference to method CFG", theGraph);
239:                assertNotNull("graph exit vertex is null", theGraph.getExit());
240:                assertEquals("TestSelect graph has wrong size", 7, theGraph
241:                        .size());
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.