[JGIT PATCH 3/5] Test case for pack index CRC32 when written by PackWriter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Suggested-by: Daniel Cheng (aka SDiZ) <j16sdiz+freenet@xxxxxxxxx>
Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../tst/org/spearce/jgit/lib/PackWriterTest.java   |   33 ++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
index 46616e3..636059f 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
@@ -40,6 +40,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -353,6 +354,37 @@ public void testWritePack4SizeThinVsNoThin() throws Exception {
 		assertTrue(sizePack4 > sizePack4Thin);
 	}
 
+	public void testWriteIndex() throws Exception {
+		writer.setIndexVersion(2);
+		writeVerifyPack4(false);
+
+		// Validate that IndexPack came up with the right CRC32 value.
+		final PackIndex idx1 = PackIndex.open(indexFile);
+		assertTrue(idx1 instanceof PackIndexV2);
+		assertEquals(0x4743F1E4L, idx1.findCRC32(ObjectId
+				.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7")));
+
+		// Validate that an index written by PackWriter is the same.
+		final File idx2File = new File(indexFile.getAbsolutePath() + ".2");
+		final FileOutputStream is = new FileOutputStream(idx2File);
+		try {
+			writer.writeIndex(is);
+		} finally {
+			is.close();
+		}
+		final PackIndex idx2 = PackIndex.open(idx2File);
+		assertTrue(idx2 instanceof PackIndexV2);
+		assertEquals(idx1.getObjectCount(), idx2.getObjectCount());
+		assertEquals(idx1.getOffset64Count(), idx2.getOffset64Count());
+
+		for (int i = 0; i < idx1.getObjectCount(); i++) {
+			final ObjectId id = idx1.getObjectId(i);
+			assertEquals(id, idx2.getObjectId(i));
+			assertEquals(idx1.findOffset(id), idx2.findOffset(id));
+			assertEquals(idx1.findCRC32(id), idx2.findCRC32(id));
+		}
+	}
+
 	// TODO: testWritePackDeltasCycle()
 	// TODO: testWritePackDeltasDepth()
 
@@ -469,6 +501,7 @@ private void verifyOpenPack(final boolean thin) throws IOException {
 		final IndexPack indexer = new IndexPack(db, is, packBase);
 		indexer.setKeepEmpty(true);
 		indexer.setFixThin(thin);
+		indexer.setIndexVersion(2);
 		indexer.index(new TextProgressMonitor());
 		pack = new PackFile(indexFile, packFile);
 	}
-- 
1.6.2.1.471.g682837

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux