summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorAustin Chen <austinchenyw@gmail.com>2015-04-16 22:30:12 -0700
committerCaolán McNamara <caolanm@redhat.com>2015-04-21 16:03:45 +0000
commitf29e959c827a5858e3baeea6e748aa597ac9fb94 (patch)
tree7ae0e9bfa73ed05ab5ee9f91c347ee91113c3f55 /sw
parent856e9b5fe2293bef9c45219391aca664d4a0dd20 (diff)
Applies CharAttribute to selected text and tests undo
Change-Id: Ibd171fda4ea38de4d76d8f252d6f6d37cf3b9a66 Reviewed-on: https://gerrit.libreoffice.org/15158 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 803e22202bd2..ffd281bd1c0b 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -89,6 +89,7 @@ public:
void testTdf90003();
void testSearchWithTransliterate();
void testTdf90362();
+ void testUndoCharAttribute();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -123,6 +124,7 @@ public:
CPPUNIT_TEST(testTdf90003);
CPPUNIT_TEST(testSearchWithTransliterate);
CPPUNIT_TEST(testTdf90362);
+ CPPUNIT_TEST(testUndoCharAttribute);
CPPUNIT_TEST_SUITE_END();
@@ -910,6 +912,42 @@ void SwUiWriterTest::testTdf90362()
CPPUNIT_ASSERT_EQUAL(false, pWrtShell->HasReadonlySel());
}
+void SwUiWriterTest::testUndoCharAttribute()
+{
+ // Create a new empty Writer document
+ SwDoc* pDoc = createDoc();
+ SwPaM* pCrsr = pDoc->GetEditShell()->GetCrsr();
+ sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
+ IDocumentContentOperations & rIDCO(pDoc->getIDocumentContentOperations());
+ // Insert some text
+ rIDCO.InsertString(*pCrsr, "This will be bolded");
+ // Position of word 9876543210
+ // Use cursor to select part of text
+ pCrsr->SetMark();
+ for (int i = 0; i < 9; i++) {
+ pCrsr->Move(fnMoveBackward);
+ }
+ // Check that correct text was selected
+ CPPUNIT_ASSERT_EQUAL(OUString("be bolded"), pCrsr->GetTxt());
+ // Apply a "Bold" attribute to selection
+ SvxWeightItem aWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT);
+ rIDCO.InsertPoolItem(*pCrsr, aWeightItem);
+ SfxItemSet aSet( pDoc->GetAttrPool(), RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT);
+ // Adds selected text's attributes to aSet
+ pCrsr->GetNode().GetTxtNode()->GetAttr(aSet, 10, 19);
+ SfxPoolItem* aPoolItem = (SfxPoolItem*) aSet.GetItem(RES_CHRATR_WEIGHT);
+ SfxPoolItem& ampPoolItem = aWeightItem;
+ // Check that bold is active on the selection; checks if it's in aSet
+ CPPUNIT_ASSERT_EQUAL((*aPoolItem == ampPoolItem), true);
+ // Invoke Undo
+ rUndoManager.Undo();
+ // Check that bold is no longer active
+ aSet.ClearItem(RES_CHRATR_WEIGHT);
+ pCrsr->GetNode().GetTxtNode()->GetAttr(aSet, 10, 19);
+ aPoolItem = (SfxPoolItem*) aSet.GetItem(RES_CHRATR_WEIGHT);
+ CPPUNIT_ASSERT_EQUAL((*aPoolItem == ampPoolItem), false);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();