Add tests for ObjectWalk
[egit/chris.git] / org.spearce.jgit.test / tst / org / spearce / jgit / revwalk / ObjectWalkTest.java
blob86f42777693eb91bd2c2e880e48958d2209e4aa6
1 /*
2 * Copyright (C) 2009, 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.revwalk;
40 public class ObjectWalkTest extends RevWalkTestCase {
41 protected ObjectWalk objw;
43 protected RevWalk createRevWalk() {
44 return objw = new ObjectWalk(db);
47 public void testNoCommits() throws Exception {
48 assertNull(objw.next());
49 assertNull(objw.nextObject());
52 public void testTwoCommitsEmptyTree() throws Exception {
53 final RevCommit a = commit();
54 final RevCommit b = commit(a);
55 markStart(b);
57 assertCommit(b, objw.next());
58 assertCommit(a, objw.next());
59 assertNull(objw.next());
61 assertSame(emptyTree, objw.nextObject());
62 assertNull(objw.nextObject());
65 public void testOneCommitOneTreeTwoBlob() throws Exception {
66 final RevBlob f0 = blob("0");
67 final RevBlob f1 = blob("1");
68 final RevTree t = tree(file("0", f0), file("1", f1), file("2", f1));
69 final RevCommit a = commit(t);
70 markStart(a);
72 assertCommit(a, objw.next());
73 assertNull(objw.next());
75 assertSame(t, objw.nextObject());
76 assertSame(f0, objw.nextObject());
77 assertSame(f1, objw.nextObject());
78 assertNull(objw.nextObject());
81 public void testTwoCommitTwoTreeTwoBlob() throws Exception {
82 final RevBlob f0 = blob("0");
83 final RevBlob f1 = blob("1");
84 final RevBlob f2 = blob("0v2");
85 final RevTree ta = tree(file("0", f0), file("1", f1), file("2", f1));
86 final RevTree tb = tree(file("0", f2), file("1", f1), file("2", f1));
87 final RevCommit a = commit(ta);
88 final RevCommit b = commit(tb, a);
89 markStart(b);
91 assertCommit(b, objw.next());
92 assertCommit(a, objw.next());
93 assertNull(objw.next());
95 assertSame(tb, objw.nextObject());
96 assertSame(f2, objw.nextObject());
97 assertSame(f1, objw.nextObject());
99 assertSame(ta, objw.nextObject());
100 assertSame(f0, objw.nextObject());
102 assertNull(objw.nextObject());
105 public void testTwoCommitDeepTree1() throws Exception {
106 final RevBlob f0 = blob("0");
107 final RevBlob f1 = blob("0v2");
108 final RevTree ta = tree(file("a/b/0", f0));
109 final RevTree tb = tree(file("a/b/1", f1));
110 final RevCommit a = commit(ta);
111 final RevCommit b = commit(tb, a);
112 markStart(b);
114 assertCommit(b, objw.next());
115 assertCommit(a, objw.next());
116 assertNull(objw.next());
118 assertSame(tb, objw.nextObject());
119 assertSame(get(tb, "a"), objw.nextObject());
120 assertSame(get(tb, "a/b"), objw.nextObject());
121 assertSame(f1, objw.nextObject());
123 assertSame(ta, objw.nextObject());
124 assertSame(get(ta, "a"), objw.nextObject());
125 assertSame(get(ta, "a/b"), objw.nextObject());
126 assertSame(f0, objw.nextObject());
128 assertNull(objw.nextObject());
131 public void testTwoCommitDeepTree2() throws Exception {
132 final RevBlob f1 = blob("1");
133 final RevTree ta = tree(file("a/b/0", f1), file("a/c/q", f1));
134 final RevTree tb = tree(file("a/b/1", f1), file("a/c/q", f1));
135 final RevCommit a = commit(ta);
136 final RevCommit b = commit(tb, a);
137 markStart(b);
139 assertCommit(b, objw.next());
140 assertCommit(a, objw.next());
141 assertNull(objw.next());
143 assertSame(tb, objw.nextObject());
144 assertSame(get(tb, "a"), objw.nextObject());
145 assertSame(get(tb, "a/b"), objw.nextObject());
146 assertSame(f1, objw.nextObject());
147 assertSame(get(tb, "a/c"), objw.nextObject());
149 assertSame(ta, objw.nextObject());
150 assertSame(get(ta, "a"), objw.nextObject());
151 assertSame(get(ta, "a/b"), objw.nextObject());
153 assertNull(objw.nextObject());
156 public void testCull() throws Exception {
157 final RevBlob f1 = blob("1");
158 final RevBlob f2 = blob("2");
159 final RevBlob f3 = blob("3");
160 final RevBlob f4 = blob("4");
162 final RevTree ta = tree(file("a/1", f1), file("c/3", f3));
163 final RevCommit a = commit(ta);
165 final RevTree tb = tree(file("a/1", f2), file("c/3", f3));
166 final RevCommit b1 = commit(tb, a);
167 final RevCommit b2 = commit(tb, b1);
169 final RevTree tc = tree(file("a/1", f4));
170 final RevCommit c1 = commit(tc, a);
171 final RevCommit c2 = commit(tc, c1);
173 markStart(b2);
174 markUninteresting(c2);
176 assertCommit(b2, objw.next());
177 assertCommit(b1, objw.next());
178 assertNull(objw.next());
180 assertTrue(a.has(RevFlag.UNINTERESTING));
181 assertTrue(ta.has(RevFlag.UNINTERESTING));
182 assertTrue(f1.has(RevFlag.UNINTERESTING));
183 assertTrue(f3.has(RevFlag.UNINTERESTING));
185 assertSame(tb, objw.nextObject());
186 assertSame(get(tb, "a"), objw.nextObject());
187 assertSame(f2, objw.nextObject());
188 assertNull(objw.nextObject());