1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Make tests inherit from BaseTestCase or BaseTestCase5

This provides the shared pre/post condition assertions to
help make sure tests are running in a clean environment.

If I had time I would convert all the tests to BaseTestCase5
which is JUnit5, but I only did the tests that had something
wrong with them.

Part of #117
This commit is contained in:
Jonah Graham 2022-10-28 15:28:39 -04:00
parent 021c03633a
commit f8dee45ba3
24 changed files with 131 additions and 140 deletions

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@ -59,7 +60,7 @@ import org.junit.jupiter.api.TestInfo;
* <li>Cleaning up the workspace at the end</li>
* </ul>
*/
public abstract class AbstractBuilderTest {
public abstract class AbstractBuilderTest extends BaseTestCase5 {
private static final boolean WINDOWS = java.io.File.separatorChar == '\\';
static final String PATH = "builderTests";
@ -67,13 +68,15 @@ public abstract class AbstractBuilderTest {
private String workspace;
private List<IProject> projects;
private boolean autoBuildingRestoreValue;
@BeforeEach
public void setUp() throws Exception {
setAutoBuilding(false);
public void setUpBaseLocal() throws Exception {
autoBuildingRestoreValue = setAutoBuilding(false);
}
@AfterEach
public void tearDown(TestInfo testInfo) throws Exception {
public void tearDownBaseLocal(TestInfo testInfo) throws Exception {
ResourceHelper.cleanUp(testInfo.getDisplayName());
// Bug 327126 Stop the indexer before tearing down so we don't deadlock
Job.getJobManager().cancel(CCorePlugin.getPDOMManager());
@ -86,6 +89,8 @@ public abstract class AbstractBuilderTest {
}
projects.clear();
}
setAutoBuilding(autoBuildingRestoreValue);
}
/**
@ -308,13 +313,17 @@ public abstract class AbstractBuilderTest {
}
}
protected void setAutoBuilding(boolean value) throws CoreException {
/**
* Return previous value
*/
protected boolean setAutoBuilding(boolean value) throws CoreException {
IWorkspace workspace = getWorkspace();
if (workspace.isAutoBuilding() == value)
return;
return value;
IWorkspaceDescription desc = workspace.getDescription();
desc.setAutoBuilding(value);
workspace.setDescription(desc);
return !value;
}
protected IWorkspace getWorkspace() throws CoreException {

View file

@ -18,23 +18,18 @@ import java.util.Set;
import java.util.TreeSet;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import junit.framework.TestCase;
/**
* Check that preconditions for running managed builder tests are in place,
* see individual tests in this class for details.
*/
public class ManagedBuilderPreconditionsTests extends TestCase {
@Override
protected void setUp() throws Exception {
}
public class ManagedBuilderPreconditionsTests extends BaseTestCase {
/**
* Many MBS tests run make and gcc and will inspect resulting artifacts of the build.
* Make sure GNU tool-chain is available for the tests.

View file

@ -16,13 +16,12 @@ package org.eclipse.cdt.build.core.scannerconfig.tests;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCSpecsConsoleParser;
import junit.framework.TestCase;
public class GCCSpecsConsoleParserTest extends TestCase {
public class GCCSpecsConsoleParserTest extends BaseTestCase {
GCCSpecsConsoleParser parser;
private IScannerInfoCollector collector;
List<String> includes;
@ -30,6 +29,7 @@ public class GCCSpecsConsoleParserTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
collector = new IScannerInfoCollector() {
@Override

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.buildmodel.BuildDescriptionManager;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildDescription;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildIOType;
@ -70,10 +71,9 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class BuildDescriptionModelTests extends TestCase {
public class BuildDescriptionModelTests extends BaseTestCase {
private static final String PREFIX = "BuildDescription_";
private static final String PROJ_PATH = "testBuildDescriptionProjects";

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -48,10 +49,9 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class BuildSystem40Tests extends TestCase {
public class BuildSystem40Tests extends BaseTestCase {
private IPath resourcesLocation = new Path(
CTestPlugin.getFileInPlugin(new Path("resources/test40Projects/")).getAbsolutePath());

View file

@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -34,10 +35,9 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.junit.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ManagedBuildCoreTests extends TestCase {
public class ManagedBuildCoreTests extends BaseTestCase {
private static IProjectType exeType;
private static IProjectType libType;
private static IProjectType dllType;

View file

@ -17,6 +17,7 @@ import java.net.URL;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
@ -46,7 +47,6 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
// TODO LK - write test for resource configurations + IOptionCategory.getOptions(config)
@ -56,7 +56,7 @@ import junit.framework.TestSuite;
/*
* These tests exercise CDT 3.0 shared tool options extensions
*/
public class ManagedBuildCore_SharedToolOptionsTests extends TestCase {
public class ManagedBuildCore_SharedToolOptionsTests extends BaseTestCase {
class IconComparator {
static final int None = 0;

View file

@ -22,6 +22,7 @@ import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
@ -36,10 +37,9 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ManagedBuildDependencyCalculatorTests extends TestCase {
public class ManagedBuildDependencyCalculatorTests extends BaseTestCase {
private IPath resourcesLocation = new Path(
CTestPlugin.getFileInPlugin(new Path("resources/depCalcProjects/")).getAbsolutePath());

View file

@ -55,6 +55,7 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
private IProject fTapp, fTlib, fTobjs;
private IToolChain[] allToolChains;
private boolean autoBuildingRestoreValue;
private void buildProject(IProject curProject) {
@ -74,13 +75,10 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
}
@Override
public void setUp() {
// Don't run super class setUp
}
@BeforeEach
public void setUpLocal() throws Exception {
autoBuildingRestoreValue = setAutoBuilding(true);
allToolChains = ManagedBuildManager.getRealToolChains();
IWorkspaceDescription wsDescription = ResourcesPlugin.getWorkspace().getDescription();
wsDescription.setAutoBuilding(false);
@ -102,6 +100,8 @@ public class ManagedBuildDependencyLibsTests extends AbstractBuilderTest {
ManagedBuildTestHelper.removeProject(fTapp.getName());
ManagedBuildTestHelper.removeProject(fTlib.getName());
ManagedBuildTestHelper.removeProject(fTobjs.getName());
setAutoBuilding(autoBuildingRestoreValue);
}
private void findFiles(IResource dir, String pattern, List<IFile> files) {

View file

@ -16,6 +16,7 @@ package org.eclipse.cdt.managedbuilder.core.tests;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
@ -25,13 +26,12 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
*
* */
public class ManagedBuildEnvironmentTests extends TestCase {
public class ManagedBuildEnvironmentTests extends BaseTestCase {
// test variable names
final private String NAME_CWD = "CWD"; //$NON-NLS-1$
final private String NAME_PWD = "PWD"; //$NON-NLS-1$

View file

@ -22,6 +22,7 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -47,10 +48,9 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ManagedBuildMacrosTests extends TestCase {
public class ManagedBuildMacrosTests extends BaseTestCase {
static IProject proj = null;
static IManagedProject mproj = null;

View file

@ -15,19 +15,19 @@
package org.eclipse.cdt.managedbuilder.core.tests;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
*
* */
public class ManagedBuildTCSupportedTest extends TestCase {
public class ManagedBuildTCSupportedTest extends BaseTestCase {
public ManagedBuildTCSupportedTest() {
super();

View file

@ -17,6 +17,7 @@ package org.eclipse.cdt.managedbuilder.core.tests;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -33,10 +34,9 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ManagedCommandLineGeneratorTest extends TestCase {
public class ManagedCommandLineGeneratorTest extends BaseTestCase {
private static String[] testCommandLinePatterns = { null, "${COMMAND}", "${COMMAND} ${FLAGS}",
"${COMMAND} ${FLAGS} ${OUTPUT_FLAG}", "${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}",

View file

@ -24,6 +24,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IAdditionalInput;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IInputType;
@ -54,10 +55,9 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ManagedProject30MakefileTests extends TestCase {
public class ManagedProject30MakefileTests extends BaseTestCase {
public static final String MBS_TEMP_DIR = "MBSTemp";
boolean pathVariableCreated = false;

View file

@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -31,10 +32,9 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class OptionCategoryEnablementTests extends TestCase {
public class OptionCategoryEnablementTests extends BaseTestCase {
private static final String testName = "optcaten"; //$NON-NLS-1$
private static boolean fHandleValueCalled;

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.managedbuilder.core.tests;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -35,10 +36,9 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class OptionEnablementTests extends TestCase implements IManagedOptionValueHandler, IOptionApplicability {
public class OptionEnablementTests extends BaseTestCase implements IManagedOptionValueHandler, IOptionApplicability {
private static final String PROJECT_TYPE = "test.four.dot.zero.cdt.managedbuild.target.gnu.exe";
private static final String CFG_NAME = "Test 4.0 ConfigName.Dbg";
private static final String TOOL_ID = "test.four.dot.zero.cdt.managedbuild.tool.gnu.c.compiler";

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.managedbuilder.core.tests;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.internal.core.model.IncludeEntry;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -26,7 +27,6 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
@ -38,7 +38,7 @@ import junit.framework.TestSuite;
* @author pn3484
*
*/
public class PathConverterTest extends TestCase {
public class PathConverterTest extends BaseTestCase {
public PathConverterTest(String name) {
super(name);

View file

@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -50,10 +51,9 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ResourceBuildCoreTests extends TestCase {
public class ResourceBuildCoreTests extends BaseTestCase {
private static final boolean boolVal = true;
private static IProjectType exeType;
private static IProjectType libType;

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -45,10 +46,9 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ToolChainModificationTests extends TestCase {
public class ToolChainModificationTests extends BaseTestCase {
private static final String PROJ_NAME_PREFIX = "TCM_";
public static Test suite() {

View file

@ -13,6 +13,10 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.templateengine.tests;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -21,6 +25,7 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.templateengine.TemplateEngine;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IOption;
@ -33,10 +38,11 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import junit.framework.TestCase;
public class TestProcesses extends TestCase {
public class TestProcesses extends BaseTestCase5 {
private static final String INCLUDE_FOLDER = "Include"; //$NON-NLS-1$
private static final String APPEND = "Append"; //$NON-NLS-1$
private static final String MBS_GNU_CPP_LINK_OPTION_ID = ".*gnu.cpp.link.option.*"; //$NON-NLS-1$
@ -47,27 +53,23 @@ public class TestProcesses extends TestCase {
String projectName;
@Override
protected void setUp() throws Exception {
@BeforeEach
protected void beforeEach() throws Exception {
TemplateEngineTestsHelper.turnOffAutoBuild();
projectName = "TemplateEngineTestsProject" + System.currentTimeMillis();
}
@Override
protected void tearDown() throws Exception {
@AfterEach
protected void afterEach() throws Exception {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
ResourceHelper.cleanUp(getName());
if (project.exists()) {
try {
ManagedBuildTestHelper.delete(CoreModel.getDefault().create(project));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
ManagedBuildTestHelper.delete(CoreModel.getDefault().create(project));
}
}
@Test
public void testCreateIncludeFolder() {
TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null,
".*CreateIncludeFolder"); //$NON-NLS-1$
@ -93,6 +95,7 @@ public class TestProcesses extends TestCase {
assertTrue(folder.exists());
}
@Test
public void testNewManagedProject() {
TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*NewManagedProject"); //$NON-NLS-1$
template.getTemplateInfo().setConfigurations(getConfigurations());
@ -110,6 +113,7 @@ public class TestProcesses extends TestCase {
assertTrue(project.exists());
}
@Test
public void testSetMBSBooleanOptionValue() {
TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null,
".*SetMBSBooleanOptionValue"); //$NON-NLS-1$
@ -136,6 +140,7 @@ public class TestProcesses extends TestCase {
}
@Test
public void testSetMBSStringOptionValue() {
TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null,
".*SetMBSStringOptionValue"); //$NON-NLS-1$
@ -162,6 +167,7 @@ public class TestProcesses extends TestCase {
}
}
@Test
public void testSetMBSStringListOptionValues() {
TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null,
".*SetMBSStringListOptionValues"); //$NON-NLS-1$
@ -191,6 +197,7 @@ public class TestProcesses extends TestCase {
}
}
@Test
public void testAppendToMBSStringOptionValue() {
TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null,
".*AppendToMBSStringOptionValue"); //$NON-NLS-1$
@ -218,6 +225,7 @@ public class TestProcesses extends TestCase {
}
}
@Test
public void testAppendToMBSStringListOptionValues() {
TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null,
".*AppendToMBSStringListOptionValues"); //$NON-NLS-1$
@ -252,6 +260,7 @@ public class TestProcesses extends TestCase {
}
}
@Test
public void testExcludeResources() {
TemplateCore template = TemplateEngine.getDefault().getFirstTemplate(PROJECT_TYPE, null, ".*ExcludeResources"); //$NON-NLS-1$
template.getTemplateInfo().setConfigurations(getConfigurations());

View file

@ -21,14 +21,14 @@ import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IProject;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class BackwardCompatiblityTests extends TestCase {
public class BackwardCompatiblityTests extends BaseTestCase {
private static final String TEST_3X_STD_MAKE_PROJECTS = "test3xStdMakeProjects";
private List<IProject> projList = new LinkedList<>();
@ -80,11 +80,6 @@ public class BackwardCompatiblityTests extends TestCase {
return ManagedBuildTestHelper.loadProject(name, TEST_3X_STD_MAKE_PROJECTS);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
ResourceHelper.cleanUp(getName());

View file

@ -13,6 +13,11 @@
*******************************************************************************/
package org.eclipse.cdt.projectmodel.tests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@ -22,6 +27,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -38,40 +44,22 @@ import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.QualifiedName;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.jupiter.api.Test;
/**
* Creates a project in a loop and checks that it is created with appropriate number
* of build configurations
*
*/
public class CProjectDescriptionSerializationTests extends TestCase {
/**
* @return Test
*/
public static Test suite() {
return new TestSuite(CProjectDescriptionSerializationTests.class);
}
@Override
protected void setUp() throws Exception {
}
@Override
protected void tearDown() throws Exception {
}
public class CProjectDescriptionSerializationTests extends BaseTestCase5 {
/**
* This test is intended to test serialization of C++ project
* @throws Exception
*/
@Test
public void testTooManyConfigurations() throws Exception {
String projectName = "testTooManyConfigurations";
String pluginProjectTypeId = "cdt.managedbuild.target.gnu.cygwin.exe";
@ -82,30 +70,30 @@ public class CProjectDescriptionSerializationTests extends TestCase {
// Create model project and accompanied descriptions
IProject project = BuildSystemTestHelper.createProject(projectName);
ICProjectDescription des = coreModel.createProjectDescription(project, false);
Assert.assertNotNull("createDescription returned null!", des);
assertNotNull(des, "createDescription returned null!");
{
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
IProjectType type = ManagedBuildManager.getProjectType(pluginProjectTypeId);
Assert.assertNotNull("project type not found", type);
assertNotNull(type, "project type not found");
ManagedProject mProj = new ManagedProject(project, type);
info.setManagedProject(mProj);
IConfiguration cfgs[] = type.getConfigurations();
Assert.assertNotNull("configurations not found", cfgs);
Assert.assertTrue("no configurations found in the project type", cfgs.length > 0);
assertNotNull(cfgs, "configurations not found");
assertTrue(cfgs.length > 0, "no configurations found in the project type");
for (IConfiguration configuration : cfgs) {
String id = ManagedBuildManager.calculateChildId(configuration.getId(), null);
Configuration config = new Configuration(mProj, (Configuration) configuration, id, false, true,
false);
CConfigurationData data = config.getConfigurationData();
Assert.assertNotNull("data is null for created configuration", data);
assertNotNull(data, "data is null for created configuration");
ICConfigurationDescription cfgDes = des
.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
}
Assert.assertEquals(2, des.getConfigurations().length);
assertEquals((Object) 2, (Object) des.getConfigurations().length);
}
// Persist the project
@ -127,18 +115,18 @@ public class CProjectDescriptionSerializationTests extends TestCase {
// Open project
IProject project = root.getProject(projectName);
project.open(null);
Assert.assertEquals(true, project.isOpen());
assertEquals(true, project.isOpen());
// Check project description
ICProjectDescription des = coreModel.getProjectDescription(project);
Assert.assertEquals(2, des.getConfigurations().length);
assertEquals((Object) 2, (Object) des.getConfigurations().length);
IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
// once in a while managedProject.getConfigurations() can return null
// inside buildInfo.getConfigurationNames() which results in NPE
String[] configurationNames = buildInfo.getConfigurationNames();
// this Assert triggers as well on occasion
Assert.assertNotNull("buildInfo.getConfigurationNames() returned null", configurationNames);
assertNotNull(configurationNames, "buildInfo.getConfigurationNames() returned null");
IConfiguration configurations[] = buildInfo.getManagedProject().getConfigurations();
// this condition is not supposed to be true
@ -148,7 +136,7 @@ public class CProjectDescriptionSerializationTests extends TestCase {
for (IConfiguration configuration : configurations) {
message = message + "[" + configuration.getName() + "], ";
}
Assert.assertEquals(message, 2, configurations.length);
assertEquals((Object) 2, (Object) configurations.length, message);
}
ResourceHelper.joinIndexerBeforeCleanup(getName());
@ -161,6 +149,7 @@ public class CProjectDescriptionSerializationTests extends TestCase {
* This test is intended to check persistentProperties after a project is created.
* @throws Exception
*/
@Test
public void testPersistentProperties() throws Exception {
CoreModel coreModel = CoreModel.getDefault();
ICProjectDescriptionManager mngr = coreModel.getProjectDescriptionManager();
@ -173,63 +162,60 @@ public class CProjectDescriptionSerializationTests extends TestCase {
IProject project = BuildSystemTestHelper.createProject(projectName);
ICProjectDescription des = coreModel.createProjectDescription(project, false);
des.setConfigurationRelations(ICProjectDescription.CONFIGS_INDEPENDENT);
Assert.assertNotNull("createDescription returned null!", des);
assertNotNull(des, "createDescription returned null!");
{
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
IProjectType type = ManagedBuildManager.getProjectType(pluginProjectTypeId);
Assert.assertNotNull("project type not found", type);
assertNotNull(type, "project type not found");
ManagedProject mProj = new ManagedProject(project, type);
info.setManagedProject(mProj);
IConfiguration cfgs[] = type.getConfigurations();
Assert.assertNotNull("configurations not found", cfgs);
Assert.assertTrue("no configurations found in the project type", cfgs.length > 0);
assertNotNull(cfgs, "configurations not found");
assertTrue(cfgs.length > 0, "no configurations found in the project type");
for (IConfiguration configuration : cfgs) {
String id = ManagedBuildManager.calculateChildId(configuration.getId(), null);
Configuration config = new Configuration(mProj, (Configuration) configuration, id, false, true,
false);
CConfigurationData data = config.getConfigurationData();
Assert.assertNotNull("data is null for created configuration", data);
assertNotNull(data, "data is null for created configuration");
ICConfigurationDescription cfgDes = des
.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
}
Assert.assertEquals(2, des.getConfigurations().length);
assertEquals((Object) 2, (Object) des.getConfigurations().length);
}
coreModel.setProjectDescription(project, des);
Assert.assertEquals(project, des.getProject());
assertEquals(project, des.getProject());
try {
QualifiedName pdomName = new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomName");
QualifiedName activeCfg = new QualifiedName(CCorePlugin.PLUGIN_ID, "activeConfiguration");
QualifiedName settingCfg = new QualifiedName(CCorePlugin.PLUGIN_ID, "settingConfiguration");
QualifiedName discoveredScannerConfigFileName = new QualifiedName(MakeCorePlugin.PLUGIN_ID,
"discoveredScannerConfigFileName");
QualifiedName pdomName = new QualifiedName(CCorePlugin.PLUGIN_ID, "pdomName");
QualifiedName activeCfg = new QualifiedName(CCorePlugin.PLUGIN_ID, "activeConfiguration");
QualifiedName settingCfg = new QualifiedName(CCorePlugin.PLUGIN_ID, "settingConfiguration");
QualifiedName discoveredScannerConfigFileName = new QualifiedName(MakeCorePlugin.PLUGIN_ID,
"discoveredScannerConfigFileName");
// pdomName is set by indexer setup, which may still be postponed or not even
// scheduled yet, so we can't join the job. Just wait for the property to appear.
// (The other properties were set synchronously in setProjectDescription().)
for (int i = 0; i < 100 && !project.getPersistentProperties().containsKey(pdomName); i++) {
Thread.sleep(100);
}
assertTrue("pdomName", project.getPersistentProperties().containsKey(pdomName));
assertTrue("activeCfg", project.getPersistentProperties().containsKey(activeCfg));
assertTrue("discoveredScannerConfigFileName",
project.getPersistentProperties().containsKey(discoveredScannerConfigFileName));
assertTrue("settingCfg", project.getPersistentProperties().containsKey(settingCfg));
} catch (CoreException e) {
Assert.fail(e.getMessage());
// pdomName is set by indexer setup, which may still be postponed or not even
// scheduled yet, so we can't join the job. Just wait for the property to appear.
// (The other properties were set synchronously in setProjectDescription().)
for (int i = 0; i < 100 && !project.getPersistentProperties().containsKey(pdomName); i++) {
Thread.sleep(100);
}
assertTrue(project.getPersistentProperties().containsKey(pdomName), "pdomName");
assertTrue(project.getPersistentProperties().containsKey(activeCfg), "activeCfg");
assertTrue(project.getPersistentProperties().containsKey(discoveredScannerConfigFileName),
"discoveredScannerConfigFileName");
assertTrue(project.getPersistentProperties().containsKey(settingCfg), "settingCfg");
ResourceHelper.joinIndexerBeforeCleanup(getName());
project.close(null);
}
}
@Test
public void testResetDefaultSetings_Bug298590() throws Exception {
String pluginProjectTypeId = "cdt.managedbuild.target.gnu.cygwin.exe";
@ -246,8 +232,8 @@ public class CProjectDescriptionSerializationTests extends TestCase {
// Initial project description after creating the project
ICProjectDescription initialProjectDescription = mngr.getProjectDescription(project);
assertNotNull("createDescription returned null!", initialProjectDescription);
assertEquals(2, initialProjectDescription.getConfigurations().length);
assertNotNull(initialProjectDescription, "createDescription returned null!");
assertEquals((Object) 2, (Object) initialProjectDescription.getConfigurations().length);
{
// No folder description initially as it does not have any custom settings

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
@ -47,23 +48,19 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class OptionStringListValueTests extends TestCase {
public class OptionStringListValueTests extends BaseTestCase {
private static final String PROJ_NAME_PREFIX = "OptionStringListValueTests_";
public static Test suite() {
return new TestSuite(OptionStringListValueTests.class);
}
@Override
protected void setUp() throws Exception {
}
@Override
protected void tearDown() throws Exception {
ResourceHelper.cleanUp(getName());
super.tearDown();
}
public void testCfgDesEntries() throws Exception {

View file

@ -40,6 +40,7 @@ import org.eclipse.cdt.core.settings.model.ICSourceEntry;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.settings.model.extension.CLanguageData;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
@ -67,10 +68,9 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ProjectModelTests extends TestCase implements IElementChangedListener {
public class ProjectModelTests extends BaseTestCase implements IElementChangedListener {
private boolean isPrint = false;
private CDefaultModelEventChecker fEventChecker;
@ -105,9 +105,9 @@ public class ProjectModelTests extends TestCase implements IElementChangedListen
@Override
protected void tearDown() throws Exception {
super.tearDown();
fEventChecker = null;
CoreModel.getDefault().removeElementChangedListener(this);
super.tearDown();
}
private void modify(ICFileDescription fiDes) {