Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9bd87b4b988c6fe4fb4bdcdbf260ed0482a73cab (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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
/*******************************************************************************
 * Copyright (c) 2003, 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 - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.ITargetPlatform;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
import org.eclipse.cdt.managedbuilder.internal.core.Option;
import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;

/*
 *  These tests exercise CDT 2.0 manifest file functionality
 */
public class ManagedBuildCoreTests20 extends TestCase {
	private static final boolean boolVal = true;
	private static final String testConfigId = "test.config.override";
	private static final String testConfigName = "Tester";
	private static final String enumVal = "Another Enum";
	private static final String[] listVal = { "_DEBUG", "/usr/include", "libglade.a" };
	private static final String newExt = "wen";
	private static final String projectName = "ManagedBuildTest";
	private static final String projectName2 = "ManagedBuildTest2";
	private static final String projectRename = "ManagedBuildRedux";
	private static final String rootExt = "toor";
	private static final String stringVal = "-c -Wall";
	private static final String anotherStringVal = "thevalue";
	private static final String subExt = "bus";

	public ManagedBuildCoreTests20(String name) {
		super(name);
	}

	public static Test suite() {
		TestSuite suite = new TestSuite(ManagedBuildCoreTests20.class.getName());

		// Note that some of the tests are dependent on others so run the suite as a whole
		suite.addTest(new ManagedBuildCoreTests20("testExtensions"));
		suite.addTest(new ManagedBuildCoreTests20("testProjectCreation"));
		suite.addTest(new ManagedBuildCoreTests20("testConfigurations"));
		suite.addTest(new ManagedBuildCoreTests20("testConfigurationReset"));
		suite.addTest(new ManagedBuildCoreTests20("testConfigBuildArtifact"));
		suite.addTest(new ManagedBuildCoreTests20("testMakeCommandManipulation"));
		suite.addTest(new ManagedBuildCoreTests20("testScannerInfoInterface"));
		suite.addTest(new ManagedBuildCoreTests20("testProjectRename"));
		suite.addTest(new ManagedBuildCoreTests20("testErrorParsers"));
		suite.addTest(new ManagedBuildCoreTests20("cleanup"));

		return suite;
	}

	/**
	 * Convert path to OS specific representation
	 */
	private String toOSLocation(String path) {
		java.io.File file = new java.io.File(path);
		try {
			path = file.getCanonicalPath();
		} catch (IOException e) {
		}

		return path;
	}

	/**
	 * Convert path to OS specific representation
	 */
	private String toOSString(String path) {
		return new Path(path).toOSString();
	}

	/**
	 * Navigates through the build info as defined in the extensions
	 * defined in this plugin
	 */
	public void testExtensions() throws Exception {
		IProjectType testRoot = null;
		IProjectType testSub = null;
		IProjectType testSubSub = null;
		IProjectType testForwardChild = null;
		IProjectType testForwardParent = null;
		IProjectType testForwardGrandchild = null;
		int numTypes = 0;

		// Note secret null parameter which means just extensions
		IProjectType[] projTypes = ManagedBuildManager.getDefinedProjectTypes();

		for (int i = 0; i < projTypes.length; ++i) {
			IProjectType type = projTypes[i];

			if (type.getName().equals("Test Root")) {
				testRoot = type;
				checkRootProjectType(testRoot);
			} else if (type.getName().equals("Test Sub")) {
				testSub = type;
				checkSubProjectType(testSub);
			} else if (type.getName().equals("Test Sub Sub")) {
				testSubSub = type;
				checkSubSubProjectType(testSubSub);
			} else if (type.getName().equals("Forward Child")) {
				testForwardChild = type;
			} else if (type.getName().equals("Forward Parent")) {
				testForwardParent = type;
			} else if (type.getName().equals("Forward Grandchild")) {
				testForwardGrandchild = type;
			} else if (type.getId().startsWith("test.provider.Test_")) {
				numTypes++;
				checkProviderProjectType(type);
			}
		}
		// check that the forward references are properly resolved.
		assertNotNull(testForwardChild);
		assertNotNull(testForwardParent);
		assertNotNull(testForwardGrandchild);
		checkForwardProjectTypes(testForwardParent, testForwardChild, testForwardGrandchild);

		// check that the proper number of projectTypes were dynamically provided
		assertEquals(3, numTypes);

		// All these project types are defines in the plugin files, so none
		// of them should be null at this point
		assertNotNull(testRoot);
		assertNotNull(testSub);
		assertNotNull(testSubSub);
	}

	/**
	 * This test exercises the interface the <code>IConfiguration</code> exposes to manipulate
	 * its make command.
	 */
	public void testMakeCommandManipulation() {
		String oldMakeCmd = "make";
		String newMakeCmd = "Ant";

		// Open the test project
		IProject project = null;
		try {
			project = createProject(projectName);
			IProjectDescription description = project.getDescription();
			// Make sure it has a managed nature
			if (description != null) {
				assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
			}
		} catch (CoreException e) {
			fail("Failed to open project in 'testMakeCommandManipulation': " + e.getLocalizedMessage());
		}
		assertNotNull(project);

		// Now get the default configuration
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
		assertNotNull(info);
		IManagedProject managedProj = info.getManagedProject();
		assertNotNull(managedProj);
		IConfiguration defaultConfig = info.getDefaultConfiguration();
		assertNotNull(defaultConfig);

		// Does it have a default build command
		assertFalse(defaultConfig.hasOverriddenBuildCommand());
		assertEquals(oldMakeCmd, defaultConfig.getBuildCommand());

		// Change it
		defaultConfig.setBuildCommand(newMakeCmd);
		assertEquals(newMakeCmd, defaultConfig.getBuildCommand());
		assertTrue(defaultConfig.hasOverriddenBuildCommand());

		// Reset it
		defaultConfig.setBuildCommand(null);
		assertFalse(defaultConfig.hasOverriddenBuildCommand());
		assertEquals(oldMakeCmd, defaultConfig.getBuildCommand());

		ManagedBuildManager.saveBuildInfo(project, false);
	}

	/**
	 * The purpose of this test is to exercise the build path info interface.
	 * To get to that point, a new project/config has to be created in the test
	 * project and the default configuration changed.
	 */
	public void testScannerInfoInterface() {
		// Open the test project
		IProject project = null;
		try {
			project = createProject(projectName);
			IProjectDescription description = project.getDescription();
			// Make sure it has a managed nature
			if (description != null) {
				assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
			}
		} catch (CoreException e) {
			fail("Failed to open project in 'testScannerInfoInterface': " + e.getLocalizedMessage());
		}

		//These are the expected path settings
		IPath buildCWD = project.getLocation().append("Sub Config");
		final String[] expectedPaths;
		if (new Path("C:\\home\\tester/include").isAbsolute()) {
			// Windows
			expectedPaths = new String[] { toOSLocation("/usr/include"), toOSLocation("/opt/gnome/include"),
					toOSLocation("C:\\home\\tester/include"),
					// relative paths from MBS will make 3 entries
					project.getLocation().append("includes").toOSString(), buildCWD.append("includes").toOSString(),
					toOSString("includes"), "/usr/gnu/include", // Not converted to OS string due to being flagged as ICSettingEntry.RESOLVED
			};
		} else {
			// Unix
			expectedPaths = new String[] { toOSLocation("/usr/include"), toOSLocation("/opt/gnome/include"),
					// on unix "C:\\home\\tester/include" is relative path
					// looks like nonsense but it this way due to MBS converting entry to keep "Sub Config/C:\\home\\tester/include" in its storage
					project.getLocation().append("Sub Config/C:\\home\\tester/include").toOSString(),
					buildCWD.append("Sub Config/C:\\home\\tester/include").toOSString(),
					toOSString("Sub Config/C:\\home\\tester/include"),
					// relative paths from MBS will make 3 entries
					project.getLocation().append("includes").toOSString(), buildCWD.append("includes").toOSString(),
					toOSString("includes"), "/usr/gnu/include", // Not converted to OS string due to being flagged as ICSettingEntry.RESOLVED
			};
		}

		// Create a new managed project based on the sub project type
		IProjectType projType = ManagedBuildManager.getExtensionProjectType("test.sub");
		assertNotNull(projType);

		// Create the managed-project for our project
		IManagedProject newProject = null;
		try {
			newProject = ManagedBuildManager.createManagedProject(project, projType);
		} catch (BuildException e) {
			fail("Failed creating new project: " + e.getLocalizedMessage());
		}
		assertNotNull(newProject);
		ManagedBuildManager.setNewProjectVersion(project);

		// Copy over the configs
		IConfiguration[] baseConfigs = projType.getConfigurations();
		for (int i = 0; i < baseConfigs.length; ++i) {
			newProject.createConfiguration(baseConfigs[i], baseConfigs[i].getId() + "." + i);
		}

		// Change the default configuration to the sub config
		IConfiguration[] configs = newProject.getConfigurations();
		assertEquals(4, configs.length);
		IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
		buildInfo.setDefaultConfiguration(newProject.getConfiguration(configs[0].getId()));
		buildInfo.setValid(true);
		// Save, close, reopen
		ManagedBuildManager.saveBuildInfo(project, true);
		ManagedBuildManager.removeBuildInfo(project);
		try {
			ResourceHelper.joinIndexerBeforeCleanup(getName());
			project.close(null);
		} catch (CoreException e) {
			fail("Failed on project close: " + e.getLocalizedMessage());
		}
		try {
			project.open(null);
		} catch (CoreException e) {
			fail("Failed on project open: " + e.getLocalizedMessage());
		}
		buildInfo = ManagedBuildManager.getBuildInfo(project);

		// Use the plugin mechanism to discover the supplier of the path information
		IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
				.getExtensionPoint(CCorePlugin.PLUGIN_ID + ".ScannerInfoProvider");
		if (extensionPoint == null) {
			fail("Failed to retrieve the extension point ScannerInfoProvider.");
		}

		// Find the first IScannerInfoProvider that supplies build info for the project
		IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
		assertNotNull(provider);

		// Now subscribe (note that the method will be called after a change
		provider.subscribe(project, new IScannerInfoChangeListener() {
			@Override
			public void changeNotification(IResource project, IScannerInfo info) {
				// Test the symbols: expect "BUILTIN" from the manifest, and "DEBUG" and "GNOME=ME"
				// from the overidden settings
				Map<String, String> definedSymbols = info.getDefinedSymbols();
				assertTrue(definedSymbols.containsKey("BUILTIN"));
				assertTrue(definedSymbols.containsKey("DEBUG"));
				assertTrue(definedSymbols.containsKey("GNOME"));
				assertTrue(definedSymbols.containsValue("ME"));
				assertEquals(definedSymbols.get("BUILTIN"), "");
				assertEquals(definedSymbols.get("DEBUG"), "");
				assertEquals(definedSymbols.get("GNOME"), "ME");
				// Test the includes path
				String[] actualPaths = info.getIncludePaths();
				BuildSystemTestHelper.checkDiff(expectedPaths, actualPaths);
			}
		});

		// Check the build information before we change it
		IScannerInfo currentSettings = provider.getScannerInformation(project);

		Map<String, String> currentSymbols = currentSettings.getDefinedSymbols();
		// It should simply contain the built-in
		assertTrue(currentSymbols.containsKey("BUILTIN"));
		assertEquals(currentSymbols.get("BUILTIN"), "");

		String[] currentPaths = currentSettings.getIncludePaths();
		BuildSystemTestHelper.checkDiff(expectedPaths, currentPaths);

		// Add some defined symbols programmatically
		String[] expectedSymbols = { "DEBUG", "GNOME = ME " };
		IConfiguration defaultConfig = buildInfo.getDefaultConfiguration();
		ITool[] tools = defaultConfig.getTools();
		ITool subTool = null;
		for (int i = 0; i < tools.length; i++) {
			ITool tool = tools[i];
			if ("tool.sub".equalsIgnoreCase(tool.getSuperClass().getId())) {
				subTool = tool;
				break;
			}
		}
		assertNotNull(subTool);
		IOption symbolOpt = null;
		IOption[] opts = subTool.getOptions();
		for (int i = 0; i < opts.length; i++) {
			IOption option = opts[i];
			try {
				if (option.getValueType() == IOption.PREPROCESSOR_SYMBOLS) {
					symbolOpt = option;
					break;
				}
			} catch (BuildException e) {
				fail("Failed getting option value-type: " + e.getLocalizedMessage());
			}
		}
		assertNotNull(symbolOpt);
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
		assertFalse(info.isDirty());
		ManagedBuildManager.setOption(defaultConfig, subTool, symbolOpt, expectedSymbols);
		assertTrue(info.isDirty());
		info.setDirty(false);
		assertFalse(info.isDirty());
	}

	/**
	 * Create a new configuration based on one defined in the plugin file.
	 * Overrides all of the configuration settings. Saves, closes, and reopens
	 * the project. Then calls a method to check the overridden options.
	 *
	 * Tests creating a new configuration.
	 * Tests setting options.
	 * Tests persisting overridden options between project sessions.
	 *
	 */
	public void testConfigurations() throws CoreException, BuildException {
		final String rootName = "Root Config";
		final String overrideName = "Root Override Config";
		final String completeOverrideName = "Complete Override Config";
		final String toolCmd = "doIt";
		final String newCmd = "never";

		// Open the test project
		IProject project = createProject(projectName);
		IProjectDescription description = project.getDescription();
		// Make sure it has a managed nature
		if (description != null) {
			assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
		}

		// Make sure there is a ManagedProject with 3 configs
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
		IManagedProject managedProj = info.getManagedProject();
		IConfiguration[] definedConfigs = managedProj.getConfigurations();
		assertEquals(3, definedConfigs.length);
		IConfiguration baseConfig = definedConfigs[0];
		assertEquals(definedConfigs[0].getName(), rootName);
		assertEquals(definedConfigs[1].getName(), overrideName);
		assertEquals(definedConfigs[2].getName(), completeOverrideName);

		// Create a new configuration and test the rename function
		IConfiguration newConfig = managedProj.createConfigurationClone(baseConfig, testConfigId);
		assertEquals(4, managedProj.getConfigurations().length);
		newConfig.setName(testConfigName);
		assertEquals(newConfig.getId(), testConfigId);
		assertEquals(newConfig.getName(), testConfigName);

		// There is only one tool
		ITool[] definedTools = newConfig.getTools();
		assertEquals(1, definedTools.length);
		ITool rootTool = definedTools[0];

		// Test changing its command
		assertEquals(rootTool.getToolCommand(), toolCmd);
		newConfig.setToolCommand(rootTool, newCmd);
		assertEquals(rootTool.getToolCommand(), newCmd);

		// Override options in the new configuration
		IOptionCategory topCategory = rootTool.getTopOptionCategory();
		assertEquals("Root Tool", topCategory.getName());
		Object[][] options = topCategory.getOptions(newConfig);
		int i;
		for (i = 0; i < options.length; i++)
			if (options[i][0] == null)
				break;
		assertEquals(2, i);
		ITool tool = (ITool) options[0][0];
		IOption option = (IOption) options[0][1];
		ManagedBuildManager.setOption(newConfig, tool, option, listVal);
		option = (IOption) options[1][1];
		ManagedBuildManager.setOption(newConfig, tool, option, boolVal);

		IOptionCategory[] categories = topCategory.getChildCategories();
		assertEquals(1, categories.length);
		options = categories[0].getOptions(newConfig);
		for (i = 0; i < options.length; i++)
			if (options[i][0] == null)
				break;
		assertEquals(4, i);
		tool = (ITool) options[0][0];
		option = (IOption) options[0][1];
		ManagedBuildManager.setOption(newConfig, tool, option, stringVal);
		option = (IOption) options[1][1];
		ManagedBuildManager.setOption(newConfig, tool, option, anotherStringVal);
		option = (IOption) options[2][1];
		ManagedBuildManager.setOption(newConfig, tool, option, enumVal);
		option = (IOption) options[3][1];
		ManagedBuildManager.setOption(newConfig, tool, option, "False");

		// Save, close, reopen and test again
		ManagedBuildManager.saveBuildInfo(project, false);
		ManagedBuildManager.removeBuildInfo(project);
		ResourceHelper.joinIndexerBeforeCleanup(getName());
		project.close(null);
		project.open(null);

		// Test the values in the new configuration
		checkOptionReferences(project);

		// Now delete the new configuration and test the managed project
		info = ManagedBuildManager.getBuildInfo(project);
		managedProj = info.getManagedProject();
		definedConfigs = managedProj.getConfigurations();
		assertEquals(4, definedConfigs.length);
		managedProj.removeConfiguration(testConfigId);
		definedConfigs = managedProj.getConfigurations();
		assertEquals(3, definedConfigs.length);
		assertEquals(definedConfigs[0].getName(), rootName);
		assertEquals(definedConfigs[1].getName(), overrideName);
		ManagedBuildManager.saveBuildInfo(project, false);
	}

	public void testConfigurationReset() {
		// Open the test project
		IProject project = null;
		try {
			project = createProject(projectName);
			IProjectDescription description = project.getDescription();
			// Make sure it has a managed nature
			if (description != null) {
				assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
			}
		} catch (CoreException e) {
			fail("Failed to open project: " + e.getLocalizedMessage());
		}

		// Get the default configuration
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
		assertNotNull(info);
		IManagedProject managedProj = info.getManagedProject();
		assertNotNull(managedProj);
		IConfiguration defaultConfig = info.getDefaultConfiguration();
		assertNotNull(defaultConfig);

		// See if it still contains the overridden values (see testProjectCreation())
		try {
			checkRootManagedProject(managedProj, "z");
		} catch (BuildException e1) {
			fail("Overridden root managed project check failed: " + e1.getLocalizedMessage());
		}

		// Reset the config and retest
		ManagedBuildManager.resetConfiguration(project, defaultConfig);
		ManagedBuildManager.saveBuildInfo(project, false);
		try {
			checkRootManagedProject(managedProj, "x");
		} catch (BuildException e2) {
			fail("Reset root managed project check failed: " + e2.getLocalizedMessage());
		}
	}

	/**
	 * @throws BuildException
	 */
	public void testProjectCreation() throws BuildException {
		// Create new project
		IProject project = null;
		try {
			project = createProject(projectName);
			// Now associate the builder with the project
			ManagedBuildTestHelper.addManagedBuildNature(project);
			IProjectDescription description = project.getDescription();
			// Make sure it has a managed nature
			if (description != null) {
				assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
			}

		} catch (CoreException e) {
			fail("Test failed on project creation: " + e.getLocalizedMessage());
		}

		// Find the base project type definition
		IProjectType projType = ManagedBuildManager.getExtensionProjectType("test.root");
		assertNotNull(projType);

		// Create the managed-project for our project that builds a dummy executable
		IManagedProject newProject = ManagedBuildManager.createManagedProject(project, projType);
		assertEquals(newProject.getName(), projType.getName());
		assertFalse(newProject.equals(projType));
		ManagedBuildManager.setNewProjectVersion(project);

		// Copy over the configs
		IConfiguration defaultConfig = null;
		IConfiguration[] configs = projType.getConfigurations();
		for (int i = 0; i < configs.length; ++i) {
			// Make the first configuration the default
			if (i == 0) {
				defaultConfig = newProject.createConfiguration(configs[i], projType.getId() + "." + i);
			} else {
				newProject.createConfiguration(configs[i], projType.getId() + "." + i);
			}
		}
		ManagedBuildManager.setDefaultConfiguration(project, defaultConfig);

		String buildArtifactName = projectName;
		defaultConfig.setArtifactName(buildArtifactName);
		defaultConfig.setArtifactExtension(newExt);

		ManagedBuildManager.getBuildInfo(project).setValid(true);

		// Initialize the path entry container
		IStatus initResult = ManagedBuildManager.initBuildInfoContainer(project);
		if (initResult.getCode() != IStatus.OK) {
			fail("Initializing build information failed for: " + project.getName() + " because: "
					+ initResult.getMessage());
		}

		// Now test the results out
		checkRootManagedProject(newProject, "x");

		// Override the "String Option in Category" option value
		configs = newProject.getConfigurations();
		ITool[] tools = configs[0].getTools();
		IOptionCategory topCategory = tools[0].getTopOptionCategory();
		IOptionCategory[] categories = topCategory.getChildCategories();
		Object[][] options = categories[0].getOptions(configs[0]);
		ITool tool = (ITool) options[0][0];
		IOption option = (IOption) options[0][1];
		configs[0].setOption(tool, option, "z");
		options = categories[0].getOptions((IConfiguration) null);
		tool = (ITool) options[0][0];
		option = (IOption) options[0][1];
		assertEquals("x", option.getStringValue());
		options = categories[0].getOptions(configs[0]);
		tool = (ITool) options[0][0];
		option = (IOption) options[0][1];
		assertEquals("z", option.getStringValue());

		// Save, close, reopen and test again
		ManagedBuildManager.saveBuildInfo(project, true);
		ManagedBuildManager.removeBuildInfo(project);
		try {
			ResourceHelper.joinIndexerBeforeCleanup(getName());
			project.close(null);
		} catch (CoreException e) {
			fail("Failed on project close: " + e.getLocalizedMessage());
		}
		try {
			project.open(null);
		} catch (CoreException e) {
			fail("Failed on project open: " + e.getLocalizedMessage());
		}

		// Test that the default config was remembered
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
		assertEquals(defaultConfig.getId(), info.getDefaultConfiguration().getId());

		// Check the rest of the default information
		checkRootManagedProject(newProject, "z");

		// Now test the information the makefile builder needs
		checkBuildTestSettings(info);
		ManagedBuildManager.removeBuildInfo(project);
	}

	/**
	 * Tests that bugzilla 44159 has been addressed. After a project was renamed, the
	 * build information mistakenly referred to the old project as its owner. This
	 * caused a number of searches on the information to fail. In this bug, it was the
	 * list of tools that could not be determined. In other cases, the information
	 * retrieval caused NPEs because the old owner no longer existed.
	 */
	public void testProjectRename() {
		// Open the test project
		IProject project = null;
		try {
			project = createProject(projectName);
			IProjectDescription description = project.getDescription();
			// Make sure it has a managed nature
			if (description != null) {
				assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
			}
		} catch (CoreException e) {
			fail("Failed to open project: " + e.getLocalizedMessage());
		}

		// Rename the project
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
		IResource newResource = workspaceRoot.findMember(projectRename);
		if (newResource != null) {
			try {
				newResource.delete(IResource.KEEP_HISTORY, new NullProgressMonitor());
			} catch (CoreException e) {
				fail("Failed to delete old project " + projectRename + ": " + e.getLocalizedMessage());
			}
		}
		IProjectDescription description = null;
		try {
			description = project.getDescription();
		} catch (CoreException e) {
			fail("Failed to find project descriptor for " + projectName + ": " + e.getLocalizedMessage());
		}
		description.setName(projectRename);
		try {
			project.move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor());
		} catch (CoreException e) {
			fail("Failed to rename project: " + e.getLocalizedMessage());
		}
		try {
			project = createProject(projectRename);
			description = project.getDescription();
			// Make sure it has a managed nature
			if (description != null) {
				assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
			}
		} catch (CoreException e) {
			fail("Failed to open renamed project: " + e.getLocalizedMessage());
		}

		// By now the project should have 3 configs
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
		IManagedProject managedProj = info.getManagedProject();
		IConfiguration[] definedConfigs = managedProj.getConfigurations();
		assertEquals(4, definedConfigs.length);
		IConfiguration baseConfig = definedConfigs[1];

		// There is only one tool
		ITool[] definedTools = baseConfig.getTools();
		assertEquals(1, definedTools.length);
		ITool rootTool = definedTools[0];

		// Get the options (2) in top category and (4) in its child
		IOptionCategory topCategory = rootTool.getTopOptionCategory();
		assertEquals("Root Tool", topCategory.getName());
		Object[][] options = topCategory.getOptions(baseConfig);
		int i;
		for (i = 0; i < options.length; i++)
			if (options[i][0] == null)
				break;
		assertEquals(2, i);
		IOptionCategory[] categories = topCategory.getChildCategories();
		assertEquals(1, categories.length);
		options = categories[0].getOptions(baseConfig);
		for (i = 0; i < options.length; i++)
			if (options[i][0] == null)
				break;
		assertEquals(4, i);

		// Set the name back
		newResource = workspaceRoot.findMember(projectName);
		if (newResource != null) {
			try {
				newResource.delete(IResource.KEEP_HISTORY, new NullProgressMonitor());
			} catch (CoreException e) {
				fail("Failed to delete old project " + projectName + ": " + e.getLocalizedMessage());
			}
		}
		try {
			description = project.getDescription();
		} catch (CoreException e) {
			fail("Failed to find project descriptor for " + projectRename + ": " + e.getLocalizedMessage());
		}
		description.setName(projectName);
		try {
			project.move(description, IResource.FORCE | IResource.SHALLOW, new NullProgressMonitor());
		} catch (CoreException e) {
			fail("Failed to re-rename project: " + e.getLocalizedMessage());
		}
		try {
			project = createProject(projectName);
			description = project.getDescription();
			// Make sure it has a managed nature
			if (description != null) {
				assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
			}
		} catch (CoreException e) {
			fail("Failed to open re-renamed project: " + e.getLocalizedMessage());
		}

		// Do it all again
		info = ManagedBuildManager.getBuildInfo(project);
		managedProj = info.getManagedProject();
		definedConfigs = managedProj.getConfigurations();
		assertEquals(4, definedConfigs.length);
		baseConfig = definedConfigs[1];
		definedTools = baseConfig.getTools();
		assertEquals(1, definedTools.length);
		rootTool = definedTools[0];
		topCategory = rootTool.getTopOptionCategory();
		assertEquals("Root Tool", topCategory.getName());
		options = topCategory.getOptions(baseConfig);
		for (i = 0; i < options.length; i++)
			if (options[i][0] == null)
				break;
		assertEquals(2, i);
		categories = topCategory.getChildCategories();
		assertEquals(1, categories.length);
		options = categories[0].getOptions(baseConfig);
		for (i = 0; i < options.length; i++)
			if (options[i][0] == null)
				break;
		assertEquals(4, i);
	}

	/**
	 * Tests the tool settings through the interface the makefile generator
	 * uses.
	 *
	 * @param project
	 */
	private void checkBuildTestSettings(IManagedBuildInfo info) {
		String ext1 = "foo";
		String ext2 = "bar";
		String badExt = "cpp";
		String expectedOutput = "toor";
		String expectedCmd = "doIt";

		assertNotNull(info);
		assertEquals(info.getBuildArtifactName(), projectName);

		// There should be a default configuration defined for the project
		IManagedProject managedProj = info.getManagedProject();
		assertNotNull(managedProj);
		IConfiguration buildConfig = info.getDefaultConfiguration();
		assertNotNull(buildConfig);

		// Check that tool handles resources with extensions foo and bar by building a baz
		assertEquals(info.getOutputExtension(ext1), expectedOutput);
		assertEquals(info.getOutputExtension(ext2), expectedOutput);

		// Check that it ignores others based on filename extensions
		assertNull(info.getOutputExtension(badExt));

		// Now see what the tool command line invocation is for foo and bar
		assertEquals(info.getToolForSource(ext1), expectedCmd);
		assertEquals(info.getToolForSource(ext2), expectedCmd);
		// Make sure that there is no tool to build files of type foo and bar
		assertNull(info.getToolForConfiguration(ext1));
		assertNull(info.getToolForConfiguration(ext2));

		// There is no tool that builds toor
		assertNull(info.getToolForSource(expectedOutput));
		// but there is one that produces it
		assertEquals(info.getToolForConfiguration(expectedOutput), expectedCmd);

		// Now check the build flags
		assertEquals(info.getFlagsForSource(ext1), "-La -Lb z -e1 -nob");
		assertEquals(info.getFlagsForSource(ext1), info.getFlagsForSource(ext2));

	}

	/**
	 * Tests that overridden options are properly read into build model.
	 * Test that option values that are not overridden remain the same.
	 *
	 * @param project The project to get build model information for.
	 * @throws BuildException
	 */
	private void checkOptionReferences(IProject project) throws BuildException {
		// Get the configs
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
		IManagedProject managedProj = info.getManagedProject();
		IConfiguration[] definedConfigs = managedProj.getConfigurations();
		assertEquals(4, definedConfigs.length);
		IConfiguration newConfig = managedProj.getConfiguration(testConfigId);
		assertNotNull(newConfig);

		// Now get the tool options and make sure the values are correct
		ITool[] definedTools = newConfig.getTools();
		assertEquals(1, definedTools.length);
		ITool rootTool = definedTools[0];

		// Check that the options in the new config contain overridden values
		IOption[] rootOptions = rootTool.getOptions();
		assertEquals(6, rootOptions.length);
		// First is the new list
		assertEquals("List Option in Top", rootOptions[0].getName());
		assertEquals(IOption.STRING_LIST, rootOptions[0].getValueType());
		String[] list = rootOptions[0].getStringListValue();
		assertEquals(3, list.length);
		assertTrue(Arrays.equals(listVal, list));
		assertEquals(rootOptions[0].getCommand(), "-L");
		// Next option is a boolean in top
		assertEquals("Boolean Option in Top", rootOptions[1].getName());
		assertEquals(IOption.BOOLEAN, rootOptions[1].getValueType());
		assertEquals(boolVal, rootOptions[1].getBooleanValue());
		assertEquals("-b", rootOptions[1].getCommand());
		// Next option is a string in category
		assertEquals("String Option in Category", rootOptions[2].getName());
		assertEquals(IOption.STRING, rootOptions[2].getValueType());
		assertEquals(stringVal, rootOptions[2].getStringValue());
		// Next option is a another string in category
		assertEquals("Another String Option in Category", rootOptions[3].getName());
		assertEquals(IOption.STRING, rootOptions[3].getValueType());
		assertEquals(anotherStringVal, rootOptions[3].getStringValue());
		assertEquals("-str", rootOptions[3].getCommand());
		// Next option is an enumerated in category
		assertEquals("Enumerated Option in Category", rootOptions[4].getName());
		assertEquals(IOption.ENUMERATED, rootOptions[4].getValueType());
		String selEnum = rootOptions[4].getSelectedEnum();
		assertEquals(enumVal, selEnum);
		String[] enums = rootOptions[4].getApplicableValues();
		assertEquals(2, enums.length);
		assertEquals("Default Enum", enums[0]);
		assertEquals("Another Enum", enums[1]);
		assertEquals("-e1", rootOptions[4].getEnumCommand(enums[0]));
		assertEquals("-e2", rootOptions[4].getEnumCommand(enums[1]));
		assertEquals("-e2", rootOptions[4].getEnumCommand(selEnum));
		// Final option is a boolean in Category
		assertEquals("Boolean Option in Category", rootOptions[5].getName());
		assertEquals(IOption.BOOLEAN, rootOptions[5].getValueType());
		assertEquals(false, rootOptions[5].getBooleanValue());
		assertEquals("-nob", rootOptions[5].getCommandFalse());
	}

	/*
	 * Do a full sanity check on the root project type.
	 */
	private void checkRootProjectType(IProjectType type) throws BuildException {
		// Project stuff
		String expectedCleanCmd = "del /myworld";
		String expectedParserId = "org.eclipse.cdt.core.PE";
		String[] expectedOSList = { "win32" };
		String[] expectedArchList = { "all" };
		assertTrue(type.isTestProjectType());
		IConfiguration[] configs = type.getConfigurations();
		if (configs[0].getArtifactName().equals("ManagedBuildTest")) {
			assertEquals(configs[0].getArtifactExtension(), newExt);
		} else {
			assertEquals(configs[0].getArtifactExtension(), rootExt);
		}
		assertEquals(expectedCleanCmd, configs[0].getCleanCommand());
		assertEquals("make", configs[0].getBuildCommand());
		IToolChain toolChain = configs[0].getToolChain();
		ITargetPlatform targetPlatform = toolChain.getTargetPlatform();
		String[] binaryParsers = targetPlatform.getBinaryParserList();
		assertEquals(binaryParsers.length, 1);
		assertEquals(binaryParsers[0], expectedParserId);
		assertTrue(Arrays.equals(expectedOSList, toolChain.getOSList()));
		assertTrue(Arrays.equals(expectedArchList, toolChain.getArchList()));
		// This configuration defines no errors parsers.
		assertNull(configs[0].getErrorParserIds());
		assertTrue(Arrays.equals(configs[0].getErrorParserList(), CCorePlugin.getDefault().getAllErrorParsersIDs()));

		// Tools
		ITool[] tools = toolChain.getTools();
		// Root Tool
		ITool rootTool = tools[0];
		assertEquals("Root Tool", rootTool.getName());
		// 6 Options are defined in the root tool
		IOption[] options = rootTool.getOptions();
		assertEquals(6, options.length);
		// First option is a 3-element list with 1 built-in
		assertEquals("List Option in Top", options[0].getName());
		assertEquals(IOption.STRING_LIST, options[0].getValueType());
		String[] valueList = options[0].getStringListValue();
		assertEquals(2, valueList.length);
		assertEquals("a", valueList[0]);
		assertEquals("b", valueList[1]);
		String[] builtInList = options[0].getBuiltIns();
		assertEquals(1, builtInList.length);
		assertEquals("c", builtInList[0]);
		assertEquals(options[0].getCommand(), "-L");
		// Next option is a boolean in top
		assertEquals("Boolean Option in Top", options[1].getName());
		assertEquals(IOption.BOOLEAN, options[1].getValueType());
		assertEquals(false, options[1].getBooleanValue());
		assertEquals("-b", options[1].getCommand());
		// Next option is a string category
		assertEquals("String Option in Category", options[2].getName());
		assertEquals(IOption.STRING, options[2].getValueType());
		assertEquals("x", options[2].getStringValue());
		// Next option is another string category
		assertEquals("Another String Option in Category", options[3].getName());
		assertEquals(IOption.STRING, options[3].getValueType());
		assertEquals("", options[3].getStringValue());
		assertEquals("-str", options[3].getCommand());
		// Next option is an enumerated
		assertEquals("Enumerated Option in Category", options[4].getName());
		assertEquals(IOption.ENUMERATED, options[4].getValueType());
		// Post-2.0 enums store the ID, not the string value
		assertEquals("default.enum.option", options[4].getSelectedEnum());
		assertEquals("-e1", options[4].getEnumCommand("default.enum.option"));
		// Need this methof to populate the UI selection widget
		valueList = options[4].getApplicableValues();
		assertEquals(2, valueList.length);
		assertEquals("Default Enum", valueList[0]);
		assertEquals("Another Enum", valueList[1]);
		// Test compatability with 1.2 scheme of getting the command from the name
		assertEquals("-e1", options[4].getEnumCommand(valueList[0]));
		assertEquals("-e2", options[4].getEnumCommand(valueList[1]));
		// Final option is another boolean
		assertEquals("Boolean Option in Category", options[5].getName());
		assertEquals(IOption.BOOLEAN, options[5].getValueType());
		assertEquals(false, options[5].getBooleanValue());
		assertEquals("", options[5].getCommand());
		assertEquals("-nob", options[5].getCommandFalse());

		// Option Categories
		IOptionCategory topCategory = rootTool.getTopOptionCategory();
		assertEquals("Root Tool", topCategory.getName());
		Object[][] catoptions = topCategory.getOptions(configs[0]);
		int i;
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(2, i);
		assertEquals("List Option in Top", ((IOption) catoptions[0][1]).getName());
		assertEquals("Boolean Option in Top", ((IOption) catoptions[1][1]).getName());
		IOptionCategory[] categories = topCategory.getChildCategories();
		assertEquals(1, categories.length);
		assertEquals("Category", categories[0].getName());
		catoptions = categories[0].getOptions(configs[0]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(4, i);
		assertEquals("String Option in Category", ((IOption) catoptions[0][1]).getName());
		assertEquals("Another String Option in Category", ((IOption) catoptions[1][1]).getName());
		assertEquals("Enumerated Option in Category", ((IOption) catoptions[2][1]).getName());
		assertEquals("Boolean Option in Category", ((IOption) catoptions[3][1]).getName());

		// There should be 3 defined configs
		configs = type.getConfigurations();
		assertEquals(3, configs.length);

		// Root Config
		IConfiguration rootConfig = configs[0];
		assertEquals("Root Config", rootConfig.getName());

		// Tool elements
		tools = rootConfig.getTools();
		assertEquals(1, tools.length);
		assertEquals("Root Tool", tools[0].getName());
		assertEquals("-r", tools[0].getOutputFlag());
		assertTrue(tools[0].buildsFileType("foo"));
		assertTrue(tools[0].buildsFileType("bar"));
		assertTrue(tools[0].producesFileType("toor"));
		assertEquals("doIt", tools[0].getToolCommand());
		assertEquals("", tools[0].getOutputPrefix());
		// The root tool defines one valid header file extension
		assertTrue(rootTool.isHeaderFile("baz"));
		assertTrue(tools[0].isHeaderFile("baz"));
		assertEquals(ITool.FILTER_C, rootTool.getNatureFilter());

		// Partially Overriden Configuration
		assertEquals("Root Override Config", configs[1].getName());
		tools = configs[1].getTools();
		assertEquals(1, tools.length);
		assertEquals("Root Tool", tools[0].getName());
		topCategory = tools[0].getTopOptionCategory();
		catoptions = topCategory.getOptions(configs[1]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(2, i);
		assertEquals("List Option in Top", ((IOption) catoptions[0][1]).getName());
		valueList = ((IOption) catoptions[0][1]).getStringListValue();
		assertEquals("a", valueList[0]);
		assertEquals("b", valueList[1]);
		assertEquals("Boolean Option in Top", ((IOption) catoptions[1][1]).getName());
		assertEquals(true, ((IOption) catoptions[1][1]).getBooleanValue());
		assertEquals("-b", ((IOption) catoptions[1][1]).getCommand());
		categories = topCategory.getChildCategories();
		catoptions = categories[0].getOptions(configs[1]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(4, i);
		assertEquals("String Option in Category", ((IOption) catoptions[0][1]).getName());
		assertEquals("y", ((IOption) catoptions[0][1]).getStringValue());
		assertEquals("Another String Option in Category", ((IOption) catoptions[1][1]).getName());
		assertEquals("", ((IOption) catoptions[1][1]).getStringValue());
		assertEquals("Enumerated Option in Category", ((IOption) catoptions[2][1]).getName());
		valueList = ((IOption) catoptions[2][1]).getApplicableValues();
		assertEquals(2, valueList.length);
		assertEquals("Default Enum", valueList[0]);
		assertEquals("Another Enum", valueList[1]);
		assertEquals("-e1", ((IOption) catoptions[2][1]).getEnumCommand(valueList[0]));
		assertEquals("-e2", ((IOption) catoptions[2][1]).getEnumCommand(valueList[1]));
		assertEquals(1, tools.length);
		assertEquals("Boolean Option in Category", ((IOption) catoptions[3][1]).getName());
		assertEquals(false, ((IOption) catoptions[3][1]).getBooleanValue());
		assertEquals("", ((IOption) catoptions[3][1]).getCommand());
		assertEquals("-nob", ((IOption) catoptions[3][1]).getCommandFalse());
		assertEquals(1, tools.length);
		ITool tool = tools[0];
		assertNotNull(tool);
		assertEquals("Root Tool", tool.getName());
		assertEquals("-r", tool.getOutputFlag());
		assertTrue(tool.buildsFileType("foo"));
		assertTrue(tool.buildsFileType("bar"));
		assertTrue(tool.producesFileType("toor"));
		assertTrue(tool.isHeaderFile("baz"));
		assertEquals("doIt", tool.getToolCommand());
		assertEquals("-La -Lb -b y -e1 -nob", tool.getToolFlags());

		// Completely Overridden configuration
		assertEquals("Complete Override Config", configs[2].getName());
		tools = configs[2].getTools();
		assertEquals(1, tools.length);
		assertEquals("Root Tool", tools[0].getName());
		topCategory = tools[0].getTopOptionCategory();
		catoptions = topCategory.getOptions(configs[2]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(2, i);
		// Check that there's an string list with totally new values
		assertEquals("List Option in Top", ((IOption) catoptions[0][1]).getName());
		assertEquals(IOption.STRING_LIST, ((IOption) catoptions[0][1]).getValueType());
		valueList = ((IOption) catoptions[0][1]).getStringListValue();
		assertTrue(valueList.length == 3);
		assertEquals("d", valueList[0]);
		assertEquals("e", valueList[1]);
		assertEquals("f", valueList[2]);
		assertEquals("-L", ((IOption) catoptions[0][1]).getCommand());
		// and a true boolean (commands should not have changed)
		assertEquals("Boolean Option in Top", ((IOption) catoptions[1][1]).getName());
		assertEquals(IOption.BOOLEAN, ((IOption) catoptions[1][1]).getValueType());
		assertEquals(true, ((IOption) catoptions[1][1]).getBooleanValue());
		assertEquals("-b", ((IOption) catoptions[1][1]).getCommand());
		// Check that there's an overridden enumeration and string
		categories = topCategory.getChildCategories();
		catoptions = categories[0].getOptions(configs[2]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(4, i);
		assertEquals("String Option in Category", ((IOption) catoptions[0][1]).getName());
		assertEquals(IOption.STRING, ((IOption) catoptions[0][1]).getValueType());
		assertEquals("overridden", ((IOption) catoptions[0][1]).getStringValue());
		assertEquals("Another String Option in Category", ((IOption) catoptions[1][1]).getName());
		assertEquals(IOption.STRING, ((IOption) catoptions[1][1]).getValueType());
		assertEquals("alsooverridden", ((IOption) catoptions[1][1]).getStringValue());
		assertEquals("Enumerated Option in Category", ((IOption) catoptions[2][1]).getName());
		assertEquals(IOption.ENUMERATED, ((IOption) catoptions[2][1]).getValueType());
		assertEquals("another.enum.option", ((IOption) catoptions[2][1]).getSelectedEnum());
		assertEquals("Boolean Option in Category", ((IOption) catoptions[3][1]).getName());
		assertEquals(IOption.BOOLEAN, ((IOption) catoptions[3][1]).getValueType());
		assertEquals(true, ((IOption) catoptions[3][1]).getBooleanValue());
		tool = tools[0];
		assertEquals("-Ld -Le -Lf -b overridden -stralsooverridden -e2", tool.getToolFlags());

		// Make sure that the build manager returns the default makefile generator (not null)
		assertNotNull(ManagedBuildManager.getBuildfileGenerator(configs[0]));
	}

	/*
	 * Do a full sanity check on the root managed project.
	 */
	private void checkRootManagedProject(IManagedProject managedProj, String testValue) throws BuildException {
		String expectedCleanCmd = "del /myworld";
		String expectedParserId = "org.eclipse.cdt.core.PE";
		String[] expectedOSList = { "win32" };
		String[] expectedArchList = { "all" };
		assertTrue(managedProj.getProjectType().isTestProjectType());
		IConfiguration[] configs = managedProj.getConfigurations();
		if (configs[0].getArtifactName().equals("ManagedBuildTest")) {
			assertEquals(configs[0].getArtifactExtension(), newExt);
		} else {
			assertEquals(configs[0].getArtifactExtension(), rootExt);
		}
		assertEquals(expectedCleanCmd, configs[0].getCleanCommand());
		assertEquals("make", configs[0].getBuildCommand());
		IToolChain toolChain = configs[0].getToolChain();
		ITargetPlatform targetPlatform = toolChain.getTargetPlatform();
		String[] binaryParsers = targetPlatform.getBinaryParserList();
		assertEquals(binaryParsers.length, 1);
		assertEquals(binaryParsers[0], expectedParserId);
		assertTrue(Arrays.equals(expectedOSList, toolChain.getOSList()));
		assertTrue(Arrays.equals(expectedArchList, toolChain.getArchList()));
		// This configuration defines no errors parsers.
		assertNull(configs[0].getErrorParserIds());
		assertTrue(Arrays.equals(configs[0].getErrorParserList(), CCorePlugin.getDefault().getAllErrorParsersIDs()));

		// Tools
		ITool[] tools = configs[0].getTools();
		// Root Tool
		ITool rootTool = tools[0];
		assertEquals("Root Tool", rootTool.getName());
		// 6 Options are defined in the root tool
		IOption[] options = rootTool.getOptions();
		assertEquals(6, options.length);
		// First option is a 3-element list with 1 built-in
		assertEquals("List Option in Top", options[0].getName());
		assertEquals(IOption.STRING_LIST, options[0].getValueType());
		String[] valueList = options[0].getStringListValue();
		assertEquals(2, valueList.length);
		assertEquals("a", valueList[0]);
		assertEquals("b", valueList[1]);
		String[] builtInList = options[0].getBuiltIns();
		assertEquals(1, builtInList.length);
		assertEquals("c", builtInList[0]);
		assertEquals(options[0].getCommand(), "-L");
		// Next option is a boolean in top
		assertEquals("Boolean Option in Top", options[1].getName());
		assertEquals(IOption.BOOLEAN, options[1].getValueType());
		assertEquals(false, options[1].getBooleanValue());
		assertEquals("-b", options[1].getCommand());
		// Next option is a string category
		assertEquals("String Option in Category", options[2].getName());
		assertEquals(IOption.STRING, options[2].getValueType());
		assertEquals(testValue, options[2].getStringValue());
		// Next option is another string category
		assertEquals("Another String Option in Category", options[3].getName());
		assertEquals(IOption.STRING, options[3].getValueType());
		assertEquals("", options[3].getStringValue());
		assertEquals("-str", options[3].getCommand());
		// Next option is an enumerated
		assertEquals("Enumerated Option in Category", options[4].getName());
		assertEquals(IOption.ENUMERATED, options[4].getValueType());
		// Post-2.0 enums store the ID, not the string value
		assertEquals("default.enum.option", options[4].getSelectedEnum());
		assertEquals("-e1", options[4].getEnumCommand("default.enum.option"));
		// Need this methof to populate the UI selection widget
		valueList = options[4].getApplicableValues();
		assertEquals(2, valueList.length);
		assertEquals("Default Enum", valueList[0]);
		assertEquals("Another Enum", valueList[1]);
		// Test compatability with 1.2 scheme of getting the command from the name
		assertEquals("-e1", options[4].getEnumCommand(valueList[0]));
		assertEquals("-e2", options[4].getEnumCommand(valueList[1]));
		// Final option is another boolean
		assertEquals("Boolean Option in Category", options[5].getName());
		assertEquals(IOption.BOOLEAN, options[5].getValueType());
		assertEquals(false, options[5].getBooleanValue());
		assertEquals("", options[5].getCommand());
		assertEquals("-nob", options[5].getCommandFalse());

		// Option Categories
		IOptionCategory topCategory = rootTool.getTopOptionCategory();
		assertEquals("Root Tool", topCategory.getName());
		Object[][] catoptions = topCategory.getOptions(configs[0]);
		int i;
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(2, i);
		IOption catOption = (IOption) catoptions[0][1];
		assertEquals("List Option in Top", catOption.getName());
		catOption = (IOption) catoptions[1][1];
		assertEquals("Boolean Option in Top", catOption.getName());
		IOptionCategory[] categories = topCategory.getChildCategories();
		assertEquals(1, categories.length);
		assertEquals("Category", categories[0].getName());
		catoptions = categories[0].getOptions(configs[0]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(4, i);
		catOption = (IOption) catoptions[0][1];
		assertEquals("String Option in Category", catOption.getName());
		catOption = (IOption) catoptions[1][1];
		assertEquals("Another String Option in Category", catOption.getName());
		catOption = (IOption) catoptions[2][1];
		assertEquals("Enumerated Option in Category", catOption.getName());
		catOption = (IOption) catoptions[3][1];
		assertEquals("Boolean Option in Category", catOption.getName());

		// There should be 3 defined configs
		assertEquals(3, configs.length);

		// Root Config
		IConfiguration rootConfig = configs[0];
		assertEquals("Root Config", rootConfig.getName());

		// Tool elements
		tools = rootConfig.getTools();
		assertEquals(1, tools.length);
		assertEquals("Root Tool", tools[0].getName());
		assertEquals("-r", tools[0].getOutputFlag());
		assertTrue(tools[0].buildsFileType("foo"));
		assertTrue(tools[0].buildsFileType("bar"));
		assertTrue(tools[0].producesFileType("toor"));
		assertEquals("doIt", tools[0].getToolCommand());
		assertEquals("", tools[0].getOutputPrefix());
		// The root tool defines one valid header file extension
		assertTrue(rootTool.isHeaderFile("baz"));
		assertTrue(tools[0].isHeaderFile("baz"));
		assertEquals(ITool.FILTER_C, rootTool.getNatureFilter());

		// Partially Overriden Configuration
		assertEquals("Root Override Config", configs[1].getName());
		tools = configs[1].getTools();
		assertEquals(1, tools.length);
		assertEquals("Root Tool", tools[0].getName());
		topCategory = tools[0].getTopOptionCategory();
		catoptions = topCategory.getOptions(configs[1]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(2, i);
		catOption = (IOption) catoptions[0][1];
		assertEquals("List Option in Top", catOption.getName());
		valueList = catOption.getStringListValue();
		assertEquals("a", valueList[0]);
		assertEquals("b", valueList[1]);
		catOption = (IOption) catoptions[1][1];
		assertEquals("Boolean Option in Top", catOption.getName());
		assertEquals(true, catOption.getBooleanValue());
		assertEquals("-b", catOption.getCommand());
		categories = topCategory.getChildCategories();
		catoptions = categories[0].getOptions(configs[1]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(4, i);
		catOption = (IOption) catoptions[0][1];
		assertEquals("String Option in Category", catOption.getName());
		assertEquals("y", catOption.getStringValue());
		catOption = (IOption) catoptions[1][1];
		assertEquals("Another String Option in Category", catOption.getName());
		assertEquals("", catOption.getStringValue());
		catOption = (IOption) catoptions[2][1];
		assertEquals("Enumerated Option in Category", catOption.getName());
		valueList = catOption.getApplicableValues();
		assertEquals(2, valueList.length);
		assertEquals("Default Enum", valueList[0]);
		assertEquals("Another Enum", valueList[1]);
		catOption = (IOption) catoptions[2][1];
		assertEquals("-e1", catOption.getEnumCommand(valueList[0]));
		assertEquals("-e2", catOption.getEnumCommand(valueList[1]));
		assertEquals(1, tools.length);
		catOption = (IOption) catoptions[3][1];
		assertEquals("Boolean Option in Category", catOption.getName());
		assertEquals(false, catOption.getBooleanValue());
		assertEquals("", catOption.getCommand());
		assertEquals("-nob", catOption.getCommandFalse());
		assertEquals(1, tools.length);
		ITool tool = tools[0];
		assertNotNull(tool);
		assertEquals("Root Tool", tool.getName());
		assertEquals("-r", tool.getOutputFlag());
		assertTrue(tool.buildsFileType("foo"));
		assertTrue(tool.buildsFileType("bar"));
		assertTrue(tool.producesFileType("toor"));
		assertTrue(tool.isHeaderFile("baz"));
		assertEquals("doIt", tool.getToolCommand());
		assertEquals("-La -Lb -b y -e1 -nob", tool.getToolFlags());

		// Completely Overridden configuration
		assertEquals("Complete Override Config", configs[2].getName());
		tools = configs[2].getTools();
		assertEquals(1, tools.length);
		assertEquals("Root Tool", tools[0].getName());
		topCategory = tools[0].getTopOptionCategory();
		catoptions = topCategory.getOptions(configs[2]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(2, i);
		// Check that there's an string list with totally new values
		catOption = (IOption) catoptions[0][1];
		assertEquals("List Option in Top", catOption.getName());
		assertEquals(IOption.STRING_LIST, catOption.getValueType());
		valueList = catOption.getStringListValue();
		assertTrue(valueList.length == 3);
		assertEquals("d", valueList[0]);
		assertEquals("e", valueList[1]);
		assertEquals("f", valueList[2]);
		assertEquals("-L", catOption.getCommand());
		// and a true boolean (commands should not have changed)
		catOption = (IOption) catoptions[1][1];
		assertEquals("Boolean Option in Top", catOption.getName());
		assertEquals(IOption.BOOLEAN, catOption.getValueType());
		assertEquals(true, catOption.getBooleanValue());
		assertEquals("-b", catOption.getCommand());
		// Check that there's an overridden enumeration and string
		categories = topCategory.getChildCategories();
		catoptions = categories[0].getOptions(configs[2]);
		for (i = 0; i < catoptions.length; i++)
			if (catoptions[i][0] == null)
				break;
		assertEquals(4, i);
		catOption = (IOption) catoptions[0][1];
		assertEquals("String Option in Category", catOption.getName());
		assertEquals(IOption.STRING, catOption.getValueType());
		assertEquals("overridden", catOption.getStringValue());
		catOption = (IOption) catoptions[1][1];
		assertEquals("Another String Option in Category", catOption.getName());
		assertEquals(IOption.STRING, catOption.getValueType());
		assertEquals("alsooverridden", catOption.getStringValue());
		catOption = (IOption) catoptions[2][1];
		assertEquals("Enumerated Option in Category", catOption.getName());
		assertEquals(IOption.ENUMERATED, catOption.getValueType());
		assertEquals("another.enum.option", catOption.getSelectedEnum());
		catOption = (IOption) catoptions[3][1];
		assertEquals("Boolean Option in Category", catOption.getName());
		assertEquals(IOption.BOOLEAN, catOption.getValueType());
		assertEquals(true, catOption.getBooleanValue());
		tool = tools[0];
		assertEquals("-Ld -Le -Lf -b overridden -stralsooverridden -e2", tool.getToolFlags());

		// Make sure that the build manager returns the default makefile generator (not null)
		assertNotNull(ManagedBuildManager.getBuildfileGenerator(configs[0]));
	}

	/*
	 * The Sub Sub project type has a reference to a tool that is defined
	 * independently from the project type itself. This is a common pattern
	 * for tools that are shared between many project types.
	 *
	 * The tool itself is defined as having two option categories, with
	 * one option in each category. To test that the reference is properly
	 * inheritted, the project type overrides the default value of the boolean
	 * option.
	 *
	 * The test confirms that the basic settings are inheritted through the
	 * reference, and that the overridden value is used instead of the
	 * default. It also tests that the command can be overidden through a
	 * tool reference.
	 *
	 * Finally, the string option in the configuration is overridden and the
	 * test confirms that it contains both the overridden boolean that the
	 * project type provides, and the overridden string that it provides.
	 *
	 * @param testSubSub
	 */
	private void checkSubSubProjectType(IProjectType projType) {
		final String indyToolName = "Target Independent Tool";
		final String indyToolCommand = "RC.EXE";
		final String indyToolInputExt = "rc";
		final String indyToolOutputExt = "free";
		final String indyToolOutFlag = "/fo";
		final String indyToolHeader = "h";
		final String indyToolHeaderNot = "j";
		final String indyCatOne = "Free";
		final String indyCatTwo = "Chained";
		final String freeOptName = "String in Free";
		final String chainedOptName = "Boolean in Chained";
		final String freeOptValue = "Live free or die";
		final String newCmd = "Let the Wookie win";
		final String stringOverride = "The future language of slaves";

		IConfiguration[] configs = projType.getConfigurations();
		// Check the inherited clean command
		assertEquals("rm -yourworld", configs[0].getCleanCommand());
		// Check that the make command is overridden from parent
		assertEquals("nmake", configs[0].getBuildCommand());
		// Make sure we get the proper binary parser
		IToolChain toolChain = configs[0].getToolChain();
		ITargetPlatform targetPlatform = toolChain.getTargetPlatform();
		assertEquals("org.eclipse.cdt.core.ELF", targetPlatform.getBinaryParserList()[0]);
		// Make sure the os list is inherited
		String[] expectedOSList = { "win32", "linux", "solaris" };
		assertTrue(Arrays.equals(expectedOSList, toolChain.getOSList()));
		// Make sure the arch list is inherited
		String[] expectedArchList = { "x86", "ppc" };
		assertTrue(Arrays.equals(expectedArchList, toolChain.getArchList()));

		// Get the 5 configurations (3 from test, 1 from test sub and 1 from this)
		assertEquals(5, configs.length);

		// Check the tools. We should have 3 (1 from each parent and the one referenced).
		ITool[] tools = configs[0].getTools();
		assertEquals(3, tools.length);
		ITool toolRef = tools[0];

		// Make sure we get all the tool settings
		assertEquals(toolRef.getName(), indyToolName);
		assertEquals(toolRef.getToolCommand(), indyToolCommand);
		assertTrue(toolRef.buildsFileType(indyToolInputExt));
		assertEquals(toolRef.getOutputExtension(indyToolInputExt), indyToolOutputExt);
		assertEquals(toolRef.getOutputFlag(), indyToolOutFlag);
		assertTrue(toolRef.isHeaderFile(indyToolHeader));
		assertFalse(toolRef.isHeaderFile(indyToolHeaderNot));
		assertEquals(toolRef.getNatureFilter(), ITool.FILTER_BOTH);
		// Check out the referenced tool and make sure we get all option categories
		IOptionCategory topCategory = toolRef.getTopOptionCategory();
		IOptionCategory[] categories = topCategory.getChildCategories();
		assertEquals(1, categories.length);
		assertEquals(categories[0].getName(), indyCatOne);
		IOptionCategory[] subCategories = categories[0].getChildCategories();
		// Is the chained category a subcategory
		assertEquals(1, subCategories.length);
		assertEquals(subCategories[0].getName(), indyCatTwo);
		// Make sure the option in the top category is correct
		Object[][] optsInCat = categories[0].getOptions(configs[0]);
		int i;
		for (i = 0; i < optsInCat.length; i++)
			if (optsInCat[i][0] == null)
				break;
		assertEquals(1, i);
		IOption optCat = (IOption) optsInCat[0][1];
		assertEquals(freeOptName, optCat.getName());
		try {
			// We get the option categories and options from the tool itself, but the
			// tool reference will have a set of 0 to n option references that contain
			// overridden settings. In this case, the string is inheritted and should
			// not be reference
			assertEquals(IOption.STRING, optCat.getValueType());
			IOption stringOpt = toolRef.getOptionById(optCat.getId());
			assertTrue(stringOpt instanceof Option);
			assertEquals(freeOptValue, stringOpt.getStringValue());
		} catch (BuildException e1) {
			fail("Failed getting string value in subsub :" + e1.getLocalizedMessage());
		}

		// Do the same for the options in the child cat
		Object[][] optsInSubCat = subCategories[0].getOptions(configs[0]);
		for (i = 0; i < optsInSubCat.length; i++)
			if (optsInSubCat[i][0] == null)
				break;
		assertEquals(1, i);
		IOption booleanRef = toolRef.getOptionById(((IOption) optsInSubCat[0][1]).getId());
		assertEquals(chainedOptName, booleanRef.getName());
		try {
			assertEquals(IOption.BOOLEAN, booleanRef.getValueType());
			assertTrue(booleanRef.getBooleanValue());
		} catch (BuildException e) {
			fail("Failure getting boolean value in subsub: " + e.getLocalizedMessage());
		}

		// Test that the tool command can be changed through the reference
		toolRef.setToolCommand(newCmd);
		assertEquals(toolRef.getToolCommand(), newCmd);

		// Muck about with the options in the local config
		IConfiguration subSubConfig = projType.getConfiguration("sub.sub.config");
		assertNotNull(subSubConfig);
		ITool[] configTools = subSubConfig.getTools();
		// This tool ref is inherited from parent, so it does not belong to the config
		ITool configToolRef = configTools[0];
		assertNotNull(configToolRef);
		optCat = (IOption) optsInCat[0][1];
		IOption configStringOpt = configToolRef.getOptionById(optCat.getId());
		assertNotNull(configStringOpt);
		// Override the string option
		try {
			subSubConfig.setOption(configToolRef, configStringOpt, stringOverride);
		} catch (BuildException e) {
			fail("Failure setting string value in subsubconfiguration: " + e.getLocalizedMessage());
		}
		// Now the config should have a tool ref to the independent tool
		configTools = subSubConfig.getTools();
		configToolRef = configTools[0];
		assertNotNull(configToolRef);

		// Test that the string option is overridden in the configuration
		optsInCat = categories[0].getOptions(configs[0]);
		for (i = 0; i < optsInCat.length; i++)
			if (optsInCat[i][0] == null)
				break;
		assertEquals(1, i);
		optCat = (IOption) optsInCat[0][1];
		assertEquals(freeOptName, optCat.getName());
		configStringOpt = configToolRef.getOptionById(optCat.getId());
		try {
			assertEquals(stringOverride, configStringOpt.getStringValue());
		} catch (BuildException e) {
			fail("Failure getting string value in subsubconfiguration: " + e.getLocalizedMessage());
		}
		// The tool should also contain the boolean option set to true
		IOption optSubCat = (IOption) optsInSubCat[0][1];
		IOption configBoolOpt = configToolRef.getOptionById(optSubCat.getId());
		assertNotNull(configBoolOpt);
		try {
			assertTrue(configBoolOpt.getBooleanValue());
		} catch (BuildException e) {
			fail("Failure getting boolean value in subsubconfiguration: " + e.getLocalizedMessage());
		}

		// Override it in config and retest
		try {
			subSubConfig.setOption(configToolRef, configBoolOpt, false);
		} catch (BuildException e) {
			fail("Failure setting boolean value in subsubconfiguration: " + e.getLocalizedMessage());
		}
		optsInSubCat = subCategories[0].getOptions(configs[0]);
		for (i = 0; i < optsInSubCat.length; i++)
			if (optsInSubCat[i][0] == null)
				break;
		assertEquals(1, i);
		configBoolOpt = configToolRef.getOptionById(((IOption) optsInSubCat[0][1]).getId());
		assertEquals(chainedOptName, booleanRef.getName());
		try {
			assertFalse(configBoolOpt.getBooleanValue());
		} catch (BuildException e) {
			fail("Failure getting boolean value in subsubconfiguration: " + e.getLocalizedMessage());
		}
	}

	/*
	 * Do a sanity check on the values in the sub-project type. Most of the
	 * sanity on the how build model entries are read is performed in
	 * the root project type check, so these tests just verify that the the sub
	 * project type properly inherits from its parent. For the new options
	 * in the sub project type, the test does a sanity check just to be complete.
	 */
	private void checkSubProjectType(IProjectType projType) throws BuildException {
		final String expectedFlags = "-I/usr/include -I/opt/gnome/include -IC:\\home\\tester/include -I\"../includes\" x y z";

		IConfiguration[] configs = projType.getConfigurations();
		// Check the overridden clean command
		assertEquals("rm -yourworld", configs[0].getCleanCommand());
		// Make sure the projType inherits the make command
		assertEquals("make", configs[0].getBuildCommand());
		// Make sure the binary parser is hard-coded and available
		IToolChain toolChain = configs[0].getToolChain();
		ITargetPlatform targetPlatform = toolChain.getTargetPlatform();
		assertEquals("org.eclipse.cdt.core.PE", targetPlatform.getBinaryParserList()[0]);
		String[] expectedOSList = { "win32", "linux", "solaris" };
		assertTrue(Arrays.equals(expectedOSList, toolChain.getOSList()));
		// Make sure the list is overridden
		String[] expectedArchList = { "x86", "ppc" };
		assertTrue(Arrays.equals(expectedArchList, toolChain.getArchList()));

		// Make sure this is a test projType
		assertTrue(projType.isTestProjectType());
		// Make sure the build artifact extension is there
		assertEquals(configs[0].getArtifactExtension(), subExt);

		// Get the tools for this projType
		ITool[] tools = configs[0].getTools();
		// Do we inherit properly from parent
		ITool rootTool = tools[0];
		assertEquals("Root Tool", rootTool.getName());
		// Now get the tool defined for this projType
		ITool subTool = tools[1];
		assertEquals("Sub Tool", subTool.getName());
		// Confirm that it has four options
		IOption[] subOpts = subTool.getOptions();
		assertEquals(5, subOpts.length);
		assertEquals("", subTool.getOutputFlag());
		assertTrue(subTool.buildsFileType("yarf"));
		assertTrue(subTool.producesFileType("bus"));
		assertEquals("", subTool.getToolCommand());
		assertEquals("lib", subTool.getOutputPrefix());
		assertTrue(subTool.isHeaderFile("arf"));
		assertTrue(subTool.isHeaderFile("barf"));
		assertEquals(ITool.FILTER_BOTH, subTool.getNatureFilter());

		// Do a sanity check on the options
		assertEquals("Include Paths", subOpts[0].getName());
		assertEquals(IOption.INCLUDE_PATH, subOpts[0].getValueType());
		String[] incPath = subOpts[0].getIncludePaths();
		assertEquals(2, incPath.length);
		assertEquals("/usr/include", incPath[0]);
		assertEquals("/opt/gnome/include", incPath[1]);
		String[] builtInPaths = subOpts[0].getBuiltIns();
		assertEquals(1, builtInPaths.length);
		assertEquals("/usr/gnu/include", builtInPaths[0]);
		assertEquals("-I", subOpts[0].getCommand());
		assertEquals(IOption.BROWSE_DIR, subOpts[0].getBrowseType());

		// There are no user-defined preprocessor symbols
		assertEquals("Defined Symbols", subOpts[1].getName());
		assertEquals(IOption.PREPROCESSOR_SYMBOLS, subOpts[1].getValueType());
		String[] defdSymbols = subOpts[1].getDefinedSymbols();
		assertEquals(0, defdSymbols.length);
		assertEquals("-D", subOpts[1].getCommand());
		// But there is a builtin
		String[] builtInSymbols = subOpts[1].getBuiltIns();
		assertEquals(1, builtInSymbols.length);
		assertEquals("BUILTIN", builtInSymbols[0]);
		// Broswe type should be none
		assertEquals(IOption.BROWSE_NONE, subOpts[1].getBrowseType());

		assertEquals("More Includes", subOpts[2].getName());
		assertEquals(IOption.INCLUDE_PATH, subOpts[2].getValueType());
		String[] moreIncPath = subOpts[2].getIncludePaths();
		assertEquals(2, moreIncPath.length);
		assertEquals("C:\\home\\tester/include", moreIncPath[0]);
		assertEquals("-I", subOpts[2].getCommand());
		assertEquals(IOption.BROWSE_DIR, subOpts[2].getBrowseType());

		// Check the user object option
		assertEquals("User Objects", subOpts[3].getName());
		assertEquals(IOption.OBJECTS, subOpts[3].getValueType());
		String[] objs = subOpts[3].getUserObjects();
		assertEquals(2, objs.length);
		assertEquals("obj1.o", objs[0]);
		assertEquals("obj2.o", objs[1]);
		assertEquals(IOption.BROWSE_FILE, subOpts[3].getBrowseType());
		assertEquals("", subOpts[3].getCommand());

		// There should be a string list with no command
		assertEquals("No Command StringList", subOpts[4].getName());
		assertEquals(IOption.STRING_LIST, subOpts[4].getValueType());

		// Make sure the tool flags look right
		assertEquals(subTool.getToolFlags(), expectedFlags);

		// Get the configs for this projType; it should inherit all the configs defined for the parent
		assertEquals(4, configs.length);
		assertEquals("Sub Config", configs[0].getName());
		assertEquals("Root Config", configs[1].getName());
		assertEquals("Root Override Config", configs[2].getName());
		assertEquals("Complete Override Config", configs[3].getName());
	}

	private void checkForwardProjectTypes(IProjectType parent, IProjectType child, IProjectType grandchild) {
		// check that the projType parent reference has been resolved.
		assertEquals(parent, child.getSuperClass());
		assertEquals(child, grandchild.getSuperClass());

		// get the parent tool
		IConfiguration[] parentConfigs = parent.getConfigurations();
		ITool[] parentTools = parentConfigs[0].getTools();
		assertEquals(1, parentTools.length);
		ITool parentTool = parentTools[0];
		assertNotNull(parentTool);

		// check option categories
		IOption option = parentTool.getOptionById("test.forward.option");
		assertNotNull(option);
		IOptionCategory[] firstLevel = parentTool.getTopOptionCategory().getChildCategories();
		assertEquals(1, firstLevel.length);
		IOptionCategory[] secondLevel = firstLevel[0].getChildCategories();
		assertEquals(1, secondLevel.length);
		assertEquals(0, secondLevel[0].getChildCategories().length);
		Object[][] optList = secondLevel[0].getOptions(parentConfigs[0]);
		int i;
		for (i = 0; i < optList.length; i++)
			if (optList[i][0] == null)
				break;
		assertEquals(1, i);
		assertEquals(option, optList[0][1]);

		// get the tool reference from the child
		IConfiguration[] childConfigs = child.getConfigurations();
		ITool[] childTools = childConfigs[0].getTools();
		assertEquals(1, childTools.length);
		ITool childToolRef = childTools[0];
		assertEquals(parentTool.getSuperClass(), childToolRef.getSuperClass());

		// get and check the option reference
		IOption optRef = childToolRef.getOptionById("test.forward.option");
		assertEquals(option, optRef);

		// get the tool reference from the grandchild
		IConfiguration[] grandConfigs = grandchild.getConfigurations();
		ITool[] grandTools = grandConfigs[0].getTools();
		assertEquals(1, grandTools.length);
		ITool grandToolRef = grandTools[0];
		assertEquals(parentTool.getSuperClass(), grandToolRef.getSuperClass());

	}

	public void checkProviderProjectType(IProjectType projType) throws Exception {
		Properties props = new Properties();
		props.load(getClass().getResourceAsStream("test_commands"));

		// check that this projType is in the file
		String command = props.getProperty(projType.getId());
		assertNotNull(command);

		IProjectType parent = projType.getSuperClass();
		assertNotNull(parent);
		assertEquals("test.forward.parent.target", parent.getId());

		IConfiguration[] configs = projType.getConfigurations();
		ITool toolRef = configs[0].getFilteredTools()[0];
		assertEquals(command, toolRef.getToolCommand());
	}

	/**
	 * Remove all the project information associated with the project used during test.
	 */
	public void cleanup() throws CoreException, IOException {
		ResourceHelper.cleanUp(getName());
		removeProject(projectName);
		removeProject(projectName2);
	}

	/* (non-Javadoc)
	 * Create a new project named <code>name</code> or return the project in
	 * the workspace of the same name if it exists.
	 *
	 * @param name The name of the project to create or retrieve.
	 * @return
	 * @throws CoreException
	 */
	private IProject createProject(String name) throws CoreException {
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		final IProject newProjectHandle = root.getProject(name);
		IProject project = null;

		if (!newProjectHandle.exists()) {
			IWorkspace workspace = ResourcesPlugin.getWorkspace();
			IWorkspaceDescription workspaceDesc = workspace.getDescription();
			workspaceDesc.setAutoBuilding(false);
			workspace.setDescription(workspaceDesc);
			IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
			//description.setLocation(root.getLocation());
			project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(),
					/*MakeCorePlugin.MAKE_PROJECT_ID*/ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);

			// Now associate the builder with the project
			ManagedBuildTestHelper.addManagedBuildNature(project);
		} else {
			IWorkspace workspace = ResourcesPlugin.getWorkspace();
			IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
				@Override
				public void run(IProgressMonitor monitor) throws CoreException {
					newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, monitor);
				}
			};
			NullProgressMonitor monitor = new NullProgressMonitor();
			workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
			project = newProjectHandle;
		}

		// Open the project if we have to
		if (!project.isOpen()) {
			project.open(new NullProgressMonitor());
		}

		return project;
	}

	/**
	 * Remove the <code>IProject</code> with the name specified in the argument from the
	 * receiver's workspace.
	 *
	 * @param name
	 */
	private void removeProject(String name) {
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		IProject project = root.getProject(name);
		if (project.exists()) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e1) {
			} finally {
				try {
					System.gc();
					System.runFinalization();
					project.delete(true, true, null);
				} catch (CoreException e2) {
					assertTrue(false);
				}
			}
		}
	}

	/**
	 * @throws BuildException
	 */
	public void testErrorParsers() throws BuildException {
		// Create new project
		IProject project = null;
		try {
			project = createProject(projectName2);
			// Now associate the builder with the project
			ManagedBuildTestHelper.addManagedBuildNature(project);
			IProjectDescription description = project.getDescription();
			// Make sure it has a managed nature
			if (description != null) {
				assertTrue(description.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
			}
		} catch (CoreException e) {
			fail("Test failed on error parser project creation: " + e.getLocalizedMessage());
		}

		// Find the base project Type definition
		IProjectType projType = ManagedBuildManager.getProjectType("test.error.parsers");
		assertNotNull(projType);

		// Create the target for our project that builds a dummy executable
		IManagedProject newProj = ManagedBuildManager.createManagedProject(project, projType);
		assertEquals(newProj.getName(), projType.getName());
		ManagedBuildManager.setNewProjectVersion(project);

		ManagedBuildManager.getBuildInfo(project).setValid(true);
		// Initialize the path entry container
		IStatus initResult = ManagedBuildManager.initBuildInfoContainer(project);
		if (initResult.getCode() != IStatus.OK) {
			fail("Initializing build information failed for: " + project.getName() + " because: "
					+ initResult.getMessage());
		}

		// Copy over the configs
		IConfiguration[] baseConfigs = projType.getConfigurations();
		for (int i = 0; i < baseConfigs.length; ++i) {
			newProj.createConfiguration(baseConfigs[i], baseConfigs[i].getId() + "." + i);
		}

		// Test this out
		checkErrorParsersProject(newProj);

		// Save, close, reopen and test again
		ManagedBuildManager.saveBuildInfo(project, true);
		ManagedBuildManager.removeBuildInfo(project);
		try {
			ResourceHelper.joinIndexerBeforeCleanup(getName());
			project.close(null);
		} catch (CoreException e) {
			fail("Failed on error parser project close: " + e.getLocalizedMessage());
		}
		try {
			project.open(null);
		} catch (CoreException e) {
			fail("Failed on error parser project open: " + e.getLocalizedMessage());
		}

		// Test that the default config was remembered
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);

		// Check the rest of the default information
		checkErrorParsersProject(info.getManagedProject());
		ManagedBuildManager.removeBuildInfo(project);
	}

	/*
	 * Do a sanity check on the error parsers target.
	 */
	private void checkErrorParsersProject(IManagedProject proj) throws BuildException {
		// Target stuff
		String expectedBinParserId = "org.eclipse.cdt.core.PE";
		IConfiguration[] configs = proj.getConfigurations();
		IToolChain toolChain = configs[0].getToolChain();
		ITargetPlatform targetPlatform = toolChain.getTargetPlatform();
		assertEquals(expectedBinParserId, targetPlatform.getBinaryParserList()[0]);
		// This target defines errors parsers.  Check that the error parsers
		// have been assigned.
		assertEquals(
				"org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GmakeErrorParser",
				configs[0].getErrorParserIds());

		// Tool
		ITool[] tools = configs[0].getTools();
		ITool rootTool = tools[0];
		assertEquals(1, tools.length);
		assertEquals("EP Tool", tools[0].getName());
		assertEquals("-o", tools[0].getOutputFlag());
		assertTrue(tools[0].buildsFileType("y"));
		assertTrue(tools[0].buildsFileType("x"));
		assertTrue(tools[0].producesFileType("xy"));
		assertEquals("EP", tools[0].getToolCommand());
		assertEquals(ITool.FILTER_C, rootTool.getNatureFilter());

		// There should be one defined configs
		assertEquals(1, configs.length);
	}

	/**
	 * Test that the build artifact of a <code>ITarget</code> can be modified
	 * programmatically.
	 */
	public void testConfigBuildArtifact() throws CoreException {
		// Open the test project
		IProject project = createProject(projectName);
		IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
		assertNotNull(info);
		IManagedProject managedProj = info.getManagedProject();
		assertNotNull(managedProj);
		IConfiguration defaultConfig = info.getDefaultConfiguration();
		assertNotNull(defaultConfig);

		// Set the build artifact of the configuration
		String ext = defaultConfig.getArtifactExtension();
		String name = project.getName() + "." + ext;
		defaultConfig.setArtifactName(name);

		// Save, close, reopen and test again
		ManagedBuildManager.saveBuildInfo(project, false);
		ManagedBuildManager.removeBuildInfo(project);
		ResourceHelper.joinIndexerBeforeCleanup(getName());
		project.close(null);
		project.open(null);

		// Check the artifact name
		info = ManagedBuildManager.getBuildInfo(project);
		assertNotNull(info);
		managedProj = info.getManagedProject();
		assertNotNull(managedProj);
		defaultConfig = info.getDefaultConfiguration();
		assertNotNull(defaultConfig);
		assertEquals(name, defaultConfig.getArtifactName());
	}

	public void testThatAlwaysFails() {
		assertTrue(false);
	}

}

Back to the top