summaryrefslogtreecommitdiff
path: root/editeng/qa
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2014-07-27 00:21:50 -0400
committerMichael Meeks <michael.meeks@collabora.com>2014-07-27 17:06:06 -0400
commit274b628a2b523eb45e297352a85f0177c6e747f0 (patch)
treeea72bf5dcf65cbb50564e48ac5c44a96d03a16f3 /editeng/qa
parenta3fc7f20089062afa4f778e70ba8be84032a30a7 (diff)
bnc#467459 - fix editeng text search with expanded fields.
Change-Id: If59d0e2f886e94148b81cb6cfcad067733fcb918
Diffstat (limited to 'editeng/qa')
-rw-r--r--editeng/qa/unit/core-test.cxx100
1 files changed, 94 insertions, 6 deletions
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index fb3d354e7b5d..4e9b82b30ee5 100644
--- a/editeng/qa/unit/core-test.cxx
+++ b/editeng/qa/unit/core-test.cxx
@@ -25,6 +25,9 @@
#include "editeng/postitem.hxx"
#include "editeng/section.hxx"
#include "editeng/editobj.hxx"
+#include "editeng/flditem.hxx"
+#include "svl/srchitem.hxx"
+#include "rtl/strbuf.hxx"
#include <com/sun/star/text/textfield/Type.hpp>
@@ -44,22 +47,22 @@ public:
void testConstruction();
- /**
- * Test UNO service class that implements text field items.
- */
+ /// Test UNO service class that implements text field items.
void testUnoTextFields();
- /**
- * AutoCorrect tests
- */
+ /// AutoCorrect tests
void testAutocorrect();
+ /// Test hyperlinks
+ void testHyperlinkSearch();
+
void testSectionAttributes();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testConstruction);
CPPUNIT_TEST(testUnoTextFields);
CPPUNIT_TEST(testAutocorrect);
+ CPPUNIT_TEST(testHyperlinkSearch);
CPPUNIT_TEST(testSectionAttributes);
CPPUNIT_TEST_SUITE_END();
@@ -340,6 +343,91 @@ void Test::testAutocorrect()
}
}
+namespace {
+ class UrlEditEngine : public EditEngine
+ {
+ public:
+ UrlEditEngine(SfxItemPool *pPool) : EditEngine(pPool) {}
+
+ virtual OUString CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, Color*&, Color*& )
+ {
+ return OUString("jim@bob.com"); // a sophisticated view of value:
+ }
+ };
+}
+
+// Odd accounting for hyperlink position & size etc.
+// https://bugzilla.novell.com/show_bug.cgi?id=467459
+void Test::testHyperlinkSearch()
+{
+ UrlEditEngine aEngine(mpItemPool);
+ EditDoc &rDoc = aEngine.GetEditDoc();
+
+ OUString aSampleText = "Please write email to . if you find a fish(not a dog).";
+ aEngine.SetText(aSampleText);
+
+ CPPUNIT_ASSERT_MESSAGE("set text", rDoc.GetParaAsString(sal_Int32(0)) == aSampleText);
+
+ ContentNode *pNode = rDoc.GetObject(0);
+ EditSelection aSel(EditPaM(pNode, 22), EditPaM(pNode, 22));
+ SvxURLField aURLField("mailto:///jim@bob.com", "jim@bob.com",
+ SVXURLFORMAT_REPR);
+ SvxFieldItem aField(aURLField, EE_FEATURE_FIELD);
+
+ aEngine.InsertField(aSel, aField);
+ aEngine.UpdateFields();
+
+ OUString aContent = pNode->GetExpandedText();
+ CPPUNIT_ASSERT_MESSAGE("get text", aContent ==
+ "Please write email to jim@bob.com. if you find a fish(not a dog).");
+ CPPUNIT_ASSERT_MESSAGE("wrong length", rDoc.GetTextLen() == (sal_uLong)aContent.getLength());
+
+ // Check expansion and positioning re-work
+ CPPUNIT_ASSERT_MESSAGE("wrong length", pNode->GetExpandedLen() ==
+ (sal_uLong)aContent.getLength());
+ for (sal_Int32 n = 0; n < aContent.getLength(); n++)
+ {
+ sal_Int32 nStart = n, nEnd = n;
+ pNode->UnExpandPositions(nStart,nEnd);
+ CPPUNIT_ASSERT_MESSAGE("out of bound start", nStart < pNode->Len());
+ CPPUNIT_ASSERT_MESSAGE("out of bound end", nEnd <= pNode->Len());
+ }
+
+ static const struct {
+ sal_Int32 mnStart, mnEnd;
+ sal_Int32 mnNewStart, mnNewEnd;
+ } aTrickyOnes[] = {
+ { 0, 1, /* -> */ 0, 1 },
+ { 21, 25, /* -> */ 21, 23 }, // the field is really just one char
+ { 25, 27, /* -> */ 22, 23 },
+ { 50, 56, /* -> */ 40, 46 }
+ };
+ for (size_t n = 0; n < SAL_N_ELEMENTS(aTrickyOnes); n++)
+ {
+ sal_Int32 nStart = aTrickyOnes[n].mnStart;
+ sal_Int32 nEnd = aTrickyOnes[n].mnEnd;
+ pNode->UnExpandPositions(nStart,nEnd);
+
+ rtl::OStringBuffer aBuf;
+ aBuf = "bound check start is ";
+ aBuf.append(nStart).append(" but should be ").append(aTrickyOnes[n].mnNewStart);
+ aBuf.append(" in row ").append((sal_Int32)n);
+ CPPUNIT_ASSERT_MESSAGE(aBuf.getStr(), nStart == aTrickyOnes[n].mnNewStart);
+ aBuf = "bound check end is ";
+ aBuf.append(nEnd).append(" but should be ").append(aTrickyOnes[n].mnNewEnd);
+ aBuf.append(" in row ").append((sal_Int32)n);
+ CPPUNIT_ASSERT_MESSAGE(aBuf.getStr(), nEnd == aTrickyOnes[n].mnNewEnd);
+ }
+
+ SvxSearchItem aItem(1); //SID_SEARCH_ITEM);
+ aItem.SetBackward(false);
+ aItem.SetSelection(false);
+ aItem.SetSearchString("fish");
+ CPPUNIT_ASSERT_MESSAGE("no fish", aEngine.HasText(aItem));
+ aItem.SetSearchString("dog");
+ CPPUNIT_ASSERT_MESSAGE("no dog", aEngine.HasText(aItem));
+}
+
bool hasBold(const editeng::Section& rSecAttr)
{
std::vector<const SfxPoolItem*>::const_iterator it = rSecAttr.maAttributes.begin(), itEnd = rSecAttr.maAttributes.end();