summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-05-03 10:53:59 +0200
committerMichael Stahl <mstahl@redhat.com>2016-05-03 11:41:04 +0200
commit20ae3d14187dacce2c2a1d2eab389e6110fe8442 (patch)
treecafebeaeba30b9be8c323129bacda22ee4dd5dde
parent9a2fccbc3870c5e9f65283df3fbed25f93fd47e2 (diff)
tdf#98512 sw: add unit test
... and fix the SAL_WARN not to warn spuriously. Change-Id: Ic951fc0d811e5cab39989285d34bdd2fff8f95fd
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx40
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx3
2 files changed, 42 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 11a08246c787..fca4a79d5dee 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -112,6 +112,7 @@ public:
void testFdo75110();
void testFdo75898();
void testFdo74981();
+ void testTdf98512();
void testShapeTextboxSelect();
void testShapeTextboxDelete();
void testCp1000071();
@@ -211,6 +212,7 @@ public:
CPPUNIT_TEST(testFdo75110);
CPPUNIT_TEST(testFdo75898);
CPPUNIT_TEST(testFdo74981);
+ CPPUNIT_TEST(testTdf98512);
CPPUNIT_TEST(testShapeTextboxSelect);
CPPUNIT_TEST(testShapeTextboxDelete);
CPPUNIT_TEST(testCp1000071);
@@ -701,6 +703,44 @@ void SwUiWriterTest::testFdo74981()
CPPUNIT_ASSERT(!pTextNode->HasHints());
}
+void SwUiWriterTest::testTdf98512()
+{
+ SwDoc* pDoc = createDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ SwInputFieldType *const pType(static_cast<SwInputFieldType*>(
+ pWrtShell->GetFieldType(0, RES_INPUTFLD)));
+ SwInputField aField1(pType, OUString("foo"), OUString("bar"), INP_TXT, 0);
+ pWrtShell->Insert(aField1);
+ pWrtShell->SttEndDoc(/*bStt=*/true);
+ SwInputField aField2(pType, OUString("baz"), OUString("quux"), INP_TXT, 0);
+ pWrtShell->Insert(aField2);
+ pWrtShell->SttEndDoc(/*bStt=*/true);
+ pWrtShell->SetMark();
+ pWrtShell->SttEndDoc(/*bStt=*/false);
+ OUString const expected1(
+ OUStringLiteral1<CH_TXT_ATR_INPUTFIELDSTART>() + "foo" + OUStringLiteral1<CH_TXT_ATR_INPUTFIELDEND>());
+ OUString const expected2(
+ OUStringLiteral1<CH_TXT_ATR_INPUTFIELDSTART>() + "baz" + OUStringLiteral1<CH_TXT_ATR_INPUTFIELDEND>()
+ + expected1);
+ CPPUNIT_ASSERT_EQUAL(expected2, pWrtShell->getShellCursor(false)->GetText());
+ sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
+ rUndoManager.Undo();
+ pWrtShell->SttEndDoc(/*bStt=*/true);
+ pWrtShell->SetMark();
+ pWrtShell->SttEndDoc(/*bStt=*/false);
+ CPPUNIT_ASSERT_EQUAL(expected1, pWrtShell->getShellCursor(false)->GetText());
+ rUndoManager.Redo();
+ pWrtShell->SttEndDoc(/*bStt=*/true);
+ pWrtShell->SetMark();
+ pWrtShell->SttEndDoc(/*bStt=*/false);
+ CPPUNIT_ASSERT_EQUAL(expected2, pWrtShell->getShellCursor(false)->GetText());
+ rUndoManager.Undo();
+ pWrtShell->SttEndDoc(/*bStt=*/true);
+ pWrtShell->SetMark();
+ pWrtShell->SttEndDoc(/*bStt=*/false);
+ CPPUNIT_ASSERT_EQUAL(expected1, pWrtShell->getShellCursor(false)->GetText());
+}
+
void SwUiWriterTest::testShapeTextboxSelect()
{
SwDoc* pDoc = createDoc("shape-textbox.odt");
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index ecc1d37a8c13..62b8024e2d82 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1940,6 +1940,7 @@ OUString SwTextNode::InsertText( const OUString & rStr, const SwIndex & rIdx,
if ( HasHints() )
{
+ bool const bHadHints(!m_pSwpHints->CanBeDeleted());
bool bMergePortionsNeeded(false);
for ( size_t i = 0; i < m_pSwpHints->Count() &&
rIdx >= m_pSwpHints->Get(i)->GetStart(); ++i )
@@ -2004,7 +2005,7 @@ OUString SwTextNode::InsertText( const OUString & rStr, const SwIndex & rIdx,
{
m_pSwpHints->MergePortions(*this);
}
- SAL_WARN_IF(m_pSwpHints->CanBeDeleted(), "sw.core",
+ SAL_WARN_IF(bHadHints && m_pSwpHints->CanBeDeleted(), "sw.core",
"SwTextNode::InsertText: unexpected loss of hints");
}