public void TestDiscoverRealSmallTextFromDocument()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document5.xml", FileMode.Open))
            {
                if (File.Exists(TESTFILE_DIR + "Document1_result.xml"))
                    File.Delete(TESTFILE_DIR + "Document1_result.xml");

                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from);

                xfb.AddNodesToTriggerList(DocxMetadataDefinitions.SmallDocumentText);

                DocumentText dt = xfb.DocumentText;

                xfb.Execute();

                Assert.AreEqual(1, dt.GetTextTypes(ContentType.SmallText).Count, "expected to get a small text type created");
                IAbstractTextType ttSmall = dt.GetTextTypes(ContentType.SmallText)[0];

                Assert.IsNotNull(ttSmall, "Missing Small Text Type");
                Assert.AreEqual(2, ttSmall.GetChildCount(), "we expected to get 2 items of small text");

                Assert.AreEqual("Very hard to see me", ttSmall.GetChild(0).GetInfo("Content")[0].value);
                Assert.AreEqual("even harder to see this", ttSmall.GetChild(1).GetInfo("Content")[0].value);


            }
        }
        public void TestDiscoverRealCommentsWithLookupTable()
        {
            PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
            pca.AddAuthor(0, "Mena Shervill", 1);
            pca.AddAuthor(1, "bobh", 2);

            using (Stream from = File.Open(TESTFILE_DIR + "Ppt_comment1.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter smbxf = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                smbxf.ConnectToInputStream(from);

                smbxf.AddNodesToTriggerList(PptxMetadataDefinitions.SlideComment(pca.AuthorByIDLookupDict));

                DocumentText dt = smbxf.DocumentText;
                smbxf.Execute();

                Assert.AreEqual(1, dt.GetTextTypes(ContentType.Comment).Count, "expected to get a comment text type created");
                IAbstractTextType ttContent = dt.GetTextTypes(ContentType.Comment)[0];

                Assert.IsNotNull(ttContent, "Missing Content Text Type");
                Assert.AreEqual(3, ttContent.GetChildCount(), "we expected to get 3 items of comment text");

                Assert.AreEqual("hjrehjkwr", ttContent.GetChild(0).GetInfo("Content")[0].value);
                Assert.AreEqual("Another comment", ttContent.GetChild(1).GetInfo("Content")[0].value);
                Assert.AreEqual("For use as no doubt", ttContent.GetChild(2).GetInfo("Content")[0].value);

                Assert.AreEqual("Mena Shervill", ttContent.GetChild(0).GetInfo("Author")[0].value);
                Assert.AreEqual("bobh", ttContent.GetChild(1).GetInfo("Author")[0].value);
                Assert.AreEqual("bobh", ttContent.GetChild(2).GetInfo("Author")[0].value);
            }
        }
        public void TestDiscoverHiddenSlide()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Ppt_HiddenSlide.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter smbxf = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                smbxf.ConnectToInputStream(from);

                smbxf.AddNodesToTriggerList(PptxMetadataDefinitions.HiddenSlide(4));

                DocumentText dt = smbxf.DocumentText;

                smbxf.Execute();
                Assert.AreEqual(1, dt.GetTextTypes(ContentType.HiddenSlide).Count, "expected to get a hidden slide text type created");
                IAbstractTextType ttHiddenSlide = dt.GetTextTypes(ContentType.HiddenSlide)[0];
                Assert.IsNotNull(ttHiddenSlide);
                Assert.AreEqual(1, ttHiddenSlide.GetChildCount(), "Should be only 1 report back");
                Assert.AreEqual("4", ttHiddenSlide.GetChild(0).GetInfo("SlideNumber")[0].value);
            }
        }
示例#4
0
        public void TestEmptyNodeEffectsRemovedCorrectly()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Extreme1.xml", FileMode.Open))
            {
                EndNodeRememberingEffect.m_lastEnd = "";
                EndNodeRememberingEffect.m_levelOffset = 0;
              
                if (File.Exists(TESTFILE_DIR + "Extreme1_result.xml"))
                    File.Delete(TESTFILE_DIR + "Extreme1_result.xml");

                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from);

                xfb.AddNodeToTriggerList(new TriggeringNodeDefinition(NamespaceId.w, "noProof", null, null,
                   GetEndNodeRememberingDescriptor()));
                xfb.Execute();

                Assert.AreEqual("w:noProof", EndNodeRememberingEffect.m_lastEnd, "We don't expect to recieve an end note notification for an empty node trigger");
            }
        }
示例#5
0
		//VE4055: This functionality has been disabled, but we retain the test for when VE1983 is restored.
		//[Test]
        public void TestCheckingCleaningAndDiscoveryXMLOutputDifferWith2010DocumentsUsingNestedChoices()
        {
            for (int count = 0; count < 2; count++)
            {
                using (Stream from = File.Open(TESTFILE_DIR + "docx2010whitetextintextbox2.xml", FileMode.Open))
                {
                    using (Stream to = new MemoryStream())
                    {
                        StateMachineBasedXmlFilter xmlFilter = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                        xmlFilter.ConnectToInputStream(from);
                        xmlFilter.ConnectToOutputStream(to);

                        xmlFilter.AddNodesToTriggerList(DocxMetadataDefinitions.HiddenDocumentText);

                        bool isCleaning = (count != 0);
                        xmlFilter.IsCleaning = isCleaning;
                        xmlFilter.Execute();

                        to.Position = 0;
                        XmlDocument doc = new XmlDocument();
                        doc.Load(to);

                        string s = doc.InnerXml;

                        if (isCleaning)
                        {
                            Assert.IsTrue(s.Contains("mc:Choice"), "Cleaning should include this Node (mc:Choice)");
                            Assert.IsTrue(s.Contains("mc:Fallback"), "Cleaning should include this Node (mc:Fallback)");
                        }
                        else
                        {
                            Assert.IsFalse(s.Contains("mc:Choice"), "Discovery should ignore this Node (mc:Choice)");
                            Assert.IsTrue(s.Contains("mc:Fallback"), "Discovery should include this Node (mc:Fallback)");
                        }
                    }
                }
            }
        }
示例#6
0
        public void TestOneLevelFiltering_ExtremeCase()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Extreme1.xml", FileMode.Open))
            {
                if (File.Exists(TESTFILE_DIR + "Extreme1_result.xml"))
                    File.Delete(TESTFILE_DIR + "Extreme1_result.xml");
                using (Stream to = new MemoryStream())
                {

                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);

                    xfb.AddNodeToTriggerList(new TriggeringNodeDefinition(NamespaceId.w, "MadeUpTag", null, null,
                        GetDeleteNodeButKeepContentsDescriptor()));

                    xfb.Execute();
                    to.Position = 0;
                    XmlDocument doc = new XmlDocument();
                    doc.Load(to);
                    XmlNodeList subNodes = doc.SelectNodes("*");
                    Assert.AreEqual(1, subNodes.Count);
                    Assert.IsTrue(subNodes.Item(0).InnerXml.Length > 0);
                }
            }
        }
        public void TestDiscoverRealHiddenTextWithStyles()
        {
            List<TriggeringNodeDefinition> existingTriggers = DocxMetadataDefinitions.HiddenDocumentText;

            using (Stream from = File.Open(TESTFILE_DIR + "hidden_styles.xml", FileMode.Open))
            {
                StyleSheet sr = new StyleSheet(new CommonNamespaces(OpenXmlFormat.Transitional));
                sr.ConnectToInputStream(from);
                sr.Execute();
                sr.Resolve();

                List<TriggeringNodeDefinition> newTriggers = sr.GenerateStyleTriggers(existingTriggers);
                foreach (TriggeringNodeDefinition tnd in newTriggers)
                {
                    existingTriggers.Add(tnd);
                }
            }

            using (Stream from2 = File.Open(TESTFILE_DIR + "hidden_styles_document.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from2);

                foreach (TriggeringNodeDefinition tnd in existingTriggers)
                {
                    xfb.AddNodeToTriggerList(tnd);
                }

                DocumentText dt = xfb.DocumentText;
                xfb.Execute();

                TextType ttHidden = dt.GetTextTypes(ContentType.HiddenText)[0] as TextType;
                Assert.IsNotNull(ttHidden);
                Assert.IsTrue(ttHidden.GetChildCount() > 0);

                Assert.AreEqual("This is some text in the document in a hidden paragraph.", ttHidden.GetChild(0).GetInfo("Content")[0].value);
                Assert.AreEqual("This para contains ", ttHidden.GetChild(1).GetInfo("Content")[0].value);
                Assert.AreEqual(" text.", ttHidden.GetChild(2).GetInfo("Content")[0].value);
                Assert.AreEqual("This hidden para contains ", ttHidden.GetChild(3).GetInfo("Content")[0].value);
                Assert.AreEqual(" text.", ttHidden.GetChild(4).GetInfo("Content")[0].value);
                Assert.AreEqual("This text in hidden style with ", ttHidden.GetChild(5).GetInfo("Content")[0].value);
                Assert.AreEqual("embedded.", ttHidden.GetChild(6).GetInfo("Content")[0].value);
                Assert.AreEqual("This text in hidden style with ", ttHidden.GetChild(7).GetInfo("Content")[0].value);
                Assert.AreEqual(" embedded.", ttHidden.GetChild(8).GetInfo("Content")[0].value);



            }

        }
        public void TestDiscoverSlideNotesDoesNotIncludeFields()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Ppt_notesSlide1.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter smbxf = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                smbxf.ConnectToInputStream(from);

                smbxf.AddNodesToTriggerList(PptxMetadataDefinitions.SpeakerNote);

                DocumentText dt = smbxf.DocumentText;
                smbxf.Execute();

                Assert.AreEqual(1, dt.GetTextTypes(ContentType.SpeakerNote).Count, "expected to get a Speaker Note text type created");
                IAbstractTextType ttSpeakerNotes = dt.GetTextTypes(ContentType.SpeakerNote)[0];
                Assert.IsNotNull(ttSpeakerNotes);
                Assert.AreEqual(1, ttSpeakerNotes.GetChildCount(), "Should be only 1 report back");
            }
        }
示例#9
0
        public void TestDiscoverRealHiddenParaWithNonHiddenBit()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document2.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from);

                xfb.AddNodesToTriggerList(DocxMetadataDefinitions.HiddenDocumentText);

                DocumentText dt = xfb.DocumentText;

                xfb.Execute();

                List<IAbstractTextType> types = dt.GetTextTypes();
                IAbstractTextType hiddenTextType = null;
                foreach (IAbstractTextType tt in types)
                {
                    if (tt.GetContentType() == ContentType.HiddenText)
                    {
                        hiddenTextType = tt;
                    }
                }
                Assert.IsNotNull(hiddenTextType, "Missing Hidden Text Type");
                Assert.AreEqual(2, hiddenTextType.GetChildCount(), "not the expect number of items - probably didn't notice the vanish val=0 tag");
                Assert.AreEqual("This is a ", hiddenTextType.GetChild(0).GetInfo(0).value);
                Assert.AreEqual(" in hidden style", hiddenTextType.GetChild(1).GetInfo(0).value);
            }
        }
示例#10
0
        public void TestDiscoverRealHiddenTextFromDocument()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document1.xml", FileMode.Open))
            {
                if (File.Exists(TESTFILE_DIR + "Document1_result.xml"))
                    File.Delete(TESTFILE_DIR + "Document1_result.xml");

                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from);

                xfb.AddNodesToTriggerList(DocxMetadataDefinitions.HiddenDocumentText);

                DocumentText dt = xfb.DocumentText;

                xfb.Execute();

                List<IAbstractTextType> types = dt.GetTextTypes();
                IAbstractTextType hiddenTextType = null;
                foreach (IAbstractTextType tt in types)
                {
                    if (tt.GetContentType() == ContentType.HiddenText)
                    {
                        hiddenTextType = tt;
                    }

                }
                Assert.IsNotNull(hiddenTextType, "Missing Hidden Text Type");
                Assert.AreEqual(1, hiddenTextType.GetChildCount(), "not the expect number of items");
                Assert.AreEqual("this text will be hidden.", hiddenTextType.GetChild(0).GetInfo(0).value);
            }
        }
示例#11
0
        public void TestCleanRealHiddenTextFromDocument()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document1.xml", FileMode.Open))
            {
                if (File.Exists(TESTFILE_DIR + "Document1_result.xml"))
                    File.Delete(TESTFILE_DIR + "Document1_result.xml");

                using (Stream to = new MemoryStream())
                {
                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);

                    xfb.AddNodesToTriggerList(DocxMetadataDefinitions.HiddenDocumentText);

                    xfb.Execute();

                    to.Position = 0;
                    XmlDocument doc = new XmlDocument();
                    doc.Load(to);
                    string sXml = doc.InnerText;
                    Assert.IsTrue(sXml.IndexOf("this text will be hidden.") == -1);

                    DocxTestUtilities.ValidateDocxMainStream(doc, TESTFILE_DIR);
                }
            }
        }
示例#12
0
        public void TestFilterOutRealCommentsFromDocument()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document1.xml", FileMode.Open))
            {
                if (File.Exists(TESTFILE_DIR + "Document1_result.xml"))
                    File.Delete(TESTFILE_DIR + "Document1_result.xml");
                using (Stream to = File.Open(TESTFILE_DIR + "Document1_result.xml", FileMode.CreateNew))
                {

                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);

                    xfb.AddNodeToTriggerList(new TriggeringNodeDefinition(NamespaceId.w, "commentRangeStart", new NullAttributeFilter()));
                    xfb.AddNodeToTriggerList(new TriggeringNodeDefinition(NamespaceId.w, "commentRangeEnd", new NullAttributeFilter()));
                    xfb.AddNodeToTriggerList(new TriggeringNodeDefinition(NamespaceId.w, "commentReference", new NullAttributeFilter()));
                    xfb.AddNodeToTriggerList(new TriggeringNodeDefinition(NamespaceId.w, "rStyle", "val", "CommentReference"));

                    xfb.Execute();
                }
            }
            Assert.IsTrue(XmlDocumentComparison.AreEquivalent(TESTFILE_DIR + "Document1_wanted.xml",
                                                              TESTFILE_DIR + "Document1_result.xml"));
        }
示例#13
0
        public void TestFilterOutDeepContentByName()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Extreme2.xml", FileMode.Open))
            {
                if (File.Exists(TESTFILE_DIR + "Extreme2_result.xml"))
                    File.Delete(TESTFILE_DIR + "Extreme2_result.xml");
                using (Stream to = File.Open(TESTFILE_DIR + "Extreme2_result.xml", FileMode.CreateNew))
                {

                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);

                    xfb.AddNodeToTriggerList(new TriggeringNodeDefinition(NamespaceId.w, "fldSimple", new NullAttributeFilter()));

                    xfb.Execute();
                }
            }
            Assert.IsTrue(XmlDocumentComparison.AreEquivalent(TESTFILE_DIR + "Extreme2_wanted.xml",
                                                              TESTFILE_DIR + "Extreme2_result.xml"));
        }
示例#14
0
        public void TestFilterOutNodesWithContentByName()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Comments3.xml", FileMode.Open))
            {
                if (File.Exists(TESTFILE_DIR + "Comments3_result.xml"))
                    File.Delete(TESTFILE_DIR + "Comments3_result.xml");
                using (Stream to = File.Open(TESTFILE_DIR + "Comments3_result.xml", FileMode.CreateNew))
                {

                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);

                    EffectDescriptor td = new EffectDescriptor();
                    td.BlockType = Effect.BlockType.Content;
                    TriggeringNodeDefinition tnd = new TriggeringNodeDefinition(NamespaceId.w, "t", null, null, td);

                    xfb.AddNodeToTriggerList(tnd);

                    xfb.Execute();
                }
            }
            Assert.IsTrue(XmlDocumentComparison.AreEquivalent(TESTFILE_DIR + "Comments3_wanted.xml",
                                                              TESTFILE_DIR + "Comments3_result.xml"));
        }
示例#15
0
        public void TestEffectsRemovedCorrectlyWithOffset()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Extreme1.xml", FileMode.Open))
            {
                EndNodeRememberingEffect.m_lastEnd = "";
                EndNodeRememberingEffect.m_levelOffset = 1;

                if (File.Exists(TESTFILE_DIR + "Extreme1_result.xml"))
                    File.Delete(TESTFILE_DIR + "Extreme1_result.xml");

                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from);

                xfb.AddNodeToTriggerList(new TriggeringNodeDefinition(NamespaceId.w, "fldSimple", null, null,
                   GetEndNodeRememberingDescriptor()));
                xfb.Execute();

                Assert.AreEqual("w:MadeUpTag", EndNodeRememberingEffect.m_lastEnd);
            }
        }
示例#16
0
        public void TestDoesNotDiscoverVisibleSlideAsHidden()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Ppt_VisibleSlide.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter smbxf = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                smbxf.ConnectToInputStream(from);

                smbxf.AddNodesToTriggerList(PptxMetadataDefinitions.HiddenSlide(3));

                DocumentText dt = smbxf.DocumentText;

                smbxf.Execute();
                Assert.AreEqual(0, dt.GetTextTypes(ContentType.HiddenSlide).Count, "Slide is not hidden so should not report that it is");
            }
        }
示例#17
0
        public void TestCanStartTwoEffectsOnOneNode()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document3.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from);

                xfb.AddNodeToTriggerList(BuildMockTriggerNodeThing());
                xfb.AddNodesToTriggerList(DocxMetadataDefinitions.HiddenDocumentText);

                DocumentText dt = xfb.DocumentText;

                xfb.Execute();

                List<IAbstractTextType> types = dt.GetTextTypes();
                IAbstractTextType hiddenTextType = null;
                IAbstractTextType smallTextType = null;
                foreach (IAbstractTextType tt in types)
                {
                    if (tt.GetContentType() == ContentType.HiddenText)
                    {
                        hiddenTextType = tt;
                    }
                    if (tt.GetContentType() == ContentType.SmallText)
                    {
                        smallTextType = tt;
                    }
                }
                Assert.IsNotNull(hiddenTextType, "Missing Hidden Text Type");
                Assert.IsNotNull(smallTextType, "Missing Small Text Type, probably can only launch one type from each node");
                Assert.AreEqual(1, hiddenTextType.GetChildCount(), "not the expect number of items");
                Assert.AreEqual(" some hidden text", hiddenTextType.GetChild(0).GetInfo(0).value);
                Assert.AreEqual(1, smallTextType.GetChildCount(), "not the expect number of items");
                Assert.AreEqual(" some hidden text", smallTextType.GetChild(0).GetInfo(0).value);
            }
        }
示例#18
0
        public void TestDiscoverFooterOnSlideNotes()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Ppt_notesSlide2.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter smbxf = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                smbxf.ConnectToInputStream(from);

                smbxf.AddNodesToTriggerList(PptxMetadataDefinitions.Footer);

                DocumentText dt = smbxf.DocumentText;
                smbxf.Execute();

                Assert.AreEqual(1, dt.GetTextTypes(ContentType.Footer).Count, "expected to get a header text type created");
                IAbstractTextType ttFooter = dt.GetTextTypes(ContentType.Footer)[0];
                Assert.IsNotNull(ttFooter);
                Assert.AreEqual(1, ttFooter.GetChildCount(), "Should be only 1 report back");

                List<IAbstractTextType> ttHeader = dt.GetTextTypes(ContentType.Header);
                Assert.IsNotNull(ttHeader);
                Assert.AreEqual(0, ttHeader.Count, "Should ignore the header");
            }
        }
示例#19
0
        public void TestDealsWithPrettyPrintedXMLSameAsOffice()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document4.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from);

                xfb.AddNodesToTriggerList(DocxMetadataDefinitions.HiddenDocumentText);

                DocumentText dt = xfb.DocumentText;

                xfb.Execute();

                List<IAbstractTextType> types = dt.GetTextTypes();
                IAbstractTextType hiddenTextType = null;
                foreach (IAbstractTextType tt in types)
                {
                    if (tt.GetContentType() == ContentType.HiddenText)
                    {
                        hiddenTextType = tt;
                    }
                }
                Assert.IsNotNull(hiddenTextType, "Missing Hidden Text Type");
                Assert.AreEqual(1, hiddenTextType.GetChildCount(), "not the expect number of items - probably didn't care about the namespace prefix of the vanish tag");
                Assert.AreEqual(" some hidden text", hiddenTextType.GetChild(0).GetInfo(0).value, "Wrong text - we're probably including the para breaks between the tags, which is wrong");
            }
        }
示例#20
0
        public void TestDiscoverRealTrackedChangesFromDocument()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document1.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from);

                xfb.AddNodesToTriggerList(DocxMetadataDefinitions.TrackedChanges);

                DocumentText dt = xfb.DocumentText;

                xfb.Execute();

                List<IAbstractTextType> types = dt.GetTextTypes();
                IAbstractTextType trackChangeType = null;
                foreach (IAbstractTextType tt in types)
                {
                    if (tt.GetContentType() == ContentType.TrackChange)
                    {
                        trackChangeType = tt;
                    }

                }
                Assert.IsNotNull(trackChangeType, "Missing TrackChange Text Type");
                Assert.AreEqual(6, trackChangeType.GetChildCount(), "not the expect number of items");
                Assert.IsTrue(CheckTrackChangeOK(trackChangeType.GetChild(0), " this ", "qaadmin", "Insertion"));
                Assert.IsTrue(CheckTrackChangeOK(trackChangeType.GetChild(1), "unblobbed ", "bobh", "Insertion"));
                Assert.IsTrue(CheckTrackChangeOK(trackChangeType.GetChild(2), "text was inserted ", "qaadmin", "Insertion"));
                Assert.IsTrue(CheckTrackChangeOK(trackChangeType.GetChild(3), "by ", "bobh", "Deletion"));
                Assert.IsTrue(CheckTrackChangeOK(trackChangeType.GetChild(4), "by qaadmin", "qaadmin", "Insertion"));
                Assert.IsTrue(CheckTrackChangeOK(trackChangeType.GetChild(5), "this text will be deleted", "qaadmin", "Deletion"));
            }
        }
示例#21
0
        public void TestCleanRealTrackedChangesFromDocument()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Document1.xml", FileMode.Open))
            {
                using (Stream to = new MemoryStream())
                {
                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);

                    xfb.AddNodesToTriggerList(DocxMetadataDefinitions.TrackedChanges);

                    xfb.Execute();

                    to.Position = 0;
                    XmlDocument doc = new XmlDocument();
                    doc.Load(to);

                    string s = doc.InnerText;
                    Assert.IsTrue(s.IndexOf("this text will be deleted") == -1, "failed to remove the deleted track change");
                    Assert.IsTrue(s.IndexOf("text was inserted") != -1, "removed the inserted track change");

                    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                    CommonNamespaces cns = xfb.CommonNamespaces;
                    nsmgr.AddNamespace("w", cns.GetAtomicName(NamespaceId.w));

                    Assert.AreEqual(0, doc.SelectNodes("//w:del", nsmgr).Count, "we were expecting all the w:del nodes to have gone");
                    Assert.AreEqual(0, doc.SelectNodes("//w:ins", nsmgr).Count, "we were expecting all the w:ins nodes to have gone");

                    DocxTestUtilities.ValidateDocxMainStream(doc, TESTFILE_DIR);
                }
            }
        }
示例#22
0
        public void TestCleanRealHiddenTextWithStyles()
        {
            List<TriggeringNodeDefinition> existingTriggers = DocxMetadataDefinitions.HiddenDocumentText;

            using (Stream from = File.Open(TESTFILE_DIR + "hidden_styles.xml", FileMode.Open))
            {
                StyleSheet sr = new StyleSheet(new CommonNamespaces(OpenXmlFormat.Transitional));
                sr.ConnectToInputStream(from);
                sr.Execute();
                sr.Resolve();

                List<TriggeringNodeDefinition> newTriggers = sr.GenerateStyleTriggers(existingTriggers);
                foreach (TriggeringNodeDefinition tnd in newTriggers)
                {
                    existingTriggers.Add(tnd);
                }
            }

            using (Stream from2 = File.Open(TESTFILE_DIR + "hidden_styles_document.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                xfb.ConnectToInputStream(from2);

                MemoryStream ms = new MemoryStream();
                xfb.ConnectToOutputStream(ms);

                foreach (TriggeringNodeDefinition tnd in existingTriggers)
                {
                    xfb.AddNodeToTriggerList(tnd);
                }

                DocumentText dt = xfb.DocumentText;
                xfb.Execute();

                ms.Position = 0;
                XmlDocument doc = new XmlDocument();
                doc.Load(ms);

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                CommonNamespaces cns = xfb.CommonNamespaces;
                nsmgr.AddNamespace("w", cns.GetAtomicName(NamespaceId.w));

                XmlNodeList nodes = doc.SelectNodes("//w:r/w:t", nsmgr);
                StringBuilder bld = new StringBuilder();
                foreach (XmlNode node in nodes)
                {
                    bld.Append(node.InnerText);
                }

                Assert.AreEqual("non-hiddennon-hidden styleThis para non-hidden. unhidden text anti-hidden style", bld.ToString(), "oops, didn't clean correctly - probably lots to do with w:r's going missing");

                DocxTestUtilities.ValidateDocxMainStream(doc, TESTFILE_DIR);

            }
        }
示例#23
0
        public void TestCleanCustomPropertiesFromDocument()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "customandworkshareproperties.xml", FileMode.Open))
            {
         
                using (Stream to = new MemoryStream())
                {
                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);

                    xfb.AddNodesToTriggerList(GenericMetadataDefinitions.CustomProperties);

                    xfb.Execute();

                    to.Position = 0;
                    XmlDocument doc = new XmlDocument();
                    doc.Load(to);

                    string s = doc.InnerText;
                    Assert.IsTrue(s.IndexOf("rubbish") == -1, "should have removed this value");
                    Assert.IsTrue(s.IndexOf("morestuff") == -1, "should have removed this value");
                    Assert.IsTrue(s.IndexOf("8a9d093f14f8701df17732b2bb182c74") != -1, "shouldn't have removed this value");
                    Assert.IsTrue(s.IndexOf("2") != -1, "shouldn't have removed this value");

                    DocxTestUtilities.ValidateDocxMainStream(doc, TESTFILE_DIR);
                }
            }
        }
示例#24
0
        private static DocumentText CheckDocument(List<TriggeringNodeDefinition> existingTriggers, string document_xml, out XmlDocument xmlDoc)
        {
            using (Stream from = File.Open(document_xml, FileMode.Open))
            {
                using (Stream to = new MemoryStream())
                {
                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);

                    foreach (TriggeringNodeDefinition tnd in existingTriggers)
                    {
                        xfb.AddNodeToTriggerList(tnd);
                    }

                    DocumentText dt = xfb.DocumentText;
                    xfb.Execute();

                    to.Position = 0;
                    xmlDoc = new XmlDocument();
                    xmlDoc.Load(to);


                    return dt;
                }
            }
        }
示例#25
0
        public void TestWithNoFiltering_ExtremeCase()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Extreme1.xml", FileMode.Open))
            {
                if (File.Exists(TESTFILE_DIR + "Extreme1_result.xml"))
                    File.Delete(TESTFILE_DIR + "Extreme1_result.xml");
                using (Stream to = File.Open(TESTFILE_DIR + "Extreme1_result.xml", FileMode.CreateNew))
                {

                    StateMachineBasedXmlFilter xfb = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                    xfb.ConnectToInputStream(from);
                    xfb.ConnectToOutputStream(to);
                    xfb.Execute();
                }
            }
            Assert.IsTrue(XmlDocumentComparison.AreEquivalent(TESTFILE_DIR + "Extreme1.xml",
                                                              TESTFILE_DIR + "Extreme1_result.xml"));
        }