View Javadoc
1   /*
2    * Copyright (C) 2012, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.internal.storage.file;
12  
13  import static org.junit.Assert.assertEquals;
14  
15  import org.eclipse.jgit.internal.storage.file.BasePackBitmapIndex.StoredBitmap;
16  import org.eclipse.jgit.lib.ObjectId;
17  import org.junit.Test;
18  
19  import com.googlecode.javaewah.EWAHCompressedBitmap;
20  
21  public class StoredBitmapTest {
22  
23  	@Test
24  	public void testGetBitmapWithoutXor() {
25  		EWAHCompressedBitmap b = bitmapOf(100);
26  		StoredBitmap sb = newStoredBitmap(bitmapOf(100));
27  		assertEquals(b, sb.getBitmap());
28  	}
29  
30  	@Test
31  	public void testGetBitmapWithOneXor() {
32  		StoredBitmap sb = newStoredBitmap(bitmapOf(100), bitmapOf(100, 101));
33  		assertEquals(bitmapOf(101), sb.getBitmap());
34  	}
35  
36  	@Test
37  	public void testGetBitmapWithThreeXor() {
38  		StoredBitmap sb = newStoredBitmap(
39  				bitmapOf(100),
40  				bitmapOf(90, 101),
41  				bitmapOf(100, 101),
42  				bitmapOf(50));
43  		assertEquals(bitmapOf(50, 90), sb.getBitmap());
44  		assertEquals(bitmapOf(50, 90), sb.getBitmap());
45  	}
46  
47  	private static final StoredBitmap newStoredBitmap(
48  			EWAHCompressedBitmap... bitmaps) {
49  		StoredBitmap sb = null;
50  		for (EWAHCompressedBitmap bitmap : bitmaps)
51  			sb = new StoredBitmap(ObjectId.zeroId(), bitmap, sb, 0);
52  		return sb;
53  	}
54  
55  	private static final EWAHCompressedBitmap bitmapOf(int... bits) {
56  		EWAHCompressedBitmap b = new EWAHCompressedBitmap();
57  		for (int bit : bits)
58  			b.set(bit);
59  		return b;
60  	}
61  }