1 /* 2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary Unit test for java.lang.Runtime.Version. 27 * @bug 8072379 8144062 8161236 28 */ 29 30 import java.lang.reflect.InvocationTargetException; 31 import java.lang.reflect.Method; 32 import java.lang.Runtime.Version; 33 import java.math.BigInteger; 34 import java.util.stream.Collectors; 35 import java.util.Arrays; 36 import java.util.ArrayList; 37 import java.util.List; 38 import java.util.Optional; 39 40 import static java.lang.System.out; 41 42 public class Basic { 43 private static final Class<? extends Throwable> IAE 44 = IllegalArgumentException.class; 45 private static final Class<? extends Throwable> NPE 46 = NullPointerException.class; 47 private static final Class<? extends Throwable> NFE 123 //// compareTo{IgnoreOptional}?() 124 // compare: after "<" == -1, equal == 0, before ">" == 1 125 // v0 v1 eq eqNO cmp cmpNO 126 testEHC("9", "9", true, true, 0, 0); 127 128 testEHC("8", "9", false, false, -1, -1); 129 testEHC("9", "10", false, false, -1, -1); 130 testEHC("9", "8", false, false, 1, 1); 131 132 // $OPT comparison 133 testEHC("9", "9+-oink", false, true, -1, 0); 134 testEHC("9+-ribbit", "9+-moo", false, true, 1, 0); 135 testEHC("9-quack+3-ribbit", 136 "9-quack+3-moo", false, true, 1, 0); 137 testEHC("9.1+7", "9.1+7-moo-baa-la", false, true, -1, 0); 138 139 // numeric vs. non-numeric $PRE 140 testEHC("9.1.1.2-2a", "9.1.1.2-12", false, false, 1, 1); 141 testEHC("9.1.1.2-12", "9.1.1.2-4", false, false, 1, 1); 142 143 testEHC("27.16", "27.16+120", false, false, 1, 1); 144 testEHC("10", "10-ea", false, false, 1, 1); 145 testEHC("10.1+1", "10.1-ea+1", false, false, 1, 1); 146 testEHC("10.0.1+22", "10.0.1+21", false, false, 1, 1); 147 148 // numeric vs. non-numeric $PRE 149 testEHC("9.1.1.2-12", "9.1.1.2-a2", false, false, -1, -1); 150 testEHC("9.1.1.2-1", "9.1.1.2-4", false, false, -1, -1); 151 152 testEHC("9-internal", "9", false, false, -1, -1); 153 testEHC("9-ea+120", "9+120", false, false, -1, -1); 154 testEHC("9-ea+120", "9+120", false, false, -1, -1); 155 testEHC("9+101", "9", false, false, -1, -1); 156 testEHC("9+101", "9+102", false, false, -1, -1); 157 testEHC("1.9-ea", "9-ea", false, false, -1, -1); 158 159 if (fail != 0) 160 throw new RuntimeException((fail + pass) + " tests: " 161 + fail + " failure(s), first", first); 162 else 163 out.println("all " + (fail + pass) + " tests passed"); 164 165 } 166 167 private static void test(String s, Integer major, Integer minor, 168 Integer sec, String pre, Integer build, 169 String opt) 170 { 171 Version v = testParse(s); 172 173 testStr(v.toString(), s); 174 175 testInt(v.major(), major); | 1 /* 2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @summary Unit test for java.lang.Runtime.Version. 27 * @bug 8072379 8144062 8161236 8160956 28 */ 29 30 import java.lang.reflect.InvocationTargetException; 31 import java.lang.reflect.Method; 32 import java.lang.Runtime.Version; 33 import java.math.BigInteger; 34 import java.util.stream.Collectors; 35 import java.util.Arrays; 36 import java.util.ArrayList; 37 import java.util.List; 38 import java.util.Optional; 39 40 import static java.lang.System.out; 41 42 public class Basic { 43 private static final Class<? extends Throwable> IAE 44 = IllegalArgumentException.class; 45 private static final Class<? extends Throwable> NPE 46 = NullPointerException.class; 47 private static final Class<? extends Throwable> NFE 123 //// compareTo{IgnoreOptional}?() 124 // compare: after "<" == -1, equal == 0, before ">" == 1 125 // v0 v1 eq eqNO cmp cmpNO 126 testEHC("9", "9", true, true, 0, 0); 127 128 testEHC("8", "9", false, false, -1, -1); 129 testEHC("9", "10", false, false, -1, -1); 130 testEHC("9", "8", false, false, 1, 1); 131 132 // $OPT comparison 133 testEHC("9", "9+-oink", false, true, -1, 0); 134 testEHC("9+-ribbit", "9+-moo", false, true, 1, 0); 135 testEHC("9-quack+3-ribbit", 136 "9-quack+3-moo", false, true, 1, 0); 137 testEHC("9.1+7", "9.1+7-moo-baa-la", false, true, -1, 0); 138 139 // numeric vs. non-numeric $PRE 140 testEHC("9.1.1.2-2a", "9.1.1.2-12", false, false, 1, 1); 141 testEHC("9.1.1.2-12", "9.1.1.2-4", false, false, 1, 1); 142 143 testEHC("27.16", "27.16+120", false, false, -1, -1); 144 testEHC("10", "10-ea", false, false, 1, 1); 145 testEHC("10.1+1", "10.1-ea+1", false, false, 1, 1); 146 testEHC("10.0.1+22", "10.0.1+21", false, false, 1, 1); 147 148 // numeric vs. non-numeric $PRE 149 testEHC("9.1.1.2-12", "9.1.1.2-a2", false, false, -1, -1); 150 testEHC("9.1.1.2-1", "9.1.1.2-4", false, false, -1, -1); 151 152 testEHC("9-internal", "9", false, false, -1, -1); 153 testEHC("9-ea+120", "9+120", false, false, -1, -1); 154 testEHC("9-ea+120", "9+120", false, false, -1, -1); 155 testEHC("9+101", "9", false, false, 1, 1); 156 testEHC("9+101", "9+102", false, false, -1, -1); 157 testEHC("1.9-ea", "9-ea", false, false, -1, -1); 158 159 if (fail != 0) 160 throw new RuntimeException((fail + pass) + " tests: " 161 + fail + " failure(s), first", first); 162 else 163 out.println("all " + (fail + pass) + " tests passed"); 164 165 } 166 167 private static void test(String s, Integer major, Integer minor, 168 Integer sec, String pre, Integer build, 169 String opt) 170 { 171 Version v = testParse(s); 172 173 testStr(v.toString(), s); 174 175 testInt(v.major(), major); |