01: package org.jgroups.tests;
02:
03: import junit.framework.TestCase;
04: import org.jgroups.Version;
05:
06: /**
07: * @author Bela Ban April 4 2003
08: * @version $Revision: 1.2.10.1 $
09: */
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: public void testDifferentVersion() {
31: short version1 = Version.encode(2, 0, 7), version2 = Version
32: .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: public void testBinaryCompatibility() {
46: assertTrue(isBinaryCompatible(0, 0, 0, 0, 0, 0));
47: assertTrue(isBinaryCompatible(1, 2, 0, 1, 2, 1));
48: assertTrue(isBinaryCompatible(1, 2, 0, 1, 2, 60));
49: assertFalse(isBinaryCompatible(2, 5, 0, 2, 4, 1));
50: assertFalse(isBinaryCompatible(2, 5, 0, 2, 6, 0));
51: }
52:
53: private boolean match(int major_1, int minor_1, int micro_1,
54: int major_2, int minor_2, int micro_2) {
55: short version1 = Version.encode(major_1, minor_1, micro_1);
56: short version2 = Version.encode(major_2, minor_2, micro_2);
57: return version1 == version2;
58: }
59:
60: private boolean isBinaryCompatible(int major_1, int minor_1,
61: 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)
66: + " binary compatibel to " + Version.print(version2)
67: + (retval ? " OK" : " FAIL"));
68: return Version.isBinaryCompatible(version1, version2);
69: }
70:
71: public static void main(String[] args) {
72: String[] testCaseName = { VersionTest.class.getName() };
73: junit.textui.TestRunner.main(testCaseName);
74: }
75: }
|