]> source.dussan.org Git - aspectj.git/commitdiff
generics: lots of generic decp tests.
authoraclement <aclement>
Mon, 11 Jul 2005 10:46:02 +0000 (10:46 +0000)
committeraclement <aclement>
Mon, 11 Jul 2005 10:46:02 +0000 (10:46 +0000)
tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml

index a385c6b92c4253b758bca831d7dcf8689b8a664f..d148b9850d6afad937e4d3e61acfa4ddf1f27c82 100644 (file)
@@ -4,6 +4,11 @@ import java.io.File;
 
 import junit.framework.Test;
 
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.classfile.Signature;
+import org.aspectj.apache.bcel.util.ClassPath;
+import org.aspectj.apache.bcel.util.SyntheticRepository;
 import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class GenericsTests extends XMLBasedAjcTestCase {
@@ -97,14 +102,54 @@ public class GenericsTests extends XMLBasedAjcTestCase {
 //             runTest("itd incorrectly using type parameter");
 //     }
 
-       // generic declare parents
+       // ----------------------------------------------------------------------------------------
+       // generic declare parents tests
+       // ----------------------------------------------------------------------------------------
+       
        public void testPR96220_GenericDecp() {
                runTest("generic decp - simple");
+               verifyClassSignature("Basic","Ljava/lang/Object;LJ<Ljava/lang/Double;>;LI<Ljava/lang/Double;>;");
+       }
+       
+       // Both the existing type decl and the one adding via decp are parameterized
+       public void testGenericDecpMultipleVariantsOfAParameterizedType1() {
+               runTest("generic decp - implementing two variants #1");
+       }
+
+       // Existing type decl is raw and the one added via decp is parameterized
+       public void testGenericDecpMultipleVariantsOfAParameterizedType2() {
+               runTest("generic decp - implementing two variants #2");
+       }
+
+       // Existing type decl is parameterized and the one added via decp is raw
+       public void testGenericDecpMultipleVariantsOfAParameterizedType3() {
+               runTest("generic decp - implementing two variants #3");
+       }
+
+       // decp is parameterized but it does match the one already on the type
+       public void testGenericDecpMultipleVariantsOfAParameterizedType4() {
+               runTest("generic decp - implementing two variants #4");
+       }
+       
+       // same as above four tests for binary weaving
+       public void testGenericDecpMultipleVariantsOfAParameterizedType1_binaryWeaving() {
+               runTest("generic decp binary - implementing two variants #1");
+       }
+       
+       public void testGenericDecpMultipleVariantsOfAParameterizedType2_binaryWeaving() {
+               runTest("generic decp binary - implementing two variants #2");
+       }
+
+       // Existing type decl is parameterized and the one added via decp is raw
+       public void testGenericDecpMultipleVariantsOfAParameterizedType3_binaryWeaving() {
+               runTest("generic decp binary - implementing two variants #3");
+       }
+
+       // decp is parameterized but it does match the one already on the type
+       public void testGenericDecpMultipleVariantsOfAParameterizedType4_binaryWeaving() {
+               runTest("generic decp binary - implementing two variants #4");
        }
        
-//     public void testGenericDecpMultipleVariantsOfAParameterizedType() {
-//             runTest("generic decp - implementing two variants");
-//     }
 //     
 //     public void testGenericDecpIncorrectNumberOfTypeParams() {
 //             runTest("generic decp - incorrect number of type parameters");
@@ -132,4 +177,28 @@ public class GenericsTests extends XMLBasedAjcTestCase {
        
        // 1. public ITDs and separate compilation - are the signatures correct for the new public members?
        // 2. ITDF
+       
+       // --- helpers
+       
+       // Check the signature attribute on a class is correct
+       private void verifyClassSignature(String classname,String sig) {
+               try {
+                       ClassPath cp = 
+                               new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path"));
+                   SyntheticRepository sRepos =  SyntheticRepository.getInstance(cp);
+                       JavaClass clazz = sRepos.loadClass(classname);
+                       Signature sigAttr = null;
+                       Attribute[] attrs = clazz.getAttributes();
+                       for (int i = 0; i < attrs.length; i++) {
+                               Attribute attribute = attrs[i];
+                               if (attribute.getName().equals("Signature")) sigAttr = (Signature)attribute;
+                       }
+                       assertTrue("Failed to find signature attribute for class "+classname,sigAttr!=null);
+                       assertTrue("Expected signature to be '"+sig+"' but was '"+sigAttr.getSignature()+"'",
+                                       sigAttr.getSignature().equals(sig));
+               } catch (ClassNotFoundException e) {
+                       fail("Couldn't find class "+classname+" in the sandbox directory.");
+               }
+       }
+       
 }
index 32155d55414f2ebd8f72004edaa524b1ffa0083f..bc11dfeb47b9e16b2f5ecf005d67440935e947ce 100644 (file)
      <run class="Basic"/>
    </ajc-test>
    
-   <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants">
-     <compile files="Basic2.aj" options="-1.5"/>
-     <run class="Basic2"/>
+   <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants #1">
+     <compile files="Basic2.aj" options="-1.5">
+        <message kind="error" line="11" text="Cannot declare parent I&lt;java.lang.Integer&gt; onto type Basic2 since it already has I&lt;java.lang.String&gt; in its hierarchy"/>
+     </compile>
+   </ajc-test>
+   
+   <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants #2">
+     <compile files="Basic2b.aj" options="-1.5">
+        <message kind="error" line="10" text="Cannot declare parent I&lt;java.lang.Integer&gt; onto type Basic2b since it already has I in its hierarchy"/>
+     </compile>
+   </ajc-test>
+   
+   <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants #3">
+     <compile files="Basic2c.aj" options="-1.5">
+        <message kind="error" line="10" text="Cannot declare parent I onto type Basic2c since it already has I&lt;java.lang.Double&gt; in its hierarchy"/>
+     </compile>
+   </ajc-test>
+   
+   <ajc-test dir="java5/generics/decp" title="generic decp - implementing two variants #4">
+     <compile files="Basic2d.aj" options="-1.5"/>
    </ajc-test>
+
+   <ajc-test dir="java5/generics/decp/binary" title="generic decp binary - implementing two variants #1">
+     <weave classesFiles="Base1.java" aspectsFiles="Asp1.aj" options="-1.5,-showWeaveInfo">
+        <message kind="error" line="2" text="Cannot declare parent I&lt;java.lang.Integer&gt; onto type Base1 since it already has I&lt;java.lang.String&gt; in its hierarchy"/>
+     </weave>
+   </ajc-test>
+   
+   <ajc-test dir="java5/generics/decp/binary" title="generic decp binary - implementing two variants #2">
+     <weave classesFiles="Base2.java" aspectsFiles="Asp2.aj" options="-1.5,-showWeaveInfo">
+        <message kind="error" line="2" text="Cannot declare parent I&lt;java.lang.Integer&gt; onto type Base2 since it already has I in its hierarchy"/>
+     </weave>
+   </ajc-test>
+   
+   <ajc-test dir="java5/generics/decp/binary" title="generic decp binary - implementing two variants #3">
+     <weave classesFiles="Base3.java" aspectsFiles="Asp3.aj" options="-1.5,-showWeaveInfo">
+        <message kind="error" line="2" text="Cannot declare parent I onto type Base3 since it already has I&lt;java.lang.Double&gt; in its hierarchy"/>
+     </weave>
+   </ajc-test>
+   
+   <ajc-test dir="java5/generics/decp/binary" title="generic decp binary - implementing two variants #4">
+     <weave classesFiles="Base4.java" aspectsFiles="Asp4.aj" options="-1.5,-showWeaveInfo"/>
+   </ajc-test>
+
+<!--                 -->
    
    <ajc-test dir="java5/generics/decp" title="generic decp - incorrect number of type parameters">
      <compile files="Basic3.aj" options="-1.5"/>