[EGIT PATCH 06/20] Tests for PackReverseIndex

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

 



Test cases based on new pack index, with big offsets (> 2^31).
Index was generated from artificially generated pack (repository).

Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx>
---
 .../org/spearce/jgit/lib/PackReverseIndexTest.java |  115 ++++++++++++++++++++
 org.spearce.jgit.test/tst/pack-huge.idx            |  Bin 0 -> 2368 bytes
 2 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java
 create mode 100644 org.spearce.jgit.test/tst/pack-huge.idx

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java
new file mode 100644
index 0000000..a06c613
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackReverseIndexTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2008, Marek Zawirski <marek.zawirski@xxxxxxxxx>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the following
+ *   disclaimer in the documentation and/or other materials provided
+ *   with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ *   names of its contributors may be used to endorse or promote
+ *   products derived from this software without specific prior
+ *   written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.lib;
+
+import java.io.File;
+
+import org.spearce.jgit.errors.CorruptObjectException;
+import org.spearce.jgit.lib.PackIndex.MutableEntry;
+
+public class PackReverseIndexTest extends RepositoryTestCase {
+
+	private PackIndex idx;
+
+	private PackReverseIndex reverseIdx;
+
+	/**
+	 * Set up tested class instance, test constructor by the way.
+	 */
+	public void setUp() throws Exception {
+		super.setUp();
+		// index with both small (< 2^31) and big offsets 
+		idx = PackIndex.open(new File(new File("tst"),
+				"pack-huge.idx"));
+		reverseIdx = new PackReverseIndex(idx);
+	}
+
+	/**
+	 * Test findObject() for all index entries.
+	 */
+	public void testFindObject() {
+		for (MutableEntry me : idx)
+			assertEquals(me.toObjectId(), reverseIdx.findObject(me.getOffset()));
+	}
+
+	/**
+	 * Test findObject() with illegal argument.
+	 */
+	public void testFindObjectWrongOffset() {
+		assertNull(reverseIdx.findObject(0));
+	}
+
+	/**
+	 * Test findNextOffset() for all index entries.
+	 * 
+	 * @throws CorruptObjectException
+	 */
+	public void testFindNextOffset() throws CorruptObjectException {
+		long offset = findFirstOffset();
+		assertTrue(offset > 0);
+		for (int i = 0; i < idx.getObjectCount(); i++) {
+			long newOffset = reverseIdx.findNextOffset(offset, Long.MAX_VALUE);
+			assertTrue(newOffset > offset);
+			if (i == idx.getObjectCount() - 1)
+				assertEquals(newOffset, Long.MAX_VALUE);
+			else
+				assertEquals(newOffset, idx.findOffset(reverseIdx
+						.findObject(newOffset)));
+			offset = newOffset;
+		}
+	}
+
+	/**
+	 * Test findNextOffset() with wrong illegal argument as offset.
+	 */
+	public void testFindNextOffsetWrongOffset() {
+		try {
+			reverseIdx.findNextOffset(0, Long.MAX_VALUE);
+			fail("findNextOffset() should throw exception");
+		} catch (CorruptObjectException x) {
+			// expected
+		}
+	}
+
+	private long findFirstOffset() {
+		long min = Long.MAX_VALUE;
+		for (MutableEntry me : idx)
+			min = Math.min(min, me.getOffset());
+		return min;
+	}
+}
diff --git a/org.spearce.jgit.test/tst/pack-huge.idx b/org.spearce.jgit.test/tst/pack-huge.idx
new file mode 100644
index 0000000000000000000000000000000000000000..0a5bbfb6a6c1453926f7d1ceaa78af494a8b460d
GIT binary patch
literal 2368
zcmd7Tdo<K(7zgkfni%6YQn^GXGpJCQK`t|=u%X&vbaR(MbA%*Y)9QkCnN)*W#wD`S
zRzxDDVik%Smy!Dz3?WJ`rOrl%eScw(<8(Tmwm<fd&-uR3^S<x%n}6oKv%zF43<eVc
z;EO=@*NB4srIvx-QV7udlI5WPy~M!XuMr3PUxEbvFOdNK#ZaJLN)q%INP+dYkOt=<
zGE2yU8iEGo{wG#|-vN>Tij`pRd#nQY7F!MKA3*`kQJkj)a;Y_-2T@r>6|DcOwP40#
zYM}m+Fks%gZ=ep&EWm>Gx4?mO3pBx6>t9&M^kUw-u`-=-wd|mdRKhc%z3Bd_j3ZUc
zWckHw-5QZ>PpzD%uTgKTG1vcev~<^Nuom1z?blMx=#@?B>gP17cQlPL4MPkyd@=~+
z)|HBnlU&683U;z@2B$a;<e(k6KFa9(dYX|0i^|BN@;#x?`wzkLs2eC6GP~Sg$0NEQ
z*$3Y45zO-0V*0d0O$sunLS`MVol`aF^Ph=-GGhFSZ^f|<y?6ZlNA~DTOZ)0kJt<-f
z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C*ooeQ@Cu0f7vz(hfwgB@70;4EjhwLNatV
z1|$lQ1f&3I0K8*}<b6?mL+}|xebEsQF#9d&%L3pngI9x;16G_uK7;Pb6C(yGAfYz{
zdOKlkROvXBm(SmQ0p$pb4Sg3%>|7>-*-)LBJeMpcl=)J(n&)cvLceIf4uG;b?o!TN
zo!C9!zXRpjn2H%FpUPah2jvJWfjFO^=k%hJ)8=Yc1(YSsoT~Z#?$l*jF@l0Nla?U^
i5q#0RPo(gxfy(+nDH~nU#sqlR)DGh}_SPGh&i(_^HDsp%

literal 0
HcmV?d00001

-- 
1.5.5.1

--
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