[Libreoffice-commits] core.git: sw/qa sw/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Fri Mar 3 07:14:48 UTC 2017


 sw/qa/extras/uiwriter/uiwriter.cxx      |  219 +++++++++++++++++++++++++++-----
 sw/source/core/inc/SwPortionHandler.hxx |    2 
 sw/source/core/inc/txtfrm.hxx           |    2 
 3 files changed, 193 insertions(+), 30 deletions(-)

New commits:
commit ba48819e9f01466b4048528f5aded766a5f11e8a
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Feb 27 12:20:33 2017 +0100

    sw: rework input field line breaking test to use portions directly
    
    Change-Id: I03cce0df2461964ce7402d32e6c5cc161b7f96ab
    Reviewed-on: https://gerrit.libreoffice.org/34684
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index dd969a4..213b51a 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -89,6 +89,8 @@
 #include <paratr.hxx>
 #include <drawfont.hxx>
 #include <txtfrm.hxx>
+#include <txttypes.hxx>
+#include <SwPortionHandler.hxx>
 #include <hyp.hxx>
 #include <editeng/svxenum.hxx>
 #include <comphelper/propertysequence.hxx>
@@ -3454,49 +3456,210 @@ void SwUiWriterTest::testTdf87922()
     CPPUNIT_ASSERT_EQUAL(COL_WHITE, aFont.GetColor().GetColor());
 }
 
+struct PortionItem
+{
+    PortionItem(OUString const & sItemType, sal_Int32 nLength = 0,
+                sal_uInt16 nTextType = 0, OUString const & sText = OUString(""))
+        : msItemType(sItemType)
+        , mnLength(nLength)
+        , mnTextType(nTextType)
+        , msText(sText)
+    {}
+
+    OUString msItemType;
+    sal_Int32 mnLength;
+    sal_uInt16 mnTextType;
+    OUString msText;
+};
+
+class PortionHandler : public SwPortionHandler
+{
+  public:
+
+    std::vector<PortionItem> mPortionItems;
+    explicit PortionHandler()
+        : SwPortionHandler()
+    {}
+
+    void clear()
+    {
+        mPortionItems.clear();
+    }
+
+    virtual void Text(sal_Int32 nLength, sal_uInt16 nType,
+                      sal_Int32 /*nHeight*/, sal_Int32 /*nWidth*/) override
+    {
+        mPortionItems.push_back(PortionItem("text", nLength, nType));
+    }
+
+    virtual void Special(sal_Int32 nLength, const OUString & rText,
+                         sal_uInt16 nType, sal_Int32 /*nHeight*/,
+                         sal_Int32 /*nWidth*/, const SwFont* /*pFont*/) override
+    {
+        mPortionItems.push_back(PortionItem("special", nLength, nType, rText));
+    }
+
+    virtual void LineBreak(sal_Int32 /*nWidth*/) override
+    {
+        mPortionItems.push_back(PortionItem("line_break"));
+    }
+
+    virtual void Skip(sal_Int32 nLength) override
+    {
+        mPortionItems.push_back(PortionItem("skip", nLength));
+    }
+
+    virtual void Finish() override
+    {
+        mPortionItems.push_back(PortionItem("finish"));
+    }
+};
+
 void SwUiWriterTest::testTdf77014()
 {
     // The problem described in the bug tdf#77014 is that the input
     // field text ("ThisIsAllOneWord") is broken up on linebreak, but
     // it should be in one piece (like normal text).
 
-    // This test checks that the input field is in one piece.
+    // This test checks that the input field is in one piece and if the
+    // input field has more words, it is broken up at the correct place.
+
+    SwDoc* pDoc = createDoc("tdf77014.odt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower());
+
+    PortionHandler aHandler;
+    pTextFrame->VisitPortions(aHandler);
+
+    {
+        // Input Field - "One Two Three Four Five" = 25 chars
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),          aHandler.mPortionItems[0].msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(25),             aHandler.mPortionItems[0].mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_INPUTFLD),  aHandler.mPortionItems[0].mnTextType);
+
+        CPPUNIT_ASSERT_EQUAL(OUString("line_break"), aHandler.mPortionItems[1].msItemType);
+
+        CPPUNIT_ASSERT_EQUAL(OUString("finish"), aHandler.mPortionItems[2].msItemType);
+    }
+
+    aHandler.clear();
 
-    load(DATA_DIRECTORY, "tdf77014.odt");
+    pTextFrame = static_cast<SwTextFrame*>(pTextFrame->GetNext());
+    pTextFrame->VisitPortions(aHandler);
 
-    // First paragraph
-    CPPUNIT_ASSERT_EQUAL(OUString("POR_TXT"), parseDump("/root/page/body/txt[4]/Text[1]", "nType"));
-    CPPUNIT_ASSERT_EQUAL(OUString("91"),      parseDump("/root/page/body/txt[4]/Text[1]", "nLength"));
+    {
+        // Input Field - "ThisIsAllOneWord" = 18 chars
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),         aHandler.mPortionItems[0].msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(18),            aHandler.mPortionItems[0].mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_INPUTFLD), aHandler.mPortionItems[0].mnTextType);
+
+        CPPUNIT_ASSERT_EQUAL(OUString("line_break"), aHandler.mPortionItems[1].msItemType);
+
+        CPPUNIT_ASSERT_EQUAL(OUString("finish"), aHandler.mPortionItems[2].msItemType);
+    }
+
+    aHandler.clear();
+
+    // skip empty paragraph
+    pTextFrame = static_cast<SwTextFrame*>(pTextFrame->GetNext());
 
-    // The "Unknown" is the input field:
-    // which is 16 chars + 2 hidden chars (start & end input field) = 18 chars
-    // If this is correct then the input field is in one piece
-    CPPUNIT_ASSERT_EQUAL(OUString("Unknown"), parseDump("/root/page/body/txt[4]/Text[2]", "nType"));
-    CPPUNIT_ASSERT_EQUAL(OUString("18"),      parseDump("/root/page/body/txt[4]/Text[2]", "nLength"));
+    pTextFrame = static_cast<SwTextFrame*>(pTextFrame->GetNext());
+    pTextFrame->VisitPortions(aHandler);
 
-    CPPUNIT_ASSERT_EQUAL(OUString("POR_TXT"), parseDump("/root/page/body/txt[4]/Text[3]", "nType"));
-    CPPUNIT_ASSERT_EQUAL(OUString("1"),       parseDump("/root/page/body/txt[4]/Text[3]", "nLength"));
+    {
+        // Text "The purpose of this report is to summarize the results of the existing bug in the LO suite"
+        // = 91 chars
+        auto& rPortionItem = aHandler.mPortionItems[0];
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),    rPortionItem.msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(91),       rPortionItem.mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_TXT), rPortionItem.mnTextType);
+
+        // NEW LINE
+        rPortionItem = aHandler.mPortionItems[1];
+        CPPUNIT_ASSERT_EQUAL(OUString("line_break"), rPortionItem.msItemType);
+
+        // Input Field: "ThisIsAllOneWord" = 18 chars
+        // which is 16 chars + 2 hidden chars (start & end input field) = 18 chars
+        // If this is correct then the input field is in one piece
+        rPortionItem = aHandler.mPortionItems[2];
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),         rPortionItem.msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(18),            rPortionItem.mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_INPUTFLD), rPortionItem.mnTextType);
+
+        // Text "."
+        rPortionItem = aHandler.mPortionItems[3];
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),    rPortionItem.msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1),        rPortionItem.mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_TXT), rPortionItem.mnTextType);
+
+        // NEW LINE
+        rPortionItem = aHandler.mPortionItems[4];
+        CPPUNIT_ASSERT_EQUAL(OUString("line_break"), rPortionItem.msItemType);
+
+        rPortionItem = aHandler.mPortionItems[5];
+        CPPUNIT_ASSERT_EQUAL(OUString("finish"), rPortionItem.msItemType);
 
-    // Second paragraph
-    CPPUNIT_ASSERT_EQUAL(OUString("POR_TXT"), parseDump("/root/page/body/txt[5]/Text[1]", "nType"));
-    CPPUNIT_ASSERT_EQUAL(OUString("91"),      parseDump("/root/page/body/txt[5]/Text[1]", "nLength"));
+    }
 
-    // The input field here has more words ("One Two Three Four Five")
-    // and it should break after "Two".
-    // "One Two" = 7 chars + 1 start input field hidden character = 8 chars
-    CPPUNIT_ASSERT_EQUAL(OUString("Unknown"), parseDump("/root/page/body/txt[5]/Text[2]", "nType"));
-    CPPUNIT_ASSERT_EQUAL(OUString("8"),       parseDump("/root/page/body/txt[5]/Text[2]", "nLength"));
+    aHandler.clear();
 
-    CPPUNIT_ASSERT_EQUAL(OUString("POR_HOLE"), parseDump("/root/page/body/txt[5]/Text[3]", "nType"));
-    CPPUNIT_ASSERT_EQUAL(OUString("1"),        parseDump("/root/page/body/txt[5]/Text[3]", "nLength"));
+    pTextFrame = static_cast<SwTextFrame*>(pTextFrame->GetNext());
+    pTextFrame->VisitPortions(aHandler);
+    {
+        printf ("Portions:\n");
 
-    // In new line..
-    // "Three Four Five" = 16 chars + 1 end input field hidden character = 16 chars
-    CPPUNIT_ASSERT_EQUAL(OUString("Unknown"), parseDump("/root/page/body/txt[5]/Text[4]", "nType"));
-    CPPUNIT_ASSERT_EQUAL(OUString("16"),      parseDump("/root/page/body/txt[5]/Text[4]", "nLength"));
+        for (auto& rPortionItem : aHandler.mPortionItems)
+        {
+            printf ("-- Type: %s length: %d text type: %d\n",
+                        rPortionItem.msItemType.toUtf8().getStr(),
+                        rPortionItem.mnLength,
+                        rPortionItem.mnTextType);
+        }
 
-    CPPUNIT_ASSERT_EQUAL(OUString("POR_TXT"), parseDump("/root/page/body/txt[5]/Text[5]", "nType"));
-    CPPUNIT_ASSERT_EQUAL(OUString("1"),       parseDump("/root/page/body/txt[5]/Text[5]", "nLength"));
+        // Text "The purpose of this report is to summarize the results of the existing bug in the LO suite"
+        // 91 chars
+        auto& rPortionItem = aHandler.mPortionItems[0];
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),    rPortionItem.msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(91),       rPortionItem.mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_TXT), rPortionItem.mnTextType);
+
+        // The input field here has more words ("One Two Three Four Five")
+        // and it should break after "Two".
+        // Input Field: "One Two" = 7 chars + 1 start input field hidden character = 8 chars
+        rPortionItem = aHandler.mPortionItems[1];
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),         rPortionItem.msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(8),             rPortionItem.mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_INPUTFLD), rPortionItem.mnTextType);
+
+        rPortionItem = aHandler.mPortionItems[2];
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),     rPortionItem.msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1),         rPortionItem.mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_HOLE), rPortionItem.mnTextType);
+
+        // NEW LINE
+        rPortionItem = aHandler.mPortionItems[3];
+        CPPUNIT_ASSERT_EQUAL(OUString("line_break"), rPortionItem.msItemType);
+
+        // Input Field:  "Three Four Five" = 16 chars + 1 end input field hidden character = 16 chars
+        rPortionItem = aHandler.mPortionItems[4];
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),         rPortionItem.msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(16),            rPortionItem.mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_INPUTFLD), rPortionItem.mnTextType);
+
+        // Text "."
+        rPortionItem = aHandler.mPortionItems[5];
+        CPPUNIT_ASSERT_EQUAL(OUString("text"),    rPortionItem.msItemType);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1),        rPortionItem.mnLength);
+        CPPUNIT_ASSERT_EQUAL(sal_uInt16(POR_TXT), rPortionItem.mnTextType);
+
+        // NEW LINE
+        rPortionItem = aHandler.mPortionItems[6];
+        CPPUNIT_ASSERT_EQUAL(OUString("line_break"), rPortionItem.msItemType);
+
+        rPortionItem = aHandler.mPortionItems[7];
+        CPPUNIT_ASSERT_EQUAL(OUString("finish"), rPortionItem.msItemType);
+    }
 }
 
 void SwUiWriterTest::testTdf92648()
diff --git a/sw/source/core/inc/SwPortionHandler.hxx b/sw/source/core/inc/SwPortionHandler.hxx
index 48fe4fe..7f88820 100644
--- a/sw/source/core/inc/SwPortionHandler.hxx
+++ b/sw/source/core/inc/SwPortionHandler.hxx
@@ -39,7 +39,7 @@ class SwFont;
  * The SwPortionHandler can be used with the
  * SwTextFrame::VisitPortions(...) method.
  */
-class SwPortionHandler
+class SW_DLLPUBLIC SwPortionHandler
 {
 public:
 
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index 811800e..36f9327 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -46,7 +46,7 @@ class SwScriptInfo;
 #define NON_PRINTING_CHARACTER_COLOR RGB_COLORDATA(0x26, 0x8b, 0xd2)
 
 /// Represents the visualization of a paragraph.
-class SwTextFrame: public SwContentFrame
+class SW_DLLPUBLIC SwTextFrame: public SwContentFrame
 {
     friend class SwTextIter;
     friend class SwTestFormat;


More information about the Libreoffice-commits mailing list