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

« back to all changes in this revision

Viewing changes to build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_335476.java

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2011 Broadcom Corporation and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *              Broadcom Corporation - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.managedbuilder.core.regressions;
 
12
 
 
13
import java.io.BufferedReader;
 
14
import java.io.InputStreamReader;
 
15
import java.util.regex.Matcher;
 
16
import java.util.regex.Pattern;
 
17
 
 
18
import org.eclipse.cdt.core.CCorePlugin;
 
19
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
 
20
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
 
21
import org.eclipse.cdt.managedbuilder.testplugin.AbstractBuilderTest;
 
22
import org.eclipse.core.resources.IFile;
 
23
import org.eclipse.core.resources.IProject;
 
24
import org.eclipse.core.resources.IResource;
 
25
import org.eclipse.core.resources.IncrementalProjectBuilder;
 
26
import org.eclipse.core.runtime.Path;
 
27
 
 
28
/**
 
29
 * This tests that an environment variable, which is part of the build
 
30
 * (in this case referenced by a -I), makes it through to makefile
 
31
 * correctly when it changes.
 
32
 */
 
33
public class Bug_335476 extends AbstractBuilderTest {
 
34
 
 
35
        private final String VAR_NAME = "INC";
 
36
        IProject app;
 
37
        IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
 
38
        ICdtVariableManager buildMacroManager = CCorePlugin.getDefault().getCdtVariableManager();
 
39
 
 
40
        @Override
 
41
        protected void setUp() throws Exception {
 
42
                super.setUp();
 
43
                setWorkspace("regressions");
 
44
                app = loadProject("bug_335476");
 
45
                // Ensure Debug is the active configuration
 
46
                setActiveConfigurationByName(app, "Debug");
 
47
        }
 
48
 
 
49
        /**
 
50
         * Build the project a few times, changing the value of the environment variable each time
 
51
         * @param build_kind
 
52
         * @throws Exception
 
53
         */
 
54
        public void runTest(int build_kind) throws Exception {
 
55
                // Environment containingg the "Lala" environment variable
 
56
                final IFile lala = app.getFile(new Path(".settings/org.eclipse.cdt.core.prefs.lala"));
 
57
                // Environment containing the "Foo" environment variable
 
58
                final IFile foo = app.getFile(new Path(".settings/org.eclipse.cdt.core.prefs.foo"));
 
59
 
 
60
                final IFile env = app.getFile(new Path(".settings/org.eclipse.cdt.core.prefs"));
 
61
 
 
62
                IFile current = foo;
 
63
                for (int i = 0; i < 5; i++) {
 
64
                        // Actual expected value
 
65
                        final String expected = current == foo ? "foo" : "lala";
 
66
                        // Update the environment to reflect the new value.
 
67
                        env.setContents(current.getContents(), IResource.NONE, null);
 
68
 
 
69
                        // Ask for a full build
 
70
                        app.build(build_kind, null);
 
71
 
 
72
                        // Check the makefile for the correct environment
 
73
                        IFile makefile = app.getFile("Debug/src/subdir.mk");
 
74
                        BufferedReader reader = new BufferedReader(new InputStreamReader(makefile.getContents()));
 
75
                        try {
 
76
                                Pattern p = Pattern.compile(".*?-I.*?\"(.*?)\".*");
 
77
                                boolean found = false;
 
78
                                while (reader.ready()) {
 
79
                                        String line = reader.readLine();
 
80
                                        if (!line.contains("gcc"))
 
81
                                                continue;
 
82
                                        Matcher m = p.matcher(line);
 
83
                                        assertTrue(m.matches());
 
84
                                        String buildVar = m.group(1);
 
85
 
 
86
                                        // Check that the Environment manager + the build manager have the variable
 
87
                                        //  (which tells us how far the variable has got through the system...)
 
88
                                        String value = envManager.getVariable(VAR_NAME, CCorePlugin.getDefault().getProjectDescription(app, false).getActiveConfiguration(), false).getValue();
 
89
                                        String value2 = buildMacroManager.resolveValue("${" + VAR_NAME + "}", "", ";", CCorePlugin.getDefault().getProjectDescription(app, false).getActiveConfiguration());
 
90
 
 
91
                                        assertTrue(i + " EnvManager "   + expected + " exepected, but was: " + value,    expected.equals(value));
 
92
                                        assertTrue(i + " CdtVarManager " + expected + " exepected, but was: " + value2,   expected.equals(value2));
 
93
                                        assertTrue(i + " Makefile: "    + expected + " exepected, but was: " + buildVar, expected.equals(buildVar));
 
94
                                        found = true;
 
95
                                }
 
96
                                // Check that we at least matched
 
97
                                assertTrue(found);
 
98
                        } finally {
 
99
                                reader.close();
 
100
                        }
 
101
 
 
102
                        // Change environment
 
103
                        if (current == lala)
 
104
                                current = foo;
 
105
                        else
 
106
                                current = lala;
 
107
                }
 
108
        }
 
109
 
 
110
        public void testChangingEnvironmentBuildSystem_FULL_BUILD() throws Exception {
 
111
                runTest(IncrementalProjectBuilder.FULL_BUILD);
 
112
        }
 
113
 
 
114
        public void testChangingEnvironmentBuildSystem_INC_BUILD() throws Exception {
 
115
                runTest(IncrementalProjectBuilder.INCREMENTAL_BUILD);
 
116
        }
 
117
 
 
118
}