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 TraceSignatureVisitorTest extends TestCase { 46 47 private static String [] DATA = { 48 "C|E|<E extends java.lang.Enum<E>> implements java.lang.Comparable<E>, java.io.Serializable|<E:Ljava/lang/Enum<TE;>;>Ljava/lang/Object;Ljava/lang/Comparable<TE;>;Ljava/io/Serializable;", 49 "C|I|<D extends java.lang.reflect.GenericDeclaration> extends java.lang.reflect.Type|<D::Ljava/lang/reflect/GenericDeclaration;>Ljava/lang/Object;Ljava/lang/reflect/Type;", 50 "C|C|<K, V> extends java.util.AbstractMap<K, V> implements java.util.concurrent.ConcurrentMap<K, V>, java.io.Serializable|<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;Ljava/util/concurrent/ConcurrentMap<TK;TV;>;Ljava/io/Serializable;", 51 "C|C|<K extends java.lang.Enum<K>, V> extends java.util.AbstractMap<K, V> implements java.io.Serializable, java.lang.Cloneable|<K:Ljava/lang/Enum<TK;>;V:Ljava/lang/Object;>Ljava/util/AbstractMap<TK;TV;>;Ljava/io/Serializable;Ljava/lang/Cloneable;", 52 "F|C|java.lang.Class<?>|Ljava/lang/Class<*>;", 53 "F|C|java.lang.reflect.Constructor<T>|Ljava/lang/reflect/Constructor<TT;>;", 54 "F|C|T[]|[TT;", 55 "F|C|java.util.Hashtable<?, ?>|Ljava/util/Hashtable<**>;", 56 "F|C|java.util.concurrent.atomic.AtomicReferenceFieldUpdater<java.io.BufferedInputStream, byte[]>|Ljava/util/concurrent/atomic/AtomicReferenceFieldUpdater<Ljava/io/BufferedInputStream;[B>;", 57 "M|C|(java.lang.String, java.lang.Class<?>, java.lang.reflect.Method[], java.lang.reflect.Method, java.lang.reflect.Method)|(Ljava/lang/String;Ljava/lang/Class<*>;[Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;)V", 58 "F|C|AA<byte[][]>|LAA<[[B>;", 59 "F|C|AA<java.util.Map<java.lang.String, java.lang.String>[][]>|LAA<[[Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;>;", 60 "M|C|()|()V^TE;" }; 61 62 public static TestSuite suite() { 63 TestSuite suite = new TestSuite(TraceSignatureVisitorTest.class.getName()); 64 65 for (int i = 0; i < DATA.length; i++) { 66 suite.addTest(new TraceSignatureVisitorTest(new TestData(DATA[i]))); 67 } 68 69 return suite; 70 } 71 72 private TestData data; 73 74 private TraceSignatureVisitorTest(TestData data) { 75 super("testSignature"); 76 this.data = data; 77 } 78 79 public void testSignature() { 80 TraceSignatureVisitor d = new TraceSignatureVisitor(data.access); 81 SignatureReader r = new SignatureReader(data.signature); 82 83 switch (data.type) { 84 case 'C': 85 r.accept(d); 86 break; 87 case 'F': 88 r.acceptType(d); 89 break; 90 case 'M': 91 r.accept(d); 92 break; 93 } 94 95 assertEquals(data.declaration, d.getDeclaration()); 96 } 97 98 public String getName() { 99 return super.getName() + " " + data.signature; 100 } 101 102 private static class TestData { 103 104 public final char type; 105 106 public final int access; 107 108 public final String declaration; 109 110 public final String signature; 111 112 private TestData(String data) { 113 StringTokenizer st = new StringTokenizer (data, "|"); 114 this.type = st.nextToken().charAt(0); 115 116 String acc = st.nextToken(); 117 switch (acc.charAt(0)) { 118 case 'E': 119 this.access = Opcodes.ACC_ENUM; 120 break; 121 case 'I': 122 this.access = Opcodes.ACC_INTERFACE; 123 break; 124 case 'A': 125 this.access = Opcodes.ACC_ANNOTATION; 126 break; 127 default: 128 this.access = 0; 129 } 130 131 this.declaration = st.nextToken(); 132 this.signature = st.nextToken(); 133 } 134 } 135 } 136 | Popular Tags |