1 package org.jgroups.tests; 2 3 import junit.framework.TestCase; 4 import org.jgroups.Version; 5 6 10 public class VersionTest extends TestCase { 11 12 public VersionTest(String s) { 13 super(s); 14 } 15 16 public void testVersionPrint() { 17 System.out.println("version is " +Version.printVersion()); 18 assertTrue(true); 19 } 20 21 public void testNullVersion() { 22 assertFalse(Version.isSame((short)0)); 23 } 24 25 public void testDifferentLengthVersion1() { 26 short version2=Version.encode(2,0,7); 27 assertFalse(Version.isSame(version2)); 28 } 29 30 31 public void testDifferentVersion() { 32 short version1=Version.encode(2,0,7), version2=Version.encode(2,0,6); 33 assertFalse(version1 == version2); 34 } 35 36 public void testSameVersion() { 37 assertTrue(match(0,0,1, 0,0,1)); 38 assertTrue(match(1,0,0, 1,0,0)); 39 assertTrue(match(10,2,60, 10,2,60)); 40 assertFalse(match(1,2,3, 1,2,0)); 41 assertFalse(match(0,0,0, 0,0,1)); 42 assertFalse(match(2,5,0, 2,5,1)); 43 } 44 45 46 public void testBinaryCompatibility() { 47 assertTrue(isBinaryCompatible(0,0,0, 0,0,0)); 48 assertTrue(isBinaryCompatible(1,2,0, 1,2,1)); 49 assertTrue(isBinaryCompatible(1,2,0, 1,2,60)); 50 assertFalse(isBinaryCompatible(2,5,0, 2,4,1)); 51 assertFalse(isBinaryCompatible(2,5,0, 2,6,0)); 52 } 53 54 55 private boolean match(int major_1, int minor_1, int micro_1, int major_2, int minor_2, int micro_2) { 56 short version1=Version.encode(major_1, minor_1, micro_1); 57 short version2=Version.encode(major_2, minor_2, micro_2); 58 return version1 == version2; 59 } 60 61 private boolean isBinaryCompatible(int major_1, int minor_1, int micro_1, int major_2, int minor_2, int micro_2) { 62 short version1=Version.encode(major_1, minor_1, micro_1); 63 short version2=Version.encode(major_2, minor_2, micro_2); 64 boolean retval=Version.isBinaryCompatible(version1, version2); 65 System.out.println(Version.print(version1) + " binary compatibel to " + Version.print(version2) + (retval? " OK" : " FAIL")); 66 return Version.isBinaryCompatible(version1, version2); 67 } 68 69 70 public static void main(String [] args) { 71 String [] testCaseName = {VersionTest.class.getName()}; 72 junit.textui.TestRunner.main(testCaseName); 73 } 74 } 75 | Popular Tags |