summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/qa/extras/inc/swmodeltestbase.hxx103
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx71
-rw-r--r--sw/qa/extras/odfimport/odfimport.cxx94
3 files changed, 141 insertions, 127 deletions
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 29f4dc1a9dc4..afd0cb36ba00 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -38,12 +38,58 @@ using namespace com::sun::star;
#define DEFAULT_STYLE "Default Style"
+/**
+ * Macro to declare a new test (with full round-trip. To test
+ * import only use the DECLARE_SW_IMPORT_TEST macro instead).
+ * In order to add a new test, one only needs to use this macro
+ * and then specify the test content, like this:
+ *
+ * DECLARE_SW_ROUNDTRIP_TEST(MyTest, "myfilename.docx", Test)
+ * {
+ * CPPUNIT_ASSERT_EQUAL(blabla);
+ * }
+ *
+ */
+#define DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, BaseClass) \
+ class TestName : public BaseClass { \
+ public:\
+ CPPUNIT_TEST_SUITE(TestName); \
+ CPPUNIT_TEST(Import); \
+ CPPUNIT_TEST(Import_Export_Import); \
+ CPPUNIT_TEST_SUITE_END(); \
+ \
+ void Import() { \
+ executeImportTest(filename);\
+ }\
+ void Import_Export_Import() {\
+ executeImportExportImportTest(filename);\
+ }\
+ void verify();\
+ }; \
+ CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
+ void TestName::verify()
+
+#define DECLARE_SW_IMPORT_TEST(TestName, filename, BaseClass) \
+ class TestName : public BaseClass { \
+ public:\
+ CPPUNIT_TEST_SUITE(TestName); \
+ CPPUNIT_TEST(Import); \
+ CPPUNIT_TEST_SUITE_END(); \
+ \
+ void Import() { \
+ executeImportTest(filename);\
+ }\
+ void verify();\
+ }; \
+ 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
{
public:
- SwModelTestBase()
- : mpXmlBuffer(0)
+ SwModelTestBase(const char* pTestDocumentPath = "", const char* pFilter = "")
+ : mpXmlBuffer(0), mpTestDocumentPath(pTestDocumentPath), mpFilter(pFilter)
{
}
@@ -66,6 +112,53 @@ public:
test::BootstrapFixture::tearDown();
}
+protected:
+ /**
+ * Helper func used by each unit test to test the 'import' code.
+ * (Loads the requested file and then calls 'verify' method)
+ */
+ void executeImportTest(const char* filename)
+ {
+ // If the testcase is stored in some other format, it's pointless to test.
+ if (mustTestImportOf(filename))
+ {
+ header();
+ load(mpTestDocumentPath, filename);
+ verify();
+ finish();
+ }
+ }
+
+ /**
+ * Helper func used by each unit test to test the 'export' code.
+ * (Loads the requested file, save it to temp file, load the
+ * temp file and then calls 'verify' method)
+ */
+ void executeImportExportImportTest(const char* filename)
+ {
+ header();
+ load(mpTestDocumentPath, filename);
+ reload(mpFilter);
+ verify();
+ finish();
+ }
+
+ /**
+ * Function overloaded by unit test. See DECLARE_SW_*_TEST macros
+ */
+ virtual void verify()
+ {
+ CPPUNIT_FAIL( "verify method must be overriden" );
+ }
+
+ /**
+ * Override this function if interested in skipping import test for this file
+ */
+ virtual bool mustTestImportOf(const char* /* filename */) const
+ {
+ return true;
+ }
+
private:
void dumpLayout()
{
@@ -295,12 +388,12 @@ protected:
calcLayout();
}
- void reload(OUString aFilter)
+ void reload(const char* pFilter)
{
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aArgs(1);
aArgs[0].Name = "FilterName";
- aArgs[0].Value <<= aFilter;
+ aArgs[0].Value <<= OUString::createFromAscii(pFilter);
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
xStorable->storeToURL(aTempFile.GetURL(), aArgs);
@@ -349,6 +442,8 @@ protected:
uno::Reference<lang::XComponent> mxComponent;
xmlBufferPtr mpXmlBuffer;
+ const char* mpTestDocumentPath;
+ const char* mpFilter;
template< typename T >
struct MethodEntry
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 437d2c253a0e..c1391ae055b7 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -8,6 +8,8 @@
*/
#include <swmodeltestbase.hxx>
+
+#if !defined(MACOSX) && !defined(WNT)
#include <com/sun/star/awt/Gradient.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/table/ShadowFormat.hpp>
@@ -15,52 +17,20 @@
class Test : public SwModelTestBase
{
public:
- void testFdo38244();
- void testFirstHeaderFooter();
- void testTextframeGradient();
- void testFdo60769();
- void testFdo58949();
- void testCharacterBorder();
- void testFdo43807();
- void testTextframeTransparentShadow();
-
- CPPUNIT_TEST_SUITE(Test);
-#if !defined(MACOSX) && !defined(WNT)
- CPPUNIT_TEST(run);
-#endif
- CPPUNIT_TEST_SUITE_END();
+ Test() : SwModelTestBase("/sw/qa/extras/odfexport/data/", "writer8") {}
-private:
- void run();
+ /**
+ * Blacklist handling
+ */
+ bool mustTestImportOf(const char* filename) const {
+ // Only test import of .odt document
+ return OString(filename).endsWith(".odt");
+ }
};
-void Test::run()
-{
- MethodEntry<Test> aMethods[] = {
- {"fdo38244.odt", &Test::testFdo38244},
- {"first-header-footer.odt", &Test::testFirstHeaderFooter},
- {"textframe-gradient.odt", &Test::testTextframeGradient},
- {"fdo60769.odt", &Test::testFdo60769},
- {"fdo58949.docx", &Test::testFdo58949},
- {"charborder.odt", &Test::testCharacterBorder },
- {"fdo43807.odt", &Test::testFdo43807 },
- {"textframe-transparent-shadow.odt", &Test::testTextframeTransparentShadow},
- };
- header();
- for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
- {
- MethodEntry<Test>& rEntry = aMethods[i];
- load("/sw/qa/extras/odfexport/data/", rEntry.pName);
- // If the testcase is stored in some other format, it's pointless to test.
- if (OString(rEntry.pName).endsWith(".odt"))
- (this->*rEntry.pMethod)();
- reload("writer8");
- (this->*rEntry.pMethod)();
- finish();
- }
-}
+#define DECLARE_ODT_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, Test)
-void Test::testFdo38244()
+DECLARE_ODT_TEST(testFdo38244, "fdo38244.odt")
{
// See ooxmlexport's testFdo38244().
@@ -86,7 +56,7 @@ void Test::testFdo38244()
CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
}
-void Test::testFirstHeaderFooter()
+DECLARE_ODT_TEST(testFirstHeaderFooter, "first-header-footer.odt")
{
// Test import and export of the header-first token.
@@ -105,7 +75,7 @@ void Test::testFirstHeaderFooter()
CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()"));
}
-void Test::testTextframeGradient()
+DECLARE_ODT_TEST(testTextframeGradient, "textframe-gradient.odt")
{
uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
@@ -126,7 +96,7 @@ void Test::testTextframeGradient()
CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
}
-void Test::testFdo60769()
+DECLARE_ODT_TEST(testFdo60769, "fdo60769.odt")
{
// Test multi-paragraph comment range feature.
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
@@ -152,7 +122,7 @@ void Test::testFdo60769()
}
}
-void Test::testFdo58949()
+DECLARE_ODT_TEST(testFdo58949, "fdo58949.docx")
{
/*
* The problem was that the exporter didn't insert "Obj102" to the
@@ -169,7 +139,7 @@ void Test::testFdo58949()
CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName("Obj102")));
}
-void Test::testCharacterBorder()
+DECLARE_ODT_TEST(testCharacterBorder, "charborder.odt")
{
// Make sure paragraph and character attributes don't interfere
// First paragraph has a paragraph border and a character border included by the paragraph style
@@ -324,7 +294,7 @@ void Test::testCharacterBorder()
}
}
-void Test::testFdo43807()
+DECLARE_ODT_TEST(testFdo43807, "fdo43807.odt")
{
uno::Reference<beans::XPropertySet> xSet(getParagraph(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("Drop Caps"),getProperty<OUString>(xSet,"DropCapCharStyleName"));
@@ -333,15 +303,14 @@ void Test::testFdo43807()
CPPUNIT_ASSERT_EQUAL(OUString("User Defined Drop Caps"),getProperty<OUString>(xSet,"DropCapCharStyleName"));
}
-void Test::testTextframeTransparentShadow()
+DECLARE_ODT_TEST(testTextframeTransparentShadow, "textframe-transparent-shadow.odt")
{
uno::Reference<drawing::XShape> xPicture = getShape(1);
// ODF stores opacity of 75%, that means 25% transparency.
CPPUNIT_ASSERT_EQUAL(sal_Int32(25), getProperty<sal_Int32>(xPicture, "ShadowTransparence"));
}
-CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+#endif
CPPUNIT_PLUGIN_IMPLEMENT();
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index d436d1aadc37..118dda750efb 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -6,11 +6,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <swmodeltestbase.hxx>
+
+#if !defined(MACOSX) && !defined(WNT)
+
#include <com/sun/star/style/PageStyleLayout.hpp>
#include <com/sun/star/table/XCell.hpp>
#include <com/sun/star/table/BorderLine.hpp>
#include <com/sun/star/text/XTextTable.hpp>
-#include <swmodeltestbase.hxx>
#include <wrtsh.hxx>
#include <ndtxt.hxx>
@@ -25,68 +28,16 @@ typedef std::pair<OUString, com::sun::star::uno::Sequence< com::sun::star::table
class Test : public SwModelTestBase
{
-public:
- void testEmptySvgFamilyName();
- void testHideAllSections();
- void testOdtBorders();
- void testPageStyleLayoutDefault();
- void testPageStyleLayoutRight();
- void testFdo61952();
- void testFdo60842();
- void testFdo56272();
- void testFdo55814();
- void testFdo68839();
- void testFdo37606();
- void testFdo37606Copy();
- void testFdo69862();
- void testFdo69979();
- void testSpellmenuRedline();
-
- CPPUNIT_TEST_SUITE(Test);
-#if !defined(MACOSX) && !defined(WNT)
- CPPUNIT_TEST(run);
-#endif
- CPPUNIT_TEST_SUITE_END();
-
-private:
- void run();
+ public:
+ Test() : SwModelTestBase("/sw/qa/extras/odfimport/data/", "writer8") {}
};
-void Test::run()
-{
- MethodEntry<Test> aMethods[] = {
- {"empty-svg-family-name.odt", &Test::testEmptySvgFamilyName},
- {"fdo53210.odt", &Test::testHideAllSections},
- {"borders_ooo33.odt", &Test::testOdtBorders},
- {"hello.odt", &Test::testPageStyleLayoutDefault},
- {"hello.odt", &Test::testPageStyleLayoutRight},
- {"hello.odt", &Test::testFdo61952},
- {"fdo60842.odt", &Test::testFdo60842},
- {"fdo56272.odt", &Test::testFdo56272},
- {"fdo55814.odt", &Test::testFdo55814},
- {"fdo68839.odt", &Test::testFdo68839},
- {"fdo37606.odt", &Test::testFdo37606},
- {"fdo37606.odt", &Test::testFdo37606Copy},
- {"fdo69862.odt", &Test::testFdo69862},
- {"fdo69979.odt", &Test::testFdo69979},
- {"spellmenu-redline.odt", &Test::testSpellmenuRedline},
- };
- header();
- for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
- {
- MethodEntry<Test>& rEntry = aMethods[i];
- load("/sw/qa/extras/odfimport/data/", rEntry.pName);
- (this->*rEntry.pMethod)();
- finish();
- }
-}
-
-void Test::testEmptySvgFamilyName()
+DECLARE_SW_IMPORT_TEST(testEmptySvgFamilyName, "empty-svg-family-name.odt", Test)
{
// .odt import did crash on the empty font list (which I think is valid according SVG spec)
}
-void Test::testHideAllSections()
+DECLARE_SW_IMPORT_TEST(testHideAllSections, "fdo53210.odt", Test)
{
// This document has a section that is conditionally hidden, but has no empty paragraph after it.
uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
@@ -98,7 +49,7 @@ void Test::testHideAllSections()
uno::Reference<util::XRefreshable>(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY)->refresh();
}
-void Test::testOdtBorders()
+DECLARE_SW_IMPORT_TEST(testOdtBorders, "borders_ooo33.odt", Test)
{
AllBordersMap map;
uno::Sequence< table::BorderLine > tempSequence(4);
@@ -285,21 +236,21 @@ void Test::testOdtBorders()
} while(xParaEnum->hasMoreElements());
}
-void Test::testPageStyleLayoutDefault()
+DECLARE_SW_IMPORT_TEST(testPageStyleLayoutDefault, "hello.odt", Test)
{
uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
// This was style::PageStyleLayout_MIRRORED.
CPPUNIT_ASSERT_EQUAL(style::PageStyleLayout_ALL, getProperty<style::PageStyleLayout>(xPropertySet, "PageStyleLayout"));
}
-void Test::testPageStyleLayoutRight()
+DECLARE_SW_IMPORT_TEST(testPageStyleLayoutRight, "hello.odt", Test)
{
uno::Reference<beans::XPropertySet> xPropertySet(getStyles("PageStyles")->getByName("Default Style"), uno::UNO_QUERY);
// This caused a crash.
xPropertySet->setPropertyValue("PageStyleLayout", uno::makeAny(style::PageStyleLayout_RIGHT));
}
-void Test::testFdo61952()
+DECLARE_SW_IMPORT_TEST(testFdo61952, "hello.odt", Test)
{
uno::Reference<beans::XPropertySet> xPara(getParagraph(0), uno::UNO_QUERY);
xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Left Page")));
@@ -308,7 +259,7 @@ void Test::testFdo61952()
xPara->setPropertyValue("PageDescName", uno::makeAny(OUString("Right Page")));
}
-void Test::testFdo60842()
+DECLARE_SW_IMPORT_TEST(testFdo60842, "fdo60842.odt", Test)
{
uno::Reference<text::XTextContent> const xTable(getParagraphOrTable(0));
getCell(xTable, "A1", "");
@@ -318,14 +269,14 @@ void Test::testFdo60842()
getCell(xTable, "E1", "01/04/2012");
}
-void Test::testFdo56272()
+DECLARE_SW_IMPORT_TEST(testFdo56272, "fdo56272.odt", Test)
{
uno::Reference<drawing::XShape> xShape = getShape(1);
// Vertical position was incorrect.
CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape->getPosition().Y); // Was -2371
}
-void Test::testFdo55814()
+DECLARE_SW_IMPORT_TEST(testFdo55814, "fdo55814.odt", Test)
{
uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
@@ -347,7 +298,7 @@ void lcl_CheckShape(
CPPUNIT_ASSERT_EQUAL(rExpected, xNamed->getName());
}
-void Test::testFdo68839()
+DECLARE_SW_IMPORT_TEST(testFdo68839, "fdo68839.odt", Test)
{
// check names
lcl_CheckShape(getShape(1), "FrameXXX");
@@ -371,7 +322,7 @@ void Test::testFdo68839()
getProperty<OUString>(xFrame2, "ChainNextName"));
}
-void Test::testFdo37606()
+DECLARE_SW_IMPORT_TEST(testFdo37606, "fdo37606.odt", Test)
{
SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
SwWrtShell* pWrtShell = pTxtDoc->GetDocShell()->GetWrtShell();
@@ -409,7 +360,7 @@ void Test::testFdo37606()
}
}
-void Test::testFdo37606Copy()
+DECLARE_SW_IMPORT_TEST(testFdo37606Copy, "fdo37606.odt", Test)
{
SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
SwWrtShell* pWrtShell = pTxtDoc->GetDocShell()->GetWrtShell();
@@ -433,7 +384,7 @@ void Test::testFdo37606Copy()
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables->getCount());
}
-void Test::testFdo69862()
+DECLARE_SW_IMPORT_TEST(testFdo69862, "fdo69862.odt", Test)
{
// The test doc is special in that it starts with a table and it also has a footnote.
SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
@@ -449,7 +400,7 @@ void Test::testFdo69862()
CPPUNIT_ASSERT_EQUAL(OUString("H" "\x01" "ello."), rEnd.GetTxt());
}
-void Test::testFdo69979()
+DECLARE_SW_IMPORT_TEST(testFdo69979, "fdo69979.odt", Test)
{
// The test doc is special in that it starts with a table and it also has a header.
SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
@@ -465,7 +416,7 @@ void Test::testFdo69979()
CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd.GetTxt());
}
-void Test::testSpellmenuRedline()
+DECLARE_SW_IMPORT_TEST(testSpellmenuRedline, "spellmenu-redline.odt", Test)
{
SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
SwWrtShell* pWrtShell = pTxtDoc->GetDocShell()->GetWrtShell();
@@ -479,8 +430,7 @@ void Test::testSpellmenuRedline()
CPPUNIT_ASSERT_EQUAL(sal_uInt16(FN_REDLINE_PREV_CHANGE), aPopup.GetItemId(aPopup.GetItemCount() - 1));
}
-CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+#endif
CPPUNIT_PLUGIN_IMPLEMENT();
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */