View | Details | Raw Unified | Return to bug 82195 | Differences between
and this patch

Collapse All | Expand All

(-)build.properties (+7 lines)
Lines 3-5 Link Here
3
bin.includes = plugin.xml,\
3
bin.includes = plugin.xml,\
4
               tests.jar,\
4
               tests.jar,\
5
               resources/
5
               resources/
6
src.includes = .classpath,\
7
               .project,\
8
               ChangeLog,\
9
               build.properties,\
10
               plugin.xml,\
11
               resources/,\
12
               src/
(-)plugin.xml (-1 lines)
Lines 16-22 Link Here
16
   <requires>
16
   <requires>
17
      <import plugin="org.eclipse.ui"/>
17
      <import plugin="org.eclipse.ui"/>
18
      <import plugin="org.eclipse.core.runtime"/>
18
      <import plugin="org.eclipse.core.runtime"/>
19
      <import plugin="org.eclipse.cdt.core"/>
20
      <import plugin="org.eclipse.cdt.rpm.core"/>
19
      <import plugin="org.eclipse.cdt.rpm.core"/>
21
      <import plugin="org.eclipse.core.resources"/>
20
      <import plugin="org.eclipse.core.resources"/>
22
      <import plugin="org.junit"/>
21
      <import plugin="org.junit"/>
(-)src/org/eclipse/cdt/rpm/core/tests/AllTests.java (-1 / +4 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * (c) 2004 Red Hat, Inc.
2
 * (c) 2004, 2005 Red Hat, Inc.
3
 *
3
 *
4
 * This program is open source software licensed under the 
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
5
 * Eclipse Public License ver. 1
Lines 7-12 Link Here
7
package org.eclipse.cdt.rpm.core.tests;
7
package org.eclipse.cdt.rpm.core.tests;
8
8
9
9
10
import org.eclipse.cdt.rpm.core.internal.tests.RPMCoreInternalTestSuite;
11
10
import junit.framework.Test;
12
import junit.framework.Test;
11
import junit.framework.TestSuite;
13
import junit.framework.TestSuite;
12
14
Lines 15-20 Link Here
15
	public static Test suite() {
17
	public static Test suite() {
16
		TestSuite suite = new TestSuite("Test for org.eclipse.cdt.rpm.core.tests");
18
		TestSuite suite = new TestSuite("Test for org.eclipse.cdt.rpm.core.tests");
17
		//$JUnit-BEGIN$
19
		//$JUnit-BEGIN$
20
		suite.addTest(RPMCoreInternalTestSuite.suite());
18
		suite.addTest(RPMCoreTestSuite.suite());
21
		suite.addTest(RPMCoreTestSuite.suite());
19
		//$JUnit-END$
22
		//$JUnit-END$
20
		return suite;
23
		return suite;
(-)src/org/eclipse/cdt/rpm/core/tests/CProjectHelper.java (-260 lines)
Removed Link Here
1
package org.eclipse.cdt.rpm.core.tests;
2
3
import junit.framework.Assert;
4
5
import org.eclipse.cdt.core.CCProjectNature;
6
import org.eclipse.cdt.core.CCorePlugin;
7
import org.eclipse.cdt.core.CProjectNature;
8
import org.eclipse.cdt.core.model.CModelException;
9
import org.eclipse.cdt.core.model.CoreModel;
10
import org.eclipse.cdt.core.model.IArchive;
11
import org.eclipse.cdt.core.model.IArchiveContainer;
12
import org.eclipse.cdt.core.model.IBinary;
13
import org.eclipse.cdt.core.model.IBinaryContainer;
14
import org.eclipse.cdt.core.model.ICContainer;
15
import org.eclipse.cdt.core.model.ICElement;
16
import org.eclipse.cdt.core.model.ICProject;
17
import org.eclipse.cdt.core.model.ISourceRoot;
18
import org.eclipse.cdt.core.model.ITranslationUnit;
19
import org.eclipse.core.resources.IFolder;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IProjectDescription;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.IWorkspace;
24
import org.eclipse.core.resources.IWorkspaceRoot;
25
import org.eclipse.core.resources.IWorkspaceRunnable;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IProgressMonitor;
29
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.ui.dialogs.IOverwriteQuery;
31
32
/**
33
 * Helper methods to set up a ICProject.
34
 */
35
public class CProjectHelper {
36
37
	/**
38
	 * Creates a ICProject.
39
	 */
40
	public static ICProject createCProject(final String projectName, String binFolderName) throws CoreException {
41
		final IWorkspace ws = ResourcesPlugin.getWorkspace();
42
		final IProject newProject[] = new IProject[1];
43
		ws.run(new IWorkspaceRunnable() {
44
45
			public void run(IProgressMonitor monitor) throws CoreException {
46
				IWorkspaceRoot root = ws.getRoot();
47
				IProject project = root.getProject(projectName);
48
				if (!project.exists()) {
49
					project.create(null);
50
				} else {
51
					project.refreshLocal(IResource.DEPTH_INFINITE, null);
52
				}
53
				if (!project.isOpen()) {
54
					project.open(null);
55
				}
56
				if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
57
					String projectId = "TestProject";
58
					addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
59
					CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
60
				}
61
				newProject[0] = project;
62
			}
63
		}, null);
64
65
		return CCorePlugin.getDefault().getCoreModel().create(newProject[0]);
66
	}
67
	
68
	private static String getMessage(IStatus status) {
69
		StringBuffer message = new StringBuffer("[");
70
		message.append(status.getMessage());
71
		if (status.isMultiStatus()) {
72
			IStatus children[] = status.getChildren();
73
			for( int i = 0; i < children.length; i++) {
74
				message.append(getMessage(children[i]));
75
			}
76
		}
77
		message.append("]");
78
		return message.toString();
79
	}
80
81
	public static ICProject createCCProject(final String projectName, final String binFolderName) throws CoreException {
82
		final IWorkspace ws = ResourcesPlugin.getWorkspace();
83
		final ICProject newProject[] = new ICProject[1];
84
		ws.run(new IWorkspaceRunnable() {
85
86
			public void run(IProgressMonitor monitor) throws CoreException {
87
				ICProject cproject = createCProject(projectName, binFolderName);
88
				if (!cproject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) {
89
					addNatureToProject(cproject.getProject(), CCProjectNature.CC_NATURE_ID, null);
90
				}
91
				newProject[0] = cproject;
92
			}
93
		}, null);
94
		return newProject[0];
95
	}
96
97
	/**
98
	 * Removes a ICProject.
99
	 */
100
	public static void delete(ICProject cproject) {
101
		try {
102
			cproject.getProject().delete(true, true, null);
103
		} catch (CoreException e) {
104
			try {
105
				Thread.sleep(1000);
106
			} catch (InterruptedException e1) {
107
			} finally {
108
				try {
109
					System.gc();
110
					System.runFinalization();
111
					cproject.getProject().delete(true, true, null);
112
				} catch (CoreException e2) {
113
					Assert.fail(getMessage(e2.getStatus()));
114
				}
115
			}
116
		}
117
	}
118
119
	/**
120
	 * Adds a folder container to a ICProject.
121
	 */
122
	public static ICContainer addCContainer(ICProject cproject, String containerName) throws CoreException {
123
		IProject project = cproject.getProject();
124
		ICContainer container = null;
125
		if (containerName == null || containerName.length() == 0) {
126
			ICContainer[] conts = cproject.getSourceRoots();
127
			if (conts.length > 0) {
128
				container = conts[0];
129
			}
130
		} else {
131
			IFolder folder = project.getFolder(containerName);
132
			if (!folder.exists()) {
133
				folder.create(false, true, null);
134
			}
135
			container = CoreModel.getDefault().create(folder);
136
		}
137
		return container;
138
	}
139
140
141
	/**
142
	 * Removes a folder from a ICProject.
143
	 */
144
	public static void removeCContainer(ICProject cproject, String containerName) throws CoreException {
145
		IFolder folder = cproject.getProject().getFolder(containerName);
146
		folder.delete(true, null);
147
	}
148
149
	/**
150
	 * Attempts to find an archive with the given name in the workspace
151
	 */
152
	public static IArchive findArchive(ICProject testProject, String name) throws CModelException {
153
		int x;
154
		IArchive[] myArchives;
155
		IArchiveContainer archCont;
156
		/***************************************************************************************************************************
157
		 * Since ArchiveContainer.getArchives does not wait until all the archives in the project have been parsed before returning
158
		 * the list, we have to do a sync ArchiveContainer.getChildren first to make sure we find all the archives.
159
		 */
160
		archCont = testProject.getArchiveContainer();
161
		myArchives = archCont.getArchives();
162
		if (myArchives.length < 1)
163
			return (null);
164
		for (x = 0; x < myArchives.length; x++) {
165
			if (myArchives[x].getElementName().equals(name))
166
				return (myArchives[x]);
167
		}
168
		return (null);
169
	}
170
171
	/**
172
	 * Attempts to find a binary with the given name in the workspace
173
	 */
174
	public static IBinary findBinary(ICProject testProject, String name) throws CModelException {
175
		IBinaryContainer binCont;
176
		int x;
177
		IBinary[] myBinaries;
178
		binCont = testProject.getBinaryContainer();
179
		myBinaries = binCont.getBinaries();
180
		if (myBinaries.length < 1)
181
			return (null);
182
		for (x = 0; x < myBinaries.length; x++) {
183
			if (myBinaries[x].getElementName().equals(name))
184
				return (myBinaries[x]);
185
		}
186
		return (null);
187
	}
188
189
	/**
190
	 * Attempts to find an object with the given name in the workspace
191
	 */
192
	public static IBinary findObject(ICProject testProject, String name) throws CModelException {
193
		ICElement[] sourceRoots = testProject.getChildren();
194
		for (int i = 0; i < sourceRoots.length; i++) {
195
			ISourceRoot root = (ISourceRoot) sourceRoots[i];
196
			ICElement[] myElements = root.getChildren();
197
			for (int x = 0; x < myElements.length; x++) {
198
				if (myElements[x].getElementName().equals(name)) {
199
					if (myElements[x] instanceof IBinary) {
200
						return ((IBinary) myElements[x]);
201
					}
202
				}
203
			}
204
		}
205
		return null;
206
	}
207
208
	/**
209
	 * Attempts to find a TranslationUnit with the given name in the workspace
210
	 */
211
	public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) throws CModelException {
212
		ICElement[] sourceRoots = testProject.getChildren();
213
		for (int i = 0; i < sourceRoots.length; i++) {
214
			ISourceRoot root = (ISourceRoot) sourceRoots[i];
215
			ICElement[] myElements = root.getChildren();
216
			for (int x = 0; x < myElements.length; x++) {
217
				if (myElements[x].getElementName().equals(name)) {
218
					if (myElements[x] instanceof ITranslationUnit) {
219
						return ((ITranslationUnit) myElements[x]);
220
					}
221
				}
222
			}
223
		}
224
		return null;
225
	}
226
227
	/**
228
	 * Attempts to find an element with the given name in the workspace
229
	 */
230
	public static ICElement findElement(ICProject testProject, String name) throws CModelException {
231
		ICElement[] sourceRoots = testProject.getChildren();
232
		for (int i = 0; i < sourceRoots.length; i++) {
233
			ISourceRoot root = (ISourceRoot) sourceRoots[i];
234
			ICElement[] myElements = root.getChildren();
235
			for (int x = 0; x < myElements.length; x++) {
236
				if (myElements[x].getElementName().equals(name)) {
237
					return myElements[x];
238
				}
239
			}
240
		}
241
		return null;
242
	}
243
244
	private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
245
		IProjectDescription description = proj.getDescription();
246
		String[] prevNatures = description.getNatureIds();
247
		String[] newNatures = new String[prevNatures.length + 1];
248
		System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
249
		newNatures[prevNatures.length] = natureId;
250
		description.setNatureIds(newNatures);
251
		proj.setDescription(description, monitor);
252
	}
253
254
	private static class ImportOverwriteQuery implements IOverwriteQuery {
255
256
		public String queryOverwrite(String file) {
257
			return ALL;
258
		}
259
	}
260
}
(-)src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestSuite.java (-4 / +3 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * (c) 2004 Red Hat, Inc.
2
 * (c) 2004, 2005 Red Hat, Inc.
3
 *
3
 *
4
 * This program is open source software licensed under the 
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
5
 * Eclipse Public License ver. 1
Lines 15-23 Link Here
15
		TestSuite suite = new TestSuite(
15
		TestSuite suite = new TestSuite(
16
				"Test for org.eclipse.cdt.rpm.core.tests");
16
				"Test for org.eclipse.cdt.rpm.core.tests");
17
		//$JUnit-BEGIN$
17
		//$JUnit-BEGIN$
18
		suite.addTest(RPMExportTests.suite());
18
		suite.addTestSuite(RPMProjectNatureTest.class);
19
		suite.addTest(SRPMImportTests.suite());
19
		suite.addTestSuite(RPMProjectFactoryTest.class);
20
		suite.addTest(SRPMExportTests.suite());
21
		//$JUnit-END$
20
		//$JUnit-END$
22
		return suite;
21
		return suite;
23
	}
22
	}
(-)src/org/eclipse/cdt/rpm/core/tests/RPMCoreTestsPlugin.java (-1 / +1 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * (c) 2004 Red Hat, Inc.
2
 * (c) 2004, 2005 Red Hat, Inc.
3
 *
3
 *
4
 * This program is open source software licensed under the 
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
5
 * Eclipse Public License ver. 1
(-)src/org/eclipse/cdt/rpm/core/tests/RPMExportTests.java (-131 lines)
Removed Link Here
1
/*
2
 * (c) 2004 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.tests;
8
9
import java.io.File;
10
import java.io.FilenameFilter;
11
import java.io.IOException;
12
import java.net.URL;
13
14
import org.eclipse.cdt.core.model.ICProject;
15
import org.eclipse.cdt.rpm.core.RPMExport;
16
import org.eclipse.cdt.rpm.core.SRPMImport;
17
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.resources.IWorkspaceDescription;
19
import org.eclipse.core.resources.IWorkspaceRoot;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Platform;
25
26
import junit.framework.TestCase;
27
import junit.framework.TestSuite;
28
29
30
/**
31
 * @author Jeremy Handcock <handcock@redhat.com>
32
 * 
33
 * This class tests the RPM plug-in's core SRPM import operation
34
 */
35
public class RPMExportTests extends TestCase {
36
	IWorkspace workspace;
37
	IWorkspaceRoot root;
38
	NullProgressMonitor monitor;
39
	String pluginRoot;
40
	static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
41
	
42
	/**
43
	 * Constructor for RPMExportTests.
44
	 * @param name
45
	 */
46
	public RPMExportTests(String name) {
47
		super(name);
48
	}
49
	
50
	/*
51
	 * @see TestCase#setUp()
52
	 */
53
	protected void setUp() throws Exception {
54
		IWorkspaceDescription desc;
55
		workspace = ResourcesPlugin.getWorkspace();
56
		root = workspace.getRoot();
57
		monitor = new NullProgressMonitor();
58
		if(workspace == null) {
59
			fail("Workspace was not setup");
60
		}
61
		if(root == null) {
62
			fail("Workspace root was not setup");
63
		}
64
		desc = workspace.getDescription();
65
		desc.setAutoBuilding(false);
66
		workspace.setDescription(desc);
67
	}
68
	
69
	public static TestSuite suite() {
70
		return new TestSuite(RPMExportTests.class);
71
	}
72
	
73
	public void testHelloWorldRPMExport() throws CoreException, IOException {
74
		/* Create C project to use during the test */
75
		RPMExportTester("helloworld", "2", "2");
76
	}
77
	
78
	private void RPMExportTester(String name, String version, String release) 
79
		throws CoreException, IOException {
80
		
81
		/* Create C project to use during the test */
82
		ICProject testProject = CProjectHelper.createCProject(name, "none"); //$NON-NLS-1$ //$NON-NLS-2$
83
		if(testProject == null) {
84
			fail("Unable to create project");
85
		}
86
		
87
		URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + 
88
				file_sep + name+"-"+version+"-"+release+".src.rpm"));
89
		if (url == null)
90
			fail("Unable to find resources" + file_sep + "srpms" + file_sep +
91
				name+"-"+version+"-"+release+".src.rpm");
92
		
93
		SRPMImport SRPMImport = new SRPMImport(testProject.getProject().getLocation().
94
				toOSString(), Platform.asLocalURL(url).getPath());
95
		SRPMImport.setDoAutoconf(true);
96
		SRPMImport.setDoPatches(true);
97
		SRPMImport.run();
98
		
99
		/* Export the SRPM */
100
		RPMExport rpmExport = new RPMExport(testProject.getProject().getLocation().toOSString());
101
		// set the various properties for an RPM export
102
		
103
		rpmExport.setUi_ver_no(version);
104
		rpmExport.setUi_rel_no(release);
105
		rpmExport.setUi_spec_file("");
106
		
107
		rpmExport.run();
108
		
109
		File f = new File(testProject.getProject().getLocation().toOSString());
110
		FilenameFilter rpms = new FilenameFilter() {
111
			public boolean accept(File dir, String name) {
112
				return (name.endsWith(".rpm") && !name.endsWith("src.rpm"));
113
			}
114
		};
115
			
116
		String[] files = f.list(rpms);
117
		assertTrue("source rpms were not generated", files != null); //$NON-NLS-1$
118
		
119
		
120
		/* Clean up */
121
		testProject.getProject().delete(true, true, monitor);
122
	}
123
	
124
	/*
125
	 * @see TestCase#tearDown()
126
	 */
127
	protected void tearDown() throws Exception {
128
		super.tearDown();
129
	}
130
	
131
}
(-)src/org/eclipse/cdt/rpm/core/tests/SRPMExportTests.java (-145 lines)
Removed Link Here
1
/*
2
 * (c) 2004 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.tests;
8
9
import java.io.File;
10
import java.io.FilenameFilter;
11
import java.io.IOException;
12
import java.net.URL;
13
14
import org.eclipse.cdt.core.model.ICProject;
15
import org.eclipse.cdt.rpm.core.SRPMExport;
16
import org.eclipse.cdt.rpm.core.SRPMImport;
17
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.resources.IWorkspaceDescription;
19
import org.eclipse.core.resources.IWorkspaceRoot;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.Platform;
25
26
import junit.framework.TestCase;
27
import junit.framework.TestSuite;
28
29
/**
30
 * @author Jeremy Handcock <handcock@redhat.com>
31
 * 
32
 * This class tests the RPM plug-in's core SRPM import operation
33
 */
34
public class SRPMExportTests extends TestCase {
35
	IWorkspace workspace;
36
	IWorkspaceRoot root;
37
	NullProgressMonitor monitor;
38
	String pluginRoot;
39
	static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
40
	
41
	/**
42
	 * Constructor for SRPMExportTests.
43
	 * @param name
44
	 */
45
	public SRPMExportTests(String name) {
46
		super(name);
47
	}
48
49
	/*
50
	 * @see TestCase#setUp()
51
	 */
52
	protected void setUp() throws Exception {
53
		IWorkspaceDescription desc;
54
		workspace = ResourcesPlugin.getWorkspace();
55
		root = workspace.getRoot();
56
		monitor = new NullProgressMonitor();
57
		if(workspace == null) {
58
			fail("Workspace was not setup");
59
		}
60
		if(root == null) {
61
			fail("Workspace root was not setup");
62
		}
63
		desc = workspace.getDescription();
64
		desc.setAutoBuilding(false);
65
		workspace.setDescription(desc);
66
	}
67
	
68
	public static TestSuite suite() {
69
		return new TestSuite(SRPMExportTests.class);
70
	}
71
72
	public void testHelloWorldSRPMExport() throws CoreException, IOException {
73
		/* Create C project to use during the test */
74
		SRPMExportTester("helloworld", "2", "2");
75
	}
76
	
77
	private void SRPMExportTester(String name, String version, String release) 
78
		throws CoreException, IOException {
79
		
80
		/* Create C project to use during the test */
81
		ICProject testProject = CProjectHelper.createCProject(name, "none"); //$NON-NLS-1$ //$NON-NLS-2$
82
		if(testProject == null) {
83
			fail("Unable to create project");
84
		}
85
		
86
		URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
87
				name+"-"+version+"-"+release+".src.rpm"));
88
		if (url == null)
89
			fail("Unable to find resources" + file_sep + "srpms" + file_sep +
90
				name+"-"+version+"-"+release+".src.rpm");
91
92
		SRPMImport SRPMImport;
93
		SRPMImport = new SRPMImport(testProject.getProject().getLocation().
94
				toOSString(), Platform.asLocalURL(url).getPath());
95
		SRPMImport.setDoAutoconf(true);
96
		SRPMImport.setDoPatches(true);
97
		SRPMImport.run();
98
		/* Make sure the import was successful */
99
		File f = new File(testProject.getProject().getLocation().toOSString() + 
100
				file_sep + ".srpminfo"); //$NON-NLS-1$
101
		f.delete();
102
		f = new File(testProject.getProject().getLocation().toOSString() + 
103
				file_sep + "eclipse_"+name+".spec"); //$NON-NLS-1$
104
		f.delete();
105
		f = new File(testProject.getProject().getLocation().toOSString() + 
106
				file_sep + name+"-"+version+"-"+release+".src.rpm"); //$NON-NLS-1$
107
		f.delete();
108
		
109
		/* Export the SRPM */
110
		SRPMExport srpmExport = new SRPMExport(testProject.getProject().getLocation().toOSString());
111
		// set the various properties of an RPM export
112
		
113
		srpmExport.setChangelog_entry(""/** Tue Sep 14 2004 -- aluchko <aluchko@redhat.com>"*/);
114
		srpmExport.setPatch_tag("");
115
		
116
		
117
		
118
		srpmExport.setUi_ver_no(version);
119
		srpmExport.setUi_rel_no(release);
120
		srpmExport.setUi_spec_file("");
121
		
122
		
123
		srpmExport.run();
124
		
125
		f = new File(testProject.getProject().getLocation().toOSString());
126
		FilenameFilter rpms = new FilenameFilter() {
127
			public boolean accept(File dir, String name) {
128
				return (name.endsWith("src.rpm"));
129
			}
130
		};
131
		String[] files = f.list(rpms);
132
		assertTrue("source rpms were not generated", files != null); //$NON-NLS-1$
133
		
134
		/* Clean up */
135
		testProject.getProject().delete(true, true, monitor);
136
	}
137
138
	/*
139
	 * @see TestCase#tearDown()
140
	 */
141
	protected void tearDown() throws Exception {
142
		super.tearDown();
143
	}
144
145
}
(-)src/org/eclipse/cdt/rpm/core/tests/SRPMImportTests.java (-121 lines)
Removed Link Here
1
/*
2
 * (c) 2004 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.tests;
8
9
import java.io.File;
10
import java.io.IOException;
11
import java.net.URL;
12
13
import junit.framework.TestCase;
14
import junit.framework.TestSuite;
15
16
import org.eclipse.cdt.core.model.ICProject;
17
import org.eclipse.cdt.rpm.core.SRPMImport;
18
import org.eclipse.core.resources.IWorkspace;
19
import org.eclipse.core.resources.IWorkspaceDescription;
20
import org.eclipse.core.resources.IWorkspaceRoot;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.NullProgressMonitor;
24
import org.eclipse.core.runtime.Path;
25
import org.eclipse.core.runtime.Platform;
26
27
/**
28
 * @author Jeremy Handcock <handcock@redhat.com>
29
 * 
30
 * This class tests the RPM plug-in's core SRPM import operation
31
 */
32
public class SRPMImportTests extends TestCase {
33
	IWorkspace workspace;
34
	IWorkspaceRoot root;
35
	NullProgressMonitor monitor;
36
	String pluginRoot;
37
	static final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
38
	
39
	/**
40
	 * Constructor for SRPMImportTests.
41
	 * @param name
42
	 */
43
	public SRPMImportTests(String name) {
44
		super(name);
45
	}
46
47
	/*
48
	 * @see TestCase#setUp()
49
	 */
50
	protected void setUp() throws Exception {
51
		IWorkspaceDescription desc;
52
		workspace = ResourcesPlugin.getWorkspace();
53
		root = workspace.getRoot();
54
		monitor = new NullProgressMonitor();
55
		if(workspace == null) {
56
			fail("Workspace was not setup");
57
		}
58
		if(root == null) {
59
			fail("Workspace root was not setup");
60
		}
61
		desc = workspace.getDescription();
62
		desc.setAutoBuilding(false);
63
		workspace.setDescription(desc);
64
	}
65
	
66
	public static TestSuite suite() {
67
		return new TestSuite(SRPMImportTests.class);
68
	}
69
70
	public void testHelloWorldSRPMImport() throws CoreException, IOException {
71
		/* Create C project to use during the test */
72
		SRPMImportTester("helloworld", "2-2");
73
	}
74
75
	private void SRPMImportTester(String name, String version) 
76
		throws CoreException, IOException {
77
78
		/* Create C project to use during the test */
79
		ICProject testProject = CProjectHelper.createCProject(name, "none"); //$NON-NLS-1$ //$NON-NLS-2$
80
		if(testProject == null) {
81
			fail("Unable to create project");
82
		}
83
		
84
		URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
85
				name+"-"+version+".src.rpm"));
86
		if (url == null)
87
			fail("Unable to find resources" + file_sep + "srpms" + file_sep +
88
				name+"-"+version+".src.rpm");
89
90
		/* Import the SRPM */
91
		SRPMImport SRPMImport;
92
		SRPMImport = new SRPMImport(
93
			testProject.getProject().getLocation().toOSString(), 
94
			Platform.asLocalURL(url).getPath());
95
		SRPMImport.setDoAutoconf(true);
96
		SRPMImport.setDoPatches(true);
97
		SRPMImport.run();
98
		
99
		/* Make sure the import was successful */
100
		File f = new File(testProject.getProject().getLocation().toOSString() + 
101
			file_sep + ".srpminfo"); //$NON-NLS-1$
102
		assertTrue(".srpminfo not found", f != null && f.exists()); //$NON-NLS-1$
103
		f = new File(testProject.getProject().getLocation().toOSString() + 
104
			file_sep + "eclipse_"+name+".spec"); //$NON-NLS-1$
105
		assertTrue("spec not found", f != null && f.exists()); //$NON-NLS-1$
106
		f = new File(testProject.getProject().getLocation().toOSString() + 
107
			file_sep + name+"-"+version+".src.rpm"); //$NON-NLS-1$
108
		assertTrue("srpm not found", f != null && f.exists()); //$NON-NLS-1$
109
110
		/* Clean up */
111
		testProject.getProject().delete(true, true, monitor);
112
	}
113
114
	/*
115
	 * @see TestCase#tearDown()
116
	 */
117
	protected void tearDown() throws Exception {
118
		super.tearDown();
119
	}
120
121
}
(-)resources/specs/helloworld.spec (+30 lines)
Added Link Here
1
%define _unpackaged_files_terminate_build 0
2
Summary: None - Eclipse-generated spec file
3
Name: helloworld
4
Version: 2
5
Release: 2
6
License: GPL
7
Group: Applications/Internet
8
Source: helloworld-%{version}.tar.bz2
9
Requires: tar
10
BuildRoot: %{_tmppath}/%{name}-root
11
%description
12
13
Basic spec file for rpm build in Eclipse for helloworld
14
15
%prep
16
%setup -q
17
%build
18
19
make
20
21
%install rm -rf $RPM_BUILD_ROOT
22
%makeinstall RPM_BUILD_ROOT=$RPM_BUILD_ROOT
23
%clean
24
rm -rf $RPM_BUILD_ROOT
25
%files
26
%defattr(-,root,root)
27
/usr/local/bin/helloworld
28
%changelog
29
* Tue Sep 07 2004 Rick Moseley <rmoseley@redhat.com>
30
- Original
(-)src/org/eclipse/cdt/rpm/core/internal/tests/RPMCoreInternalTestSuite.java (+23 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.internal.tests;
8
9
import junit.framework.Test;
10
import junit.framework.TestSuite;
11
12
public class RPMCoreInternalTestSuite extends TestSuite {
13
14
	public static Test suite() {
15
		TestSuite suite = new TestSuite(
16
				"Test for org.eclipse.cdt.rpm.core.internal.tests");
17
		//$JUnit-BEGIN$
18
        suite.addTest(RPMProjectTest.suite());
19
        suite.addTest(SpecFileParserTest.suite());
20
		//$JUnit-END$
21
		return suite;
22
	}
23
}
(-)src/org/eclipse/cdt/rpm/core/internal/tests/RPMProjectTest.java (+301 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.internal.tests;
8
9
import java.io.File;
10
import java.io.StringBufferInputStream;
11
import java.net.URL;
12
import java.text.SimpleDateFormat;
13
import java.util.Date;
14
15
import junit.framework.TestCase;
16
import junit.framework.TestSuite;
17
18
import org.eclipse.cdt.rpm.core.IRPMConstants;
19
import org.eclipse.cdt.rpm.core.IRPMProject;
20
import org.eclipse.cdt.rpm.core.ISpecFile;
21
import org.eclipse.cdt.rpm.core.RPMCorePlugin;
22
import org.eclipse.cdt.rpm.core.RPMExportDelta;
23
import org.eclipse.cdt.rpm.core.RPMProjectFactory;
24
import org.eclipse.cdt.rpm.core.RPMProjectNature;
25
import org.eclipse.cdt.rpm.core.tests.RPMCoreTestsPlugin;
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IFolder;
28
import org.eclipse.core.resources.IProject;
29
import org.eclipse.core.resources.IResource;
30
import org.eclipse.core.resources.IWorkspace;
31
import org.eclipse.core.resources.IWorkspaceDescription;
32
import org.eclipse.core.resources.IWorkspaceRoot;
33
import org.eclipse.core.resources.ResourcesPlugin;
34
import org.eclipse.core.runtime.NullProgressMonitor;
35
import org.eclipse.core.runtime.Path;
36
import org.eclipse.core.runtime.Platform;
37
import org.eclipse.core.runtime.QualifiedName;
38
39
public class RPMProjectTest extends TestCase {
40
41
    IWorkspace workspace;
42
    IWorkspaceRoot root;
43
    NullProgressMonitor monitor;
44
    String pluginRoot;
45
	
46
    final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
47
	private final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$
48
    
49
    /*
50
     * @see TestCase#setUp()
51
     */
52
    protected void setUp() throws Exception {
53
        super.setUp();
54
        IWorkspaceDescription desc;
55
        workspace = ResourcesPlugin.getWorkspace();
56
        root = workspace.getRoot();
57
        monitor = new NullProgressMonitor();
58
        if(workspace == null) {
59
            fail("Workspace was not setup");
60
        }
61
        if(root == null) {
62
            fail("Workspace root was not setup");
63
        }
64
        desc = workspace.getDescription();
65
        desc.setAutoBuilding(false);
66
        workspace.setDescription(desc);
67
    }
68
    
69
    public static TestSuite suite() {
70
        return new TestSuite(RPMProjectTest.class);
71
    }
72
73
    public void testImportHelloWorld() throws Exception {
74
        // Create a project for the test
75
        IProject testProject = root.getProject("testHelloWorld");
76
        testProject.create(monitor);
77
        testProject.open(monitor);
78
        if(testProject == null) {
79
            fail("Unable to create test project");
80
        }
81
		
82
		// Instantiate an RPMProject
83
		IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject);
84
        
85
        // Find the test SRPM and install it
86
        URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
87
                "helloworld-2-2.src.rpm"));
88
        if (url == null) {
89
            fail("Unable to find resource" + file_sep + "srpms" + file_sep +
90
                "helloworld-2-2.src.rpm");
91
        }
92
        File foo = new File(Platform.asLocalURL(url).getPath());
93
        rpmProject.importSourceRPM(foo);
94
        
95
        // Make sure the original SRPM got copied into the workspace
96
        IFile srpm = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-2.src.rpm");
97
        assertTrue(srpm.exists());
98
		assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, 
99
				IRPMConstants.SRPM_PROPERTY)));
100
        
101
        // Make sure everything got installed properly
102
        IFile spec = rpmProject.getConfiguration().getSpecsFolder().getFile("helloworld.spec");
103
        assertTrue(spec.exists());
104
        IFile sourceBall = rpmProject.getConfiguration().getSourcesFolder().getFile("helloworld-2.tar.bz2");
105
        assertTrue(sourceBall.exists());
106
107
        // Make sure we got the spec file
108
        ISpecFile specFile = rpmProject.getSpecFile();
109
        assertTrue(specFile != null);
110
		assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID,
111
				IRPMConstants.SPEC_FILE_PROPERTY)));
112
        
113
		// Make sure the sources got copied from BUILD to the project root
114
		IResource[] sources = rpmProject.getConfiguration().getBuildFolder().members();
115
		// If there is one folder, assume it contains all the sources
116
		if(sources.length == 1 && sources[0].getType() == IResource.FOLDER) {
117
			IFolder foo1 = rpmProject.getProject().getFolder(sources[0].getProjectRelativePath());
118
			sources = foo1.members();
119
		}
120
		for(int i=0; i < sources.length; i++) {
121
			if(sources[i].getType() == IResource.FILE) {
122
				assertTrue(testProject.getFile(sources[i].getName()).exists());
123
			}
124
			else if(sources[i].getType() == IResource.FOLDER) {
125
				assertTrue(testProject.getFolder(sources[i].getName()).exists());
126
			}
127
		}
128
		
129
		// Make sure the checksum was stored
130
		assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID,
131
				IRPMConstants.CHECKSUM_PROPERTY)));
132
		
133
		// Make sure the RPM nature was added
134
		assertTrue(rpmProject.getProject().hasNature(RPMProjectNature.RPM_NATURE_ID));
135
		
136
        // Clean up
137
        testProject.delete(true, false, monitor);
138
    }
139
    
140
    public void testBuildPrepHelloWorld() throws Exception {
141
        // Create a project for the test
142
        IProject testProject = root.getProject("testBuildPrepHelloWorld");
143
        testProject.create(monitor);
144
        testProject.open(monitor);
145
        if(testProject == null) {
146
            fail("Unable to create test project");
147
        }
148
		
149
		// Instantiate an RPMProject
150
		IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject);
151
        
152
        // Find the test SRPM, install, and build-prep it
153
        URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
154
                "helloworld-2-2.src.rpm"));
155
        if (url == null) {
156
            fail("Unable to find resource" + file_sep + "srpms" + file_sep +
157
                "helloworld-2-2.src.rpm");
158
        }
159
        File foo = new File(Platform.asLocalURL(url).getPath());
160
        rpmProject.importSourceRPM(foo);
161
        rpmProject.buildPrep();
162
        
163
        // Make sure we got everything in the build directory
164
        IFolder builddir = rpmProject.getConfiguration().getBuildFolder();
165
        IFolder helloworldFolder = builddir.getFolder("helloworld-2");
166
        assertTrue(helloworldFolder.exists());
167
        
168
        // Clean up
169
        testProject.delete(true, false, monitor);
170
    }
171
	
172
	public void testIsChangedHelloWorld() throws Exception {
173
		// Create a project for the test
174
        IProject testProject = root.getProject("testIsChangedHelloWorld");
175
        testProject.create(monitor);
176
        testProject.open(monitor);
177
        if(testProject == null) {
178
            fail("Unable to create test project");
179
        }
180
		
181
		// Instantiate an RPMProject
182
		IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject);
183
        
184
        // Find the test SRPM and install it
185
        URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
186
                "helloworld-2-2.src.rpm"));
187
        if (url == null) {
188
            fail("Unable to find resource" + file_sep + "srpms" + file_sep +
189
                "helloworld-2-2.src.rpm");
190
        }
191
        File foo = new File(Platform.asLocalURL(url).getPath());
192
        rpmProject.importSourceRPM(foo);
193
		assertFalse(rpmProject.isChanged());
194
		
195
		testProject.delete(true, false, null);
196
	}
197
	
198
	public void testIsChangedHelloWorld1() throws Exception {
199
		// Create a project for the test
200
        IProject testProject = root.getProject("testIsChangedHelloWorld1");
201
        testProject.create(monitor);
202
        testProject.open(monitor);
203
        if(testProject == null) {
204
            fail("Unable to create test project");
205
        }
206
		
207
		// Instantiate an RPMProject
208
		IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject);
209
        
210
        // Find the test SRPM and install it
211
        URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
212
                "helloworld-2-2.src.rpm"));
213
        if (url == null) {
214
            fail("Unable to find resource" + file_sep + "srpms" + file_sep +
215
                "helloworld-2-2.src.rpm");
216
        }
217
        File foo = new File(Platform.asLocalURL(url).getPath());
218
        rpmProject.importSourceRPM(foo);
219
		IFile sourceFile = rpmProject.getProject().getFile("helloworld.cpp");
220
		StringBufferInputStream foo1 = new StringBufferInputStream("/* */");
221
		sourceFile.appendContents(foo1, false, false, null);
222
		assertTrue(rpmProject.isChanged());
223
		
224
		testProject.delete(true, false, null);
225
	}
226
	
227
	public void testBuildSourceRPMHelloWorld() throws Exception {
228
		// Create a project for the test
229
        IProject testProject = root.getProject("testBuildSourceRPMHelloWorld1");
230
        testProject.create(monitor);
231
        testProject.open(monitor);
232
        if(testProject == null) {
233
            fail("Unable to create test project");
234
        }
235
		
236
		// Instantiate an RPMProject
237
		IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject);
238
        
239
        // Find the test SRPM and install it
240
        URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
241
                "helloworld-2-2.src.rpm"));
242
        if (url == null) {
243
            fail("Unable to find resource" + file_sep + "srpms" + file_sep +
244
                "helloworld-2-2.src.rpm");
245
        }
246
        File foo = new File(Platform.asLocalURL(url).getPath());
247
        rpmProject.importSourceRPM(foo);
248
		RPMExportDelta export = new RPMExportDelta();
249
		export.setSpecFile(rpmProject.getSpecFile().getFile());
250
		export.setVersion("2");
251
		export.setRelease("3");
252
		rpmProject.buildSourceRPM(export);
253
		
254
		IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-3.src.rpm");
255
		assertTrue(foo2.exists());
256
		
257
		testProject.delete(true, false, null);
258
	}
259
	
260
	public void testBuildSourceRPMHelloWorld1() throws Exception {
261
		// Create a project for the test
262
        IProject testProject = root.getProject("testBuildSourceRPMHelloWorld");
263
        testProject.create(monitor);
264
        testProject.open(monitor);
265
        if(testProject == null) {
266
            fail("Unable to create test project");
267
        }
268
		
269
		// Instantiate an RPMProject
270
		IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject);
271
        
272
        // Find the test SRPM and install it
273
        URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
274
                "helloworld-2-2.src.rpm"));
275
        if (url == null) {
276
            fail("Unable to find resource" + file_sep + "srpms" + file_sep +
277
                "helloworld-2-2.src.rpm");
278
        }
279
        File foo = new File(Platform.asLocalURL(url).getPath());
280
        rpmProject.importSourceRPM(foo);
281
		IFile sourceFile = rpmProject.getProject().getFile("helloworld.cpp");
282
		StringBufferInputStream foo1 = new StringBufferInputStream("/* */");
283
		sourceFile.appendContents(foo1, false, false, null);
284
		RPMExportDelta export = new RPMExportDelta();
285
		export.setSpecFile(rpmProject.getSpecFile().getFile());
286
		export.setVersion("2");
287
		export.setRelease("4");
288
		export.setPatchName("myPatchFFFFF.patch");
289
		Date today = new Date();
290
		SimpleDateFormat df = new SimpleDateFormat("E MMM dd yyyy"); //$NON-NLS-1$
291
		export.setChangelogEntry("* " + df.format(today) + "  Foo Bot  <bot@foo.bar>  2-4" + line_sep + 
292
				"- Made test change" + line_sep);
293
		rpmProject.buildSourceRPM(export);
294
		
295
		// Make sure patch was created
296
		assertTrue(rpmProject.getConfiguration().getSourcesFolder().getFile(export.getPatchName()).exists());
297
		
298
		IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-4.src.rpm");
299
		assertTrue(foo2.exists());
300
	}
301
}
(-)src/org/eclipse/cdt/rpm/core/internal/tests/SpecFileParserTest.java (+100 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
package org.eclipse.cdt.rpm.core.internal.tests;
8
9
import java.io.File;
10
import java.io.FileInputStream;
11
import java.net.URL;
12
13
import org.eclipse.cdt.rpm.core.internal.SpecFileParser;
14
import org.eclipse.cdt.rpm.core.tests.RPMCoreTestsPlugin;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.resources.IWorkspaceDescription;
19
import org.eclipse.core.resources.IWorkspaceRoot;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.Platform;
24
25
import junit.framework.TestCase;
26
import junit.framework.TestSuite;
27
28
public class SpecFileParserTest extends TestCase {
29
    
30
    IWorkspace workspace;
31
    IWorkspaceRoot root;
32
    NullProgressMonitor monitor;
33
    String pluginRoot;
34
    final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
35
    
36
    public static TestSuite suite() {
37
        return new TestSuite(SpecFileParserTest.class);
38
    }
39
    
40
    /*
41
     * @see TestCase#setUp()
42
     */
43
    protected void setUp() throws Exception {
44
        super.setUp();
45
        IWorkspaceDescription desc;
46
        workspace = ResourcesPlugin.getWorkspace();
47
        root = workspace.getRoot();
48
        monitor = new NullProgressMonitor();
49
        if(workspace == null) {
50
            fail("Workspace was not setup");
51
        }
52
        if(root == null) {
53
            fail("Workspace root was not setup");
54
        }
55
        desc = workspace.getDescription();
56
        desc.setAutoBuilding(false);
57
        workspace.setDescription(desc);
58
    }
59
60
    public void testParseHelloWorld() throws Exception {
61
        // Create a project for the test
62
        IProject testProject = root.getProject("testHelloWorldSpec");
63
        testProject.create(monitor);
64
        testProject.open(monitor);
65
        if(testProject == null) {
66
            fail("Unable to create test project");
67
        }
68
        
69
        // Find the spec
70
        URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "specs" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$
71
                "helloworld.spec"));
72
        if (url == null) {
73
            fail("Unable to find resource" + file_sep + "srpms" + file_sep +
74
                "helloworld.spec");
75
        }
76
        File foo = new File(Platform.asLocalURL(url).getPath());
77
        
78
        // Copy the spec into workspace
79
        IFile specFile = testProject.getFile("helloworld.spec");
80
        specFile.create(new FileInputStream(foo), false, null);
81
        assertTrue(specFile.exists());
82
        
83
        // Try parsing it
84
        SpecFileParser parser = new SpecFileParser(specFile);
85
        parser.parse();
86
        
87
        // Make sure we parsed the spec correctly
88
        String name = parser.getName();
89
        assertTrue(name.equals("helloworld"));
90
        String version = parser.getVersion();
91
        assertTrue(version.equals("2"));
92
        String release = parser.getRelease();
93
        assertTrue(release.equals("2"));
94
        assertTrue(parser.getConfigureArgs() == null);
95
        
96
        // Clean up
97
        testProject.delete(true, false, monitor);
98
    }
99
100
}
(-)src/org/eclipse/cdt/rpm/core/tests/RPMProjectFactoryTest.java (+62 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
8
package org.eclipse.cdt.rpm.core.tests;
9
10
import org.eclipse.cdt.rpm.core.IRPMProject;
11
import org.eclipse.cdt.rpm.core.RPMProjectFactory;
12
import org.eclipse.core.resources.IProject;
13
import org.eclipse.core.resources.IWorkspace;
14
import org.eclipse.core.resources.IWorkspaceDescription;
15
import org.eclipse.core.resources.IWorkspaceRoot;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.NullProgressMonitor;
18
19
import junit.framework.TestCase;
20
21
public class RPMProjectFactoryTest extends TestCase {
22
	
23
	IWorkspace workspace;
24
    IWorkspaceRoot root;
25
    NullProgressMonitor monitor;
26
    String pluginRoot;
27
    final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$
28
    
29
    /*
30
     * @see TestCase#setUp()
31
     */
32
    protected void setUp() throws Exception {
33
        super.setUp();
34
        IWorkspaceDescription desc;
35
        workspace = ResourcesPlugin.getWorkspace();
36
        root = workspace.getRoot();
37
        monitor = new NullProgressMonitor();
38
        if(workspace == null) {
39
            fail("Workspace was not setup");
40
        }
41
        if(root == null) {
42
            fail("Workspace root was not setup");
43
        }
44
        desc = workspace.getDescription();
45
        desc.setAutoBuilding(false);
46
        workspace.setDescription(desc);
47
    }
48
	
49
	public void testGetNewProject() throws Exception {
50
		// Create a project for the test
51
        IProject testProject = root.getProject("testHelloWorld");
52
        testProject.create(monitor);
53
        testProject.open(monitor);
54
        if(testProject == null) {
55
            fail("Unable to create test project");
56
        }
57
		
58
		IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject);
59
		assertNotNull(rpmProject);
60
		testProject.delete(true, false, monitor);
61
	}
62
}
(-)src/org/eclipse/cdt/rpm/core/tests/RPMProjectNatureTest.java (+59 lines)
Added Link Here
1
/*
2
 * (c) 2005 Red Hat, Inc.
3
 *
4
 * This program is open source software licensed under the 
5
 * Eclipse Public License ver. 1
6
 */
7
8
package org.eclipse.cdt.rpm.core.tests;
9
10
import org.eclipse.cdt.rpm.core.RPMProjectNature;
11
import org.eclipse.core.resources.IProject;
12
import org.eclipse.core.resources.IWorkspace;
13
import org.eclipse.core.resources.IWorkspaceDescription;
14
import org.eclipse.core.resources.IWorkspaceRoot;
15
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.runtime.NullProgressMonitor;
17
18
import junit.framework.TestCase;
19
20
public class RPMProjectNatureTest extends TestCase {
21
22
	IWorkspace workspace;
23
    IWorkspaceRoot root;
24
    NullProgressMonitor monitor;
25
    String pluginRoot;
26
    
27
    /*
28
     * @see TestCase#setUp()
29
     */
30
    protected void setUp() throws Exception {
31
        super.setUp();
32
        IWorkspaceDescription desc;
33
        workspace = ResourcesPlugin.getWorkspace();
34
        root = workspace.getRoot();
35
        monitor = new NullProgressMonitor();
36
        if(workspace == null) {
37
            fail("Workspace was not setup");
38
        }
39
        if(root == null) {
40
            fail("Workspace root was not setup");
41
        }
42
        desc = workspace.getDescription();
43
        desc.setAutoBuilding(false);
44
        workspace.setDescription(desc);
45
    }
46
	
47
	public void testAddRPMProjectNature() throws Exception {
48
		IProject testProject = root.getProject("testProject");
49
		testProject.create(monitor);
50
		testProject.open(monitor);
51
		if(testProject == null) {
52
            fail("Unable to create test project");
53
        }
54
		RPMProjectNature.addRPMNature(testProject, monitor);
55
		assertTrue(testProject.hasNature(RPMProjectNature.RPM_NATURE_ID));
56
		testProject.delete(true, false, monitor);
57
	}
58
	
59
}

Return to bug 82195