mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Test cases added
This commit is contained in:
parent
4c419cc214
commit
80e4cd9fc6
4 changed files with 74 additions and 11 deletions
|
@ -21,6 +21,7 @@ import java.util.Set;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.ErrorParserManager;
|
import org.eclipse.cdt.core.ErrorParserManager;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||||
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||||
|
@ -59,7 +60,7 @@ public class GCCBuildCommandParserTest extends TestCase {
|
||||||
private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$
|
private static final String GCC_BUILD_COMMAND_PARSER_EXT = "org.eclipse.cdt.make.core.build.command.parser.gcc"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String ELEM_TEST = "test";
|
private static final String ELEM_TEST = "test";
|
||||||
private static final String LANG_CPP = "org.eclipse.cdt.core.g++";
|
private static final String LANG_CPP = GPPLanguage.ID;
|
||||||
|
|
||||||
// those attributes must match that in AbstractBuiltinSpecsDetector
|
// those attributes must match that in AbstractBuiltinSpecsDetector
|
||||||
private static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$
|
private static final String ATTR_EXPAND_RELATIVE_PATHS = "expand-relative-paths"; //$NON-NLS-1$
|
||||||
|
@ -1872,4 +1873,37 @@ public class GCCBuildCommandParserTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testBuildResourceTree() throws Exception {
|
||||||
|
// create resources
|
||||||
|
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||||
|
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
|
||||||
|
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
|
||||||
|
IFolder folder = ResourceHelper.createFolder(project, "Folder");
|
||||||
|
IFile file = ResourceHelper.createFile(project, "Folder/file.cpp");
|
||||||
|
|
||||||
|
// create GCCBuildCommandParser
|
||||||
|
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT);
|
||||||
|
ErrorParserManager epm = new ErrorParserManager(project, null);
|
||||||
|
|
||||||
|
// parse line
|
||||||
|
parser.startup(cfgDescription);
|
||||||
|
parser.processLine("gcc "
|
||||||
|
+ " -DMACRO"
|
||||||
|
+ " Folder/file.cpp",
|
||||||
|
epm);
|
||||||
|
parser.shutdown();
|
||||||
|
|
||||||
|
// check that entries go to highest possible level
|
||||||
|
CMacroEntry entry = new CMacroEntry("MACRO", null, 0);
|
||||||
|
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
entries.add(entry);
|
||||||
|
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, file, LANG_CPP));
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, folder, LANG_CPP));
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(parser, cfgDescription, project, LANG_CPP));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||||
|
@ -46,8 +48,8 @@ public class GCCBuiltinSpecsDetectorTest extends TestCase {
|
||||||
private static final String PROVIDER_ID = "provider.id";
|
private static final String PROVIDER_ID = "provider.id";
|
||||||
private static final String PROVIDER_NAME = "provider name";
|
private static final String PROVIDER_NAME = "provider name";
|
||||||
private static final String LANGUAGE_ID = "language.test.id";
|
private static final String LANGUAGE_ID = "language.test.id";
|
||||||
private static final String LANGUAGE_ID_C = "org.eclipse.cdt.core.gcc";
|
private static final String LANGUAGE_ID_C = GCCLanguage.ID;
|
||||||
private static final String LANGUAGE_ID_CPP = "org.eclipse.cdt.core.g++";
|
private static final String LANGUAGE_ID_CPP = GPPLanguage.ID;
|
||||||
private static final String CUSTOM_PARAMETER = "customParameter";
|
private static final String CUSTOM_PARAMETER = "customParameter";
|
||||||
private static final String ELEM_TEST = "test";
|
private static final String ELEM_TEST = "test";
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||||
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
||||||
|
@ -48,6 +49,7 @@ public class LanguageSettingsManagerTests extends TestCase {
|
||||||
private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0"));
|
private static final IFile FILE_0 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/project/path0"));
|
||||||
private static final String CFG_ID = "test.configuration.id";
|
private static final String CFG_ID = "test.configuration.id";
|
||||||
private static final String LANG_ID = "test.lang.id";
|
private static final String LANG_ID = "test.lang.id";
|
||||||
|
private static final String LANG_CPP = GPPLanguage.ID;
|
||||||
private static final String PROVIDER_0 = "test.provider.0.id";
|
private static final String PROVIDER_0 = "test.provider.0.id";
|
||||||
private static final String PROVIDER_1 = "test.provider.1.id";
|
private static final String PROVIDER_1 = "test.provider.1.id";
|
||||||
private static final String PROVIDER_2 = "test.provider.2.id";
|
private static final String PROVIDER_2 = "test.provider.2.id";
|
||||||
|
@ -230,6 +232,7 @@ public class LanguageSettingsManagerTests extends TestCase {
|
||||||
// use careless provider causing an exception
|
// use careless provider causing an exception
|
||||||
{
|
{
|
||||||
ILanguageSettingsProvider providerNPE = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) {
|
ILanguageSettingsProvider providerNPE = new MockProvider(PROVIDER_1, PROVIDER_NAME_1, null) {
|
||||||
|
@Override
|
||||||
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
|
||||||
throw new NullPointerException("Can you handle me?");
|
throw new NullPointerException("Can you handle me?");
|
||||||
}
|
}
|
||||||
|
@ -820,7 +823,7 @@ public class LanguageSettingsManagerTests extends TestCase {
|
||||||
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
provider.setSettingEntries(null, file, null, entries);
|
provider.setSettingEntries(null, file, null, entries);
|
||||||
// build the hierarchy
|
// build the hierarchy
|
||||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
LanguageSettingsManager.buildResourceTree(provider, null, null, project);
|
||||||
|
|
||||||
// check that entries go to highest possible level
|
// check that entries go to highest possible level
|
||||||
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null));
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, null));
|
||||||
|
@ -849,7 +852,7 @@ public class LanguageSettingsManagerTests extends TestCase {
|
||||||
provider.setSettingEntries(null, file1, null, entries1);
|
provider.setSettingEntries(null, file1, null, entries1);
|
||||||
provider.setSettingEntries(null, file2, null, entries2);
|
provider.setSettingEntries(null, file2, null, entries2);
|
||||||
// build the hierarchy
|
// build the hierarchy
|
||||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
LanguageSettingsManager.buildResourceTree(provider, null, null, project);
|
||||||
|
|
||||||
// check that entries go to highest possible level
|
// check that entries go to highest possible level
|
||||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||||
|
@ -863,7 +866,7 @@ public class LanguageSettingsManagerTests extends TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public void testBuildResourceTree_IncrementalBuildFlippingSettings() throws Exception {
|
public void testBuildResourceTree_FlippingSettings() throws Exception {
|
||||||
// sample entries
|
// sample entries
|
||||||
List<ICLanguageSettingEntry> entries1 = new ArrayList<ICLanguageSettingEntry>();
|
List<ICLanguageSettingEntry> entries1 = new ArrayList<ICLanguageSettingEntry>();
|
||||||
entries1.add(new CMacroEntry("MACRO_1", null, 0));
|
entries1.add(new CMacroEntry("MACRO_1", null, 0));
|
||||||
|
@ -883,17 +886,17 @@ public class LanguageSettingsManagerTests extends TestCase {
|
||||||
provider.setSettingEntries(null, file1, null, entries1);
|
provider.setSettingEntries(null, file1, null, entries1);
|
||||||
provider.setSettingEntries(null, file2, null, entries1);
|
provider.setSettingEntries(null, file2, null, entries1);
|
||||||
// build the hierarchy
|
// build the hierarchy
|
||||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
LanguageSettingsManager.buildResourceTree(provider, null, null, project);
|
||||||
// double-check where the entries go
|
// double-check where the entries go
|
||||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
||||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||||
|
|
||||||
// set the entries for the second+third files (with overlap)
|
// set the entries for the second+third files (second file flips the settings)
|
||||||
provider.setSettingEntries(null, file2, null, entries2);
|
provider.setSettingEntries(null, file2, null, entries2);
|
||||||
provider.setSettingEntries(null, file3, null, entries2);
|
provider.setSettingEntries(null, file3, null, entries2);
|
||||||
// build the hierarchy
|
// build the hierarchy
|
||||||
LanguageSettingsExtensionManager.buildResourceTree(provider, null, null, project);
|
LanguageSettingsManager.buildResourceTree(provider, null, null, project);
|
||||||
// check where the entries go, it should not lose entries for the first file
|
// check where the entries go, it should not lose entries for the first file
|
||||||
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
assertEquals(entries1, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file1, null));
|
||||||
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file2, null));
|
||||||
|
@ -901,4 +904,29 @@ public class LanguageSettingsManagerTests extends TestCase {
|
||||||
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
assertEquals(entries2, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public void testBuildResourceTree_WithLanguage() throws Exception {
|
||||||
|
// sample entries
|
||||||
|
CMacroEntry entry = new CMacroEntry("MACRO", null, 0);
|
||||||
|
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
|
||||||
|
entries.add(entry);
|
||||||
|
|
||||||
|
// create resources
|
||||||
|
IProject project = ResourceHelper.createCDTProjectWithConfig(this.getName());
|
||||||
|
IFolder folder = ResourceHelper.createFolder(project, "Folder");
|
||||||
|
IFile file = ResourceHelper.createFile(project, "Folder/file.cpp");
|
||||||
|
|
||||||
|
// create a provider and set the entries
|
||||||
|
LanguageSettingsSerializable provider = new LanguageSettingsSerializable(PROVIDER_1, PROVIDER_NAME_1);
|
||||||
|
provider.setSettingEntries(null, file, LANG_CPP, entries);
|
||||||
|
// build the hierarchy
|
||||||
|
LanguageSettingsManager.buildResourceTree(provider, null, LANG_CPP, project);
|
||||||
|
|
||||||
|
// check that entries go to highest possible level
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, file, LANG_CPP));
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, folder, LANG_CPP));
|
||||||
|
assertEquals(entries, LanguageSettingsManager.getSettingEntriesUpResourceTree(provider, null, project, LANG_CPP));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ import org.eclipse.core.runtime.IExtensionRegistry;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.content.IContentType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class {@code LanguageSettingsExtensionManager} manages {@link ILanguageSettingsProvider} extensions
|
* Class {@code LanguageSettingsExtensionManager} manages {@link ILanguageSettingsProvider} extensions
|
||||||
|
@ -478,7 +477,7 @@ public class LanguageSettingsExtensionManager {
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$
|
CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
if (lang==null || (languageId!=null && languageId.equals(lang.getId()))) {
|
if (lang==null || (languageId!=null && !languageId.equals(lang.getId()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue