Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1f7679c77e44272fbeb88c1b478fbb69dd6a033a (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
/*******************************************************************************
 *  Copyright (c) 2017 Simeon Andreev 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:
 *     Simeon Andreev - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.preferences.tests;

import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.resources.ACBuilder;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;

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

/**
 * Test case for Bug 529023: Cannot set build.proj.ref.configs.enabled via
 * plugin_customization.ini.
 *
 * @author Simeon Andreev
 */
public class TestScopeOfBuildConfigResourceChangesPreference extends TestCase {

	private static final String PREFERENCE_NAME = CCorePreferenceConstants.PREF_BUILD_CONFIGS_RESOURCE_CHANGES;

	private boolean oldInstanceScopeValue;
	private boolean oldDefaultScopeValue;

    public static Test suite() {
        return new TestSuite(TestScopeOfBuildConfigResourceChangesPreference.class);
    }

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		oldInstanceScopeValue = ACBuilder.buildConfigResourceChanges();
		IEclipsePreferences defaultScopePreferences = defaultScopePreferences();
		oldDefaultScopeValue = defaultScopePreferences.getBoolean(PREFERENCE_NAME, oldInstanceScopeValue);
	}

	@Override
	protected void tearDown() throws Exception {
		ACBuilder.setBuildConfigResourceChanges(oldInstanceScopeValue);
		IEclipsePreferences defaultScopePreferences = defaultScopePreferences();
		defaultScopePreferences.putBoolean(PREFERENCE_NAME, oldDefaultScopeValue);

		super.tearDown();
	}

	private static IEclipsePreferences defaultScopePreferences() {
		return DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
	}

	/**
	 * Validates that {@link ACBuilder#buildConfigResourceChanges()} also takes
	 * {@link DefaultScope} into account.
	 */
	public void testSettingPreferenceViaDefaultScope() throws Exception {
		IEclipsePreferences defaultScopePreferences = defaultScopePreferences();
		defaultScopePreferences.putBoolean(PREFERENCE_NAME, true);

		boolean buildConfigResourceChanges = ACBuilder.buildConfigResourceChanges();
		assertTrue("unable to set preference \"" + PREFERENCE_NAME + "\" via default scope",
				buildConfigResourceChanges);
	}
}

Back to the top