Source Code Cross Referenced for Engine.java in  » Testing » TT » U2 » T2 » 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 » Testing » TT » U2.T2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package U2.T2;
002:
003:        //import U2.T2.Obj.* ;
004:        import java.lang.reflect.*;
005:        import java.util.*;
006:        import java.io.*;
007:        import U2.T2.Reflection.*;
008:
009:        /**
010:         * Abstract class representing the general structure and parameters of
011:         * a test engine; furthermore the class contains a bunch of utility
012:         * static methods.
013:         */
014:        abstract public class Engine {
015:
016:            /**
017:             * The class under the test.
018:             */
019:            protected Class CUT;
020:
021:            /**
022:             * The object pool used by the engine.
023:             */
024:            protected Pool pool;
025:
026:            /*
027:             * Saved execution traces. Typically it contains traces of
028:             * violating executions.
029:             */
030:            // protected LinkedList<Trace> savedTraces ;
031:            /**
032:             * Specify a maximum on the numbers of total execution steps
033:             * generated by the engine. Default is 500.
034:             */
035:            protected int maxNumOfSteps = 500;
036:
037:            /**
038:             * Specify a maximum on the length of each execution. Default is
039:             * 4.
040:             */
041:            protected int maxExecLength = 4;
042:
043:            /**
044:             * The engine should stop if the number of violations found
045:             * reaches maxNumViolations. Default is 1.
046:             */
047:            protected int maxNumViolations = 1;
048:
049:            // some variables to keep track progress:
050:
051:            /**
052:             * Total number of execution steps generated.
053:             */
054:            protected int numOfSteps = 0;
055:
056:            /**
057:             * Total number of executions generated.
058:             */
059:            protected int numOfExecs = 0;
060:
061:            /**
062:             * Total number of violations found.
063:             */
064:            protected int numOfViolations = 0;
065:
066:            /**
067:             * Total number of relevant checks.
068:             */
069:            protected int numOfRelevantChecks = 0;
070:
071:            /*
072:             * Construct an engine with a default setting. The CUT is set to
073:             * null.
074:             */
075:            // public Engine() {	}  // :)
076:            /**
077:             * Run the test engine. It does nothing here, and should be
078:             * overiden by subclass.
079:             */
080:            abstract public void runMe();
081:
082:            /**
083:             * To report violating traces found by the engine. It does nothing
084:             * here, and should be overiden by subclass.
085:             */
086:            abstract public void report(PrintStream out);
087:
088:            // Some utilities methods
089:
090:            private static final String CLASSINV_STR = "classinv";
091:            private static final String MAIN_STR = "main";
092:            private static final String SPEC_STR = "_spec";
093:
094:            /**
095:             * Get the constructors of a class that act as interface
096:             * points. Currently these are the declared, non-private
097:             * constructors of the class.
098:             */
099:            public static List<Constructor> getConsIPs(Class C) {
100:
101:                List<Constructor> result = new LinkedList<Constructor>();
102:                Constructor[] cons = C.getDeclaredConstructors();
103:                for (int i = 0; i < cons.length; i++)
104:                    if (!Modifier.isPrivate(cons[i].getModifiers()))
105:                        result.add(cons[i]);
106:
107:                return result;
108:
109:            }
110:
111:            /**
112:             * Get the methods of a class that act as interface
113:             * points. Currently this is all public methods of its
114:             * superclasses + its own declared non-private methods.
115:             */
116:            public static List<Method> getMethsIPs(Class C) {
117:
118:                Class CLASS_OBJECT = (new Object()).getClass();
119:
120:                List<Method> result = new LinkedList<Method>();
121:                // first get C's own declared methods:
122:                Method[] methods = C.getDeclaredMethods();
123:                for (int i = 0; i < methods.length; i++)
124:                    if ((!Modifier.isPrivate(methods[i].getModifiers()))
125:                            && (!Modifier.isStatic(methods[i].getModifiers()) || ReflUtil
126:                                    .canAcceptAsParameter(C, methods[i]))
127:                            && !methods[i].getName().equals(CLASSINV_STR)
128:                            && !methods[i].getName().endsWith(SPEC_STR) &&
129:                            // exclude main for now ...
130:                            !methods[i].getName().equals(MAIN_STR))
131:                        result.add(methods[i]);
132:
133:                // now get public methods from C + superclasses:
134:                methods = C.getMethods();
135:                for (int i = 0; i < methods.length; i++)
136:                    if ((!result.contains(methods[i]))
137:                            && (!Modifier.isStatic(methods[i].getModifiers()) || ReflUtil
138:                                    .canAcceptAsParameter(C, methods[i]))
139:                            &&
140:                            // exclude methods of "Object" ... they should be safe:
141:                            (methods[i].getDeclaringClass() != CLASS_OBJECT)
142:                            && !methods[i].getName().equals(CLASSINV_STR)
143:                            && !methods[i].getName().endsWith(SPEC_STR) &&
144:                            // exclude main for now ...
145:                            !methods[i].getName().equals(MAIN_STR))
146:                        result.add(methods[i]);
147:
148:                return result;
149:
150:            }
151:
152:            /**
153:             * Get the fields of a class that act as interface
154:             * points. Currently this is all public fields of its
155:             * superclasses + its own declared non-private fields.
156:             */
157:            public static List<Field> getFieldsIPs(Class C) {
158:
159:                Class CLASS_OBJECT = (new Object()).getClass();
160:
161:                List<Field> result = new LinkedList<Field>();
162:                // first get C's own declared fields:
163:                Field[] fields = C.getDeclaredFields();
164:                for (int i = 0; i < fields.length; i++)
165:                    if (!Modifier.isPrivate(fields[i].getModifiers())
166:                            &&
167:                            // Ehm... for now excluding static fields:
168:                            !Modifier.isStatic(fields[i].getModifiers())
169:                            && !Modifier.isFinal(fields[i].getModifiers()))
170:                        result.add(fields[i]);
171:
172:                // now get public fields from C + superclasses:
173:                fields = C.getFields();
174:                for (int i = 0; i < fields.length; i++)
175:                    if (!result.contains(fields[i])
176:                            && !Modifier.isStatic(fields[i].getModifiers())
177:                            && !Modifier.isFinal(fields[i].getModifiers()))
178:                        result.add(fields[i]);
179:
180:                return result;
181:
182:            }
183:
184:            /**
185:             * Construct a mapping such that for any method m of the class C
186:             * that has m_spec as its specification, we add the pair
187:             * (m,m_spec) to the mapping.
188:             */
189:            public static HashMap<Method, Method> mk_specMap(Class C,
190:                    List<Method> methods) {
191:
192:                HashMap<Method, Method> map = new HashMap<Method, Method>();
193:                for (Method m : methods) {
194:                    Method spec = null;
195:                    Class[] paramTypes = m.getParameterTypes();
196:
197:                    try {
198:                        spec = C.getMethod(m.getName() + SPEC_STR, paramTypes);
199:                    } catch (Exception e) {
200:                        continue;
201:                    }
202:                    ;
203:
204:                    map.put(m, spec);
205:                }
206:                ;
207:
208:                return map;
209:            }
210:
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.