diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-13 22:42:44 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-05-13 22:47:37 -0400 |
commit | dff4725f0dbb3bd7c32155e51ba49c05ee104d4f (patch) | |
tree | df1f99d1a2e688bb62f0ba7c6c75c658a7da85f6 | |
parent | a362f15f85fc3f00ea3144f763798131cb66e3e3 (diff) |
fdo#76710: Write test for this.
Change-Id: Ia0338d2839f0f319881948c208a74bee950da4af
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 106 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 2 |
2 files changed, 108 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 2a2f706647c9..14a323ba32e4 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -5882,6 +5882,112 @@ void Test::testCondFormatInsertRow() m_pDoc->DeleteTab(0); } +void Test::testCondFormatInsertDeleteSheets() +{ + m_pDoc->InsertTab(0, "Test"); + + // Add a conditional format to B2:B4. + ScConditionalFormat* pFormat = new ScConditionalFormat(1, m_pDoc); + pFormat->AddRange(ScRange(1,1,0,1,3,0)); + + sal_uLong nKey = m_pDoc->AddCondFormat(pFormat, 0); + + // Add condition in which if the value equals 2, set the "Result" style. + ScCondFormatEntry* pEntry = new ScCondFormatEntry( + SC_COND_EQUAL, "=2", "" , m_pDoc, ScAddress(0,0,0), ScGlobal::GetRscString(STR_STYLENAME_RESULT)); + pFormat->AddEntry(pEntry); + + // Apply the format to the range. + m_pDoc->AddCondFormatData(pFormat->GetRange(), 0, nKey); + + // Make sure this conditional format entry is really there. + ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0); + CPPUNIT_ASSERT(pList); + const ScConditionalFormat* pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT_MESSAGE("Wrong condntional format instance.", pCheck == pFormat); + + // ... and its range is B2:B4. + ScRangeList aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + const ScRange* pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4.", *pRange == ScRange(1,1,0,1,3,0)); + + ScDocFunc& rFunc = getDocShell().GetDocFunc(); + + // Insert a new sheet at the left. + bool bInserted = rFunc.InsertTable(0, "Inserted", true, true); + CPPUNIT_ASSERT(bInserted); + + pList = m_pDoc->GetCondFormList(1); + CPPUNIT_ASSERT(pList); + pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT(pCheck); + + // Make sure the range also got shifted. + aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4 on the 2nd sheet after the sheet insertion.", *pRange == ScRange(1,1,1,1,3,1)); + + // Delete the sheet to the left. + bool bDeleted = rFunc.DeleteTable(0, true, true); + CPPUNIT_ASSERT(bDeleted); + + pList = m_pDoc->GetCondFormList(0); + CPPUNIT_ASSERT(pList); + pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT(pCheck); + + // Make sure the range got shifted back. + aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4 on the 1st sheet after the sheet removal.", *pRange == ScRange(1,1,0,1,3,0)); + + SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + + // Undo and re-check. + pUndoMgr->Undo(); + + pList = m_pDoc->GetCondFormList(1); + CPPUNIT_ASSERT(pList); + pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT(pCheck); + + aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4 on the 2nd sheet after the undo of the sheet removal.", *pRange == ScRange(1,1,1,1,3,1)); + +#if 0 // TODO : Undo of sheet insertion currently depends on the presence of + // view shell, and crashes when executed during cppunit run. + + // Undo again and re-check. + pUndoMgr->Undo(); + + pList = m_pDoc->GetCondFormList(0); + CPPUNIT_ASSERT(pList); + pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT(pCheck); + + // Make sure the range got shifted back. + aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4 on the 1st sheet after the undo of sheet insertion.", *pRange == ScRange(1,1,0,1,3,0)); +#else + m_pDoc->DeleteTab(1); +#endif + + m_pDoc->DeleteTab(0); +} + void Test::testCondCopyPaste() { m_pDoc->InsertTab(0, "Test"); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index f69da1bb9a38..ec32e235194a 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -353,6 +353,7 @@ public: void testCondFormatINSDEL(); void testCondFormatInsertRow(); void testCondFormatInsertCol(); + void testCondFormatInsertDeleteSheets(); void testCondCopyPaste(); void testIconSet(); @@ -512,6 +513,7 @@ public: CPPUNIT_TEST(testCondFormatINSDEL); CPPUNIT_TEST(testCondFormatInsertRow); CPPUNIT_TEST(testCondFormatInsertCol); + CPPUNIT_TEST(testCondFormatInsertDeleteSheets); CPPUNIT_TEST(testCondCopyPaste); CPPUNIT_TEST(testIconSet); CPPUNIT_TEST(testImportStream); |