Merge commit 'egit/spearce/master' into rr/fetch_and_index
[egit/zawir.git] / org.spearce.jgit.test / tst / org / spearce / jgit / fetch / IndexPackTest.java
blobe49ac99785bca56609efdcc60b26c731f0eadc95
1 /*
2 * Copyright (C) 2007 Robin Rosenberg
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License, version 2, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org.spearce.jgit.fetch;
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.IOException;
22 import java.io.InputStream;
24 import org.spearce.jgit.fetch.IndexPack;
25 import org.spearce.jgit.lib.ObjectId;
26 import org.spearce.jgit.lib.PackFile;
27 import org.spearce.jgit.lib.RepositoryTestCase;
28 import org.spearce.jgit.lib.TextProgressMonitor;
30 /**
31 * Test indexing of git packs. A pack is read from a stream, copied
32 * to a new pack and an index is created. Then the packs are tested
33 * to make sure they contain the expected objects (well we don't test
34 * for all of them unless the packs are very small).
36 public class IndexPackTest extends RepositoryTestCase {
38 /**
39 * Test indexing one of the test packs in the egit repo. It has deltas.
41 * @throws IOException
43 public void test1() throws IOException {
44 File packFile = new File("tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
45 final InputStream is = new FileInputStream(packFile);
46 try {
47 IndexPack pack = new IndexPack(is, new File("tmp_pack1"));
48 pack.index(new TextProgressMonitor());
49 PackFile file = new PackFile(db, new File("tmp_pack1.idx"), new File("tmp_pack1.pack"));
50 assertTrue(file.hasObject(ObjectId.fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904")));
51 assertTrue(file.hasObject(ObjectId.fromString("540a36d136cf413e4b064c2b0e0a4db60f77feab")));
52 assertTrue(file.hasObject(ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259")));
53 assertTrue(file.hasObject(ObjectId.fromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3")));
54 assertTrue(file.hasObject(ObjectId.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7")));
55 assertTrue(file.hasObject(ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327")));
56 assertTrue(file.hasObject(ObjectId.fromString("aabf2ffaec9b497f0950352b3e582d73035c2035")));
57 assertTrue(file.hasObject(ObjectId.fromString("c59759f143fb1fe21c197981df75a7ee00290799")));
58 } finally {
59 is.close();
63 /**
64 * This is just another pack. It so happens that we have two convenient pack to
65 * test with in the repository.
67 * @throws IOException
69 public void test2() throws IOException {
70 File packFile = new File("tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack");
71 final InputStream is = new FileInputStream(packFile);
72 try {
73 IndexPack pack = new IndexPack(is, new File("tmp_pack2"));
74 pack.index(new TextProgressMonitor());
75 PackFile file = new PackFile(db, new File("tmp_pack2.idx"), new File("tmp_pack2.pack"));
76 assertTrue(file.hasObject(ObjectId.fromString("02ba32d3649e510002c21651936b7077aa75ffa9")));
77 assertTrue(file.hasObject(ObjectId.fromString("0966a434eb1a025db6b71485ab63a3bfbea520b6")));
78 assertTrue(file.hasObject(ObjectId.fromString("09efc7e59a839528ac7bda9fa020dc9101278680")));
79 assertTrue(file.hasObject(ObjectId.fromString("0a3d7772488b6b106fb62813c4d6d627918d9181")));
80 assertTrue(file.hasObject(ObjectId.fromString("1004d0d7ac26fbf63050a234c9b88a46075719d3")));
81 assertTrue(file.hasObject(ObjectId.fromString("10da5895682013006950e7da534b705252b03be6")));
82 assertTrue(file.hasObject(ObjectId.fromString("1203b03dc816ccbb67773f28b3c19318654b0bc8")));
83 assertTrue(file.hasObject(ObjectId.fromString("15fae9e651043de0fd1deef588aa3fbf5a7a41c6")));
84 assertTrue(file.hasObject(ObjectId.fromString("16f9ec009e5568c435f473ba3a1df732d49ce8c3")));
85 assertTrue(file.hasObject(ObjectId.fromString("1fd7d579fb6ae3fe942dc09c2c783443d04cf21e")));
86 assertTrue(file.hasObject(ObjectId.fromString("20a8ade77639491ea0bd667bf95de8abf3a434c8")));
87 assertTrue(file.hasObject(ObjectId.fromString("2675188fd86978d5bc4d7211698b2118ae3bf658")));
88 // and lots more...
89 } finally {
90 is.close();