~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/projectmodel/tests/ProjectModelTests.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2007, 2010 Intel Corporation and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 * Intel Corporation - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.projectmodel.tests;
 
12
 
 
13
import java.util.ArrayList;
 
14
import java.util.Arrays;
 
15
import java.util.List;
 
16
 
 
17
import junit.framework.Test;
 
18
import junit.framework.TestCase;
 
19
import junit.framework.TestSuite;
 
20
 
 
21
import org.eclipse.cdt.core.CCorePlugin;
 
22
import org.eclipse.cdt.core.model.CoreModel;
 
23
import org.eclipse.cdt.core.model.ElementChangedEvent;
 
24
import org.eclipse.cdt.core.model.ICElementDelta;
 
25
import org.eclipse.cdt.core.model.IElementChangedListener;
 
26
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
 
27
import org.eclipse.cdt.core.settings.model.CMacroEntry;
 
28
import org.eclipse.cdt.core.settings.model.CSourceEntry;
 
29
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
 
30
import org.eclipse.cdt.core.settings.model.ICFileDescription;
 
31
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
 
32
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
 
33
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
 
34
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
 
35
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
 
36
import org.eclipse.cdt.core.settings.model.ICSettingBase;
 
37
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
 
38
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
 
39
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
 
40
import org.eclipse.cdt.core.settings.model.extension.CLanguageData;
 
41
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
 
42
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
 
43
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
 
44
import org.eclipse.cdt.managedbuilder.core.IProjectType;
 
45
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
 
46
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
 
47
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
 
48
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
 
49
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
 
50
import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper;
 
51
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
 
52
import org.eclipse.core.resources.IProject;
 
53
import org.eclipse.core.resources.IProjectDescription;
 
54
import org.eclipse.core.resources.IResource;
 
55
import org.eclipse.core.resources.IWorkspace;
 
56
import org.eclipse.core.resources.IWorkspaceDescription;
 
57
import org.eclipse.core.resources.IWorkspaceRoot;
 
58
import org.eclipse.core.resources.IWorkspaceRunnable;
 
59
import org.eclipse.core.resources.ResourcesPlugin;
 
60
import org.eclipse.core.runtime.CoreException;
 
61
import org.eclipse.core.runtime.IPath;
 
62
import org.eclipse.core.runtime.IProgressMonitor;
 
63
import org.eclipse.core.runtime.NullProgressMonitor;
 
64
import org.eclipse.core.runtime.Path;
 
65
 
 
66
public class ProjectModelTests extends TestCase implements IElementChangedListener{
 
67
        private boolean isPrint = false;
 
68
        private CDefaultModelEventChecker fEventChecker;
 
69
        
 
70
        public void elementChanged(ElementChangedEvent event) {
 
71
                if(fEventChecker != null)
 
72
                        fEventChecker.checkEvent(event);
 
73
        }
 
74
        
 
75
        private class CDefaultModelEventChecker {
 
76
 
 
77
                void checkEvent(ElementChangedEvent event) {
 
78
                        assertEquals(ElementChangedEvent.POST_CHANGE, event.getType());
 
79
                        
 
80
                        ICElementDelta delta = event.getDelta();
 
81
                        if (isPrint)
 
82
                                System.out.println(delta.toString());
 
83
                }
 
84
                
 
85
        }
 
86
        
 
87
        
 
88
 
 
89
        public static Test suite() {
 
90
                return new TestSuite(ProjectModelTests.class);
 
91
        }
 
92
        
 
93
        @Override
 
94
        protected void setUp() throws Exception {
 
95
                super.setUp();
 
96
                fEventChecker = null;
 
97
                CoreModel.getDefault().addElementChangedListener(this);
 
98
        }
 
99
 
 
100
        @Override
 
101
        protected void tearDown() throws Exception {
 
102
                super.tearDown();
 
103
                fEventChecker = null;
 
104
                CoreModel.getDefault().removeElementChangedListener(this);
 
105
        }
 
106
 
 
107
        private void modify(ICFileDescription fiDes){
 
108
                ICLanguageSetting ls = fiDes.getLanguageSetting();
 
109
                modify(ls);
 
110
        }
 
111
        
 
112
        private void modify(ICFolderDescription foDes){
 
113
                ICLanguageSetting ls = foDes.getLanguageSettingForFile("a.c");
 
114
                modify(ls);
 
115
        }
 
116
        
 
117
        private void modify(ICLanguageSetting ls){
 
118
                List<ICLanguageSettingEntry> list = ls.getSettingEntriesList(ICSourceEntry.INCLUDE_PATH);
 
119
                list.add(new CIncludePathEntry("_modify_", 0));
 
120
                ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, list);
 
121
        }
 
122
 
 
123
        private void modify(IFileInfo fiInfo){
 
124
                CLanguageData lData = fiInfo.getCLanguageDatas()[0];
 
125
                modify(lData);
 
126
        }
 
127
        
 
128
        private void modify(CLanguageData lData){
 
129
                ICLanguageSettingEntry[] entries = lData.getEntries(ICSourceEntry.INCLUDE_PATH);
 
130
                ICLanguageSettingEntry[] updatedEntries = new ICLanguageSettingEntry[entries.length + 1];
 
131
                System.arraycopy(entries, 0, updatedEntries, 0, entries.length);
 
132
                updatedEntries[entries.length] = new CIncludePathEntry("_modify_", 0);
 
133
                lData.setEntries(ICSettingEntry.INCLUDE_PATH, updatedEntries);
 
134
        }
 
135
 
 
136
        public void testDescription() throws Exception{
 
137
                final String projectName = "test1";
 
138
                IProject project = createProject(projectName);
 
139
                CoreModel coreModel = CoreModel.getDefault();
 
140
                ICProjectDescription des = coreModel.getProjectDescription(project);
 
141
                assertNull("detDescription1 returned not null!", des);
 
142
                
 
143
                des = coreModel.createProjectDescription(project, true);
 
144
                assertNotNull("createDescription returned null!", des);
 
145
                
 
146
                assertNull("detDescription2 returned not null!", coreModel.getProjectDescription(project));
 
147
                
 
148
                assertFalse("new des should be not valid", des.isValid());
 
149
                
 
150
                assertEquals(0, des.getConfigurations().length);
 
151
                
 
152
                ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
 
153
                IProjectType type = ManagedBuildManager.getProjectType("cdt.managedbuild.target.gnu30.exe");
 
154
                assertNotNull("project type not found", type);
 
155
 
 
156
                ManagedProject mProj = new ManagedProject(project, type);
 
157
                info.setManagedProject(mProj);
 
158
                
 
159
                IConfiguration cfgs[] = type.getConfigurations();
 
160
                
 
161
 
 
162
                for(int i = 0; i < cfgs.length; i++){
 
163
                        String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
 
164
                        Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true, false);
 
165
                        CConfigurationData data = config.getConfigurationData();
 
166
                        assertNotNull("data is null for created configuration", data);
 
167
                        des.createConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider", data);
 
168
                }
 
169
                coreModel.setProjectDescription(project, des);
 
170
                
 
171
                IWorkspace wsp = ResourcesPlugin.getWorkspace();
 
172
                IWorkspaceRoot root = wsp.getRoot(); 
 
173
                project.delete(false, true, new NullProgressMonitor());
 
174
                
 
175
                project = root.getProject(projectName);
 
176
                des = coreModel.getProjectDescription(project);
 
177
                assertNull("project description is not null for removed project", des);
 
178
                
 
179
                project = createProject(projectName);
 
180
                des = coreModel.getProjectDescription(project);
 
181
                assertNotNull("project description is null for re-created project", des);
 
182
                assertTrue("des should be valid for re-created project", des.isValid());
 
183
                
 
184
                ICConfigurationDescription cfgDess[] = des.getConfigurations();
 
185
                
 
186
                assertEquals(2, cfgDess.length);
 
187
                
 
188
                ICConfigurationDescription cfgDes = cfgDess[0];
 
189
                ICResourceDescription rcDess[] = cfgDes.getResourceDescriptions();
 
190
                assertEquals(1, rcDess.length);
 
191
                assertEquals(cfgDes.getRootFolderDescription(), rcDess[0]);
 
192
                assertFalse(cfgDes.isModified());
 
193
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
 
194
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
 
195
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
 
196
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), false));
 
197
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
 
198
                assertEquals(null, cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), true));
 
199
                
 
200
                ICFileDescription fd_abc = cfgDes.createFileDescription(new Path("a/b/c.c"), rcDess[0]);
 
201
                
 
202
                assertTrue(cfgDes.isModified());
 
203
 
 
204
                modify(fd_abc);
 
205
                
 
206
                        ICProjectDescription anotherDes = coreModel.getProjectDescription(project);
 
207
                        assertNotNull("project description is null for re-created project", des);
 
208
                        assertTrue("des should be valid for re-created project", des.isValid());
 
209
                        
 
210
                        ICConfigurationDescription anotherCfgDess[] = anotherDes.getConfigurations();
 
211
                        
 
212
                        assertEquals(2, anotherCfgDess.length);
 
213
                        
 
214
                        ICConfigurationDescription anotherCfgDes = anotherCfgDess[0];
 
215
                        ICResourceDescription anotherRcDess[] = anotherCfgDes.getResourceDescriptions();
 
216
                        assertEquals(1, anotherRcDess.length);
 
217
                        assertEquals(anotherCfgDes.getRootFolderDescription(), anotherRcDess[0]);
 
218
                        assertFalse(anotherCfgDes.isModified());
 
219
                
 
220
                CConfigurationData cfgData = cfgDes.getConfigurationData();
 
221
                assertEquals(cfgData, cfgDes.getConfigurationData());
 
222
                IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);
 
223
                IResourceInfo infos[] = cfg.getResourceInfos();
 
224
                assertEquals(2, infos.length);
 
225
 
 
226
                ICFolderDescription rf = cfgDes.getRootFolderDescription();
 
227
                ICResourceDescription nestedFis[] = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
 
228
                ICResourceDescription nestedFos[] = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
 
229
                assertEquals(2, cfgDes.getResourceDescriptions().length);
 
230
                assertEquals(0, nestedFos.length);
 
231
                assertEquals(1, nestedFis.length);
 
232
                
 
233
                ICFileDescription fd_asd = cfgDes.createFileDescription(new Path("a/s/d.c"), cfgDes.getRootFolderDescription());
 
234
                modify(fd_asd);
 
235
                assertEquals(3, cfgDes.getResourceDescriptions().length);
 
236
                nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
 
237
                nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
 
238
                assertEquals(0, nestedFos.length);
 
239
                assertEquals(2, nestedFis.length);
 
240
                
 
241
                IFileInfo fi = cfg.createFileInfo(new Path("z/x/c.c"));
 
242
                modify(fi);
 
243
                nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
 
244
                nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
 
245
                assertEquals(0, nestedFos.length);
 
246
                assertEquals(3, nestedFis.length);
 
247
                assertEquals(4, cfgDes.getResourceDescriptions().length);
 
248
 
 
249
                fi = cfg.createFileInfo(new Path("q/w/e.c"));
 
250
                modify(fi);
 
251
                ICFileDescription fd_qwe = (ICFileDescription)cfgDes.getResourceDescription(new Path("q/w/e.c"), true);
 
252
                assertNotNull(fd_qwe);
 
253
                assertEquals(5, cfgDes.getResourceDescriptions().length);
 
254
                nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
 
255
                nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
 
256
                assertEquals(0, nestedFos.length);
 
257
                assertEquals(4, nestedFis.length);
 
258
                
 
259
                cfgDes.removeResourceDescription(fd_abc);
 
260
                nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
 
261
                nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
 
262
                assertEquals(0, nestedFos.length);
 
263
                assertEquals(3, nestedFis.length);
 
264
                assertEquals(4, cfgDes.getResourceDescriptions().length);
 
265
 
 
266
                cfg.removeResourceInfo(new Path("a/s/d.c"));
 
267
                assertEquals(3, cfgDes.getResourceDescriptions().length);
 
268
                nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
 
269
                nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
 
270
                assertEquals(0, nestedFos.length);
 
271
                assertEquals(2, nestedFis.length);
 
272
                
 
273
                IFileInfo fi_qwe = (IFileInfo)cfg.getResourceInfo(new Path("q/w/e.c"), true);
 
274
                assertNotNull(fi_qwe);
 
275
                
 
276
                ICFileDescription fid_qwe = (ICFileDescription)cfgDes.getResourceDescription(new Path("q/w/e.c"), true);
 
277
                assertNotNull(fid_qwe);
 
278
                fi_qwe.setPath(new Path("r/t/y.c"));
 
279
                assertEquals(fi_qwe, cfg.getResourceInfo(new Path("r/t/y.c"), true));
 
280
                assertNull(cfgDes.getResourceDescription(new Path("q/w/e.c"), true));
 
281
                ICFileDescription fid_rty = (ICFileDescription)cfgDes.getResourceDescription(new Path("r/t/y.c"), true);
 
282
                assertEquals(fid_qwe, fid_rty);
 
283
                
 
284
                fid_rty.setPath(new Path("f/g/h.c"));
 
285
                assertNull(cfg.getResourceInfo(new Path("r/t/y.c"), true));
 
286
                IFileInfo fi_fgh = (IFileInfo)cfg.getResourceInfo(new Path("f/g/h.c"), true);
 
287
                assertEquals(fi_qwe, fi_fgh);
 
288
                
 
289
                ICFolderDescription fod_fg1 = cfgDes.createFolderDescription(new Path("f/g/1"), cfgDes.getRootFolderDescription());
 
290
                modify(fod_fg1);
 
291
                ICFolderDescription fod_fg12 = cfgDes.createFolderDescription(new Path("f/g/1/2"), fod_fg1);
 
292
                modify(fod_fg12);
 
293
                assertEquals(fod_fg12, fod_fg1.getNestedResourceDescription(new Path("2"), true));
 
294
 
 
295
                ICFileDescription fid_fg13 = cfgDes.createFileDescription(new Path("f/g/1/3.c"), fod_fg1);
 
296
                modify(fid_fg13);
 
297
                assertEquals(fid_fg13, fod_fg1.getNestedResourceDescription(new Path("3.c"), true));
 
298
                
 
299
                assertEquals(2, fod_fg1.getNestedResourceDescriptions().length);
 
300
                assertEquals(1, fod_fg1.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE).length);
 
301
                assertEquals(1, fod_fg1.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER).length);
 
302
 
 
303
                IFolderInfo fo_fg1 = (IFolderInfo)cfg.getResourceInfo(new Path("f/g/1"), true);
 
304
                assertNotNull(fo_fg1);
 
305
                
 
306
                fo_fg1.setPath(new Path("t/y/u"));
 
307
 
 
308
                assertEquals(2, fod_fg1.getNestedResourceDescriptions().length);
 
309
                assertEquals(1, fod_fg1.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE).length);
 
310
                assertEquals(1, fod_fg1.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER).length);
 
311
                
 
312
                assertEquals(fod_fg12, cfgDes.getResourceDescription(new Path("t/y/u/2"), true));
 
313
                assertEquals(fid_fg13, cfgDes.getResourceDescription(new Path("t/y/u/3.c"), true));
 
314
 
 
315
                ICLanguageSetting settings[] = cfgDes.getRootFolderDescription().getLanguageSettings();
 
316
                for(int i = 0; i < settings.length; i++){
 
317
                        ICLanguageSetting setting = settings[i];
 
318
                        ICLanguageSettingEntry[] entries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
 
319
                        if (!setting.supportsEntryKind(ICSettingEntry.INCLUDE_PATH))
 
320
                                assertTrue(entries.length == 0);
 
321
                        if (isPrint) {
 
322
                                for(int j = 0; j < entries.length; j++){
 
323
                                        System.out.println(entries[j].getName());
 
324
                                }
 
325
                                System.out.println(entries.length);
 
326
                        }
 
327
                }
 
328
                coreModel.setProjectDescription(project, des);
 
329
                
 
330
                project.delete(false, true, new NullProgressMonitor());
 
331
                
 
332
                project = root.getProject(projectName);
 
333
                assertFalse(project.exists());
 
334
                assertFalse(project.isOpen());
 
335
                des = coreModel.getProjectDescription(project);
 
336
                assertFalse(project.exists());
 
337
                assertFalse(project.isOpen());
 
338
                assertNull("project description is not null for removed project", des);
 
339
                
 
340
                project = createProject(projectName);
 
341
                long time = System.currentTimeMillis();
 
342
                des = coreModel.getProjectDescription(project);
 
343
                time = System.currentTimeMillis() - time;
 
344
                if (isPrint)
 
345
                        System.out.println("time to load = " + time);
 
346
                
 
347
                assertNotNull("project description is null for re-created project", des);
 
348
                assertTrue("des should be valid for re-created project", des.isValid());
 
349
                
 
350
                cfgDess = des.getConfigurations();
 
351
                cfgDes = cfgDess[0];
 
352
                rf = cfgDes.getRootFolderDescription();
 
353
                settings = rf.getLanguageSettings();
 
354
                ICLanguageSettingEntry updatedEntries[] = new ICLanguageSettingEntry[0];
 
355
                for(int i = 0; i < settings.length; i++){
 
356
                        ICLanguageSetting setting = settings[i];
 
357
                        ICLanguageSettingEntry[] entries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
 
358
                        if(entries.length > 0){
 
359
                                ICLanguageSettingEntry updated[] = new ICLanguageSettingEntry[entries.length + 1];
 
360
                                System.arraycopy(entries, 0, updated, 1, entries.length);
 
361
                                updated[0] = new CIncludePathEntry("a/b/c", 0);
 
362
                                setting.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, updated);
 
363
                                updatedEntries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
 
364
                                assertEquals(updated.length, updatedEntries.length);
 
365
                                for(int k = 0; k < updated.length; k++){
 
366
                                        assertEquals(updated[i].getValue(), updatedEntries[i].getValue());
 
367
                                }
 
368
                        }
 
369
                }
 
370
                
 
371
                fEventChecker = new CDefaultModelEventChecker();
 
372
                coreModel.setProjectDescription(project, des);
 
373
                fEventChecker = null;
 
374
                
 
375
                project.delete(false, true, new NullProgressMonitor());
 
376
                
 
377
                project = root.getProject(projectName);
 
378
                assertFalse(project.exists());
 
379
                assertFalse(project.isOpen());
 
380
                des = coreModel.getProjectDescription(project);
 
381
                assertNull("project description is not null for removed project", des);
 
382
                
 
383
                project = createProject(projectName);
 
384
                time = System.currentTimeMillis();
 
385
                des = coreModel.getProjectDescription(project);
 
386
                time = System.currentTimeMillis() - time;
 
387
                if (isPrint)
 
388
                        System.out.println("time to load = " + time);
 
389
                
 
390
                assertNotNull("project description is null for re-created project", des);
 
391
                assertTrue("des should be valid for re-created project", des.isValid());
 
392
                
 
393
                cfgDess = des.getConfigurations();
 
394
                cfgDes = cfgDess[0];
 
395
                rf = cfgDes.getRootFolderDescription();
 
396
                settings = rf.getLanguageSettings();
 
397
 
 
398
                for(int i = 0; i < settings.length; i++){
 
399
                        ICLanguageSetting setting = settings[i];
 
400
                        ICLanguageSettingEntry[] entries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
 
401
                        if (setting.supportsEntryKind(ICSettingEntry.INCLUDE_PATH)) {
 
402
                                BuildSystemTestHelper.checkDiff(entries, updatedEntries);
 
403
                                assertEquals(entries.length, updatedEntries.length);
 
404
                                for(int k = 0; k < entries.length; k++)
 
405
                                        assertEquals(entries[i].getValue(), updatedEntries[i].getValue());
 
406
                        } else
 
407
                                assertTrue(entries.length == 0);
 
408
                }
 
409
 
 
410
                assertEquals(2, cfgDess.length);
 
411
                nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
 
412
                nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
 
413
                assertEquals(2, nestedFos.length);
 
414
                assertEquals(3, nestedFis.length);
 
415
                
 
416
                assertEquals(6, cfgDes.getResourceDescriptions().length);
 
417
                
 
418
                ManagedBuildTestHelper.createFolder(project, "a/b");
 
419
                ICFolderDescription base = (ICFolderDescription)cfgDes.getResourceDescription(new Path("a/b"), false);
 
420
                ICFolderDescription abFoDes =  cfgDes.createFolderDescription(new Path("a/b"), base);
 
421
                ICLanguageSetting ls = abFoDes.getLanguageSettingForFile("a.c");
 
422
                assertNotNull(ls);
 
423
                List<ICLanguageSettingEntry> list = ls.getSettingEntriesList(ICLanguageSettingEntry.INCLUDE_PATH);
 
424
                list.add(0, new CIncludePathEntry("zzza/b/c", 0));
 
425
                ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, list);
 
426
 
 
427
                if (isPrint)
 
428
                        System.out.println("setting entries for non-root folder..\n");
 
429
                fEventChecker = new CDefaultModelEventChecker();
 
430
                coreModel.setProjectDescription(project, des);
 
431
                fEventChecker = null;
 
432
                
 
433
                time = System.currentTimeMillis();
 
434
                des = coreModel.getProjectDescription(project);
 
435
                time = System.currentTimeMillis() - time;
 
436
                if (isPrint)
 
437
                        System.out.println("time to load = " + time);
 
438
                
 
439
                assertNotNull("project description is null for re-created project", des);
 
440
                assertTrue("des should be valid for re-created project", des.isValid());
 
441
                
 
442
                cfgDess = des.getConfigurations();
 
443
                cfgDes = cfgDess[0];
 
444
                rf = cfgDes.getRootFolderDescription();
 
445
                
 
446
                ManagedBuildTestHelper.createFolder(project, "b/c");
 
447
                base = (ICFolderDescription)cfgDes.getResourceDescription(new Path("b/c"), false);
 
448
                ICFolderDescription bcFoDes =  cfgDes.createFolderDescription(new Path("b/c"), base);
 
449
                ls = bcFoDes.getLanguageSettingForFile("a.c");
 
450
                assertNotNull(ls);
 
451
                ICLanguageSetting rLS = rf.getLanguageSettingForFile("a.c");
 
452
                assertNotNull(rLS);
 
453
                ls.getSettingEntriesList(ICLanguageSettingEntry.INCLUDE_PATH);
 
454
                rLS.getSettingEntriesList(ICLanguageSettingEntry.INCLUDE_PATH);
 
455
                
 
456
                if (isPrint)
 
457
                        System.out.println("default entries for non-root folder..\n");
 
458
                fEventChecker = new CDefaultModelEventChecker();
 
459
                coreModel.setProjectDescription(project, des);
 
460
                fEventChecker = null;
 
461
 
 
462
                project.delete(true, true, new NullProgressMonitor());
 
463
        }
 
464
        
 
465
        public void testSourceEntries() throws Exception {
 
466
                final String projectName = "test2";
 
467
                IProject project = createProject(projectName);
 
468
                CoreModel coreModel = CoreModel.getDefault();
 
469
                ICProjectDescription des = coreModel.getProjectDescription(project);
 
470
                assertNull("detDescription1 returned not null!", des);
 
471
                
 
472
                des = coreModel.createProjectDescription(project, true);
 
473
                assertNotNull("createDescription returned null!", des);
 
474
                
 
475
                assertNull("detDescription2 returned not null!", coreModel.getProjectDescription(project));
 
476
                
 
477
                assertFalse("new des should be not valid", des.isValid());
 
478
                
 
479
                assertEquals(0, des.getConfigurations().length);
 
480
                
 
481
                ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
 
482
                IProjectType type = ManagedBuildManager.getProjectType("cdt.managedbuild.target.gnu30.exe");
 
483
                assertNotNull("project type not found", type);
 
484
 
 
485
                ManagedProject mProj = new ManagedProject(project, type);
 
486
                info.setManagedProject(mProj);
 
487
                
 
488
                IConfiguration cfgs[] = type.getConfigurations();
 
489
                
 
490
 
 
491
                for(int i = 0; i < cfgs.length; i++){
 
492
                        String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
 
493
                        Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true);
 
494
                        CConfigurationData data = config.getConfigurationData();
 
495
                        assertNotNull("data is null for created configuration", data);
 
496
                        des.createConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider", data);
 
497
                }
 
498
                coreModel.setProjectDescription(project, des);
 
499
                
 
500
                IWorkspace wsp = ResourcesPlugin.getWorkspace();
 
501
                IWorkspaceRoot root = wsp.getRoot(); 
 
502
                project.delete(false, true, new NullProgressMonitor());
 
503
                
 
504
                project = root.getProject(projectName);
 
505
                des = coreModel.getProjectDescription(project);
 
506
                assertNull("project description is not null for removed project", des);
 
507
                
 
508
                project = createProject(projectName);
 
509
                des = coreModel.getProjectDescription(project);
 
510
                assertNotNull("project description is null for re-created project", des);
 
511
                assertTrue("des should be valid for re-created project", des.isValid());
 
512
                
 
513
                ICConfigurationDescription cfgDess[] = des.getConfigurations();
 
514
                
 
515
                assertEquals(2, cfgDess.length);
 
516
                
 
517
                ICConfigurationDescription cfgDes = cfgDess[0];
 
518
                ICResourceDescription rcDess[] = cfgDes.getResourceDescriptions();
 
519
                assertEquals(1, rcDess.length);
 
520
                assertEquals(cfgDes.getRootFolderDescription(), rcDess[0]);
 
521
                assertFalse(cfgDes.isModified());
 
522
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
 
523
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
 
524
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
 
525
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), false));
 
526
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
 
527
                assertEquals(null, cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), true));
 
528
 
 
529
                ICSourceEntry s[] = cfgDes.getSourceEntries();
 
530
                IPath projPath = cfgDes.getProjectDescription().getProject().getFullPath();
 
531
                assertEquals(1, s.length);
 
532
                assertEquals(projPath, s[0].getFullPath());
 
533
                assertEquals(0, s[0].getExclusionPatterns().length);
 
534
                
 
535
                ManagedBuildTestHelper.createFolder(project, "a/b");
 
536
 
 
537
                ICSourceEntry updatetSEs[] = new ICSourceEntry[2];
 
538
                updatetSEs[0] = new CSourceEntry(projPath.append("a"), new Path[]{new Path("b")}, ICSourceEntry.VALUE_WORKSPACE_PATH);
 
539
                updatetSEs[1] = s[0];
 
540
                
 
541
                cfgDes.setSourceEntries(updatetSEs);
 
542
                
 
543
                s = cfgDes.getSourceEntries();
 
544
                updatetSEs[1] = new CSourceEntry(projPath, new Path[]{new Path("a")}, ICSourceEntry.VALUE_WORKSPACE_PATH | ICSourceEntry.RESOLVED);
 
545
                checkArrays(updatetSEs, s);
 
546
                //assertTrue(Arrays.equals(updatetSEs, s));
 
547
 
 
548
                if (isPrint)
 
549
                        System.out.println("saving updated source entries..\n");
 
550
                fEventChecker = new CDefaultModelEventChecker();
 
551
                coreModel.setProjectDescription(project, des);
 
552
                fEventChecker = null;
 
553
                
 
554
                des = coreModel.getProjectDescription(project);
 
555
                cfgDes = des.getConfigurations()[0];
 
556
                checkArrays(cfgDes.getSourceEntries(), s);
 
557
                
 
558
                project.delete(true, true, new NullProgressMonitor());
 
559
        }
 
560
 
 
561
        public void testMacroEntries() throws Exception {
 
562
                final String projectName = "test3";
 
563
                IProject project = createProject(projectName);
 
564
                CoreModel coreModel = CoreModel.getDefault();
 
565
                ICProjectDescription des = coreModel.getProjectDescription(project);
 
566
                assertNull("detDescription1 returned not null!", des);
 
567
                
 
568
                des = coreModel.createProjectDescription(project, true);
 
569
                assertNotNull("createDescription returned null!", des);
 
570
                
 
571
                assertNull("detDescription2 returned not null!", coreModel.getProjectDescription(project));
 
572
                
 
573
                assertFalse("new des should be not valid", des.isValid());
 
574
                
 
575
                assertEquals(0, des.getConfigurations().length);
 
576
                
 
577
                ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
 
578
                IProjectType type = ManagedBuildManager.getProjectType("cdt.managedbuild.target.gnu30.exe");
 
579
                assertNotNull("project type not found", type);
 
580
 
 
581
                ManagedProject mProj = new ManagedProject(project, type);
 
582
                info.setManagedProject(mProj);
 
583
                
 
584
                IConfiguration cfgs[] = type.getConfigurations();
 
585
                
 
586
                for(int i = 0; i < cfgs.length; i++){
 
587
                        String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
 
588
                        Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true);
 
589
                        CConfigurationData data = config.getConfigurationData();
 
590
                        assertNotNull("data is null for created configuration", data);
 
591
                        des.createConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider", data);
 
592
                }
 
593
                coreModel.setProjectDescription(project, des);
 
594
 
 
595
                des = coreModel.getProjectDescription(project);
 
596
                assertNotNull("project description is null ", des);
 
597
                assertTrue("des should be valid ", des.isValid());
 
598
                
 
599
                ICConfigurationDescription cfgDess[] = des.getConfigurations();
 
600
                
 
601
                assertEquals(2, cfgDess.length);
 
602
                
 
603
                ICConfigurationDescription cfgDes = cfgDess[0];
 
604
                ICResourceDescription rcDess[] = cfgDes.getResourceDescriptions();
 
605
                assertEquals(1, rcDess.length);
 
606
                assertEquals(cfgDes.getRootFolderDescription(), rcDess[0]);
 
607
                assertFalse(cfgDes.isModified());
 
608
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
 
609
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
 
610
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
 
611
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), false));
 
612
                assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
 
613
                assertEquals(null, cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), true));
 
614
 
 
615
                ICFolderDescription rf = cfgDes.getRootFolderDescription();
 
616
                ICLanguageSetting setting = rf.getLanguageSettingForFile("a.c");
 
617
                ICLanguageSettingEntry entries[] = setting.getSettingEntries(ICLanguageSettingEntry.MACRO);
 
618
                
 
619
                if (isPrint) {
 
620
                        for(int i = 0; i < entries.length; i++){
 
621
                                System.out.println("name = \"" + entries[i].getName() + "\", value = \"" + entries[i].getValue() + "\"");
 
622
                        }
 
623
                }
 
624
                
 
625
                CMacroEntry entry = new CMacroEntry("a", "b", 0);
 
626
                List<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>();
 
627
                list.add(entry);
 
628
                list.addAll(Arrays.asList(entries));
 
629
                
 
630
                setting.setSettingEntries(ICLanguageSettingEntry.MACRO, list);
 
631
        
 
632
                ICLanguageSettingEntry updatedEntries[] = setting.getSettingEntries(ICLanguageSettingEntry.MACRO);
 
633
                assertEquals(entries.length + 1, updatedEntries.length);
 
634
                
 
635
                boolean found = false;
 
636
                for(int i = 0; i < updatedEntries.length; i++){
 
637
                        if(updatedEntries[i].getName().equals("a") 
 
638
                                        && updatedEntries[i].getValue().equals("b")){
 
639
                                found = true;
 
640
                                break;
 
641
                        }
 
642
                }
 
643
                
 
644
                assertTrue(found);
 
645
        }
 
646
        
 
647
        public void testActiveCfg() throws Exception{
 
648
                final String projectName = "test8";
 
649
                
 
650
                IProject project = createProject(projectName, "cdt.managedbuild.target.gnu30.exe");
 
651
                CoreModel coreModel = CoreModel.getDefault();
 
652
                
 
653
                ICProjectDescription des = coreModel.getProjectDescription(project);
 
654
                ICConfigurationDescription cfgs[] = des.getConfigurations();
 
655
                String id1 = cfgs[0].getId();
 
656
                cfgs[1].getId();
 
657
                
 
658
                cfgs[0].setActive();
 
659
                assertEquals(cfgs[0], des.getActiveConfiguration());
 
660
                
 
661
                coreModel.setProjectDescription(project, des);
 
662
                
 
663
                des = coreModel.getProjectDescription(project);
 
664
                cfgs = des.getConfigurations();
 
665
                assertEquals(id1, des.getActiveConfiguration().getId());
 
666
                
 
667
                ICConfigurationDescription newActive = null;
 
668
                for(int i = 0; i < cfgs.length; i++){
 
669
                        if(!cfgs[i].getId().equals(id1)){
 
670
                                newActive = cfgs[i];
 
671
                                break;
 
672
                        }
 
673
                }
 
674
                
 
675
                String newActiveId = newActive.getId();
 
676
                newActive.setActive();
 
677
                assertEquals(newActive, des.getActiveConfiguration());
 
678
                
 
679
                coreModel.setProjectDescription(project, des);
 
680
                
 
681
                des = coreModel.getProjectDescription(project);
 
682
                assertEquals(newActiveId, des.getActiveConfiguration().getId());
 
683
                
 
684
                
 
685
        }
 
686
 
 
687
        private void checkArrays(Object[] a1, Object[] a2){
 
688
                if(a1 == null){
 
689
                        assertTrue(a2 == null);
 
690
                        return;
 
691
                }
 
692
                assertTrue(a2 != null);
 
693
 
 
694
                assertEquals(a1.length, a2.length);
 
695
                
 
696
                for(int i = 0; i < a1.length; i++){
 
697
                        Object o1 = a1[i];
 
698
                        boolean found = false;
 
699
                        for(int j = 0; j < a2.length; j++){
 
700
                                if(o1.equals(a2[j])){
 
701
                                        found = true;
 
702
                                        break;
 
703
                                }
 
704
                        }
 
705
                        
 
706
                        if(!found){
 
707
                                fail("a2 array does not contain the \"" + o1 + "\" element");
 
708
                        }
 
709
                }
 
710
        }
 
711
        
 
712
        static public IProject createProject(String name, String projTypeId) throws CoreException{
 
713
                IProject project = createProject(name);
 
714
                
 
715
                CoreModel coreModel = CoreModel.getDefault();
 
716
                ICProjectDescription des = coreModel.getProjectDescription(project);
 
717
                assertNull("detDescription1 returned not null!", des);
 
718
                
 
719
                des = coreModel.createProjectDescription(project, true);
 
720
                assertNotNull("createDescription returned null!", des);
 
721
                
 
722
                assertNull("detDescription2 returned not null!", coreModel.getProjectDescription(project));
 
723
                
 
724
                assertFalse("new des should be not valid", des.isValid());
 
725
                
 
726
                assertEquals(0, des.getConfigurations().length);
 
727
                
 
728
                ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
 
729
                IProjectType type = ManagedBuildManager.getProjectType(projTypeId);
 
730
                assertNotNull("project type not found", type);
 
731
 
 
732
                ManagedProject mProj = new ManagedProject(project, type);
 
733
                info.setManagedProject(mProj);
 
734
                
 
735
                IConfiguration cfgs[] = type.getConfigurations();
 
736
                
 
737
 
 
738
                for(int i = 0; i < cfgs.length; i++){
 
739
                        String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
 
740
                        Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true);
 
741
                        CConfigurationData data = config.getConfigurationData();
 
742
                        assertNotNull("data is null for created configuration", data);
 
743
                        des.createConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider", data);
 
744
                }
 
745
 
 
746
                coreModel.setProjectDescription(project, des);
 
747
 
 
748
                return project;
 
749
        }
 
750
        
 
751
        static public IProject createProject(String name) throws CoreException{
 
752
                return createProject(name, (IPath)null);
 
753
        }
 
754
        
 
755
        static public IProject createProject(
 
756
                        final String name, 
 
757
                        final IPath location) throws CoreException{
 
758
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
 
759
                IWorkspaceRoot root = workspace.getRoot();
 
760
                final IProject newProjectHandle = root.getProject(name);
 
761
                IProject project = null;
 
762
                
 
763
                if (!newProjectHandle.exists()) {
 
764
                        IWorkspaceDescription workspaceDesc = workspace.getDescription();
 
765
                        workspaceDesc.setAutoBuilding(false);
 
766
                        workspace.setDescription(workspaceDesc);
 
767
                        IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
 
768
                        if(location != null)
 
769
                                description.setLocation(location);
 
770
                        //description.setLocation(root.getLocation());
 
771
                        project = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, new NullProgressMonitor());
 
772
                } else {
 
773
                        IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
 
774
                                public void run(IProgressMonitor monitor) throws CoreException {
 
775
                                        newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, monitor);
 
776
                                }
 
777
                        };
 
778
                        NullProgressMonitor monitor = new NullProgressMonitor();
 
779
                        workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
 
780
                        project = newProjectHandle;
 
781
                }
 
782
        
 
783
                // Open the project if we have to
 
784
                if (!project.isOpen()) {
 
785
                        project.open(new NullProgressMonitor());
 
786
                }
 
787
                                
 
788
                return project; 
 
789
        }
 
790
}