test/jdk/java/lang/Runtime/Version/Basic.java
changeset 48327 d2a837cf9ff1
parent 47216 71c04702a3d5
child 48545 fb978155215d
equal deleted inserted replaced
48326:e1eb12343774 48327:d2a837cf9ff1
    36 import java.util.stream.Collectors;
    36 import java.util.stream.Collectors;
    37 
    37 
    38 import static java.lang.System.out;
    38 import static java.lang.System.out;
    39 
    39 
    40 public class Basic {
    40 public class Basic {
       
    41 
    41     private static final Class<? extends Throwable> IAE
    42     private static final Class<? extends Throwable> IAE
    42         = IllegalArgumentException.class;
    43         = IllegalArgumentException.class;
    43     private static final Class<? extends Throwable> NPE
    44     private static final Class<? extends Throwable> NPE
    44         = NullPointerException.class;
    45         = NullPointerException.class;
    45     private static final Class<? extends Throwable> NFE
    46     private static final Class<? extends Throwable> NFE
    49         = (BigInteger.valueOf(Integer.MAX_VALUE)).add(BigInteger.ONE);
    50         = (BigInteger.valueOf(Integer.MAX_VALUE)).add(BigInteger.ONE);
    50     private static final String TOO_BIG_STR = TOO_BIG.toString();
    51     private static final String TOO_BIG_STR = TOO_BIG.toString();
    51 
    52 
    52     public static void main(String ... args) {
    53     public static void main(String ... args) {
    53 
    54 
    54         //// Tests for parse(), major(), minor(), security(), pre(),
    55         //// Tests for parse(), feature(), interim(), update(), patch(),
    55         //// build(), optional(), version(), toString()
    56         //// pre(), build(), optional(), version(), and toString()
    56         //   v                          M     m sec pre bld opt
    57         //   v                          f     i  u  p pre bld opt
    57 
    58 
    58         // $VNUM
    59         // $VNUM
    59         test("9",                       9,    0, 0, "", 0, "");
    60         test("9",                       9,    0, 0, 0, "", 0, "");
    60         test("9.1",                     9,    1, 0, "", 0, "");
    61         test("9.1",                     9,    1, 0, 0, "", 0, "");
    61         test("9.0.1",                   9,    0, 1, "", 0, "");
    62         test("9.0.1",                   9,    0, 1, 0, "", 0, "");
    62         test("404.1.2",                 404,  1, 2, "", 0, "");
    63         test("9.0.0.1",                 9,    0, 0, 1, "", 0, "");
    63         test("9.1.2.3",                 9,    1, 2, "", 0, "");
    64         test("9.0.0.0.1",               9,    0, 0, 0, "", 0, "");
    64         test("1000.0.0.0.0.0.99999999", 1000, 0, 0, "", 0, "");
    65         test("404.1.2",                 404,  1, 2, 0, "", 0, "");
       
    66         test("9.1.2.3",                 9,    1, 2, 3, "", 0, "");
       
    67         test("1000.0.0.0.0.0.99999999", 1000, 0, 0, 0, "", 0, "");
    65 
    68 
    66         tryCatch(null,    NPE);
    69         tryCatch(null,    NPE);
    67         tryCatch("",      IAE);
    70         tryCatch("",      IAE);
    68         tryCatch("foo",   IAE);
    71         tryCatch("foo",   IAE);
    69         tryCatch("7a",    IAE);
    72         tryCatch("7a",    IAE);
    73         tryCatch("9.0.",  IAE);
    76         tryCatch("9.0.",  IAE);
    74         tryCatch("1.9,1", IAE);
    77         tryCatch("1.9,1", IAE);
    75         tryCatch(TOO_BIG_STR, NFE);
    78         tryCatch(TOO_BIG_STR, NFE);
    76 
    79 
    77         // $PRE
    80         // $PRE
    78         test("9-ea",       9, 0, 0, "ea",       0, "");
    81         test("9-ea",       9, 0, 0, 0, "ea",       0, "");
    79         test("9-internal", 9, 0, 0, "internal", 0, "");
    82         test("9-internal", 9, 0, 0, 0, "internal", 0, "");
    80         test("9-0",        9, 0, 0, "0",        0, "");
    83         test("9-0",        9, 0, 0, 0, "0",        0, "");
    81         test("9.2.7-8",    9, 2, 7, "8",        0, "");
    84         test("9.2.7-8",    9, 2, 7, 0, "8",        0, "");
    82         test("1-ALL",      1, 0, 0, "ALL",      0, "");
    85         test("1-ALL",      1, 0, 0, 0, "ALL",      0, "");
    83         test("2.3.4.5-1a", 2, 3, 4, "1a",       0, "");
    86         test("2.3.4.5-1a", 2, 3, 4, 5, "1a",       0, "");
    84         test("1-" + TOO_BIG_STR, 1, 0, 0, TOO_BIG_STR, 0, "");
    87         test("1-" + TOO_BIG_STR, 1, 0, 0, 0, TOO_BIG_STR, 0, "");
    85 
    88 
    86         tryCatch("9:-ea",     IAE);
    89         tryCatch("9:-ea",     IAE);
    87         tryCatch("3.14159-",  IAE);
    90         tryCatch("3.14159-",  IAE);
    88         tryCatch("3.14159-%", IAE);
    91         tryCatch("3.14159-%", IAE);
    89 
    92 
    90         // $BUILD
    93         // $BUILD
    91         test("9+0",            9, 0,  0,  "",      0,       "");
    94         test("9+0",            9, 0,  0,  0, "",      0,       "");
    92         test("3.14+9999900",   3, 14, 0,  "",      9999900, "");
    95         test("3.14+9999900",   3, 14, 0,  0, "",      9999900, "");
    93         test("9-pre+105",      9, 0,  0,  "pre",   105,     "");
    96         test("9-pre+105",      9, 0,  0,  0, "pre",   105,     "");
    94         test("6.0.42-8beta+4", 6, 0,  42, "8beta", 4,       "");
    97         test("6.0.42-8beta+4", 6, 0,  42, 0, "8beta", 4,       "");
    95 
    98 
    96         tryCatch("9+",     IAE);
    99         tryCatch("9+",     IAE);
    97         tryCatch("7+a",    IAE);
   100         tryCatch("7+a",    IAE);
    98         tryCatch("9+00",   IAE);
   101         tryCatch("9+00",   IAE);
    99         tryCatch("4.2+01", IAE);
   102         tryCatch("4.2+01", IAE);
   100         tryCatch("4.2+1a", IAE);
   103         tryCatch("4.2+1a", IAE);
   101         tryCatch("1+" + TOO_BIG_STR, NFE);
   104         tryCatch("1+" + TOO_BIG_STR, NFE);
   102 
   105 
   103         // $OPT
   106         // $OPT
   104         test("9+-foo",          9,   0, 0, "",       0,  "foo");
   107         test("9+-foo",          9,   0, 0, 0, "",       0,  "foo");
   105         test("9-pre-opt",       9,   0, 0, "pre",    0,  "opt");
   108         test("9-pre-opt",       9,   0, 0, 0, "pre",    0,  "opt");
   106         test("42+---bar",       42,  0, 0, "",       0,  "--bar");
   109         test("42+---bar",       42,  0, 0, 0, "",       0,  "--bar");
   107         test("2.91+-8061493-",  2,  91, 0, "",       0,  "8061493-");
   110         test("2.91+-8061493-",  2,  91, 0, 0, "",       0,  "8061493-");
   108         test("24+-foo.bar",     24,  0, 0, "",       0,  "foo.bar");
   111         test("24+-foo.bar",     24,  0, 0, 0, "",       0,  "foo.bar");
   109         test("9-ribbit+17-...", 9,   0, 0, "ribbit", 17, "...");
   112         test("9-ribbit+17-...", 9,   0, 0, 0, "ribbit", 17, "...");
   110         test("7+1-" + TOO_BIG_STR, 7,0, 0, "",       1,  TOO_BIG_STR);
   113         test("7+1-" + TOO_BIG_STR, 7,0, 0, 0, "",       1,  TOO_BIG_STR);
   111 
   114 
   112         tryCatch("9-pre+-opt", IAE);
   115         tryCatch("9-pre+-opt", IAE);
   113         tryCatch("1.4142+-",   IAE);
   116         tryCatch("1.4142+-",   IAE);
   114         tryCatch("2.9979+-%",  IAE);
   117         tryCatch("2.9979+-%",  IAE);
   115 
   118 
   125         testEHC("8",          "9",                false, false, -1,   -1);
   128         testEHC("8",          "9",                false, false, -1,   -1);
   126         testEHC("9",          "10",               false, false, -1,   -1);
   129         testEHC("9",          "10",               false, false, -1,   -1);
   127         testEHC("9",          "8",                false, false,  1,    1);
   130         testEHC("9",          "8",                false, false,  1,    1);
   128 
   131 
   129         testEHC("10.512.1",   "10.512.2",         false, false, -1,   -1);
   132         testEHC("10.512.1",   "10.512.2",         false, false, -1,   -1);
       
   133         testEHC("10.512.0.1", "10.512.0.2",       false, false, -1,   -1);
       
   134         testEHC("10.512.0.0.1", "10.512.0.0.2",   false, false, -1,   -1);
   130         testEHC("512.10.1",   "512.11.1",         false, false, -1,   -1);
   135         testEHC("512.10.1",   "512.11.1",         false, false, -1,   -1);
   131 
   136 
   132         // $OPT comparison
   137         // $OPT comparison
   133         testEHC("9",          "9+-oink",          false, true,  -1,    0);
   138         testEHC("9",          "9+-oink",          false, true,  -1,    0);
   134         testEHC("9+-ribbit",  "9+-moo",           false, true,   1,    0);
   139         testEHC("9+-ribbit",  "9+-moo",           false, true,   1,    0);
   162         else
   167         else
   163             out.println("all " + (fail + pass) + " tests passed");
   168             out.println("all " + (fail + pass) + " tests passed");
   164 
   169 
   165     }
   170     }
   166 
   171 
   167     private static void test(String s, Integer major, Integer minor,
   172     private static void test(String s, Integer feature, Integer interim,
   168                              Integer sec, String pre, Integer build,
   173                              Integer update, Integer patch,
   169                              String opt)
   174                              String pre, Integer build, String opt)
   170     {
   175     {
   171         Version v = testParse(s);
   176         Version v = testParse(s);
   172 
   177 
   173         testStr(v.toString(), s);
   178         testStr(v.toString(), s);
   174 
   179 
   175         testInt(v.major(), major);
   180         testInt(v.feature(), feature);
   176         testInt(v.minor(), minor);
   181         testInt(v.major(), feature);
   177         testInt(v.security(), sec);
   182         testInt(v.interim(), interim);
       
   183         testInt(v.minor(), interim);
       
   184         testInt(v.update(), update);
       
   185         testInt(v.security(), update);
       
   186         testInt(v.patch(), patch);
   178         testStr((v.pre().isPresent() ? v.pre().get() : ""), pre);
   187         testStr((v.pre().isPresent() ? v.pre().get() : ""), pre);
   179         testInt((v.build().isPresent() ? v.build().get() : 0), build);
   188         testInt((v.build().isPresent() ? v.build().get() : 0), build);
   180         testStr((v.optional().isPresent() ? v.optional().get() : ""), opt);
   189         testStr((v.optional().isPresent() ? v.optional().get() : ""), opt);
   181 
   190 
   182         testVersion(v.version(), s);
   191         testVersion(v.version(), s);
   379             throw new RuntimeException(s);
   388             throw new RuntimeException(s);
   380         } catch (RuntimeException x) {
   389         } catch (RuntimeException x) {
   381             first = x;
   390             first = x;
   382         }
   391         }
   383     }
   392     }
       
   393 
   384 }
   394 }