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

Collapse All | Expand All

(-)src/org/eclipse/team/tests/ccvs/ui/AllUITests.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 35-41 Link Here
35
		suite.addTest(EditorTests.suite());
35
		suite.addTest(EditorTests.suite());
36
		suite.addTest(PatchWizardRadioButtonGroupTests.suite());
36
		suite.addTest(PatchWizardRadioButtonGroupTests.suite());
37
		suite.addTest(CVSProjectSetImportTest.suite());
37
		suite.addTest(CVSProjectSetImportTest.suite());
38
		suite.addTest(CreatePatchTest.suite());
38
		return suite;
39
		return suite;
39
	}
40
	}
40
	
41
41
}
42
}
(-)plugin.xml (-35 / +2 lines)
Lines 1-41 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.0"?>
3
<plugin
3
<plugin>
4
   id="org.eclipse.team.tests.cvs.core"
5
   name="Eclipse CVS Tests Core"
6
   version="3.3.200"
7
   provider-name="Eclipse.org">
8
9
   <runtime>
10
      <library name="cvstests.jar">
11
         <export name="*"/>
12
      </library>
13
   </runtime>
14
   <requires>
15
      <import plugin="org.eclipse.ui.ide" optional="true"/>
16
      <import plugin="org.eclipse.ui.views" optional="true"/>
17
      <import plugin="org.eclipse.jface.text" optional="true"/>
18
      <import plugin="org.eclipse.ui.workbench.texteditor" optional="true"/>
19
      <import plugin="org.eclipse.ui.editors" optional="true"/>
20
      <import plugin="org.eclipse.core.tests.harness"/>
21
      <import plugin="org.eclipse.core.runtime.compatibility"/> 
22
      <import plugin="org.eclipse.core.runtime"/> 
23
      <import plugin="org.eclipse.core.resources"/>
24
      <import plugin="org.eclipse.team.core"/>
25
      <import plugin="org.eclipse.team.cvs.core"/>
26
      <import plugin="org.eclipse.team.ui"/>
27
      <import plugin="org.eclipse.team.cvs.ui"/>
28
      <import plugin="org.eclipse.compare"/>
29
      <import plugin="org.eclipse.ui"/>
30
      <import plugin="org.eclipse.update.core"/>
31
      <import plugin="org.junit"/>
32
      <import plugin="org.eclipse.team.tests.core"/>
33
      <import plugin="org.eclipse.test.performance"/>
34
      <import plugin="org.eclipse.core.tests.resources"/>
35
      <import plugin="org.eclipse.core.expressions"/>
36
   </requires>
37
38
4
5
    
39
<!-- *************** Connection Methods **************** -->
6
<!-- *************** Connection Methods **************** -->
40
   <extension
7
   <extension
41
         id="pserver"
8
         id="pserver"
(-)build.properties (-1 / +2 lines)
Lines 15-19 Link Here
15
               test.xml,\
15
               test.xml,\
16
               repository.properties,\
16
               repository.properties,\
17
               resources/,\
17
               resources/,\
18
               icons/
18
               icons/,\
19
               META-INF/
19
src.includes = resources/
20
src.includes = resources/
(-)src/org/eclipse/team/tests/ccvs/ui/CreatePatchTest.java (+315 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.ui;
12
13
import java.io.BufferedReader;
14
import java.io.IOException;
15
import java.io.InputStream;
16
import java.io.InputStreamReader;
17
import java.lang.reflect.InvocationTargetException;
18
import java.net.URL;
19
20
import junit.framework.Test;
21
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.IWorkspaceRunnable;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.Path;
31
import org.eclipse.jface.wizard.IWizardPage;
32
import org.eclipse.jface.wizard.WizardDialog;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.widgets.Button;
35
import org.eclipse.swt.widgets.Display;
36
import org.eclipse.swt.widgets.Event;
37
import org.eclipse.swt.widgets.Shell;
38
import org.eclipse.swt.widgets.Text;
39
import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
40
import org.eclipse.team.internal.ccvs.ui.wizards.GenerateDiffFileWizard;
41
import org.eclipse.team.tests.ccvs.core.EclipseTest;
42
import org.eclipse.team.tests.ccvs.core.TeamCVSTestPlugin;
43
import org.eclipse.ui.IWorkbenchPage;
44
import org.eclipse.ui.IWorkbenchPart;
45
import org.eclipse.ui.IWorkbenchWindow;
46
import org.eclipse.ui.PlatformUI;
47
48
public class CreatePatchTest extends EclipseTest {
49
50
	public static final String PATCHDATA = "patchdata";
51
52
	private final static int INITIAL_WIDTH = 300;
53
	private final static int INITIAL_HEIGHT = 350;
54
55
	private GenerateDiffFileWizard wizard = null;
56
	private WizardDialog wizardDialog = null;
57
58
	private IProject testProject = null;
59
60
	public CreatePatchTest() {
61
		super();
62
	}
63
64
	public CreatePatchTest(String name) {
65
		super(name);
66
	}
67
68
	public static Test suite() {
69
		return suite(CreatePatchTest.class);
70
	}
71
72
	protected void setUp() throws Exception {
73
		super.setUp();
74
		testProject = createProject("ApplyPatchTest", new String[] {});
75
	}
76
77
	protected void tearDown() throws Exception {
78
		super.tearDown();
79
		testProject.delete(true, null);
80
	}
81
82
	public void testCreateWorkspacePatch() throws Exception {
83
		copyIntoWorkspace("exp_addition.txt", "addition.txt");
84
85
		openGenerateDiffFileWizard(new IResource[] { testProject });
86
		assertTrue(wizard.getPageCount() == 2);
87
88
		IWizardPage locationPage = wizard.getPages()[0];
89
90
		getButton(locationPage, "cpRadio").setSelection(false);
91
		getButton(locationPage, "fsRadio").setSelection(false);
92
		getButton(locationPage, "wsRadio").setSelection(true);
93
		getButton(locationPage, "wsRadio").notifyListeners(SWT.Selection,
94
				createSelectionEvent());
95
		getText(locationPage, "wsPathText").setText(
96
				"/" + testProject.getName() + "/patch_addition.txt");
97
98
		waitForSelection();
99
100
		processQueuedEvents();
101
		assertTrue(locationPage.canFlipToNextPage());
102
		callMethod(wizardDialog, "nextPressed");
103
104
		IWizardPage optionsPage = wizard.getPages()[1];
105
106
		getButton(optionsPage, "unifiedDiffOption").setSelection(true);
107
		getButton(optionsPage, "contextDiffOption").setSelection(false);
108
		getButton(optionsPage, "regularDiffOption").setSelection(false);
109
		getButton(optionsPage, "unified_workspaceRelativeOption").setSelection(
110
				true);
111
		getButton(optionsPage, "unified_projectRelativeOption").setSelection(
112
				false);
113
		getButton(optionsPage, "unified_selectionRelativeOption").setSelection(
114
				false);
115
116
		processQueuedEvents();
117
		assertTrue(wizard.canFinish());
118
		wizard.performFinish();
119
		wizardDialog.close();
120
121
		// Ignore lines prefixed with following values to avoid timestamps
122
		// mismatches
123
		String prefixesToIgnore[] = new String[] { "#P ApplyPatchTest-",
124
				"--- /dev/null", "+++ addition.txt" };
125
126
		InputStream expectedIS = asInputStream("patch_addition.txt");
127
		String expected = filterStream(expectedIS, prefixesToIgnore);
128
129
		IFile patchFile = testProject.getFile("patch_addition.txt");
130
		String actual = readProjectFile(patchFile, prefixesToIgnore);
131
132
		assertEquals(expected, actual);
133
	}
134
135
	private void openGenerateDiffFileWizard(IResource resources[]) {
136
		String title = CVSUIMessages.GenerateCVSDiff_title;
137
		wizard = new GenerateDiffFileWizard(getActivePart(), resources, true);
138
		wizard.setWindowTitle(title);
139
		wizardDialog = new WizardDialog(getShell(), wizard);
140
		wizardDialog.setMinimumPageSize(INITIAL_WIDTH, INITIAL_HEIGHT);
141
		wizardDialog.setBlockOnOpen(false);
142
		wizardDialog.open();
143
	}
144
145
	private void copyIntoWorkspace(String source, String target) {
146
		IFile file = testProject.getFile(target);
147
		InputStream is = asInputStream(source);
148
		try {
149
			if (file.exists()) {
150
				file.setContents(is, true, true, null);
151
			} else {
152
				file.create(is, true, null);
153
			}
154
		} catch (CoreException e) {
155
			fail(e.getMessage());
156
		}
157
	}
158
159
	private void waitForSelection() {
160
		IWizardPage locationPage = wizard.getPages()[0];
161
		int toSleep = 100;
162
		int totalWaited = 0;
163
		IResource[] sel = null;
164
		while (sel == null || sel.length == 0) {
165
			sel = (IResource[]) callMethod(locationPage, "getSelectedResources");
166
			processQueuedEvents();
167
			try {
168
				Thread.sleep(toSleep);
169
			} catch (InterruptedException e) {
170
				fail(e.getMessage());
171
			}
172
			totalWaited += toSleep;
173
			assertTrue(totalWaited < 2500);
174
		}
175
	}
176
177
	private String readProjectFile(final IFile file,
178
			final String[] prefixesToIgnore) {
179
		final String[] ret = new String[1];
180
		int toSleep = 100;
181
		int totalWaited = 0;
182
		while (!file.exists()) {
183
			processQueuedEvents();
184
			try {
185
				Thread.sleep(toSleep);
186
			} catch (InterruptedException e) {
187
				fail(e.getMessage());
188
			}
189
			totalWaited += toSleep;
190
			assertTrue(totalWaited < 2500);
191
		}
192
		try {
193
			ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
194
				public void run(IProgressMonitor monitor) throws CoreException {
195
					ret[0] = filterStream(file.getContents(), prefixesToIgnore);
196
				}
197
			}, file, IResource.NONE, null);
198
		} catch (CoreException e) {
199
			fail(e.getMessage());
200
		}
201
		return ret[0];
202
	}
203
204
	private String filterStream(InputStream stream, String prefixesToIgnore[]) {
205
		BufferedReader reader = new BufferedReader(
206
				new InputStreamReader(stream));
207
		String line = null;
208
		StringBuffer buffer = new StringBuffer();
209
		try {
210
			while ((line = reader.readLine()) != null) {
211
				boolean ignore = false;
212
				for (int i = 0; i < prefixesToIgnore.length && !ignore; i++) {
213
					ignore = line.startsWith(prefixesToIgnore[i]);
214
				}
215
				if (!ignore) {
216
					buffer.append(line + "\n");
217
				}
218
			}
219
		} catch (IOException e) {
220
			fail(e.getMessage());
221
		}
222
		String ret = buffer.toString();
223
		try {
224
			reader.close();
225
		} catch (IOException e) {
226
			fail(e.getMessage());
227
		}
228
		return ret;
229
	}
230
231
	private InputStream asInputStream(String name) {
232
		IPath path = new Path(PATCHDATA).append(name);
233
		try {
234
			URL base = TeamCVSTestPlugin.getDefault().getBundle().getEntry("/");
235
			URL url = new URL(base, path.toString());
236
			return url.openStream();
237
		} catch (IOException e) {
238
			fail("Failed while reading " + name);
239
			return null;
240
		}
241
	}
242
243
	private Text getText(Object object, String name) {
244
		return (Text) getField(object, name);
245
	}
246
247
	private Button getButton(Object object, String name) {
248
		return (Button) getField(object, name);
249
	}
250
251
	private Object getField(Object object, String name) {
252
		Object ret = null;
253
		try {
254
			ret = ReflectionUtils.getField(object, name);
255
		} catch (IllegalArgumentException e) {
256
			fail(e.getMessage());
257
		} catch (SecurityException e) {
258
			fail(e.getMessage());
259
		} catch (IllegalAccessException e) {
260
			fail(e.getMessage());
261
		} catch (NoSuchFieldException e) {
262
			fail(e.getMessage());
263
		}
264
		return ret;
265
	}
266
267
	private Object callMethod(Object object, String name) {
268
		return callMethod(object, name, new Object[] {});
269
	}
270
271
	private Object callMethod(Object object, String name, Object args[]) {
272
		Object ret = null;
273
		try {
274
			ret = ReflectionUtils.callMethod(object, name, args);
275
		} catch (IllegalArgumentException e) {
276
			fail(e.getMessage());
277
		} catch (IllegalAccessException e) {
278
			fail(e.getMessage());
279
		} catch (InvocationTargetException e) {
280
			fail(e.getMessage());
281
		} catch (NoSuchMethodException e) {
282
			fail(e.getMessage());
283
		}
284
		return ret;
285
	}
286
287
	private Shell getShell() {
288
		return getActivePart().getSite().getShell();
289
	}
290
291
	private IWorkbenchPart getActivePart() {
292
		IWorkbenchWindow window = PlatformUI.getWorkbench()
293
				.getActiveWorkbenchWindow();
294
		if (window == null) {
295
			return null;
296
		}
297
		IWorkbenchPage page = window.getActivePage();
298
		if (page == null) {
299
			return null;
300
		}
301
		return page.getActivePart();
302
	}
303
304
	private void processQueuedEvents() {
305
		while (Display.getCurrent().readAndDispatch()) {
306
		}
307
	}
308
309
	private Event createSelectionEvent() {
310
		Event event = new Event();
311
		event.type = SWT.Selection;
312
		return event;
313
	}
314
315
}
(-)META-INF/MANIFEST.MF (+41 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Eclipse CVS Tests Core
4
Bundle-SymbolicName: org.eclipse.team.tests.cvs.core; singleton:=true
5
Bundle-Version: 3.3.200
6
Bundle-ClassPath: cvstests.jar
7
Bundle-Activator: org.eclipse.team.tests.ccvs.core.TeamCVSTestPlugin
8
Bundle-Vendor: Eclipse.org
9
Bundle-Localization: plugin
10
Export-Package: org.eclipse.team.tests.ccvs.core,
11
 org.eclipse.team.tests.ccvs.core.compatible,
12
 org.eclipse.team.tests.ccvs.core.cvsresources,
13
 org.eclipse.team.tests.ccvs.core.mappings,
14
 org.eclipse.team.tests.ccvs.core.provider,
15
 org.eclipse.team.tests.ccvs.core.subscriber,
16
 org.eclipse.team.tests.ccvs.ui,
17
 org.eclipse.team.tests.ccvs.ui.benchmark
18
Require-Bundle: org.eclipse.ui.ide;resolution:=optional,
19
 org.eclipse.ui.views;resolution:=optional,
20
 org.eclipse.jface.text;resolution:=optional,
21
 org.eclipse.ui.workbench.texteditor;resolution:=optional,
22
 org.eclipse.ui.editors;resolution:=optional,
23
 org.eclipse.core.tests.harness,
24
 org.eclipse.core.runtime.compatibility,
25
 org.eclipse.core.runtime,
26
 org.eclipse.core.resources,
27
 org.eclipse.team.core,
28
 org.eclipse.team.cvs.core,
29
 org.eclipse.team.ui,
30
 org.eclipse.team.cvs.ui,
31
 org.eclipse.compare,
32
 org.eclipse.ui,
33
 org.eclipse.update.core,
34
 org.junit,
35
 org.eclipse.team.tests.core,
36
 org.eclipse.test.performance,
37
 org.eclipse.core.tests.resources,
38
 org.eclipse.core.expressions
39
Bundle-ActivationPolicy: lazy
40
Eclipse-AutoStart: true
41
Plugin-Class: org.eclipse.team.tests.ccvs.core.TeamCVSTestPlugin
(-)src/org/eclipse/team/tests/ccvs/ui/ReflectionUtils.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.ui;
12
13
import java.lang.reflect.Field;
14
import java.lang.reflect.InvocationTargetException;
15
import java.lang.reflect.Method;
16
17
public class ReflectionUtils {
18
19
	public static Object callMethod(Object object, String name, Object args[])
20
			throws IllegalArgumentException, IllegalAccessException,
21
			InvocationTargetException, NoSuchMethodException {
22
		Class types[] = new Class[args.length];
23
		for (int i = 0; i < args.length; i++) {
24
			types[i] = args[i].getClass();
25
		}
26
		Method method = null;
27
		Class clazz = object.getClass();
28
		NoSuchMethodException ex = null;
29
		while (method == null && clazz != null) {
30
			try {
31
				method = clazz.getDeclaredMethod(name, types);
32
			} catch (NoSuchMethodException e) {
33
				if (ex == null) {
34
					ex = e;
35
				}
36
				clazz = clazz.getSuperclass();
37
			}
38
		}
39
		if (method == null) {
40
			throw ex;
41
		}
42
		method.setAccessible(true);
43
		Object ret = method.invoke(object, args);
44
		return ret;
45
	}
46
47
	public static Object getField(Object object, String name)
48
			throws IllegalArgumentException, IllegalAccessException,
49
			SecurityException, NoSuchFieldException {
50
		Field field = object.getClass().getDeclaredField(name);
51
		field.setAccessible(true);
52
		Object ret = field.get(object);
53
		return ret;
54
	}
55
56
}
(-)patchdata/patch_addition.txt (+18 lines)
Added Link Here
1
### Eclipse Workspace Patch 1.0
2
#P ApplyPatchTest-
3
Index: addition.txt
4
===================================================================
5
RCS file: addition.txt
6
diff -N addition.txt
7
--- /dev/null
8
+++ addition.txt
9
@@ -0,0 +1,9 @@
10
+[1]
11
+[2]
12
+[3]
13
+[4]
14
+[5]
15
+[6]
16
+[7]
17
+[8]
18
+[9]
(-)src/org/eclipse/team/tests/ccvs/core/TeamCVSTestPlugin.java (+27 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.core;
12
13
import org.eclipse.core.runtime.Plugin;
14
15
public class TeamCVSTestPlugin extends Plugin {
16
17
	private static TeamCVSTestPlugin fgPlugin;
18
19
	public TeamCVSTestPlugin() {
20
		fgPlugin = this;
21
	}
22
23
	public static TeamCVSTestPlugin getDefault() {
24
		return fgPlugin;
25
	}
26
27
}
(-)patchdata/exp_addition.txt (+9 lines)
Added Link Here
1
[1]
2
[2]
3
[3]
4
[4]
5
[5]
6
[6]
7
[7]
8
[8]
9
[9]

Return to bug 266812