[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-4.1' - sw/qa

Miklos Vajna vmiklos at collabora.co.uk
Tue Jan 28 02:10:05 PST 2014


 sw/qa/extras/inc/swmodeltestbase.hxx |   72 +++++++++++++++++++++++++++++++++--
 sw/qa/extras/rtfimport/rtfimport.cxx |   14 ++++++
 2 files changed, 82 insertions(+), 4 deletions(-)

New commits:
commit a9df0a63656b9aea2d8212760542b4a22a824422
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Jan 28 11:07:37 2014 +0100

    Fix build: DECLARE_RTFIMPORT_TEST macro wasn't defined
    
    Change-Id: I87c1c9be2869c5de0a815bdb9fe68a908ff0d747

diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 727580d..9eb7a31 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -35,12 +35,27 @@ using namespace com::sun::star;
 
 #define DEFAULT_STYLE "Default Style"
 
+#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)
     {
     }
 
@@ -63,6 +78,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()
     {
@@ -289,12 +351,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);
@@ -343,6 +405,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/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 14da8f1..df118b0 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -1537,12 +1537,26 @@ void Test::testFdo65090()
 
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
+#if !defined(MACOSX) && !defined(WNT)
+
+class BackportedTest : public SwModelTestBase
+{
+public:
+    BackportedTest() : SwModelTestBase("/sw/qa/extras/rtfimport/data/", "Rich Text Format")
+    {
+    }
+};
+
+#define DECLARE_RTFIMPORT_TEST(TestName, filename) DECLARE_SW_IMPORT_TEST(TestName, filename, BackportedTest)
+
 DECLARE_RTFIMPORT_TEST(testCharColor, "char-color.rtf")
 {
     // This was -1: character color wasn't set.
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0x365F91), getProperty<sal_Int32>(getParagraph(1), "CharColor"));
 }
 
+#endif
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list