diff options
author | Andre Weinand | 2005-10-06 17:18:01 +0000 |
---|---|---|
committer | Andre Weinand | 2005-10-06 17:18:01 +0000 |
commit | 7e2bef4f3ad770ae114904f5acaa9e7be1006ae6 (patch) | |
tree | ae7d6b3964d58685a44a62e052b90d232193cbc8 /tests/org.eclipse.compare.tests | |
parent | 6a13d381629723ed4466f91d1267c259ce305f27 (diff) | |
download | eclipse.platform.team-7e2bef4f3ad770ae114904f5acaa9e7be1006ae6.tar.gz eclipse.platform.team-7e2bef4f3ad770ae114904f5acaa9e7be1006ae6.tar.xz eclipse.platform.team-7e2bef4f3ad770ae114904f5acaa9e7be1006ae6.zip |
released patch for #110481: Ability for Apply Patch wizard to work with multiple-project patches
Diffstat (limited to 'tests/org.eclipse.compare.tests')
11 files changed, 444 insertions, 6 deletions
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java index 14fab809e..e8fe84296 100644 --- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java @@ -17,13 +17,13 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; -import org.eclipse.compare.internal.patch.Diff; -import org.eclipse.compare.internal.patch.Patcher; -import org.eclipse.compare.internal.patch.LineReader; - import junit.framework.Assert; import junit.framework.TestCase; +import org.eclipse.compare.internal.patch.Diff; +import org.eclipse.compare.internal.patch.LineReader; +import org.eclipse.compare.internal.patch.WorkspacePatcher; + public class PatchTest extends TestCase { public PatchTest(String name) { @@ -41,7 +41,7 @@ public class PatchTest extends TestCase { public void testCreatePatch() { patch("addition.txt", "patch_addition.txt", "exp_addition.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - + public void testUnterminatedCreatePatch() { patch("addition.txt", "patch_addition2.txt", "exp_addition2.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } @@ -58,6 +58,44 @@ public class PatchTest extends TestCase { patch("context.txt", "patch_context3.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } + //Test creation of new workspace patch + public void testWorkspacePatch_Create(){ + //Note the order that exists in the array of expected results is based purely on the order of the files in the patch + patchWorkspace(new String[]{"addition.txt", "addition.txt"}, "patch_workspacePatchAddition.txt", new String[] { "exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt"}, false); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + } + + //Test applying the reverse of workspace creation patch + public void testWorkspacePatch_Create_Reverse(){ + //Note the order that exists in the array of expected results is based purely on the order of the files in the patch + patchWorkspace(new String[]{"exp_workspacePatchAddition2.txt","exp_workspacePatchAddition.txt"}, "patch_workspacePatchAddition.txt", new String[] {"addition.txt", "addition.txt"}, true); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + } + + //Test the patching of an already existing file, the creation of a new one and the deletion of elements in a file + public void testWorkspacePatch_Modify(){ + //Note the order that exists in the array of expected results is based purely on the order of the files in the patch + 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 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + } + + //Test applying the reverse of a workspace modify patch + public void testWorkspacePatch_Modify_Reverse(){ + //Note the order that exists in the array of expected results is based purely on the order of the files in the patch + 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 ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ + } + + //Tests the deletion of an already existing file, and the modification of another file + public void testWorkspacePatch_Delete(){ + //Note the order that exists in the array of expected results is based purely on the order of the files in the patch + 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 ); //$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$ + } + + //Test applying the reverse of a workspace deletion patch + public void testWorkspacePatch_Delete_Reverse(){ + //Note the order that exists in the array of expected results is based purely on the order of the files in the patch + 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 ); //$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$ + } + + + //Test changing private BufferedReader getReader(String name) { InputStream resourceAsStream= getClass().getResourceAsStream("patchdata/" + name); //$NON-NLS-1$ InputStreamReader reader2= new InputStreamReader(resourceAsStream); @@ -69,7 +107,7 @@ public class PatchTest extends TestCase { LineReader lr= new LineReader(getReader(old)); List inLines= lr.readLines(); - Patcher patcher= new Patcher(); + WorkspacePatcher patcher= new WorkspacePatcher(); try { patcher.parse(getReader(patch)); } catch (IOException e) { @@ -93,4 +131,51 @@ public class PatchTest extends TestCase { for (int i= 0; i < expected.length; i++) Assert.assertEquals(expected[i], result[i]); } + + /** + * Parses a workspace patch and applies the diffs to the appropriate files + * @param originalFiles + * @param patch + * @param expectedOutcomeFiles + * @p + */ + private void patchWorkspace(String[] originalFiles, String patch, String[] expectedOutcomeFiles, boolean reverse) { + + //ensure that we have the same number of input files as we have expected files + Assert.assertEquals(originalFiles.length, expectedOutcomeFiles.length); + + //Parse the passed in patch and extract all the Diffs + WorkspacePatcher patcher= new WorkspacePatcher(); + try { + patcher.parse(getReader(patch)); + patcher.setReversed(reverse); + } catch (IOException e) { + e.printStackTrace(); + } + + //Sort the diffs by project + Diff[] diffs= patcher.getDiffs(); + + //Iterate through all of the original files, apply the diffs that belong to the file and compare + //with the corresponding outcome file + for (int i = 0; i < originalFiles.length; i++) { + LineReader lr= new LineReader(getReader(originalFiles[i])); + List inLines= lr.readLines(); + + + List failedHunks= new ArrayList(); + patcher.patch(diffs[i], inLines, failedHunks); + + LineReader expectedContents= new LineReader(getReader(expectedOutcomeFiles[i])); + List expectedLines= expectedContents.readLines(); + + Object[] expected= expectedLines.toArray(); + Object[] result= inLines.toArray(); + + Assert.assertEquals(expected.length, result.length); + + for (int j= 0; j < expected.length; j++) + Assert.assertEquals(expected[j], result[j]); + } + } } diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchAddition.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchAddition.txt new file mode 100644 index 000000000..f101fe5f1 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchAddition.txt @@ -0,0 +1,19 @@ +package testPkg; + +public class TestProjectClass1 { + + public TestProjectClass1(){}; + + /** + * Does something - how much is dictated by howMuchSomething, the something + * is called nameOfSomething + * + * @param howMuchSomething + * @param nameOfSomething + */ + public void doSomething(int howMuchSomething, String nameOfSomething){ + //does something + } + + +} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchAddition2.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchAddition2.txt new file mode 100644 index 000000000..280555aec --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchAddition2.txt @@ -0,0 +1,12 @@ +package testPkg2; + +public class TestProject2Class2 { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + } + +} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchDelete1.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchDelete1.txt new file mode 100644 index 000000000..85c0cf3e4 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchDelete1.txt @@ -0,0 +1,18 @@ +package testPkg2; + +public class YetAnotherClass extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchDelete2.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchDelete2.txt new file mode 100644 index 000000000..4b18e1bbc --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchDelete2.txt @@ -0,0 +1,11 @@ +package testPkg; + +public abstract class TestProject2Class2 { + + public TestProject2Class2(){ + + } + + protected abstract void doAnything(); + +} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod1.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod1.txt new file mode 100644 index 000000000..a00a46b2b --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod1.txt @@ -0,0 +1,11 @@ +package testPkg2; + +public abstract class TestProject2Class2 { + + public TestProject2Class2(){ + + } + + protected abstract void doAnything(); + +} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod2.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod2.txt new file mode 100644 index 000000000..085662cb7 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod2.txt @@ -0,0 +1,35 @@ +package testPkg; + +public class TestProjectClass1 implements IWorkspacePatcherTest { + + public TestProjectClass1(){}; + + /** + * Does something - how much is dictated by howMuchSomething, the something + * is called nameOfSomething + * + * @param howMuchSomething + * @param nameOfSomething + */ + public void doSomething(int howMuchSomething, String nameOfSomething){ + //does something + } + + public boolean canApplyToMultipleProjects() { + // TODO Auto-generated method stub + return false; + } + + public void doSomething() { + // TODO Auto-generated method stub + + } + + public boolean isWorkspacePatcherTest() { + // TODO Auto-generated method stub + return false; + } + + + +} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod3.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod3.txt new file mode 100644 index 000000000..15cb4e489 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_workspacePatchMod3.txt @@ -0,0 +1,10 @@ +package testPkg; + +public interface IWorkspacePatcherTest { + + public boolean canApplyToMultipleProjects(); + + public void doSomething(); + + public boolean isWorkspacePatcherTest(); +} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchAddition.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchAddition.txt new file mode 100644 index 000000000..c336caa33 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchAddition.txt @@ -0,0 +1,48 @@ +### Eclipse Workspace Patch 1.0 +#P TestProject2 +Index: testPkg2/TestProject2Class2.java +=================================================================== +RCS file: testPkg2/TestProject2Class2.java +diff -N testPkg2/TestProject2Class2.java +--- /dev/null 1 Jan 1970 00:00:00 -0000 ++++ testPkg2/TestProject2Class2.java 1 Jan 1970 00:00:00 -0000 +@@ -0,0 +1,12 @@ ++package testPkg2; ++ ++public class TestProject2Class2 { ++ ++ /** ++ * @param args ++ */ ++ public static void main(String[] args) { ++ // TODO Auto-generated method stub ++ } ++ ++} +#P TestProject +Index: testPkg/TestProjectClass1.java +=================================================================== +RCS file: testPkg/TestProjectClass1.java +diff -N testPkg/TestProjectClass1.java +--- /dev/null 1 Jan 1970 00:00:00 -0000 ++++ testPkg/TestProjectClass1.java 1 Jan 1970 00:00:00 -0000 +@@ -0,0 +1,19 @@ ++package testPkg; ++ ++public class TestProjectClass1 { ++ ++ public TestProjectClass1(){}; ++ ++ /** ++ * Does something - how much is dictated by howMuchSomething, the something ++ * is called nameOfSomething ++ * ++ * @param howMuchSomething ++ * @param nameOfSomething ++ */ ++ public void doSomething(int howMuchSomething, String nameOfSomething){ ++ //does something ++ } ++ ++ ++} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchDelete.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchDelete.txt new file mode 100644 index 000000000..dea65ff07 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchDelete.txt @@ -0,0 +1,106 @@ +### Eclipse Workspace Patch 1.0 +#P TestProject +Index: testPkg/TestProjectClass1.java +=================================================================== +RCS file: testPkg/TestProjectClass1.java +diff -N testPkg/TestProjectClass1.java +--- testPkg/TestProjectClass1.java 6 Sep 2005 18:42:52 -0000 1.4 ++++ /dev/null 1 Jan 1970 00:00:00 -0000 +@@ -1,35 +0,0 @@ +-package testPkg; +- +-public class TestProjectClass1 implements IWorkspacePatcherTest { +- +- public TestProjectClass1(){}; +- +- /** +- * Does something - how much is dictated by howMuchSomething, the something +- * is called nameOfSomething +- * +- * @param howMuchSomething +- * @param nameOfSomething +- */ +- public void doSomething(int howMuchSomething, String nameOfSomething){ +- //does something +- } +- +- public boolean canApplyToMultipleProjects() { +- // TODO Auto-generated method stub +- return false; +- } +- +- public void doSomething() { +- // TODO Auto-generated method stub +- +- } +- +- public boolean isWorkspacePatcherTest() { +- // TODO Auto-generated method stub +- return false; +- } +- +- +- +-} +Index: testPkg/TestProject2Class2.java +=================================================================== +RCS file: testPkg/TestProject2Class2.java +diff -N testPkg/TestProject2Class2.java +--- /dev/null 1 Jan 1970 00:00:00 -0000 ++++ testPkg/TestProject2Class2.java 1 Jan 1970 00:00:00 -0000 +@@ -0,0 +1,11 @@ ++package testPkg; ++ ++public abstract class TestProject2Class2 { ++ ++ public TestProject2Class2(){ ++ ++ } ++ ++ protected abstract void doAnything(); ++ ++} +#P TestProject2 +Index: testPkg2/TestProject2Class2.java +=================================================================== +RCS file: testPkg2/TestProject2Class2.java +diff -N testPkg2/TestProject2Class2.java +--- testPkg2/TestProject2Class2.java 6 Sep 2005 18:42:53 -0000 1.4 ++++ /dev/null 1 Jan 1970 00:00:00 -0000 +@@ -1,11 +0,0 @@ +-package testPkg2; +- +-public abstract class TestProject2Class2 { +- +- public TestProject2Class2(){ +- +- } +- +- protected abstract void doAnything(); +- +-} +Index: testPkg2/YetAnotherClass.java +=================================================================== +RCS file: testPkg2/YetAnotherClass.java +diff -N testPkg2/YetAnotherClass.java +--- /dev/null 1 Jan 1970 00:00:00 -0000 ++++ testPkg2/YetAnotherClass.java 1 Jan 1970 00:00:00 -0000 +@@ -0,0 +1,18 @@ ++package testPkg2; ++ ++public class YetAnotherClass extends Exception { ++ ++ /** ++ * ++ */ ++ private static final long serialVersionUID = 1L; ++ ++ /** ++ * @param args ++ */ ++ public static void main(String[] args) { ++ // TODO Auto-generated method stub ++ ++ } ++ ++} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchMod.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchMod.txt new file mode 100644 index 000000000..be4fea8e4 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_workspacePatchMod.txt @@ -0,0 +1,83 @@ +### Eclipse Workspace Patch 1.0 +#P TestProject2 +Index: testPkg2/TestProject2Class2.java +=================================================================== +RCS file: /home/bog/repo/TestProject2/testPkg2/TestProject2Class2.java,v +retrieving revision 1.3 +diff -u -r1.3 TestProject2Class2.java +--- testPkg2/TestProject2Class2.java 6 Sep 2005 16:13:09 -0000 1.3 ++++ testPkg2/TestProject2Class2.java 6 Sep 2005 18:17:06 -0000 +@@ -1,12 +1,11 @@ + package testPkg2; + +-public class TestProject2Class2 { ++public abstract class TestProject2Class2 { + +- /** +- * @param args +- */ +- public static void main(String[] args) { +- // TODO Auto-generated method stub +- } ++ public TestProject2Class2(){ ++ ++ } + ++ protected abstract void doAnything(); ++ + } +#P TestProject +Index: testPkg/TestProjectClass1.java +=================================================================== +RCS file: /home/bog/repo/TestProject/testPkg/TestProjectClass1.java,v +retrieving revision 1.3 +diff -u -r1.3 TestProjectClass1.java +--- testPkg/TestProjectClass1.java 6 Sep 2005 16:13:09 -0000 1.3 ++++ testPkg/TestProjectClass1.java 6 Sep 2005 18:17:06 -0000 +@@ -1,6 +1,6 @@ + package testPkg; + +-public class TestProjectClass1 { ++public class TestProjectClass1 implements IWorkspacePatcherTest { + + public TestProjectClass1(){}; + +@@ -15,5 +15,21 @@ + //does something + } + ++ public boolean canApplyToMultipleProjects() { ++ // TODO Auto-generated method stub ++ return false; ++ } ++ ++ public void doSomething() { ++ // TODO Auto-generated method stub ++ ++ } ++ ++ public boolean isWorkspacePatcherTest() { ++ // TODO Auto-generated method stub ++ return false; ++ } ++ ++ + + } +Index: testPkg/IWorkspacePatcherTest.java +=================================================================== +RCS file: testPkg/IWorkspacePatcherTest.java +diff -N testPkg/IWorkspacePatcherTest.java +--- /dev/null 1 Jan 1970 00:00:00 -0000 ++++ testPkg/IWorkspacePatcherTest.java 1 Jan 1970 00:00:00 -0000 +@@ -0,0 +1,10 @@ ++package testPkg; ++ ++public interface IWorkspacePatcherTest { ++ ++ public boolean canApplyToMultipleProjects(); ++ ++ public void doSomething(); ++ ++ public boolean isWorkspacePatcherTest(); ++} |