Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2005-05-09 11:25:30 +0000
committerAndre Weinand2005-05-09 11:25:30 +0000
commit1bd9ae8c1b9d6fc516d74e89aeef94f1e49e68aa (patch)
tree4d41145d3673336dc393965f0db73f07243feda4
parent8b0e452ef02579e75125268789f6ce264d2851c8 (diff)
downloadeclipse.platform.team-1bd9ae8c1b9d6fc516d74e89aeef94f1e49e68aa.tar.gz
eclipse.platform.team-1bd9ae8c1b9d6fc516d74e89aeef94f1e49e68aa.tar.xz
eclipse.platform.team-1bd9ae8c1b9d6fc516d74e89aeef94f1e49e68aa.zip
added more test cases for patcher
-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/LineReaderTest.java44
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/PatchTest.java20
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/empty.txt0
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/normal.txt3
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/unterminated.txt3
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/addition.txt0
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/context.txt (renamed from tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/old.txt)0
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_addition.txt9
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_addition2.txt9
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_context.txt (renamed from tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/new.txt)0
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_addition.txt12
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_addition2.txt13
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_context0.txt (renamed from tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch0.txt)0
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_context1.txt (renamed from tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch1.txt)0
-rw-r--r--tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_context3.txt (renamed from tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch3.txt)0
16 files changed, 108 insertions, 6 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 4c1c85a48..e78120938 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
@@ -23,6 +23,7 @@ public class AllTests {
TestSuite suite= new TestSuite("Test for org.eclipse.compare.tests"); //$NON-NLS-1$
//$JUnit-BEGIN$
//suite.addTestSuite(UITest.class);
+ suite.addTestSuite(LineReaderTest.class);
suite.addTestSuite(StreamMergerTest.class);
suite.addTestSuite(DocLineComparatorTest.class);
suite.addTestSuite(FilterTest.class);
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
new file mode 100644
index 000000000..a047d3ab4
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/LineReaderTest.java
@@ -0,0 +1,44 @@
+package org.eclipse.compare.tests;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.List;
+
+import org.eclipse.compare.internal.patch.LineReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class LineReaderTest extends TestCase {
+
+ public void testReadEmpty() {
+ LineReader lr= new LineReader(getReader("empty.txt")); //$NON-NLS-1$
+ List inLines= lr.readLines();
+ Assert.assertEquals(0, inLines.size());
+ }
+
+ public void testReadNormal() {
+ LineReader lr= new LineReader(getReader("normal.txt")); //$NON-NLS-1$
+ List inLines= lr.readLines();
+ Assert.assertEquals(3, inLines.size());
+ Assert.assertEquals("[1]\n", inLines.get(0)); //$NON-NLS-1$
+ Assert.assertEquals("[2]\n", inLines.get(1)); //$NON-NLS-1$
+ Assert.assertEquals("[3]\n", inLines.get(2)); //$NON-NLS-1$
+ }
+
+ public void testReadUnterminatedLastLine() {
+ LineReader lr= new LineReader(getReader("unterminated.txt")); //$NON-NLS-1$
+ List inLines= lr.readLines();
+ Assert.assertEquals(3, inLines.size());
+ Assert.assertEquals("[1]\n", inLines.get(0)); //$NON-NLS-1$
+ Assert.assertEquals("[2]\n", inLines.get(1)); //$NON-NLS-1$
+ Assert.assertEquals("[3]", inLines.get(2)); //$NON-NLS-1$
+ }
+
+ private BufferedReader getReader(String name) {
+ InputStream resourceAsStream= getClass().getResourceAsStream("linereaderdata/" + name); //$NON-NLS-1$
+ InputStreamReader reader2= new InputStreamReader(resourceAsStream);
+ return new BufferedReader(reader2);
+ }
+}
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 4bee45b4b..14fab809e 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
@@ -38,16 +38,24 @@ public class PatchTest extends TestCase {
super.tearDown();
}
+ 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$
+ }
+
public void testContext0Patch() {
- patch("patch0.txt"); //$NON-NLS-1$
+ patch("context.txt", "patch_context0.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testContext1Patch() {
- patch("patch1.txt"); //$NON-NLS-1$
+ patch("context.txt", "patch_context1.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testContext3Patch() {
- patch("patch3.txt"); //$NON-NLS-1$
+ patch("context.txt", "patch_context3.txt", "exp_context.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
private BufferedReader getReader(String name) {
@@ -56,9 +64,9 @@ public class PatchTest extends TestCase {
return new BufferedReader(reader2);
}
- private void patch(String patch) {
+ private void patch(String old, String patch, String expt) {
- LineReader lr= new LineReader(getReader("old.txt")); //$NON-NLS-1$
+ LineReader lr= new LineReader(getReader(old));
List inLines= lr.readLines();
Patcher patcher= new Patcher();
@@ -74,7 +82,7 @@ public class PatchTest extends TestCase {
List failedHunks= new ArrayList();
patcher.patch(diffs[0], inLines, failedHunks);
- LineReader expectedContents= new LineReader(getReader("new.txt")); //$NON-NLS-1$
+ LineReader expectedContents= new LineReader(getReader(expt));
List expectedLines= expectedContents.readLines();
Object[] expected= expectedLines.toArray();
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/empty.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/empty.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/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/src/org/eclipse/compare/tests/linereaderdata/normal.txt
new file mode 100644
index 000000000..274901976
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/normal.txt
@@ -0,0 +1,3 @@
+[1]
+[2]
+[3]
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/unterminated.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/unterminated.txt
new file mode 100644
index 000000000..ebc22e8bf
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/linereaderdata/unterminated.txt
@@ -0,0 +1,3 @@
+[1]
+[2]
+[3] \ No newline at end of file
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/addition.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/addition.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/addition.txt
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/context.txt
index 1b8d4c7ca..1b8d4c7ca 100644
--- 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/context.txt
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_addition.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_addition.txt
new file mode 100644
index 000000000..d97f8d461
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_addition.txt
@@ -0,0 +1,9 @@
+[1]
+[2]
+[3]
+[4]
+[5]
+[6]
+[7]
+[8]
+[9]
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_addition2.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_addition2.txt
new file mode 100644
index 000000000..e58329b43
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/exp_addition2.txt
@@ -0,0 +1,9 @@
+[1]
+[2]
+[3]
+[4]
+[5]
+[6]
+[7]
+[8]
+[9] \ No newline at end of file
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/exp_context.txt
index c13853369..c13853369 100644
--- 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/exp_context.txt
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_addition.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_addition.txt
new file mode 100644
index 000000000..4ec0df92e
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_addition.txt
@@ -0,0 +1,12 @@
+--- addition.txt 2005-05-09 12:14:04.000000000 +0200
++++ exp_addition.txt 2005-05-09 13:15:34.000000000 +0200
+@@ -0,0 +1,9 @@
++[1]
++[2]
++[3]
++[4]
++[5]
++[6]
++[7]
++[8]
++[9]
diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_addition2.txt b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_addition2.txt
new file mode 100644
index 000000000..409e0b84d
--- /dev/null
+++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/patchdata/patch_addition2.txt
@@ -0,0 +1,13 @@
+--- addition.txt 2005-05-09 12:14:04.000000000 +0200
++++ exp_addition.txt 2005-05-09 12:29:24.000000000 +0200
+@@ -0,0 +1,9 @@
++[1]
++[2]
++[3]
++[4]
++[5]
++[6]
++[7]
++[8]
++[9]
+\ No newline at end of file
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/patch_context0.txt
index 4fbbf3e33..4fbbf3e33 100644
--- 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/patch_context0.txt
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/patch_context1.txt
index ebe945ea1..ebe945ea1 100644
--- 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/patch_context1.txt
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/patch_context3.txt
index e31be0bdc..e31be0bdc 100644
--- 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/patch_context3.txt

Back to the top