jdk/test/com/sun/jdi/sde/MangleTest.java
author ykantser
Thu, 07 May 2015 09:11:49 +0200
changeset 30376 2ccf2cf7ea48
parent 24973 8c4bc3fa4c4e
child 44423 306c020eb154
permissions -rw-r--r--
8078896: Add @modules as needed to the jdk_svc tests Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *  @bug 4390869
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *  @bug 4460328
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *  @summary Test the new SourceDebugExtension facility
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *  @author Robert Field
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  @library ..
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 24973
diff changeset
    10
 *  @modules jdk.jdi
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *  @run compile MangleTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *  @run compile -g onion/pickle/Mangle.java
24973
8c4bc3fa4c4e 6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure
sla
parents: 2
diff changeset
    14
 *  @run driver MangleTest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
public class MangleTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
    static final String op = "onion" + File.separator + "pickle" + File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    MangleTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
        testSetUp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
        new MangleTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    /********** test set-up **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    static void testSetUp() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        InstallSDE.install(new File(System.getProperty("test.classes", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                                    op + "Mangle.class"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                           new File(System.getProperty("test.src", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                                    "Mangle.sde"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /********** test assist **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    void checkLocation(Location loc, String label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                       String expectedSourceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                       String expectedSourcePath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                       int expectedLinenumber) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        String sourceName = loc.sourceName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        if (sourceName.equals(expectedSourceName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            println(label + " sourceName: " + sourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            failure("FAIL: " + label +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                    " expected sourceName " + expectedSourceName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                    " got - " + sourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        String sourcePath = loc.sourcePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (sourcePath.equals(expectedSourcePath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            println(label + " sourcePath: " + sourcePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            failure("FAIL: " + label +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                    " expected sourcePath " + expectedSourcePath +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    " got - " + sourcePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        int ln = loc.lineNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (ln == expectedLinenumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            println(label + " line number: " + ln);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            failure("FAIL: " + label +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    " expected line number " + expectedLinenumber +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    " got - " + ln);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    void checkLocation(String stratum, Location loc, String label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                       String expectedSourceName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                       String expectedSourcePath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                       int expectedLinenumber) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        String sourceName = loc.sourceName(stratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (sourceName.equals(expectedSourceName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            println(label + "(" + stratum + ")" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    " sourceName: " + sourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            failure("FAIL: " + label + "(" + stratum + ")" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    " expected sourceName " + expectedSourceName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    " got " + sourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        String sourcePath = loc.sourcePath(stratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (sourcePath.equals(expectedSourcePath)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            println(label + "(" + stratum + ")" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    " sourcePath: " + sourcePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            failure("FAIL: " + label + "(" + stratum + ")" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    " expected sourcePath " + expectedSourcePath +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    " got " + sourcePath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        int ln = loc.lineNumber(stratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (ln == expectedLinenumber) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            println(label + "(" + stratum + ")" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    " line number: " + ln);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            failure("FAIL: " + label + "(" + stratum + ")" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    " expected line number " + expectedLinenumber +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    " got " + ln);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    Location getLoc(int index, List locList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return ((Location)(locList.get(index)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    void lineMatch(int index, String stratum, Location loc, int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        int gotLine = loc.lineNumber(stratum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (gotLine != line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            failure("FAIL: index=" + index +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    " " + stratum + " line=" + gotLine +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    " expected: " + line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    void lineMatch(int index, Location loc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                   int javaLine, int xyzLine, int ratsLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        lineMatch(index, "Java", loc, javaLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        lineMatch(index, "XYZ", loc, xyzLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        lineMatch(index, "Rats", loc, ratsLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    List listWith(String s1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        List result = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        result.add(s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    List listWith(String s1, String s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        List result = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        result.add(s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        result.add(s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         * to determine targetClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        BreakpointEvent bpe = startToMain("onion.pickle.Mangle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // ref type source name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        String sourceName = targetClass.sourceName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (sourceName.equals("Mangle.xyz")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            println("ref type sourceName: " + sourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            failure("FAIL: unexpected ref type sourceName - " + sourceName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        // ref type source names /paths
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        List sourceNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        sourceNames = targetClass.sourceNames("Java");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (sourceNames.equals(listWith("Mangle.java"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            println("ref type Java sourceNames: " + sourceNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            failure("FAIL: unexpected ref type Java sourceNames - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    sourceNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        sourceNames = targetClass.sourceNames("XYZ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (sourceNames.equals(listWith("Mangle.xyz", "Incl.xyz"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            println("ref type XYZ sourceNames: " + sourceNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            failure("FAIL: unexpected ref type XYZ sourceNames - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    sourceNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        sourceNames = targetClass.sourceNames(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (sourceNames.equals(listWith("Mangle.xyz", "Incl.xyz"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            println("ref type null sourceNames: " + sourceNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            failure("FAIL: unexpected ref type null sourceNames - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    sourceNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        sourceNames = targetClass.sourceNames("Rats");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (sourceNames.equals(listWith("Mangle.rats", "Incl.rats"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            println("ref type Rats sourceNames: " + sourceNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            failure("FAIL: unexpected ref type Rats sourceNames - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    sourceNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        List sourcePaths;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        sourcePaths = targetClass.sourcePaths("Java");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (sourcePaths.equals(listWith(op + "Mangle.java"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            println("ref type Java sourcePaths: " + sourcePaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            failure("FAIL: unexpected ref type Java sourcePaths - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    sourcePaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        sourcePaths = targetClass.sourcePaths("XYZ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (sourcePaths.equals(listWith("database14", op + "Incl.xyz"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            println("ref type XYZ sourcePaths: " + sourcePaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            failure("FAIL: unexpected ref type XYZ sourcePaths - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    sourcePaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        sourcePaths = targetClass.sourcePaths(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (sourcePaths.equals(listWith("database14", op + "Incl.xyz"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            println("ref type null sourcePaths: " + sourcePaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            failure("FAIL: unexpected ref type null sourcePaths - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    sourcePaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        sourcePaths = targetClass.sourcePaths("Rats");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (sourcePaths.equals(listWith(op + "Mangle.rats",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                        "bleep:bleep:Incl.rats"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            println("ref type Rats sourcePaths: " + sourcePaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            failure("FAIL: unexpected ref type Rats sourcePaths - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    sourcePaths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Method main = findMethod(targetClass, "main",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                 "([Ljava/lang/String;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        List allLines = main.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        List javaLines = main.allLineLocations("Java", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        List bogusLines = main.allLineLocations("bogus", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        List nullLines = main.allLineLocations(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        List xyzLines = main.allLineLocations("XYZ", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        List ratsLines = main.allLineLocations("Rats", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        List tl = new ArrayList(allLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        tl.removeAll(xyzLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (tl.isEmpty() && allLines.size() == xyzLines.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            println("allLineLocations() is OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            failure("FAIL: allLineLocations() wrong - " + allLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        tl = new ArrayList(bogusLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        tl.removeAll(xyzLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (tl.isEmpty() && bogusLines.size() == xyzLines.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            println("allLineLocations(\"bogus\") is OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            failure("FAIL: allLineLocations(\"bogus\") wrong - " + bogusLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        tl = new ArrayList(nullLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        tl.removeAll(xyzLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (tl.isEmpty() && nullLines.size() == xyzLines.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            println("allLineLocations(null) is OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            failure("FAIL: allLineLocations(null) wrong - " + nullLines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (!javaLines.get(0).equals(ratsLines.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            failure("FAIL: locations should match - " + javaLines.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (javaLines.get(0).equals(xyzLines.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            failure("FAIL: locations should not match - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    javaLines.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (!javaLines.get(1).equals(ratsLines.get(1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            failure("FAIL: locations should match - " + javaLines.get(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (!javaLines.get(1).equals(xyzLines.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            failure("FAIL: locations should match - " + javaLines.get(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (javaLines.get(2).equals(ratsLines.get(1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            failure("FAIL: locations should not match - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    javaLines.get(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (xyzLines.contains(javaLines.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            failure("FAIL: xyz locations should not match - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    javaLines.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (xyzLines.contains(javaLines.get(2))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            failure("FAIL: xyz locations should not match - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    javaLines.get(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (xyzLines.contains(javaLines.get(6))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            failure("FAIL: xyz locations should not match - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    javaLines.get(6));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (ratsLines.contains(javaLines.get(2))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            failure("FAIL: rats locations should not match - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    javaLines.get(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (ratsLines.contains(javaLines.get(4))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            failure("FAIL: rats locations should not match - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    javaLines.get(4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (ratsLines.contains(javaLines.get(5))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            failure("FAIL: rats locations should not match - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    javaLines.get(5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        println("*** Java");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        for (Iterator it = javaLines.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            Location loc = (Location)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            print("" + loc.lineNumber("Java") + " - ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            print(loc.sourceName("XYZ") + " : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            print("" + loc.lineNumber("XYZ") + " ... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            print(loc.sourceName("Rats") + " : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            println("" + loc.lineNumber("Rats"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        println("*** XYZ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        for (Iterator it = xyzLines.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            Location loc = (Location)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            print("" + loc.lineNumber("Java") + " - ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            print(loc.sourceName("XYZ") + " : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            print("" + loc.lineNumber("XYZ") + " ... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            print(loc.sourceName("Rats") + " : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            println("" + loc.lineNumber("Rats"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        println("*** Rats");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        for (Iterator it = ratsLines.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            Location loc = (Location)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            print("" + loc.lineNumber("Java") + " - ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            print(loc.sourceName("XYZ") + " : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            print("" + loc.lineNumber("XYZ") + " ... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            print(loc.sourceName("Rats") + " : ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            println("" + loc.lineNumber("Rats"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        checkLocation(getLoc(0, javaLines), "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                      "Incl.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                      op + "Incl.xyz", 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        checkLocation(null, getLoc(0, javaLines), "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                      "Incl.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                      op + "Incl.xyz", 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        checkLocation("bogus", getLoc(0, javaLines), "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                      "Incl.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                      op + "Incl.xyz", 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        checkLocation("Java", getLoc(0, javaLines), "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                      "Mangle.java",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                      op + "Mangle.java", 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        checkLocation("XYZ", getLoc(0, javaLines), "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                      "Incl.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                      op + "Incl.xyz", 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        checkLocation("Rats", getLoc(0, javaLines), "0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                      "Mangle.rats",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                      op + "Mangle.rats", 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        checkLocation(getLoc(3, javaLines), "3",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                      "Mangle.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                      "database14", 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        checkLocation(null, getLoc(3, javaLines), "3",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                      "Mangle.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                      "database14", 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        checkLocation("bogus", getLoc(3, javaLines), "3",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                      "Mangle.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                      "database14", 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        checkLocation("Java", getLoc(3, javaLines), "3",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                      "Mangle.java",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                      op + "Mangle.java", 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        checkLocation("XYZ", getLoc(3, javaLines), "3",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                      "Mangle.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                      "database14", 210);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        checkLocation("Rats", getLoc(3, javaLines), "3",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                      "Incl.rats",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                      "bleep:bleep:Incl.rats", 1112);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        checkLocation(getLoc(6, javaLines), "6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                      "Mangle.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                      "database14", 218);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        checkLocation(null, getLoc(6, javaLines), "6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                      "Mangle.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                      "database14", 218);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        checkLocation("bogus", getLoc(6, javaLines), "6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                      "Mangle.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                      "database14", 218);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        checkLocation("Java", getLoc(6, javaLines), "6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                      "Mangle.java",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                      op + "Mangle.java", 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        checkLocation("XYZ", getLoc(6, javaLines), "6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                      "Mangle.xyz",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                      "database14", 218);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        checkLocation("Rats", getLoc(6, javaLines), "6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                      "Incl.rats",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                      "bleep:bleep:Incl.rats", 1112);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        lineMatch(0, getLoc(0, javaLines), 4, 200, 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        lineMatch(1, getLoc(1, javaLines), 5, 200, 1111);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        lineMatch(2, getLoc(2, javaLines), 6, 200, 1111);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        lineMatch(3, getLoc(3, javaLines), 7, 210, 1112);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        lineMatch(4, getLoc(4, javaLines), 8, 217, 1112);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        lineMatch(5, getLoc(5, javaLines), 9, 218, 1112);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        lineMatch(6, getLoc(6, javaLines), 10, 218, 1112);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         * resume the target listening for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            println("MangleTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            throw new Exception("MangleTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
}