mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
2004-11-08 Mikhail Voronin
New tests for help extension. * ui/org/eclipse/cdt/ui/tests/chelp/CHelpProviderTester.java * ui/org/eclipse/cdt/ui/tests/chelp/CHelpTest.java * ui/org/eclipse/cdt/ui/tests/chelp/CHelpTestInfoProvider.java
This commit is contained in:
parent
db8bcbda60
commit
3988b8ef5b
5 changed files with 668 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
2004-11-08 Mikhail Voronin
|
||||
New tests for help extension.
|
||||
* ui/org/eclipse/cdt/ui/tests/chelp/CHelpProviderTester.java
|
||||
* ui/org/eclipse/cdt/ui/tests/chelp/CHelpTest.java
|
||||
* ui/org/eclipse/cdt/ui/tests/chelp/CHelpTestInfoProvider.java
|
||||
|
||||
2004-11-02 Tanya Wolff
|
||||
added content assist regression tests
|
||||
*ui.tests.text.contentassist/ContentAssistRegressionTests.java
|
||||
|
|
|
@ -21,7 +21,22 @@
|
|||
<import plugin="org.eclipse.core.runtime.compatibility"/>
|
||||
<import plugin="org.eclipse.cdt.core"/>
|
||||
<import plugin="org.eclipse.cdt.core.tests"/>
|
||||
<import plugin="org.eclipse.help"/>
|
||||
</requires>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.cdt.ui.CHelpProvider">
|
||||
<provider
|
||||
class="org.eclipse.cdt.ui.tests.chelp.CHelpTestInfoProvider"
|
||||
id="org.eclipse.cdt.ui.tests.chelp.extension.1"/>
|
||||
<provider
|
||||
class="org.eclipse.cdt.ui.tests.chelp.CHelpTestInfoProvider"
|
||||
id="org.eclipse.cdt.ui.tests.chelp.extension.2"/>
|
||||
<provider
|
||||
class="org.eclipse.cdt.ui.tests.chelp.CHelpTestInfoProvider"
|
||||
id="org.eclipse.cdt.ui.tests.chelp.extension.3"/>
|
||||
|
||||
</extension>
|
||||
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,332 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 Intel Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.chelp;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
|
||||
import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor;
|
||||
import org.eclipse.cdt.internal.ui.text.CHelpSettings;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.ICHelpBook;
|
||||
import org.eclipse.cdt.ui.ICHelpResourceDescriptor;
|
||||
import org.eclipse.cdt.ui.IFunctionSummary;
|
||||
import org.eclipse.cdt.ui.IRequiredInclude;
|
||||
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.help.IHelpResource;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CHelpProviderTester{
|
||||
private static final String KEY_PROVIDER_ID = "providerID";
|
||||
private static final String KEY_REQUESTED_NAME = "requestedName";
|
||||
private static final String KEY_BOOK_TITLE = "bookTitle";
|
||||
private static final String KEY_BOOK_TYPE = "bookType";
|
||||
|
||||
private Properties fProperties;
|
||||
private static CHelpProviderTester fDefaultInstance = null;
|
||||
|
||||
private CHelpProviderTester(){
|
||||
}
|
||||
|
||||
public static CHelpProviderTester getDefault(){
|
||||
if(fDefaultInstance == null)
|
||||
fDefaultInstance = new CHelpProviderTester();
|
||||
return fDefaultInstance;
|
||||
}
|
||||
|
||||
private class CHelpBook implements ICHelpBook{
|
||||
private int fCHelpType;
|
||||
private String fTitle;
|
||||
|
||||
public CHelpBook(String providerID, int type){
|
||||
fCHelpType = type;
|
||||
fTitle = generateBookTitle(providerID,type);
|
||||
}
|
||||
|
||||
public String getTitle(){
|
||||
return fTitle;
|
||||
}
|
||||
|
||||
public int getCHelpType(){
|
||||
return fCHelpType;
|
||||
}
|
||||
}
|
||||
|
||||
private class CHelpResourceDescriptor implements ICHelpResourceDescriptor{
|
||||
ICHelpBook fBook;
|
||||
String fString;
|
||||
String fLabel;
|
||||
String fHref;
|
||||
IHelpResource fResources[];
|
||||
|
||||
public CHelpResourceDescriptor(ICHelpBook helpBook, String string, String providerID){
|
||||
fBook = helpBook;
|
||||
fString = string;
|
||||
fHref = string + helpBook.getTitle() + ".html";
|
||||
fLabel = generateHelpString(helpBook, string, providerID);
|
||||
fResources = new IHelpResource[1];
|
||||
fResources[0] = new IHelpResource(){
|
||||
public String getHref(){
|
||||
return fHref;
|
||||
}
|
||||
|
||||
public String getLabel(){
|
||||
return fLabel;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public ICHelpBook getCHelpBook(){
|
||||
return fBook;
|
||||
}
|
||||
|
||||
public IHelpResource[] getHelpResources(){
|
||||
return fResources;
|
||||
}
|
||||
}
|
||||
|
||||
private class FunctionSummary implements IFunctionSummary {
|
||||
|
||||
private String fName = "Name";
|
||||
private String fReturnType = "ReturnType";
|
||||
private String fPrototype = "Prototype";
|
||||
private String fSummary = "Summary";
|
||||
private String fSynopsis = "Synopsis";
|
||||
private class RequiredInclude implements IRequiredInclude {
|
||||
private String include;
|
||||
|
||||
public RequiredInclude (String file) {
|
||||
include = file;
|
||||
}
|
||||
|
||||
public String getIncludeName() {
|
||||
return include;
|
||||
}
|
||||
|
||||
public boolean isStandard() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public FunctionSummary(ICHelpBook helpBook, String string, String providerID){
|
||||
fName = string;
|
||||
fSummary = generateHelpString(helpBook, string, providerID);
|
||||
}
|
||||
|
||||
public class FunctionPrototypeSummary implements IFunctionPrototypeSummary {
|
||||
public String getName() { return fName; }
|
||||
public String getReturnType() { return fReturnType; }
|
||||
public String getArguments() { return fPrototype; }
|
||||
public String getPrototypeString(boolean namefirst) {
|
||||
if (true == namefirst) {
|
||||
return fName + " (" + fPrototype + ") " + fReturnType;
|
||||
}
|
||||
else {
|
||||
return fReturnType + " " + fName + " (" + fPrototype + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() { return fName; }
|
||||
public String getNamespace() { return "dummy namespace"; }
|
||||
public String getDescription() { return fSummary; }
|
||||
public IFunctionPrototypeSummary getPrototype() { return new FunctionPrototypeSummary(); }
|
||||
|
||||
public IRequiredInclude[] getIncludes() {
|
||||
return (IRequiredInclude[])null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static String generateHelpString(ICHelpBook helpBook, String name, String providerID){
|
||||
Properties props = new Properties();
|
||||
props.setProperty(KEY_PROVIDER_ID, providerID);
|
||||
props.setProperty(KEY_REQUESTED_NAME, name);
|
||||
props.setProperty(KEY_BOOK_TITLE, helpBook.getTitle());
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try{
|
||||
props.store(outputStream,null);
|
||||
}
|
||||
catch(Exception e){
|
||||
}
|
||||
return outputStream.toString();
|
||||
}
|
||||
|
||||
private static String generateBookTitle(String providerID, int bookType){
|
||||
Properties props = new Properties();
|
||||
props.setProperty(KEY_PROVIDER_ID, providerID);
|
||||
props.setProperty(KEY_BOOK_TYPE, String.valueOf(bookType));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try{
|
||||
props.store(outputStream,null);
|
||||
}
|
||||
catch(Exception e){
|
||||
}
|
||||
return outputStream.toString();
|
||||
}
|
||||
|
||||
private CHelpProviderTester(String string) throws IOException{
|
||||
fProperties = new Properties();
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(string.getBytes());
|
||||
|
||||
try{
|
||||
fProperties.load(stream);
|
||||
}catch(IOException e){
|
||||
//TODO: handle
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private String getValueByKey(String key){
|
||||
String val = fProperties.getProperty(key);
|
||||
if(val == null)
|
||||
val = new String();
|
||||
return val;
|
||||
}
|
||||
|
||||
private String getHelpProviderID(){
|
||||
return getValueByKey(KEY_PROVIDER_ID);
|
||||
}
|
||||
|
||||
private String getRequestedName(){
|
||||
return getValueByKey(KEY_REQUESTED_NAME);
|
||||
}
|
||||
|
||||
private String getBookTitle(){
|
||||
return getValueByKey(KEY_BOOK_TITLE);
|
||||
}
|
||||
|
||||
public boolean onlyTestInfoProvidersAvailable(){
|
||||
IConfigurationElement configElements[] = Platform.getExtensionRegistry().getConfigurationElementsFor(CUIPlugin.PLUGIN_ID, CHelpSettings.CONTRIBUTION_EXTENSION);
|
||||
int numExts = 0;
|
||||
for(int i = 0; i < configElements.length; i++){
|
||||
String id = configElements[i].getAttribute("id");
|
||||
if(!id.startsWith(CHelpTest.TEST_EXTENSION_ID_PREFIX))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ICHelpResourceDescriptor[] generateHelpResources(ICHelpBook[] helpBooks, String name, String providerID){
|
||||
ICHelpResourceDescriptor des[] = new ICHelpResourceDescriptor[helpBooks.length];
|
||||
for(int i = 0; i < helpBooks.length; i++){
|
||||
des[i] = new CHelpResourceDescriptor(helpBooks[i],name,providerID);
|
||||
}
|
||||
return des;
|
||||
}
|
||||
|
||||
public IFunctionSummary generateFunctionInfo(ICHelpBook[] helpBooks, String name, String providerID){
|
||||
if(helpBooks.length == 0)
|
||||
return null;
|
||||
return new FunctionSummary(helpBooks[0],name,providerID);
|
||||
}
|
||||
|
||||
public IFunctionSummary[] generateMatchingFunctions(ICHelpBook[] helpBooks, String prefix, String providerID){
|
||||
IFunctionSummary sum[] = new IFunctionSummary[helpBooks.length];
|
||||
for(int i = 0; i < helpBooks.length; i++){
|
||||
sum[i] = new FunctionSummary(helpBooks[i],prefix,providerID);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public ICHelpBook[] generateCHelpBooks(final String providerID){
|
||||
ICHelpBook books[] = new ICHelpBook[3];
|
||||
books[0] = new CHelpBook(providerID,ICHelpBook.HELP_TYPE_C);
|
||||
books[1] = new CHelpBook(providerID,ICHelpBook.HELP_TYPE_CPP);
|
||||
books[2] = new CHelpBook(providerID,ICHelpBook.HELP_TYPE_ASM);
|
||||
return books;
|
||||
}
|
||||
|
||||
private void checkResponse(CHelpProviderTester data[], ICHelpInvocationContext context, String name, boolean allBooksResponded){
|
||||
CHelpBookDescriptor bookDes[] = CHelpProviderManager.getDefault().getCHelpBookDescriptors(context);
|
||||
for(int i = 0; i < data.length; i++){
|
||||
CHelpProviderTester tester = data[i];
|
||||
Assert.assertTrue("the name passed to CHelpProvider (" + tester.getRequestedName() + ") differs prom tha name passed to manager (" + name + ")",name.equals(tester.getRequestedName()));
|
||||
String bookTitle = tester.getBookTitle();
|
||||
int j = 0;
|
||||
for(; j < bookDes.length; j++){
|
||||
if(bookTitle.equals(bookDes[j].getCHelpBook().getTitle())){
|
||||
Assert.assertTrue("provider was requested for help in disabled book",bookDes[j].isEnabled());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertFalse("provider was requested for help in non-existent book",j == bookDes.length);
|
||||
}
|
||||
|
||||
if(allBooksResponded){
|
||||
for(int i = 0; i < bookDes.length; i++){
|
||||
if(bookDes[i].isEnabled()){
|
||||
String bookTitle = bookDes[i].getCHelpBook().getTitle();
|
||||
int j = 0;
|
||||
for(; j < data.length; j++){
|
||||
if(bookTitle.equals(data[j].getBookTitle()))
|
||||
break;
|
||||
}
|
||||
Assert.assertFalse("provider was not requested for help in enabled book",j == bookDes.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkHelpResources(ICHelpResourceDescriptor helpDescriptors[], ICHelpInvocationContext context, String name){
|
||||
if(helpDescriptors == null || helpDescriptors.length == 0)
|
||||
return;
|
||||
List dataList = new ArrayList(helpDescriptors.length);
|
||||
for(int i = 0; i < helpDescriptors.length; i++){
|
||||
try{
|
||||
dataList.add(new CHelpProviderTester(helpDescriptors[i].getHelpResources()[0].getLabel()));
|
||||
}catch(IOException e){
|
||||
Assert.fail("checkHelpResources failed to instantiate CHelpProviderTester, IOException occured: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
if(dataList.size() > 0)
|
||||
checkResponse((CHelpProviderTester[])dataList.toArray(new CHelpProviderTester[dataList.size()]), context, name, true);
|
||||
}
|
||||
|
||||
public void checkMatchingFunctions(IFunctionSummary summaries[], ICHelpInvocationContext context, String name){
|
||||
if(summaries == null || summaries.length == 0)
|
||||
return;
|
||||
List dataList = new ArrayList(summaries.length);
|
||||
for(int i = 0; i < summaries.length; i++){
|
||||
try{
|
||||
dataList.add(new CHelpProviderTester(summaries[i].getDescription()));
|
||||
}catch(IOException e){
|
||||
Assert.fail("checkMatchingFunctions failed to instantiate CHelpProviderTester, IOException occured: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
if(dataList.size() > 0)
|
||||
checkResponse((CHelpProviderTester[])dataList.toArray(new CHelpProviderTester[dataList.size()]), context, name, true);
|
||||
}
|
||||
|
||||
public void checkFunctionInfo(IFunctionSummary summary, ICHelpInvocationContext context, String name){
|
||||
if(summary == null)
|
||||
return;
|
||||
CHelpProviderTester data[] = new CHelpProviderTester[1];
|
||||
try{
|
||||
data[0] = new CHelpProviderTester(summary.getDescription());
|
||||
checkResponse(data, context, name, false);
|
||||
}catch(IOException e){
|
||||
Assert.fail("checkFunctionInfo failed to instantiate CHelpProviderTester, IOException occured: " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,229 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 Intel Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.chelp;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
|
||||
import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor;
|
||||
import org.eclipse.cdt.internal.ui.text.CHelpSettings;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.ICHelpBook;
|
||||
import org.eclipse.cdt.ui.ICHelpResourceDescriptor;
|
||||
import org.eclipse.cdt.ui.IFunctionSummary;
|
||||
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
/**
|
||||
*
|
||||
* CHelpProvider tests
|
||||
*/
|
||||
public class CHelpTest extends TestCase {
|
||||
public final static String TEST_EXTENSION_ID_PREFIX = "org.eclipse.cdt.ui.tests.chelp.extension";
|
||||
private final static String C_PROJECT_NAME = "cHelpTestProject";
|
||||
private final static String CC_PROJECT_NAME = "ccHelpTestProject";
|
||||
private final static String BIN_DIR_NAME = "bin";
|
||||
|
||||
private ICProject fCProject = null;
|
||||
private ICProject fCCProject = null;
|
||||
private ICHelpInvocationContext fDefaultCCHelpContext = null;
|
||||
private ICHelpInvocationContext fDefaultCHelpContext = null;
|
||||
|
||||
private ICHelpInvocationContext getDefaultCCHelpContext() throws CoreException{
|
||||
if(fDefaultCCHelpContext == null){
|
||||
final IProject project = getCCProject().getProject();
|
||||
fDefaultCCHelpContext = new ICHelpInvocationContext(){
|
||||
public IProject getProject(){
|
||||
return project;
|
||||
}
|
||||
public ITranslationUnit getTranslationUnit(){
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
return fDefaultCCHelpContext;
|
||||
}
|
||||
|
||||
private ICHelpInvocationContext getDefaultCHelpContext() throws CoreException{
|
||||
if(fDefaultCHelpContext == null){
|
||||
final IProject project = getCProject().getProject();
|
||||
fDefaultCHelpContext = new ICHelpInvocationContext(){
|
||||
public IProject getProject(){
|
||||
return project;
|
||||
}
|
||||
public ITranslationUnit getTranslationUnit(){
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
return fDefaultCHelpContext;
|
||||
}
|
||||
|
||||
private ICProject getCProject() throws CoreException{
|
||||
if(fCProject == null)
|
||||
fCProject = CProjectHelper.createCProject(C_PROJECT_NAME, BIN_DIR_NAME);
|
||||
return fCProject;
|
||||
}
|
||||
|
||||
private ICProject getCCProject() throws CoreException{
|
||||
if(fCCProject == null)
|
||||
fCCProject = CProjectHelper.createCCProject(CC_PROJECT_NAME, BIN_DIR_NAME);
|
||||
return fCCProject;
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(CHelpTest.class);
|
||||
}
|
||||
|
||||
public void testCHelpProviderManagerGeneral(){
|
||||
CHelpProviderManager mngr = CHelpProviderManager.getDefault();
|
||||
if(mngr == null)
|
||||
fail("manager not created");
|
||||
if(mngr != CHelpProviderManager.getDefault())
|
||||
fail("getDefault returned an other instance of manager");
|
||||
|
||||
try{
|
||||
ICHelpInvocationContext cContext = getDefaultCHelpContext();
|
||||
ICHelpInvocationContext ccContext = getDefaultCCHelpContext();
|
||||
|
||||
String requestedName = "dummyName";
|
||||
CHelpProviderManager.getDefault().getMatchingFunctions(cContext,requestedName);
|
||||
CHelpProviderManager.getDefault().getMatchingFunctions(ccContext,requestedName);
|
||||
|
||||
CHelpProviderManager.getDefault().getFunctionInfo(cContext,requestedName);
|
||||
CHelpProviderManager.getDefault().getFunctionInfo(ccContext,requestedName);
|
||||
|
||||
CHelpProviderManager.getDefault().getHelpResources(cContext,requestedName);
|
||||
CHelpProviderManager.getDefault().getHelpResources(ccContext,requestedName);
|
||||
|
||||
IConfigurationElement configElements[] = Platform.getExtensionRegistry().getConfigurationElementsFor(CUIPlugin.PLUGIN_ID, CHelpSettings.CONTRIBUTION_EXTENSION);
|
||||
int numExts = 0;
|
||||
for(int i = 0; i < configElements.length; i++){
|
||||
String id = configElements[i].getAttribute("id");
|
||||
if(id.startsWith(TEST_EXTENSION_ID_PREFIX))
|
||||
numExts++;
|
||||
}
|
||||
|
||||
assertTrue("number of provider instances created (" + CHelpTestInfoProvider.getNumProviders() + ") is not equal to number of extensions (" + numExts + ")",numExts == CHelpTestInfoProvider.getNumProviders());
|
||||
}catch(CoreException e){
|
||||
fail("CoreException occured: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetMatchingFunctions(){
|
||||
if(!CHelpProviderTester.getDefault().onlyTestInfoProvidersAvailable()){
|
||||
//this test assumes that only CHelpTestInfoProviders are available
|
||||
return;
|
||||
}
|
||||
try{
|
||||
ICHelpInvocationContext cContext = getDefaultCHelpContext();
|
||||
ICHelpInvocationContext ccContext = getDefaultCCHelpContext();
|
||||
|
||||
String requestedName = "dummyName";
|
||||
IFunctionSummary summaries[] = CHelpProviderManager.getDefault().getMatchingFunctions(cContext,requestedName);
|
||||
CHelpProviderTester.getDefault().checkMatchingFunctions(summaries, cContext, requestedName);
|
||||
|
||||
summaries = CHelpProviderManager.getDefault().getMatchingFunctions(ccContext,requestedName);
|
||||
CHelpProviderTester.getDefault().checkMatchingFunctions(summaries, ccContext, requestedName);
|
||||
}
|
||||
catch(CoreException e){
|
||||
fail("CoreException occured: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetFunctionInfo(){
|
||||
if(!CHelpProviderTester.getDefault().onlyTestInfoProvidersAvailable()){
|
||||
//this test assumes that only CHelpTestInfoProviders are available
|
||||
return;
|
||||
}
|
||||
try{
|
||||
ICHelpInvocationContext cContext = getDefaultCHelpContext();
|
||||
ICHelpInvocationContext ccContext = getDefaultCCHelpContext();
|
||||
|
||||
String requestedName = "dummyName";
|
||||
IFunctionSummary summary = CHelpProviderManager.getDefault().getFunctionInfo(cContext,requestedName);
|
||||
CHelpProviderTester.getDefault().checkFunctionInfo(summary, cContext, requestedName);
|
||||
|
||||
summary = CHelpProviderManager.getDefault().getFunctionInfo(ccContext,requestedName);
|
||||
CHelpProviderTester.getDefault().checkFunctionInfo(summary, ccContext, requestedName);
|
||||
}
|
||||
catch(CoreException e){
|
||||
fail("CoreException occured: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetHelpResources(){
|
||||
if(!CHelpProviderTester.getDefault().onlyTestInfoProvidersAvailable()){
|
||||
//this test assumes that only CHelpTestInfoProviders are available
|
||||
return;
|
||||
}
|
||||
try{
|
||||
ICHelpInvocationContext cContext = getDefaultCHelpContext();
|
||||
ICHelpInvocationContext ccContext = getDefaultCCHelpContext();
|
||||
|
||||
String requestedName = "dummyName";
|
||||
ICHelpResourceDescriptor resourceDes[] = CHelpProviderManager.getDefault().getHelpResources(cContext,requestedName);
|
||||
CHelpProviderTester.getDefault().checkHelpResources(resourceDes, cContext, requestedName);
|
||||
|
||||
resourceDes = CHelpProviderManager.getDefault().getHelpResources(ccContext,requestedName);
|
||||
CHelpProviderTester.getDefault().checkHelpResources(resourceDes, ccContext, requestedName);
|
||||
}
|
||||
catch(CoreException e){
|
||||
fail("CoreException occured: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testCHelpBookDescriptors(){
|
||||
CHelpProviderManager mngr = CHelpProviderManager.getDefault();
|
||||
|
||||
try{
|
||||
CHelpBookDescriptor ccBookDescriptors[] = mngr.getCHelpBookDescriptors(getDefaultCCHelpContext());
|
||||
CHelpBookDescriptor cBookDescriptors[] = mngr.getCHelpBookDescriptors(getDefaultCHelpContext());
|
||||
|
||||
assertTrue("CC book descriptors length (" + ccBookDescriptors.length + ") is less than C book descriptors length (" + cBookDescriptors.length + ")",
|
||||
ccBookDescriptors.length >= cBookDescriptors.length);
|
||||
|
||||
for(int i = 0; i < cBookDescriptors.length; i++){
|
||||
CHelpBookDescriptor curBookDes = cBookDescriptors[i];
|
||||
assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" of type HELP_TYPE_CPP in book descriptors for C project \"" + getDefaultCHelpContext().getProject().getName() + "\"",
|
||||
curBookDes.getCHelpBook().getCHelpType() != ICHelpBook.HELP_TYPE_CPP);
|
||||
int j = 0;
|
||||
for(; j < ccBookDescriptors.length; j++){
|
||||
if(ccBookDescriptors[j].getCHelpBook().getTitle().equals(curBookDes.getCHelpBook().getTitle()))
|
||||
break;
|
||||
}
|
||||
assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" was not found in CC books",j < ccBookDescriptors.length);
|
||||
}
|
||||
|
||||
for(int i = 0; i < ccBookDescriptors.length; i++){
|
||||
CHelpBookDescriptor curBookDes = ccBookDescriptors[i];
|
||||
int j = 0;
|
||||
for(; j < cBookDescriptors.length; j++){
|
||||
if(cBookDescriptors[j].getCHelpBook().getTitle().equals(curBookDes.getCHelpBook().getTitle()))
|
||||
break;
|
||||
}
|
||||
assertTrue("book \"" + curBookDes.getCHelpBook().getTitle() + "\" of type HELP_TYPE_C was not found in C books",
|
||||
j < cBookDescriptors.length || curBookDes.getCHelpBook().getCHelpType() == ICHelpBook.HELP_TYPE_CPP);
|
||||
}
|
||||
}
|
||||
catch(CoreException e){
|
||||
fail("CoreException occured: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 Intel Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Intel Corporation - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.chelp;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.cdt.ui.ICHelpBook;
|
||||
import org.eclipse.cdt.ui.ICHelpProvider;
|
||||
import org.eclipse.cdt.ui.ICHelpResourceDescriptor;
|
||||
import org.eclipse.cdt.ui.IFunctionSummary;
|
||||
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* this class implements ICHelpProvider and provides test information
|
||||
*/
|
||||
public class CHelpTestInfoProvider implements ICHelpProvider {
|
||||
private static int fNumProviders = 0;
|
||||
private static final String PROVIDER_ID_PREFIX = "TestInfoProvider_";
|
||||
|
||||
final private String fProviderID;
|
||||
private boolean fIsInitialized = false;
|
||||
|
||||
private ICHelpBook fCHelpBooks[];
|
||||
|
||||
public CHelpTestInfoProvider(){
|
||||
fProviderID = PROVIDER_ID_PREFIX + fNumProviders++;
|
||||
fCHelpBooks = CHelpProviderTester.getDefault().generateCHelpBooks(fProviderID);
|
||||
}
|
||||
|
||||
public static int getNumProviders(){
|
||||
return fNumProviders;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.ICHelpProvider#initialize()
|
||||
*/
|
||||
public void initialize() {
|
||||
Assert.assertFalse("initialize is called several times",fIsInitialized);
|
||||
fIsInitialized = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.ICHelpProvider#getCHelpBooks()
|
||||
*/
|
||||
public ICHelpBook[] getCHelpBooks() {
|
||||
Assert.assertTrue("getCHelpBooks is called before completion contributor gets initialized",fIsInitialized);
|
||||
return fCHelpBooks;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.ICHelpProvider#getFunctionInfo(org.eclipse.cdt.ui.text.ICHelpInvocationContext, org.eclipse.cdt.ui.ICHelpBook[], java.lang.String)
|
||||
*/
|
||||
public IFunctionSummary getFunctionInfo(ICHelpInvocationContext context,
|
||||
ICHelpBook[] helpBooks, String name) {
|
||||
Assert.assertTrue("getFunctionInfo is called before completion contributor gets initialized",fIsInitialized);
|
||||
return CHelpProviderTester.getDefault().generateFunctionInfo(helpBooks,name,fProviderID);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.ICHelpProvider#getMatchingFunctions(org.eclipse.cdt.ui.text.ICHelpInvocationContext, org.eclipse.cdt.ui.ICHelpBook[], java.lang.String)
|
||||
*/
|
||||
public IFunctionSummary[] getMatchingFunctions(
|
||||
ICHelpInvocationContext context, ICHelpBook[] helpBooks,
|
||||
String prefix) {
|
||||
Assert.assertTrue("getMatchingFunctions is called before completion contributor gets initialized",fIsInitialized);
|
||||
return CHelpProviderTester.getDefault().generateMatchingFunctions(helpBooks,prefix,fProviderID);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.ui.ICHelpProvider#getHelpResources(org.eclipse.cdt.ui.text.ICHelpInvocationContext, org.eclipse.cdt.ui.ICHelpBook[], java.lang.String)
|
||||
*/
|
||||
public ICHelpResourceDescriptor[] getHelpResources(
|
||||
ICHelpInvocationContext context, ICHelpBook[] helpBooks, String name) {
|
||||
Assert.assertTrue("getHelpResources is called before completion contributor gets initialized",fIsInitialized);
|
||||
return CHelpProviderTester.getDefault().generateHelpResources(helpBooks,name,fProviderID);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue