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


001:        package org.hansel.probes;
002:
003:        import org.hansel.Probe;
004:        import org.hansel.ProbeData;
005:        import org.objectweb.asm.Label;
006:        import org.objectweb.asm.MethodVisitor;
007:        import org.objectweb.asm.Opcodes;
008:
009:        public class SelectProbe extends Probe {
010:            private boolean[] covered;
011:            private int[] keys;
012:            private Label[] labels;
013:            private boolean[] isDefault;
014:            private boolean defaultCovered;
015:
016:            private boolean isHit;
017:
018:            public SelectProbe(ProbeData pd, int min, int max, Label dflt,
019:                    Label labels[]) {
020:                super (pd);
021:
022:                this .labels = labels;
023:                this .keys = new int[max - min + 1];
024:                for (int i = 0; i < max - min + 1; i++) {
025:                    keys[i] = min + i;
026:                }
027:
028:                this .covered = new boolean[labels.length];
029:
030:                // Some targets might point to default target.
031:                // These targets have to be treated just like the defaultTarget
032:                isDefault = new boolean[labels.length];
033:                for (int i = 0; i < isDefault.length; i++) {
034:                    isDefault[i] = (labels[i] == dflt);
035:                    covered[i] = isDefault[i];
036:                }
037:            }
038:
039:            public SelectProbe(ProbeData pd, Label dflt, int[] keys,
040:                    Label[] labels) {
041:                super (pd);
042:
043:                this .labels = labels;
044:                this .keys = keys;
045:                this .covered = new boolean[labels.length];
046:
047:                // Some targets might point to default target.
048:                // These targets have to be treated just like the defaultTarget
049:                isDefault = new boolean[labels.length];
050:                for (int i = 0; i < isDefault.length; i++) {
051:                    isDefault[i] = (labels[i] == dflt);
052:                    covered[i] = isDefault[i];
053:                }
054:            }
055:
056:            /** 
057:             * Return the filure message for this probe.
058:             * @return Failure message.
059:             */
060:            public String getFailureMessage() {
061:                int count = 0;
062:                String cases = "";
063:
064:                for (int i = 0; i < covered.length; i++) {
065:                    if (!covered[i]) {
066:                        cases += "'" + keys[i] + "', ";
067:                        count++;
068:                    }
069:                }
070:
071:                if (!defaultCovered) {
072:                    count++;
073:                    cases += "'default', ";
074:                }
075:
076:                cases = cases.substring(0, cases.length() - 2);
077:
078:                int index = cases.lastIndexOf(',');
079:                if (index > -1) {
080:                    cases = cases.substring(0, index) + " and "
081:                            + cases.substring(index + 2);
082:                }
083:
084:                if (count > 1) {
085:                    return "Switch-cases " + cases + " have not been covered.";
086:                } else {
087:                    return "Switch-case " + cases + " has not been covered.";
088:                }
089:            }
090:
091:            /**
092:             * Return wether this probe failed to be covered.
093:             * A probe for a conditional branch fails, if the branch is only taken,
094:             * or only omitted. If both cases are encountered, the probe is fully
095:             * covered. If the probe is not executed at all, this method still returns
096:             * false, because in that case, another probe has to fail (otherwise this
097:             * probe had been reached). Because the other failure is more important,
098:             * the result of this probe is left out in this case.
099:             * @return true If covering this probe failed.
100:             */
101:            public boolean displayFailure() {
102:                if (!isHit) {
103:                    return false;
104:                }
105:
106:                return coverageFailure();
107:            }
108:
109:            public boolean coverageFailure() {
110:                if (!defaultCovered) {
111:                    return true;
112:                }
113:
114:                for (int i = 0; i < covered.length; i++) {
115:                    if (!covered[i]) {
116:                        return true;
117:                    }
118:                }
119:
120:                return false;
121:            }
122:
123:            private final int getIndex(int value) {
124:                for (int i = 0; i < keys.length; i++) {
125:                    if (keys[i] == value) {
126:                        return i;
127:                    } else if (keys[i] > value) {
128:                        return -1;
129:                    }
130:
131:                }
132:
133:                return -1;
134:            }
135:
136:            public void hit(int value) {
137:                isHit = true;
138:
139:                int index = getIndex(value);
140:
141:                if ((index == -1) || isDefault[index]) {
142:                    defaultCovered = true;
143:                } else {
144:                    // Cover all keys that point to the same label.
145:                    Label label = labels[index];
146:                    for (int i = 0; i < labels.length; i++) {
147:                        if (labels[i] == label) {
148:                            covered[i] = true;
149:                        }
150:                    }
151:                }
152:            }
153:
154:            public void insertProbeCode(MethodVisitor cv) {
155:                cv.visitInsn(Opcodes.DUP);
156:                cv.visitLdcInsn(new Integer(getID()));
157:                cv.visitMethodInsn(Opcodes.INVOKESTATIC, HIT_CLASS,
158:                        "hitSelect", "(II)V");
159:            }
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.