Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2009-02-24 12:13:32 +0000
committerTomasz Zarna2009-02-24 12:13:32 +0000
commitd73580ccfe6ce867144efb5b54ede39e16e27770 (patch)
treee548f7aa1e59ac205faa9d7d5816baecf74f14f6
parent2cba557debd386be7e64f2bfbbe8ece496ddc35c (diff)
downloadeclipse.platform.team-d73580ccfe6ce867144efb5b54ede39e16e27770.tar.gz
eclipse.platform.team-d73580ccfe6ce867144efb5b54ede39e16e27770.tar.xz
eclipse.platform.team-d73580ccfe6ce867144efb5b54ede39e16e27770.zip
Rebasing.
-rw-r--r--tests/org.eclipse.compare.tests/META-INF/MANIFEST.MF1
-rw-r--r--tests/org.eclipse.compare.tests/build.properties5
-rw-r--r--tests/org.eclipse.compare.tests/linereaderdata/empty.txt (renamed from tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/empty.txt)0
-rw-r--r--tests/org.eclipse.compare.tests/linereaderdata/normal.txt (renamed from tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/normal.txt)0
-rw-r--r--tests/org.eclipse.compare.tests/linereaderdata/unterminated.txt (renamed from tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/unterminated.txt)0
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/context_full.txt52
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/exp_addHunks.txt59
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/exp_createFilePatch.txt27
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/exp_hunkFilter.txt24
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/exp_modifyHunks.txt28
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/exp_removeHunks.txt51
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/patch_addHunks.txt34
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/patch_createHunk0.txt19
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/patch_createHunk1.txt26
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/patch_createHunk2.txt12
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/patch_createHunk3.txt14
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/patch_hunkFilter.txt25
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/patch_modifyHunks.txt25
-rw-r--r--tests/org.eclipse.compare.tests/patchdata/patch_removeHunks.txt55
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/AllTests.java1
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java5
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java27
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java296
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java229
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUtils.java170
25 files changed, 1064 insertions, 121 deletions
diff --git a/tests/org.eclipse.compare.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.compare.tests/META-INF/MANIFEST.MF
index 522ebb28d..57bd9eedb 100644
--- a/tests/org.eclipse.compare.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.compare.tests/META-INF/MANIFEST.MF
@@ -20,5 +20,4 @@ Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Export-Package: org.eclipse.compare.tests,
- org.eclipse.compare.tests.linereaderdata,
org.eclipse.compare.tests.performance
diff --git a/tests/org.eclipse.compare.tests/build.properties b/tests/org.eclipse.compare.tests/build.properties
index 826ffe7b8..c19c08f4a 100644
--- a/tests/org.eclipse.compare.tests/build.properties
+++ b/tests/org.eclipse.compare.tests/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2008 IBM Corporation and others.
+# Copyright (c) 2000, 2009 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
@@ -13,7 +13,8 @@ bin.includes = plugin.properties,\
about.html,\
*.jar,\
META-INF/,\
- patchdata/
+ patchdata/,\
+ linereaderdata/
src.includes = about.html
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/empty.txt b/tests/org.eclipse.compare.tests/linereaderdata/empty.txt
index e69de29bb..e69de29bb 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/empty.txt
+++ b/tests/org.eclipse.compare.tests/linereaderdata/empty.txt
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/normal.txt b/tests/org.eclipse.compare.tests/linereaderdata/normal.txt
index 274901976..274901976 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/normal.txt
+++ b/tests/org.eclipse.compare.tests/linereaderdata/normal.txt
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/unterminated.txt b/tests/org.eclipse.compare.tests/linereaderdata/unterminated.txt
index ebc22e8bf..ebc22e8bf 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/unterminated.txt
+++ b/tests/org.eclipse.compare.tests/linereaderdata/unterminated.txt
diff --git a/tests/org.eclipse.compare.tests/patchdata/context_full.txt b/tests/org.eclipse.compare.tests/patchdata/context_full.txt
new file mode 100644
index 000000000..ff06fcb44
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/context_full.txt
@@ -0,0 +1,52 @@
+[a]
+[b]
+[c]
+[d]
+[e]
+[f]
+[g]
+[h]
+[i]
+[j]
+[k]
+[l]
+[m]
+[n]
+[o]
+[p]
+[q]
+[r]
+[s]
+[t]
+[u]
+[v]
+[w]
+[x]
+[y]
+[z]
+[A]
+[B]
+[C]
+[D]
+[E]
+[F]
+[G]
+[H]
+[I]
+[J]
+[K]
+[L]
+[M]
+[N]
+[O]
+[P]
+[Q]
+[R]
+[S]
+[T]
+[U]
+[V]
+[W]
+[X]
+[Y]
+[Z] \ No newline at end of file
diff --git a/tests/org.eclipse.compare.tests/patchdata/exp_addHunks.txt b/tests/org.eclipse.compare.tests/patchdata/exp_addHunks.txt
new file mode 100644
index 000000000..3d09ef1ad
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/exp_addHunks.txt
@@ -0,0 +1,59 @@
+[a1]
+[a2]
+[a]
+[b]
+[c]
+[d]
+[d1]
+[d2]
+[d3]
+[d4]
+[e]
+[f]
+[g]
+[h]
+[i]
+[j]
+[k]
+[l]
+[m]
+[n]
+[o]
+[p]
+[q]
+[r]
+[s]
+[t]
+[u]
+[v]
+[y]
+[z]
+[A]
+[B]
+[C]
+[D]
+[E]
+[F]
+[G]
+[H]
+[I]
+[J]
+[K]
+[L]
+[N]
+[N1]
+[N2]
+[O]
+[P]
+[Q]
+[R]
+[S]
+[T]
+[U]
+[V]
+[W]
+[W1]
+[W2]
+[W3]
+[Y]
+[Z] \ No newline at end of file
diff --git a/tests/org.eclipse.compare.tests/patchdata/exp_createFilePatch.txt b/tests/org.eclipse.compare.tests/patchdata/exp_createFilePatch.txt
new file mode 100644
index 000000000..7d137a8e3
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/exp_createFilePatch.txt
@@ -0,0 +1,27 @@
+[a1]
+[a2]
+[a3]
+[a]
+[b]
+[c]
+[f]
+[g]
+[h]
+[h1]
+[i]
+[j]
+[j1]
+[j2]
+[k]
+[l]
+[m]
+[n]
+[o]
+[p]
+[q]
+[r]
+[s]
+[t]
+[u]
+[v]
+[w]
diff --git a/tests/org.eclipse.compare.tests/patchdata/exp_hunkFilter.txt b/tests/org.eclipse.compare.tests/patchdata/exp_hunkFilter.txt
new file mode 100644
index 000000000..135627bcc
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/exp_hunkFilter.txt
@@ -0,0 +1,24 @@
+[a]
+[b]
+[c]
+[c1]
+[c2]
+[d]
+[e]
+[f]
+[g]
+[h]
+[i1]
+[j]
+[k]
+[l]
+[m]
+[n]
+[p]
+[q]
+[r]
+[s]
+[t]
+[u]
+[v]
+[w]
diff --git a/tests/org.eclipse.compare.tests/patchdata/exp_modifyHunks.txt b/tests/org.eclipse.compare.tests/patchdata/exp_modifyHunks.txt
new file mode 100644
index 000000000..c3e64d74b
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/exp_modifyHunks.txt
@@ -0,0 +1,28 @@
+[a]
+[b]
+[c]
+[d]
+[d1]
+[d2]
+[d3]
+[d4]
+[e]
+[f]
+[g]
+[h]
+[i1]
+[j]
+[k]
+[l]
+[m]
+[n]
+[o]
+[p]
+[q]
+[r]
+[s]
+[s1]
+[t]
+[u]
+[v]
+[w]
diff --git a/tests/org.eclipse.compare.tests/patchdata/exp_removeHunks.txt b/tests/org.eclipse.compare.tests/patchdata/exp_removeHunks.txt
new file mode 100644
index 000000000..68fc86fcd
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/exp_removeHunks.txt
@@ -0,0 +1,51 @@
+[a]
+[b]
+[c]
+[d]
+[e]
+[f]
+[g]
+[h]
+[i]
+[j]
+[k]
+[l]
+[m]
+[n]
+[o]
+[p]
+[q]
+[r]
+[s]
+[t]
+[u]
+[v]
+[y]
+[z]
+[A]
+[B]
+[C]
+[D]
+[E]
+[F]
+[I]
+[J]
+[J1]
+[K]
+[L]
+[M]
+[N]
+[O]
+[P]
+[Q]
+[R]
+[S]
+[T]
+[U]
+[V]
+[W]
+[W1]
+[W2]
+[W3]
+[Y]
+[Z] \ No newline at end of file
diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_addHunks.txt b/tests/org.eclipse.compare.tests/patchdata/patch_addHunks.txt
new file mode 100644
index 000000000..4c75b3d6e
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/patch_addHunks.txt
@@ -0,0 +1,34 @@
+### Eclipse Workspace Patch 1.0
+#P Bug202944
+Index: tmp/context_full.txt
+===================================================================
+RCS file: /TEST/Bug202944/tmp/context_full.txt,v
+retrieving revision 1.1
+diff -u -r1.1 context_full.txt
+--- tmp/context_full.txt 23 Feb 2009 09:39:56 -0000 1.1
++++ tmp/context_full.txt 23 Feb 2009 09:40:51 -0000
+@@ -1,3 +1,5 @@
++[a1]
++[a2]
+ [a]
+ [b]
+ [c]
+@@ -20,8 +22,6 @@
+ [t]
+ [u]
+ [v]
+-[w]
+-[x]
+ [y]
+ [z]
+ [A]
+@@ -47,6 +47,8 @@
+ [U]
+ [V]
+ [W]
+-[X]
++[W1]
++[W2]
++[W3]
+ [Y]
+ [Z]
diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_createHunk0.txt b/tests/org.eclipse.compare.tests/patchdata/patch_createHunk0.txt
new file mode 100644
index 000000000..f1de92aaf
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/patch_createHunk0.txt
@@ -0,0 +1,19 @@
+### Eclipse Workspace Patch 1.0
+#P Bug202944
+Index: tmp/list.txt
+===================================================================
+RCS file: /TEST/Bug202944/tmp/list.txt,v
+retrieving revision 1.2
+diff -u -r1.2 list.txt
+--- tmp/list.txt 20 Feb 2009 11:02:27 -0000 1.2
++++ tmp/list.txt 20 Feb 2009 11:03:29 -0000
+@@ -1,6 +1,8 @@
++[a1]
++[a2]
++[a3]
+ [a]
+ [b]
+-[c]
+ [d]
+ [e]
+ [f]
diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_createHunk1.txt b/tests/org.eclipse.compare.tests/patchdata/patch_createHunk1.txt
new file mode 100644
index 000000000..7b0fb2930
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/patch_createHunk1.txt
@@ -0,0 +1,26 @@
+### Eclipse Workspace Patch 1.0
+#P Bug202944
+Index: tmp/list.txt
+===================================================================
+RCS file: /TEST/Bug202944/tmp/list.txt,v
+retrieving revision 1.2
+diff -u -r1.2 list.txt
+--- tmp/list.txt 20 Feb 2009 11:02:27 -0000 1.2
++++ tmp/list.txt 20 Feb 2009 11:32:47 -0000
+@@ -1,13 +1,14 @@
+ [a]
+ [b]
+-[c]
+ [d]
+-[e]
+ [f]
+ [g]
+ [h]
++[h1]
+ [i]
+ [j]
++[j1]
++[j2]
+ [k]
+ [l]
+ [m]
diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_createHunk2.txt b/tests/org.eclipse.compare.tests/patchdata/patch_createHunk2.txt
new file mode 100644
index 000000000..2f64be799
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/patch_createHunk2.txt
@@ -0,0 +1,12 @@
+### Eclipse Workspace Patch 1.0
+#P Bug202944
+Index: tmp/a.txt
+===================================================================
+RCS file: tmp/a.txt
+diff -N tmp/a.txt
+--- /dev/null 1 Jan 1970 00:00:00 -0000
++++ tmp/a.txt 1 Jan 1970 00:00:00 -0000
+@@ -0,0 +1,3 @@
++[aa]
++[bb]
++[cc]
diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_createHunk3.txt b/tests/org.eclipse.compare.tests/patchdata/patch_createHunk3.txt
new file mode 100644
index 000000000..0bec1a205
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/patch_createHunk3.txt
@@ -0,0 +1,14 @@
+### Eclipse Workspace Patch 1.0
+#P Bug202944
+Index: tmp/a.txt
+===================================================================
+RCS file: /TEST/Bug202944/tmp/a.txt,v
+retrieving revision 1.1
+diff -u -r1.1 a.txt
+--- tmp/a.txt 20 Feb 2009 11:37:35 -0000 1.1
++++ tmp/a.txt 20 Feb 2009 11:38:40 -0000
+@@ -1,4 +0,0 @@
+-[aa]
+-[bb]
+-[cc]
+-[dd]
diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_hunkFilter.txt b/tests/org.eclipse.compare.tests/patchdata/patch_hunkFilter.txt
new file mode 100644
index 000000000..fe0831c4a
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/patch_hunkFilter.txt
@@ -0,0 +1,25 @@
+--- 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]
+@@ -29,2 +32,3 @@
+ [yy]
++[xx]
+ [yy]
+ \ No newline at end of file
diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_modifyHunks.txt b/tests/org.eclipse.compare.tests/patchdata/patch_modifyHunks.txt
new file mode 100644
index 000000000..917b62b9b
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/patch_modifyHunks.txt
@@ -0,0 +1,25 @@
+--- 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]
+@@ -29,2 +31,3 @@
+ [yy]
++[xx]
+ [yy]
+ \ No newline at end of file
diff --git a/tests/org.eclipse.compare.tests/patchdata/patch_removeHunks.txt b/tests/org.eclipse.compare.tests/patchdata/patch_removeHunks.txt
new file mode 100644
index 000000000..860e39ad7
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/patchdata/patch_removeHunks.txt
@@ -0,0 +1,55 @@
+### Eclipse Workspace Patch 1.0
+#P Bug202944
+Index: tmp/context_full.txt
+===================================================================
+RCS file: /TEST/Bug202944/tmp/context_full.txt,v
+retrieving revision 1.1
+diff -u -r1.1 context_full.txt
+--- tmp/context_full.txt 23 Feb 2009 09:39:56 -0000 1.1
++++ tmp/context_full.txt 23 Feb 2009 10:03:51 -0000
+@@ -1,3 +1,5 @@
++[a1]
++[a2]
+ [a]
+ [b]
+ [c]
+@@ -11,6 +13,8 @@
+ [k]
+ [l]
+ [m]
++[m1]
++[m2]
+ [n]
+ [o]
+ [p]
+@@ -20,8 +24,6 @@
+ [t]
+ [u]
+ [v]
+-[w]
+-[x]
+ [y]
+ [z]
+ [A]
+@@ -30,10 +32,9 @@
+ [D]
+ [E]
+ [F]
+-[G]
+-[H]
+ [I]
+ [J]
++[J1]
+ [K]
+ [L]
+ [M]
+@@ -47,6 +48,8 @@
+ [U]
+ [V]
+ [W]
+-[X]
++[W1]
++[W2]
++[W3]
+ [Y]
+ [Z]
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 168fa50ed..204b224bf 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
@@ -28,6 +28,7 @@ public class AllTests {
suite.addTestSuite(DocLineComparatorTest.class);
suite.addTestSuite(FilterTest.class);
suite.addTestSuite(PatchTest.class);
+ suite.addTestSuite(PatchBuilderTest.class);
suite.addTestSuite(AsyncExecTests.class);
suite.addTestSuite(DiffTest.class);
suite.addTestSuite(FileDiffResultTest.class);
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java
index e21c7ec9a..aba379831 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/FileDiffResultTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 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
@@ -30,6 +30,7 @@ import org.eclipse.compare.patch.WorkspacePatcherUI;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -78,7 +79,7 @@ public class FileDiffResultTest extends WorkspaceTest {
assertNotNull(filePatch);
assertEquals(1, filePatch.length);
- IFilePatchResult filePatchResult = filePatch[0].apply(null,
+ IFilePatchResult filePatchResult = filePatch[0].apply((IStorage)null,
patchConfiguration, nullProgressMonitor);
assertTrue(filePatchResult.hasMatches());
assertEquals(0, filePatchResult.getRejects().length);
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
index 553ee0075..0e2357435 100644
--- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2009 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
@@ -11,15 +11,20 @@
package org.eclipse.compare.tests;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.List;
-import org.eclipse.compare.internal.core.patch.LineReader;
-
import junit.framework.Assert;
import junit.framework.TestCase;
+import org.eclipse.compare.internal.core.patch.LineReader;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
public class LineReaderTest extends TestCase {
public void testReadEmpty() {
@@ -54,8 +59,18 @@ public class LineReaderTest extends TestCase {
}
private BufferedReader getReader(String name) {
- InputStream resourceAsStream= getClass().getResourceAsStream("linereaderdata/" + name); //$NON-NLS-1$
- InputStreamReader reader2= new InputStreamReader(resourceAsStream);
- return new BufferedReader(reader2);
+ IPath path = new Path("linereaderdata/" + name);
+ URL url;
+ try {
+ url = new URL(CompareTestPlugin.getDefault().getBundle().getEntry("/"), path.toString());
+ InputStream resourceAsStream = url.openStream();
+ InputStreamReader reader2 = new InputStreamReader(resourceAsStream);
+ return new BufferedReader(reader2);
+ } catch (MalformedURLException e) {
+ fail(e.getMessage());
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ return null;
}
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java
new file mode 100644
index 000000000..177f82030
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchBuilderTest.java
@@ -0,0 +1,296 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.compare.internal.core.patch.FileDiff;
+import org.eclipse.compare.internal.core.patch.Hunk;
+import org.eclipse.compare.internal.core.patch.LineReader;
+import org.eclipse.compare.internal.patch.FileDiffWrapper;
+import org.eclipse.compare.patch.ApplyPatchOperation;
+import org.eclipse.compare.patch.IFilePatch;
+import org.eclipse.compare.patch.IFilePatch2;
+import org.eclipse.compare.patch.IFilePatchResult;
+import org.eclipse.compare.patch.IHunk;
+import org.eclipse.compare.patch.PatchBuilder;
+import org.eclipse.compare.patch.PatchConfiguration;
+import org.eclipse.compare.tests.PatchUtils.StringStorage;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+public class PatchBuilderTest extends TestCase {
+
+ public PatchBuilderTest() {
+
+ }
+
+ protected void setUp() throws Exception {
+ // Nothing to do
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testModifyHunks() throws CoreException, IOException {
+ IStorage patchStorage = new StringStorage("patch_modifyHunks.txt");
+ IStorage contextStorage = new StringStorage("context.txt");
+ IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
+ assertEquals(1, patches.length);
+ IHunk[] hunksBefore = patches[0].getHunks();
+ assertEquals(5, hunksBefore.length);
+
+ String[] lines = new String[] { " [d]", "+[d1]", "+[d2]", "+[d3]",
+ "+[d4]", " [e]" };
+ addLineDelimiters(lines);
+ IHunk[] toAdd = new IHunk[] { PatchBuilder.createHunk(3, lines) };
+ IFilePatch2 filePatch = PatchBuilder.addHunks(patches[0], toAdd);
+
+ IHunk[] toRemove = new IHunk[] { hunksBefore[0], hunksBefore[2] };
+ filePatch = PatchBuilder.removeHunks(filePatch, toRemove);
+
+ IHunk[] hunksAfter = filePatch.getHunks();
+ assertEquals(4, hunksAfter.length);
+ assertEquals(3, ((Hunk) hunksAfter[0]).getStart(false));
+ assertEquals(3, ((Hunk) hunksAfter[0]).getStart(true));
+ assertEquals(7, ((Hunk) hunksAfter[1]).getStart(false));
+ assertEquals(11, ((Hunk) hunksAfter[1]).getStart(true));
+ assertEquals(18, ((Hunk) hunksAfter[2]).getStart(false));
+ assertEquals(22, ((Hunk) hunksAfter[2]).getStart(true));
+ assertEquals(28, ((Hunk) hunksAfter[3]).getStart(false));
+ assertEquals(33, ((Hunk) hunksAfter[3]).getStart(true));
+
+ FileDiffWrapper wrapper = new FileDiffWrapper((FileDiff) filePatch);
+ IFilePatchResult result = wrapper.apply(contextStorage,
+ new PatchConfiguration(), new NullProgressMonitor());
+
+ IHunk[] rejects = result.getRejects();
+ assertEquals(1, rejects.length);
+
+ InputStream actual = result.getPatchedContents();
+
+ LineReader lr = new LineReader(PatchUtils
+ .getReader("exp_modifyHunks.txt"));
+ List inLines = lr.readLines();
+ String expected = LineReader.createString(false, inLines);
+
+ assertEquals(expected, PatchUtils.asString(actual));
+ }
+
+ public void testAddHunks() throws CoreException, IOException {
+ IStorage patchStorage = new StringStorage("patch_addHunks.txt");
+ IStorage contextStorage = new StringStorage("context_full.txt");
+ IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
+ assertEquals(1, patches.length);
+ IHunk[] hunksBefore = patches[0].getHunks();
+ assertEquals(3, hunksBefore.length);
+
+ String[] lines0 = new String[] { " [d]", "+[d1]", "+[d2]", "+[d3]",
+ "+[d4]", " [e]" };
+ addLineDelimiters(lines0);
+ IHunk hunk0 = PatchBuilder.createHunk(3, lines0);
+
+ String[] lines1 = new String[] { " [K]", " [L]", "-[M]", " [N]",
+ "+[N1]", "+[N2]", " [O]", " [P]" };
+ addLineDelimiters(lines1);
+ IHunk hunk1 = PatchBuilder.createHunk(36, lines1);
+
+ IHunk[] toAdd = new IHunk[] { hunk0, hunk1 };
+ IFilePatch2 filePatch = PatchBuilder.addHunks(patches[0], toAdd);
+
+ IHunk[] hunksAfter = filePatch.getHunks();
+ assertEquals(5, hunksAfter.length);
+ assertEquals(0, ((Hunk) hunksAfter[0]).getStart(false));
+ assertEquals(0, ((Hunk) hunksAfter[0]).getStart(true));
+ assertEquals(3, ((Hunk) hunksAfter[1]).getStart(false));
+ assertEquals(5, ((Hunk) hunksAfter[1]).getStart(true));
+ assertEquals(19, ((Hunk) hunksAfter[2]).getStart(false));
+ assertEquals(25, ((Hunk) hunksAfter[2]).getStart(true));
+ assertEquals(36, ((Hunk) hunksAfter[3]).getStart(false));
+ assertEquals(40, ((Hunk) hunksAfter[3]).getStart(true));
+ assertEquals(46, ((Hunk) hunksAfter[4]).getStart(false));
+ assertEquals(51, ((Hunk) hunksAfter[4]).getStart(true));
+
+ FileDiffWrapper wrapper = new FileDiffWrapper((FileDiff) filePatch);
+ IFilePatchResult result = wrapper.apply(contextStorage,
+ new PatchConfiguration(), new NullProgressMonitor());
+
+ IHunk[] rejects = result.getRejects();
+ assertEquals(0, rejects.length);
+
+ InputStream actual = result.getPatchedContents();
+
+ LineReader lr = new LineReader(PatchUtils.getReader("exp_addHunks.txt"));
+ List inLines = lr.readLines();
+ String expected = LineReader.createString(false, inLines);
+
+ assertEquals(expected, PatchUtils.asString(actual));
+ }
+
+ public void testRemoveHunks() throws CoreException, IOException {
+ IStorage patchStorage = new StringStorage("patch_removeHunks.txt");
+ IStorage contextStorage = new StringStorage("context_full.txt");
+ IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
+ assertEquals(1, patches.length);
+ IHunk[] hunksBefore = patches[0].getHunks();
+ assertEquals(5, hunksBefore.length);
+
+ IHunk[] toRemove = new IHunk[] { hunksBefore[0], hunksBefore[1] };
+ IFilePatch2 filePatch = PatchBuilder.removeHunks(patches[0], toRemove);
+
+ IHunk[] hunksAfter = filePatch.getHunks();
+ assertEquals(3, hunksAfter.length);
+ assertEquals(19, ((Hunk) hunksAfter[0]).getStart(false));
+ assertEquals(19, ((Hunk) hunksAfter[0]).getStart(true));
+ assertEquals(29, ((Hunk) hunksAfter[1]).getStart(false));
+ assertEquals(27, ((Hunk) hunksAfter[1]).getStart(true));
+ assertEquals(46, ((Hunk) hunksAfter[2]).getStart(false));
+ assertEquals(43, ((Hunk) hunksAfter[2]).getStart(true));
+
+ FileDiffWrapper wrapper = new FileDiffWrapper((FileDiff) filePatch);
+ IFilePatchResult result = wrapper.apply(contextStorage,
+ new PatchConfiguration(), new NullProgressMonitor());
+
+ IHunk[] rejects = result.getRejects();
+ assertEquals(0, rejects.length);
+
+ InputStream actual = result.getPatchedContents();
+
+ LineReader lr = new LineReader(PatchUtils
+ .getReader("exp_removeHunks.txt"));
+ List inLines = lr.readLines();
+ String expected = LineReader.createString(false, inLines);
+
+ assertEquals(expected, PatchUtils.asString(actual));
+ }
+
+ public void testCreateFilePatch() throws CoreException, IOException {
+ IStorage contextStorage = new StringStorage("context.txt");
+
+ String[] lines0 = new String[] { "+[a1]", "+[a2]", "+[a3]", " [a]" };
+ addLineDelimiters(lines0);
+ Hunk hunk0 = (Hunk) PatchBuilder.createHunk(0, lines0);
+
+ String[] lines1 = new String[] { " [b]", " [c]", "-[d]", "-[e]",
+ " [f]", " [g]", " [h]", "+[h1]", " [i]", " [j]", "+[j1]",
+ "+[j2]", " [k]", " [l]" };
+ addLineDelimiters(lines1);
+ Hunk hunk1 = (Hunk) PatchBuilder.createHunk(1, lines1);
+
+ IHunk[] hunks = new IHunk[] { hunk1, hunk0 };
+
+ IFilePatch2 filePatch = PatchBuilder.createFilePatch(new Path(""),
+ IFilePatch2.DATE_UNKNOWN, new Path(""),
+ IFilePatch2.DATE_UNKNOWN, hunks);
+
+ assertEquals(2, filePatch.getHunks().length);
+ assertEquals(hunk0, filePatch.getHunks()[0]);
+ assertEquals(hunk1, filePatch.getHunks()[1]);
+
+ FileDiffWrapper wrapper = new FileDiffWrapper((FileDiff) filePatch);
+ IFilePatchResult result = wrapper.apply(contextStorage,
+ new PatchConfiguration(), new NullProgressMonitor());
+
+ InputStream actual = result.getPatchedContents();
+
+ LineReader lr = new LineReader(PatchUtils
+ .getReader("exp_createFilePatch.txt"));
+ List inLines = lr.readLines();
+ String expected = LineReader.createString(false, inLines);
+
+ assertEquals(expected, PatchUtils.asString(actual));
+ }
+
+ public void testCreateHunk0() throws CoreException {
+ IStorage patch = new StringStorage("patch_createHunk0.txt");
+ IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
+ assertEquals(1, filePatches.length);
+ assertEquals(1, filePatches[0].getHunks().length);
+
+ String[] lines = new String[] { "+[a1]", "+[a2]", "+[a3]", " [a]",
+ " [b]", "-[c]", " [d]", " [e]", " [f]" };
+ addLineDelimiters(lines);
+ Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
+
+ assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
+ }
+
+ public void testCreateHunk1() throws CoreException {
+ IStorage patch = new StringStorage("patch_createHunk1.txt");
+ IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
+ assertEquals(1, filePatches.length);
+ assertEquals(1, filePatches[0].getHunks().length);
+
+ String[] lines = new String[] { " [a]", " [b]", "-[c]", " [d]", "-[e]",
+ " [f]", " [g]", " [h]", "+[h1]", " [i]", " [j]", "+[j1]",
+ "+[j2]", " [k]", " [l]", " [m]" };
+ addLineDelimiters(lines);
+ Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
+
+ assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
+ }
+
+ public void testCreateHunk2() throws CoreException {
+ IStorage patch = new StringStorage("patch_createHunk2.txt");
+ IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
+ assertEquals(1, filePatches.length);
+ assertEquals(1, filePatches[0].getHunks().length);
+
+ String[] lines = new String[] { "+[aa]", "+[bb]", "+[cc]" };
+ addLineDelimiters(lines);
+ Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
+
+ assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
+ }
+
+ public void testCreateHunk3() throws CoreException {
+ IStorage patch = new StringStorage("patch_createHunk3.txt");
+ IFilePatch[] filePatches = ApplyPatchOperation.parsePatch(patch);
+ assertEquals(1, filePatches.length);
+ assertEquals(1, filePatches[0].getHunks().length);
+
+ String[] lines = new String[] { "-[aa]", "-[bb]", "-[cc]", "-[dd]" };
+ addLineDelimiters(lines);
+ Hunk hunk = (Hunk) PatchBuilder.createHunk(0, lines);
+
+ assertHunkEquals(hunk, (Hunk) filePatches[0].getHunks()[0]);
+ }
+
+ private void assertHunkEquals(Hunk h1, Hunk h2) {
+ String[] l1 = h1.getLines();
+ String[] l2 = h2.getLines();
+ assertEquals(l1.length, l2.length);
+ for (int i = 0; i < l1.length; i++) {
+ assertFalse(l1[i] == null && l2[i] != null);
+ assertEquals(l1[i], (l2[i]));
+ }
+ assertEquals(h1.getStart(false), h2.getStart(false));
+ assertEquals(h1.getStart(true), h2.getStart(true));
+ assertEquals(h1.getLength(false), h2.getLength(false));
+ assertEquals(h1.getLength(true), h2.getLength(true));
+ assertEquals(h1.getHunkType(false), h2.getHunkType(false));
+ assertEquals(h1.getHunkType(true), h2.getHunkType(true));
+ }
+
+ private void addLineDelimiters(String[] lines) {
+ for (int i = 0; i < lines.length; i++) {
+ lines[i] = lines[i] + "\r\n";
+ }
+ }
+
+}
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 3a71cdd0a..80884e150 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 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
@@ -15,7 +15,6 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -42,12 +41,16 @@ import org.eclipse.compare.internal.core.patch.LineReader;
import org.eclipse.compare.internal.patch.WorkspacePatcher;
import org.eclipse.compare.patch.ApplyPatchOperation;
import org.eclipse.compare.patch.IFilePatch;
+import org.eclipse.compare.patch.IFilePatchResult;
+import org.eclipse.compare.patch.IHunk;
+import org.eclipse.compare.patch.IHunkFilter;
import org.eclipse.compare.patch.PatchConfiguration;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
@@ -56,36 +59,9 @@ public class PatchTest extends AbstractPatchTest {
private static final String PATCHDATA = "patchdata";
private static final String PATCH_CONFIGURATION = "patchConfiguration.properties";
-
+
Properties defaultPatchProperties;
-
- class FileStorage implements IStorage {
- File file;
- public FileStorage(File file) {
- this.file = file;
- }
- public InputStream getContents() throws CoreException {
- try {
- return new FileInputStream(file);
- } catch (FileNotFoundException e) {
- // ignore, should never happen
- }
- return null;
- }
- public IPath getFullPath() {
- return new Path(file.getAbsolutePath());
- }
- public String getName() {
- return file.getName();
- }
- public boolean isReadOnly() {
- return true;
- }
- public Object getAdapter(Class adapter) {
- return null;
- }
- }
-
+
class JarEntryStorage implements IStorage {
JarEntry jarEntry;
JarFile jarFile;
@@ -114,7 +90,7 @@ public class PatchTest extends AbstractPatchTest {
return null;
}
}
-
+
class PatchTestConfiguration {
String subfolderName;
PatchConfiguration pc;
@@ -124,7 +100,7 @@ public class PatchTest extends AbstractPatchTest {
String[] actualFileNames;
// TODO: getters, setters
}
-
+
public PatchTest(String name) {
super(name);
defaultPatchProperties = new Properties();
@@ -145,11 +121,11 @@ public class PatchTest extends AbstractPatchTest {
protected void tearDown() throws Exception {
super.tearDown();
}
-
+
public void testCreatePatch() throws CoreException, IOException {
patch("addition.txt", "patch_addition.txt", "exp_addition.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
-
+
public void testUnterminatedCreatePatch() throws CoreException, IOException {
patch("addition.txt", "patch_addition2.txt", "exp_addition2.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
@@ -165,7 +141,38 @@ public class PatchTest extends AbstractPatchTest {
public void testContext3Patch() throws CoreException, IOException {
patch("context.txt", "patch_context3.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
-
+
+ public void testHunkFilter() throws CoreException, IOException {
+ IStorage patchStorage = new StringStorage("patch_hunkFilter.txt");
+ IStorage expStorage = new StringStorage("context.txt");
+ IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
+ assertEquals(1, patches.length);
+ IHunk[] hunks = patches[0].getHunks();
+ assertEquals(5, hunks.length);
+ PatchConfiguration pc = new PatchConfiguration();
+ final IHunk toFilterOut = hunks[3];
+ pc.addHunkFilter(new IHunkFilter() {
+ public boolean select(IHunk hunk) {
+ return hunk != toFilterOut;
+ }
+ });
+ IFilePatchResult result = patches[0].apply(expStorage, pc,
+ new NullProgressMonitor());
+ IHunk[] rejects = result.getRejects();
+ assertEquals(2, rejects.length);
+ boolean aFiltered = pc.getHunkFilters()[0].select(rejects[0]);
+ boolean bFiltered = pc.getHunkFilters()[0].select(rejects[1]);
+ assertTrue((aFiltered && !bFiltered) || (!aFiltered && bFiltered));
+
+ InputStream actual = result.getPatchedContents();
+
+ LineReader lr = new LineReader(PatchUtils.getReader("exp_hunkFilter.txt"));
+ List inLines = lr.readLines();
+ String expected = LineReader.createString(false, inLines);
+
+ assertEquals(expected, PatchUtils.asString(actual));
+ }
+
public void testContext3PatchWithHeader() throws CoreException, IOException {
patch("context.txt", "patch_context3_header.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IStorage patchStorage = new StringStorage("patch_context3_header.txt");
@@ -178,81 +185,82 @@ public class PatchTest extends AbstractPatchTest {
expected.add("UID: 42\n");
assertEquals(LineReader.createString(false, expected), LineReader.createString(false, lines));
}
-
+
public void testDateUnknown() throws CoreException {
IStorage patchStorage = new StringStorage("patch_dateunknown.txt");
IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
assertEquals(IFilePatch.DATE_UNKNOWN, patches[0].getBeforeDate());
assertEquals(IFilePatch.DATE_UNKNOWN, patches[0].getAfterDate());
}
-
+
public void testDateError() throws CoreException {
IStorage patchStorage = new StringStorage("patch_dateerror.txt");
IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
assertEquals(IFilePatch.DATE_UNKNOWN, patches[0].getBeforeDate());
assertEquals(IFilePatch.DATE_UNKNOWN, patches[0].getAfterDate());
}
-
+
public void testDateKnown() throws CoreException {
IStorage patchStorage = new StringStorage("patch_datevalid.txt");
IFilePatch[] patches = ApplyPatchOperation.parsePatch(patchStorage);
assertFalse(IFilePatch.DATE_UNKNOWN == patches[0].getBeforeDate());
assertFalse(IFilePatch.DATE_UNKNOWN == patches[0].getAfterDate());
}
-
- //Test creation of new workspace patch
+
+ //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
+ //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, 0); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
-
- //Test applying the reverse of workspace creation patch
+
+ //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
+ //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, 0); //$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
+ //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, 0 ); //$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
+ //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, 0 ); //$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
+ //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, 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$
}
-
+
//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
+ //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, 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$
}
-
+
// Keeps track of the failures
private List failures = new ArrayList();
-
+
public void testPatchdataSubfolders() throws IOException, CoreException {
- URL patchdataUrl = new URL(getBundle().getEntry("/"), new Path(PATCHDATA).toString());
+ URL patchdataUrl = new URL(PatchUtils.getBundle().getEntry("/"),
+ new Path(PatchUtils.PATCHDATA).toString());
patchdataUrl = FileLocator.resolve(patchdataUrl);
-
+
Map map = null;
if (patchdataUrl.getProtocol().equals("file")) {
map = extractNamesForFileProtocol(patchdataUrl);
} else if (patchdataUrl.getProtocol().equals("jar")) {
- map = extractNamesForJarProtocol(patchdataUrl);
+ map = extractNamesForJarProtocol(patchdataUrl);
} else {
fail("Unknown protocol");
}
assertNotNull(map);
-
+
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
String sf = (String) iterator.next(); // subfolder
PatchTestConfiguration ptc = (PatchTestConfiguration) map.get(sf);
@@ -261,10 +269,11 @@ public class PatchTest extends AbstractPatchTest {
String[] expectedFiles = ptc.expectedFileNames;
String[] actualFiles = ptc.actualFileNames;
PatchConfiguration pc = ptc.pc;
-
+
// create a message to distinguish tests from different subfolders
- String msg = "Test for subfolder [" + PATCHDATA + "/" + sf + "] failed.";
-
+ String msg = "Test for subfolder [" + PatchUtils.PATCHDATA + "/"
+ + sf + "] failed.";
+
try {
// test with expected result
patchWorkspace(msg, originalFiles, patch, expectedFiles, pc);
@@ -281,11 +290,11 @@ public class PatchTest extends AbstractPatchTest {
continue; // continue with a next subfolder
}
failures.add(new AssertionFailedError(
- "\npatchWorkspace should fail for folder [" + PATCHDATA
- + "/" + sf + "]."));
+ "\npatchWorkspace should fail for folder ["
+ + PatchUtils.PATCHDATA + "/" + sf + "]."));
}
}
-
+
if (failures.isEmpty())
return;
@@ -293,7 +302,7 @@ public class PatchTest extends AbstractPatchTest {
throw (AssertionFailedError) failures.get(0);
StringBuffer sb = new StringBuffer(
- "Failures occured while testing data from patchdata subfolder (Please check log for further details):");
+ "Failures occured while testing data from patchdata subfolder (Please check log for further details):");
for (Iterator iterator = failures.iterator(); iterator.hasNext();) {
AssertionFailedError error = (AssertionFailedError) iterator.next();
log("org.eclipse.compare.tests", error);
@@ -301,17 +310,17 @@ public class PatchTest extends AbstractPatchTest {
}
throw new AssertionFailedError(sb.toString());
}
-
+
// both copy-pasted from CoreTest
-
+
private void log(String pluginID, IStatus status) {
Platform.getLog(Platform.getBundle(pluginID)).log(status);
}
-
+
private void log(String pluginID, Throwable e) {
log(pluginID, new Status(IStatus.ERROR, pluginID, IStatus.ERROR, "Error", e)); //$NON-NLS-1$
}
-
+
/**
* @param patchdataUrl
* @return A map with subfolder name as a key and an array of objects as a
@@ -324,16 +333,16 @@ public class PatchTest extends AbstractPatchTest {
* @throws CoreException
*/
private Map extractNamesForJarProtocol(URL patchdataUrl) throws IOException,
- CoreException {
+ CoreException {
JarFile jarFile = ((JarURLConnection) patchdataUrl.openConnection()).getJarFile();
-
+
// look for the patchdata folder entry
String patchdataName = null;
Enumeration entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement();
String entryName = entry.getName();
- if (entryName.endsWith("/" + PATCHDATA + "/")) {
+ if (entryName.endsWith("/" + PatchUtils.PATCHDATA + "/")) {
patchdataName = entryName;
break;
}
@@ -341,7 +350,7 @@ public class PatchTest extends AbstractPatchTest {
// patchdata folder not found
if (patchdataName == null)
return null;
-
+
Map result = new HashMap();
entries = jarFile.entries();
while (entries.hasMoreElements()) {
@@ -354,23 +363,23 @@ public class PatchTest extends AbstractPatchTest {
if (patchConf != null) {
JarEntryStorage jes = new JarEntryStorage(entry,jarFile);
Properties properties = new Properties();
- try {
- properties.load(jes.getContents());
- } catch (IOException e) {
- fail("IOException occured while loading the Patch Configuration file for "+entryName.toString());
- }
- processProperties(result, properties, entryName);
+ try {
+ properties.load(jes.getContents());
+ } catch (IOException e) {
+ fail("IOException occured while loading the Patch Configuration file for "+entryName.toString());
+ }
+ processProperties(result, properties, entryName);
} else {
processProperties(result, defaultPatchProperties, entryName);
}
}
- }
+ }
}
return result;
}
-
+
private Map extractNamesForFileProtocol(URL patchdataUrl)
- throws CoreException {
+ throws CoreException {
Map result = new HashMap(); // configuration map
@@ -378,27 +387,27 @@ public class PatchTest extends AbstractPatchTest {
File patchdataFolderFile = patchdataFolderPath.toFile();
assertTrue(patchdataFolderFile.isDirectory());
File[] listOfSubfolders = patchdataFolderFile
- .listFiles(new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- });
+ .listFiles(new FileFilter() {
+ public boolean accept(File pathname) {
+ return pathname.isDirectory();
+ }
+ });
for (int i = 0; i < listOfSubfolders.length; i++) {
File subfolder = listOfSubfolders[i];
Path pcPath = new Path(subfolder.getPath() + "/" + PATCH_CONFIGURATION);
File pcFile = pcPath.toFile();
-
+
if (subfolder.getName().equals("CVS"))
continue;
if (pcFile.exists()) {
Properties properties = new Properties();
- try {
- properties.load(new FileInputStream(pcFile));
- } catch (IOException e) {
- fail("IOException occured while loading the Patch Configuration file for "
+ try {
+ properties.load(new FileInputStream(pcFile));
+ } catch (IOException e) {
+ fail("IOException occured while loading the Patch Configuration file for "
+ subfolder.toString());
- }
- processProperties(result, properties, subfolder.getName());
+ }
+ processProperties(result, properties, subfolder.getName());
} else {
processProperties(result, defaultPatchProperties, subfolder.getName());
}
@@ -418,7 +427,7 @@ public class PatchTest extends AbstractPatchTest {
String arfp = p.getProperty("actualResultFile", null);
if (arfp != null)
arf = arfp.split(",");
- int fuzzFactor = Integer.parseInt(p.getProperty("fuzzFactor", "0"));
+ int fuzzFactor = Integer.parseInt(p.getProperty("fuzzFactor", "0"));
boolean ignoreWhitespace = Boolean.valueOf(p.getProperty("ignoreWhitespace", "false")).booleanValue();
int prefixSegmentStrip = Integer.parseInt(p.getProperty("prefixSegmentStrip", "0"));
boolean reversed = Boolean.valueOf(p.getProperty("reversed", "false")).booleanValue();
@@ -477,37 +486,37 @@ public class PatchTest extends AbstractPatchTest {
* should be calculated automatically.
*/
private void patchWorkspace(String msg, String[] originalFiles, String patch, String[] expectedOutcomeFiles, PatchConfiguration patchConfiguration) {
-
+
//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.getConfiguration().setFuzz(patchConfiguration.getFuzz());
patcher.getConfiguration().setIgnoreWhitespace(patchConfiguration.isIgnoreWhitespace());
patcher.getConfiguration().setPrefixSegmentStripCount(patchConfiguration.getPrefixSegmentStripCount());
- patcher.parse(getReader(patch));
+ patcher.parse(PatchUtils.getReader(patch));
patcher.setReversed(patchConfiguration.isReversed());
} catch (IOException e) {
e.printStackTrace();
}
-
- //Sort the diffs by project
+
+ //Sort the diffs by project
FileDiff[] 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]));
+ for (int i = 0; i < originalFiles.length; i++) {
+ LineReader lr= new LineReader(PatchUtils.getReader(originalFiles[i]));
List inLines= lr.readLines();
-
+
FileDiffResult diffResult = patcher.getDiffResult(diffs[i]);
diffResult.patch(inLines, null);
-
- LineReader expectedContents= new LineReader(getReader(expectedOutcomeFiles[i]));
+
+ LineReader expectedContents= new LineReader(PatchUtils.getReader(expectedOutcomeFiles[i]));
List expectedLines= expectedContents.readLines();
-
+
Object[] expected= expectedLines.toArray();
String resultString = LineReader.createString(patcher.isPreserveLineDelimeters(), inLines);
@@ -515,9 +524,9 @@ public class PatchTest extends AbstractPatchTest {
Object[] result = resultReader.readLines().toArray();
Assert.assertEquals(msg, expected.length, result.length);
-
+
for (int j= 0; j < expected.length; j++)
Assert.assertEquals(msg, expected[j], result[j]);
}
- }
+ }
}
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUtils.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUtils.java
new file mode 100644
index 000000000..1dbd16c74
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchUtils.java
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import junit.framework.Assert;
+
+import org.eclipse.compare.internal.Utilities;
+import org.eclipse.compare.patch.PatchConfiguration;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.osgi.framework.Bundle;
+
+public class PatchUtils {
+
+ public static final String PATCHDATA = "patchdata";
+
+ public static class PatchTestConfiguration {
+ String subfolderName;
+ PatchConfiguration pc;
+ String patchFileName;
+ String[] originalFileNames;
+ String[] expectedFileNames;
+ String[] actualFileNames;
+ }
+
+ public static class StringStorage implements IStorage {
+ String fileName;
+
+ public StringStorage(String old) {
+ fileName = old;
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ public String getName() {
+ return fileName;
+ }
+
+ public IPath getFullPath() {
+ return null;
+ }
+
+ public InputStream getContents() throws CoreException {
+ return new BufferedInputStream(asInputStream(fileName));
+ }
+ }
+
+ public static class FileStorage implements IStorage {
+ File file;
+
+ public FileStorage(File file) {
+ this.file = file;
+ }
+
+ public InputStream getContents() throws CoreException {
+ try {
+ return new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ // ignore, should never happen
+ }
+ return null;
+ }
+
+ public IPath getFullPath() {
+ return new Path(file.getAbsolutePath());
+ }
+
+ public String getName() {
+ return file.getName();
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+ }
+
+ public static class JarEntryStorage implements IStorage {
+ JarEntry jarEntry;
+ JarFile jarFile;
+
+ public JarEntryStorage(JarEntry jarEntry, JarFile jarFile) {
+ this.jarEntry = jarEntry;
+ this.jarFile = jarFile;
+ }
+
+ public InputStream getContents() throws CoreException {
+ try {
+ return jarFile.getInputStream(jarEntry);
+ } catch (IOException e) {
+ // ignore, should never happen
+ }
+ return null;
+ }
+
+ public IPath getFullPath() {
+ return new Path(jarFile.getName());
+ }
+
+ public String getName() {
+ return jarEntry.getName();
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+ }
+
+ public static String asString(InputStream exptStream) throws IOException {
+ return Utilities.readString(exptStream, ResourcesPlugin.getEncoding());
+ }
+
+ public static InputStream asInputStream(String name) {
+ IPath path = new Path(PATCHDATA).append(name);
+ try {
+ URL url = new URL(getBundle().getEntry("/"), path.toString());
+ return url.openStream();
+ } catch (IOException e) {
+ Assert.fail("Failed while reading " + name);
+ return null; // never reached
+ }
+ }
+
+ public static BufferedReader getReader(String name) {
+ InputStream resourceAsStream = PatchUtils.asInputStream(name);
+ InputStreamReader reader2 = new InputStreamReader(resourceAsStream);
+ return new BufferedReader(reader2);
+ }
+
+ public static Bundle getBundle() {
+ return CompareTestPlugin.getDefault().getBundle();
+ }
+
+}

Back to the top