diff --git a/tests/msodde_doc/test_basic.py b/tests/msodde_doc/test_basic.py index 0d366b1..542ad87 100644 --- a/tests/msodde_doc/test_basic.py +++ b/tests/msodde_doc/test_basic.py @@ -30,12 +30,28 @@ class TestReturnCode(unittest.TestCase): def test_valid_doc(self): """ check that a valid doc file leads to 0 exit status """ - print(join(BASE_DIR, 'msodde-doc/test_document.doc')) - self.do_test_validity(join(BASE_DIR, 'msodde-doc/test_document.doc')) + for filename in ('dde-test-from-office2003', 'dde-test-from-office2016', + 'harmless-clean'): + self.do_test_validity(join(BASE_DIR, 'msodde-doc', + filename + '.doc')) def test_valid_docx(self): """ check that a valid docx file leads to 0 exit status """ - self.do_test_validity(join(BASE_DIR, 'msodde-doc/test_document.docx')) + for filename in 'dde-test', 'harmless-clean': + self.do_test_validity(join(BASE_DIR, 'msodde-doc', + filename + '.docx')) + + def test_valid_docm(self): + """ check that a valid docm file leads to 0 exit status """ + for filename in 'dde-test', 'harmless-clean': + self.do_test_validity(join(BASE_DIR, 'msodde-doc', + filename + '.docm')) + + def test_invalid_other(self): + """ check that xml do not work yet """ + for extn in '-2003.xml', '.xml': + self.do_test_validity(join(BASE_DIR, 'msodde-doc', + 'harmless-clean' + extn), True) def test_invalid_none(self): """ check that no file argument leads to non-zero exit status """ @@ -63,7 +79,10 @@ class TestReturnCode(unittest.TestCase): if se.code is None: return_code = 0 - self.assertEqual(expect_error, have_exception or (return_code != 0)) + self.assertEqual(expect_error, have_exception or (return_code != 0), + msg='Args={0}, expect={1}, exc={2}, return={3}' + .format(args, expect_error, have_exception, + return_code)) class OutputCapture: @@ -92,27 +111,35 @@ class OutputCapture: class TestDdeInDoc(unittest.TestCase): + def get_dde_from_output(self, capturer): + """ helper to read dde links from captured output """ + have_start_line = False + result = [] + for line in capturer: + if not line.strip(): + continue # skip empty lines + if have_start_line: + result.append(line) + elif line == 'DDE Links:': + have_start_line = True + + self.assertTrue(have_start_line) # ensure output was complete + return result + def test_with_dde(self): """ check that dde links appear on stdout """ with OutputCapture() as capturer: - msodde.main([join(BASE_DIR, 'msodde-doc', 'dde-test.doc')]) - - for line in capturer: - print(line) - pass # we just want to get the last line - - self.assertNotEqual(len(line.strip()), 0) + msodde.main([join(BASE_DIR, 'msodde-doc', + 'dde-test-from-office2003.doc')]) + self.assertNotEqual(len(self.get_dde_from_output(capturer)), 0, + msg='Found no dde links in output for doc file') def test_no_dde(self): """ check that no dde links appear on stdout """ with OutputCapture() as capturer: - msodde.main([join(BASE_DIR, 'msodde-doc', 'test_document.doc')]) - - for line in capturer: - print(line) - pass # we just want to get the last line - - self.assertEqual(line.strip(), '') + msodde.main([join(BASE_DIR, 'msodde-doc', 'harmless-clean.doc')]) + self.assertEqual(len(self.get_dde_from_output(capturer)), 0, + msg='Found dde links in output for doc file') if __name__ == '__main__': diff --git a/tests/test-data/msodde-doc/dde-test.doc b/tests/test-data/msodde-doc/dde-test-from-office2003.doc index da5562c..da5562c 100644 --- a/tests/test-data/msodde-doc/dde-test.doc +++ b/tests/test-data/msodde-doc/dde-test-from-office2003.doc diff --git a/tests/test-data/msodde-doc/dde-test-from-office2016.doc b/tests/test-data/msodde-doc/dde-test-from-office2016.doc new file mode 100644 index 0000000..563de19 --- /dev/null +++ b/tests/test-data/msodde-doc/dde-test-from-office2016.doc diff --git a/tests/test-data/msodde-doc/dde-test.docm b/tests/test-data/msodde-doc/dde-test.docm new file mode 100644 index 0000000..ee5362a --- /dev/null +++ b/tests/test-data/msodde-doc/dde-test.docm diff --git a/tests/test-data/msodde-doc/dde-test.docx b/tests/test-data/msodde-doc/dde-test.docx new file mode 100644 index 0000000..5fba6b2 --- /dev/null +++ b/tests/test-data/msodde-doc/dde-test.docx diff --git a/tests/test-data/msodde-doc/harmless-clean-2003.xml b/tests/test-data/msodde-doc/harmless-clean-2003.xml new file mode 100644 index 0000000..477069f --- /dev/null +++ b/tests/test-data/msodde-doc/harmless-clean-2003.xml @@ -0,0 +1,3 @@ + + +useruser202017-10-26T09:10:00Z2017-10-26T09:10:00Z1392502128816TestThis is a harmless test document.It contains neither macros nor dde links nor embedded viruses nor links to evil web pages. Not even a single insult. Boring!Just to make things slightly interesting, however, we add some ünicöde-ßtringß and different text sizes, colors and fonts \ No newline at end of file diff --git a/tests/test-data/msodde-doc/harmless-clean.doc b/tests/test-data/msodde-doc/harmless-clean.doc new file mode 100644 index 0000000..38fcf72 --- /dev/null +++ b/tests/test-data/msodde-doc/harmless-clean.doc diff --git a/tests/test-data/msodde-doc/harmless-clean.docm b/tests/test-data/msodde-doc/harmless-clean.docm new file mode 100644 index 0000000..f234cae --- /dev/null +++ b/tests/test-data/msodde-doc/harmless-clean.docm diff --git a/tests/test-data/msodde-doc/harmless-clean.docx b/tests/test-data/msodde-doc/harmless-clean.docx new file mode 100644 index 0000000..59099f3 --- /dev/null +++ b/tests/test-data/msodde-doc/harmless-clean.docx diff --git a/tests/test-data/msodde-doc/harmless-clean.xml b/tests/test-data/msodde-doc/harmless-clean.xml new file mode 100644 index 0000000..cd1e53c --- /dev/null +++ b/tests/test-data/msodde-doc/harmless-clean.xml @@ -0,0 +1,3 @@ + + +TestThis is a harmless test document.It contains neither macros nor dde links nor embedded viruses nor links to evil web pages. Not even a single insult. Boring!Just to make things slightly interesting, however, we add some ünicöde-ßtringß and different text sizes, colors and fonts0139250Microsoft Office Word021falseTitel1false288falsefalse16.0000useruser22017-10-26T09:10:00Z2017-10-26T09:10:00Z \ No newline at end of file diff --git a/tests/test-data/msodde-doc/test_document.doc b/tests/test-data/msodde-doc/test_document.doc deleted file mode 100644 index 2c1768f..0000000 --- a/tests/test-data/msodde-doc/test_document.doc +++ /dev/null diff --git a/tests/test-data/msodde-doc/test_document.docx b/tests/test-data/msodde-doc/test_document.docx deleted file mode 100644 index 4dd2265..0000000 --- a/tests/test-data/msodde-doc/test_document.docx +++ /dev/null