1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.internal.storage.file;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertFalse;
48 import static org.junit.Assert.fail;
49
50 import java.io.File;
51 import java.util.Iterator;
52 import java.util.NoSuchElementException;
53
54 import org.eclipse.jgit.errors.MissingObjectException;
55 import org.eclipse.jgit.internal.storage.file.PackIndex;
56 import org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry;
57 import org.eclipse.jgit.junit.RepositoryTestCase;
58 import org.junit.Test;
59
60 public abstract class PackIndexTestCase extends RepositoryTestCase {
61
62 PackIndex smallIdx;
63
64 PackIndex denseIdx;
65
66 public void setUp() throws Exception {
67 super.setUp();
68 smallIdx = PackIndex.open(getFileForPack34be9032());
69 denseIdx = PackIndex.open(getFileForPackdf2982f28());
70 }
71
72
73
74
75
76
77 public abstract File getFileForPack34be9032();
78
79
80
81
82
83
84 public abstract File getFileForPackdf2982f28();
85
86
87
88
89
90
91
92 public abstract void testCRC32() throws MissingObjectException,
93 UnsupportedOperationException;
94
95
96
97
98
99 @Test
100 public void testIteratorMethodsContract() {
101 Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator();
102 while (iter.hasNext()) {
103 iter.next();
104 }
105
106 try {
107 iter.next();
108 fail("next() unexpectedly returned element");
109 } catch (NoSuchElementException x) {
110
111 }
112
113 try {
114 iter.remove();
115 fail("remove() shouldn't be implemented");
116 } catch (UnsupportedOperationException x) {
117
118 }
119 }
120
121
122
123
124
125 @Test
126 public void testIteratorReturnedValues1() {
127 Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator();
128 assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", iter.next()
129 .name());
130 assertEquals("540a36d136cf413e4b064c2b0e0a4db60f77feab", iter.next()
131 .name());
132 assertEquals("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259", iter.next()
133 .name());
134 assertEquals("6ff87c4664981e4397625791c8ea3bbb5f2279a3", iter.next()
135 .name());
136 assertEquals("82c6b885ff600be425b4ea96dee75dca255b69e7", iter.next()
137 .name());
138 assertEquals("902d5476fa249b7abc9d84c611577a81381f0327", iter.next()
139 .name());
140 assertEquals("aabf2ffaec9b497f0950352b3e582d73035c2035", iter.next()
141 .name());
142 assertEquals("c59759f143fb1fe21c197981df75a7ee00290799", iter.next()
143 .name());
144 assertFalse(iter.hasNext());
145 }
146
147
148
149
150 @Test
151 public void testCompareEntriesOffsetsWithFindOffsets() {
152 for (MutableEntry me : smallIdx) {
153 assertEquals(smallIdx.findOffset(me.toObjectId()), me.getOffset());
154 }
155 for (MutableEntry me : denseIdx) {
156 assertEquals(denseIdx.findOffset(me.toObjectId()), me.getOffset());
157 }
158 }
159
160
161
162
163 @Test
164 public void testCompareEntriesOffsetsWithGetOffsets() {
165 int i = 0;
166 for (MutableEntry me : smallIdx) {
167 assertEquals(smallIdx.getOffset(i++), me.getOffset());
168 }
169 int j = 0;
170 for (MutableEntry me : denseIdx) {
171 assertEquals(denseIdx.getOffset(j++), me.getOffset());
172 }
173 }
174
175
176
177
178
179 @Test
180 public void testIteratorReturnedValues2() {
181 Iterator<PackIndex.MutableEntry> iter = denseIdx.iterator();
182 while (!iter.next().name().equals(
183 "0a3d7772488b6b106fb62813c4d6d627918d9181")) {
184
185 }
186 assertEquals("1004d0d7ac26fbf63050a234c9b88a46075719d3", iter.next()
187 .name());
188 assertEquals("10da5895682013006950e7da534b705252b03be6", iter.next()
189 .name());
190 assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8", iter.next()
191 .name());
192 }
193
194 }