2011-09-28 13:48:34 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
2013-04-19 21:10:42 +01:00
|
|
|
* This file is part of the LibreOffice project.
|
2011-09-28 13:48:34 +01:00
|
|
|
*
|
2013-04-19 21:10:42 +01:00
|
|
|
* 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/.
|
2011-09-28 13:48:34 +01:00
|
|
|
*/
|
2014-05-22 11:12:44 +03:00
|
|
|
|
|
|
|
#include <config_features.h>
|
|
|
|
|
2011-09-28 13:48:34 +01:00
|
|
|
#include <test/bootstrapfixture.hxx>
|
2016-08-29 17:54:04 +02:00
|
|
|
#include <test/setupvcl.hxx>
|
2017-04-14 15:29:06 +10:00
|
|
|
#include <vcl/errinf.hxx>
|
2011-09-28 13:48:34 +01:00
|
|
|
#include <rtl/strbuf.hxx>
|
2011-09-29 18:30:06 +02:00
|
|
|
#include <rtl/bootstrap.hxx>
|
2011-09-28 13:48:34 +01:00
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/lang/Locale.hpp>
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2012-09-14 18:08:57 +02:00
|
|
|
#include <com/sun/star/ucb/XContentProvider.hpp>
|
|
|
|
#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
|
2011-09-28 13:48:34 +01:00
|
|
|
|
2014-04-11 17:03:58 +01:00
|
|
|
#include <i18nlangtag/mslangid.hxx>
|
2011-09-28 13:48:34 +01:00
|
|
|
#include <vcl/svapp.hxx>
|
2017-07-31 17:16:27 +01:00
|
|
|
#include <unotools/resmgr.hxx>
|
2015-08-06 11:50:29 +02:00
|
|
|
#include <tools/link.hxx>
|
2013-01-02 22:07:41 +01:00
|
|
|
#include <vcl/graphicfilter.hxx>
|
2011-09-28 13:48:34 +01:00
|
|
|
#include <unotools/syslocaleoptions.hxx>
|
2014-03-05 11:11:41 +01:00
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <unotools/tempfile.hxx>
|
|
|
|
|
2014-12-10 16:17:15 +01:00
|
|
|
#include <isheadless.hxx>
|
|
|
|
|
2015-06-15 17:58:15 +09:00
|
|
|
#include <memory>
|
2014-03-05 11:11:41 +01:00
|
|
|
#include <cstring>
|
2011-09-28 13:48:34 +01:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
2012-10-04 17:13:24 +02:00
|
|
|
static void aBasicErrorFunc( const OUString &rErr, const OUString &rAction )
|
2011-09-28 13:48:34 +01:00
|
|
|
{
|
2012-08-01 21:35:08 +02:00
|
|
|
OStringBuffer aErr( "Unexpected dialog: " );
|
|
|
|
aErr.append( OUStringToOString( rAction, RTL_TEXTENCODING_ASCII_US ) );
|
2011-09-28 13:48:34 +01:00
|
|
|
aErr.append( " Error: " );
|
2012-08-01 21:35:08 +02:00
|
|
|
aErr.append( OUStringToOString( rErr, RTL_TEXTENCODING_ASCII_US ) );
|
2011-09-28 13:48:34 +01:00
|
|
|
CPPUNIT_ASSERT_MESSAGE( aErr.getStr(), false);
|
|
|
|
}
|
|
|
|
|
2011-10-05 16:00:44 +01:00
|
|
|
// NB. this constructor is called before any tests are run, once for each
|
|
|
|
// test function in a rather non-intuitive way. This is why all the 'real'
|
|
|
|
// heavy lifting is deferred until setUp. setUp and tearDown are interleaved
|
|
|
|
// between the tests as you might expect.
|
2011-09-30 12:39:08 +01:00
|
|
|
test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB )
|
2011-10-05 16:00:44 +01:00
|
|
|
: m_bNeedUCB( bNeedUCB )
|
|
|
|
, m_bAssertOnDialog( bAssertOnDialog )
|
2011-09-28 13:48:34 +01:00
|
|
|
{
|
2012-04-13 11:13:19 +01:00
|
|
|
}
|
|
|
|
|
2013-04-05 23:07:18 +02:00
|
|
|
extern "C"
|
2012-04-13 11:13:19 +01:00
|
|
|
{
|
|
|
|
|
2013-04-05 23:07:18 +02:00
|
|
|
void test_init_impl(bool bAssertOnDialog, bool bNeedUCB,
|
|
|
|
lang::XMultiServiceFactory * pSFactory)
|
|
|
|
{
|
|
|
|
if (bAssertOnDialog)
|
2017-04-23 22:01:46 +10:00
|
|
|
ErrorRegistry::RegisterDisplay( aBasicErrorFunc );
|
2012-08-01 10:05:05 +02:00
|
|
|
|
|
|
|
// Make GraphicConverter work, normally done in desktop::Desktop::Main()
|
2013-04-05 23:07:18 +02:00
|
|
|
Application::SetFilterHdl(
|
2015-11-10 10:26:03 +01:00
|
|
|
LINK(nullptr, test::BootstrapFixture, ImplInitFilterHdl));
|
2012-09-14 18:08:57 +02:00
|
|
|
|
2013-04-05 23:07:18 +02:00
|
|
|
if (bNeedUCB)
|
2012-09-14 18:08:57 +02:00
|
|
|
{
|
|
|
|
// initialise unconfigured UCB:
|
2013-04-05 23:07:18 +02:00
|
|
|
uno::Reference<ucb::XUniversalContentBroker> xUcb(pSFactory->createInstance("com.sun.star.ucb.UniversalContentBroker"), uno::UNO_QUERY_THROW);
|
|
|
|
uno::Reference<ucb::XContentProvider> xFileProvider(pSFactory->createInstance("com.sun.star.ucb.FileContentProvider"), uno::UNO_QUERY_THROW);
|
2016-04-20 17:20:22 +02:00
|
|
|
xUcb->registerContentProvider(xFileProvider, "file", true);
|
2013-04-05 23:07:18 +02:00
|
|
|
uno::Reference<ucb::XContentProvider> xTdocProvider(pSFactory->createInstance("com.sun.star.ucb.TransientDocumentsContentProvider"), uno::UNO_QUERY);
|
2012-09-14 18:08:57 +02:00
|
|
|
if (xTdocProvider.is())
|
|
|
|
{
|
2016-04-20 17:20:22 +02:00
|
|
|
xUcb->registerContentProvider(xTdocProvider, "vnd.sun.star.tdoc", true);
|
2012-09-14 18:08:57 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-28 13:48:34 +01:00
|
|
|
}
|
|
|
|
|
2013-04-05 23:07:18 +02:00
|
|
|
// this is called from pyuno
|
|
|
|
SAL_DLLPUBLIC_EXPORT void test_init(lang::XMultiServiceFactory *pFactory)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
::comphelper::setProcessServiceFactory(pFactory);
|
2016-08-29 17:54:04 +02:00
|
|
|
test::setUpVcl();
|
2013-04-05 23:07:18 +02:00
|
|
|
test_init_impl(false, true, pFactory);
|
|
|
|
}
|
|
|
|
catch (...) { abort(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
void test::BootstrapFixture::setUp()
|
|
|
|
{
|
|
|
|
test::BootstrapFixtureBase::setUp();
|
|
|
|
|
|
|
|
test_init_impl(m_bAssertOnDialog, m_bNeedUCB, m_xSFactory.get());
|
|
|
|
}
|
|
|
|
|
2011-09-28 13:48:34 +01:00
|
|
|
test::BootstrapFixture::~BootstrapFixture()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-14 21:12:23 +02:00
|
|
|
#if HAVE_EXPORT_VALIDATION
|
2014-03-05 11:11:41 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
OString loadFile(const OUString& rURL)
|
|
|
|
{
|
|
|
|
osl::File aFile(rURL);
|
|
|
|
osl::FileBase::RC eStatus = aFile.open(osl_File_OpenFlag_Read);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(eStatus, osl::FileBase::E_None);
|
|
|
|
sal_uInt64 nSize;
|
|
|
|
aFile.getSize(nSize);
|
2015-06-15 17:58:15 +09:00
|
|
|
std::unique_ptr<char[]> aBytes(new char[nSize]);
|
2014-03-05 11:11:41 +01:00
|
|
|
sal_uInt64 nBytesRead;
|
|
|
|
aFile.read(aBytes.get(), nSize, nBytesRead);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(nSize, nBytesRead);
|
2014-03-30 21:02:36 +01:00
|
|
|
OString aContent(aBytes.get(), nBytesRead);
|
2014-03-05 11:11:41 +01:00
|
|
|
|
|
|
|
return aContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-05-14 21:12:23 +02:00
|
|
|
#endif
|
2014-03-05 11:11:41 +01:00
|
|
|
|
|
|
|
void test::BootstrapFixture::validate(const OUString& rPath, test::ValidationFormat eFormat )
|
|
|
|
{
|
|
|
|
#if HAVE_EXPORT_VALIDATION
|
2015-04-20 16:47:53 +02:00
|
|
|
OUString var;
|
2014-03-05 11:11:41 +01:00
|
|
|
if( eFormat == test::OOXML )
|
|
|
|
{
|
2015-04-20 16:47:53 +02:00
|
|
|
var = "OFFICEOTRON";
|
2014-03-05 11:11:41 +01:00
|
|
|
}
|
2016-06-17 10:36:38 +03:00
|
|
|
else if ( eFormat == test::ODF )
|
2014-03-08 16:51:47 +01:00
|
|
|
{
|
2015-04-20 16:47:53 +02:00
|
|
|
var = "ODFVALIDATOR";
|
2014-03-08 16:51:47 +01:00
|
|
|
}
|
2016-06-17 10:36:38 +03:00
|
|
|
else if ( eFormat == test::MSBINARY )
|
|
|
|
{
|
|
|
|
#if HAVE_BFFVALIDATOR
|
|
|
|
var = "BFFVALIDATOR";
|
|
|
|
#else
|
|
|
|
// Binary Format Validator is disabled
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
2015-04-20 16:47:53 +02:00
|
|
|
OUString aValidator;
|
|
|
|
oslProcessError e = osl_getEnvironment(var.pData, &aValidator.pData);
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
|
|
|
OUString("cannot get env var " + var).toUtf8().getStr(),
|
|
|
|
osl_Process_E_None, e);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE(
|
|
|
|
OUString("empty get env var " + var).toUtf8().getStr(),
|
|
|
|
!aValidator.isEmpty());
|
|
|
|
aValidator += " ";
|
2014-03-05 11:11:41 +01:00
|
|
|
|
|
|
|
utl::TempFile aOutput;
|
|
|
|
aOutput.EnableKillingFile();
|
|
|
|
OUString aOutputFile = aOutput.GetFileName();
|
|
|
|
OUString aCommand = aValidator + rPath + " > " + aOutputFile;
|
|
|
|
|
2014-04-19 09:30:33 +02:00
|
|
|
int returnValue = system(OUStringToOString(aCommand, RTL_TEXTENCODING_UTF8).getStr());
|
2014-05-14 15:28:29 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
2014-12-18 17:57:46 +01:00
|
|
|
OUStringToOString("failed to execute: " + aCommand,
|
2014-07-04 05:34:13 +02:00
|
|
|
RTL_TEXTENCODING_UTF8).getStr(), 0, returnValue);
|
2014-03-05 11:11:41 +01:00
|
|
|
|
|
|
|
OString aContentString = loadFile(aOutput.GetURL());
|
2014-11-06 17:24:13 +01:00
|
|
|
OUString aContentOUString = OStringToOUString(aContentString, RTL_TEXTENCODING_UTF8);
|
2014-03-05 11:11:41 +01:00
|
|
|
|
|
|
|
if( eFormat == test::OOXML && !aContentOUString.isEmpty() )
|
|
|
|
{
|
|
|
|
// check for validation errors here
|
|
|
|
sal_Int32 nIndex = aContentOUString.lastIndexOf("Grand total of errors in submitted package: ");
|
|
|
|
if(nIndex == -1)
|
|
|
|
{
|
2014-04-29 21:13:15 +02:00
|
|
|
SAL_WARN("test", "no summary line");
|
2014-03-05 11:11:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Int32 nStartOfNumber = nIndex + std::strlen("Grand total of errors in submitted package: ");
|
|
|
|
OUString aNumber = aContentOUString.copy(nStartOfNumber);
|
|
|
|
sal_Int32 nErrors = aNumber.toInt32();
|
|
|
|
OString aMsg("validation error in OOXML export: Errors: ");
|
|
|
|
aMsg = aMsg + OString::number(nErrors);
|
|
|
|
if(nErrors)
|
|
|
|
{
|
|
|
|
SAL_WARN("test", aContentOUString);
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsg.getStr(), sal_Int32(0), nErrors);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 16:51:47 +01:00
|
|
|
else if( eFormat == test::ODF && !aContentOUString.isEmpty() )
|
|
|
|
{
|
|
|
|
if( aContentOUString.indexOf("Error") != -1 )
|
|
|
|
{
|
|
|
|
SAL_WARN("test", aContentOUString);
|
2014-03-26 23:43:41 +01:00
|
|
|
CPPUNIT_FAIL(aContentString.getStr());
|
2014-03-08 16:51:47 +01:00
|
|
|
}
|
|
|
|
}
|
2017-07-02 22:28:19 +02:00
|
|
|
#else
|
|
|
|
(void)rPath;
|
|
|
|
(void)eFormat;
|
2014-03-05 11:11:41 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_STATIC_LINK(
|
2015-09-21 09:14:04 +02:00
|
|
|
test::BootstrapFixture, ImplInitFilterHdl, ConvertData&, rData, bool)
|
2012-08-01 10:05:05 +02:00
|
|
|
{
|
2015-09-23 15:10:45 +02:00
|
|
|
return GraphicFilter::GetGraphicFilter().GetFilterCallback().Call( rData );
|
2012-08-01 10:05:05 +02:00
|
|
|
}
|
|
|
|
|
2011-09-28 13:48:34 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|