Source Code Cross Referenced for AllClassesTest.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.7 $
022:         */
023:
024:        /**
025:         * Created on 03.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.AllClasses command.
037:         */
038:        public class AllClassesTest 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.AllClasses command.
046:             * <BR>At first the test starts HelloWorld debuggee.
047:             * <BR> Then the test performs VirtualMachine.AllClasses command and checks that:
048:             * <BR>&nbsp;&nbsp; - number of reference types returned by command has
049:             *                    non-zero value;
050:             * <BR>&nbsp;&nbsp; - there are no classes with the 'ARRAY' or
051:             *                    'PRIMITIVE' bits in the status flag;
052:             */
053:            public void testAllClasses002() {
054:                logWriter.println("==> testAllClasses002: START...");
055:
056:                synchronizer
057:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
058:
059:                logWriter
060:                        .println("==> Send VirtualMachine::AllClasses command...");
061:                CommandPacket packet = new CommandPacket(
062:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
063:                        JDWPCommands.VirtualMachineCommandSet.AllClassesCommand);
064:                ReplyPacket reply = debuggeeWrapper.vmMirror
065:                        .performCommand(packet);
066:                checkReplyPacket(reply, "VirtualMachine::AllClasses command");
067:
068:                long typeID;
069:                String signature;
070:                int status;
071:
072:                int classes = reply.getNextValueAsInt();
073:                assertTrue(classes > 0);
074:
075:                int count = 0;
076:                for (int i = 0; i < classes; i++) {
077:
078:                    reply.getNextValueAsByte();
079:                    typeID = reply.getNextValueAsReferenceTypeID();
080:                    signature = reply.getNextValueAsString();
081:                    status = reply.getNextValueAsInt();
082:
083:                    if ((status & JDWPConstants.ClassStatus.ARRAY) != 0) {
084:                        logWriter
085:                                .println("## FAILURE: Unexpected status is returned:");
086:                        logWriter.println("##          ReferenceTypeId = "
087:                                + typeID);
088:                        logWriter.println("##          Class signature: "
089:                                + signature);
090:                        logWriter.println("##          Class status = 0x"
091:                                + Integer.toHexString(status) + "("
092:                                + JDWPConstants.ClassStatus.getName(status)
093:                                + ")");
094:                        logWriter
095:                                .println("##          Status \"0x"
096:                                        + Integer
097:                                                .toHexString(JDWPConstants.ClassStatus.ARRAY)
098:                                        + "("
099:                                        + JDWPConstants.ClassStatus
100:                                                .getName(JDWPConstants.ClassStatus.ARRAY)
101:                                        + ")\" must NOT be returned!");
102:                        count++;
103:                    }
104:                    if ((status & JDWPConstants.ClassStatus.PRIMITIVE) != 0) {
105:                        logWriter
106:                                .println("## FAILURE: Unexpected status is returned:");
107:                        logWriter.println("##          ReferenceTypeId = "
108:                                + typeID);
109:                        logWriter.println("##          Class signature: "
110:                                + signature);
111:                        logWriter.println("##          Class status = 0x"
112:                                + Integer.toHexString(status) + "("
113:                                + JDWPConstants.ClassStatus.getName(status)
114:                                + ")");
115:                        logWriter
116:                                .println("##          Status \"0x"
117:                                        + Integer
118:                                                .toHexString(JDWPConstants.ClassStatus.PRIMITIVE)
119:                                        + "("
120:                                        + JDWPConstants.ClassStatus
121:                                                .getName(JDWPConstants.ClassStatus.PRIMITIVE)
122:                                        + ")\" must NOT be returned!");
123:                        count++;
124:                    }
125:                }
126:                assertEquals("count must be 0", 0, count);
127:                synchronizer
128:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
129:                logWriter.println("==> testAllClasses002: OK.");
130:            }
131:
132:            /**
133:             * This testcase exercises VirtualMachine.AllClasses command.
134:             * <BR>At first the test starts HelloWorld debuggee.
135:             * <BR> Then the test performs VirtualMachine.AllClasses command and checks that:
136:             * <BR>&nbsp;&nbsp; - number of reference types returned by command has
137:             * non-zero value;
138:             * <BR>&nbsp;&nbsp; - refTypeTag takes one of the TypeTag constants:
139:             *                    'CLASS', 'INTERFACE', 'ARRAY';
140:             * <BR>&nbsp;&nbsp; - length of the signature string is not zero and starts with 'L' or
141:             *                    '[' symbols;
142:             * <BR>&nbsp;&nbsp; - signature of at least one class contains the "HelloWorld" string;
143:             * <BR>&nbsp;&nbsp; - All data were read from reply packet;
144:             */
145:            public void testAllClasses001() {
146:                logWriter.println("==> testAllClasses001: START...");
147:
148:                synchronizer
149:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
150:
151:                logWriter
152:                        .println("==> Send VirtualMachine::AllClasses command...");
153:                CommandPacket packet = new CommandPacket(
154:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
155:                        JDWPCommands.VirtualMachineCommandSet.AllClassesCommand);
156:                ReplyPacket reply = debuggeeWrapper.vmMirror
157:                        .performCommand(packet);
158:                checkReplyPacket(reply, "VirtualMachine::AllClasses command");
159:
160:                byte refTypeTag;
161:                String refTypeTagName;
162:                long typeID;
163:                String signature;
164:                int status;
165:                String msgLine;
166:                boolean flagForHelloWorld = false;
167:
168:                int classes = reply.getNextValueAsInt();
169:                logWriter.println("==> Number of reference types = " + classes);
170:                assertTrue(classes > 0);
171:
172:                int printBound_1 = classes;
173:                int printBound_2 = 0;
174:                if (classes > 50) {
175:                    printBound_1 = 5;
176:                    printBound_2 = classes - 5;
177:                }
178:                for (int i = 0; i < classes; i++) {
179:
180:                    boolean infoIsPrinted = false;
181:                    refTypeTag = reply.getNextValueAsByte();
182:                    try {
183:                        refTypeTagName = JDWPConstants.TypeTag
184:                                .getName(refTypeTag);
185:                    } catch (Throwable thrown) {
186:                        refTypeTagName = "UnknownTagName";
187:                    }
188:                    msgLine = "\n" + i + ". " + refTypeTagName;
189:                    typeID = reply.getNextValueAsReferenceTypeID();
190:                    signature = reply.getNextValueAsString();
191:                    msgLine = msgLine + ": " + signature;
192:                    status = reply.getNextValueAsInt();
193:                    msgLine = msgLine + " "
194:                            + JDWPConstants.ClassStatus.getName(status);
195:                    if ((i < printBound_1) || (i >= printBound_2)) {
196:                        logWriter.println(msgLine);
197:                        logWriter.println("\treferenceTypeID = " + typeID);
198:                        logWriter.println("\trefTypeTag = " + refTypeTagName
199:                                + "(" + refTypeTag + ")");
200:                        logWriter.println("\tsignature = " + signature);
201:                        if (i == (printBound_1 - 1)) {
202:                            logWriter.println("...\n...\n...");
203:                        }
204:                        infoIsPrinted = true;
205:                    }
206:
207:                    try {
208:                        assertTrue(refTypeTag == JDWPConstants.TypeTag.ARRAY
209:                                || refTypeTag == JDWPConstants.TypeTag.CLASS
210:                                || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
211:
212:                        assertTrue(signature.length() > 0);
213:                        assertTrue(signature.toCharArray()[0] == 'L'
214:                                || signature.toCharArray()[0] == '[');
215:                    } catch (Throwable thrown) {
216:                        // some assert is cought
217:                        if (!infoIsPrinted) {
218:                            logWriter.println(msgLine);
219:                            logWriter.println("\treferenceTypeID = " + typeID);
220:                            logWriter.println("\trefTypeTag = "
221:                                    + refTypeTagName + "(" + refTypeTag + ")");
222:                            logWriter.println("\tsignature = " + signature);
223:                        }
224:                        logWriter
225:                                .println("## FAILURE is found out for this referenceType!\n");
226:                        assertTrue(refTypeTag == JDWPConstants.TypeTag.ARRAY
227:                                || refTypeTag == JDWPConstants.TypeTag.CLASS
228:                                || refTypeTag == JDWPConstants.TypeTag.INTERFACE);
229:
230:                        assertTrue(signature.length() > 0);
231:                        assertTrue(signature.toCharArray()[0] == 'L'
232:                                || signature.toCharArray()[0] == '[');
233:                    }
234:
235:                    if (signature.indexOf("HelloWorld") != -1)
236:                        flagForHelloWorld = true;
237:                }
238:                assertAllDataRead(reply);
239:                assertTrue(
240:                        "HelloWorld has not been found in signatures of returned reference types",
241:                        flagForHelloWorld);
242:
243:                synchronizer
244:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
245:                logWriter.println("==> testAllClasses001: OK.");
246:            }
247:
248:            public static void main(String[] args) {
249:                junit.textui.TestRunner.run(AllClassesTest.class);
250:            }
251:        }
ww_w___.___j___a__v___a__2s__.__c___om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.