1
/*******************************************************************************
2
* Copyright (c) 2006, 2007 Symbian Software and others.
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
9
* Andrew Ferguson (Symbian) - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.pdom.tests;
13
import java.util.regex.Pattern;
15
import junit.framework.TestSuite;
17
import org.eclipse.cdt.core.dom.ILinkage;
18
import org.eclipse.cdt.core.dom.ast.IBasicType;
19
import org.eclipse.cdt.core.dom.ast.IBinding;
20
import org.eclipse.cdt.core.dom.ast.IPointerType;
21
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
22
import org.eclipse.cdt.core.index.IndexFilter;
23
import org.eclipse.cdt.core.model.ICProject;
24
import org.eclipse.cdt.internal.core.CCoreInternals;
25
import org.eclipse.cdt.internal.core.pdom.PDOM;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.NullProgressMonitor;
30
* Test overloaded symbols are correctly resolved when in a common header. This
31
* is of interested with the Fast Indexer, as binding resolution occurs purely on
32
* AST information (as opposed to adapting a non-PDOM binding to a PDOM binding)
34
public class OverloadsWithinCommonHeaderTests extends PDOMTestBase {
37
public static TestSuite suite() {
38
return suite(OverloadsWithinCommonHeaderTests.class);
41
protected void setUp() throws Exception {
43
ICProject project = createProject("overloadsWithinCommonHeader", true);
44
pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project);
46
pdom.acquireReadLock();
49
protected void tearDown() throws Exception {
50
pdom.releaseReadLock();
53
public void testOverloadedInCommonHeader_ClassScope() throws CoreException {
54
Pattern[] ManyOverloadedQuxPath = makePatternArray(new String[] {"ManyOverloaded","qux"});
55
IBinding[] ManyOverloadedQux = pdom.findBindings(ManyOverloadedQuxPath, true, IndexFilter.ALL, new NullProgressMonitor());
56
assertEquals(5,ManyOverloadedQux.length);
58
// ManyOverloaded.qux()
59
assertFunctionRefCount(new Class[0], ManyOverloadedQux, 2);
61
// ManyOverloaded.qux(int)
62
assertFunctionRefCount(new Class[]{IBasicType.class}, ManyOverloadedQux, 4);
64
// ManyOverloaded.qux(int,char)
65
assertFunctionRefCount(new Class[]{IBasicType.class,IBasicType.class}, ManyOverloadedQux, 6);
67
// ManyOverloaded.qux(ManyOverloaded*)
68
assertFunctionRefCount(new Class[]{IPointerType.class}, ManyOverloadedQux, 8);
70
// ManyOverloaded.qux(ManyOverloaded)
71
assertFunctionRefCount(new Class[]{ICPPClassType.class}, ManyOverloadedQux, 10);
74
public void testOverloadedInCommonHeader_FileScope() throws CoreException {
75
Pattern[] QuuxPath = makePatternArray(new String[] {"quux"});
76
IBinding[] Quux = pdom.findBindings(QuuxPath, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor());
78
assertEquals(5,Quux.length);
80
// (file scope) quux()
81
assertFunctionRefCount(new Class[0], Quux, 4);
83
// (file scope) quux(int,char)
84
assertFunctionRefCount(new Class[] {IBasicType.class}, Quux, 6);
86
// (file scope) quux(int,char)
87
assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, Quux, 8);
89
// (file scope) quux(ManyOverloaded*)
90
assertFunctionRefCount(new Class[] {IPointerType.class}, Quux, 10);
92
// (file scope) quux(ManyOverloaded)
93
assertFunctionRefCount(new Class[] {ICPPClassType.class}, Quux, 12);
96
public void testOverloadedInCommonHeader_NamespaceScope() throws CoreException {
97
Pattern[] GraultPath = makePatternArray(new String[] {"corge","grault"});
98
IBinding[] Grault = pdom.findBindings(GraultPath, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor());
99
assertEquals(5,Grault.length);
102
assertFunctionRefCount(new Class[0], Grault, 6);
104
// corge::grault(int,char)
105
assertFunctionRefCount(new Class[] {IBasicType.class}, Grault, 8);
107
// corge::grault(int,char)
108
assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, Grault, 10);
110
// corge::grault(ManyOverloaded*)
111
assertFunctionRefCount(new Class[] {IPointerType.class}, Grault, 12);
113
// corge::grault(ManyOverloaded)
114
assertFunctionRefCount(new Class[] {ICPPClassType.class}, Grault, 14);
117
public void testOverloadedInCommonHeader_NamespaceScope_Collides_With_Filescope() throws CoreException {
118
Pattern[] ns2Path = makePatternArray(new String[] {"ns2","quux"});
119
IBinding[] ns2 = pdom.findBindings(ns2Path, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor());
120
assertEquals(5,ns2.length);
123
assertFunctionRefCount(new Class[0], ns2, 16);
125
// ns2::quux(int,char)
126
assertFunctionRefCount(new Class[] {IBasicType.class}, ns2, 20);
128
// ns2::quux(int,char)
129
assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, ns2, 24);
131
// ns2::quux(ManyOverloaded*)
132
assertFunctionRefCount(new Class[] {IPointerType.class}, ns2, 28);
134
// ns2::quux(ManyOverloaded)
135
assertFunctionRefCount(new Class[] {ICPPClassType.class}, ns2, 32);
138
protected void assertFunctionRefCount(Class[] args, IBinding[] bindingPool, int refCount) throws CoreException {
139
assertFunctionRefCount(pdom, args, bindingPool, refCount);