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 Vitaly A. Provodin
21  */
22 
23 /**
24  * Created on 10.02.2005
25  */
26 package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
27 
28 import java.io.File;
29 
30 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
31 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
32 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
33 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
34 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
35 
36 
37 
38 /**
39  * JDWP Unit test for VirtualMachine.ClassPaths command.
40  */
41 public class ClassPathsTest extends JDWPSyncTestCase {
42 
getDebuggeeClassName()43     protected String getDebuggeeClassName() {
44         return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
45     }
46 
47     /**
48      * This testcase exercises VirtualMachine.ClassPaths command.
49      * <BR>At first the test starts HelloWorld debuggee.
50      * <BR> Then the test performs VirtualMachine.ClassPaths command and checks that:
51      * <BR>&nbsp;&nbsp; - the 'baseDir' directory exists;
52      * <BR>&nbsp;&nbsp; - amount of bootclasspaths is greater than 0;
53      * <BR>&nbsp;&nbsp; - length of strings representing classpaths, bootclasspaths is not zero;
54      * <BR>&nbsp;&nbsp; - there are no extra data in the reply packet;
55      */
testClassPaths001()56     public void testClassPaths001() {
57         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
58 
59         CommandPacket packet = new CommandPacket(
60                 JDWPCommands.VirtualMachineCommandSet.CommandSetID,
61                 JDWPCommands.VirtualMachineCommandSet.ClassPathsCommand);
62         logWriter.println("\trequest class paths");
63 
64         ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
65         checkReplyPacket(reply, "VirtualMachine::ClassPaths command");
66 
67         String baseDir = reply.getNextValueAsString();
68         logWriter.println("baseDir = " + baseDir);
69         assertTrue("baseDir = " + baseDir + " doesn't exists",
70                 new File(baseDir).exists());
71 
72         int classpaths = reply.getNextValueAsInt();
73         logWriter.println("classpaths = " + classpaths);
74         for (int i = 0; i < classpaths; i++) {
75             String path = reply.getNextValueAsString();
76             logWriter.println("\t" + path);
77             if(!(path.length() > 0)){
78                 logWriter.println("Path length = "+path.length());
79             }
80         }
81 
82         int bootclasspaths = reply.getNextValueAsInt();
83         logWriter.println("bootclasspaths = " + bootclasspaths);
84         assertTrue(bootclasspaths > 0);
85         for (int i = 0; i < bootclasspaths; i++) {
86             String path = reply.getNextValueAsString();
87             logWriter.println("\t" + path);
88             assertTrue("Invalid path", path.length() > 0);
89         }
90 
91         assertAllDataRead(reply);
92         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
93     }
94 }
95