/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include static char const DATA_DIRECTORY[] = "/sw/qa/extras/layout/data/"; /// Test to assert layout / rendering result of Writer. class SwLayoutWriter : public SwModelTestBase { public: void testUserFieldTypeLanguage(); void testTdf106390(); CPPUNIT_TEST_SUITE(SwLayoutWriter); CPPUNIT_TEST(testUserFieldTypeLanguage); CPPUNIT_TEST(testTdf106390); CPPUNIT_TEST_SUITE_END(); private: SwDoc* createDoc(const char* pName = nullptr); }; SwDoc* SwLayoutWriter::createDoc(const char* pName) { load(DATA_DIRECTORY, pName); SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); CPPUNIT_ASSERT(pTextDoc); return pTextDoc->GetDocShell()->GetDoc(); } void SwLayoutWriter::testUserFieldTypeLanguage() { // Set the system locale to German, the document will be English. SvtSysLocaleOptions aOptions; aOptions.SetLocaleConfigString("de-DE"); aOptions.Commit(); comphelper::ScopeGuard g([&aOptions] { aOptions.SetLocaleConfigString(OUString()); aOptions.Commit(); }); SwDoc* pDoc = createDoc("user-field-type-language.fodt"); SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell(); pViewShell->UpdateFields(); xmlDocPtr pXmlDoc = parseLayoutDump(); // This was "123,456.00", via a buggy 1234.56 -> 1234,56 -> 123456 -> // 123,456.00 transform chain. assertXPath(pXmlDoc, "/root/page/body/txt/Special[@nType='POR_FLD']", "rText", "1,234.56"); } void SwLayoutWriter::testTdf106390() { SwDoc* pDoc = createDoc("tdf106390.odt"); SwDocShell* pShell = pDoc->GetDocShell(); // Dump the rendering of the first page as an XML file. std::shared_ptr xMetaFile = pShell->GetPreviewMetaFile(); MetafileXmlDump dumper; xmlDocPtr pXmlDoc = dumper.dumpAndParse(*xMetaFile); CPPUNIT_ASSERT(pXmlDoc); sal_Int32 nBottom = getXPath(pXmlDoc, "//sectrectclipregion", "bottom").toInt32(); // No end point of line segments shall go below the bottom of the clipping area. const OString sXPath = "//polyline/point[@y>" + OString::number(nBottom) + "]"; assertXPath(pXmlDoc, sXPath, 0); } CPPUNIT_TEST_SUITE_REGISTRATION(SwLayoutWriter); CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */