RevWalk: Fix RevSort.REVERSE combined with RevSort.TOPO
[egit/fonseca.git] / org.spearce.jgit.test / tst / org / spearce / jgit / lib / PackIndexTest.java
blob8ab380e2221391faf05e970268877511e7101c75
1 /*
2 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
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.lib;
40 import java.io.File;
41 import java.util.Iterator;
42 import java.util.NoSuchElementException;
44 import org.spearce.jgit.errors.MissingObjectException;
45 import org.spearce.jgit.lib.PackIndex.MutableEntry;
47 public abstract class PackIndexTest extends RepositoryTestCase {
49 PackIndex smallIdx;
51 PackIndex denseIdx;
53 public void setUp() throws Exception {
54 super.setUp();
55 smallIdx = PackIndex.open(getFileForPack34be9032());
56 denseIdx = PackIndex.open(getFileForPackdf2982f28());
59 /**
60 * Return file with appropriate index version for prepared pack.
62 * @return file with index
64 public abstract File getFileForPack34be9032();
66 /**
67 * Return file with appropriate index version for prepared pack.
69 * @return file with index
71 public abstract File getFileForPackdf2982f28();
73 /**
74 * Verify CRC32 support.
76 * @throws MissingObjectException
77 * @throws UnsupportedOperationException
79 public abstract void testCRC32() throws MissingObjectException,
80 UnsupportedOperationException;
82 /**
83 * Test contracts of Iterator methods and this implementation remove()
84 * limitations.
86 public void testIteratorMethodsContract() {
87 Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator();
88 while (iter.hasNext()) {
89 iter.next();
92 try {
93 iter.next();
94 fail("next() unexpectedly returned element");
95 } catch (NoSuchElementException x) {
96 // expected
99 try {
100 iter.remove();
101 fail("remove() shouldn't be implemented");
102 } catch (UnsupportedOperationException x) {
103 // expected
108 * Test results of iterator comparing to content of well-known (prepared)
109 * small index.
111 public void testIteratorReturnedValues1() {
112 Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator();
113 assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", iter.next()
114 .name());
115 assertEquals("540a36d136cf413e4b064c2b0e0a4db60f77feab", iter.next()
116 .name());
117 assertEquals("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259", iter.next()
118 .name());
119 assertEquals("6ff87c4664981e4397625791c8ea3bbb5f2279a3", iter.next()
120 .name());
121 assertEquals("82c6b885ff600be425b4ea96dee75dca255b69e7", iter.next()
122 .name());
123 assertEquals("902d5476fa249b7abc9d84c611577a81381f0327", iter.next()
124 .name());
125 assertEquals("aabf2ffaec9b497f0950352b3e582d73035c2035", iter.next()
126 .name());
127 assertEquals("c59759f143fb1fe21c197981df75a7ee00290799", iter.next()
128 .name());
129 assertFalse(iter.hasNext());
133 * Compare offset from iterator entries with output of findOffset() method.
135 public void testCompareEntriesOffsetsWithFindOffsets() {
136 for (MutableEntry me : smallIdx) {
137 assertEquals(smallIdx.findOffset(me), me.getOffset());
139 for (MutableEntry me : denseIdx) {
140 assertEquals(denseIdx.findOffset(me), me.getOffset());
145 * Test partial results of iterator comparing to content of well-known
146 * (prepared) dense index, that may need multi-level indexing.
148 public void testIteratorReturnedValues2() {
149 Iterator<PackIndex.MutableEntry> iter = denseIdx.iterator();
150 while (!iter.next().name().equals(
151 "0a3d7772488b6b106fb62813c4d6d627918d9181")) {
152 // just iterating
154 assertEquals("1004d0d7ac26fbf63050a234c9b88a46075719d3", iter.next()
155 .name()); // same level-1
156 assertEquals("10da5895682013006950e7da534b705252b03be6", iter.next()
157 .name()); // same level-1
158 assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8", iter.next()
159 .name());