Source Code Cross Referenced for AllClassesWithGenericTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » jdwp » VirtualMachine » 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 » Apache Harmony Java SE » org package » org.apache.harmony.jpda.tests.jdwp.VirtualMachine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         *  See the License for the specific language governing permissions and
016:         *  limitations under the License.
017:         */
018:
019:        /**
020:         * @author Vitaly A. Provodin
021:         * @version $Revision: 1.8 $
022:         */
023:
024:        /**
025:         * Created on 10.02.2005
026:         */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
027:
028:        import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
031:        import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032:        import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
033:        import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
034:
035:        /**
036:         * JDWP Unit test for VirtualMachine.AllClassesWithGeneric command.
037:         */
038:        public class AllClassesWithGenericTest extends JDWPSyncTestCase {
039:
040:            protected String getDebuggeeClassName() {
041:                return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
042:            }
043:
044:            /**
045:             * This testcase exercises VirtualMachine.AllClassesWithGeneric command.
046:             * <BR>At first the test starts HelloWorld debuggee.
047:             * <BR> Then the test performs VirtualMachine.AllClassesWithGeneric 
048:             * command and checks that:
049:             * <BR>&nbsp;&nbsp; - number of reference types returned by command has
050:             *                    non-zero value;
051:             * <BR>&nbsp;&nbsp; - there are no classes with the 'ARRAY' or
052:             *                    'PRIMITIVE' bits in the status flag;
053:             */
054:            public void testAllClassesWithGeneric002() {
055:                logWriter.println("==> testAllClassesWithGeneric002: START...");
056:
057:                synchronizer
058:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
059:
060:                logWriter
061:                        .println("==> Send VirtualMachine::AllClassesWithGeneric command...");
062:                CommandPacket packet = new CommandPacket(
063:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
064:                        JDWPCommands.VirtualMachineCommandSet.AllClassesWithGenericCommand);
065:                ReplyPacket reply = debuggeeWrapper.vmMirror
066:                        .performCommand(packet);
067:                checkReplyPacket(reply,
068:                        "VirtualMachine::AllClassesWithGeneric command");
069:
070:                long typeID;
071:                String signature, genericSignature;
072:                int status;
073:
074:                int classes = reply.getNextValueAsInt();
075:                assertTrue(classes > 0);
076:
077:                int count = 0;
078:                for (int i = 0; i < classes; i++) {
079:
080:                    reply.getNextValueAsByte();
081:                    typeID = reply.getNextValueAsReferenceTypeID();
082:                    signature = reply.getNextValueAsString();
083:                    genericSignature = reply.getNextValueAsString();
084:                    status = reply.getNextValueAsInt();
085:
086:                    if ((status & JDWPConstants.ClassStatus.ARRAY) != 0) {
087:                        logWriter
088:                                .println("## FAILURE: Unexpected status is returned:");
089:                        logWriter.println("##          ReferenceTypeId = "
090:                                + typeID);
091:                        logWriter.println("##          Class signature: "
092:                                + signature);
093:                        logWriter
094:                                .println("##          Class generic signature: "
095:                                        + genericSignature);
096:                        logWriter.println("##          Class status = 0x"
097:                                + Integer.toHexString(status) + "("
098:                                + JDWPConstants.ClassStatus.getName(status)
099:                                + ")");
100:                        logWriter
101:                                .println("##          Status \"0x"
102:                                        + Integer
103:                                                .toHexString(JDWPConstants.ClassStatus.ARRAY)
104:                                        + "("
105:                                        + JDWPConstants.ClassStatus
106:                                                .getName(JDWPConstants.ClassStatus.ARRAY)
107:                                        + ")\" must NOT be returned!");
108:                        count++;
109:                    }
110:                    if ((status & JDWPConstants.ClassStatus.PRIMITIVE) != 0) {
111:                        logWriter
112:                                .println("## FAILURE: Unexpected status is returned:");
113:                        logWriter.println("##          ReferenceTypeId = "
114:                                + typeID);
115:                        logWriter.println("##          Class signature: "
116:                                + signature);
117:                        logWriter
118:                                .println("##          Class generic signature: "
119:                                        + genericSignature);
120:                        logWriter.println("##          Class status = 0x"
121:                                + Integer.toHexString(status) + "("
122:                                + JDWPConstants.ClassStatus.getName(status)
123:                                + ")");
124:                        logWriter
125:                                .println("##          Status \"0x"
126:                                        + Integer
127:                                                .toHexString(JDWPConstants.ClassStatus.PRIMITIVE)
128:                                        + "("
129:                                        + JDWPConstants.ClassStatus
130:                                                .getName(JDWPConstants.ClassStatus.PRIMITIVE)
131:                                        + ")\" must NOT be returned!");
132:                        count++;
133:                    }
134:                }
135:                assertEquals("count must be 0", 0, count);
136:                synchronizer
137:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
138:                logWriter.println("==> testAllClassesWithGeneric002: OK.");
139:            }
140:
141:            /**
142:             * This testcase exercises VirtualMachine.AllClassesWithGeneric command.
143:             * <BR>At first the test starts HelloWorld debuggee.
144:             * <BR> Then the test performs VirtualMachine.AllClassesWithGeneric
145:             * command and checks that:
146:             * <BR>&nbsp;&nbsp; - number of reference types returned by command has
147:             * non-zero value;
148:             * <BR>&nbsp;&nbsp; - refTypeTag takes one of the TypeTag constants:
149:             *                    'CLASS', 'INTERFACE', 'ARRAY';
150:             * <BR>&nbsp;&nbsp; - length of the signature string is not zero and starts with 'L' or
151:             *                    '[' symbols;
152:             * <BR>&nbsp;&nbsp; - signature of at least one class contains the "HelloWorld" string;
153:             * <BR>&nbsp;&nbsp; - All data were read from reply packet;
154:             */
155:            public void testAllClassesWithGeneric001() {
156:
157:                logWriter.println("==> testAllClassesWithGeneric001: START...");
158:                synchronizer
159:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
160:
161:                logWriter
162:                        .println("==> Send VirtualMachine::AllClassesWithGeneric command...");
163:                CommandPacket packet = new CommandPacket(
164:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
165:                        JDWPCommands.VirtualMachineCommandSet.AllClassesWithGenericCommand);
166:                ReplyPacket reply = debuggeeWrapper.vmMirror
167:                        .performCommand(packet);
168:                checkReplyPacket(reply,
169:                        "VirtualMachine::AllClassesWithGeneric command");
170:
171:                byte refTypeTag;
172:                String refTypeTagName;
173:                long typeID;
174:                String signature, genericSignature;
175:                int status;
176:                String msgLine;
177:                boolean flagForHelloWorld = false;
178:
179:                int classes = reply.getNextValueAsInt();
180:                logWriter.println("==> Number of reference types = " + classes);
181:                assertTrue(
182:                        "VirtualMachine::AllClassesWithGeneric command returned invalid number of classes: "
183:                                + classes, classes > 0);
184:
185:                int printBound_1 = classes;
186:                int printBound_2 = 0;
187:                if (classes > 50) {
188:                    printBound_1 = 5;
189:                    printBound_2 = classes - 5;
190:                }
191:                for (int i = 0; i < classes; i++) {
192:
193:                    boolean infoIsPrinted = false;
194:                    refTypeTag = reply.getNextValueAsByte();
195:                    try {
196:                        refTypeTagName = JDWPConstants.TypeTag
197:                                .getName(refTypeTag);
198:                    } catch (Throwable thrown) {
199:                        refTypeTagName = "UnknownTagName";
200:                    }
201:                    msgLine = "\n" + i + ". " + refTypeTagName;
202:                    typeID = reply.getNextValueAsReferenceTypeID();
203:                    signature = reply.getNextValueAsString();
204:                    msgLine = msgLine + ": " + signature;
205:                    genericSignature = reply.getNextValueAsString();
206:                    status = reply.getNextValueAsInt();
207:                    msgLine = msgLine + " "
208:                            + JDWPConstants.ClassStatus.getName(status);
209:                    if ((i < printBound_1) || (i >= printBound_2)) {
210:                        logWriter.println(msgLine);
211:                        logWriter.println("\treferenceTypeID = " + typeID);
212:                        logWriter.println("\trefTypeTag = " + refTypeTagName
213:                                + "(" + refTypeTag + ")");
214:                        logWriter.println("\tsignature = " + signature);
215:                        logWriter.println("\tgenericSignature = "
216:                                + genericSignature);
217:                        if (i == (printBound_1 - 1)) {
218:                            logWriter.println("...\n...\n...");
219:                        }
220:                        infoIsPrinted = true;
221:                    }
222:
223:                    try {
224:                        assertTrue(refTypeTag == JDWPConstants.TypeTag.ARRAY
225:                                || refTypeTag == JDWPConstants.TypeTag.CLASS
226:                                || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
227:
228:                        assertTrue(signature.length() > 0);
229:                        assertTrue(signature.toCharArray()[0] == 'L'
230:                                || signature.toCharArray()[0] == '[');
231:                    } catch (Throwable thrown) {
232:                        // some assert is cought
233:                        if (!infoIsPrinted) {
234:                            logWriter.println(msgLine);
235:                            logWriter.println("\treferenceTypeID = " + typeID);
236:                            logWriter.println("\trefTypeTag = "
237:                                    + refTypeTagName + "(" + refTypeTag + ")");
238:                            logWriter.println("\tsignature = " + signature);
239:                            logWriter.println("\tgenericSignature = "
240:                                    + genericSignature);
241:                        }
242:                        logWriter
243:                                .println("## FAILURE is found out for this referenceType!\n");
244:                        assertTrue(
245:                                "Unexpected refTypeTag",
246:                                refTypeTag == JDWPConstants.TypeTag.ARRAY
247:                                        || refTypeTag == JDWPConstants.TypeTag.CLASS
248:                                        || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
249:
250:                        assertTrue("Invalid signature", signature.length() > 0);
251:                        assertTrue("Invalid signature",
252:                                signature.toCharArray()[0] == 'L'
253:                                        || signature.toCharArray()[0] == '[');
254:                    }
255:                    if (signature.indexOf("HelloWorld") != -1)
256:                        flagForHelloWorld = true;
257:                }
258:
259:                assertAllDataRead(reply);
260:                assertTrue(
261:                        "HelloWorld has not been found in signatures of returned reference types",
262:                        flagForHelloWorld);
263:
264:                synchronizer
265:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
266:                logWriter.println("==> testAllClassesWithGeneric001: OK.");
267:            }
268:
269:            public static void main(String[] args) {
270:                junit.textui.TestRunner.run(AllClassesWithGenericTest.class);
271:            }
272:        }
w_ww__._j___a___v___a_2_s.c_o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.