Kaydet (Commit) 771aadfc authored tarafından Kohei Yoshida's avatar Kohei Yoshida

fdo#74556: Write test for ReleaseNote().

It's supposed to release note instance, not destroy it.

Change-Id: I40cd1a97d20b495f03fda68a991ad576de13ebc5
üst f6f83f2f
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#include <svx/svdpage.hxx> #include <svx/svdpage.hxx>
#include <svx/svdocirc.hxx> #include <svx/svdocirc.hxx>
#include <svx/svdopath.hxx> #include <svx/svdopath.hxx>
#include <svx/svdocapt.hxx>
#include "svl/srchitem.hxx" #include "svl/srchitem.hxx"
#include "svl/sharedstringpool.hxx" #include "svl/sharedstringpool.hxx"
...@@ -4756,6 +4757,49 @@ void Test::testNoteDeleteCol() ...@@ -4756,6 +4757,49 @@ void Test::testNoteDeleteCol()
pDoc->DeleteTab(0); pDoc->DeleteTab(0);
} }
void Test::testNoteLifeCycle()
{
m_pDoc->InsertTab(0, "Test");
// We need a drawing layer in order to create caption objects.
m_pDoc->InitDrawLayer(&getDocShell());
ScAddress aPos(1,1,0);
ScPostIt* pNote = m_pDoc->GetOrCreateNote(aPos);
CPPUNIT_ASSERT_MESSAGE("Failed to insert a new cell comment.", pNote);
pNote->SetText(aPos, "New note");
ScPostIt* pNote2 = m_pDoc->ReleaseNote(aPos);
CPPUNIT_ASSERT_MESSAGE("This note instance is expected to be identical to the original.", pNote == pNote2);
CPPUNIT_ASSERT_MESSAGE("The note shouldn't be here after it's been released.", !m_pDoc->HasNote(aPos));
// Modify the internal state of the note instance to make sure it's really
// been released.
pNote->SetText(aPos, "New content");
// Re-insert the note back to the same place.
m_pDoc->SetNote(aPos, pNote);
const SdrCaptionObj* pCaption = pNote->GetOrCreateCaption(aPos);
CPPUNIT_ASSERT_MESSAGE("Failed to create a caption object.", pCaption);
CPPUNIT_ASSERT_MESSAGE("This caption should belong to the drawing layer of the document.",
pCaption->GetModel() == m_pDoc->GetDrawLayer());
// Copy B2 with note to a clipboard.
ScClipParam aClipParam(aPos, false);
ScDocument aClipDoc(SCDOCMODE_CLIP);
ScMarkData aMarkData;
aMarkData.SelectOneTable(0);
m_pDoc->CopyToClip(aClipParam, &aClipDoc, &aMarkData, false, false, true, true, false);
ScPostIt* pClipNote = aClipDoc.GetNote(aPos);
CPPUNIT_ASSERT_MESSAGE("Failed to copy note to the clipboard.", pClipNote);
CPPUNIT_ASSERT_MESSAGE("Note on the clipboard should share the same caption object from the original.",
pClipNote->GetCaption() == pCaption);
m_pDoc->DeleteTab(0);
}
void Test::testAreasWithNotes() void Test::testAreasWithNotes()
{ {
ScDocument* pDoc = getDocShell().GetDocument(); ScDocument* pDoc = getDocShell().GetDocument();
......
...@@ -300,6 +300,7 @@ public: ...@@ -300,6 +300,7 @@ public:
void testNoteBasic(); void testNoteBasic();
void testNoteDeleteRow(); void testNoteDeleteRow();
void testNoteDeleteCol(); void testNoteDeleteCol();
void testNoteLifeCycle();
void testAreasWithNotes(); void testAreasWithNotes();
void testAnchoredRotatedShape(); void testAnchoredRotatedShape();
void testCellTextWidth(); void testCellTextWidth();
...@@ -428,6 +429,7 @@ public: ...@@ -428,6 +429,7 @@ public:
CPPUNIT_TEST(testShiftCells); CPPUNIT_TEST(testShiftCells);
CPPUNIT_TEST(testNoteDeleteRow); CPPUNIT_TEST(testNoteDeleteRow);
CPPUNIT_TEST(testNoteDeleteCol); CPPUNIT_TEST(testNoteDeleteCol);
CPPUNIT_TEST(testNoteLifeCycle);
CPPUNIT_TEST(testAreasWithNotes); CPPUNIT_TEST(testAreasWithNotes);
CPPUNIT_TEST(testAnchoredRotatedShape); CPPUNIT_TEST(testAnchoredRotatedShape);
CPPUNIT_TEST(testCellTextWidth); CPPUNIT_TEST(testCellTextWidth);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment