Ejemplo n.º 1
0
        public void testTwoLevelSubtree()
        {
            DirCache dc = DirCache.read(db);

            string[]        paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i] = new DirCacheEntry(paths[i]);
                ents[i].setFileMode(FileMode.RegularFile);
            }
            int aFirst  = 1;
            int aLast   = 4;
            int acFirst = 2;
            int acLast  = 3;

            DirCacheBuilder b = dc.builder();

            for (int i = 0; i < ents.Length; i++)
            {
                b.add(ents[i]);
            }
            b.finish();

            Assert.IsNull(dc.getCacheTree(false));
            DirCacheTree root = dc.getCacheTree(true);

            Assert.IsNotNull(root);
            Assert.AreSame(root, dc.getCacheTree(true));
            Assert.AreEqual(string.Empty, root.getNameString());
            Assert.AreEqual(string.Empty, root.getPathString());
            Assert.AreEqual(1, root.getChildCount());
            Assert.AreEqual(dc.getEntryCount(), root.getEntrySpan());
            Assert.IsFalse(root.isValid());

            DirCacheTree aTree = root.getChild(0);

            Assert.IsNotNull(aTree);
            Assert.AreSame(aTree, root.getChild(0));
            Assert.AreEqual("a", aTree.getNameString());
            Assert.AreEqual("a/", aTree.getPathString());
            Assert.AreEqual(1, aTree.getChildCount());
            Assert.AreEqual(aLast - aFirst + 1, aTree.getEntrySpan());
            Assert.IsFalse(aTree.isValid());

            DirCacheTree acTree = aTree.getChild(0);

            Assert.IsNotNull(acTree);
            Assert.AreSame(acTree, aTree.getChild(0));
            Assert.AreEqual("c", acTree.getNameString());
            Assert.AreEqual("a/c/", acTree.getPathString());
            Assert.AreEqual(0, acTree.getChildCount());
            Assert.AreEqual(acLast - acFirst + 1, acTree.getEntrySpan());
            Assert.IsFalse(acTree.isValid());
        }
Ejemplo n.º 2
0
        public void testEmptyCache_CreateEmptyCacheTree()
        {
            DirCache     dc   = DirCache.read(db);
            DirCacheTree tree = dc.getCacheTree(true);

            Assert.IsNotNull(tree);
            Assert.AreSame(tree, dc.getCacheTree(false));
            Assert.AreSame(tree, dc.getCacheTree(true));
            Assert.AreEqual(string.Empty, tree.getNameString());
            Assert.AreEqual(string.Empty, tree.getPathString());
            Assert.AreEqual(0, tree.getChildCount());
            Assert.AreEqual(0, tree.getEntrySpan());
            Assert.IsFalse(tree.isValid());
        }
        public void testReadIndex_DirCacheTree()
        {
            List <CGitIndexRecord>  cList = ReadLsFiles();
            List <CGitLsTreeRecord> cTree = ReadLsTree();
            var dc = new DirCache(_index);

            Assert.AreEqual(0, dc.getEntryCount());
            dc.read();
            Assert.AreEqual(cList.Count, dc.getEntryCount());

            DirCacheTree jTree = dc.getCacheTree(false);

            Assert.IsNotNull(jTree);
            Assert.AreEqual(string.Empty, jTree.getNameString());
            Assert.AreEqual(string.Empty, jTree.getPathString());
            Assert.IsTrue(jTree.isValid());
            Assert.AreEqual(ObjectId
                            .FromString("698dd0b8d0c299f080559a1cffc7fe029479a408"), jTree
                            .getObjectId());
            Assert.AreEqual(cList.Count, jTree.getEntrySpan());

            var subtrees = new List <CGitLsTreeRecord>();

            foreach (CGitLsTreeRecord r in cTree)
            {
                if (FileMode.Tree.Equals(r.Mode))
                {
                    subtrees.Add(r);
                }
            }
            Assert.AreEqual(subtrees.Count, jTree.getChildCount());

            for (int i = 0; i < jTree.getChildCount(); i++)
            {
                DirCacheTree     sj = jTree.getChild(i);
                CGitLsTreeRecord sc = subtrees[i];
                Assert.AreEqual(sc.Path, sj.getNameString());
                Assert.AreEqual(sc.Path + "/", sj.getPathString());
                Assert.IsTrue(sj.isValid());
                Assert.AreEqual(sc.Id, sj.getObjectId());
            }
        }