77 // a public method |
77 // a public method |
78 result.add(new TestCase(true, SingleSubclass.class, "usualMethod")); |
78 result.add(new TestCase(true, SingleSubclass.class, "usualMethod")); |
79 // overriden method |
79 // overriden method |
80 result.add(new TestCase(true, SingleSubclass.class, "overridenMethod")); |
80 result.add(new TestCase(true, SingleSubclass.class, "overridenMethod")); |
81 // private method |
81 // private method |
82 result.add(new TestCase(true, SingleSubclass.class, "privateMethod")); |
82 result.add(new TestCase(InternalError.class, SingleSubclass.class, "privateMethod")); |
83 // protected method |
83 // protected method |
84 result.add(new TestCase(true, SingleSubclass.class, "protectedMethod")); |
84 result.add(new TestCase(true, SingleSubclass.class, "protectedMethod")); |
85 // default(package-private) method |
85 // default(package-private) method |
86 result.add(new TestCase(true, SingleSubclass.class, "defaultAccessMethod")); |
86 result.add(new TestCase(true, SingleSubclass.class, "defaultAccessMethod")); |
87 // default interface method redefined in implementer |
87 // default interface method redefined in implementer |
90 result.add(new TestCase(true, MultipleImplementer1.class, "testMethod")); |
90 result.add(new TestCase(true, MultipleImplementer1.class, "testMethod")); |
91 // default interface method not redefined in implementer |
91 // default interface method not redefined in implementer |
92 // result.add(new TestCase(true, SingleImplementer.class, |
92 // result.add(new TestCase(true, SingleImplementer.class, |
93 // SingleImplementerInterface.class, "defaultMethod")); |
93 // SingleImplementerInterface.class, "defaultMethod")); |
94 // static method |
94 // static method |
95 result.add(new TestCase(false, SingleSubclass.class, "staticMethod")); |
95 result.add(new TestCase(InternalError.class, SingleSubclass.class, "staticMethod")); |
96 // interface method |
96 // interface method |
97 result.add(new TestCase(false, MultipleSuperImplementers.class, |
97 result.add(new TestCase(false, MultipleSuperImplementers.class, |
98 DuplicateSimpleSingleImplementerInterface.class, "interfaceMethod")); |
98 DuplicateSimpleSingleImplementerInterface.class, "interfaceMethod")); |
99 result.add(new TestCase(false, MultipleSuperImplementers.class, |
99 result.add(new TestCase(false, MultipleSuperImplementers.class, |
100 SimpleSingleImplementerInterface.class, "interfaceMethod")); |
100 SimpleSingleImplementerInterface.class, "interfaceMethod")); |
107 HotSpotResolvedJavaMethod testMethod = CTVMUtilities.getResolvedMethod(method); |
107 HotSpotResolvedJavaMethod testMethod = CTVMUtilities.getResolvedMethod(method); |
108 |
108 |
109 HotSpotResolvedObjectType resolvedType = CompilerToVMHelper |
109 HotSpotResolvedObjectType resolvedType = CompilerToVMHelper |
110 .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver), getClass(), |
110 .lookupTypeHelper(Utils.toJVMTypeSignature(tcase.receiver), getClass(), |
111 /* resolve = */ true); |
111 /* resolve = */ true); |
112 HotSpotResolvedJavaMethod concreteMethod = CompilerToVMHelper |
112 if (tcase.exception != null) { |
113 .findUniqueConcreteMethod(resolvedType, testMethod); |
113 try { |
114 Asserts.assertEQ(concreteMethod, tcase.isPositive ? testMethod : null, |
114 HotSpotResolvedJavaMethod concreteMethod = CompilerToVMHelper |
115 "Unexpected concrete method for " + tcase.methodName); |
115 .findUniqueConcreteMethod(resolvedType, testMethod); |
|
116 |
|
117 Asserts.fail("Exception " + tcase.exception.getName() + " not thrown for " + tcase.methodName); |
|
118 } catch (Throwable t) { |
|
119 Asserts.assertEQ(t.getClass(), tcase.exception, "Wrong exception thrown for " + tcase.methodName); |
|
120 } |
|
121 } else { |
|
122 HotSpotResolvedJavaMethod concreteMethod = CompilerToVMHelper |
|
123 .findUniqueConcreteMethod(resolvedType, testMethod); |
|
124 Asserts.assertEQ(concreteMethod, tcase.isPositive ? testMethod : null, |
|
125 "Unexpected concrete method for " + tcase.methodName); |
|
126 } |
116 } |
127 } |
117 |
128 |
118 private static class TestCase { |
129 private static class TestCase { |
119 public final Class<?> receiver; |
130 public final Class<?> receiver; |
120 public final Class<?> holder; |
131 public final Class<?> holder; |
121 public final String methodName; |
132 public final String methodName; |
122 public final boolean isPositive; |
133 public final boolean isPositive; |
|
134 public final Class<?> exception; |
123 |
135 |
124 public TestCase(boolean isPositive, Class<?> clazz, Class<?> holder, |
136 public TestCase(boolean isPositive, Class<?> clazz, Class<?> holder, |
125 String methodName) { |
137 String methodName, Class<?> exception) { |
126 this.receiver = clazz; |
138 this.receiver = clazz; |
127 this.methodName = methodName; |
139 this.methodName = methodName; |
128 this.isPositive = isPositive; |
140 this.isPositive = isPositive; |
129 this.holder = holder; |
141 this.holder = holder; |
|
142 this.exception = exception; |
|
143 } |
|
144 |
|
145 public TestCase(boolean isPositive, Class<?> clazz, Class<?> holder, |
|
146 String methodName) { |
|
147 this(isPositive, clazz, holder, methodName, null); |
130 } |
148 } |
131 |
149 |
132 public TestCase(boolean isPositive, Class<?> clazz, String methodName) { |
150 public TestCase(boolean isPositive, Class<?> clazz, String methodName) { |
133 this(isPositive, clazz, clazz, methodName); |
151 this(isPositive, clazz, clazz, methodName, null); |
|
152 } |
|
153 |
|
154 public TestCase(Class<?> exception, Class<?> clazz, String methodName) { |
|
155 this(false, clazz, clazz, methodName, exception); |
134 } |
156 } |
135 |
157 |
136 @Override |
158 @Override |
137 public String toString() { |
159 public String toString() { |
138 return String.format("CASE: receiver=%s, holder=%s, method=%s, isPositive=%s", |
160 return String.format("CASE: receiver=%s, holder=%s, method=%s, isPositive=%s, exception=%s", |
139 receiver.getName(), holder.getName(), methodName, isPositive); |
161 receiver.getName(), holder.getName(), methodName, isPositive, |
|
162 exception == null ? "<none>" : exception.getName()); |
140 } |
163 } |
141 } |
164 } |
142 } |
165 } |