Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5a2031e61a0ccfaf744ab8ff54fac8138ac72990 (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
/*******************************************************************************
 * Copyright (c) 2005, 2007 Intel Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.projectmodel.tests;

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

import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
/**
 * Creates a project in a loop and checks that it is created with appropriate number
 * of build configurations
 *
 */
public class CProjectDescriptionSerializationTests extends TestCase {
	/**
	 * @return Test
	 */
	public static Test suite() {
		return new TestSuite(CProjectDescriptionSerializationTests.class);
	}

	@Override
	protected void setUp() throws Exception {
	}

	@Override
	protected void tearDown() throws Exception {
	}

	/**
	 * This test is intended to test serialization of C++ project
	 * @throws Exception
	 */
	public void testTooManyConfigurations() throws Exception {
		String projectName = "testTooManyConfigurations";
		String pluginProjectTypeId = "cdt.managedbuild.target.gnu.cygwin.exe";

		CoreModel coreModel = CoreModel.getDefault();
		
		{
			// Create model project and accompanied descriptions
			IProject project = BuildSystemTestHelper.createProject(projectName);
			ICProjectDescription des = coreModel.createProjectDescription(project, false);
			Assert.assertNotNull("createDescription returned null!", des);

			{
				ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
				IProjectType type = ManagedBuildManager.getProjectType(pluginProjectTypeId);
				Assert.assertNotNull("project type not found", type);

				ManagedProject mProj = new ManagedProject(project, type);
				info.setManagedProject(mProj);

				IConfiguration cfgs[] = type.getConfigurations();
				Assert.assertNotNull("configurations not found", cfgs);
				Assert.assertTrue("no configurations found in the project type",cfgs.length>0);

				for (IConfiguration configuration : cfgs) {
					String id = ManagedBuildManager.calculateChildId(configuration.getId(), null);
					Configuration config = new Configuration(mProj, (Configuration)configuration, id, false, true, false);
					CConfigurationData data = config.getConfigurationData();
					Assert.assertNotNull("data is null for created configuration", data);
					ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
				}
				Assert.assertEquals(2, des.getConfigurations().length);
			}

			// Persist the project
			coreModel.setProjectDescription(project, des);
			project.close(null);
		}


		{
			IWorkspace workspace = ResourcesPlugin.getWorkspace();
			IWorkspaceRoot root = workspace.getRoot();

			IWorkspaceDescription workspaceDesc = workspace.getDescription();
			workspaceDesc.setAutoBuilding(false);
			workspace.setDescription(workspaceDesc);

			// Trying to induce an anomaly
			for (int i=0;i<144;i++)
			{
				// Open project
				IProject project = root.getProject(projectName);
				project.open(null);
				Assert.assertEquals(true, project.isOpen());

				// Check project description
				ICProjectDescription des = coreModel.getProjectDescription(project);
				Assert.assertEquals(2, des.getConfigurations().length);

				IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
				// once in a while managedProject.getConfigurations() can return null
				// inside buildInfo.getConfigurationNames() which results in NPE
				String[] configurationNames = buildInfo.getConfigurationNames();
				// this Assert triggers as well on occasion
				Assert.assertNotNull("buildInfo.getConfigurationNames() returned null", configurationNames);

				IConfiguration configurations[] = buildInfo.getManagedProject().getConfigurations();
				// this condition is not supposed to be true
				// since the project is supposed to have exactly 2 configurations
				if (configurations.length != 2) {
					String message = i + "-th round: Invalid number (not 2) of configurations loaded. ";
					for (IConfiguration configuration : configurations) {
						message = message + "["+configuration.getName()+"], ";
					}
					Assert.assertEquals(message, 2, configurations.length);
				}

				project.close(null);
			}
		}
	}
}

Back to the top