KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TraceSignatureVisitor unit tests.
42  *
43  * @author Eugene Kuleshov
44  */

45 public class TraceSignatureVisitorUnitTest extends TestCase {
46
47     public final static String JavaDoc[] 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 JavaDoc 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 JavaDoc 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 JavaDoc declaration;
155
156         public final String JavaDoc signature;
157
158         public TestData(final String JavaDoc data) {
159             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(data, "|");
160             this.type = st.nextToken().charAt(0);
161
162             String JavaDoc 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