Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 398ac110b3334a6956dd7cbb5d0c40fcb29cc191 (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
/*******************************************************************************
 * Copyright (c) 2002, 2012 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 Rational Software - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.model.tests;

import java.io.FileInputStream;

import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;

import junit.framework.TestCase;

/**
 * @author jcamelon
 *
 */
public class TranslationUnitBaseTest extends TestCase {
	/**
	 *
	 */
	public TranslationUnitBaseTest() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param name
	 */
	public TranslationUnitBaseTest(String name) {
		super(name);
		// TODO Auto-generated constructor stub
	}

	protected IWorkspace workspace;
	protected IWorkspaceRoot root;
	protected ICProject testProject;
	protected IFile objfile;
	protected IFile archfile;
	protected IFile libfile;
	protected IFile exefile;
	protected IFile cfile;
	protected Path objpath;
	protected Path archpath;
	protected Path libpath;
	protected Path exepath;
	protected Path cpath;
	protected NullProgressMonitor monitor;

	/**
	     * Sets up the test fixture.
	     *
	     * Called before every test case method.
	     *
	     * Example code test the packages in the project
	     *  "com.qnx.tools.ide.cdt.core"
	     */
	@Override
	protected void setUp() throws Exception {
		/***
		 * The rest of the tests assume that they have a working workspace
		 * and workspace root object to use to create projects/files in,
		 * so we need to get them setup first.
		 */
		IWorkspaceDescription desc;
		workspace = ResourcesPlugin.getWorkspace();
		root = workspace.getRoot();
		monitor = new NullProgressMonitor();
		if (workspace == null)
			fail("Workspace was not setup");
		if (root == null)
			fail("Workspace root was not setup");

		desc = workspace.getDescription();
		desc.setAutoBuilding(false);
		workspace.setDescription(desc);

		/***
		 * Setup the various files, paths and projects that are needed by the
		 * tests
		 */

		testProject = CProjectHelper.createCProject("filetest", "none", IPDOMManager.ID_NO_INDEXER);
		if (testProject == null)
			fail("Unable to create project");

		cfile = testProject.getProject().getFile("exetest.c");
		if (!cfile.exists()) {
			cfile.create(
					new FileInputStream(
							CTestPlugin.getDefault().getFileInPlugin(new Path("resources/cfiles/TranslationUnits.c"))),
					false, monitor);
		}
		cpath = new Path(workspace.getRoot().getLocation() + "/filetest/main.c");

		objfile = testProject.getProject().getFile("exetest.o");
		if (!objfile.exists()) {
			objfile.create(
					new FileInputStream(
							CTestPlugin.getDefault().getFileInPlugin(new Path("resources/exe/x86/o.g/main.o"))),
					false, monitor);
		}
		objpath = new Path(workspace.getRoot().getLocation() + "/filetest/main.o");

		exefile = testProject.getProject().getFile("test_g");
		if (!exefile.exists()) {
			exefile.create(
					new FileInputStream(
							CTestPlugin.getDefault().getFileInPlugin(new Path("resources/exe/x86/o.g/exe_g"))),
					false, monitor);
		}
		exepath = new Path(workspace.getRoot().getLocation() + "/filetest/exe_g");

		archfile = testProject.getProject().getFile("libtestlib_g.a");
		if (!archfile.exists()) {
			archfile.create(new FileInputStream(
					CTestPlugin.getDefault().getFileInPlugin(new Path("resources/testlib/x86/a.g/libtestlib_g.a"))),
					false, monitor);
		}
		libpath = new Path(workspace.getRoot().getLocation() + "/filetest/libtestlib_g.so");

		libfile = testProject.getProject().getFile("libtestlib_g.so");
		if (!libfile.exists()) {
			libfile.create(new FileInputStream(
					CTestPlugin.getDefault().getFileInPlugin(new Path("resources/testlib/x86/so.g/libtestlib_g.so"))),
					false, monitor);
		}
		archpath = new Path(workspace.getRoot().getLocation() + "/filetest/libtestlib_g.a");
	}

	/**
	     * Tears down the test fixture.
	     *
	     * Called after every test case method.
	     */
	@Override
	protected void tearDown() {
		// release resources here and clean-up
		try {
			testProject.getProject().delete(true, true, monitor);
		} catch (CoreException e) {
		}
	}
}

Back to the top