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 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 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); } }
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"); } }
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"); } }
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"); } }
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); } } }
//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)"); } } } } }
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")); } }
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); } } }
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"); } }
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); } }
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); } }
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); } }
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); } } }