1 30 package org.objectweb.asm.util; 31 32 import java.util.StringTokenizer ; 33 34 import junit.framework.TestCase; 35 import junit.framework.TestSuite; 36 37 import org.objectweb.asm.Opcodes; 38 import org.objectweb.asm.signature.SignatureReader; 39 40 45 public class TraceSignatureVisitorUnitTest extends TestCase { 46 47 public final static String [] DATA = { 48 "C|E|<E extends java.lang.Enum<E>> implements java.lang.Comparable<E>, java.io.Serializable" 49 + "|<E:Ljava/lang/Enum<TE;>;>Ljava/lang/Object;Ljava/lang/Comparable<TE;>;Ljava/io/Serializable;", 50 51 "C|I|<D extends java.lang.reflect.GenericDeclaration> extends java.lang.reflect.Type" 52 + "|<D::Ljava/lang/reflect/GenericDeclaration;>Ljava/lang/Object;Ljava/lang/reflect/Type;", 53 54 "C|C|<K, V> extends java.util.AbstractMap<K, V> implements java.util.concurrent.ConcurrentMap<K, V>, java.io.Serializable" 55 + "|<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;Ljava/util/concurrent/ConcurrentMap<TK;TV;>;Ljava/io/Serializable;", 56 57 "C|C|<K extends java.lang.Enum<K>, V> extends java.util.AbstractMap<K, V> implements java.io.Serializable, java.lang.Cloneable" 58 + "|<K:Ljava/lang/Enum<TK;>;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;Ljava/io/Serializable;Ljava/lang/Cloneable;", 59 60 "F|C|java.lang.Class<?>|Ljava/lang/Class<*>;", 61 62 "F|C|java.lang.reflect.Constructor<T>|Ljava/lang/reflect/Constructor<TT;>;", 63 64 "F|C|T[]|[TT;", 65 66 "F|C|java.util.Hashtable<?, ?>|Ljava/util/Hashtable<**>;", 67 68 "F|C|java.util.concurrent.atomic.AtomicReferenceFieldUpdater<java.io.BufferedInputStream, byte[]>" 69 + "|Ljava/util/concurrent/atomic/AtomicReferenceFieldUpdater<Ljava/io/BufferedInputStream;[B>;", 70 71 "F|C|AA<byte[][]>|LAA<[[B>;", 72 73 "F|C|AA<java.util.Map<java.lang.String, java.lang.String>[][]>" 74 + "|LAA<[[Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;>;", 75 76 "F|C|java.util.Hashtable<java.lang.Object, java.lang.String>" 77 + "|Ljava/util/Hashtable<Ljava/lang/Object;Ljava/lang/String;>;", 78 79 "M|C|void(boolean, byte, char, short, int, float, long, double)" 80 + "|(ZBCSIFJD)V", 81 82 "M|C|void()E, F|()V^TE;^TF;", 83 84 "M|C|java.lang.Class<? extends E><E extends java.lang.Class>()" 85 + "|<E:Ljava/lang/Class;>()Ljava/lang/Class<+TE;>;", 86 87 "M|C|java.lang.Class<? super E><E extends java.lang.Class>()" 88 + "|<E:Ljava/lang/Class;>()Ljava/lang/Class<-TE;>;", 89 90 "M|C|void(A<E>.B)|(LA<TE;>.B;)V", 91 92 "M|C|void(A<E>.B<F>)|(LA<TE;>.B<TF;>;)V", 93 94 "M|C|void(java.lang.String, java.lang.Class<?>, java.lang.reflect.Method[], java.lang.reflect.Method, java.lang.reflect.Method)" 95 + "|(Ljava/lang/String;Ljava/lang/Class<*>;[Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;)V", 96 97 "M|C|java.util.Map<java.lang.Object, java.lang.String>(java.lang.Object, java.util.Map<java.lang.Object, java.lang.String>)" 98 + "|(Ljava/lang/Object;Ljava/util/Map<Ljava/lang/Object;Ljava/lang/String;>;)Ljava/util/Map<Ljava/lang/Object;Ljava/lang/String;>;", 99 100 "M|C|java.util.Map<java.lang.Object, java.lang.String><T>(java.lang.Object, java.util.Map<java.lang.Object, java.lang.String>, T)" 101 + "|<T:Ljava/lang/Object;>(Ljava/lang/Object;Ljava/util/Map<Ljava/lang/Object;Ljava/lang/String;>;TT;)Ljava/util/Map<Ljava/lang/Object;Ljava/lang/String;>;", 102 103 "M|C|java.util.Map<java.lang.Object, java.lang.String><E, T extends java.lang.Comparable<E>>(java.lang.Object, java.util.Map<java.lang.Object, java.lang.String>, T)" 104 + "|<E:Ljava/lang/Object;T::Ljava/lang/Comparable<TE;>;>(Ljava/lang/Object;Ljava/util/Map<Ljava/lang/Object;Ljava/lang/String;>;TT;)Ljava/util/Map<Ljava/lang/Object;Ljava/lang/String;>;", }; 105 106 public static TestSuite suite() { 107 TestSuite suite = new TestSuite(TraceSignatureVisitorUnitTest.class.getName()); 108 for (int i = 0; i < DATA.length; i++) { 109 suite.addTest(new TraceSignatureVisitorUnitTest(new TestData(DATA[i]))); 110 } 111 return suite; 112 } 113 114 private TestData data; 115 116 private TraceSignatureVisitorUnitTest(final TestData data) { 117 super("testSignature"); 118 this.data = data; 119 } 120 121 public void testSignature() { 122 TraceSignatureVisitor d = new TraceSignatureVisitor(data.access); 123 SignatureReader r = new SignatureReader(data.signature); 124 125 switch (data.type) { 126 case 'C': 127 r.accept(d); 128 assertEquals(data.declaration, d.getDeclaration()); 129 break; 130 case 'F': 131 r.acceptType(d); 132 assertEquals(data.declaration, d.getDeclaration()); 133 break; 134 case 'M': 135 r.accept(d); 136 String fullMethodDeclaration = d.getReturnType() 137 + d.getDeclaration() 138 + (d.getExceptions() != null ? d.getExceptions() : ""); 139 assertEquals(data.declaration, fullMethodDeclaration); 140 break; 141 } 142 } 143 144 public String getName() { 145 return super.getName() + " " + data.signature; 146 } 147 148 public static class TestData { 149 150 public final char type; 151 152 public final int access; 153 154 public final String declaration; 155 156 public final String signature; 157 158 public TestData(final String data) { 159 StringTokenizer st = new StringTokenizer (data, "|"); 160 this.type = st.nextToken().charAt(0); 161 162 String acc = st.nextToken(); 163 switch (acc.charAt(0)) { 164 case 'E': 165 this.access = Opcodes.ACC_ENUM; 166 break; 167 case 'I': 168 this.access = Opcodes.ACC_INTERFACE; 169 break; 170 case 'A': 171 this.access = Opcodes.ACC_ANNOTATION; 172 break; 173 default: 174 this.access = 0; 175 } 176 177 this.declaration = st.nextToken(); 178 this.signature = st.nextToken(); 179 } 180 } 181 } 182 | Popular Tags |