starmath/CppunitTest_starmath_import.mk | 26 ------ starmath/qa/extras/mmlimport-test.cxx | 131 ++++++++++++-------------------- 2 files changed, 55 insertions(+), 102 deletions(-)
New commits: commit 9affc1f4eb591cd1bf0ca7d87041d1bdc4936f78 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu Mar 16 13:26:49 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Mar 16 16:04:55 2023 +0000 CppunitTest_starmath_import: inherit from UnoApiTest Change-Id: I77e48dc05c2bd6a36c42e1860a209ed563e71ad8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148988 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/starmath/CppunitTest_starmath_import.mk b/starmath/CppunitTest_starmath_import.mk index 2bbda9c70d92..15c9053facfb 100644 --- a/starmath/CppunitTest_starmath_import.mk +++ b/starmath/CppunitTest_starmath_import.mk @@ -38,6 +38,7 @@ $(eval $(call gb_CppunitTest_use_libraries,starmath_import,\ sm \ smd \ sot \ + subsequenttest \ svl \ svt \ svx \ @@ -55,30 +56,7 @@ $(eval $(call gb_CppunitTest_use_libraries,starmath_import,\ $(eval $(call gb_CppunitTest_use_ure,starmath_import)) $(eval $(call gb_CppunitTest_use_vcl,starmath_import)) -$(eval $(call gb_CppunitTest_use_components,starmath_import,\ - configmgr/source/configmgr \ - framework/util/fwk \ - i18npool/util/i18npool \ - package/source/xstor/xstor \ - package/util/package2 \ - sfx2/util/sfx \ - starmath/util/sm \ - starmath/util/smd \ - toolkit/util/tk \ - ucb/source/core/ucb1 \ - ucb/source/ucp/file/ucpfile1 \ - unotools/util/utl \ - comphelper/util/comphelp \ - filter/source/config/cache/filterconfig1 \ - oox/util/oox \ - sax/source/expatwrap/expwrap \ - svl/source/fsstor/fsstorage \ - svl/util/svl \ - svx/util/svx \ - unoxml/source/service/unoxml \ - uui/util/uui \ - xmloff/util/xo \ -)) +$(eval $(call gb_CppunitTest_use_rdb,starmath_import,services)) $(eval $(call gb_CppunitTest_use_configuration,starmath_import)) diff --git a/starmath/qa/extras/mmlimport-test.cxx b/starmath/qa/extras/mmlimport-test.cxx index d6411f8ff406..3411953aabcc 100644 --- a/starmath/qa/extras/mmlimport-test.cxx +++ b/starmath/qa/extras/mmlimport-test.cxx @@ -8,28 +8,22 @@ */ #include <sal/config.h> -#include <test/bootstrapfixture.hxx> +#include <test/unoapi_test.hxx> -#include <comphelper/fileformat.h> - -#include <sfx2/docfile.hxx> -#include <sfx2/docfilt.hxx> -#include <sfx2/sfxmodelfactory.hxx> +#include <sfx2/sfxbasemodel.hxx> #include <document.hxx> #include <smdll.hxx> -namespace -{ using namespace ::com::sun::star; -typedef tools::SvRef<SmDocShell> SmDocShellRef; - -class Test : public test::BootstrapFixture +class Test : public UnoApiTest { public: - virtual void setUp() override; - virtual void tearDown() override; + Test() + : UnoApiTest("starmath/qa/extras/data/") + { + } void testColor(); void testSimple(); @@ -56,51 +50,13 @@ public: CPPUNIT_TEST(testTdf151842); CPPUNIT_TEST(testMathmlEntities); CPPUNIT_TEST_SUITE_END(); - -private: - void loadURL(const OUString& rURL) - { - // Cf. - // filter/source/config/fragments/filters/MathML_XML__Math_.xcu - auto pFilter = std::make_shared<SfxFilter>( - MATHML_XML, OUString(), - SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::TEMPLATE, - SotClipboardFormatId::STARCALC_8, "MathML 2.0", OUString(), OUString(), - "private:factory/smath*"); - pFilter->SetVersion(SOFFICE_FILEFORMAT_60); - - mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT - | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS - | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); - - SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ); - pSrcMed->SetFilter(pFilter); - pSrcMed->UseInteractionHandler(false); - bool bLoaded = mxDocShell->DoLoad(pSrcMed); - CPPUNIT_ASSERT_MESSAGE( - OString("failed to load " + OUStringToOString(rURL, RTL_TEXTENCODING_UTF8)).getStr(), - bLoaded); - } - - SmDocShellRef mxDocShell; }; -void Test::setUp() -{ - BootstrapFixture::setUp(); - SmGlobals::ensure(); -} - -void Test::tearDown() -{ - if (mxDocShell.is()) - mxDocShell->DoClose(); - BootstrapFixture::tearDown(); -} - void Test::testColor() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/color.mml")); + loadFromURL(u"color.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); CPPUNIT_ASSERT_EQUAL(OUString("{ color black b" " color white w" " color red r" @@ -121,73 +77,91 @@ void Test::testColor() " color dvip apricot" " a color yellow y" " color rgb 220 20 61 x }"), - mxDocShell->GetText()); + pDocShell->GetText()); } void Test::testSimple() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/simple.mml")); + loadFromURL(u"simple.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("left ( { a + b } right ) ^ 2"), - mxDocShell->GetText()); + pDocShell->GetText()); } void Test::testNsPrefixMath() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/ns-prefix-math.mml")); + loadFromURL(u"ns-prefix-math.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("left ( { a + b } right ) ^ 2"), - mxDocShell->GetText()); + pDocShell->GetText()); } void Test::testMaction() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/maction.mml")); + loadFromURL(u"maction.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("matrix{ 1 ## 2 ## 3 }"), - mxDocShell->GetText()); + pDocShell->GetText()); } void Test::testMspace() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/mspace.mml")); - CPPUNIT_ASSERT_EQUAL(OUString("{ a b ~ c ~~``` d }"), mxDocShell->GetText()); + loadFromURL(u"mspace.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); + CPPUNIT_ASSERT_EQUAL(OUString("{ a b ~ c ~~``` d }"), pDocShell->GetText()); } void Test::testtdf99556() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf99556-1.mml")); - CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("sqrt { }"), mxDocShell->GetText()); + loadFromURL(u"tdf99556-1.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("loaded text", OUString("sqrt { }"), pDocShell->GetText()); } void Test::testTdf103430() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf103430.mml")); + loadFromURL(u"tdf103430.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); CPPUNIT_ASSERT_EQUAL( OUString("{ frac { { nitalic d ^ 2 nitalic color blue y } } { { color dvip " "apricot nitalic d font sans bold italic color red x } } }"), - mxDocShell->GetText()); + pDocShell->GetText()); } void Test::testTdf103500() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf103500.mml")); + loadFromURL(u"tdf103500.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); CPPUNIT_ASSERT_EQUAL( OUString("{ { int csup b csub a { { frac { 1 } { x } } ` nitalic d x } } = { " "intd csup b csub a { { frac { 1 } { y } } ` nitalic d y } } }"), - mxDocShell->GetText()); + pDocShell->GetText()); } void Test::testTdf137008() { // Without the fix in place, this test would have crashed - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf137008.mml")); - CPPUNIT_ASSERT_EQUAL(OUString("matrix{ { } # ## # }"), mxDocShell->GetText()); + loadFromURL(u"tdf137008.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); + CPPUNIT_ASSERT_EQUAL(OUString("matrix{ { } # ## # }"), pDocShell->GetText()); } void Test::testTdf151842() { // Without the fix in place, this test would have crashed - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/tdf151842.odf")); - CPPUNIT_ASSERT_EQUAL(OUString("test"), mxDocShell->GetText()); - SmFormat aFormat = mxDocShell->GetFormat(); + loadFromURL(u"tdf151842.odf"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); + CPPUNIT_ASSERT_EQUAL(OUString("test"), pDocShell->GetText()); + SmFormat aFormat = pDocShell->GetFormat(); // Without the fix in place, this test would have failed with // - Expected: 4233 @@ -197,13 +171,14 @@ void Test::testTdf151842() void Test::testMathmlEntities() { - loadURL(m_directories.getURLFromSrc(u"starmath/qa/extras/data/mthmlentities.mml")); - CPPUNIT_ASSERT_EQUAL(OUString(u"{ \u03C3 \u221E \u221E \u03C3 }"), mxDocShell->GetText()); + loadFromURL(u"mthmlentities.mml"); + SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get()); + SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); + CPPUNIT_ASSERT_EQUAL(OUString(u"{ \u03C3 \u221E \u221E \u03C3 }"), pDocShell->GetText()); } CPPUNIT_TEST_SUITE_REGISTRATION(Test); -} // namespace CPPUNIT_PLUGIN_IMPLEMENT(); -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */