filter/qa/unit/data/sample-markdown.md | 1 + filter/qa/unit/textfilterdetect.cxx | 20 ++++++++++++++++++++ sw/CppunitTest_sw_filter_md.mk | 2 ++ sw/qa/filter/md/data/heading.md | 1 + sw/qa/filter/md/data/list.md | 2 ++ sw/qa/filter/md/md.cxx | 27 +++++++++++++++++++++++++++ 6 files changed, 53 insertions(+)
New commits: commit e2e48ef8e67fd902d51d358fb68e21ba5b9aa45d Author: Ujjawal Kumar <randomfores...@gmail.com> AuthorDate: Thu Jul 10 16:04:12 2025 +0530 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Aug 26 11:50:04 2025 +0200 tdf#162153 Unit tests for Markdown Filter Conflicts: sw/qa/filter/md/md.cxx Change-Id: I45cbc3ecbe0434ef7c852433266a8957c98ae365 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190206 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/filter/qa/unit/data/sample-markdown.md b/filter/qa/unit/data/sample-markdown.md new file mode 100644 index 000000000000..e9f940ccdd42 --- /dev/null +++ b/filter/qa/unit/data/sample-markdown.md @@ -0,0 +1 @@ +For filter detection. diff --git a/filter/qa/unit/textfilterdetect.cxx b/filter/qa/unit/textfilterdetect.cxx index 8c13da5461fd..62fc04c4e362 100644 --- a/filter/qa/unit/textfilterdetect.cxx +++ b/filter/qa/unit/textfilterdetect.cxx @@ -250,6 +250,26 @@ CPPUNIT_TEST_FIXTURE(TextFilterDetectTest, testTdf163295) // Without the fix, this was "writer_PocketWord_File" CPPUNIT_ASSERT_EQUAL(u"generic_Text"_ustr, detection); } + +CPPUNIT_TEST_FIXTURE(TextFilterDetectTest, testMarkdownDetect) +{ + uno::Reference<document::XExtendedFilterDetection> xDetect( + getMultiServiceFactory()->createInstance( + u"com.sun.star.comp.filters.PlainTextFilterDetect"_ustr), + uno::UNO_QUERY); + OUString aURL = createFileURL(u"sample-markdown.md"); + SvFileStream aStream(aURL, StreamMode::READ); + uno::Reference<io::XInputStream> xStream(new utl::OStreamWrapper(aStream)); + uno::Sequence<beans::PropertyValue> aDescriptor + = { comphelper::makePropertyValue(u"DocumentService"_ustr, + u"com.sun.star.text.TextDocument"_ustr), + comphelper::makePropertyValue(u"InputStream"_ustr, xStream), + comphelper::makePropertyValue(u"TypeName"_ustr, u"generic_Markdown"_ustr) }; + xDetect->detect(aDescriptor); + utl::MediaDescriptor aMediaDesc(aDescriptor); + OUString aFilterName = aMediaDesc.getUnpackedValueOrDefault(u"FilterName"_ustr, OUString()); + CPPUNIT_ASSERT_EQUAL(u"Markdown"_ustr, aFilterName); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/CppunitTest_sw_filter_md.mk b/sw/CppunitTest_sw_filter_md.mk index 94f029838eba..1432bc5cb2b6 100644 --- a/sw/CppunitTest_sw_filter_md.mk +++ b/sw/CppunitTest_sw_filter_md.mk @@ -9,6 +9,8 @@ $(eval $(call gb_CppunitTest_CppunitTest,sw_filter_md)) +$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_filter_md)) + $(eval $(call gb_CppunitTest_add_exception_objects,sw_filter_md, \ sw/qa/filter/md/md \ )) diff --git a/sw/qa/filter/md/data/heading.md b/sw/qa/filter/md/data/heading.md new file mode 100644 index 000000000000..bd706e91c44a --- /dev/null +++ b/sw/qa/filter/md/data/heading.md @@ -0,0 +1 @@ +# Heading 1 diff --git a/sw/qa/filter/md/data/list.md b/sw/qa/filter/md/data/list.md new file mode 100644 index 000000000000..77680774a5d3 --- /dev/null +++ b/sw/qa/filter/md/data/list.md @@ -0,0 +1,2 @@ +1. Ordered + * Unordered diff --git a/sw/qa/filter/md/md.cxx b/sw/qa/filter/md/md.cxx index c9f0126e021d..f39cc500e6d7 100644 --- a/sw/qa/filter/md/md.cxx +++ b/sw/qa/filter/md/md.cxx @@ -99,6 +99,33 @@ CPPUNIT_TEST_FIXTURE(Test, testExportingRedlines) CPPUNIT_ASSERT(aParagraph.indexOf("</ins>") >= 0); } +CPPUNIT_TEST_FIXTURE(Test, testHeading) +{ + setImportFilterName("Markdown"); + createSwDoc("heading.md"); + + CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"), getParagraph(1)->getString()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), + getProperty<sal_Int16>(getParagraph(1), u"OutlineLevel"_ustr)); +} + +CPPUNIT_TEST_FIXTURE(Test, testList) +{ + setImportFilterName("Markdown"); + createSwDoc("list.md"); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(SVX_NUM_ARABIC), getNumberingTypeOfParagraph(1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(0), + getProperty<sal_Int16>(getParagraph(1), u"NumberingLevel"_ustr)); + CPPUNIT_ASSERT_EQUAL(OUString("Ordered"), getParagraph(1)->getString()); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(SVX_NUM_CHAR_SPECIAL), + getNumberingTypeOfParagraph(2)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(1), + getProperty<sal_Int16>(getParagraph(2), u"NumberingLevel"_ustr)); + CPPUNIT_ASSERT_EQUAL(OUString("Unordered"), getParagraph(2)->getString()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */