KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > asm > util > TraceSignatureVisitorTest


1 /***
2  * ASM tests
3  * Copyright (c) 2002-2005 France Telecom
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package org.objectweb.asm.util;
31
32 import java.util.StringTokenizer JavaDoc;
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 /**
41  * ClassSignatureDecompilerTest
42  *
43  * @author Eugene Kuleshov
44  */

45 public class TraceSignatureVisitorTest extends TestCase {
46
47     private static String JavaDoc[] 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 JavaDoc 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 JavaDoc declaration;
109
110         public final String JavaDoc signature;
111
112         private TestData(String JavaDoc data) {
113             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(data, "|");
114             this.type = st.nextToken().charAt(0);
115
116             String JavaDoc 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