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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*******************************************************************************
* Copyright (c) 2011 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
public class OptionCategoryEnablementTests extends TestCase {
private static final String testName = "optcaten"; //$NON-NLS-1$
private static boolean fHandleValueCalled;
public static Test suite() {
return new TestSuite(OptionCategoryEnablementTests.class);
}
private void resetValueHandler(){
fHandleValueCalled = false;
}
public void testEnablement(){
resetValueHandler();
IProject project = ManagedBuildTestHelper.createProject(testName,
"cdt.managedbuild.target.enablement.exe"); //$NON-NLS-1$
IFolder folder = ManagedBuildTestHelper.createFolder(project, "Folder");
IFile aFile = ManagedBuildTestHelper.createFile(project, "a.c"); //$NON-NLS-1$
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
IConfiguration cfg = info.getManagedProject().getConfigurations()[0];
assertFalse(fHandleValueCalled);
doTestEnablement(cfg, folder, aFile);
ManagedBuildTestHelper.removeProject(testName);
}
private void doTestEnablement(IBuildObject cfg, IFolder folder, IFile file){
final String TOOL_ID = "enablement.this"; //$NON-NLS-1$
final String OPTION_ID = "enablement.trigger"; //$NON-NLS-1$
final String CATEGORY_ID = "enablement.category"; //$NON-NLS-1$
IOption option;
IOptionCategory optionCategory;
try{
ITool tool = getTool(cfg, TOOL_ID);
option = tool.getOptionBySuperClassId(OPTION_ID);
assertEquals(option.getBooleanValue(),false);
// Config Level
// trigger option is false, so category should not be visible
optionCategory = tool.getOptionCategory(CATEGORY_ID);
assertFalse(optionCategory.getApplicabilityCalculator().isOptionCategoryVisible(cfg, tool, optionCategory));
// set the trigger option
((IConfiguration) cfg).setOption(tool, option, true);
// trigger option is true, so category should be visible
assertTrue(optionCategory.getApplicabilityCalculator().isOptionCategoryVisible(cfg, tool, optionCategory));
// Folder Level
IResourceInfo folderInfo = ((IConfiguration) cfg).getResourceInfo(folder.getFullPath(),false);
assertNotNull(folderInfo);
// unset the trigger option
option = getOptionForFolder((IFolderInfo)folderInfo, TOOL_ID, OPTION_ID);
assertNotNull(option);
folderInfo.setOption(tool, option, false);
// category should not be visible
optionCategory = getOptionCategoryForFolder((IFolderInfo)folderInfo, /*TOOL_ID,*/ CATEGORY_ID);
assertNotNull(optionCategory);
assertFalse(optionCategory.getApplicabilityCalculator().isOptionCategoryVisible(cfg, tool, optionCategory));
// set the trigger option
folderInfo.setOption(tool, option, true);
// category should be visible
assertTrue(optionCategory.getApplicabilityCalculator().isOptionCategoryVisible(cfg, tool, optionCategory));
// File Level
// set the trigger option
IResourceConfiguration fileInfo = ((IConfiguration) cfg).getResourceConfiguration(file.getFullPath().toString());
if (fileInfo==null)
fileInfo = ((IConfiguration) cfg).createResourceConfiguration(file);
option = getOptionForFile((IFileInfo)fileInfo, OPTION_ID);
assertNotNull(option);
fileInfo.setOption(tool, option, false);
optionCategory = getOptionCategoryForFile((IFileInfo)fileInfo, CATEGORY_ID);
assertNotNull(optionCategory);
// category should not be visible
assertFalse(optionCategory.getApplicabilityCalculator().isOptionCategoryVisible(cfg, tool, optionCategory));
// set the trigger option
fileInfo.setOption(tool, option, true);
// category should be visible
assertTrue(optionCategory.getApplicabilityCalculator().isOptionCategoryVisible(cfg, tool, optionCategory));
}catch (BuildException e){
fail(e.getLocalizedMessage());
}
}
private ITool getTool(IBuildObject cfgBo, String id){
IResourceConfiguration rcCfg = null;
IConfiguration cfg = null;
ITool tool = null;
if(cfgBo instanceof IResourceConfiguration){
rcCfg = (IResourceConfiguration)cfgBo;
cfg = rcCfg.getParent();
ITool tools[] = rcCfg.getTools();
for(int i = 0; i < tools.length; i++){
for(ITool tmp = tools[i]; tmp != null; tmp=tmp.getSuperClass()){
if(tmp.getId().equals(id)){
tool = tools[i];
break;
}
}
}
} else if(cfgBo instanceof IConfiguration){
cfg = (IConfiguration)cfgBo;
tool = cfg.getToolsBySuperClassId(id)[0];
} else
fail("wrong argument");
return tool;
}
private IOption getOptionForFolder(IFolderInfo rcInfo, String toolId, String optionId) {
ITool[] tools = null;
tools = rcInfo.getToolsBySuperClassId(toolId);
assertNotNull(tools);
ITool tool = tools[0];
assertNotNull(tool);
IOption option = tool.getOptionBySuperClassId(optionId);
return option;
}
private IOption getOptionForFile(IFileInfo rcInfo, String optionId) {
ITool[] tools = null;
tools = rcInfo.getTools();
assertNotNull(tools);
ITool tool = tools[0];
assertNotNull(tool);
IOption option = tool.getOptionBySuperClassId(optionId);
return option;
}
private IOptionCategory getOptionCategoryForFolder(IFolderInfo rcInfo, String categoryId) {
ITool[] tools = rcInfo.getTools();
tools = rcInfo.getTools();
assertNotNull(tools);
ITool tool = tools[0];
assertNotNull(tool);
IOptionCategory optionCategory = tool.getOptionCategory(categoryId);
return optionCategory;
}
private IOptionCategory getOptionCategoryForFile(IFileInfo rcInfo, String categoryId) {
ITool[] tools = rcInfo.getTools();
tools = rcInfo.getTools();
assertNotNull(tools);
ITool tool = tools[0];
assertNotNull(tool);
IOptionCategory optionCategory = tool.getOptionCategory(categoryId);
return optionCategory;
}
}
|