You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ej...@apache.org on 2011/11/29 18:24:01 UTC
svn commit: r1207981 [2/2] - in /aries/trunk/versioning/versioning-checker:
./ src/main/java/org/apache/aries/versioning/check/
src/main/java/org/apache/aries/versioning/utils/
src/test/java/org/apache/aries/versioning/impl/org/apache/aries/versioning/...
Modified: aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/BinaryCompatibilityTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/BinaryCompatibilityTest.java?rev=1207981&r1=1207231&r2=1207981&view=diff
==============================================================================
--- aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/BinaryCompatibilityTest.java (original)
+++ aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/BinaryCompatibilityTest.java Tue Nov 29 17:23:57 2011
@@ -1,3 +1,5 @@
+
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -16,9 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-package org.apache.aries.versioning.impl.org.apache.aries.versioning.utils;
-
+package org.apache.aries.versioning.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -43,7 +43,10 @@ import java.util.Collection;
import java.util.HashSet;
import org.apache.aries.versioning.utils.BinaryCompatibilityStatus;
+import org.apache.aries.versioning.utils.MethodDeclaration;
import org.apache.aries.versioning.utils.SemanticVersioningClassVisitor;
+import static org.apache.aries.versioning.utils.SemanticVersioningUtils.htmlOneLineBreak;
+import static org.apache.aries.versioning.utils.SemanticVersioningUtils.htmlTwoLineBreaks;
import org.junit.BeforeClass;
import org.junit.Test;
import org.objectweb.asm.ClassReader;
@@ -53,6 +56,8 @@ import org.objectweb.asm.ClassWriter;
/**
* Test the jdk chap 13 -binary compatibility implementation
*
+ * @author emily
+ *
*/
public class BinaryCompatibilityTest
{
@@ -95,7 +100,7 @@ public class BinaryCompatibilityTest
"When a class is changed from non abstract to abstract, this should break binary compatibility.",
bcs.isCompatible());
- assertEquals("The class pkg/Test was not abstract but is changed to be abstract.", bcs.getReason());
+ assertEquals(" The class pkg/Test was not abstract but is changed to be abstract.", bcs.getReason());
}
/**
@@ -160,7 +165,7 @@ public class BinaryCompatibilityTest
"When a class is changed from non final to final, this should break binary compatibility.",
bcs.isCompatible());
- assertEquals("The class pkg/Test was not final but is changed to be final.", bcs.getReason());
+ assertEquals(" The class pkg/Test was not final but is changed to be final.", bcs.getReason());
}
/**
@@ -261,7 +266,8 @@ public class BinaryCompatibilityTest
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
- cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
+ cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestBChild", null);
+
cw.visitEnd();
byte[] newBytes = cw.toByteArray();
SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
@@ -275,7 +281,67 @@ public class BinaryCompatibilityTest
"Changing the direct superclass or the set of direct superinterfaces of a class type will not breake binary compatibility if not losing any members.",
newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration())).isCompatible());
}
+
+ /**
+ * Changing field type breaks binary compatibility
+ * with pre-existing binaries, provided that the total set of superclasses or superinterfaces, respectively, of the class type loses no members but the one of the fields has changed type.
+ */
+ @Test
+ public void test_jdk_chap13_4_7_4() throws IOException
+ {
+ ClassWriter cw = new ClassWriter(0);
+ cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", new String[] { "versioning/java/files/TestB" });
+ cw.visitEnd();
+ byte[] oldBytes = cw.toByteArray();
+
+ cw = new ClassWriter(0);
+ cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
+
+ cw.visitEnd();
+ byte[] newBytes = cw.toByteArray();
+ SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
+ SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
+ ClassReader newCR = new ClassReader(newBytes);
+ ClassReader oldCR = new ClassReader(oldBytes);
+
+ newCR.accept(newCV, 0);
+ oldCR.accept(oldCV, 0);
+ BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
+ assertFalse(
+ "Changing the direct superclass or the set of direct superinterfaces of a class type results fields changes. This should breake binary compatibility if not losing any members.",
+ bcs.isCompatible());
+ assertEquals(" The public field bar was static but is changed to be non static or vice versa. The public field bar has changed its type.", bcs.getReason());
+ }
+
+ /**
+ * Change the signature of the field from Colllection<AA> to Collection<String>
+ */
+ @Test
+ public void test_jdk_chap13_4_7_5() {
+ ClassWriter cw = new ClassWriter(0);
+ cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", null);
+ cw.visitField(ACC_PUBLIC, "more", "Ljava/util/Collection;", "Lcom/bim/AA;", null).visitEnd();
+ cw.visitEnd();
+ byte[] oldBytes = cw.toByteArray();
+
+ cw = new ClassWriter(0);
+ cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", null);
+ cw.visitField(ACC_PROTECTED, "more", "Ljava/util/Collection;", "Ljava/lang/String;", null).visitEnd();
+ cw.visitEnd();
+ byte[] newBytes = cw.toByteArray();
+ SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
+ SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
+ ClassReader newCR = new ClassReader(newBytes);
+ ClassReader oldCR = new ClassReader(oldBytes);
+ newCR.accept(newCV, 0);
+ oldCR.accept(oldCV, 0);
+ BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
+ assertEquals(htmlOneLineBreak +"The public field more has changed its type. The public field more becomes less accessible.", bcs.getReason());
+ assertFalse(
+ "Changing the declared access of a field to permit less access , this should break binary compatibility.",
+ bcs.isCompatible());
+ }
/**
* If a change to the direct superclass or the set of direct superinterfaces results in any class or interface no longer being a superclass or superinterface, respectively, it will break binary compatibility.
*/
@@ -303,7 +369,7 @@ public class BinaryCompatibilityTest
assertFalse(
"If a change to the direct superclass or the set of direct superinterfaces results in any class or interface no longer being a superclass or superinterface, respectively, it will break binary compatibility.",
bcs.isCompatible());
- assertEquals("The superclasses or superinterfaces have stopped being super: [versioning/java/files/TestC, versioning/java/files/TestA]", bcs.getReason());
+ assertEquals(" The superclasses or superinterfaces have stopped being super: [versioning/java/files/TestC, versioning/java/files/TestA]. The method int getFooLen(java.lang.String) has been deleted or its return type or parameter list has changed. The method int getBooLen(java.lang.String) has been deleted or its return type or parameter list has changed. The method java.lang.String getFoo() has changed from non abstract to abstract. The method int getBarLen(java.lang.String) has been deleted or its return type or parameter list has changed. The protcted field c has been deleted. The public field bar was not final but has been changed to be final. The public field bar was static but is changed to be non static or vice versa. The public field bar has changed its type.", bcs.getReason());
}
/**
@@ -330,7 +396,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int convert(java/lang/Object) has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int convert(java.lang.Object) has been deleted or its return type or parameter list has changed.", bcs.getReason());
assertFalse(
"deleting a class member or constructor that is not declared private breaks binary compatibility.",
bcs.isCompatible());
@@ -418,7 +484,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int convert(java/lang/Object) is less accessible.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int convert(java.lang.Object) is less accessible.", bcs.getReason());
assertFalse(
"Changing the declared access of a member or contructor to permit less access , this should break binary compatibility.",
bcs.isCompatible());
@@ -445,7 +511,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The public or protected field lESS is less accessible.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The public field lESS becomes less accessible.", bcs.getReason());
assertFalse(
"Changing the declared access of a field to permit less access , this should break binary compatibility.",
bcs.isCompatible());
@@ -504,7 +570,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The new field bar conflicts with the same field in its super class. For more details, check the Binary Compatibility section(Chapter 13) of the Java Specification.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The public field bar becomes less accessible.", bcs.getReason());
assertFalse(
"The new field conflicts with a field in the super class. Check chapter 13.4.7 java spec for more info.",
bcs.isCompatible());
@@ -537,7 +603,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The public or protected field aa was not final but has been changed to be final.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The public field aa was not final but has been changed to be final.", bcs.getReason());
assertFalse(
"Change that a public or protected field was final but is changed to be not final will break binary compatibility.",
bcs.isCompatible());
@@ -601,7 +667,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The public or protected field aa was static but is changed to be non static or vice versa.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The public field aa was static but is changed to be non static or vice versa.", bcs.getReason());
assertFalse(
"If a field was static is changed to be non-static, then it will break compatibility.",
bcs.isCompatible());
@@ -634,7 +700,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The public or protected field aa was static but is changed to be non static or vice versa.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The public field aa was static but is changed to be non static or vice versa.", bcs.getReason());
assertFalse(
"If a field was non-static is changed to be static, then it will break compatibility.",
bcs.isCompatible());
@@ -731,7 +797,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getFooLen(java/lang/STring) has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getFooLen(java.lang.STring) has been deleted or its return type or parameter list has changed.", bcs.getReason());
assertFalse(
"Deleting a public/protected method when there is no such a method in the superclass breaks binary compatibility.",
bcs.isCompatible());
@@ -794,7 +860,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getFooLen(java/lang/String) has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getFooLen(java.lang.String) is less accessible.", bcs.getReason());
assertFalse(
"If a change to the direct superclass or the set of direct superinterfaces results in any class or interface no longer being a superclass or superinterface, respectively, it will break binary compatibility.",
bcs.isCompatible());
@@ -827,7 +893,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getCooLen(java/lang/String) has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getCooLen(java.lang.String) has been deleted or its return type or parameter list has changed.", bcs.getReason());
assertFalse(
"Changing a parameter list will break binary compatibility.",
bcs.isCompatible());
@@ -850,7 +916,7 @@ public class BinaryCompatibilityTest
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitField(ACC_PUBLIC + ACC_TRANSIENT, "aa", "Ljava/lang/String;", null, new String("newBar")).visitEnd();
- cw.visitMethod(ACC_PUBLIC, "getCooLen", "(Ljava/lang/Object)I", null, null).visitEnd();
+ cw.visitMethod(ACC_PUBLIC, "getCooLen", "(Ljava/lang/Object;)I", null, null).visitEnd();
cw.visitEnd();
byte[] newBytes = cw.toByteArray();
SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
@@ -861,13 +927,44 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getCooLen(java/lang/String) has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getCooLen(java.lang.String) has been deleted or its return type or parameter list has changed.", bcs.getReason());
assertFalse(
"Changing a method paramether type will break binary compatibility.",
bcs.isCompatible());
}
/**
+ * Changing a method formal type parameter is not a binary compatibility change.
+ */
+ @Test
+ public void test_jdk_chap13_4_12_3()
+ {
+ ClassWriter cw = new ClassWriter(0);
+ cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
+ cw.visitMethod(ACC_PUBLIC, "getCooLen", "(Ljava/util/List;)I", "Ljava/lang/String;", null).visitEnd();
+ cw.visitEnd();
+ byte[] oldBytes = cw.toByteArray();
+
+
+ cw = new ClassWriter(0);
+ cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
+
+ cw.visitMethod(ACC_PUBLIC, "getCooLen", "(Ljava/util/List;)I", "Lcome/ibm/blah;", null).visitEnd();
+ cw.visitEnd();
+ byte[] newBytes = cw.toByteArray();
+ SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
+ SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
+ ClassReader newCR = new ClassReader(newBytes);
+ ClassReader oldCR = new ClassReader(oldBytes);
+
+ newCR.accept(newCV, 0);
+ oldCR.accept(oldCV, 0);
+ BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
+ assertTrue(
+ "Changing a method formal type parameter should not break binary compatibility.",
+ bcs.isCompatible());
+ }
+ /**
* Changing a method return type is a binary compatibility change.
*/
@Test
@@ -894,7 +991,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getCooLen(java/lang/String) has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getCooLen(java.lang.String) has been deleted or its return type or parameter list has changed.", bcs.getReason());
assertFalse(
"Changing a method return type will break binary compatibility.",
bcs.isCompatible());
@@ -927,7 +1024,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getCooLen(java/lang/String) has changed from non abstract to abstract. ", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getCooLen(java.lang.String) has changed from non abstract to abstract. ", bcs.getReason());
assertFalse(
"Changing a method to be abstract will break binary compatibility.",
bcs.isCompatible());
@@ -992,7 +1089,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getCooLen(java/lang/String) was not final but has been changed to be final.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getCooLen(java.lang.String) was not final but has been changed to be final.", bcs.getReason());
assertFalse(
"Changing an instance method from non-final to final will break binary compatibility.",
bcs.isCompatible());
@@ -1149,7 +1246,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getCooLen(java/lang/String) has changed from static to non-static or vice versa.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getCooLen(java.lang.String) has changed from static to non-static or vice versa.", bcs.getReason());
assertFalse(
"If a method is not private was not declared static and is changed to be decalared static, this should break compatibility.",
bcs.isCompatible());
@@ -1182,7 +1279,7 @@ public class BinaryCompatibilityTest
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getCooLen(java/lang/String) has changed from static to non-static or vice versa.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getCooLen(java.lang.String) has changed from static to non-static or vice versa.", bcs.getReason());
assertFalse(
"If a method is not private was declared static and is changed to not be decalared static, this should break compatibility.",
bcs.isCompatible());
@@ -1369,7 +1466,7 @@ public class BinaryCompatibilityTest
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The superclasses or superinterfaces have stopped being super: [versioning/java/files/TestB]", bcs.getReason());
+ assertEquals(" The method java.lang.String getFoo() has been deleted or its return type or parameter list has changed. The public field bar has been deleted. The superclasses or superinterfaces have stopped being super: [versioning/java/files/TestB]." , bcs.getReason());
assertFalse(
"Changes to the interface hierarchy resulting an interface not being a super interface should break compatibility.",
bcs.isCompatible());
@@ -1402,7 +1499,7 @@ public class BinaryCompatibilityTest
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getFoo() has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getFoo() has been deleted or its return type or parameter list has changed.", bcs.getReason());
assertFalse(
"Deleting a method in an interface should break compatibility.",
bcs.isCompatible());
@@ -1468,7 +1565,7 @@ public class BinaryCompatibilityTest
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getFoo() has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getFoo() has been deleted or its return type or parameter list has changed.", bcs.getReason());
assertFalse(
"Changing a method return type in an interface should break compatibility.",
bcs.isCompatible());
@@ -1502,7 +1599,7 @@ public class BinaryCompatibilityTest
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
- assertEquals("The method int getFoo(int) has been deleted or its return type or parameter list has changed.", bcs.getReason());
+ assertEquals(htmlOneLineBreak +"The method int getFoo(int) has been deleted or its return type or parameter list has changed.", bcs.getReason());
assertFalse(
"Changing a method parameter in an interface should break compatibility.",
bcs.isCompatible());
@@ -1539,9 +1636,12 @@ public class BinaryCompatibilityTest
"Adding an abstract methods should not break compatibility.",
newCV.getClassDeclaration().getBinaryCompatibleStatus(oldCV.getClassDeclaration()).isCompatible());
- assertEquals(
- "getMoo",
- newCV.getClassDeclaration().getExtraMethods(oldCV.getClassDeclaration()).getName());
+ Collection<MethodDeclaration> extraMethods = newCV.getClassDeclaration().getExtraMethods(oldCV.getClassDeclaration());
+ assertEquals(1, extraMethods.size());
+ for (MethodDeclaration md : extraMethods) {
+ assertEquals(
+ "getMoo", md.getName());
+ }
}
/**
@@ -1576,9 +1676,45 @@ public class BinaryCompatibilityTest
newCV.getClassDeclaration().getBinaryCompatibleStatus(oldCV.getClassDeclaration()).isCompatible());
- assertNull(
- "Containing more abstract methods should return false.",
- newCV.getClassDeclaration().getExtraMethods(oldCV.getClassDeclaration()));
+ assertEquals(
+ "Containing more abstract methods should return false.", 0,
+ newCV.getClassDeclaration().getExtraMethods(oldCV.getClassDeclaration()).size());
+ }
+
+ @Test
+ public void test_ignore_clinit()
+ {
+ ClassWriter cw = new ClassWriter(0);
+ cw.visit(V1_5, ACC_PUBLIC , "pkg/Test", null, "java/lang/Object", new String[]{"versioning/java/files/TestB"});
+ cw.visitField(ACC_PUBLIC , "foo", "I", null, null).visitEnd();
+ cw.visitEnd();
+ byte[] oldBytes = cw.toByteArray();
+
+
+ cw = new ClassWriter(0);
+ cw.visit(V1_5, ACC_PUBLIC , "pkg/Test", null, "java/lang/Object", new String[]{"versioning/java/files/TestB"});
+ cw.visitField(ACC_PUBLIC + ACC_STATIC , "bar", "I", null, null).visitEnd();
+ cw.visitField(ACC_PUBLIC , "foo", "I", null, null).visitEnd();
+ cw.visitMethod(ACC_PUBLIC , "<clinit>", "()V", null, null).visitEnd();
+
+ cw.visitEnd();
+ byte[] newBytes = cw.toByteArray();
+ SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
+ SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
+ ClassReader newCR = new ClassReader(newBytes);
+ ClassReader oldCR = new ClassReader(oldBytes);
+
+ newCR.accept(newCV, 0);
+ oldCR.accept(oldCV, 0);
+
+ assertTrue(
+ "No change should not break compatibility.",
+ newCV.getClassDeclaration().getBinaryCompatibleStatus(oldCV.getClassDeclaration()).isCompatible());
+
+
+ assertEquals(
+ "Containing more abstract methods should return false.", 0,
+ newCV.getClassDeclaration().getExtraMethods(oldCV.getClassDeclaration()).size());
}
}
Modified: aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/SemanticVersionUtilsTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/SemanticVersionUtilsTest.java?rev=1207981&r1=1207231&r2=1207981&view=diff
==============================================================================
--- aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/SemanticVersionUtilsTest.java (original)
+++ aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/SemanticVersionUtilsTest.java Tue Nov 29 17:23:57 2011
@@ -1,3 +1,5 @@
+
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -16,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.aries.versioning.impl.org.apache.aries.versioning.utils;
+package org.apache.aries.versioning.tests;
import static org.junit.Assert.assertEquals;
import org.apache.aries.versioning.utils.SemanticVersioningUtils;
@@ -32,50 +34,50 @@ public class SemanticVersionUtilsTest
String returnStr = SemanticVersioningUtils.getReadableMethodSignature( "getAccountNum", "(Ljava/lang/String;)Ljava/lang/String;");
- String expectedStr = "method java/lang/String getAccountNum(java/lang/String)";
+ String expectedStr = "method java.lang.String getAccountNum(java.lang.String)";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
returnStr = SemanticVersioningUtils.getReadableMethodSignature( "handleNotification", "(Ljavax/management/Notification;Ljava/lang/Object;)V");
- expectedStr = "method void handleNotification(javax/management/Notification, java/lang/Object)";
+ expectedStr = "method void handleNotification(javax.management.Notification, java.lang.Object)";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
- returnStr = SemanticVersioningUtils.getReadableMethodSignature("addItemDeepCopy", "(Lcom/ibm/xml/xci/Cursor$Area;Lcom/ibm/xml/xci/Cursor;Lcom/ibm/xml/xci/Cursor$Profile;Lcom/ibm/xml/xci/Cursor$Profile;ZZZ)Lcom/ibm/xml/xci/Cursor;");
- expectedStr = "method com/ibm/xml/xci/Cursor addItemDeepCopy(com/ibm/xml/xci/Cursor$Area, com/ibm/xml/xci/Cursor, com/ibm/xml/xci/Cursor$Profile, com/ibm/xml/xci/Cursor$Profile, boolean, boolean, boolean)";
+ returnStr = SemanticVersioningUtils.getReadableMethodSignature("addItemDeepCopy", "(Lcom/xml/xci/Cursor$Area;Lcom/xml/xci/Cursor;Lcom/xml/xci/Cursor$Profile;Lcom/xml/xci/Cursor$Profile;ZZZ)Lcom/xml/xci/Cursor;");
+ expectedStr = "method com.xml.xci.Cursor addItemDeepCopy(com.xml.xci.Cursor$Area, com.xml.xci.Cursor, com.xml.xci.Cursor$Profile, com.xml.xci.Cursor$Profile, boolean, boolean, boolean)";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
- returnStr = SemanticVersioningUtils.getReadableMethodSignature("createParserAndCompiler", "(Ljavax/xml/transform/Source;Lcom/ibm/xltxe/rnm1/xtq/exec/XTQStaticContext;Lcom/ibm/xltxe/rnm1/xtq/common/utils/ErrorHandler;)Lcom/ibm/xltxe/rnm1/xtq/xquery/drivers/XQueryCompiler;");
- expectedStr = "method com/ibm/xltxe/rnm1/xtq/xquery/drivers/XQueryCompiler createParserAndCompiler(javax/xml/transform/Source, com/ibm/xltxe/rnm1/xtq/exec/XTQStaticContext, com/ibm/xltxe/rnm1/xtq/common/utils/ErrorHandler)";
+ returnStr = SemanticVersioningUtils.getReadableMethodSignature("createParserAndCompiler", "(Ljavax/xml/transform/Source;Lcom/xltxe/rnm1/xtq/exec/XTQStaticContext;Lcom/xltxe/rnm1/xtq/common/utils/ErrorHandler;)Lcom/xltxe/rnm1/xtq/xquery/drivers/XQueryCompiler;");
+ expectedStr = "method com.xltxe.rnm1.xtq.xquery.drivers.XQueryCompiler createParserAndCompiler(javax.xml.transform.Source, com.xltxe.rnm1.xtq.exec.XTQStaticContext, com.xltxe.rnm1.xtq.common.utils.ErrorHandler)";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
- returnStr = SemanticVersioningUtils.getReadableMethodSignature("getAxis", "()Lcom/ibm/xml/xci/exec/Axis;");
- expectedStr = "method com/ibm/xml/xci/exec/Axis getAxis()";
+ returnStr = SemanticVersioningUtils.getReadableMethodSignature("getAxis", "()Lcom/xml/xci/exec/Axis;");
+ expectedStr = "method com.xml.xci.exec.Axis getAxis()";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
- returnStr = SemanticVersioningUtils.getReadableMethodSignature("createEmpty", "()Lcom/ibm/xml/xci/dp/cache/dom/InternalNodeData;");
- expectedStr = "method com/ibm/xml/xci/dp/cache/dom/InternalNodeData createEmpty()";
+ returnStr = SemanticVersioningUtils.getReadableMethodSignature("createEmpty", "()Lcom/xml/xci/dp/cache/dom/InternalNodeData;");
+ expectedStr = "method com.xml.xci.dp.cache.dom.InternalNodeData createEmpty()";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
returnStr = SemanticVersioningUtils.getReadableMethodSignature("addElement", "(Lorg/w3c/dom/Node;)V");
- expectedStr = "method void addElement(org/w3c/dom/Node)";
+ expectedStr = "method void addElement(org.w3c.dom.Node)";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
- returnStr = SemanticVersioningUtils.getReadableMethodSignature("isExternalFunctionCall", "(Lcom/ibm/xltxe/rnm1/xtq/ast/nodes/FunctionCall;Lcom/ibm/xltxe/rnm1/xtq/xpath/drivers/XPathCompiler;)Z");
- expectedStr = "method boolean isExternalFunctionCall(com/ibm/xltxe/rnm1/xtq/ast/nodes/FunctionCall, com/ibm/xltxe/rnm1/xtq/xpath/drivers/XPathCompiler)";
+ returnStr = SemanticVersioningUtils.getReadableMethodSignature("isExternalFunctionCall", "(Lcom/xltxe/rnm1/xtq/ast/nodes/FunctionCall;Lcom/xltxe/rnm1/xtq/xpath/drivers/XPathCompiler;)Z");
+ expectedStr = "method boolean isExternalFunctionCall(com.xltxe.rnm1.xtq.ast.nodes.FunctionCall, com.xltxe.rnm1.xtq.xpath.drivers.XPathCompiler)";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
- returnStr = SemanticVersioningUtils.getReadableMethodSignature("wrapForTracing", "(Lcom/ibm/xltxe/rnm1/xtq/xslt/runtime/output/ResultTreeSequenceWriterStream$TraceOutputEventGenerator;Lcom/ibm/xml/xci/SessionContext;Lcom/ibm/xml/xci/Cursor;Lcom/ibm/xml/xci/RequestInfo;Lcom/ibm/xltxe/rnm1/xtq/xslt/runtime/output/ResultTreeSequenceWriterStream$DeferredTraceResultTreeSequenceWriterStream;)Lcom/ibm/xml/xci/Cursor;");
- expectedStr = "method com/ibm/xml/xci/Cursor wrapForTracing(com/ibm/xltxe/rnm1/xtq/xslt/runtime/output/ResultTreeSequenceWriterStream$TraceOutputEventGenerator, com/ibm/xml/xci/SessionContext, com/ibm/xml/xci/Cursor, com/ibm/xml/xci/RequestInfo, com/ibm/xltxe/rnm1/xtq/xslt/runtime/output/ResultTreeSequenceWriterStream$DeferredTraceResultTreeSequenceWriterStream)";
+ returnStr = SemanticVersioningUtils.getReadableMethodSignature("wrapForTracing", "(Lcom/xltxe/rnm1/xtq/xslt/runtime/output/ResultTreeSequenceWriterStream$TraceOutputEventGenerator;Lcom/xml/xci/SessionContext;Lcom/xml/xci/Cursor;Lcom/xml/xci/RequestInfo;Lcom/xltxe/rnm1/xtq/xslt/runtime/output/ResultTreeSequenceWriterStream$DeferredTraceResultTreeSequenceWriterStream;)Lcom/xml/xci/Cursor;");
+ expectedStr = "method com.xml.xci.Cursor wrapForTracing(com.xltxe.rnm1.xtq.xslt.runtime.output.ResultTreeSequenceWriterStream$TraceOutputEventGenerator, com.xml.xci.SessionContext, com.xml.xci.Cursor, com.xml.xci.RequestInfo, com.xltxe.rnm1.xtq.xslt.runtime.output.ResultTreeSequenceWriterStream$DeferredTraceResultTreeSequenceWriterStream)";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
returnStr = SemanticVersioningUtils.getReadableMethodSignature("<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/security/Key;Ljava/security/Key;Ljava/security/cert/Certificate;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IJJLjava/lang/String;)V");
- expectedStr = "constructor with parameter list (java/lang/String, java/lang/String, java/lang/String, java/security/Key, java/security/Key, java/security/cert/Certificate, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, java/lang/String, int, long, long, java/lang/String)";
+ expectedStr = "constructor with parameter list (java.lang.String, java.lang.String, java.lang.String, java.security.Key, java.security.Key, java.security.cert.Certificate, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, int, long, long, java.lang.String)";
assertEquals("The return str is incorrect.", expectedStr, returnStr);
}
Added: aries/trunk/versioning/versioning-checker/src/test/java/versioning/java/files/TestBChild.java
URL: http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-checker/src/test/java/versioning/java/files/TestBChild.java?rev=1207981&view=auto
==============================================================================
--- aries/trunk/versioning/versioning-checker/src/test/java/versioning/java/files/TestBChild.java (added)
+++ aries/trunk/versioning/versioning-checker/src/test/java/versioning/java/files/TestBChild.java Tue Nov 29 17:23:57 2011
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package versioning.java.files;
+public interface TestBChild extends TestB{
+ public String getBar();
+
+}
\ No newline at end of file