public void TestRegexLookupCount() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument1.doc"); string description = "Originally a test document used by one of FCS Lite's tests."; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { string regEx = @"(The quick brown fox jumped over the lazy dog.){1}"; string[] context = { "Paragraph", "HeaderOrFooter", "Comment", "Footnote", "Endnote", "TrackChange", "TextBox", "Reviewer", "HiddenText", "SmallText", "WhiteText", "AttachedTemplate", "SmartTag", "Version", "AutoVersion", "Field", "Hyperlink", "RoutingSlip", "Variable", "HiddenSlide", "SpeakerNote" }; int regexCount = analysis.RegExLookupCount(testFile, regEx, context); Assert.AreEqual(1, regexCount, "Expected the value of regexCount to be [1], but was [" + regexCount + "]"); } }
public void TestTextLookupCount() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument1.doc"); string description = "Originally a test document used by one of FCS Lite's tests."; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { string[] content = { "A4CC013A-BBE2-4a21-8651-F4511D689EDA" }; string[] context = { "Paragraph", "Header", "Footer", "Comment", "Footnote", "Endnote", "TrackChange", "TextBox", "Reviewer", "HiddenText", "SmallText", "WhiteText", "AttachedTemplate", "SmartTag", "Version", "AutoVersion", "Field", "Hyperlink", "RoutingSlip", "Variable", "HiddenSlide", "SpeakerNote" }; int textCount = analysis.TextLookupCount(testFile, content, context); Assert.AreEqual(6, textCount, "Expected value of textCount to be [5], but was [" + textCount + "]"); } }
public void TestTextLookupCountCorruptedWordDoc() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument1.doc"); string description = "Originally a test document used by one of FCS Lite's tests."; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { string[] content = { "A4CC013A-BBE2-4a21-8651-F4511D689EDA" }; string[] context = { "Paragraph", "Header", "Footer", "Comment", "Footnote", "Endnote", "TrackChange", "TextBox", "Reviewer", "HiddenText", "SmallText", "WhiteText", "AttachedTemplate", "SmartTag", "Version", "AutoVersion", "Field", "Hyperlink", "RoutingSlip", "Variable", "HiddenSlide", "SpeakerNote" }; try { int textCount = analysis.TextLookupCount(testFile, content, context); Assert.Fail("Should have thrown an exception on reading corrupted WORD document"); } catch (Exception e) { string msg = e.Message; } } }
public void TestHtmlHTMLTextLookupCount() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string filename = m_testunicodehtmldoc; string description = "An HTML file"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { string[] content = { "testing" }; string[] context = { "Paragraph" }; int textCount = analysis.TextLookupCount(testFile, content, context); Assert.AreEqual(1, textCount, "Expected value of textCount to be [1], but was [" + textCount + "]"); // this removed until we can look at HtmlAgilityPack's use of codepages //string[] content2 = { "正規表現" }; //textCount = analysis.TextLookupCount(testFile, content2, context); //Assert.AreEqual(1, textCount, "Expected value of textCount to be [1], but was [" + textCount + "]"); } }
public void TestCannotOpenContentInFileType() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string[] fileTypes = { "RTFDocument", "XMLDocument" }; string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument1.doc"); string description = "Originally a test document used by one of FCS Lite's tests."; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { //file type is incorrect, not password protected Assert.IsFalse(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result in 'incorrect file type, not password protected'"); //file type is correct, not password protected fileTypes = new string[] { "XMLDocument", "WordDocument", "RTFDocument"}; Assert.IsFalse(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result in 'correct file type, not password protected'"); } filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\PasswordProtectedDoc.doc"); description = "A password protected file"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { //file type is correct and document is password protected - nominal .doc case Assert.IsTrue(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result in 'incorrect file type, not password protected'"); //file type is incorrect, password protected fileTypes = new string[] { "RTFDocument", "ExcelSpreadsheet" }; Assert.IsFalse(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result in 'incorrect file type, not password protected'"); } //nominal xls filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\PasswordProtected.xls"); description = "A password protected file"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { //file type is correct and document is password protected fileTypes = new string[] { "ExcelSheet", "PowerPoint", "PDFDocument", "ZIP", "RTFDocument" }; Assert.IsTrue(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result on xls"); } //nominal ppt filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\PasswordProtected.ppt"); description = "A password protected file"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { //file type is correct and document is password protected Assert.IsTrue(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result on ppt"); } //nominal pdf filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\PasswordProtected.pdf"); description = "A password protected file"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { //file type is correct and document is password protected Assert.IsTrue(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result on pdf"); } //nominal zip filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\PasswordProtected.zip"); description = "A password protected file"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { //file type is correct and document is password protected Assert.IsTrue(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result on zip"); } //nominal rtf filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\profanity.rtf"); description = "A password protected file"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { //file type is correct and document is password protected Assert.IsFalse(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result on rtf"); } //nominal text filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument.txt"); description = "A password protected file"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { //file type is correct and document is password protected Assert.IsFalse(analysis.CannotOpenContentInFileType(testFile, fileTypes), "unexpected result on rtf"); } }
public void TestRegexLookupInFileType() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string regEx = @"(The quick brown fox jumped over the lazy dog.){1}"; string[] context = { "Paragraph", "HeaderOrFooter", "Comment", "Footnote", "Endnote", "TrackChange", "TextBox", "Reviewer", "HiddenText", "SmallText", "WhiteText", "AttachedTemplate", "SmartTag", "Version", "AutoVersion", "Field", "Hyperlink", "RoutingSlip", "Variable", "HiddenSlide", "SpeakerNote" }; string[] fileTypes = { "WordDocument" }; string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument1.doc"); string description = "Originally a test document used by one of FCS Lite's tests."; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundRegex = analysis.RegExLookupInFileType(testFile, fileTypes, regEx, context); Assert.AreEqual(1, foundRegex.Length); } //right file type, wrong content filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\testlookup.doc"); description = "File doesn't contain any of the stuff we're searching for"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundRegex = analysis.RegExLookupInFileType(testFile, fileTypes, regEx, context); Assert.AreEqual(0, foundRegex.Length); } //wrong file type, right content filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument.txt"); description = "File contains things we're looking for"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundRegex = analysis.RegExLookupInFileType(testFile, fileTypes, regEx, context); Assert.AreEqual(0, foundRegex.Length); } //now change file type and repeat with previous doc - right file type, right content fileTypes[0] = "TextDocument"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundRegex = analysis.RegExLookupInFileType(testFile, fileTypes, regEx, context); Assert.AreEqual(1, foundRegex.Length); } }
public void TestTextLookupInFileTypeMatchWholeWord() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string[] content = { "A4CC013A-BBE2-4a21-8651-F4511D689EDA" }; bool[] matchWholeWords = { false }; string[] context = { "Paragraph", "Header", "Footer", "Comment", "Footnote", "Endnote", "TrackChange", "TextBox", "Reviewer", "HiddenText", "SmallText", "WhiteText", "AttachedTemplate", "SmartTag", "Version", "AutoVersion", "Field", "Hyperlink", "RoutingSlip", "Variable", "HiddenSlide", "SpeakerNote" }; string[] fileTypes = { "WordDocument" }; //right file type, right content string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument1.doc"); string description = "Originally a test document used by one of FCS Lite's tests."; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundContents = analysis.TextLookupInFileType(testFile, fileTypes, content, context, matchWholeWords); Assert.AreEqual(6, foundContents.Length); } matchWholeWords = new bool[] { true }; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundContents = analysis.TextLookupInFileType(testFile, fileTypes, content, context, matchWholeWords); Assert.AreEqual(5, foundContents.Length); } //right file type, wrong content filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\testlookup.doc"); description = "File doesn't contain any of the stuff we're searching for"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundContents = analysis.TextLookupInFileType(testFile, fileTypes, content, context, matchWholeWords); Assert.AreEqual(0, foundContents.Length); } //wrong file type, right content filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\TestDocument.txt"); description = "File contains things we're looking for"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundContents = analysis.TextLookupInFileType(testFile, fileTypes, content, context, matchWholeWords); Assert.AreEqual(0, foundContents.Length); } //now change file type and repeat with previous doc - right file type, right content fileTypes[0] = "TextDocument"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { System.Collections.DictionaryEntry[] foundContents = analysis.TextLookupInFileType(testFile, fileTypes, content, context, matchWholeWords); Assert.AreEqual(1, foundContents.Length); } }
public void TestFallbackTextLookupCountBadType() { try { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\unrecognized_type.xyz"); string description = "A random chunk of binary rubbish"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { string[] content = { "text" }; string[] context = { "Paragraph" }; int textCount = analysis.TextLookupCount(testFile, content, context); } } catch(Exception) { Assert.Fail("Fallback should not cause an exception when analysing a corrupt document"); } }
public void TestFallbackTextLookupCount() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\lotus-wordpro.lwp"); string description = "A lotus wordpro document"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { string[] content = { "text" }; string[] context = { "Paragraph" }; int textCount = analysis.TextLookupCount(testFile, content, context); Assert.AreEqual(69, textCount, "Expected value of textCount to be [69], but was [" + textCount + "]"); } }
public void TestPdfLookupCountOnCorruptedPdf() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\test2corrupted.pdf"); string description = "A corrupted pdf document"; try { using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { string[] content = { "point" }; string[] context = { "Paragraph" }; int textCount = analysis.TextLookupCount(testFile, content, context); Assert.Fail("Should have thrown an exception on reading corrupt document"); } } catch (Exception e) { string message = e.Message; } }
public void TestPdfTextLookupCountOverLineBreaks2() { Workshare.Policy.Condition.ContentAnalysis analysis = new Workshare.Policy.Condition.ContentAnalysis(); string filename = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\ContentAnalysis.Tests\docs\testlookup_adobe.pdf"); string description = "Test pdf document"; using (IFile testFile = Workshare.Policy.Engine.FileFactory.Create(filename, description)) { string[] content = { "This first paragraph extends over multiple" };// multiple lines" }; string[] context = { "Paragraph" }; int textCount = analysis.TextLookupCount(testFile, content, context); Assert.AreEqual(1, textCount, "Expected value of textCount to be [1], but was [" + textCount + "]"); } }