summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Dhall <varun.dhall@studentpartner.com>2016-03-01 18:54:48 +0530
committerMichael Stahl <mstahl@redhat.com>2016-03-23 21:56:19 +0000
commit013b7f6cb249fa08d00cb9124a1ab3429d72d6d2 (patch)
tree52fa7e54823f470895eac00992a8d7e7fb07547b
parent19c5fb059b4c2bca88d37bafe4c0bada1f0f48a7 (diff)
Added Test for tdf#63553 copy/paste of cross references
Change-Id: I9d50b170b228e270e60212cb10711fb537dae706 Reviewed-on: https://gerrit.libreoffice.org/22809 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx263
1 files changed, 263 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index ef694d9ddfd0..5a3cbb710fe8 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -151,6 +151,7 @@ public:
void testTdf73660();
void testNewDocModifiedState();
void testTdf77342();
+ void testTdf63553();
void testTdf74230();
void testTdf74363();
void testTdf80663();
@@ -243,6 +244,7 @@ public:
CPPUNIT_TEST(testTdf73660);
CPPUNIT_TEST(testNewDocModifiedState);
CPPUNIT_TEST(testTdf77342);
+ CPPUNIT_TEST(testTdf63553);
CPPUNIT_TEST(testTdf74230);
CPPUNIT_TEST(testTdf74363);
CPPUNIT_TEST(testTdf80663);
@@ -2146,6 +2148,267 @@ void SwUiWriterTest::testTdf77342()
CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pTFNote15->GetSeqRefNo());
}
+void SwUiWriterTest::testTdf63553()
+{
+ SwDoc* pDoc = createDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ SwPaM* pCursor = pDoc->GetEditShell()->GetCursor();
+ //inserting sequence field 1
+ SwSetExpFieldType* pSeqType = static_cast<SwSetExpFieldType*>(pWrtShell->GetFieldType(RES_SETEXPFLD, "Illustration"));
+ SwSetExpField aSetField1(pSeqType, OUString(""), SVX_NUM_ARABIC);
+ pWrtShell->Insert(aSetField1);
+ SwGetRefFieldType* pRefType = static_cast<SwGetRefFieldType*>(pWrtShell->GetFieldType(0, RES_GETREFFLD));
+ //moving cursor to the starting of document
+ pWrtShell->SttDoc();
+ //inserting reference field 1
+ SwGetRefField aGetField1(pRefType, OUString("Illustration"), REF_SEQUENCEFLD, sal_uInt16(0), REF_CONTENT);
+ pWrtShell->Insert(aGetField1);
+ //now we have ref1-seq1
+ //moving the cursor
+ pCursor->Move(fnMoveForward);
+ //inserting sequence field 2
+ SwSetExpField aSetField2(pSeqType, OUString(""), SVX_NUM_ARABIC);
+ pWrtShell->Insert(aSetField2);
+ //moving the cursor
+ pWrtShell->SttDoc();
+ pCursor->Move(fnMoveForward);
+ //inserting reference field 2
+ SwGetRefField aGetField2(pRefType, OUString("Illustration"), REF_SEQUENCEFLD, sal_uInt16(1), REF_CONTENT);
+ pWrtShell->Insert(aGetField2);
+ //now we have ref1-ref2-seq1-seq2
+ //moving the cursor
+ pCursor->Move(fnMoveForward);
+ pCursor->Move(fnMoveForward);
+ //inserting sequence field 3
+ SwSetExpField aSetField3(pSeqType, OUString(""), SVX_NUM_ARABIC);
+ pWrtShell->Insert(aSetField3);
+ pWrtShell->SttDoc();
+ pCursor->Move(fnMoveForward);
+ pCursor->Move(fnMoveForward);
+ //inserting reference field 3
+ SwGetRefField aGetField3(pRefType, OUString("Illustration"), REF_SEQUENCEFLD, sal_uInt16(2), REF_CONTENT);
+ pWrtShell->Insert(aGetField3);
+ //now after insertion we have ref1-ref2-ref3-seq1-seq2-seq3
+ //updating the fields
+ IDocumentFieldsAccess& rField(pDoc->getIDocumentFieldsAccess());
+ rField.UpdateExpFields(nullptr, true);
+ //creating new clipboard doc
+ SwDoc* pClpDoc = new SwDoc();
+ pClpDoc->acquire();
+ pClpDoc->SetClipBoard(true);
+ pClpDoc->getIDocumentFieldsAccess().LockExpFields();
+ //selecting reference field 2 and 3 and sequence field 1 and 2
+ //selection is such that more than one and not all sequence fields and reference fields are selected
+ //ref1-[ref2-ref3-seq1-seq2]-seq3
+ pWrtShell->SttDoc();
+ pCursor->Move(fnMoveForward);
+ //start marking
+ pCursor->SetMark();
+ pCursor->Move(fnMoveForward);
+ pCursor->Move(fnMoveForward);
+ pCursor->Move(fnMoveForward);
+ pCursor->Move(fnMoveForward);
+ //copying the selection to clipboard
+ pWrtShell->Copy(pClpDoc);
+ //deleting selection mark after copy
+ pCursor->DeleteMark();
+ //checking whether the sequence and reference fields have same values after copy operation
+ uno::Any aAny;
+ sal_uInt16 aFormat;
+ //reference field 1
+ pWrtShell->SttDoc();
+ SwField* pRef1 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pRef1->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pRef1->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(0)), aAny);
+ //reference field 2
+ pCursor->Move(fnMoveForward);
+ SwField* pRef2 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pRef2->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pRef2->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(1)), aAny);
+ //reference field 3
+ pCursor->Move(fnMoveForward);
+ SwField* pRef3 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pRef3->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pRef3->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(2)), aAny);
+ //sequence field 1
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pSeqF1 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pSeqF1->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeqF1->GetFieldName());
+ //sequence field 2
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pSeqF2 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pSeqF2->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeqF2->GetFieldName());
+ //sequence field 3
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pSeqF3 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pSeqF3->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeqF3->GetFieldName());
+ //moving cursor to the end of the document
+ pWrtShell->EndDoc();
+ //pasting the copied selection at current cursor position
+ pWrtShell->Paste(pClpDoc);
+ //checking the fields, both new and old, for proper values
+ pWrtShell->SttDoc();
+ //now we have ref1-ref2-ref3-seq1-seq2-seq3-nref1-nref2-nseq1-nseq2
+ //old reference field 1
+ SwField* pOldRef11 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pOldRef11->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pOldRef11->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(0)), aAny);
+ //old reference field 2
+ pCursor->Move(fnMoveForward);
+ SwField* pOldRef12 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pOldRef12->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pOldRef12->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(1)), aAny);
+ //old reference field 3
+ pCursor->Move(fnMoveForward);
+ SwField* pOldRef13 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pOldRef13->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pOldRef13->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(2)), aAny);
+ //old sequence field 1
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pSeq1 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pSeq1->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeq1->GetFieldName());
+ //old sequence field 2
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pSeq2 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pSeq2->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeq2->GetFieldName());
+ //old sequence field 3
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pSeq3 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pSeq3->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pSeq3->GetFieldName());
+ //new reference field 1
+ pCursor->Move(fnMoveForward);
+ SwField* pNewRef11 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pNewRef11->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pNewRef11->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(4)), aAny);
+ //new reference field 2
+ pCursor->Move(fnMoveForward);
+ SwField* pNewRef12 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pNewRef12->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pNewRef12->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(2)), aAny);
+ //new sequence field 1
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pNewSeq1 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pNewSeq1->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pNewSeq1->GetFieldName());
+ //new sequence field 2
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pNewSeq2 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), pNewSeq2->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pNewSeq2->GetFieldName());
+ //moving the cursor to the starting of document
+ pWrtShell->SttDoc();
+ //pasting the selection again at current cursor position
+ pWrtShell->Paste(pClpDoc);
+ //checking the fields, both new and old, for proper values
+ pWrtShell->SttDoc();
+ //now we have [nnref1-nnref2-nnseq1-nnseq2]-ref1-[ref2-ref3-seq1-seq2]-seq3-[nref1-nref2-nseq1-nseq2]
+ //new reference field 1
+ SwField* pNewRef21 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pNewRef21->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pNewRef21->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(6)), aAny);
+ //new reference field 2
+ pCursor->Move(fnMoveForward);
+ SwField* pNewRef22 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pNewRef22->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pNewRef22->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(2)), aAny);
+ //new sequence field 1
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pNewSeq11 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(5), pNewSeq11->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pNewSeq11->GetFieldName());
+ //new sequence field 2
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pNewSeq12 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(6), pNewSeq12->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pNewSeq12->GetFieldName());
+ //old reference field 1
+ pCursor->Move(fnMoveForward);
+ SwField* pOldRef21 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pOldRef21->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pOldRef21->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(0)), aAny);
+ //old reference field 2
+ pCursor->Move(fnMoveForward);
+ SwField* pOldRef22 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pOldRef22->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pOldRef22->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(1)), aAny);
+ //old reference field 3
+ pCursor->Move(fnMoveForward);
+ SwField* pOldRef23 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pOldRef23->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pOldRef23->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(2)), aAny);
+ //old sequence field 1
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pOldSeq11 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pOldSeq11->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq11->GetFieldName());
+ //old sequence field 2
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pOldSeq12 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pOldSeq12->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq12->GetFieldName());
+ //old sequence field 3
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pOldSeq13 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), pOldSeq13->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq13->GetFieldName());
+ //old reference field 4
+ pCursor->Move(fnMoveForward);
+ SwField* pOldRef24 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pOldRef24->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pOldRef24->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(4)), aAny);
+ //old reference field 5
+ pCursor->Move(fnMoveForward);
+ SwField* pOldRef25 = SwCursorShell::GetFieldAtCursor(pCursor, true);
+ aFormat = pOldRef25->GetFormat();
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_CONTENT), aFormat);
+ pOldRef25->QueryValue(aAny, sal_uInt16(FIELD_PROP_SHORT1));
+ CPPUNIT_ASSERT_EQUAL(uno::makeAny(sal_uInt16(2)), aAny);
+ //old sequence field 4
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pOldSeq14 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pOldSeq14->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq14->GetFieldName());
+ //old sequence field 5
+ pCursor->Move(fnMoveForward);
+ SwSetExpField* pOldSeq15 = static_cast<SwSetExpField*> (SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), pOldSeq15->GetSeqNumber());
+ CPPUNIT_ASSERT_EQUAL(OUString("Number range Illustration"), pOldSeq15->GetFieldName());
+}
+
void SwUiWriterTest::testTdf74230()
{
createDoc();