1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */
18 
19 /**
20  * @author Aleksander V. Budniy
21  */
22 
23 /**
24  * Created on 8.7.2005
25  */
26 package org.apache.harmony.jpda.tests.jdwp.MultiSession;
27 
28 import org.apache.harmony.jpda.tests.framework.TestOptions;
29 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
30 import org.apache.harmony.jpda.tests.jdwp.share.JDWPUnitDebuggeeWrapper;
31 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
32 
33 
34 /**
35  * JDWP Unit test for verifying invalidating of classObjectID after re-connection.
36  */
37 public class ClassObjectIDTest extends JDWPSyncTestCase {
38 
39     private String DEBUGGEE_SIGNATURE = "Lorg/apache/harmony/jpda/tests/jdwp/MultiSession/MultiSessionDebuggee;";
40 
41     //private String METHOD_NAME = "printWord";
42 
getDebuggeeClassName()43     protected String getDebuggeeClassName() {
44         return "org.apache.harmony.jpda.tests.jdwp.MultiSession.MultiSessionDebuggee";
45     }
46 
47     /**
48      * This testcase verifies invalidating of classObjectID after re-connection.
49      * <BR>It runs multiSessionDebuggee, gets classID and classObjectID, re-connects
50      * and tries to get refTypeID with ObjectReference.ReferenceType command
51      * using old classObjectID.
52      * <BR>It is expected that INVALID_OBJECT error is returned by command.
53      */
testClassObjectID001()54     public void testClassObjectID001() {
55 
56         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
57 
58         long classID = debuggeeWrapper.vmMirror.getClassID(DEBUGGEE_SIGNATURE);
59         long classObjectID = debuggeeWrapper.vmMirror.getClassObjectId(classID);
60 
61         logWriter.println("");
62         logWriter.println("=> CLOSE CONNECTION..");
63         closeConnection();
64         logWriter.println("=> CONNECTION CLOSED");
65 
66         logWriter.println("");
67         logWriter.println("=> OPEN NEW CONNECTION..");
68         openConnection();
69         logWriter.println("=> CONNECTION OPENED");
70 
71         logWriter.println("=> Trying to get classID using old classObjectID");
72         boolean success = false;
73         try {
74             //long requestID =
75                 debuggeeWrapper.vmMirror.getReferenceType(classObjectID);
76         } catch (Exception e) {
77             logWriter.println("=> TEST PASSED, because INVALID_OBJECT exception was occurred");
78             success = true;
79         }
80 
81         if (!success) {
82             logWriter.println("=> TEST FAILED, because INVALID_OBJECT exception was not occurred");
83             fail("INVALID_OBJECT exception was not occurred");
84         }
85 
86         //resuming debuggee
87         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
88         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
89         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
90     }
91 
beforeDebuggeeStart(JDWPUnitDebuggeeWrapper debuggeeWrapper)92     protected void beforeDebuggeeStart(JDWPUnitDebuggeeWrapper debuggeeWrapper) {
93         settings.setAttachConnectorKind();
94         if (settings.getTransportAddress() == null) {
95             settings.setTransportAddress(TestOptions.DEFAULT_ATTACHING_ADDRESS);
96         }
97         logWriter.println("ATTACH connector kind");
98         super.beforeDebuggeeStart(debuggeeWrapper);
99     }
100 }
101