Пример #1
0
        public void TestNonEmptyConstructor()
        {
            DirectoryProperty property1 = new DirectoryProperty("parent");
            DirectoryProperty property2 = new DirectoryProperty("child1");

            property1.AddChild(property2);
            property1.AddChild(new DocumentProperty("child2", 2000));
            property2.AddChild(new DocumentProperty("child3", 30000));
            DirectoryNode node = new DirectoryNode(property1,
                                                   new POIFSFileSystem(), null);

            // Verify that GetEntries behaves correctly
            int         count = 0;
            IEnumerator iter  = node.Entries;

            while (iter.MoveNext())
            {
                count++;
                //iter.Current;
            }
            Assert.AreEqual(2, count);

            // Verify behavior of IsEmpty
            Assert.IsTrue(!node.IsEmpty);

            // Verify behavior of EntryCount
            Assert.AreEqual(2, node.EntryCount);

            // Verify behavior of Entry
            DirectoryNode child1 = (DirectoryNode)node.GetEntry("child1");

            child1.GetEntry("child3");
            node.GetEntry("child2");
            try
            {
                node.GetEntry("child3");
                Assert.Fail("Should have caught FileNotFoundException");
            }
            catch (FileNotFoundException)
            {
                // as expected
            }

            // Verify behavior of isDirectoryEntry
            Assert.IsTrue(node.IsDirectoryEntry);

            // Verify behavior of GetName
            Assert.AreEqual(property1.Name, node.Name);

            // Verify behavior of isDocumentEntry
            Assert.IsTrue(!node.IsDocumentEntry);

            // Verify behavior of GetParent
            Assert.IsNull(node.Parent);
        }
Пример #2
0
        protected void PopulatePropertyTree(DirectoryProperty root)
        {
            try
            {
                int index = root.ChildIndex;

                if (!Property.IsValidIndex(index))
                    return;

                Stack<Property> children = new Stack<Property>();

                children.Push(_properties[index]);

                while (children.Count != 0)
                {
                    Property property = children.Pop();
                    if (property == null)
                    {
                        // unknown / unsupported / corrupted property, skip
                        continue;
                    }
                    root.AddChild(property);

                    if (property.IsDirectory)
                    {
                        PopulatePropertyTree((DirectoryProperty)property);
                    }

                    index = property.PreviousChildIndex;
                    if (Property.IsValidIndex(index))
                    {
                        children.Push(_properties[index]);
                    }

                    index = property.NextChildIndex;
                    if (Property.IsValidIndex(index))
                    {
                        children.Push(_properties[index]);
                    }
                }

            }
            catch (IOException ex)
            {
                throw ex;
            }
        }
        public void TestPreWrite()
        {
            CreateBasicDirectoryProperty();
            _property.PreWrite();

            // shouldn't Change anything at all
            VerifyProperty();
            VerifyChildren(0);

            // now try Adding 1 property
            CreateBasicDirectoryProperty();
            _property.AddChild(new LocalProperty(1));
            _property.PreWrite();

            // update children index
            _testblock[0x4C] = 1;
            _testblock[0x4D] = 0;
            _testblock[0x4E] = 0;
            _testblock[0x4F] = 0;
            VerifyProperty();
            VerifyChildren(1);

            // now try Adding 2 properties
            CreateBasicDirectoryProperty();
            _property.AddChild(new LocalProperty(1));
            _property.AddChild(new LocalProperty(2));
            _property.PreWrite();

            // update children index
            _testblock[0x4C] = 2;
            _testblock[0x4D] = 0;
            _testblock[0x4E] = 0;
            _testblock[0x4F] = 0;
            VerifyProperty();
            VerifyChildren(2);

            // beat on the children allocation code
            for (int count = 1; count < 100; count++)
            {
                CreateBasicDirectoryProperty();
                for (int j = 1; j < (count + 1); j++)
                {
                    _property.AddChild(new LocalProperty(j));
                }
                _property.PreWrite();
                VerifyChildren(count);
            }
        }
Пример #4
0
        public void TestNonEmptyConstructor()
        {
            DirectoryProperty property1 = new DirectoryProperty("parent");
            DirectoryProperty property2 = new DirectoryProperty("child1");

            property1.AddChild(property2);
            property1.AddChild(new DocumentProperty("child2", 2000));
            property2.AddChild(new DocumentProperty("child3", 30000));
            DirectoryNode node = new DirectoryNode(property1, new POIFSFileSystem(), null);

            // Verify that GetEntries behaves correctly
            int count = 0;
            IEnumerator iter = node.Entries;

            while (iter.MoveNext())
            {
                count++;
                //iter.Current;
            }
            Assert.AreEqual(2, count);

            // Verify behavior of IsEmpty
            Assert.IsTrue(!node.IsEmpty);

            // Verify behavior of EntryCount
            Assert.AreEqual(2, node.EntryCount);

            // Verify behavior of Entry
            DirectoryNode child1 = (DirectoryNode)node.GetEntry("child1");

            child1.GetEntry("child3");
            node.GetEntry("child2");
            try
            {
                node.GetEntry("child3");
                Assert.Fail("Should have caught FileNotFoundException");
            }
            catch (FileNotFoundException)
            {

                // as expected
            }

            // Verify behavior of isDirectoryEntry
            Assert.IsTrue(node.IsDirectoryEntry);

            // Verify behavior of GetName
            Assert.AreEqual(property1.Name, node.Name);

            // Verify behavior of isDocumentEntry
            Assert.IsTrue(!node.IsDocumentEntry);

            // Verify behavior of GetParent
            Assert.IsNull(node.Parent);
        }