summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-04-08 08:46:43 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-04-08 13:15:56 +0200
commitb2d6ca342cf98685390e4d7354dcb61de40ee8b7 (patch)
treefc4a0b3ca4681683c379fd3e4f83f67438d6060e
parent2387805ffc4860046de57b154a51bc2354484bcd (diff)
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
-rw-r--r--sw/qa/extras/inc/swmodeltestbase.hxx80
1 files changed, 66 insertions, 14 deletions
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 9b3faf8936b4..d133d73e6933 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -28,6 +28,7 @@
#include <rtl/ustrbuf.hxx>
#include <comphelper/processfactory.hxx>
#include <unotools/tempfile.hxx>
+#include <unotools/mediadescriptor.hxx>
#include <unotxdoc.hxx>
#include <docsh.hxx>
@@ -39,7 +40,7 @@
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
-using namespace com::sun::star;
+using namespace css;
#define DEFAULT_STYLE "Default Style"
#define EMU_TO_MM100(EMU) (EMU / 360)
@@ -58,6 +59,8 @@ using namespace com::sun::star;
*/
#define DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, BaseClass) \
class TestName : public BaseClass { \
+ protected:\
+ virtual OUString getTestName() { return OUString::createFromAscii(#TestName); }\
public:\
CPPUNIT_TEST_SUITE(TestName); \
CPPUNIT_TEST(Import); \
@@ -77,6 +80,8 @@ using namespace com::sun::star;
#define DECLARE_SW_IMPORT_TEST(TestName, filename, BaseClass) \
class TestName : public BaseClass { \
+ protected:\
+ virtual OUString getTestName() { return OUString::createFromAscii(#TestName); }\
public:\
CPPUNIT_TEST_SUITE(TestName); \
CPPUNIT_TEST(Import); \
@@ -90,22 +95,50 @@ using namespace com::sun::star;
CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
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.
class SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest
{
+ OUString maFilterOptions;
+protected:
+ virtual OUString getTestName() { return OUString(); }
+
public:
+ OUString& getFilterOptions()
+ {
+ return maFilterOptions;
+ }
+ void setFilterOptions(OUString rFilterOptions)
+ {
+ maFilterOptions = rFilterOptions;
+ }
+
SwModelTestBase(const char* pTestDocumentPath = "", const char* pFilter = "")
: mpXmlBuffer(0),
mpTestDocumentPath(pTestDocumentPath),
mpFilter(pFilter),
m_nStartTime(0),
m_bExported(false)
- {
- }
+ {}
virtual ~SwModelTestBase()
- {
- }
+ {}
virtual void setUp() SAL_OVERRIDE
{
@@ -158,6 +191,23 @@ protected:
}
/**
+ * 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
*/
virtual void verify()
@@ -443,12 +493,13 @@ protected:
void reload(const char* pFilter, const char* filename)
{
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
- uno::Sequence<beans::PropertyValue> aArgs(1);
- aArgs[0].Name = "FilterName";
OUString aFilterName = OUString::createFromAscii(pFilter);
- aArgs[0].Value <<= aFilterName;
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= aFilterName;
+ if (!maFilterOptions.isEmpty())
+ aMediaDescriptor["FilterOptions"] <<= maFilterOptions;
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);
xComponent->dispose();
m_bExported = true;
@@ -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.
- void save(const OUString& aFilter, utl::TempFile& rTempFile)
+ void save(const OUString& aFilterName, utl::TempFile& rTempFile)
{
rTempFile.EnableKillingFile();
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
- uno::Sequence<beans::PropertyValue> aFilterArgs(1);
- aFilterArgs[0].Name = "FilterName";
- aFilterArgs[0].Value <<= aFilter;
- xStorable->storeToURL(rTempFile.GetURL(), aFilterArgs);
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= aFilterName;
+ if (!maFilterOptions.isEmpty())
+ aMediaDescriptor["FilterOptions"] <<= maFilterOptions;
+ xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
}
void finish()