/* -*- 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/.
*/
/** * Maps database URIs to the registered database names for quick lookups
*/ typedef std::map<OUString, OUString> DBuriMap;
DBuriMap aDBuriMap;
class MailMergeTestBase : public SwModelTestBase
{ public:
MailMergeTestBase()
: SwModelTestBase(u"/sw/qa/extras/mailmerge/data/"_ustr, u"writer8"_ustr)
, mnCurOutputType(0)
, maMMtestFilename(nullptr)
{
}
virtualvoid tearDown() override
{ if (mxSwTextDocument.is())
{ if (mnCurOutputType == text::MailMergeType::SHELL)
mxSwTextDocument->GetDocShell()->DoClose(); else
mxSwTextDocument->dispose();
} if (mxCurResultSet.is())
{
css::uno::Reference<css::lang::XComponent>(mxCurResultSet, css::uno::UNO_QUERY_THROW)
->dispose();
}
SwModelTestBase::tearDown();
}
/** * Helper func used by each unit test to test the 'mail merge' code. * * Registers the data source, loads the original file as reference, * initializes the mail merge job and its default argument sequence. * * The 'verify' method actually has to execute the mail merge by * calling executeMailMerge() after modifying the job arguments.
*/ void executeMailMergeTest(constchar* filename, constchar* datasource, constchar* tablename, charconst* const filter, int selection, constchar* column)
{
maMMtestFilename = filename;
header();
// all error checking was already done by the MM job execution if (rName == UNO_NAME_OUTPUT_URL)
bOk &= rValue >>= msMailMergeOutputURL; elseif (rName == UNO_NAME_FILE_NAME_PREFIX)
bOk &= rValue >>= msMailMergeOutputPrefix; elseif (rName == UNO_NAME_OUTPUT_TYPE)
bOk &= rValue >>= mnCurOutputType; elseif (rName == UNO_NAME_FILE_NAME_FROM_COLUMN)
bOk &= rValue >>= bMMFilenameFromColumn; elseif (rName == UNO_NAME_DOCUMENT_URL)
bOk &= rValue >>= msMailMergeDocumentURL;
}
CPPUNIT_ASSERT(bOk);
// MM via UNO just works with file names. If we load the file on // Windows before MM uses it, MM won't work, as it's already open. // Don't move the load before the mail merge execution! // (see gb_CppunitTest_use_instdir_configuration)
createSwDoc(maMMtestFilename);
/** * Like parseExport(), but for given mail merge document.
*/
xmlDocUniquePtr parseMailMergeExport(const OUString& rStreamName)
{ if (mnCurOutputType != text::MailMergeType::FILE) return nullptr;
void loadMailMergeDocument(const OUString& filename)
{
assert(mnCurOutputType == text::MailMergeType::FILE); // Output name early, so in the case of a hang, the name of the hanging input file is visible.
std::cout << filename << ",";
loadFromURL(msMailMergeOutputURL + "/" + filename);
calcLayout();
}
/** Loads number-th document from mail merge. Requires file output from mail merge.
*/ void loadMailMergeDocument(int number, charconst* const ext = ".odt")
{
OUString name; if (!msMailMergeOutputPrefix.isEmpty())
name = msMailMergeOutputPrefix; else
{
INetURLObject aURLObj;
aURLObj.SetSmartProtocol(INetProtocol::File);
aURLObj.SetSmartURL(msMailMergeDocumentURL);
name = aURLObj.GetBase();
}
name += OUString::number(number)
+ OStringToOUString(std::string_view(ext, strlen(ext)), RTL_TEXTENCODING_ASCII_US);
loadMailMergeDocument(name);
}
// Returns page number of the first page of a MM document inside the large MM document (used in the SHELL case). int documentStartPageNumber(int document) const
{ // See documentStartPageNumber() .
CPPUNIT_ASSERT(mxSwTextDocument);
SwWrtShell* shell = mxSwTextDocument->GetDocShell()->GetWrtShell();
IDocumentMarkAccess* marks = shell->GetDoc()->getIDocumentMarkAccess(); // Unfortunately, the pages are marked using UNO bookmarks, which have internals names, so they cannot be referred to by their names. // Assume that there are no other UNO bookmarks than the ones used by mail merge, and that they are in the sorted order.
IDocumentMarkAccess::const_iterator mark; int pos = 0; for (mark = marks->getAllMarksBegin(); mark != marks->getAllMarksEnd() && pos < document;
++mark)
{ if (IDocumentMarkAccess::GetType(**mark) == IDocumentMarkAccess::MarkType::UNO_BOOKMARK)
++pos;
}
CPPUNIT_ASSERT_EQUAL(document, pos);
sal_uInt16 page, dummy;
shell->Push();
shell->GotoMark(*mark);
shell->GetPageNum(page, dummy);
shell->Pop(SwCursorShell::PopMode::DeleteCurrent); return page;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.