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

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/OverloadsWithinCommonHeaderTests.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, 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
 
7
 *
 
8
 * Contributors:
 
9
 * Andrew Ferguson (Symbian) - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.internal.pdom.tests;
 
12
 
 
13
import java.util.regex.Pattern;
 
14
 
 
15
import junit.framework.TestSuite;
 
16
 
 
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;
 
28
 
 
29
/**
 
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)
 
33
 */
 
34
public class OverloadsWithinCommonHeaderTests extends PDOMTestBase {
 
35
        protected PDOM pdom;
 
36
 
 
37
        public static TestSuite suite() {
 
38
                return suite(OverloadsWithinCommonHeaderTests.class);
 
39
        }
 
40
        
 
41
        protected void setUp() throws Exception {
 
42
                if (pdom == null) {
 
43
                        ICProject project = createProject("overloadsWithinCommonHeader", true);
 
44
                        pdom = (PDOM)CCoreInternals.getPDOMManager().getPDOM(project);
 
45
                }
 
46
                pdom.acquireReadLock();
 
47
        }
 
48
 
 
49
        protected void tearDown() throws Exception {
 
50
                pdom.releaseReadLock();
 
51
        }
 
52
        
 
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);
 
57
                
 
58
                // ManyOverloaded.qux()
 
59
                assertFunctionRefCount(new Class[0], ManyOverloadedQux, 2);
 
60
                
 
61
                // ManyOverloaded.qux(int)
 
62
                assertFunctionRefCount(new Class[]{IBasicType.class}, ManyOverloadedQux, 4);
 
63
                
 
64
                // ManyOverloaded.qux(int,char)
 
65
                assertFunctionRefCount(new Class[]{IBasicType.class,IBasicType.class}, ManyOverloadedQux, 6);
 
66
                
 
67
                // ManyOverloaded.qux(ManyOverloaded*)
 
68
                assertFunctionRefCount(new Class[]{IPointerType.class}, ManyOverloadedQux, 8);
 
69
                                
 
70
                // ManyOverloaded.qux(ManyOverloaded)
 
71
                assertFunctionRefCount(new Class[]{ICPPClassType.class}, ManyOverloadedQux, 10);
 
72
        }
 
73
        
 
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());
 
77
                
 
78
                assertEquals(5,Quux.length);
 
79
                
 
80
                // (file scope) quux()
 
81
                assertFunctionRefCount(new Class[0], Quux, 4);
 
82
                
 
83
                // (file scope) quux(int,char)
 
84
                assertFunctionRefCount(new Class[] {IBasicType.class}, Quux, 6);
 
85
                
 
86
                // (file scope) quux(int,char)
 
87
                assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, Quux, 8);
 
88
                
 
89
                // (file scope) quux(ManyOverloaded*)
 
90
                assertFunctionRefCount(new Class[] {IPointerType.class}, Quux, 10);
 
91
                
 
92
                // (file scope) quux(ManyOverloaded)
 
93
                assertFunctionRefCount(new Class[] {ICPPClassType.class}, Quux, 12);
 
94
        }
 
95
        
 
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);
 
100
                 
 
101
                // corge::grault()
 
102
                assertFunctionRefCount(new Class[0], Grault, 6);
 
103
                
 
104
                // corge::grault(int,char)
 
105
                assertFunctionRefCount(new Class[] {IBasicType.class}, Grault, 8);
 
106
                
 
107
                // corge::grault(int,char)
 
108
                assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, Grault, 10);
 
109
                
 
110
                // corge::grault(ManyOverloaded*)
 
111
                assertFunctionRefCount(new Class[] {IPointerType.class}, Grault, 12);
 
112
                
 
113
                // corge::grault(ManyOverloaded)
 
114
                assertFunctionRefCount(new Class[] {ICPPClassType.class}, Grault, 14);
 
115
        }
 
116
        
 
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);
 
121
                 
 
122
                // ns2::quux()
 
123
                assertFunctionRefCount(new Class[0], ns2, 16);
 
124
                
 
125
                // ns2::quux(int,char)
 
126
                assertFunctionRefCount(new Class[] {IBasicType.class}, ns2, 20);
 
127
                
 
128
                // ns2::quux(int,char)
 
129
                assertFunctionRefCount(new Class[] {IBasicType.class, IBasicType.class}, ns2, 24);
 
130
                
 
131
                // ns2::quux(ManyOverloaded*)
 
132
                assertFunctionRefCount(new Class[] {IPointerType.class}, ns2, 28);
 
133
                
 
134
                // ns2::quux(ManyOverloaded)
 
135
                assertFunctionRefCount(new Class[] {ICPPClassType.class}, ns2, 32);
 
136
        }
 
137
        
 
138
        protected void assertFunctionRefCount(Class[] args, IBinding[] bindingPool, int refCount) throws CoreException {
 
139
                assertFunctionRefCount(pdom, args, bindingPool, refCount);
 
140
        }
 
141
}