mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
tidy up and doc unit test helper methods
This commit is contained in:
parent
ff970aefd8
commit
e9f535bcfa
3 changed files with 58 additions and 62 deletions
|
@ -85,30 +85,33 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
||||||
protected IASTName[] findNames(String section, int len) {
|
protected IASTName[] findNames(String section, int len) {
|
||||||
// get the language from the language manager
|
// get the language from the language manager
|
||||||
ILanguage language = null;
|
ILanguage language = null;
|
||||||
ICProject cproject = strategy.getCProject();
|
|
||||||
IASTTranslationUnit ast = strategy.getAst();
|
IASTTranslationUnit ast = strategy.getAst();
|
||||||
try {
|
try {
|
||||||
IProject project = cproject.getProject();
|
IProject project = strategy.getCProject().getProject();
|
||||||
ICConfigurationDescription configuration = CoreModel.getDefault().getProjectDescription(project, false).getActiveConfiguration();
|
ICConfigurationDescription configuration = CoreModel.getDefault().getProjectDescription(project, false).getActiveConfiguration();
|
||||||
language = LanguageManager.getInstance().getLanguageForFile(strategy.getAst().getFilePath(), project, configuration);
|
language = LanguageManager.getInstance().getLanguageForFile(ast.getFilePath(), project, configuration);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
fail("Unexpected exception while getting language for file.");
|
fail("Unexpected exception while getting language for file.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
assertNotNull("No language for file " + ast.getFilePath().toString(), language);
|
assertNotNull("No language for file " + ast.getFilePath().toString(), language);
|
||||||
|
|
||||||
return language.getSelectedNames(ast, strategy.getTestData()[1].indexOf(section), len);
|
return language.getSelectedNames(ast, strategy.getTestData()[1].indexOf(section), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to get an IBinding from the initial specified number of characters
|
||||||
|
* from the specified code fragment. Fails the test if
|
||||||
|
* <ul>
|
||||||
|
* <li> There is not a unique name with the specified criteria
|
||||||
|
* <li> The binding associated with the name is null or a problem binding
|
||||||
|
* </ul>
|
||||||
|
* @param section the code fragment to search for in the AST. The first occurrence of an identical section is used.
|
||||||
|
* @param len the length of the specified section to use as a name. This can also be useful for distinguishing between
|
||||||
|
* template names, and template ids.
|
||||||
|
* @return the associated name's binding
|
||||||
|
*/
|
||||||
protected IBinding getBindingFromASTName(String section, int len) {
|
protected IBinding getBindingFromASTName(String section, int len) {
|
||||||
return getBindingFromASTName(section, len, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IBinding getBindingFromASTName(String section, int len, boolean matchLength) {
|
|
||||||
IASTName[] names= findNames(section, len);
|
IASTName[] names= findNames(section, len);
|
||||||
if(matchLength) {
|
|
||||||
List lnames= new ArrayList(Arrays.asList(names));
|
List lnames= new ArrayList(Arrays.asList(names));
|
||||||
for(ListIterator li= lnames.listIterator(); li.hasNext(); ) {
|
for(ListIterator li= lnames.listIterator(); li.hasNext(); ) {
|
||||||
IASTName name= (IASTName) li.next();
|
IASTName name= (IASTName) li.next();
|
||||||
|
@ -117,31 +120,24 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
names= (IASTName[]) lnames.toArray(new IASTName[lnames.size()]);
|
names= (IASTName[]) lnames.toArray(new IASTName[lnames.size()]);
|
||||||
}
|
|
||||||
assertEquals("<>1 name found for \""+section+"\"", 1, names.length);
|
assertEquals("<>1 name found for \""+section+"\"", 1, names.length);
|
||||||
|
|
||||||
IBinding binding = names[0].resolveBinding();
|
IBinding binding = names[0].resolveBinding();
|
||||||
assertNotNull("No binding for "+names[0].getRawSignature(), binding);
|
assertNotNull("No binding for "+names[0].getRawSignature(), binding);
|
||||||
assertFalse("Binding is a ProblemBinding for name "+names[0].getRawSignature(), IProblemBinding.class.isAssignableFrom(names[0].resolveBinding().getClass()));
|
assertFalse("Binding is a ProblemBinding for name "+names[0].getRawSignature(), IProblemBinding.class.isAssignableFrom(names[0].resolveBinding().getClass()));
|
||||||
return names[0].resolveBinding();
|
return names[0].resolveBinding();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to verify that the resolved binding for a name is a problem binding.
|
||||||
|
* @param section the code fragment to search for in the AST. The first occurrence of an identical section is used.
|
||||||
|
* @param len the length of the specified section to use as a name
|
||||||
|
* @return the associated name's binding
|
||||||
|
*/
|
||||||
protected IBinding getProblemFromASTName(String section, int len) {
|
protected IBinding getProblemFromASTName(String section, int len) {
|
||||||
// get the language from the language manager
|
IASTName[] names= findNames(section, len);
|
||||||
ILanguage language = null;
|
|
||||||
ICProject cproject = strategy.getCProject();
|
|
||||||
IASTTranslationUnit ast = strategy.getAst();
|
|
||||||
try {
|
|
||||||
IProject project = cproject.getProject();
|
|
||||||
ICConfigurationDescription configuration = CoreModel.getDefault().getProjectDescription(project, false).getActiveConfiguration();
|
|
||||||
language = LanguageManager.getInstance().getLanguageForFile(ast.getFilePath(), project, configuration);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
fail("Unexpected exception while getting language for file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
assertNotNull("No language for file " + ast.getFilePath().toString(), language);
|
|
||||||
|
|
||||||
IASTName[] names= language.getSelectedNames(ast, strategy.getTestData()[1].indexOf(section), len);
|
|
||||||
assertEquals("<>1 name found for \""+section+"\"", 1, names.length);
|
assertEquals("<>1 name found for \""+section+"\"", 1, names.length);
|
||||||
|
|
||||||
IBinding binding = names[0].resolveBinding();
|
IBinding binding = names[0].resolveBinding();
|
||||||
assertNotNull("No binding for "+names[0].getRawSignature(), binding);
|
assertNotNull("No binding for "+names[0].getRawSignature(), binding);
|
||||||
assertTrue("Binding is not a ProblemBinding for name "+names[0].getRawSignature(), IProblemBinding.class.isAssignableFrom(names[0].resolveBinding().getClass()));
|
assertTrue("Binding is not a ProblemBinding for name "+names[0].getRawSignature(), IProblemBinding.class.isAssignableFrom(names[0].resolveBinding().getClass()));
|
||||||
|
|
|
@ -111,8 +111,8 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
|
||||||
// Bug 185828 reports a StackOverflowException is thrown before we get here.
|
// Bug 185828 reports a StackOverflowException is thrown before we get here.
|
||||||
// That the SOE is thrown is detected in BaseTestCase via an Error IStatus
|
// That the SOE is thrown is detected in BaseTestCase via an Error IStatus
|
||||||
|
|
||||||
IBinding b0= getBindingFromASTName("C", 1);
|
IBinding b0= getBindingFromASTName("C<int>", 1);
|
||||||
IBinding b1= getBindingFromASTName("C<int>", 6, true);
|
IBinding b1= getBindingFromASTName("C<int>", 6);
|
||||||
IBinding b2= getProblemFromASTName("unresolvable", 12);
|
IBinding b2= getProblemFromASTName("unresolvable", 12);
|
||||||
|
|
||||||
assertInstance(b0, ICPPClassType.class);
|
assertInstance(b0, ICPPClassType.class);
|
||||||
|
|
|
@ -81,8 +81,8 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
// // foo<int,int> -> CPPMethodInstance
|
// // foo<int,int> -> CPPMethodInstance
|
||||||
// }
|
// }
|
||||||
public void testCPPConstructorTemplateSpecialization() throws Exception {
|
public void testCPPConstructorTemplateSpecialization() throws Exception {
|
||||||
IBinding b0= getBindingFromASTName("D<int>(", 1, true);
|
IBinding b0= getBindingFromASTName("D<int>(", 1);
|
||||||
IBinding b1= getBindingFromASTName("D<int>(", 6, true);
|
IBinding b1= getBindingFromASTName("D<int>(", 6);
|
||||||
|
|
||||||
assertInstance(b0, ICPPClassTemplate.class); // *D*<int>(5, 6)
|
assertInstance(b0, ICPPClassTemplate.class); // *D*<int>(5, 6)
|
||||||
assertInstance(b0, ICPPClassType.class); // *D*<int>(5, 6)
|
assertInstance(b0, ICPPClassType.class); // *D*<int>(5, 6)
|
||||||
|
@ -111,7 +111,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
// a.f= foo<B>;
|
// a.f= foo<B>;
|
||||||
// }
|
// }
|
||||||
public void _testOverloadedFunctionTemplate() {
|
public void _testOverloadedFunctionTemplate() {
|
||||||
IBinding b0= getBindingFromASTName("foo<B>;", 6, true);
|
IBinding b0= getBindingFromASTName("foo<B>;", 6);
|
||||||
assertInstance(b0, ICPPFunction.class);
|
assertInstance(b0, ICPPFunction.class);
|
||||||
assertInstance(b0, ICPPSpecialization.class);
|
assertInstance(b0, ICPPSpecialization.class);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
// }
|
// }
|
||||||
public void _testTemplateTemplateParameter() throws Exception {
|
public void _testTemplateTemplateParameter() throws Exception {
|
||||||
IBinding b0= getBindingFromASTName("Foo<A,X>", 3);
|
IBinding b0= getBindingFromASTName("Foo<A,X>", 3);
|
||||||
IBinding b1= getBindingFromASTName("Foo<A,X>", 8, true);
|
IBinding b1= getBindingFromASTName("Foo<A,X>", 8);
|
||||||
IBinding b2= getBindingFromASTName("f.s.foo", 1);
|
IBinding b2= getBindingFromASTName("f.s.foo", 1);
|
||||||
IBinding b3= getBindingFromASTName("s.foo", 1);
|
IBinding b3= getBindingFromASTName("s.foo", 1);
|
||||||
IBinding b4= getBindingFromASTName("foo(*", 3);
|
IBinding b4= getBindingFromASTName("foo(*", 3);
|
||||||
|
@ -228,9 +228,9 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
// template<typename T3>
|
// template<typename T3>
|
||||||
// class D<C, T3> {};
|
// class D<C, T3> {};
|
||||||
public void _testClassPartialSpecializations() throws Exception {
|
public void _testClassPartialSpecializations() throws Exception {
|
||||||
IBinding b0= getBindingFromASTName("D<A, T3>", 8, true);
|
IBinding b0= getBindingFromASTName("D<A, T3>", 8);
|
||||||
IBinding b1= getBindingFromASTName("D<B, T3>", 8, true);
|
IBinding b1= getBindingFromASTName("D<B, T3>", 8);
|
||||||
IBinding b2= getBindingFromASTName("D<C, T3>", 8, true);
|
IBinding b2= getBindingFromASTName("D<C, T3>", 8);
|
||||||
IBinding b3= getBindingFromASTName("D<B", 1);
|
IBinding b3= getBindingFromASTName("D<B", 1);
|
||||||
|
|
||||||
List spBindings= new ArrayList();
|
List spBindings= new ArrayList();
|
||||||
|
@ -279,7 +279,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
// X<int> x;
|
// X<int> x;
|
||||||
// }
|
// }
|
||||||
public void testClassImplicitInstantiations_188274() throws Exception {
|
public void testClassImplicitInstantiations_188274() throws Exception {
|
||||||
IBinding b2= getBindingFromASTName("X<int>", 6, true);
|
IBinding b2= getBindingFromASTName("X<int>", 6);
|
||||||
assertInstance(b2, ICPPClassType.class);
|
assertInstance(b2, ICPPClassType.class);
|
||||||
assertInstance(b2, ICPPTemplateInstance.class);
|
assertInstance(b2, ICPPTemplateInstance.class);
|
||||||
ICPPClassType ct2= (ICPPClassType) b2;
|
ICPPClassType ct2= (ICPPClassType) b2;
|
||||||
|
@ -289,14 +289,14 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
ICPPClassType ct2b= (ICPPClassType) bss2[0].getBaseClass();
|
ICPPClassType ct2b= (ICPPClassType) bss2[0].getBaseClass();
|
||||||
assertInstance(ct2b, ICPPTemplateInstance.class);
|
assertInstance(ct2b, ICPPTemplateInstance.class);
|
||||||
|
|
||||||
IBinding b0= getBindingFromASTName("B<int>", 6, true);
|
IBinding b0= getBindingFromASTName("B<int>", 6);
|
||||||
assertInstance(b0, ICPPClassType.class);
|
assertInstance(b0, ICPPClassType.class);
|
||||||
ICPPClassType ct= (ICPPClassType) b0;
|
ICPPClassType ct= (ICPPClassType) b0;
|
||||||
ICPPBase[] bss= ct.getBases();
|
ICPPBase[] bss= ct.getBases();
|
||||||
assertEquals(1, bss.length);
|
assertEquals(1, bss.length);
|
||||||
assertInstance(bss[0].getBaseClass(), ICPPClassType.class);
|
assertInstance(bss[0].getBaseClass(), ICPPClassType.class);
|
||||||
|
|
||||||
IBinding b1= getBindingFromASTName("B<long>", 7, true);
|
IBinding b1= getBindingFromASTName("B<long>", 7);
|
||||||
assertInstance(b1, ICPPClassType.class);
|
assertInstance(b1, ICPPClassType.class);
|
||||||
ICPPClassType ct1= (ICPPClassType) b1;
|
ICPPClassType ct1= (ICPPClassType) b1;
|
||||||
ICPPBase[] bss1= ct1.getBases();
|
ICPPBase[] bss1= ct1.getBases();
|
||||||
|
@ -324,7 +324,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
|
|
||||||
// A<B> ab;
|
// A<B> ab;
|
||||||
public void testClassSpecializationMethods() throws Exception {
|
public void testClassSpecializationMethods() throws Exception {
|
||||||
IBinding b0= getBindingFromASTName("A<B> ab", 4, true);
|
IBinding b0= getBindingFromASTName("A<B> ab", 4);
|
||||||
assertInstance(b0, ICPPClassType.class);
|
assertInstance(b0, ICPPClassType.class);
|
||||||
assertInstance(b0, ICPPSpecialization.class);
|
assertInstance(b0, ICPPSpecialization.class);
|
||||||
assertFalse(b0 instanceof ICPPTemplateInstance);
|
assertFalse(b0 instanceof ICPPTemplateInstance);
|
||||||
|
@ -593,7 +593,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
// Foo<B> b2;
|
// Foo<B> b2;
|
||||||
public void _testClassSpecializations_180738() {
|
public void _testClassSpecializations_180738() {
|
||||||
IBinding b1a = getBindingFromASTName("Foo<B> b1;", 3);
|
IBinding b1a = getBindingFromASTName("Foo<B> b1;", 3);
|
||||||
IBinding b1b = getBindingFromASTName("Foo<B> b1;", 6, true);
|
IBinding b1b = getBindingFromASTName("Foo<B> b1;", 6);
|
||||||
|
|
||||||
assertInstance(b1a, ICPPClassType.class);
|
assertInstance(b1a, ICPPClassType.class);
|
||||||
assertInstance(b1a, ICPPClassTemplate.class);
|
assertInstance(b1a, ICPPClassTemplate.class);
|
||||||
|
@ -608,7 +608,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
assertEquals("B", b1pct.getName());
|
assertEquals("B", b1pct.getName());
|
||||||
|
|
||||||
IBinding b2a = getBindingFromASTName("Foo<B> b2;", 3);
|
IBinding b2a = getBindingFromASTName("Foo<B> b2;", 3);
|
||||||
IBinding b2b = getBindingFromASTName("Foo<B> b2;", 6, true);
|
IBinding b2b = getBindingFromASTName("Foo<B> b2;", 6);
|
||||||
|
|
||||||
assertInstance(b2a, ICPPClassType.class);
|
assertInstance(b2a, ICPPClassType.class);
|
||||||
assertInstance(b2a, ICPPClassTemplate.class);
|
assertInstance(b2a, ICPPClassTemplate.class);
|
||||||
|
|
Loading…
Add table
Reference in a new issue