Remove System.out.println from RevWalkFilterTest
[egit/chris.git] / org.spearce.jgit.test / tst / org / spearce / jgit / patch / PatchCcTest.java
blob9e8650b5b1205ec3fa49372b2341fa3539cea44f
1 /*
2 * Copyright (C) 2008, Google Inc.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org.spearce.jgit.patch;
40 import java.io.IOException;
41 import java.io.InputStream;
43 import org.spearce.jgit.lib.FileMode;
45 import junit.framework.TestCase;
47 public class PatchCcTest extends TestCase {
48 public void testParse_OneFileCc() throws IOException {
49 final Patch p = parseTestPatchFile();
50 assertEquals(1, p.getFiles().size());
51 assertTrue(p.getErrors().isEmpty());
53 final CombinedFileHeader cfh = (CombinedFileHeader) p.getFiles().get(0);
55 assertEquals("org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java",
56 cfh.getNewName());
57 assertEquals(cfh.getNewName(), cfh.getOldName());
59 assertEquals(98, cfh.startOffset);
61 assertEquals(2, cfh.getParentCount());
62 assertSame(cfh.getOldId(0), cfh.getOldId());
63 assertEquals("169356b", cfh.getOldId(0).name());
64 assertEquals("dd8c317", cfh.getOldId(1).name());
65 assertEquals("fd85931", cfh.getNewId().name());
67 assertSame(cfh.getOldMode(0), cfh.getOldMode());
68 assertSame(FileMode.REGULAR_FILE, cfh.getOldMode(0));
69 assertSame(FileMode.REGULAR_FILE, cfh.getOldMode(1));
70 assertSame(FileMode.EXECUTABLE_FILE, cfh.getNewMode());
71 assertSame(FileHeader.ChangeType.MODIFY, cfh.getChangeType());
72 assertSame(FileHeader.PatchType.UNIFIED, cfh.getPatchType());
74 assertEquals(1, cfh.getHunks().size());
76 final CombinedHunkHeader h = cfh.getHunks().get(0);
78 assertSame(cfh, h.getFileHeader());
79 assertEquals(346, h.startOffset);
80 assertEquals(764, h.endOffset);
82 assertSame(h.getOldImage(0), h.getOldImage());
83 assertSame(cfh.getOldId(0), h.getOldImage(0).getId());
84 assertSame(cfh.getOldId(1), h.getOldImage(1).getId());
86 assertEquals(55, h.getOldImage(0).getStartLine());
87 assertEquals(12, h.getOldImage(0).getLineCount());
88 assertEquals(3, h.getOldImage(0).getLinesAdded());
89 assertEquals(0, h.getOldImage(0).getLinesDeleted());
91 assertEquals(163, h.getOldImage(1).getStartLine());
92 assertEquals(13, h.getOldImage(1).getLineCount());
93 assertEquals(2, h.getOldImage(1).getLinesAdded());
94 assertEquals(0, h.getOldImage(1).getLinesDeleted());
96 assertEquals(163, h.getNewStartLine());
97 assertEquals(15, h.getNewLineCount());
99 assertEquals(10, h.getLinesContext());
103 public void testParse_CcNewFile() throws IOException {
104 final Patch p = parseTestPatchFile();
105 assertEquals(1, p.getFiles().size());
106 assertTrue(p.getErrors().isEmpty());
108 final CombinedFileHeader cfh = (CombinedFileHeader) p.getFiles().get(0);
110 assertSame(FileHeader.DEV_NULL, cfh.getOldName());
111 assertEquals("d", cfh.getNewName());
113 assertEquals(187, cfh.startOffset);
115 assertEquals(2, cfh.getParentCount());
116 assertSame(cfh.getOldId(0), cfh.getOldId());
117 assertEquals("0000000", cfh.getOldId(0).name());
118 assertEquals("0000000", cfh.getOldId(1).name());
119 assertEquals("4bcfe98", cfh.getNewId().name());
121 assertSame(cfh.getOldMode(0), cfh.getOldMode());
122 assertSame(FileMode.MISSING, cfh.getOldMode(0));
123 assertSame(FileMode.MISSING, cfh.getOldMode(1));
124 assertSame(FileMode.REGULAR_FILE, cfh.getNewMode());
125 assertSame(FileHeader.ChangeType.ADD, cfh.getChangeType());
126 assertSame(FileHeader.PatchType.UNIFIED, cfh.getPatchType());
128 assertEquals(1, cfh.getHunks().size());
130 final CombinedHunkHeader h = cfh.getHunks().get(0);
132 assertSame(cfh, h.getFileHeader());
133 assertEquals(273, h.startOffset);
134 assertEquals(300, h.endOffset);
136 assertSame(h.getOldImage(0), h.getOldImage());
137 assertSame(cfh.getOldId(0), h.getOldImage(0).getId());
138 assertSame(cfh.getOldId(1), h.getOldImage(1).getId());
140 assertEquals(1, h.getOldImage(0).getStartLine());
141 assertEquals(0, h.getOldImage(0).getLineCount());
142 assertEquals(1, h.getOldImage(0).getLinesAdded());
143 assertEquals(0, h.getOldImage(0).getLinesDeleted());
145 assertEquals(1, h.getOldImage(1).getStartLine());
146 assertEquals(0, h.getOldImage(1).getLineCount());
147 assertEquals(1, h.getOldImage(1).getLinesAdded());
148 assertEquals(0, h.getOldImage(1).getLinesDeleted());
150 assertEquals(1, h.getNewStartLine());
151 assertEquals(1, h.getNewLineCount());
153 assertEquals(0, h.getLinesContext());
157 public void testParse_CcDeleteFile() throws IOException {
158 final Patch p = parseTestPatchFile();
159 assertEquals(1, p.getFiles().size());
160 assertTrue(p.getErrors().isEmpty());
162 final CombinedFileHeader cfh = (CombinedFileHeader) p.getFiles().get(0);
164 assertEquals("a", cfh.getOldName());
165 assertSame(FileHeader.DEV_NULL, cfh.getNewName());
167 assertEquals(187, cfh.startOffset);
169 assertEquals(2, cfh.getParentCount());
170 assertSame(cfh.getOldId(0), cfh.getOldId());
171 assertEquals("7898192", cfh.getOldId(0).name());
172 assertEquals("2e65efe", cfh.getOldId(1).name());
173 assertEquals("0000000", cfh.getNewId().name());
175 assertSame(cfh.getOldMode(0), cfh.getOldMode());
176 assertSame(FileMode.REGULAR_FILE, cfh.getOldMode(0));
177 assertSame(FileMode.REGULAR_FILE, cfh.getOldMode(1));
178 assertSame(FileMode.MISSING, cfh.getNewMode());
179 assertSame(FileHeader.ChangeType.DELETE, cfh.getChangeType());
180 assertSame(FileHeader.PatchType.UNIFIED, cfh.getPatchType());
182 assertTrue(cfh.getHunks().isEmpty());
185 private Patch parseTestPatchFile() throws IOException {
186 final String patchFile = getName() + ".patch";
187 final InputStream in = getClass().getResourceAsStream(patchFile);
188 if (in == null) {
189 fail("No " + patchFile + " test vector");
190 return null; // Never happens
192 try {
193 final Patch p = new Patch();
194 p.parse(in);
195 return p;
196 } finally {
197 in.close();