2010-12-20 16:20:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Thorsten Behrens <tbehrens@novell.com>
|
2011-02-14 20:31:03 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011 the
|
|
|
|
* Initial Developer. All Rights Reserved.
|
2010-12-20 16:20:30 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Thorsten Behrens <tbehrens@novell.com>
|
|
|
|
* Caolán McNamara <caolanm@redhat.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
|
|
|
|
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
|
|
|
|
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
|
|
|
|
* instead of those above.
|
|
|
|
*/
|
|
|
|
#include "precompiled_sw.hxx"
|
|
|
|
|
2011-01-09 14:38:14 +00:00
|
|
|
#ifdef WNT
|
2011-02-13 20:56:23 +01:00
|
|
|
#include <prewin.h>
|
|
|
|
#include <postwin.h>
|
2011-01-09 14:38:14 +00:00
|
|
|
#endif
|
|
|
|
|
2010-12-20 16:20:30 +00:00
|
|
|
#include <cppunit/TestSuite.h>
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/TestCase.h>
|
|
|
|
#include <cppunit/plugin/TestPlugIn.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <osl/process.h>
|
|
|
|
#include <cppuhelper/compbase1.hxx>
|
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
|
|
|
#include <cppuhelper/basemutex.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
2011-03-02 09:01:51 +00:00
|
|
|
|
2010-12-20 16:20:30 +00:00
|
|
|
#include <sfx2/app.hxx>
|
2011-03-02 09:01:51 +00:00
|
|
|
#include <sfx2/docfilt.hxx>
|
2011-01-04 19:48:56 +00:00
|
|
|
#include <sfx2/docfile.hxx>
|
|
|
|
#include <sfx2/sfxmodelfactory.hxx>
|
2011-03-02 09:01:51 +00:00
|
|
|
|
2011-01-04 19:48:56 +00:00
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
#include <unotools/tempfile.hxx>
|
2011-02-17 20:45:49 +00:00
|
|
|
#include <ucbhelper/contentbroker.hxx>
|
2010-12-20 16:20:30 +00:00
|
|
|
|
|
|
|
#include "init.hxx"
|
|
|
|
#include "swtypes.hxx"
|
|
|
|
#include "doc.hxx"
|
2011-01-04 19:48:56 +00:00
|
|
|
#include "docsh.hxx"
|
2010-12-20 17:10:42 +00:00
|
|
|
#include "shellres.hxx"
|
2011-01-04 19:48:56 +00:00
|
|
|
#include "docufld.hxx"
|
|
|
|
|
|
|
|
SO2_DECL_REF(SwDocShell)
|
|
|
|
SO2_IMPL_REF(SwDocShell)
|
2010-12-20 16:20:30 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
2011-02-18 11:20:58 +00:00
|
|
|
static USHORT aWndFunc(Window *, USHORT, const String &, const String &)
|
|
|
|
{
|
|
|
|
return ERRCODE_BUTTON_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-20 16:20:30 +00:00
|
|
|
/* Implementation of Swdoc-Test class */
|
|
|
|
|
|
|
|
class SwDocTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SwDocTest();
|
|
|
|
~SwDocTest();
|
|
|
|
|
|
|
|
virtual void setUp();
|
|
|
|
virtual void tearDown();
|
|
|
|
|
2011-03-02 09:01:51 +00:00
|
|
|
bool testLoad(const rtl::OUString &rFilter, const rtl::OUString &rURL);
|
|
|
|
|
2010-12-20 17:10:42 +00:00
|
|
|
void randomTest();
|
2011-01-04 19:48:56 +00:00
|
|
|
void testPageDescName();
|
|
|
|
void testFileNameFields();
|
2010-12-20 16:20:30 +00:00
|
|
|
|
2011-03-02 09:01:51 +00:00
|
|
|
/**
|
|
|
|
* Ensure CVEs remain unbroken
|
|
|
|
*/
|
|
|
|
void testCVEs();
|
|
|
|
|
2010-12-20 16:20:30 +00:00
|
|
|
CPPUNIT_TEST_SUITE(SwDocTest);
|
|
|
|
CPPUNIT_TEST(randomTest);
|
2010-12-20 17:10:42 +00:00
|
|
|
CPPUNIT_TEST(testPageDescName);
|
2011-01-04 19:48:56 +00:00
|
|
|
CPPUNIT_TEST(testFileNameFields);
|
2011-03-02 09:01:51 +00:00
|
|
|
CPPUNIT_TEST(testCVEs);
|
2010-12-20 16:20:30 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
private:
|
|
|
|
uno::Reference<uno::XComponentContext> m_xContext;
|
|
|
|
uno::Reference<lang::XMultiComponentFactory> m_xFactory;
|
|
|
|
SwDoc *m_pDoc;
|
2011-01-04 19:48:56 +00:00
|
|
|
SwDocShellRef m_xDocShRef;
|
2011-03-02 09:01:51 +00:00
|
|
|
::rtl::OUString m_aPWDURL;
|
2010-12-20 16:20:30 +00:00
|
|
|
};
|
|
|
|
|
2010-12-20 17:10:42 +00:00
|
|
|
void SwDocTest::testPageDescName()
|
|
|
|
{
|
|
|
|
ShellResource aShellResources;
|
|
|
|
|
|
|
|
std::vector<rtl::OUString> aResults;
|
|
|
|
|
|
|
|
//These names must be unique for each different combination, otherwise
|
|
|
|
//duplicate page description names may exist, which will causes lookup
|
|
|
|
//by name to be incorrect, and so the corresponding export to .odt
|
|
|
|
aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::NORMAL_PAGE));
|
|
|
|
aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::FIRST_PAGE));
|
|
|
|
aResults.push_back(aShellResources.GetPageDescName(1, ShellResource::FOLLOW_PAGE));
|
|
|
|
|
|
|
|
std::sort(aResults.begin(), aResults.end());
|
|
|
|
aResults.erase(std::unique(aResults.begin(), aResults.end()), aResults.end());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("GetPageDescName results must be unique", aResults.size() == 3);
|
|
|
|
}
|
|
|
|
|
2011-01-04 19:48:56 +00:00
|
|
|
//See https://bugs.freedesktop.org/show_bug.cgi?id=32463 for motivation
|
|
|
|
void SwDocTest::testFileNameFields()
|
|
|
|
{
|
|
|
|
//Here's a file name with some chars in it that will be %% encoded, when expanding
|
|
|
|
//SwFileNameFields we want to restore the original readable filename
|
|
|
|
utl::TempFile aTempFile(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("demo [name]")));
|
|
|
|
aTempFile.EnableKillingFile();
|
|
|
|
|
|
|
|
INetURLObject aTempFileURL(aTempFile.GetURL());
|
|
|
|
String sFileURL = aTempFileURL.GetMainURL(INetURLObject::NO_DECODE);
|
2011-02-17 20:45:49 +00:00
|
|
|
SfxMedium aDstMed(sFileURL, STREAM_STD_READWRITE, true);
|
2011-01-04 19:48:56 +00:00
|
|
|
|
2011-02-17 20:45:49 +00:00
|
|
|
m_xDocShRef->DoSaveAs(aDstMed);
|
|
|
|
m_xDocShRef->DoSaveCompleted(&aDstMed);
|
2011-01-04 19:48:56 +00:00
|
|
|
|
|
|
|
const INetURLObject &rUrlObj = m_xDocShRef->GetMedium()->GetURLObject();
|
|
|
|
|
|
|
|
SwFileNameFieldType aNameField(m_pDoc);
|
|
|
|
|
|
|
|
{
|
|
|
|
rtl::OUString sResult(aNameField.Expand(FF_NAME));
|
|
|
|
rtl::OUString sExpected(rUrlObj.getName(INetURLObject::LAST_SEGMENT,
|
|
|
|
true,INetURLObject::DECODE_WITH_CHARSET));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
rtl::OUString sResult(aNameField.Expand(FF_PATHNAME));
|
|
|
|
rtl::OUString sExpected(rUrlObj.GetFull());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
rtl::OUString sResult(aNameField.Expand(FF_PATH));
|
|
|
|
INetURLObject aTemp(rUrlObj);
|
|
|
|
aTemp.removeSegment();
|
|
|
|
rtl::OUString sExpected(aTemp.PathToFileName());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
rtl::OUString sResult(aNameField.Expand(FF_NAME_NOEXT));
|
|
|
|
rtl::OUString sExpected(rUrlObj.getName(INetURLObject::LAST_SEGMENT,
|
|
|
|
true,INetURLObject::DECODE_WITH_CHARSET));
|
|
|
|
//Chop off .tmp
|
|
|
|
sExpected = sExpected.copy(0, sExpected.getLength() - 4);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
|
|
|
|
}
|
2011-02-17 20:45:49 +00:00
|
|
|
|
|
|
|
m_xDocShRef->DoInitNew(0);
|
2011-01-04 19:48:56 +00:00
|
|
|
}
|
|
|
|
|
2011-03-02 09:01:51 +00:00
|
|
|
bool SwDocTest::testLoad(const rtl::OUString &rFilter, const rtl::OUString &rURL)
|
|
|
|
{
|
|
|
|
SfxFilter aFilter(
|
|
|
|
rFilter,
|
|
|
|
rtl::OUString(), 0, 0, rtl::OUString(), 0, rtl::OUString(),
|
|
|
|
rtl::OUString(), rtl::OUString() );
|
|
|
|
|
|
|
|
SwDocShellRef xDocShRef = new SwDocShell;
|
|
|
|
SfxMedium aSrcMed(rURL, STREAM_STD_READ, true);
|
|
|
|
aSrcMed.SetFilter(&aFilter);
|
|
|
|
return xDocShRef->DoLoad(&aSrcMed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwDocTest::testCVEs()
|
|
|
|
{
|
|
|
|
//To-Do: I know this works on Linux, please check if this test works under
|
|
|
|
//windows and enable it if so
|
|
|
|
#ifndef WNT
|
|
|
|
bool bResult;
|
|
|
|
|
|
|
|
bResult = testLoad(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StarOffice XML (Writer)")),
|
|
|
|
m_aPWDURL + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/CVE/CVE-2006-3117-1.sxw")));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("CVE-2006-3117 regression", bResult == false);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-12-20 17:10:42 +00:00
|
|
|
void SwDocTest::randomTest()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("SwDoc::IsRedlineOn()", !m_pDoc->IsRedlineOn());
|
|
|
|
}
|
|
|
|
|
2010-12-20 16:20:30 +00:00
|
|
|
SwDocTest::SwDocTest()
|
|
|
|
{
|
|
|
|
m_xContext = cppu::defaultBootstrap_InitialComponentContext();
|
|
|
|
m_xFactory = m_xContext->getServiceManager();
|
|
|
|
|
|
|
|
uno::Reference<lang::XMultiServiceFactory> xSM(m_xFactory, uno::UNO_QUERY_THROW);
|
|
|
|
|
|
|
|
//Without this we're crashing because callees are using
|
|
|
|
//getProcessServiceFactory. In general those should be removed in favour
|
|
|
|
//of retaining references to the root ServiceFactory as its passed around
|
|
|
|
comphelper::setProcessServiceFactory(xSM);
|
|
|
|
|
|
|
|
InitVCL(xSM);
|
|
|
|
|
|
|
|
SwDLL::Init();
|
2011-02-18 11:20:58 +00:00
|
|
|
|
2011-03-02 09:01:51 +00:00
|
|
|
oslProcessError err = osl_getProcessWorkingDir(&m_aPWDURL.pData);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("no PWD!", err == osl_Process_E_None);
|
|
|
|
|
2011-02-18 11:20:58 +00:00
|
|
|
ErrorHandler::RegisterDisplay(&aWndFunc);
|
2010-12-20 16:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SwDocTest::setUp()
|
|
|
|
{
|
|
|
|
m_pDoc = new SwDoc;
|
2011-01-04 19:48:56 +00:00
|
|
|
m_xDocShRef = new SwDocShell(m_pDoc, SFX_CREATE_MODE_EMBEDDED);
|
|
|
|
m_xDocShRef->DoInitNew(0);
|
2010-12-20 16:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SwDocTest::~SwDocTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwDocTest::tearDown()
|
|
|
|
{
|
2011-01-04 19:48:56 +00:00
|
|
|
m_xDocShRef.Clear();
|
2010-12-20 16:20:30 +00:00
|
|
|
delete m_pDoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(SwDocTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|