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 Anton V. Karnachuk
21 */
22
23/**
24 * Created on 14.02.2005
25 */
26package org.apache.harmony.jpda.tests.jdwp.Method;
27
28import java.io.UnsupportedEncodingException;
29
30import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
31import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
32
33
34
35/**
36 * JDWP Unit test for Method.LineTable command.
37 */
38public class LineTableTest extends JDWPMethodTestCase {
39    /**
40     * This testcase exercises Method.LineTable command.
41     * <BR>It runs MethodDebuggee, receives methods of debuggee.
42     * For each received method sends Method.LineTable command
43     * and prints returned LineTable.
44     */
45    public void testLineTableTest001() throws UnsupportedEncodingException {
46        logWriter.println("testLineTableTest001 started");
47        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
48
49        long classID = getClassIDBySignature("L"+getDebuggeeClassName().replace('.', '/')+";");
50
51        MethodInfo[] methodsInfo = jdwpGetMethodsInfo(classID);
52        assertFalse("Invalid number of methods: 0", methodsInfo.length == 0);
53
54        for (int i = 0; i < methodsInfo.length; i++) {
55            logWriter.println(methodsInfo[i].toString());
56
57            // get variable table for this class
58            ReplyPacket reply = getLineTable(classID, methodsInfo[i].getMethodID());
59
60            long start = reply.getNextValueAsLong();
61            logWriter.println("start = " + start);
62            long end = reply.getNextValueAsLong();
63            logWriter.println("end = " + end);
64
65            int lines = reply.getNextValueAsInt();
66            logWriter.println("lines = "+lines);
67
68            for (int j = 0; j < lines; j++) {
69                long lineCodeIndex = reply.getNextValueAsLong();
70                logWriter.println("lineCodeIndex = "+lineCodeIndex);
71                int lineNumber = reply.getNextValueAsInt();
72                logWriter.println("lineNumber = "+lineNumber);
73            }
74        }
75
76        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
77    }
78}
79