Source Code Cross Referenced for ReferenceTypeTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » jdwp » ObjectReference » 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.ObjectReference 
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 Anatoly F. Bondarenko
021:         * @version $Revision: 1.6 $
022:         */
023:
024:        /**
025:         * Created on 25.02.2005
026:         */package org.apache.harmony.jpda.tests.jdwp.ObjectReference;
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.framework.jdwp.Value;
033:        import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
034:        import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036:        /**
037:         * JDWP Unit test for ObjectReference.ReferenceType command.
038:         */
039:        public class ReferenceTypeTest extends JDWPSyncTestCase {
040:
041:            static final int testStatusPassed = 0;
042:            static final int testStatusFailed = -1;
043:            static final String this CommandName = "ObjectReference.ReferenceType command";
044:            static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferenceTypeDebuggee;";
045:
046:            protected String getDebuggeeClassName() {
047:                return "org.apache.harmony.jpda.tests.jdwp.ObjectReference.ReferenceTypeDebuggee";
048:            }
049:
050:            /**
051:             * This test exercises ObjectReference.ReferenceType command.
052:             * <BR>The test starts ReferenceTypeDebuggee class, gets objectIDs
053:             * as values of some static fields of this class and then for each objectID
054:             * executes ObjectReference.ReferenceType command and checks
055:             * that command returns expected refTypeTags and returned Reference Types have
056:             * expected signatures.
057:             */
058:            public void testReferenceType001() {
059:                String this TestName = "testReferenceType001";
060:                logWriter.println("==> " + this TestName + " for "
061:                        + this CommandName + ": START...");
062:                int testStatus = testStatusPassed;
063:                String failMessage = "";
064:                synchronizer
065:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
066:
067:                CommandPacket classesBySignatureCommand = new CommandPacket(
068:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
069:                        JDWPCommands.VirtualMachineCommandSet.ClassesBySignatureCommand);
070:                classesBySignatureCommand
071:                        .setNextValueAsString(debuggeeSignature);
072:
073:                ReplyPacket classesBySignatureReply = debuggeeWrapper.vmMirror
074:                        .performCommand(classesBySignatureCommand);
075:                classesBySignatureCommand = null;
076:
077:                checkReplyPacket(classesBySignatureReply,
078:                        "VirtualMachine::ClassesBySignature command");
079:
080:                classesBySignatureReply.getNextValueAsInt();
081:                // Number of returned reference types - is NOt used here
082:
083:                classesBySignatureReply.getNextValueAsByte();
084:                // refTypeTag of class - is NOt used here
085:
086:                long refTypeID = classesBySignatureReply
087:                        .getNextValueAsReferenceTypeID();
088:                classesBySignatureReply = null;
089:
090:                logWriter.println("=> Debuggee class = "
091:                        + getDebuggeeClassName());
092:                logWriter.println("=> referenceTypeID for Debuggee class = "
093:                        + refTypeID);
094:
095:                String neededFieldNames[] = { "class_ReferenceType001Object",
096:                        "referenceTypeDebuggeeArray", "stringArrayField",
097:                        "stringField", };
098:
099:                long neededFieldIDs[] = checkFields(refTypeID, neededFieldNames);
100:                int neededFieldsNumber = neededFieldNames.length;
101:
102:                logWriter
103:                        .println("=> Send ReferenceType::GetValues command and and get ObjectIDs to check...");
104:                CommandPacket getValuesCommand = new CommandPacket(
105:                        JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
106:                        JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
107:                getValuesCommand.setNextValueAsReferenceTypeID(refTypeID);
108:                getValuesCommand.setNextValueAsInt(neededFieldsNumber);
109:                for (int k = 0; k < neededFieldsNumber; k++) {
110:                    getValuesCommand.setNextValueAsFieldID(neededFieldIDs[k]);
111:                }
112:
113:                ReplyPacket getValuesReply = debuggeeWrapper.vmMirror
114:                        .performCommand(getValuesCommand);
115:                getValuesCommand = null;
116:                checkReplyPacket(getValuesReply,
117:                        "ReferenceType::GetValues command");
118:
119:                int returnedValuesNumber = getValuesReply.getNextValueAsInt();
120:                logWriter.println("=> Returned values number = "
121:                        + returnedValuesNumber);
122:                if (returnedValuesNumber != neededFieldsNumber) {
123:                    logWriter
124:                            .println("\n## FAILURE: ReferenceType::GetValues command returned unexpected number of values:");
125:                    logWriter.println("## Expected number = "
126:                            + neededFieldsNumber);
127:                    logWriter.println("## Returned number = "
128:                            + returnedValuesNumber);
129:                    logWriter.println("==> " + this TestName + " for "
130:                            + this CommandName + ": FINISH");
131:                    assertTrue(false);
132:                }
133:                logWriter.println("=> Check for returned objectIDs...");
134:                byte expectedFieldTags[] = { JDWPConstants.Tag.OBJECT_TAG,
135:                        JDWPConstants.Tag.ARRAY_TAG,
136:                        JDWPConstants.Tag.ARRAY_TAG,
137:                        JDWPConstants.Tag.STRING_TAG, };
138:                String expectedSignatures[] = {
139:                        "Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/Class_ReferenceType001;",
140:                        "[Lorg/apache/harmony/jpda/tests/jdwp/ObjectReference/ReferenceTypeDebuggee;",
141:                        "[Ljava/lang/String;", "Ljava/lang/String;", };
142:                byte expectedRefTypeTags[] = { JDWPConstants.TypeTag.CLASS,
143:                        JDWPConstants.TypeTag.ARRAY,
144:                        JDWPConstants.TypeTag.ARRAY,
145:                        JDWPConstants.TypeTag.CLASS, };
146:                ReplyPacket checkedReply = null;
147:                for (int k = 0; k < neededFieldsNumber; k++) {
148:                    Value fieldValue = getValuesReply.getNextValueAsValue();
149:                    byte fieldTag = fieldValue.getTag();
150:                    logWriter.println("\n=> Returned value for field: "
151:                            + neededFieldNames[k] + ":");
152:                    logWriter.println("=> Value tag = " + fieldTag + "("
153:                            + JDWPConstants.Tag.getName(fieldTag) + ")");
154:                    if (fieldTag != expectedFieldTags[k]) {
155:                        logWriter
156:                                .println("\n## FAILURE: ReferenceType::GetValues command returned unexpected value tag ");
157:                        logWriter.println("## Expected tag = "
158:                                + expectedFieldTags[k]);
159:                        assertTrue(false);
160:                    }
161:                    long objectIdValue = fieldValue.getLongValue();
162:                    logWriter.println("=> objectId = " + objectIdValue);
163:                    logWriter.println("=> CHECK: send " + this CommandName
164:                            + " for this objectID and check reply...");
165:                    CommandPacket checkedCommand = new CommandPacket(
166:                            JDWPCommands.ObjectReferenceCommandSet.CommandSetID,
167:                            JDWPCommands.ObjectReferenceCommandSet.ReferenceTypeCommand);
168:                    checkedCommand.setNextValueAsObjectID(objectIdValue);
169:
170:                    checkedReply = debuggeeWrapper.vmMirror
171:                            .performCommand(checkedCommand);
172:                    checkedCommand = null;
173:                    checkReplyPacket(checkedReply, this CommandName);
174:
175:                    byte refTypeTag = checkedReply.getNextValueAsByte();
176:                    long objectRefTypeID = checkedReply
177:                            .getNextValueAsReferenceTypeID();
178:                    logWriter.println("=> Returned refTypeTag = " + refTypeTag
179:                            + "(" + JDWPConstants.TypeTag.getName(refTypeTag)
180:                            + ")");
181:                    if (refTypeTag != expectedRefTypeTags[k]) {
182:                        logWriter.println("\n## FAILURE: " + this CommandName
183:                                + " returned unexpected refTypeTag:");
184:                        logWriter.println("## Expected refTypeTag = "
185:                                + expectedRefTypeTags[k]
186:                                + "("
187:                                + JDWPConstants.TypeTag
188:                                        .getName(expectedRefTypeTags[k]) + ")");
189:                        testStatus = testStatusFailed;
190:                        failMessage = failMessage
191:                                + this CommandName
192:                                + " returned unexpected refTypeTag: "
193:                                + refTypeTag
194:                                + "("
195:                                + JDWPConstants.TypeTag.getName(refTypeTag)
196:                                + ")"
197:                                + ", Expected: "
198:                                + expectedRefTypeTags[k]
199:                                + "("
200:                                + JDWPConstants.TypeTag
201:                                        .getName(expectedRefTypeTags[k])
202:                                + ")\n";
203:                    }
204:                    logWriter.println("=> ReferenceTypeID for this objectID = "
205:                            + objectRefTypeID);
206:                    logWriter
207:                            .println("=> Get signature for returned ReferenceTypeID...");
208:                    CommandPacket signatureCommand = new CommandPacket(
209:                            JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
210:                            JDWPCommands.ReferenceTypeCommandSet.SignatureCommand);
211:                    signatureCommand
212:                            .setNextValueAsReferenceTypeID(objectRefTypeID);
213:
214:                    ReplyPacket signatureReply = debuggeeWrapper.vmMirror
215:                            .performCommand(signatureCommand);
216:                    signatureCommand = null;
217:                    checkReplyPacket(signatureReply,
218:                            "ReferenceType::Signature command");
219:
220:                    String returnedSignature = signatureReply
221:                            .getNextValueAsString();
222:                    logWriter.println("=> Returned Signature = "
223:                            + returnedSignature);
224:
225:                    if (!expectedSignatures[k].equals(returnedSignature)) {
226:                        logWriter
227:                                .println("\n## FAILURE: Unexpected signature is returned:");
228:                        logWriter.println("## Expected signature = "
229:                                + expectedSignatures[k]);
230:                        testStatus = testStatusFailed;
231:                        failMessage = failMessage
232:                                + "Unexpected signature is returned: "
233:                                + returnedSignature + ", Expected: "
234:                                + expectedSignatures[k] + "\n";
235:                    }
236:                }
237:
238:                if (testStatus == testStatusPassed) {
239:                    logWriter
240:                            .println("\n=> CHECK PASSED: All expected reference types are got and have expected attributes");
241:                }
242:
243:                assertAllDataRead(checkedReply);
244:
245:                synchronizer
246:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
247:                logWriter.println("==> " + this TestName + " for "
248:                        + this CommandName + ": FINISH");
249:                if (failMessage.length() > 0) {
250:                    fail(failMessage);
251:                }
252:            }
253:
254:            public static void main(String[] args) {
255:                junit.textui.TestRunner.run(ReferenceTypeTest.class);
256:            }
257:        }
w__ww_.j__a_v_a___2s___._co__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.