hotspot/test/serviceability/ParserTest.java
author duke
Wed, 05 Jul 2017 18:18:57 +0200
changeset 13386 382651d28f25
parent 13200 7b506e7b406e
child 15793 4867678e3517
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12262
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     1
/*
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     2
 * @test ParserTest
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     3
 * @summary verify that whitebox functions can be linked and executed
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     4
 * @run compile -J-XX:+UnlockDiagnosticVMOptions -J-XX:+WhiteBoxAPI ParserTest.java
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     5
 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ParserTest
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     6
 */
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     7
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     8
import java.math.BigInteger;
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
     9
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    10
import sun.hotspot.parser.DiagnosticCommand;
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    11
import sun.hotspot.parser.DiagnosticCommand.DiagnosticArgumentType;
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    12
import sun.hotspot.WhiteBox;
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    13
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    14
public class ParserTest {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    15
    WhiteBox wb;
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    16
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    17
    public ParserTest() throws Exception {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    18
        wb = WhiteBox.getWhiteBox();
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    19
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    20
        testNanoTime();
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    21
        testJLong();
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    22
        testBool();
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
    23
        testQuotes();
12262
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    24
        testMemorySize();
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    25
    }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    26
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    27
    public static void main(String... args) throws Exception  {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    28
         new ParserTest();
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    29
    }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    30
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    31
    public void testNanoTime() throws Exception {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    32
        String name = "name";
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    33
        DiagnosticCommand arg = new DiagnosticCommand(name,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    34
                "desc", DiagnosticArgumentType.NANOTIME,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    35
                false, "0");
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    36
        DiagnosticCommand[] args = {arg};
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    37
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    38
        BigInteger bi = new BigInteger("7");
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    39
        //These should work
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    40
        parse(name, bi.toString(), name + "=7ns", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    41
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    42
        bi = bi.multiply(BigInteger.valueOf(1000));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    43
        parse(name, bi.toString(), name + "=7us", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    44
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    45
        bi = bi.multiply(BigInteger.valueOf(1000));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    46
        parse(name, bi.toString(), name + "=7ms", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    47
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    48
        bi = bi.multiply(BigInteger.valueOf(1000));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    49
        parse(name, bi.toString(), name + "=7s", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    50
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    51
        bi = bi.multiply(BigInteger.valueOf(60));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    52
        parse(name, bi.toString() , name + "=7m", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    53
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    54
        bi = bi.multiply(BigInteger.valueOf(60));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    55
        parse(name, bi.toString() , name + "=7h", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    56
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    57
        bi = bi.multiply(BigInteger.valueOf(24));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    58
        parse(name, bi.toString() , name + "=7d", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    59
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    60
        parse(name, "0", name + "=0", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    61
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    62
        shouldFail(name + "=7xs", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    63
        shouldFail(name + "=7mms", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    64
        shouldFail(name + "=7f", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    65
        //Currently, only value 0 is allowed without unit
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    66
        shouldFail(name + "=7", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    67
    }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    68
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    69
    public void testJLong() throws Exception {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    70
        String name = "name";
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    71
        DiagnosticCommand arg = new DiagnosticCommand(name,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    72
                "desc", DiagnosticArgumentType.JLONG,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    73
                false, "0");
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    74
        DiagnosticCommand[] args = {arg};
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    75
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    76
        wb.parseCommandLine(name + "=10", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    77
        parse(name, "10", name + "=10", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    78
        parse(name, "-5", name + "=-5", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    79
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    80
        //shouldFail(name + "=12m", args); <-- should fail, doesn't
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    81
    }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    82
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    83
    public void testBool() throws Exception {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    84
        String name = "name";
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    85
        DiagnosticCommand arg = new DiagnosticCommand(name,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    86
                "desc", DiagnosticArgumentType.BOOLEAN,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    87
                false, "false");
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    88
        DiagnosticCommand[] args = {arg};
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    89
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    90
        parse(name, "true", name + "=true", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    91
        parse(name, "false", name + "=false", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    92
        parse(name, "true", name, args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    93
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    94
        //Empty commandline to parse, tests default value
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    95
        //of the parameter "name"
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    96
        parse(name, "false", "", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    97
    }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
    98
13200
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
    99
    public void testQuotes() throws Exception {
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   100
        String name = "name";
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   101
        DiagnosticCommand arg1 = new DiagnosticCommand(name,
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   102
                "desc", DiagnosticArgumentType.STRING,
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   103
                false, null);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   104
        DiagnosticCommand arg2 = new DiagnosticCommand("arg",
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   105
                "desc", DiagnosticArgumentType.STRING,
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   106
                false, null);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   107
        DiagnosticCommand[] args = {arg1, arg2};
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   108
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   109
        // try with a quoted value
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   110
        parse(name, "Recording 1", name + "=\"Recording 1\"", args);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   111
        // try with a quoted argument
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   112
        parse(name, "myrec", "\"" + name + "\"" + "=myrec", args);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   113
        // try with both a quoted value and a quoted argument
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   114
        parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\"", args);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   115
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   116
        // now the same thing but with other arguments after
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   117
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   118
        // try with a quoted value
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   119
        parse(name, "Recording 1", name + "=\"Recording 1\",arg=value", args);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   120
        // try with a quoted argument
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   121
        parse(name, "myrec", "\"" + name + "\"" + "=myrec,arg=value", args);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   122
        // try with both a quoted value and a quoted argument
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   123
        parse(name, "Recording 1", "\"" + name + "\"" + "=\"Recording 1\",arg=value", args);
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   124
    }
7b506e7b406e 7178703: Fix handling of quoted arguments and better error messages in dcmd
sla
parents: 12262
diff changeset
   125
12262
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   126
    public void testMemorySize() throws Exception {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   127
        String name = "name";
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   128
        String defaultValue = "1024";
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   129
        DiagnosticCommand arg = new DiagnosticCommand(name,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   130
                "desc", DiagnosticArgumentType.MEMORYSIZE,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   131
                false, defaultValue);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   132
        DiagnosticCommand[] args = {arg};
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   133
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   134
        BigInteger bi = new BigInteger("7");
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   135
        parse(name, bi.toString(), name + "=7b", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   136
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   137
        bi = bi.multiply(BigInteger.valueOf(1024));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   138
        parse(name, bi.toString(), name + "=7k", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   139
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   140
        bi = bi.multiply(BigInteger.valueOf(1024));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   141
        parse(name, bi.toString(), name + "=7m", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   142
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   143
        bi = bi.multiply(BigInteger.valueOf(1024));
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   144
        parse(name, bi.toString(), name + "=7g", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   145
        parse(name, defaultValue, "", args);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   146
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   147
        //shouldFail(name + "=7gg", args); <---- should fail, doesn't
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   148
        //shouldFail(name + "=7t", args);  <----- should fail, doesn't
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   149
    }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   150
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   151
    public void parse(String searchName, String expectedValue,
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   152
            String cmdLine, DiagnosticCommand[] argumentTypes) throws Exception {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   153
        //parseCommandLine will return an object array that looks like
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   154
        //{<name of parsed object>, <of parsed object> ... }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   155
        Object[] res = wb.parseCommandLine(cmdLine, argumentTypes);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   156
        for (int i = 0; i < res.length-1; i+=2) {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   157
            String parsedName = (String) res[i];
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   158
            if (searchName.equals(parsedName)) {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   159
                String parsedValue = (String) res[i+1];
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   160
                if (expectedValue.equals(parsedValue)) {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   161
                    return;
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   162
                } else {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   163
                    throw new Exception("Parsing of cmdline '" + cmdLine + "' failed!\n"
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   164
                            + searchName + " parsed as " + parsedValue
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   165
                            + "! Expected: " + expectedValue);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   166
                }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   167
            }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   168
        }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   169
        throw new Exception(searchName + " not found as a parsed Argument!");
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   170
    }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   171
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   172
    private void shouldFail(String argument, DiagnosticCommand[] argumentTypes) throws Exception {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   173
        try {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   174
            wb.parseCommandLine(argument, argumentTypes);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   175
            throw new Exception("Parser accepted argument: " + argument);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   176
        } catch (IllegalArgumentException e) {
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   177
            //expected
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   178
        }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   179
    }
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
diff changeset
   180
}