[JGIT PATCH 12/12] Add PackIndex specific tests, currently only iterators tests

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

 



Abstract PackIndexTest added, with specializations for v1 and v2
indexes. New dedicated indexes files for v2 tests created.

Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx>
---
 .../tst/org/spearce/jgit/lib/PackIndexTest.java    |  152 ++++++++++++++++++++
 .../tst/org/spearce/jgit/lib/PackIndexV1Test.java  |   54 +++++++
 .../tst/org/spearce/jgit/lib/PackIndexV2Test.java  |   54 +++++++
 ...-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2 |  Bin 0 -> 1296 bytes
 ...-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2 |  Bin 0 -> 2976 bytes
 5 files changed, 260 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java
 create mode 100644 org.spearce.jgit.test/tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2
 create mode 100644 org.spearce.jgit.test/tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java
new file mode 100644
index 0000000..c682153
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java
@@ -0,0 +1,152 @@
+/*
+ * 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 java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.spearce.jgit.lib.PackIndex.MutableEntry;
+
+public abstract class PackIndexTest extends RepositoryTestCase {
+
+	PackIndex smallIdx;
+
+	PackIndex denseIdx;
+
+	public void setUp() throws Exception {
+		super.setUp();
+		smallIdx = PackIndex.open(getFileForPack34be9032());
+		denseIdx = PackIndex.open(getFileForPackdf2982f28());
+	}
+
+	/**
+	 * Return file with appropriate index version for prepared pack.
+	 * 
+	 * @return file with index
+	 */
+	public abstract File getFileForPack34be9032();
+
+	/**
+	 * Return file with appropriate index version for prepared pack.
+	 * 
+	 * @return file with index
+	 */
+	public abstract File getFileForPackdf2982f28();
+
+	/**
+	 * Test contracts of Iterator methods and this implementation remove()
+	 * limitations.
+	 */
+	public void testIteratorMethodsContract() {
+		Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator();
+		while (iter.hasNext()) {
+			iter.next();
+		}
+
+		try {
+			iter.next();
+			fail("next() unexpectedly returned element");
+		} catch (NoSuchElementException x) {
+			// expected
+		}
+
+		try {
+			iter.remove();
+			fail("remove() shouldn't be implemented");
+		} catch (UnsupportedOperationException x) {
+			// expected
+		}
+	}
+
+	/**
+	 * Test results of iterator comparing to content of well-known (prepared)
+	 * small index.
+	 */
+	public void testIteratorReturnedValues1() {
+		Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator();
+		assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", iter.next()
+				.toString());
+		assertEquals("540a36d136cf413e4b064c2b0e0a4db60f77feab", iter.next()
+				.toString());
+		assertEquals("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259", iter.next()
+				.toString());
+		assertEquals("6ff87c4664981e4397625791c8ea3bbb5f2279a3", iter.next()
+				.toString());
+		assertEquals("82c6b885ff600be425b4ea96dee75dca255b69e7", iter.next()
+				.toString());
+		assertEquals("902d5476fa249b7abc9d84c611577a81381f0327", iter.next()
+				.toString());
+		assertEquals("aabf2ffaec9b497f0950352b3e582d73035c2035", iter.next()
+				.toString());
+		assertEquals("c59759f143fb1fe21c197981df75a7ee00290799", iter.next()
+				.toString());
+		assertFalse(iter.hasNext());
+	}
+
+	/**
+	 * Compare offset from iterator entries with output of findOffset() method.
+	 */
+	public void testCompareEntriesOffsetsWithFindOffsets() {
+		for (MutableEntry me : smallIdx) {
+			assertEquals(smallIdx.findOffset(me), me.getOffset());
+		}
+		for (MutableEntry me : denseIdx) {
+			assertEquals(denseIdx.findOffset(me), me.getOffset());
+		}
+	}
+
+	/**
+	 * Test partial results of iterator comparing to content of well-known
+	 * (prepared) dense index, that may need multi-level indexing.
+	 */
+	public void testIteratorReturnedValues2() {
+		Iterator<PackIndex.MutableEntry> iter = denseIdx.iterator();
+		while (!iter.next().toString().equals(
+				"0a3d7772488b6b106fb62813c4d6d627918d9181")) {
+			// just iterating
+		}
+		assertEquals("1004d0d7ac26fbf63050a234c9b88a46075719d3", iter.next()
+				.toString()); // same level-1
+		assertEquals("10da5895682013006950e7da534b705252b03be6", iter.next()
+				.toString()); // same level-1
+		assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8", iter.next()
+				.toString());
+	}
+
+}
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java
new file mode 100644
index 0000000..dda3ef4
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+public class PackIndexV1Test extends PackIndexTest {
+	@Override
+	public File getFileForPack34be9032() {
+		return new File(new File("tst"),
+				"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idx");
+	}
+
+	@Override
+	public File getFileForPackdf2982f28() {
+		return new File(new File("tst"),
+				"pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx");
+	}
+}
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java
new file mode 100644
index 0000000..8267e48
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+public class PackIndexV2Test extends PackIndexTest {
+	@Override
+	public File getFileForPack34be9032() {
+		return new File(new File("tst"),
+				"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2");
+	}
+
+	@Override
+	public File getFileForPackdf2982f28() {
+		return new File(new File("tst"),
+				"pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2");
+	}
+}
diff --git a/org.spearce.jgit.test/tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2 b/org.spearce.jgit.test/tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.idxV2
new file mode 100644
index 0000000000000000000000000000000000000000..1d45fa811a1855a9ac71e5237c8aa91e502e8224
GIT binary patch
literal 1296
zcmexg;-AdGz`z8=qk#AjU<4{9gh6473o`@dsEJvC=1~i?0?i@^vjO$d1G59|p%>-=
z+BG7ucT?;!r_*^m7bHCO{&8(m$M1KZEFoNG7tPK)+Ih42X!CLTZsRZiw>mnnChbt!
z^F&^+;^TY=7k)p;U=*4EqsA>|hMe>Cr0|I+URm#sSE^jxbZkfK{{-$Qs#{)7yZ1cy
zlxlS5^9i~kWxrHrSM8bGa!fG1s?kE8S$)-h{a<fpd)9LXm}=Wa=oT}_D3~6d9{JJv
zxBMd+$;!t2rOV$jXtK{dw9P4^Xl?kR{{l-YO*Yluad-asB!%0wTTA?O9Jh7!G6n{@
zG+>qt24*>6K48)T#v2b%%mOHO4anZ)^4)OqwtbqDxeqp+n<8~%>Q9^4X-{K**qkZ&
S;_1>JC~?!}g1(aBk0JolEO)B_

literal 0
HcmV?d00001

diff --git a/org.spearce.jgit.test/tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2 b/org.spearce.jgit.test/tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idxV2
new file mode 100644
index 0000000000000000000000000000000000000000..ccbf00e34fb8de324c5fe3f584b80bdb99e02df0
GIT binary patch
literal 2976
zcmb`Jc{J4PAIHCTgRx}KHdlq1j4d}LNmof_JF>(LG1<A6$h2TI4Oy~9nKYP^t!63=
zYLulYB3n$iD0_*r=DPIzIH%6(bbj4#=iKL<*Lgn6`+1(vf6x0<nAKqfK{$agivxo1
z!390;@4yT7RrtPwA7a$MKmas?-$4lK{|{lPe~k#_{{^CO&-YjZy`MoG^k0yGSn@ka
zL0$SYGO({A`vc^lFApgE2PncFt0)1=z=qGLz^?WWY=qt_>Yveo{aZFc?Pt&gJr2<N
z0XooMMfWGr1MTK-(1(1LUjc(3U<m!MF@pRHTOs~}F~r-x!36SEw*N~^LAT0|pTrFG
z-?9^G{|INbPN!$C4Z>L`Ws~j~98nzpsR)Iq>AhXc=~_`Kak}JiK`rYFrUEtfaQGrI
zQ>~Q1z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{Hr419R(c00?`o!y%*>P
z`-VjjF7PqvO0ZlxkP{I^>Hx%cU>jLrwP=vHAqWrbs~%7o{#xNQu!^APy^kOg5m0`D
zAYvrYfPa(%A1MT9`IEuY9s~_|6Nx?W<^r6{gZn;$wgfD!CD_y%=+(nph0p^JC3zUE
zS~koX3-dex9U5?lGw_c~g0B<=jaV;W54shY`xa;)!CY_Q-A|x#fO;a_1+#I$8+^`?
z!=H-+4~2$YssQeqfHRXYoBYl^A8q!6_j1OT;sSk?0(z_H4h!AoN{ZqUN0dGrKk#Uu
L#~L@=K-~WTG^vnn

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