Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 317bc27071f9961e1f68b9f4f3daafaad517e36c (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
/*******************************************************************************
 * Copyright (c) 2007, 2011 Intel 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:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.make.builder.tests;

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

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
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.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

public class CDataProviderTests extends TestCase {
	/**
	 * @param name
	 */
	public CDataProviderTests(String name) {
		super(name);
	}

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

		//		// Add the relevant tests to the suite
		//		suite.addTest(new StandardBuildTests("testProjectCreation"));
		//		suite.addTest(new StandardBuildTests("testProjectSettings"));
		//		suite.addTest(new StandardBuildTests("testProjectConversion"));
		//		suite.addTest(new StandardBuildTests("testProjectCleanup"));
		//
		//		suite.addTestSuite(ScannerConfigConsoleParserTests.class);
		//		suite.addTestSuite(ScannerConfigDiscoveryTests.class);

		return suite;
	}

	public void testCData() throws Exception {
		IProject project = createProject("a1");
		ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
		assertNotNull("project description should not be null", projDes);

		ICConfigurationDescription cfgs[] = projDes.getConfigurations();
		assertEquals(1, cfgs.length);

		int lssNum = cfgs[0].getRootFolderDescription().getLanguageSettings().length;
		int rcDessNum = cfgs[0].getResourceDescriptions().length;
		assertTrue(rcDessNum > 0);
		ICConfigurationDescription cfg2 = projDes.createConfiguration("aasasa", "cfg2", cfgs[0]);
		assertNotNull(cfg2);
		assertEquals(2, projDes.getConfigurations().length);
		assertEquals(lssNum, cfg2.getRootFolderDescription().getLanguageSettings().length);
		assertEquals(rcDessNum, cfg2.getResourceDescriptions().length);

		CCorePlugin.getDefault().setProjectDescription(project, projDes);

		projDes = CCorePlugin.getDefault().getProjectDescription(project);
		assertEquals(2, projDes.getConfigurations().length);
		cfgs = projDes.getConfigurations();
		assertEquals(2, cfgs.length);
		cfg2 = cfgs[0];
		assertNotNull(cfg2);
		assertEquals(2, projDes.getConfigurations().length);
		assertEquals(lssNum, cfg2.getRootFolderDescription().getLanguageSettings().length);
		assertEquals(rcDessNum, cfg2.getResourceDescriptions().length);

		projDes = CCorePlugin.getDefault().getProjectDescription(project, false);
		assertEquals(2, projDes.getConfigurations().length);
		cfgs = projDes.getConfigurations();
		assertEquals(2, cfgs.length);
		cfg2 = cfgs[0];
		assertNotNull(cfg2);
		assertEquals(2, projDes.getConfigurations().length);
		assertEquals(lssNum, cfg2.getRootFolderDescription().getLanguageSettings().length);
		assertEquals(rcDessNum, cfg2.getResourceDescriptions().length);

		project.delete(false, true, new NullProgressMonitor());

		project = ResourcesPlugin.getWorkspace().getRoot().getProject("a1");
		project.create(new NullProgressMonitor());
		project.open(new NullProgressMonitor());

		projDes = CCorePlugin.getDefault().getProjectDescription(project);
		assertNotNull("project description should not be null", projDes);

		cfgs = projDes.getConfigurations();
		assertEquals(2, cfgs.length);
		cfg2 = cfgs[0];
		assertNotNull(cfg2);
		assertEquals(2, projDes.getConfigurations().length);
		assertEquals(lssNum, cfg2.getRootFolderDescription().getLanguageSettings().length);
		assertEquals(rcDessNum, cfg2.getResourceDescriptions().length);

		cfg2 = cfgs[1];
		assertNotNull(cfg2);
		assertEquals(2, projDes.getConfigurations().length);
		assertEquals(lssNum, cfg2.getRootFolderDescription().getLanguageSettings().length);
		assertEquals(rcDessNum, cfg2.getResourceDescriptions().length);
	}

	private IProject createProject(final String name) throws CoreException {
		final Object[] result = new Object[1];
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {

			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
				IProject project = root.getProject(name);
				IProjectDescription description = null;

				if (!project.exists()) {
					project.create(null);
				} else {
					project.refreshLocal(IResource.DEPTH_INFINITE, null);
				}

				if (!project.isOpen()) {
					project.open(null);
				}

				description = project.getDescription();
				//				ICommand[] commands = description.getBuildSpec();
				//				for (int i = 0; i < commands.length; ++i) {
				//					if (commands[i].getBuilderName().equals(ScannerConfigBuilder.BUILDER_ID)) {
				//						return;
				//					}
				//				}
				//				ICommand command = description.newCommand();
				//				command.setBuilderName(ScannerConfigBuilder.BUILDER_ID);
				//				ICommand[] newCommands = new ICommand[commands.length + 1];
				//				System.arraycopy(commands, 0, newCommands, 0, commands.length);
				//				newCommands[commands.length] = command;
				//				description.setBuildSpec(newCommands);
				//				project.setDescription(description, null);

				CCorePlugin.getDefault().createCDTProject(description, project, MakeCorePlugin.CFG_DATA_PROVIDER_ID,
						new NullProgressMonitor());
				result[0] = project;
			}
		}, null);
		return (IProject) result[0];
	}
}

Back to the top