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