~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/MethodTests.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2006, 2008 IBM Corporation.
3
 
 * All rights reserved. This program and the accompanying materials
4
 
 * are made available under the terms of the Eclipse Public License v1.0
5
 
 * which accompanies this distribution, and is available at
6
 
 * http://www.eclipse.org/legal/epl-v10.html
7
 
 *
8
 
 * Contributors:
9
 
 *     IBM Corporation - initial API and implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.cdt.internal.pdom.tests;
12
 
 
13
 
import junit.framework.Test;
14
 
 
15
 
import org.eclipse.cdt.core.dom.ast.IBasicType;
16
 
import org.eclipse.cdt.core.dom.ast.IBinding;
17
 
import org.eclipse.cdt.core.dom.ast.IParameter;
18
 
import org.eclipse.cdt.core.dom.ast.IType;
19
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
20
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
21
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
22
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
23
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
24
 
import org.eclipse.cdt.core.model.ICProject;
25
 
import org.eclipse.cdt.core.testplugin.CProjectHelper;
26
 
import org.eclipse.cdt.internal.core.CCoreInternals;
27
 
import org.eclipse.cdt.internal.core.pdom.PDOM;
28
 
 
29
 
/**
30
 
 * Tests for verifying whether the PDOM correctly stores information about
31
 
 * C++ class member functions.
32
 
 */
33
 
public class MethodTests extends PDOMTestBase {
34
 
        protected ICProject project;
35
 
        protected PDOM pdom;
36
 
 
37
 
        public static Test suite() {
38
 
                return suite(MethodTests.class);
39
 
        }
40
 
 
41
 
        @Override
42
 
        protected void setUp() throws Exception {
43
 
                project = createProject("methodTests");
44
 
                pdom = (PDOM) CCoreInternals.getPDOMManager().getPDOM(project);
45
 
                pdom.acquireReadLock();
46
 
        }
47
 
 
48
 
        @Override
49
 
        protected void tearDown() throws Exception {
50
 
                pdom.releaseReadLock();
51
 
                if (project != null) {
52
 
                        CProjectHelper.delete(project);
53
 
                        project= null;
54
 
                }
55
 
        }
56
 
 
57
 
        public void testMethodParameters() throws Exception {
58
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::normalMethod");
59
 
                assertEquals(1, bindings.length);
60
 
                ICPPFunction function = (ICPPFunction) bindings[0];
61
 
                IParameter[] parameters = function.getParameters();
62
 
                assertEquals(IBasicType.t_int, ((ICPPBasicType) parameters[0].getType()).getType());
63
 
                assertEquals("p1", parameters[0].getName());
64
 
                assertEquals(IBasicType.t_char, ((ICPPBasicType) parameters[1].getType()).getType());
65
 
                assertEquals("p2", parameters[1].getName());
66
 
                assertEquals(IBasicType.t_float, ((ICPPBasicType) parameters[2].getType()).getType());
67
 
                assertEquals("p3", parameters[2].getName());
68
 
        }
69
 
        
70
 
        public void testVirtualMethod() throws Exception {
71
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::inheritedMethod");
72
 
                assertEquals(1, bindings.length);
73
 
                ICPPMethod method = (ICPPMethod) bindings[0];
74
 
                assertTrue(method.isVirtual());
75
 
        }
76
 
        
77
 
        public void testVirtualMethodType() throws Exception {
78
 
                assertType(pdom, "Class1::inheritedMethod", ICPPFunction.class);
79
 
        }
80
 
 
81
 
        public void testVirtualMethodDeclarations() throws Exception {
82
 
                assertDeclarationCount(pdom, "Class1::inheritedMethod", 2);
83
 
        }
84
 
 
85
 
        public void testVirtualMethodDefinitions() throws Exception {
86
 
                assertDefinitionCount(pdom, "Class1::inheritedMethod", 1);
87
 
        }
88
 
 
89
 
        public void testVirtualMethodReferences() throws Exception {
90
 
                assertReferenceCount(pdom, "Class1::inheritedMethod", 3);
91
 
        }
92
 
 
93
 
        public void testInheritedMethodType() throws Exception {
94
 
                assertEquals(0, findQualifiedName(pdom, "Class2::inheritedMethod").length);
95
 
        }
96
 
 
97
 
        public void testInheritedMethodDeclarations() throws Exception {
98
 
                assertDeclarationCount(pdom, "Class2::inheritedMethod", 0);
99
 
        }
100
 
 
101
 
        public void testInheritedMethodDefinitions() throws Exception {
102
 
                assertDefinitionCount(pdom, "Class2::inheritedMethod", 0);
103
 
        }
104
 
 
105
 
        public void testInheritedMethodReferences() throws Exception {
106
 
                assertReferenceCount(pdom, "Class2::inheritedMethod", 0);
107
 
        }
108
 
 
109
 
        public void testPureVirtualMethod() throws Exception {
110
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::pureVirtualMethod");
111
 
                assertEquals(1, bindings.length);
112
 
                ICPPMethod method = (ICPPMethod) bindings[0];
113
 
                assertTrue(method.isVirtual());
114
 
                assertTrue(method.isPureVirtual());
115
 
        }
116
 
        
117
 
        public void testPureVirtualMethodType() throws Exception {
118
 
                assertType(pdom, "Class1::pureVirtualMethod", ICPPFunction.class);
119
 
                assertType(pdom, "Class2::pureVirtualMethod", ICPPFunction.class);
120
 
        }
121
 
 
122
 
        public void testPureVirtualMethodDeclarations() throws Exception {
123
 
                assertDeclarationCount(pdom, "Class1::pureVirtualMethod", 1);
124
 
                assertDeclarationCount(pdom, "Class2::pureVirtualMethod", 2);
125
 
        }
126
 
 
127
 
        public void testPureVirtualMethodDefinitions() throws Exception {
128
 
                assertDefinitionCount(pdom, "Class1::pureVirtualMethod", 0);
129
 
                assertDefinitionCount(pdom, "Class2::pureVirtualMethod", 1);
130
 
        }
131
 
 
132
 
        public void testPureVirtualMethodReferences() throws Exception {
133
 
                assertReferenceCount(pdom, "Class1::pureVirtualMethod", 2);
134
 
                assertReferenceCount(pdom, "Class2::pureVirtualMethod", 3);
135
 
        }
136
 
 
137
 
        public void testOverriddenMethodType() throws Exception {
138
 
                assertType(pdom, "Class1::overriddenMethod", ICPPFunction.class);
139
 
                assertType(pdom, "Class2::overriddenMethod", ICPPFunction.class);
140
 
        }
141
 
 
142
 
        public void testOverriddenMethodDeclarations() throws Exception {
143
 
                assertDeclarationCount(pdom, "Class1::overriddenMethod", 2);
144
 
                assertDeclarationCount(pdom, "Class2::overriddenMethod", 2);
145
 
        }
146
 
 
147
 
        public void testOverriddenMethodDefinitions() throws Exception {
148
 
                assertDefinitionCount(pdom, "Class1::overriddenMethod", 1);
149
 
                assertDefinitionCount(pdom, "Class2::overriddenMethod", 1);
150
 
        }
151
 
 
152
 
        public void testOverriddenMethodReferences() throws Exception {
153
 
                assertReferenceCount(pdom, "Class1::overriddenMethod", 3);
154
 
                assertReferenceCount(pdom, "Class2::overriddenMethod", 4);
155
 
        }
156
 
 
157
 
        public void testDestructor() throws Exception {
158
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::~Class1");
159
 
                assertEquals(1, bindings.length);
160
 
                ICPPMethod method = (ICPPMethod) bindings[0];
161
 
                assertTrue(method.isDestructor());
162
 
        }
163
 
        
164
 
        public void testDefaultPrivateMethod() throws Exception {
165
 
                assertVisibility(pdom, "Class3::defaultMethod", ICPPMember.v_private);
166
 
        }
167
 
        
168
 
        public void testPrivateMethod() throws Exception {
169
 
                assertVisibility(pdom, "Class3::privateMethod", ICPPMember.v_private);
170
 
        }
171
 
        
172
 
        public void testProtectedMethod() throws Exception {
173
 
                assertVisibility(pdom, "Class3::protectedMethod", ICPPMember.v_protected);
174
 
        }
175
 
        
176
 
        public void testPublicMethod() throws Exception {
177
 
                assertVisibility(pdom, "Class3::publicMethod", ICPPMember.v_public);
178
 
        }
179
 
        
180
 
        public void testInlineMethod() throws Exception {
181
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::inlineMethod");
182
 
                assertEquals(1, bindings.length);
183
 
                ICPPMethod method = (ICPPMethod) bindings[0];
184
 
                assertTrue(method.isInline());
185
 
        }
186
 
        
187
 
        public void testStaticMethod() throws Exception {
188
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::staticMethod");
189
 
                assertEquals(1, bindings.length);
190
 
                ICPPMethod method = (ICPPMethod) bindings[0];
191
 
                assertTrue(method.isStatic());
192
 
        }
193
 
        
194
 
        public void testVarArgsMethod() throws Exception {
195
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::varArgsMethod");
196
 
                assertEquals(1, bindings.length);
197
 
                ICPPMethod method = (ICPPMethod) bindings[0];
198
 
                assertTrue(method.takesVarArgs());
199
 
        }
200
 
        
201
 
        public void testConstMethod() throws Exception {
202
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::constMethod");
203
 
                assertEquals(1, bindings.length);
204
 
                ICPPMethod method = (ICPPMethod) bindings[0];
205
 
                ICPPFunctionType type = method.getType();
206
 
                assertTrue(type.isConst());
207
 
        }
208
 
        
209
 
        public void testVolatileMethod() throws Exception {
210
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::volatileMethod");
211
 
                assertEquals(1, bindings.length);
212
 
                ICPPMethod method = (ICPPMethod) bindings[0];
213
 
                ICPPFunctionType type = method.getType();
214
 
                assertTrue(type.isVolatile());
215
 
        }
216
 
                
217
 
        public void testConstVolatileMethod() throws Exception {
218
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::constVolatileMethod");
219
 
                assertEquals(1, bindings.length);
220
 
                ICPPMethod method = (ICPPMethod) bindings[0];
221
 
                ICPPFunctionType type = method.getType();
222
 
                assertTrue(type.isConst());
223
 
                assertTrue(type.isVolatile());
224
 
        }
225
 
        
226
 
        public void testNotConstMethod() throws Exception {
227
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::notConstMethod");
228
 
                assertEquals(1, bindings.length);
229
 
                ICPPMethod method = (ICPPMethod) bindings[0];
230
 
                ICPPFunctionType type = method.getType();
231
 
                assertFalse(type.isConst());
232
 
        }
233
 
        
234
 
        public void testNotVolatileMethod() throws Exception {
235
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::notVolatileMethod");
236
 
                assertEquals(1, bindings.length);
237
 
                ICPPMethod method = (ICPPMethod) bindings[0];
238
 
                ICPPFunctionType type = method.getType();
239
 
                assertFalse(type.isVolatile());
240
 
        }
241
 
                
242
 
        public void testNotConstVolatileMethod() throws Exception {
243
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::notConstVolatileMethod");
244
 
                assertEquals(1, bindings.length);
245
 
                ICPPMethod method = (ICPPMethod) bindings[0];
246
 
                ICPPFunctionType type = method.getType();
247
 
                assertFalse(type.isConst());
248
 
                assertFalse(type.isVolatile());
249
 
        }
250
 
        
251
 
        public void testNoExceptionSpecification() throws Exception {
252
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::noExceptionSpecMethod");
253
 
                assertEquals(1, bindings.length);
254
 
                ICPPMethod method = (ICPPMethod) bindings[0];
255
 
                IType[] exceptionSpec = method.getExceptionSpecification();
256
 
                assertNull(exceptionSpec);
257
 
        }
258
 
        
259
 
        public void testEmptyExceptionSpecification() throws Exception {
260
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::emptyExceptionSpecMethod");
261
 
                assertEquals(1, bindings.length);
262
 
                ICPPMethod method = (ICPPMethod) bindings[0];
263
 
                IType[] exceptionSpec = method.getExceptionSpecification();
264
 
                assertEquals(0, exceptionSpec.length);
265
 
        }
266
 
        
267
 
        public void testNonEmptyExceptionSpecification() throws Exception {
268
 
                IBinding[] bindings = findQualifiedName(pdom, "Class1::nonEmptyExceptionSpecMethod");
269
 
                assertEquals(1, bindings.length);
270
 
                ICPPMethod method = (ICPPMethod) bindings[0];
271
 
                IType[] exceptionSpec = method.getExceptionSpecification();
272
 
                assertEquals(1, exceptionSpec.length);
273
 
                assertEquals(IBasicType.t_int, ((ICPPBasicType) exceptionSpec[0]).getType());
274
 
        }
275
 
 
276
 
        public void testImplicitCtorExceptionSpec() throws Exception {
277
 
                IBinding[] bindings = findQualifiedPossiblyImplicit(pdom, "D::D");
278
 
                // get both default ctor + copy ctor
279
 
                assertEquals(2, bindings.length);
280
 
                ICPPMethod method = (ICPPMethod) bindings[0];
281
 
                IType[] exceptionSpec = method.getExceptionSpecification();
282
 
                assertNull(exceptionSpec);
283
 
        }
284
 
 
285
 
        public void testImplicitCopyCtorExceptionSpec() throws Exception {
286
 
                IBinding[] bindings = findQualifiedPossiblyImplicit(pdom, "D::D");
287
 
                // get both default ctor + copy ctor
288
 
                assertEquals(2, bindings.length);
289
 
                ICPPMethod method = (ICPPMethod) bindings[1];
290
 
                IType[] exceptionSpec = method.getExceptionSpecification();
291
 
                assertEquals(0, exceptionSpec.length);
292
 
        }
293
 
 
294
 
        public void testImplicitDtorExceptionSpec() throws Exception {
295
 
                IBinding[] bindings = findQualifiedPossiblyImplicit(pdom, "D::~D");
296
 
                assertEquals(1, bindings.length);
297
 
                ICPPMethod method = (ICPPMethod) bindings[0];
298
 
                IType[] exceptionSpec = method.getExceptionSpecification();
299
 
                assertEquals(2, exceptionSpec.length);
300
 
                int t1= ((ICPPBasicType) exceptionSpec[0]).getType();
301
 
                int t2= ((ICPPBasicType) exceptionSpec[1]).getType();
302
 
                assertEquals(IBasicType.t_int, Math.min(t1, t2));
303
 
                assertEquals(IBasicType.t_double, Math.max(t1, t2));
304
 
        }
305
 
}