Esempio n. 1
0
        public void test008_SubtreeInternalSorting()
        {
            Tree t = new Tree(db);
            FileTreeEntry e0 = t.AddFile("a-b");
            FileTreeEntry e1 = t.AddFile("a-");
            FileTreeEntry e2 = t.AddFile("a=b");
            Tree e3 = t.AddTree("a");
            FileTreeEntry e4 = t.AddFile("a=");

            TreeEntry[] ents = t.Members;
            Assert.AreSame(e1, ents[0]);
            Assert.AreSame(e0, ents[1]);
            Assert.AreSame(e3, ents[2]);
            Assert.AreSame(e4, ents[3]);
            Assert.AreSame(e2, ents[4]);
        }
Esempio n. 2
0
 public void test007_manyFileLookup()
 {
     Tree t = new Tree(db);
     var files = new List<FileTreeEntry>(26 * 26);
     for (char level1 = 'a'; level1 <= 'z'; level1++)
     {
         for (char level2 = 'a'; level2 <= 'z'; level2++)
         {
             String n = "." + level1 + level2 + "9";
             FileTreeEntry f = t.AddFile(n);
             Assert.IsNotNull(f, "File " + n + " added.");
             Assert.AreEqual(n, f.Name);
             files.Add(f);
         }
     }
     Assert.AreEqual(files.Count, t.MemberCount);
     TreeEntry[] ents = t.Members;
     Assert.IsNotNull(ents);
     Assert.AreEqual(files.Count, ents.Length);
     for (int k = 0; k < ents.Length; k++)
     {
         Assert.IsTrue(files[k] == ents[k], "File " + files[k].Name + " is at " + k + ".");
     }
 }
Esempio n. 3
0
        public void test002_addFile()
        {
            Tree t = new Tree(db);
            t.Id = SOME_FAKE_ID;
            Assert.IsTrue(t.Id != null);
            Assert.IsFalse(t.IsModified);

            String n = "bob";
            FileTreeEntry f = t.AddFile(n);
            Assert.IsNotNull(f);
            Assert.AreEqual(n, f.Name);
            Assert.AreEqual(f.Name, Encoding.UTF8.GetString(f.NameUTF8));
            Assert.AreEqual(n, f.FullName);
            Assert.IsTrue(f.Id == null);
            Assert.IsTrue(t.IsModified);
            Assert.IsTrue(t.Id == null);
            Assert.IsTrue(t.FindBlobMember(f.Name) == f);

            TreeEntry[] i = t.Members;
            Assert.IsNotNull(i);
            Assert.IsTrue(i != null && i.Length > 0);
            Assert.IsTrue(i != null && i[0] == f);
            Assert.IsTrue(i != null && i.Length == 1);
        }
Esempio n. 4
0
 public void test005_addRecursiveFile()
 {
     Tree t = new Tree(db);
     FileTreeEntry f = t.AddFile("a/b/c");
     Assert.IsNotNull(f);
     Assert.AreEqual(f.Name, "c");
     Assert.AreEqual(f.Parent.Name, "b");
     Assert.AreEqual(f.Parent.Parent.Name, "a");
     Assert.IsTrue(t == f.Parent.Parent.Parent, "t is great-grandparent");
 }
Esempio n. 5
0
        public FileTreeEntry AddFile(byte[] s, int offset)
        {
            int slash;
            int p;

            for (slash = offset; slash < s.Length && s[slash] != '/'; slash++)
            {
                // search for path component terminator
                // [henon] body is empty by intention!
            }

            EnsureLoaded();
            byte xlast = (byte)(slash < s.Length ? '/' : 0);
            p = BinarySearch(_contents, s, xlast, offset, slash);
            if (p >= 0 && slash < s.Length && _contents[p] is Tree)
                return ((Tree)_contents[p]).AddFile(s, slash + 1);

            byte[] newName = SubString(s, offset, slash);
            if (p >= 0)
                throw new EntryExistsException(Constants.CHARSET.GetString(newName));
            else if (slash < s.Length)
            {
                Tree t = new Tree(this, newName);
                InsertEntry(p, t);
                return t.AddFile(s, slash + 1);
            }
            else
            {
                FileTreeEntry f = new FileTreeEntry(this, null, newName, false);
                InsertEntry(p, f);
                return f;
            }
        }