2 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
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
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
;
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
{
53 public void setUp() throws Exception
{
55 smallIdx
= PackIndex
.open(getFileForPack34be9032());
56 denseIdx
= PackIndex
.open(getFileForPackdf2982f28());
60 * Return file with appropriate index version for prepared pack.
62 * @return file with index
64 public abstract File
getFileForPack34be9032();
67 * Return file with appropriate index version for prepared pack.
69 * @return file with index
71 public abstract File
getFileForPackdf2982f28();
74 * Verify CRC32 support.
76 * @throws MissingObjectException
77 * @throws UnsupportedOperationException
79 public abstract void testCRC32() throws MissingObjectException
,
80 UnsupportedOperationException
;
83 * Test contracts of Iterator methods and this implementation remove()
86 public void testIteratorMethodsContract() {
87 Iterator
<PackIndex
.MutableEntry
> iter
= smallIdx
.iterator();
88 while (iter
.hasNext()) {
94 fail("next() unexpectedly returned element");
95 } catch (NoSuchElementException x
) {
101 fail("remove() shouldn't be implemented");
102 } catch (UnsupportedOperationException x
) {
108 * Test results of iterator comparing to content of well-known (prepared)
111 public void testIteratorReturnedValues1() {
112 Iterator
<PackIndex
.MutableEntry
> iter
= smallIdx
.iterator();
113 assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", iter
.next()
115 assertEquals("540a36d136cf413e4b064c2b0e0a4db60f77feab", iter
.next()
117 assertEquals("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259", iter
.next()
119 assertEquals("6ff87c4664981e4397625791c8ea3bbb5f2279a3", iter
.next()
121 assertEquals("82c6b885ff600be425b4ea96dee75dca255b69e7", iter
.next()
123 assertEquals("902d5476fa249b7abc9d84c611577a81381f0327", iter
.next()
125 assertEquals("aabf2ffaec9b497f0950352b3e582d73035c2035", iter
.next()
127 assertEquals("c59759f143fb1fe21c197981df75a7ee00290799", iter
.next()
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")) {
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()