blob: a2e09593c3b9486c6917ab8524bec3ea8b037680 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*******************************************************************************
* Copyright (c) 2009, 2013 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.build.core.scannerconfig.tests;
import java.util.Map;
import org.eclipse.cdt.build.core.scannerconfig.CfgInfoContext;
import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set;
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager;
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import junit.framework.Test;
import junit.framework.TestSuite;
public class CfgScannerConfigProfileManagerTests extends BaseTestCase {
IProject fProject;
public static Test suite() {
TestSuite suite = new TestSuite(CfgScannerConfigProfileManagerTests.class.getName());
suite.addTestSuite(CfgScannerConfigProfileManagerTests.class);
return suite;
}
@Override
protected void setUp() throws Exception {
fProject = ManagedBuildTestHelper.createProject("CfgScannerConfigProfileManagerProj",
"cdt.managedbuild.target.gnu.exe");
ManagedBuildTestHelper.addManagedBuildNature(fProject);
}
@Override
protected void tearDown() throws Exception {
ResourceHelper.cleanUp(getName());
ManagedBuildTestHelper.removeProject(fProject.getName());
}
/**
* Basic testing of Config based ScannerConfigProfile management.
*
* This test runs through some of the funcationality used by the DiscoveryTab
* @throws CoreException
*/
public void testBasicCfgScannerConfigProfileChanges() throws CoreException {
ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(fProject, false);
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(fProject);
ICConfigurationDescription[] cfgDescs = prjDesc.getConfigurations();
assertTrue(cfgDescs.length > 0);
IConfiguration cfg0 = ManagedBuildManager.getConfigurationForDescription(cfgDescs[0]);
ICfgScannerConfigBuilderInfo2Set scbis = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(cfg0);
// Test changing ICfgScannerConfigBuilderInfo2Set settings
boolean resCfgTypeDiscovery = scbis.isPerRcTypeDiscovery();
scbis.setPerRcTypeDiscovery(!resCfgTypeDiscovery);
// Test changing settings on one of the ScannerConfigBuilderInfos
Map<CfgInfoContext, IScannerConfigBuilderInfo2> infoMap = scbis.getInfoMap();
CfgInfoContext cic = infoMap.entrySet().iterator().next().getKey();
IScannerConfigBuilderInfo2 scbi = infoMap.entrySet().iterator().next().getValue();
// Get all the settings and invert them
boolean autoDiscovery = scbi.isAutoDiscoveryEnabled();
scbi.setAutoDiscoveryEnabled(!autoDiscovery);
boolean problemReport = scbi.isProblemReportingEnabled();
scbi.setProblemReportingEnabled(!problemReport);
boolean buildOutputParser = scbi.isBuildOutputParserEnabled();
scbi.setBuildOutputParserEnabled(!buildOutputParser);
boolean buildOutputFileAction = scbi.isBuildOutputFileActionEnabled();
scbi.setBuildOutputFileActionEnabled(!buildOutputFileAction);
String buildOutputFilePath = scbi.getBuildOutputFilePath();
scbi.setBuildOutputFilePath("dummyFile");
// Persist the changes
scbis.applyInfo(cic, scbi);
// Save the project description
CoreModel.getDefault().setProjectDescription(fProject, prjDesc);
fProject.close(null);
fProject.open(null);
// Check that the changes have persisted
prjDesc = CoreModel.getDefault().getProjectDescription(fProject);
cfg0 = ManagedBuildManager.getConfigurationForDescription(prjDesc.getConfigurations()[0]);
scbis = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(cfg0);
assertTrue(scbis.isPerRcTypeDiscovery() != resCfgTypeDiscovery);
scbi = scbis.getInfo(cic);
// Check that the changes have persisted
Assert.isTrue(autoDiscovery != scbi.isAutoDiscoveryEnabled());
Assert.isTrue(problemReport != scbi.isProblemReportingEnabled());
Assert.isTrue(buildOutputParser != scbi.isBuildOutputParserEnabled());
Assert.isTrue(buildOutputFileAction != scbi.isBuildOutputFileActionEnabled());
Assert.isTrue("dummyFile".equals(scbi.getBuildOutputFilePath()));
// Test restore defaults
scbis.applyInfo(cic, null);
// Save the project description
CoreModel.getDefault().setProjectDescription(fProject, prjDesc);
fProject.close(null);
fProject.open(null);
// Check settings are back to original
prjDesc = CoreModel.getDefault().getProjectDescription(fProject);
cfg0 = ManagedBuildManager.getConfigurationForDescription(prjDesc.getConfigurations()[0]);
scbis = CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(cfg0);
scbi = scbis.getInfo(cic);
Assert.isTrue(autoDiscovery == scbi.isAutoDiscoveryEnabled());
Assert.isTrue(problemReport == scbi.isProblemReportingEnabled());
Assert.isTrue(buildOutputParser == scbi.isBuildOutputParserEnabled());
Assert.isTrue(buildOutputFileAction == scbi.isBuildOutputFileActionEnabled());
Assert.isTrue(buildOutputFilePath.equals(buildOutputFilePath));
}
}
|