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