1 /* 2 Copyright (C) 2011 Red Hat, Inc. 3 4 This file is part of IcedTea. 5 6 IcedTea is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, version 2. 9 10 IcedTea is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with IcedTea; see the file COPYING. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 02110-1301 USA. 19 20 Linking this library statically or dynamically with other modules is 21 making a combined work based on this library. Thus, the terms and 22 conditions of the GNU General Public License cover the whole 23 combination. 24 25 As a special exception, the copyright holders of this library give you 26 permission to link this library with independent modules to produce an 27 executable, regardless of the license terms of these independent 28 modules, and to copy and distribute the resulting executable under 29 terms of your choice, provided that you also meet, for each linked 30 independent module, the terms and conditions of the license of that 31 module. An independent module is a module which is not derived from 32 or based on this library. If you modify this library, you may extend 33 this exception to your version of the library, but you are not 34 obligated to do so. If you do not wish to do so, delete this 35 exception statement from your version. 36 */ 37 package net.sourceforge.jnlp; 38 39 import org.junit.Assert; 40 import org.junit.Test; 41 42 public class VersionTest { 43 44 private static boolean[] results = {true, 45 true, 46 false, 47 true, 48 false, 49 true, 50 false, 51 true, 52 false, 53 false, 54 false, 55 false, 56 true, 57 true, 58 true, 59 true, 60 true, 61 true, 62 false, 63 true}; 64 private static Version jvms[] = { 65 new Version("1.1* 1.3*"), 66 new Version("1.2+"),}; 67 private static Version versions[] = { 68 new Version("1.1"), 69 new Version("1.1.8"), 70 new Version("1.2"), 71 new Version("1.3"), 72 new Version("2.0"), 73 new Version("1.3.1"), 74 new Version("1.2.1"), 75 new Version("1.3.1-beta"), 76 new Version("1.1 1.2"), 77 new Version("1.2 1.3"),}; 78 79 @Test testMatches()80 public void testMatches() { 81 82 int i = 0; 83 for (int j = 0; j < jvms.length; j++) { 84 for (int v = 0; v < versions.length; v++) { 85 i++; 86 String debugOutput = i + " " + jvms[j].toString() + " "; 87 if (!jvms[j].matches(versions[v])) { 88 debugOutput += "!"; 89 } 90 debugOutput += "matches " + versions[v].toString(); 91 ServerAccess.logOutputReprint(debugOutput); 92 Assert.assertEquals(results[i - 1], jvms[j].matches(versions[v])); 93 } 94 } 95 96 97 } 98 99 100 @Test cornerCases()101 public void cornerCases() { 102 Assert.assertTrue(new Version("1.5").matches("1.5")); 103 Assert.assertTrue(new Version("1.5+").matches("1.5")); 104 Assert.assertTrue(new Version("1.5+").matches("1.6")); 105 Assert.assertFalse(new Version("1.5+").matches("1.4")); 106 Assert.assertFalse(new Version("1.5").matches("1.4")); 107 Assert.assertFalse(new Version("1.5").matches("1.6")); 108 } 109 110 @Test testMatchesMinus()111 public void testMatchesMinus() { 112 Assert.assertTrue(new Version("1.5-").matches("1.5")); 113 //this fails, do we need to patch it? 114 //Assert.assertTrue(new Version("1.5-").matches("1.4")); 115 //not until somebody complains 116 Assert.assertFalse(new Version("1.5-").matches("1.6")); 117 118 } 119 120 @Test multiplePossibilities()121 public void multiplePossibilities() { 122 Assert.assertTrue(new Version("1.4 1.5").matches("1.5")); 123 Assert.assertFalse(new Version("1.3 1.4").matches("1.5")); 124 } 125 126 @Test jreVersionTestOk()127 public void jreVersionTestOk() { 128 //no exception occures 129 //head support jdk 7+, so this statements should be always true 130 Version.JreVersion jreVersion = new Version.JreVersion("1.4 1.5+", true, true); 131 Version.JreVersion jreVersion1 = new Version.JreVersion("1.6+", true, true); 132 } 133 134 @Test(expected = RuntimeException.class) jreVersionTestFails1()135 public void jreVersionTestFails1() { 136 //head support jdk 7+, so this statements should be always false 137 Version.JreVersion jreVersion = new Version.JreVersion("2", true, true); 138 } 139 140 @Test(expected = RuntimeException.class) jreVersionTestFails2()141 public void jreVersionTestFails2() { 142 //head support jdk 7+, so this statements should be always false 143 Version.JreVersion jreVersion = new Version.JreVersion("1.4", true, true); 144 } 145 } 146