diff options
Diffstat (limited to 'tests/org.eclipse.compare.tests/src/org')
7 files changed, 198 insertions, 0 deletions
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java index fd6e7ca56..4c1c85a48 100644 --- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java @@ -26,6 +26,7 @@ public class AllTests { suite.addTestSuite(StreamMergerTest.class); suite.addTestSuite(DocLineComparatorTest.class); suite.addTestSuite(FilterTest.class); + suite.addTestSuite(PatchTest.class); //$JUnit-END$ return suite; } 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 new file mode 100644 index 000000000..4bee45b4b --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.compare.tests; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +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; + +public class PatchTest extends TestCase { + + public PatchTest(String name) { + super(name); + } + + protected void setUp() throws Exception { + // empty + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testContext0Patch() { + patch("patch0.txt"); //$NON-NLS-1$ + } + + public void testContext1Patch() { + patch("patch1.txt"); //$NON-NLS-1$ + } + + public void testContext3Patch() { + patch("patch3.txt"); //$NON-NLS-1$ + } + + private BufferedReader getReader(String name) { + InputStream resourceAsStream= getClass().getResourceAsStream("patchdata/" + name); //$NON-NLS-1$ + InputStreamReader reader2= new InputStreamReader(resourceAsStream); + return new BufferedReader(reader2); + } + + private void patch(String patch) { + + LineReader lr= new LineReader(getReader("old.txt")); //$NON-NLS-1$ + List inLines= lr.readLines(); + + Patcher patcher= new Patcher(); + try { + patcher.parse(getReader(patch)); + } catch (IOException e) { + e.printStackTrace(); + } + + Diff[] diffs= patcher.getDiffs(); + Assert.assertEquals(diffs.length, 1); + + List failedHunks= new ArrayList(); + patcher.patch(diffs[0], inLines, failedHunks); + + LineReader expectedContents= new LineReader(getReader("new.txt")); //$NON-NLS-1$ + List expectedLines= expectedContents.readLines(); + + Object[] expected= expectedLines.toArray(); + Object[] result= inLines.toArray(); + + Assert.assertEquals(expected.length, result.length); + + for (int i= 0; i < expected.length; i++) + Assert.assertEquals(expected[i], result[i]); + } +} diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/new.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/new.txt new file mode 100644 index 000000000..c13853369 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/new.txt @@ -0,0 +1,25 @@ +[a] +[b] +[c] +[c1] +[c2] +[d] +[e] +[f] +[g] +[h] +[i1] +[j] +[k] +[l] +[m] +[n] +[p] +[q] +[r] +[s] +[s1] +[t] +[u] +[v] +[w] diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/old.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/old.txt new file mode 100644 index 000000000..1b8d4c7ca --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/old.txt @@ -0,0 +1,23 @@ +[a] +[b] +[c] +[d] +[e] +[f] +[g] +[h] +[i] +[j] +[k] +[l] +[m] +[n] +[o] +[p] +[q] +[r] +[s] +[t] +[u] +[v] +[w] diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch0.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch0.txt new file mode 100644 index 000000000..4fbbf3e33 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch0.txt @@ -0,0 +1,12 @@ +--- old.txt 2005-05-07 00:16:20.000000000 +0200 ++++ new.txt 2005-05-07 00:16:32.000000000 +0200 +@@ -3,0 +4,2 @@ ++[c1] ++[c2] +@@ -9 +11 @@ +-[i] ++[i1] +@@ -15 +16,0 @@ +-[o] +@@ -19,0 +21 @@ ++[s1] diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch1.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch1.txt new file mode 100644 index 000000000..ebe945ea1 --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch1.txt @@ -0,0 +1,20 @@ +--- old.txt 2005-05-07 00:16:20.000000000 +0200 ++++ new.txt 2005-05-07 00:16:32.000000000 +0200 +@@ -3,2 +3,4 @@ + [c] ++[c1] ++[c2] + [d] +@@ -8,3 +10,3 @@ + [h] +-[i] ++[i1] + [j] +@@ -14,3 +16,2 @@ + [n] +-[o] + [p] +@@ -19,2 +20,3 @@ + [s] ++[s1] + [t] diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch3.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch3.txt new file mode 100644 index 000000000..e31be0bdc --- /dev/null +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch3.txt @@ -0,0 +1,29 @@ +--- old.txt 2005-05-07 00:16:20.000000000 +0200 ++++ new.txt 2005-05-07 00:16:32.000000000 +0200 +@@ -1,22 +1,24 @@ + [a] + [b] + [c] ++[c1] ++[c2] + [d] + [e] + [f] + [g] + [h] +-[i] ++[i1] + [j] + [k] + [l] + [m] + [n] +-[o] + [p] + [q] + [r] + [s] ++[s1] + [t] + [u] + [v] |