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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
* Copyright (C) 2024, GerritForge Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.internal.storage.midx;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import org.eclipse.jgit.internal.storage.midx.MultiPackIndexLoader.MultiPackIndexBuilder;
import org.eclipse.jgit.internal.storage.midx.MultiPackIndexLoader.MultiPackIndexFormatException;
import org.junit.Test;
public class MultiPackIndexBuilderTest {
@Test
public void testRepeatedChunk() throws Exception {
byte[] buffer = new byte[2048];
MultiPackIndexBuilder builder1 = MultiPackIndexBuilder.builder();
builder1.addOidFanout(buffer);
Exception e1 = assertThrows(MultiPackIndexFormatException.class, () -> {
builder1.addOidFanout(buffer);
});
assertEquals("midx chunk id 0x4f494446 appears multiple times",
e1.getMessage());
MultiPackIndexBuilder builder2 = MultiPackIndexBuilder.builder();
builder2.addOidLookUp(buffer);
Exception e2 = assertThrows(MultiPackIndexFormatException.class, () -> {
builder2.addOidLookUp(buffer);
});
assertEquals("midx chunk id 0x4f49444c appears multiple times",
e2.getMessage());
MultiPackIndexBuilder builder3 = MultiPackIndexBuilder.builder();
builder3.addObjectOffsets(buffer);
Exception e3 = assertThrows(MultiPackIndexFormatException.class, () -> {
builder3.addObjectOffsets(buffer);
});
assertEquals("midx chunk id 0x4f4f4646 appears multiple times",
e3.getMessage());
MultiPackIndexBuilder builder4 = MultiPackIndexBuilder.builder();
builder4.addPackNames(buffer);
Exception e4 = assertThrows(MultiPackIndexFormatException.class, () -> {
builder4.addPackNames(buffer);
});
assertEquals("midx chunk id 0x504e414d appears multiple times",
e4.getMessage());
MultiPackIndexBuilder builder5 = MultiPackIndexBuilder.builder();
builder5.addBitmappedPacks(buffer);
Exception e5 = assertThrows(MultiPackIndexFormatException.class, () -> {
builder5.addBitmappedPacks(buffer);
});
assertEquals("midx chunk id 0x42544d50 appears multiple times",
e5.getMessage());
MultiPackIndexBuilder builder6 = MultiPackIndexBuilder.builder();
builder6.addObjectLargeOffsets(buffer);
Exception e6 = assertThrows(MultiPackIndexFormatException.class, () -> {
builder6.addObjectLargeOffsets(buffer);
});
assertEquals("midx chunk id 0x4c4f4646 appears multiple times",
e6.getMessage());
MultiPackIndexBuilder builder7 = MultiPackIndexBuilder.builder();
builder7.addReverseIndex(buffer);
Exception e7 = assertThrows(MultiPackIndexFormatException.class, () -> {
builder7.addReverseIndex(buffer);
});
assertEquals("midx chunk id 0x52494458 appears multiple times",
e7.getMessage());
}
@Test
public void testNeededChunk() {
byte[] buffer = new byte[2048];
Exception e1 = assertThrows(MultiPackIndexFormatException.class, () -> {
MultiPackIndexBuilder.builder().addOidLookUp(buffer).build();
});
assertEquals("midx 0x4f494446 chunk has not been loaded",
e1.getMessage());
Exception e2 = assertThrows(MultiPackIndexFormatException.class, () -> {
MultiPackIndexBuilder.builder().addOidFanout(buffer)
.addOidLookUp(buffer).build();
});
assertEquals("midx 0x504e414d chunk has not been loaded",
e2.getMessage());
Exception e3 = assertThrows(MultiPackIndexFormatException.class, () -> {
MultiPackIndexBuilder.builder().addOidFanout(buffer)
.addOidLookUp(buffer).addPackNames(buffer).build();
});
assertEquals("midx 0x4f4f4646 chunk has not been loaded",
e3.getMessage());
}
}
|