Lines 52-58
Link Here
|
52 |
import org.eclipse.core.runtime.FileLocator; |
52 |
import org.eclipse.core.runtime.FileLocator; |
53 |
import org.eclipse.core.runtime.IPath; |
53 |
import org.eclipse.core.runtime.IPath; |
54 |
import org.eclipse.core.runtime.IStatus; |
54 |
import org.eclipse.core.runtime.IStatus; |
55 |
import org.eclipse.core.runtime.NullProgressMonitor; |
55 |
//import org.eclipse.core.runtime.NullProgressMonitor; |
56 |
import org.eclipse.core.runtime.Path; |
56 |
import org.eclipse.core.runtime.Path; |
57 |
import org.eclipse.core.runtime.Platform; |
57 |
import org.eclipse.core.runtime.Platform; |
58 |
import org.eclipse.core.runtime.Status; |
58 |
import org.eclipse.core.runtime.Status; |
Lines 187-223
Link Here
|
187 |
//Test creation of new workspace patch |
187 |
//Test creation of new workspace patch |
188 |
public void testWorkspacePatch_Create(){ |
188 |
public void testWorkspacePatch_Create(){ |
189 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
189 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
190 |
patchWorkspace(new String[]{"addition.txt", "addition.txt"}, "patch_workspacePatchAddition.txt", new String[] { "exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt"}, false, false); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
190 |
patchWorkspace(new String[]{"addition.txt", "addition.txt"}, "patch_workspacePatchAddition.txt", new String[] { "exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt"}, false, 0); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
191 |
} |
191 |
} |
192 |
|
192 |
|
193 |
//Test applying the reverse of workspace creation patch |
193 |
//Test applying the reverse of workspace creation patch |
194 |
public void testWorkspacePatch_Create_Reverse(){ |
194 |
public void testWorkspacePatch_Create_Reverse(){ |
195 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
195 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
196 |
patchWorkspace(new String[]{"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt"}, "patch_workspacePatchAddition.txt", new String[] {"addition.txt", "addition.txt"}, true, false); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
196 |
patchWorkspace(new String[]{"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt"}, "patch_workspacePatchAddition.txt", new String[] {"addition.txt", "addition.txt"}, true, 0); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
197 |
} |
197 |
} |
198 |
|
198 |
|
199 |
//Test the patching of an already existing file, the creation of a new one and the deletion of elements in a file |
199 |
//Test the patching of an already existing file, the creation of a new one and the deletion of elements in a file |
200 |
public void testWorkspacePatch_Modify(){ |
200 |
public void testWorkspacePatch_Modify(){ |
201 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
201 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
202 |
patchWorkspace(new String[]{"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt", "addition.txt"}, "patch_workspacePatchMod.txt", new String[] { "exp_workspacePatchMod1.txt","exp_workspacePatchMod2.txt", "exp_workspacePatchMod3.txt"}, false, false ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ |
202 |
patchWorkspace(new String[]{"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt", "addition.txt"}, "patch_workspacePatchMod.txt", new String[] { "exp_workspacePatchMod1.txt","exp_workspacePatchMod2.txt", "exp_workspacePatchMod3.txt"}, false, 0 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ |
203 |
} |
203 |
} |
204 |
|
204 |
|
205 |
//Test applying the reverse of a workspace modify patch |
205 |
//Test applying the reverse of a workspace modify patch |
206 |
public void testWorkspacePatch_Modify_Reverse(){ |
206 |
public void testWorkspacePatch_Modify_Reverse(){ |
207 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
207 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
208 |
patchWorkspace(new String[]{ "exp_workspacePatchMod1.txt","exp_workspacePatchMod2.txt", "exp_workspacePatchMod3.txt"}, "patch_workspacePatchMod.txt", new String[] {"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt", "addition.txt"}, true, false ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ |
208 |
patchWorkspace(new String[]{ "exp_workspacePatchMod1.txt","exp_workspacePatchMod2.txt", "exp_workspacePatchMod3.txt"}, "patch_workspacePatchMod.txt", new String[] {"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt", "addition.txt"}, true, 0 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ |
209 |
} |
209 |
} |
210 |
|
210 |
|
211 |
//Tests the deletion of an already existing file, and the modification of another file |
211 |
//Tests the deletion of an already existing file, and the modification of another file |
212 |
public void testWorkspacePatch_Delete(){ |
212 |
public void testWorkspacePatch_Delete(){ |
213 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
213 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
214 |
patchWorkspace(new String[]{"exp_workspacePatchMod2.txt","addition.txt", "exp_workspacePatchMod1.txt","addition.txt"}, "patch_workspacePatchDelete.txt", new String[] { "addition.txt","exp_workspacePatchDelete2.txt", "addition.txt", "exp_workspacePatchDelete1.txt"}, false, false ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ |
214 |
patchWorkspace(new String[]{"exp_workspacePatchMod2.txt","addition.txt", "exp_workspacePatchMod1.txt","addition.txt"}, "patch_workspacePatchDelete.txt", new String[] { "addition.txt","exp_workspacePatchDelete2.txt", "addition.txt", "exp_workspacePatchDelete1.txt"}, false, 0 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ |
215 |
} |
215 |
} |
216 |
|
216 |
|
217 |
//Test applying the reverse of a workspace deletion patch |
217 |
//Test applying the reverse of a workspace deletion patch |
218 |
public void testWorkspacePatch_Delete_Reverse(){ |
218 |
public void testWorkspacePatch_Delete_Reverse(){ |
219 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
219 |
//Note the order that exists in the array of expected results is based purely on the order of the files in the patch |
220 |
patchWorkspace(new String[]{"addition.txt","exp_workspacePatchDelete2.txt", "addition.txt", "exp_workspacePatchDelete1.txt" }, "patch_workspacePatchDelete.txt", new String[] {"exp_workspacePatchMod2.txt","addition.txt", "exp_workspacePatchMod1.txt","addition.txt"}, true, false ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ |
220 |
patchWorkspace(new String[]{"addition.txt","exp_workspacePatchDelete2.txt", "addition.txt", "exp_workspacePatchDelete1.txt" }, "patch_workspacePatchDelete.txt", new String[] {"exp_workspacePatchMod2.txt","addition.txt", "exp_workspacePatchMod1.txt","addition.txt"}, true, 0 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ |
221 |
} |
221 |
} |
222 |
|
222 |
|
223 |
// Keeps track of the failures |
223 |
// Keeps track of the failures |
Lines 250-260
Link Here
|
250 |
String msg = "Test for subfolder [patchdata/" + subfolder |
250 |
String msg = "Test for subfolder [patchdata/" + subfolder |
251 |
+ "] failed."; |
251 |
+ "] failed."; |
252 |
|
252 |
|
|
|
253 |
// get the fuzz factor for the patch if provided |
254 |
// TODO: what if fuzz > 3 |
255 |
String patch = filenames[1].substring(subfolder.length()); |
256 |
int fuzz = -1; |
257 |
if (patch.indexOf("fuzz3") > -1 || patch.indexOf("f3") > -1) |
258 |
fuzz = 3; |
259 |
if (patch.indexOf("fuzz2") > -1 || patch.indexOf("f2") > -1) |
260 |
fuzz = 2; |
261 |
if (patch.indexOf("fuzz1") > -1 || patch.indexOf("f1") > -1) |
262 |
fuzz = 1; |
263 |
if (patch.indexOf("fuzz0") > -1 || patch.indexOf("f0") > -1) |
264 |
fuzz = 0; |
265 |
|
253 |
try { |
266 |
try { |
254 |
// test with expected result |
267 |
// test with expected result |
255 |
patchWorkspace(msg, new String[] { filenames[0] }, |
268 |
patchWorkspace(msg, new String[] { filenames[0] }, |
256 |
filenames[1], new String[] { filenames[2] }, false, |
269 |
filenames[1], new String[] { filenames[2] }, false, |
257 |
true); |
270 |
fuzz); |
258 |
} catch (AssertionFailedError e) { |
271 |
} catch (AssertionFailedError e) { |
259 |
failures.add(e); |
272 |
failures.add(e); |
260 |
} |
273 |
} |
Lines 264-270
Link Here
|
264 |
try { |
277 |
try { |
265 |
patchWorkspace(msg, new String[] { filenames[0] }, |
278 |
patchWorkspace(msg, new String[] { filenames[0] }, |
266 |
filenames[1], new String[] { filenames[3] }, false, |
279 |
filenames[1], new String[] { filenames[3] }, false, |
267 |
true); |
280 |
fuzz); |
268 |
} catch (AssertionFailedError e) { |
281 |
} catch (AssertionFailedError e) { |
269 |
// a failure is expected |
282 |
// a failure is expected |
270 |
continue; // continue with a next subfolder |
283 |
continue; // continue with a next subfolder |
Lines 520-549
Link Here
|
520 |
|
533 |
|
521 |
private void patchWorkspace(String[] originalFiles, String patch, |
534 |
private void patchWorkspace(String[] originalFiles, String patch, |
522 |
String[] expectedOutcomeFiles, boolean reverse, |
535 |
String[] expectedOutcomeFiles, boolean reverse, |
523 |
boolean guessFuzzFactor) { |
536 |
int fuzzFactor) { |
524 |
patchWorkspace(null, originalFiles, patch, expectedOutcomeFiles, |
537 |
patchWorkspace(null, originalFiles, patch, expectedOutcomeFiles, |
525 |
reverse, guessFuzzFactor); |
538 |
reverse, fuzzFactor); |
526 |
} |
539 |
} |
527 |
|
540 |
|
528 |
/** |
541 |
/** |
529 |
* Parses a workspace patch and applies the diffs to the appropriate files |
542 |
* Parses a workspace patch and applies the diffs to the appropriate files |
|
|
543 |
* |
530 |
* @param msg |
544 |
* @param msg |
531 |
* @param originalFiles |
545 |
* @param originalFiles |
532 |
* @param patch |
546 |
* @param patch |
533 |
* @param expectedOutcomeFiles |
547 |
* @param expectedOutcomeFiles |
534 |
* @param reverse |
548 |
* @param reverse |
535 |
* @param guessFuzzFactor TODO |
549 |
* @param fuzzFactor |
|
|
550 |
* The fuzz factor to use, ranging from 0 (all context must |
551 |
* match) to 2 (the default maximum fuzz factor). <code>-1</code> |
552 |
* means that the fuzz factor should be calculated automatically. |
536 |
*/ |
553 |
*/ |
537 |
private void patchWorkspace(String msg, String[] originalFiles, String patch, String[] expectedOutcomeFiles, boolean reverse, boolean guessFuzzFactor) { |
554 |
private void patchWorkspace(String msg, String[] originalFiles, String patch, String[] expectedOutcomeFiles, boolean reverse, int fuzzFactor) { |
538 |
|
555 |
|
539 |
//ensure that we have the same number of input files as we have expected files |
556 |
//ensure that we have the same number of input files as we have expected files |
540 |
Assert.assertEquals(originalFiles.length, expectedOutcomeFiles.length); |
557 |
Assert.assertEquals(originalFiles.length, expectedOutcomeFiles.length); |
541 |
|
558 |
|
542 |
//Parse the passed in patch and extract all the Diffs |
559 |
// Parse the passed in patch and extract all the Diffs |
543 |
WorkspacePatcher patcher= new WorkspacePatcher(); |
560 |
WorkspacePatcher patcher = new WorkspacePatcher(); |
544 |
try { |
561 |
try { |
545 |
if (guessFuzzFactor) |
562 |
patcher.getConfiguration().setFuzz(fuzzFactor); |
546 |
patcher.getConfiguration().setFuzz(patcher.guessFuzzFactor(new NullProgressMonitor())); |
|
|
547 |
patcher.parse(getReader(patch)); |
563 |
patcher.parse(getReader(patch)); |
548 |
patcher.setReversed(reverse); |
564 |
patcher.setReversed(reverse); |
549 |
} catch (IOException e) { |
565 |
} catch (IOException e) { |
Lines 558-564
Link Here
|
558 |
for (int i = 0; i < originalFiles.length; i++) { |
574 |
for (int i = 0; i < originalFiles.length; i++) { |
559 |
LineReader lr= new LineReader(getReader(originalFiles[i])); |
575 |
LineReader lr= new LineReader(getReader(originalFiles[i])); |
560 |
List inLines= lr.readLines(); |
576 |
List inLines= lr.readLines(); |
561 |
|
|
|
562 |
|
577 |
|
563 |
FileDiffResult diffResult = patcher.getDiffResult(diffs[i]); |
578 |
FileDiffResult diffResult = patcher.getDiffResult(diffs[i]); |
564 |
diffResult.patch(inLines, null); |
579 |
diffResult.patch(inLines, null); |