Source Code Cross Referenced for SetValuesTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » jdwp » StackFrame » 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.StackFrame 
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 Aleksander V. Budniy
021:         * @version $Revision: 1.4 $
022:
023:         /**
024:         * Created on 15.08.2005
025:         */package org.apache.harmony.jpda.tests.jdwp.StackFrame;
026:
027:        import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
028:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
029:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
030:        import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
031:        import org.apache.harmony.jpda.tests.framework.jdwp.Value;
032:        import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
033:
034:        /**
035:         * JDWP Unit test for StackFrame.SetValues command.
036:         */
037:        public class SetValuesTest extends JDWPStackFrameTestCase {
038:
039:            String testedMethodName = "nestledMethod3";
040:            String testedThreadName = "";
041:
042:            VarInfo[] varInfos;
043:
044:            String varSignature[] = {
045:                    "Lorg/apache/harmony/jpda/tests/jdwp/StackFrame/StackTraceDebuggee;",
046:                    "Z", "I", "Ljava/lang/String;" };
047:
048:            String varNames[] = { "this", "boolLocalVariable",
049:                    "intLocalVariable", "strLocalVariable" };
050:
051:            byte varTags[] = { JDWPConstants.Tag.OBJECT_TAG,
052:                    JDWPConstants.Tag.BOOLEAN_TAG, JDWPConstants.Tag.INT_TAG,
053:                    JDWPConstants.Tag.STRING_TAG };
054:
055:            private String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/StackFrame/StackTraceDebuggee;";
056:
057:            /**
058:             * This testcase exercises StackFrame.SetValues command.
059:             * <BR>The test starts StackTraceDebuggee, sets breakpoint at the beginning of
060:             * the tested method - 'nestledMethod3' and stops at the breakpoint.
061:             * <BR> Then the test performs Method.VariableTable command and checks
062:             * returned VariableTable.
063:             * <BR> Next, the test performs StackFrame.SetValues command and checks
064:             * result of this command with help of StackFrame.GetValues command - 
065:             * returned values of variables should be equal to values which were set.
066:             *  
067:             */
068:            public void testSetValues001() {
069:                logWriter.println("==> testSetValues001 started...");
070:                testedThreadName = synchronizer.receiveMessage();
071:                // release on run()
072:                synchronizer
073:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
074:
075:                // pass nestledMethod1()
076:                synchronizer
077:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
078:                synchronizer
079:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
080:
081:                // enter nestledMethod2()
082:                synchronizer
083:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
084:
085:                //release debuggee
086:                synchronizer
087:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
088:                synchronizer
089:                        .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
090:
091:                //sets and checks local variables of tested method
092:                examineGetValues();
093:
094:                // signal to finish debuggee
095:                synchronizer
096:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
097:                logWriter.println("==> testSetValues001 - OK.");
098:
099:            }
100:
101:            private void examineGetValues() {
102:
103:                long refTypeID = getClassIDBySignature(debuggeeSignature);
104:                logWriter.println("=> Debuggee class = "
105:                        + getDebuggeeClassName());
106:                logWriter.println("=> referenceTypeID for Debuggee class = "
107:                        + refTypeID);
108:                long threadID = debuggeeWrapper.vmMirror
109:                        .getThreadID(testedThreadName);
110:
111:                logWriter.println("=> testedThreadID = " + threadID);
112:                if (threadID == -1) {
113:                    printErrorAndFail("testedThread is not found!");
114:                }
115:
116:                // suspend thread
117:                jdwpSuspendThread(threadID);
118:
119:                //get number of frames
120:                int frameCount = jdwpGetFrameCount(threadID);
121:                logWriter.println("=> frames count = " + frameCount);
122:
123:                //get frames info
124:                FrameInfo[] frameIDs = jdwpGetFrames(threadID, 0, frameCount);
125:                if (frameIDs.length != frameCount) {
126:                    printErrorAndFail("Received number of frames = "
127:                            + frameIDs.length
128:                            + " differ from expected number = " + frameCount);
129:                }
130:
131:                //check and print methods info
132:                long methodID = 0;
133:                long frameID = 0;
134:                String methodName = "";
135:                boolean testedMethodChecked = false;
136:                for (int i = 0; i < frameCount; i++) {
137:                    logWriter.println("\n");
138:                    methodName = getMethodName(frameIDs[i].location.classID,
139:                            frameIDs[i].location.methodID);
140:                    logWriter.println("=> method name = " + methodName);
141:                    logWriter.println("=> methodID = "
142:                            + frameIDs[i].location.methodID);
143:                    logWriter.println("=> frameID = " + frameIDs[i].frameID);
144:                    logWriter.println("\n");
145:                    if (methodName.equals(testedMethodName)) {
146:                        methodID = frameIDs[i].location.methodID;
147:                        frameID = frameIDs[i].frameID;
148:                        methodName = getMethodName(
149:                                frameIDs[i].location.classID,
150:                                frameIDs[i].location.methodID);
151:                        testedMethodChecked = true;
152:                    }
153:                }
154:                if (testedMethodChecked) {
155:                    logWriter.println("=> Tested method is found");
156:                    logWriter.println("=> method name = " + testedMethodName);
157:                    logWriter.println("=> methodID = " + methodID);
158:                    logWriter.println("=> frameID = " + frameID);
159:
160:                } else {
161:                    printErrorAndFail("Tested method is not found");
162:                }
163:
164:                //getting Variable Table
165:                logWriter.println("");
166:                logWriter.println("=> Getting Variable Table...");
167:                varInfos = jdwpGetVariableTable(refTypeID, methodID);
168:                if (checkVarTable(varInfos)) {
169:                    logWriter.println("=> Variable table check passed.");
170:                } else {
171:                    printErrorAndFail("Variable table check failed.");
172:                }
173:
174:                //prepare and perform SetValues command
175:                logWriter.println("");
176:                logWriter.println("==> Send StackFrame::SetValues command...");
177:                CommandPacket packet = new CommandPacket(
178:                        JDWPCommands.StackFrameCommandSet.CommandSetID,
179:                        JDWPCommands.StackFrameCommandSet.SetValuesCommand);
180:                packet.setNextValueAsThreadID(threadID);
181:                packet.setNextValueAsLong(frameID);
182:
183:                packet.setNextValueAsInt(varTags.length - 2);
184:                packet.setNextValueAsInt(varInfos[1].getSlot());
185:                packet.setNextValueAsValue(new Value(false));
186:                packet.setNextValueAsInt(varInfos[2].getSlot());
187:                packet.setNextValueAsValue(new Value((int) 12345));
188:
189:                ReplyPacket reply = debuggeeWrapper.vmMirror
190:                        .performCommand(packet);
191:                checkReplyPacket(reply, "StackFrame::SetValues command");
192:
193:                //prepare and perform GetValues command
194:                logWriter.println("");
195:                logWriter.println("=> Send StackFrame::GetValues command...");
196:                packet = new CommandPacket(
197:                        JDWPCommands.StackFrameCommandSet.CommandSetID,
198:                        JDWPCommands.StackFrameCommandSet.GetValuesCommand);
199:                packet.setNextValueAsThreadID(threadID);
200:                packet.setNextValueAsFrameID(frameID);
201:
202:                logWriter.println("=> Thread: " + threadID);
203:                logWriter.println("=> Frame: " + frameID);
204:                packet.setNextValueAsInt(varTags.length);
205:                for (int i = 0; i < varTags.length; i++) {
206:                    logWriter.println("");
207:                    logWriter.println("=> For variable #" + i + ":");
208:                    packet.setNextValueAsInt(varInfos[i].getSlot());
209:                    logWriter.println("=> Slot = " + varInfos[i].getSlot());
210:                    packet.setNextValueAsByte(varTags[i]);
211:                    logWriter.println("=> Tag = "
212:                            + JDWPConstants.Tag.getName(varTags[i]));
213:                    logWriter.println("");
214:                }
215:
216:                //check reply for errors
217:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
218:                checkReplyPacket(reply, "StackFrame::GetValues command");
219:
220:                //check number of retrieved values
221:                int numberOfValues = reply.getNextValueAsInt();
222:                logWriter.println("=> Number of values = " + numberOfValues);
223:                if (numberOfValues != varTags.length) {
224:                    logWriter
225:                            .println("##FAILURE: unexpected number of values: "
226:                                    + numberOfValues + " instead of "
227:                                    + varTags.length);
228:                    assertTrue(false);
229:                }
230:
231:                boolean success = true;
232:                //print and check values of variables
233:                logWriter.println("=> Values of variables: ");
234:
235:                Value val = reply.getNextValueAsValue();
236:                if (val.getTag() == JDWPConstants.Tag.OBJECT_TAG) {
237:                    logWriter.println("=> Tag is correct");
238:                    logWriter.println("");
239:                } else {
240:                    logWriter.printError("Unexpected tag of variable: "
241:                            + JDWPConstants.Tag.getName(val.getTag())
242:                            + " instead of: CLASS_OBJECT_TAG");
243:                    logWriter.printError("");
244:                    success = false;
245:                }
246:
247:                val = reply.getNextValueAsValue();
248:                if (val.getTag() == JDWPConstants.Tag.BOOLEAN_TAG) {
249:                    logWriter.println("=>Tag is correct");
250:                    boolean boolValue = val.getBooleanValue();
251:                    if (!boolValue) {
252:                        logWriter.println("=> " + varInfos[1].getName() + " = "
253:                                + boolValue);
254:                        logWriter.println("");
255:                    } else {
256:                        logWriter
257:                                .printError("Unexpected value of boolean variable: "
258:                                        + boolValue + " instead of: false");
259:                        logWriter.printError("");
260:                        success = false;
261:                    }
262:                } else {
263:                    logWriter.printError("Unexpected tag of variable: "
264:                            + JDWPConstants.Tag.getName(val.getTag())
265:                            + " instead of: boolean");
266:                    logWriter.printError("");
267:                    success = false;
268:                }
269:
270:                val = reply.getNextValueAsValue();
271:                if (val.getTag() == JDWPConstants.Tag.INT_TAG) {
272:                    logWriter.println("=>Tag is correct");
273:                    int intValue = val.getIntValue();
274:                    if (intValue == 12345) {
275:                        logWriter.println("=> " + varInfos[2].getName() + " = "
276:                                + intValue);
277:                        logWriter.println("");
278:                    } else {
279:                        logWriter
280:                                .printError("Unexpected value of int variable: "
281:                                        + intValue + " instead of: 12345");
282:                        logWriter.printError("");
283:                        success = false;
284:                    }
285:                } else {
286:                    logWriter.printError("Unexpected tag of variable: "
287:                            + JDWPConstants.Tag.getName(val.getTag())
288:                            + " instead of: integer");
289:                    logWriter.printError("");
290:                    success = false;
291:                }
292:
293:                val = reply.getNextValueAsValue();
294:                if (val.getTag() == JDWPConstants.Tag.STRING_TAG) {
295:                    logWriter.println("=>Tag is correct");
296:                    long strLocalVariableID = val.getLongValue();
297:                    String strLocalVariable = getStringValue(strLocalVariableID);
298:                    if (strLocalVariable.equals("test string")) {
299:                        logWriter.println("=> " + varInfos[2].getName() + " = "
300:                                + strLocalVariable);
301:                        logWriter.println("");
302:                    } else {
303:                        logWriter
304:                                .printError("Unexpected value of string variable: "
305:                                        + strLocalVariable
306:                                        + " instead of: "
307:                                        + "test string");
308:                        logWriter.printError("");
309:                        success = false;
310:                    }
311:                } else {
312:                    logWriter.printError("Unexpected tag of variable: "
313:                            + JDWPConstants.Tag.getName(val.getTag())
314:                            + " instead of: string");
315:                    logWriter.printError("");
316:                    success = false;
317:                }
318:                assertTrue(logWriter.getErrorMessage(), success);
319:            }
320:
321:            //prints variables info, checks signatures
322:            boolean checkVarTable(VarInfo[] varInfos) {
323:                boolean success = true;
324:                logWriter.println("==> Number of variables = "
325:                        + varInfos.length);
326:                if (varInfos.length != varTags.length) {
327:
328:                    printErrorAndFail("Unexpected number of variables: "
329:                            + varInfos.length + " instead of " + varTags.length);
330:                }
331:                for (int i = 0; i < varInfos.length; i++) {
332:                    logWriter.println("");
333:                    logWriter.println("=> Name = " + varInfos[i].getName());
334:                    //## take codeIndex and length and check them
335:                    logWriter.println("=> Slot = " + varInfos[i].getSlot());
336:                    logWriter
337:                            .println("=> Sign = " + varInfos[i].getSignature());
338:                    if (!(varSignature[i].equals(varInfos[i].getSignature()))) {
339:                        logWriter
340:                                .printError("Unexpected signature of variable = "
341:                                        + varInfos[i].getName()
342:                                        + ", on slot = "
343:                                        + varInfos[i].getSlot()
344:                                        + ", with unexpected signature = "
345:                                        + varInfos[i].getSignature()
346:                                        + " instead of signature = "
347:                                        + varSignature[i]);
348:                        success = false;
349:                        ;
350:                    }
351:                    if (!(varNames[i].equals(varInfos[i].getName()))) {
352:                        logWriter.println("Unexpected name of variable  "
353:                                + varInfos[i].getName() + ", on slot = "
354:                                + varInfos[i].getSlot() + " instead of name = "
355:                                + varNames[i]);
356:                        success = false;
357:                        ;
358:                    }
359:
360:                    logWriter.println("");
361:                }
362:                return success;
363:            }
364:
365:            public static void main(String[] args) {
366:                junit.textui.TestRunner.run(SetValuesTest.class);
367:            }
368:
369:        }
ww__w_.j__a___v__a___2__s___.__c___om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.