Kaydet (Commit) b2d6ca34 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

sw test: add export test macro, remember test name

Added a new export only macro - this can be used to create tests
which import a document (in any format), and export it in a format
that is being tested. The exported document isn't loaded again, but
it must be asserted using xpath. The primary usage of this is to
test the HTML export.

Change-Id: I1ad300f6274a2181f7f29fed3903b99b68f37fd9
üst 2387805f
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <unotools/mediadescriptor.hxx>
#include <unotxdoc.hxx> #include <unotxdoc.hxx>
#include <docsh.hxx> #include <docsh.hxx>
...@@ -39,7 +40,7 @@ ...@@ -39,7 +40,7 @@
#include <libxml/xpathInternals.h> #include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h> #include <libxml/parserInternals.h>
using namespace com::sun::star; using namespace css;
#define DEFAULT_STYLE "Default Style" #define DEFAULT_STYLE "Default Style"
#define EMU_TO_MM100(EMU) (EMU / 360) #define EMU_TO_MM100(EMU) (EMU / 360)
...@@ -58,6 +59,8 @@ using namespace com::sun::star; ...@@ -58,6 +59,8 @@ using namespace com::sun::star;
*/ */
#define DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, BaseClass) \ #define DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, BaseClass) \
class TestName : public BaseClass { \ class TestName : public BaseClass { \
protected:\
virtual OUString getTestName() { return OUString::createFromAscii(#TestName); }\
public:\ public:\
CPPUNIT_TEST_SUITE(TestName); \ CPPUNIT_TEST_SUITE(TestName); \
CPPUNIT_TEST(Import); \ CPPUNIT_TEST(Import); \
...@@ -77,6 +80,8 @@ using namespace com::sun::star; ...@@ -77,6 +80,8 @@ using namespace com::sun::star;
#define DECLARE_SW_IMPORT_TEST(TestName, filename, BaseClass) \ #define DECLARE_SW_IMPORT_TEST(TestName, filename, BaseClass) \
class TestName : public BaseClass { \ class TestName : public BaseClass { \
protected:\
virtual OUString getTestName() { return OUString::createFromAscii(#TestName); }\
public:\ public:\
CPPUNIT_TEST_SUITE(TestName); \ CPPUNIT_TEST_SUITE(TestName); \
CPPUNIT_TEST(Import); \ CPPUNIT_TEST(Import); \
...@@ -90,22 +95,50 @@ using namespace com::sun::star; ...@@ -90,22 +95,50 @@ using namespace com::sun::star;
CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \ CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
void TestName::verify() void TestName::verify()
#define DECLARE_SW_EXPORT_TEST(TestName, filename, BaseClass) \
class TestName : public BaseClass { \
protected:\
virtual OUString getTestName() { return OUString::createFromAscii(#TestName); }\
public:\
CPPUNIT_TEST_SUITE(TestName); \
CPPUNIT_TEST(Import_Export); \
CPPUNIT_TEST_SUITE_END(); \
\
void Import_Export() {\
executeImportExport(filename);\
}\
void verify() SAL_OVERRIDE;\
}; \
CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
void TestName::verify()
/// Base class for filter tests loading or roundtriping a document, then asserting the document model. /// Base class for filter tests loading or roundtriping a document, then asserting the document model.
class SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest class SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest
{ {
OUString maFilterOptions;
protected:
virtual OUString getTestName() { return OUString(); }
public: public:
OUString& getFilterOptions()
{
return maFilterOptions;
}
void setFilterOptions(OUString rFilterOptions)
{
maFilterOptions = rFilterOptions;
}
SwModelTestBase(const char* pTestDocumentPath = "", const char* pFilter = "") SwModelTestBase(const char* pTestDocumentPath = "", const char* pFilter = "")
: mpXmlBuffer(0), : mpXmlBuffer(0),
mpTestDocumentPath(pTestDocumentPath), mpTestDocumentPath(pTestDocumentPath),
mpFilter(pFilter), mpFilter(pFilter),
m_nStartTime(0), m_nStartTime(0),
m_bExported(false) m_bExported(false)
{ {}
}
virtual ~SwModelTestBase() virtual ~SwModelTestBase()
{ {}
}
virtual void setUp() SAL_OVERRIDE virtual void setUp() SAL_OVERRIDE
{ {
...@@ -157,6 +190,23 @@ protected: ...@@ -157,6 +190,23 @@ protected:
finish(); finish();
} }
/**
* Helper func used by each unit test to test the 'export' code.
* (Loads the requested file for document base (this represents
* the initial document condition), exports with the desired
* export filter and then calls 'verify' method)
*/
void executeImportExport(const char* filename)
{
header();
preTest(filename);
load(mpTestDocumentPath, filename);
save(OUString::createFromAscii(mpFilter), m_aTempFile);
postTest(filename);
verify();
finish();
}
/** /**
* Function overloaded by unit test. See DECLARE_SW_*_TEST macros * Function overloaded by unit test. See DECLARE_SW_*_TEST macros
*/ */
...@@ -443,12 +493,13 @@ protected: ...@@ -443,12 +493,13 @@ protected:
void reload(const char* pFilter, const char* filename) void reload(const char* pFilter, const char* filename)
{ {
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aArgs(1);
aArgs[0].Name = "FilterName";
OUString aFilterName = OUString::createFromAscii(pFilter); OUString aFilterName = OUString::createFromAscii(pFilter);
aArgs[0].Value <<= aFilterName; utl::MediaDescriptor aMediaDescriptor;
aMediaDescriptor["FilterName"] <<= aFilterName;
if (!maFilterOptions.isEmpty())
aMediaDescriptor["FilterOptions"] <<= maFilterOptions;
m_aTempFile.EnableKillingFile(); m_aTempFile.EnableKillingFile();
xStorable->storeToURL(m_aTempFile.GetURL(), aArgs); xStorable->storeToURL(m_aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
uno::Reference<lang::XComponent> xComponent(xStorable, uno::UNO_QUERY); uno::Reference<lang::XComponent> xComponent(xStorable, uno::UNO_QUERY);
xComponent->dispose(); xComponent->dispose();
m_bExported = true; m_bExported = true;
...@@ -474,14 +525,15 @@ protected: ...@@ -474,14 +525,15 @@ protected:
} }
/// Save the loaded document to a tempfile. Can be used to check the resulting docx/odt directly as a ZIP file. /// Save the loaded document to a tempfile. Can be used to check the resulting docx/odt directly as a ZIP file.
void save(const OUString& aFilter, utl::TempFile& rTempFile) void save(const OUString& aFilterName, utl::TempFile& rTempFile)
{ {
rTempFile.EnableKillingFile(); rTempFile.EnableKillingFile();
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aFilterArgs(1); utl::MediaDescriptor aMediaDescriptor;
aFilterArgs[0].Name = "FilterName"; aMediaDescriptor["FilterName"] <<= aFilterName;
aFilterArgs[0].Value <<= aFilter; if (!maFilterOptions.isEmpty())
xStorable->storeToURL(rTempFile.GetURL(), aFilterArgs); aMediaDescriptor["FilterOptions"] <<= maFilterOptions;
xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
} }
void finish() void finish()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment