diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-07-08 18:28:43 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-07-08 22:00:56 -0400 |
commit | 100c0f885be5c1b308ad13e60b56060d59bc7100 (patch) | |
tree | 655b66e9dc0c8ef689f842230eae40efb547226d /sc | |
parent | eef53622798e2e2f81f28ee5e1c82de0d48c149c (diff) |
Split ucalc.cxx into multiple source files.
Change-Id: Ic46dcc8cb415fd3ea9062d477260cb6f120fb815
Diffstat (limited to 'sc')
-rw-r--r-- | sc/CppunitTest_sc_ucalc.mk | 1 | ||||
-rw-r--r-- | sc/qa/unit/helper/qahelper.cxx | 10 | ||||
-rw-r--r-- | sc/qa/unit/helper/qahelper.hxx | 14 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 536 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.hxx | 306 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_sharedformula.cxx | 227 |
6 files changed, 561 insertions, 533 deletions
diff --git a/sc/CppunitTest_sc_ucalc.mk b/sc/CppunitTest_sc_ucalc.mk index 702117facde3..8ab28b13e076 100644 --- a/sc/CppunitTest_sc_ucalc.mk +++ b/sc/CppunitTest_sc_ucalc.mk @@ -13,6 +13,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sc_ucalc)) $(eval $(call gb_CppunitTest_add_exception_objects,sc_ucalc, \ sc/qa/unit/ucalc \ + sc/qa/unit/ucalc_sharedformula \ )) $(eval $(call gb_CppunitTest_use_library_objects,sc_ucalc,sc)) diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index b330f2c5fffb..ee806bc481a7 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -14,6 +14,16 @@ #include <fstream> +FileFormat aFileFormats[] = { + { "ods" , "calc8", "", ODS_FORMAT_TYPE }, + { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE }, + { "xlsx", "Calc MS Excel 2007 XML" , "MS Excel 2007 XML", XLSX_FORMAT_TYPE }, + { "csv" , "Text - txt - csv (StarCalc)", "generic_Text", CSV_FORMAT_TYPE }, + { "html" , "calc_HTML_WebQuery", "generic_HTML", HTML_FORMAT_TYPE }, + { "123" , "Lotus", "calc_Lotus", LOTUS123_FORMAT_TYPE }, + { "dif", "DIF", "calc_DIF", DIF_FORMAT_TYPE }, +}; + bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol ) { return ( labs( nVal1 - nVal2 ) <= nTol ); diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx index b01a58104ad0..31e00a8c8105 100644 --- a/sc/qa/unit/helper/qahelper.hxx +++ b/sc/qa/unit/helper/qahelper.hxx @@ -71,15 +71,7 @@ struct FileFormat { const char* pName; const char* pFilterName; const char* pTypeName; unsigned int nFormatType; }; -FileFormat aFileFormats[] = { - { "ods" , "calc8", "", ODS_FORMAT_TYPE }, - { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE }, - { "xlsx", "Calc MS Excel 2007 XML" , "MS Excel 2007 XML", XLSX_FORMAT_TYPE }, - { "csv" , "Text - txt - csv (StarCalc)", "generic_Text", CSV_FORMAT_TYPE }, - { "html" , "calc_HTML_WebQuery", "generic_HTML", HTML_FORMAT_TYPE }, - { "123" , "Lotus", "calc_Lotus", LOTUS123_FORMAT_TYPE }, - { "dif", "DIF", "calc_DIF", DIF_FORMAT_TYPE }, -}; +extern FileFormat aFileFormats[]; // Why is this here and not in osl, and using the already existing file // handling APIs? Do we really want to add arbitrary new file handling @@ -94,7 +86,9 @@ SC_DLLPUBLIC void testFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab, St //need own handler because conditional formatting strings must be generated SC_DLLPUBLIC void testCondFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab); -std::string print(const ScAddress& rAddr) +SC_DLLPUBLIC void clearRange(ScDocument* pDoc, const ScRange& rRange); + +inline std::string print(const ScAddress& rAddr) { std::ostringstream str; str << "Col: " << rAddr.Col(); diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index f05872f46bab..8b2f6da51605 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -54,7 +54,6 @@ #include "tokenarray.hxx" #include "scopetools.hxx" #include "dociter.hxx" -#include "editutil.hxx" #include "formula/IFunctionDescription.hxx" @@ -80,309 +79,7 @@ #include <sstream> #include <vector> -#include "helper/qahelper.hxx" - -using namespace ::com::sun::star; - -using ::std::cout; -using ::std::cerr; -using ::std::endl; -using ::std::vector; - -namespace { - -class Test : public test::BootstrapFixture { -public: - Test(); - - virtual void setUp(); - virtual void tearDown(); - - /** - * Basic performance regression test. Pick some actions that *should* take - * only a fraction of a second to complete, and make sure they stay that - * way. We set the threshold to 1 second for each action which should be - * large enough to accommodate slower machines or machines with high load. - */ - void testPerf(); - void testCollator(); - void testRangeList(); - void testInput(); - void testFormulaHashAndTag(); - void testFuncSUM(); - void testFuncPRODUCT(); - void testFuncN(); - void testFuncCOUNTIF(); - void testFuncNUMBERVALUE(); - void testFuncVLOOKUP(); - void testFuncMATCH(); - void testFuncCELL(); - void testFuncDATEDIF(); - void testFuncINDIRECT(); - void testFuncIFERROR(); - void testCopyToDocument(); - /** - * Make sure the SHEETS function gets properly updated during sheet - * insertion and removal. - */ - void testSheetsFunc(); - void testVolatileFunc(); - - void testHorizontalIterator(); - - /** - * Basic test for formula dependency tracking. - */ - void testFormulaDepTracking(); - - /** - * Another test for formula dependency tracking, inspired by fdo#56278. - */ - void testFormulaDepTracking2(); - - /** - * More direct test for cell broadcaster management, used to track formula - * dependencies. - */ - void testCellBroadcaster(); - - void testFuncParam(); - void testNamedRange(); - void testCSV(); - void testMatrix(); - void testEnterMixedMatrix(); - - /** - * Basic test for pivot tables. - */ - void testPivotTable(); - - /** - * Test against unwanted automatic format detection on field names and - * field members in pivot tables. - */ - void testPivotTableLabels(); - - /** - * Make sure that we set cells displaying date values numeric cells, - * rather than text cells. Grouping by date or number functionality - * depends on this. - */ - void testPivotTableDateLabels(); - - /** - * Test for pivot table's filtering functionality by page fields. - */ - void testPivotTableFilters(); - - /** - * Test for pivot table's named source range. - */ - void testPivotTableNamedSource(); - - /** - * Test for pivot table cache. Each dimension in the pivot cache stores - * only unique values that are sorted in ascending order. - */ - void testPivotTableCache(); - - /** - * Test for pivot table containing data fields that reference the same - * source field but different functions. - */ - void testPivotTableDuplicateDataFields(); - - void testPivotTableNormalGrouping(); - void testPivotTableNumberGrouping(); - void testPivotTableDateGrouping(); - void testPivotTableEmptyRows(); - void testPivotTableTextNumber(); - - /** - * Test for checking that pivot table treats strings in a case insensitive - * manner. - */ - void testPivotTableCaseInsensitiveStrings(); - - /** - * Test for pivot table's handling of double-precision numbers that are - * very close together. - */ - void testPivotTableNumStability(); - - /** - * Test for pivot table that include field with various non-default field - * refrences. - */ - void testPivotTableFieldReference(); - - /** - * Test pivot table functionality performed via ScDBDocFunc. - */ - void testPivotTableDocFunc(); - - void testSheetCopy(); - void testSheetMove(); - void testExternalRef(); - void testExternalRefFunctions(); - void testDataArea(); - void testAutofilter(); - void testCopyPaste(); - void testMergedCells(); - void testUpdateReference(); - void testSearchCells(); - void testSharedFormulas(); - void testFormulaPosition(); - - /** - * Make sure the sheet streams are invalidated properly. - */ - void testStreamValid(); - - /** - * Test built-in cell functions to make sure their categories and order - * are correct. - */ - void testFunctionLists(); - - void testGraphicsInGroup(); - void testGraphicsOnSheetMove(); - - void testPostIts(); - - /** - * Test toggling relative/absolute flag of cell and cell range references. - * This corresponds with hitting Shift-F4 while the cursor is on a formula - * cell. - */ - void testToggleRefFlag(); - - /** - * Test to make sure correct precedent / dependent cells are obtained when - * preparing to jump to them. - */ - void testJumpToPrecedentsDependents(); - - void testSetBackgroundColor(); - void testRenameTable(); - - void testAutoFill(); - void testCopyPasteFormulas(); - void testCopyPasteFormulasExternalDoc(); - - void testFindAreaPosVertical(); - void testFindAreaPosColRight(); - void testSort(); - void testSortWithFormulaRefs(); - void testShiftCells(); - void testDeleteRow(); - void testDeleteCol(); - void testAnchoredRotatedShape(); - void testCellTextWidth(); - - /** - * Test formula & formula grouping - */ - void testFormulaGrouping(); - void testCondFormatINSDEL(); - - CPPUNIT_TEST_SUITE(Test); -#if CALC_TEST_PERF - CPPUNIT_TEST(testPerf); -#endif - CPPUNIT_TEST(testCollator); - CPPUNIT_TEST(testRangeList); - CPPUNIT_TEST(testInput); - CPPUNIT_TEST(testFormulaHashAndTag); - CPPUNIT_TEST(testFuncSUM); - CPPUNIT_TEST(testFuncPRODUCT); - CPPUNIT_TEST(testFuncN); - CPPUNIT_TEST(testFuncCOUNTIF); - CPPUNIT_TEST(testFuncNUMBERVALUE); - CPPUNIT_TEST(testFuncVLOOKUP); - CPPUNIT_TEST(testFuncMATCH); - CPPUNIT_TEST(testFuncCELL); - CPPUNIT_TEST(testFuncDATEDIF); - CPPUNIT_TEST(testFuncINDIRECT); - CPPUNIT_TEST(testFuncIFERROR); - CPPUNIT_TEST(testCopyToDocument); - CPPUNIT_TEST(testSheetsFunc); - CPPUNIT_TEST(testVolatileFunc); - CPPUNIT_TEST(testHorizontalIterator); - CPPUNIT_TEST(testFormulaDepTracking); - CPPUNIT_TEST(testFormulaDepTracking2); - CPPUNIT_TEST(testCellBroadcaster); - CPPUNIT_TEST(testFuncParam); - CPPUNIT_TEST(testNamedRange); - CPPUNIT_TEST(testCSV); - CPPUNIT_TEST(testMatrix); - CPPUNIT_TEST(testEnterMixedMatrix); - CPPUNIT_TEST(testPivotTable); - CPPUNIT_TEST(testPivotTableLabels); - CPPUNIT_TEST(testPivotTableDateLabels); - CPPUNIT_TEST(testPivotTableFilters); - CPPUNIT_TEST(testPivotTableNamedSource); - CPPUNIT_TEST(testPivotTableCache); - CPPUNIT_TEST(testPivotTableDuplicateDataFields); - CPPUNIT_TEST(testPivotTableNormalGrouping); - CPPUNIT_TEST(testPivotTableNumberGrouping); - CPPUNIT_TEST(testPivotTableDateGrouping); - CPPUNIT_TEST(testPivotTableEmptyRows); - CPPUNIT_TEST(testPivotTableTextNumber); - CPPUNIT_TEST(testPivotTableCaseInsensitiveStrings); - CPPUNIT_TEST(testPivotTableNumStability); - CPPUNIT_TEST(testPivotTableFieldReference); - CPPUNIT_TEST(testPivotTableDocFunc); - CPPUNIT_TEST(testSheetCopy); - CPPUNIT_TEST(testSheetMove); - CPPUNIT_TEST(testExternalRef); - CPPUNIT_TEST(testExternalRefFunctions); - CPPUNIT_TEST(testDataArea); - CPPUNIT_TEST(testGraphicsInGroup); - CPPUNIT_TEST(testGraphicsOnSheetMove); - CPPUNIT_TEST(testPostIts); - CPPUNIT_TEST(testStreamValid); - CPPUNIT_TEST(testFunctionLists); - CPPUNIT_TEST(testToggleRefFlag); - CPPUNIT_TEST(testAutofilter); - CPPUNIT_TEST(testCopyPaste); - CPPUNIT_TEST(testMergedCells); - CPPUNIT_TEST(testUpdateReference); - CPPUNIT_TEST(testSearchCells); - CPPUNIT_TEST(testSharedFormulas); - CPPUNIT_TEST(testFormulaPosition); - CPPUNIT_TEST(testJumpToPrecedentsDependents); - CPPUNIT_TEST(testSetBackgroundColor); - CPPUNIT_TEST(testRenameTable); - CPPUNIT_TEST(testAutoFill); - CPPUNIT_TEST(testCopyPasteFormulas); - CPPUNIT_TEST(testCopyPasteFormulasExternalDoc); - CPPUNIT_TEST(testFindAreaPosVertical); - CPPUNIT_TEST(testFindAreaPosColRight); - CPPUNIT_TEST(testSort); - CPPUNIT_TEST(testSortWithFormulaRefs); - CPPUNIT_TEST(testShiftCells); - CPPUNIT_TEST(testDeleteRow); - CPPUNIT_TEST(testDeleteCol); - CPPUNIT_TEST(testAnchoredRotatedShape); - CPPUNIT_TEST(testCellTextWidth); - CPPUNIT_TEST(testFormulaGrouping); - CPPUNIT_TEST(testCondFormatINSDEL); - CPPUNIT_TEST_SUITE_END(); - -private: - ScDocument *m_pDoc; - ScDocShellRef m_xDocShRef; -}; - -void clearRange(ScDocument* pDoc, const ScRange& rRange) -{ - ScMarkData aMarkData; - aMarkData.SetMarkArea(rRange); - pDoc->DeleteArea( - rRange.aStart.Col(), rRange.aStart.Row(), - rRange.aEnd.Col(), rRange.aEnd.Row(), aMarkData, IDF_CONTENTS); -} +#include "ucalc.hxx" void printRange(ScDocument* pDoc, const ScRange& rRange, const char* pCaption) { @@ -407,7 +104,7 @@ ScRange insertRangeData(ScDocument* pDoc, const ScAddress& rPos, const char* aDa aRange.aEnd.SetCol(rPos.Col()+_Size-1); aRange.aEnd.SetRow(rPos.Row()+nRowCount-1); - clearRange(pDoc, aRange); + Test::clearRange(pDoc, aRange); for (size_t i = 0; i < _Size; ++i) { @@ -4969,8 +4666,8 @@ void Test::testExternalRef() void testExtRefFuncT(ScDocument* pDoc, ScDocument* pExtDoc) { - clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0)); - clearRange(pExtDoc, ScRange(0, 0, 0, 1, 9, 0)); + Test::clearRange(pDoc, ScRange(0, 0, 0, 1, 9, 0)); + Test::clearRange(pExtDoc, ScRange(0, 0, 0, 1, 9, 0)); pExtDoc->SetString(0, 0, 0, OUString("'1.2")); pExtDoc->SetString(0, 1, 0, OUString("Foo")); @@ -6313,220 +6010,6 @@ void Test::testSearchCells() m_pDoc->DeleteTab(0); } -void Test::testSharedFormulas() -{ - m_pDoc->InsertTab(0, "Test"); - - ScAddress aPos(1, 9, 0); // B10 - m_pDoc->SetString(aPos, "=A10*2"); // Insert into B10. - const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("Expected to be a non-shared cell.", pFC && !pFC->IsShared()); - - aPos.SetRow(10); // B11 - m_pDoc->SetString(aPos, "=A11*2"); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(9), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); - - aPos.SetRow(8); // B9 - m_pDoc->SetString(aPos, "=A9*2"); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength()); - - aPos.SetRow(12); // B13 - m_pDoc->SetString(aPos, "=A13*2"); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This formula cell shouldn't be shared yet.", pFC && !pFC->IsShared()); - - // Insert a formula to B12, and B9:B13 should be shared. - aPos.SetRow(11); // B12 - m_pDoc->SetString(aPos, "=A12*2"); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(5), pFC->GetSharedLength()); - - // Insert formulas to B15:B16. - aPos.SetRow(14); // B15 - m_pDoc->SetString(aPos, "=A15*2"); - aPos.SetRow(15); // B16 - m_pDoc->SetString(aPos, "=A16*2"); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(14), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); - - // Insert a formula to B14, and B9:B16 should be shared. - aPos.SetRow(13); // B14 - m_pDoc->SetString(aPos, "=A14*2"); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedLength()); - - // Insert an incompatible formula to B12, to split the shared range to B9:B11 and B13:B16. - aPos.SetRow(11); // B12 - m_pDoc->SetString(aPos, "=$A$1*4"); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell shouldn't be shared.", pFC && !pFC->IsShared()); - - aPos.SetRow(8); // B9 - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength()); - - aPos.SetRow(12); // B13 - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(12), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength()); - - // Extend B13:B16 to B13:B20. - aPos.SetRow(16); // B17 - m_pDoc->SetString(aPos, "=A17*2"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A18*2"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A19*2"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A20*2"); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); - // B13:B20 shuld be shared. - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(12), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedLength()); - - // Empty B19. This should split it into B13:B18, and B20 non-shared. - aPos.SetRow(18); - m_pDoc->SetEmptyCell(aPos); - CPPUNIT_ASSERT_MESSAGE("This cell should have been emptied.", m_pDoc->GetCellType(aPos) == CELLTYPE_NONE); - aPos.SetRow(12); // B13 - pFC = m_pDoc->GetFormulaCell(aPos); - // B13:B18 should be shared. - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(12), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(6), pFC->GetSharedLength()); - // B20 shold be non-shared. - aPos.SetRow(19); // B20 - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("B20 should be a formula cell.", pFC); - CPPUNIT_ASSERT_MESSAGE("This cell should be non-shared.", !pFC->IsShared()); - - // Empty B14, to make B13 non-shared and B15:B18 shared. - aPos.SetRow(13); // B14 - m_pDoc->SetEmptyCell(aPos); - aPos.SetRow(12); // B13 - pFC = m_pDoc->GetFormulaCell(aPos); - // B13 should be non-shared. - CPPUNIT_ASSERT_MESSAGE("B13 should be a formula cell.", pFC); - CPPUNIT_ASSERT_MESSAGE("This cell should be non-shared.", !pFC->IsShared()); - // B15:B18 should be shared. - aPos.SetRow(14); // B15 - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(14), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength()); - - // Set numeric value to B15, to make B16:B18 shared. - aPos.SetRow(14); - m_pDoc->SetValue(aPos, 1.2); - aPos.SetRow(15); - pFC = m_pDoc->GetFormulaCell(aPos); - // B16:B18 should be shared. - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(15), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength()); - - // Set string value to B16 to make B17:B18 shared. - aPos.SetRow(15); - ScCellValue aCell("Test"); - CPPUNIT_ASSERT_MESSAGE("This should be a string value.", aCell.meType == CELLTYPE_STRING); - aCell.commit(*m_pDoc, aPos); - CPPUNIT_ASSERT_EQUAL(*aCell.mpString, m_pDoc->GetString(aPos)); - aPos.SetRow(16); - pFC = m_pDoc->GetFormulaCell(aPos); - // B17:B18 should be shared. - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(16), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); - - // Set edit text to B17. Now B18 should be non-shared. - ScFieldEditEngine& rEditEngine = m_pDoc->GetEditEngine(); - rEditEngine.SetText("Edit Text"); - aPos.SetRow(16); - m_pDoc->SetEditText(aPos, rEditEngine.CreateTextObject()); - CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, m_pDoc->GetCellType(aPos)); - aPos.SetRow(17); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("B18 should be a formula cell.", pFC); - CPPUNIT_ASSERT_MESSAGE("B18 should be non-shared.", !pFC->IsShared()); - - // Set up a new group for shared formulas in B2:B10. - clearRange(m_pDoc, ScRange(0,0,0,2,100,0)); - - aPos.SetRow(1); - m_pDoc->SetString(aPos, "=A2*10"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A3*10"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A4*10"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A5*10"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A6*10"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A7*10"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A8*10"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A9*10"); - aPos.IncRow(); - m_pDoc->SetString(aPos, "=A10*10"); - - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("B10 should be a formula cell.", pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(9), pFC->GetSharedLength()); - - // Delete A4:B8. This should splite the grouping to B2:B3 and B9:B10. - clearRange(m_pDoc, ScRange(0,3,0,1,7,0)); - aPos.SetRow(1); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("B2 should be a formula cell.", pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); - - aPos.SetRow(8); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("B9 should be a formula cell.", pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); - - // Delete rows 4:8 and shift row 9 and below up to row 4. This should - // re-merge the two into a group of B2:B5. - m_pDoc->DeleteRow(ScRange(0,3,0,MAXCOL,7,0)); - aPos.SetRow(1); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("B2 should be a formula cell.", pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength()); - - // Insert 2 rows at row 4, to split it into B2:B3 and B6:B7. - m_pDoc->InsertRow(ScRange(0,3,0,MAXCOL,4,0)); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("B2 should be a formula cell.", pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); - - aPos.SetRow(5); - pFC = m_pDoc->GetFormulaCell(aPos); - CPPUNIT_ASSERT_MESSAGE("B6 should be a formula cell.", pFC); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(5), pFC->GetSharedTopRow()); - CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); - - m_pDoc->DeleteTab(0); -} - namespace { bool checkFormulaPosition(ScDocument& rDoc, const ScAddress& rPos) @@ -7446,10 +6929,17 @@ void Test::testCondFormatINSDEL() m_pDoc->DeleteTab(0); } -CPPUNIT_TEST_SUITE_REGISTRATION(Test); - +void Test::clearRange(ScDocument* pDoc, const ScRange& rRange) +{ + ScMarkData aMarkData; + aMarkData.SetMarkArea(rRange); + pDoc->DeleteArea( + rRange.aStart.Col(), rRange.aStart.Row(), + rRange.aEnd.Col(), rRange.aEnd.Row(), aMarkData, IDF_CONTENTS); } +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx new file mode 100644 index 000000000000..ca5ddcfbe5ce --- /dev/null +++ b/sc/qa/unit/ucalc.hxx @@ -0,0 +1,306 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef SC_UCALC_HXX +#define SC_UCALC_HXX + +#include "helper/qahelper.hxx" + +class Test : public test::BootstrapFixture +{ +public: + + static void clearRange(ScDocument* pDoc, const ScRange& rRange); + + Test(); + + virtual void setUp(); + virtual void tearDown(); + + /** + * Basic performance regression test. Pick some actions that *should* take + * only a fraction of a second to complete, and make sure they stay that + * way. We set the threshold to 1 second for each action which should be + * large enough to accommodate slower machines or machines with high load. + */ + void testPerf(); + void testCollator(); + void testRangeList(); + void testInput(); + void testFormulaHashAndTag(); + void testFuncSUM(); + void testFuncPRODUCT(); + void testFuncN(); + void testFuncCOUNTIF(); + void testFuncNUMBERVALUE(); + void testFuncVLOOKUP(); + void testFuncMATCH(); + void testFuncCELL(); + void testFuncDATEDIF(); + void testFuncINDIRECT(); + void testFuncIFERROR(); + void testCopyToDocument(); + /** + * Make sure the SHEETS function gets properly updated during sheet + * insertion and removal. + */ + void testSheetsFunc(); + void testVolatileFunc(); + + void testHorizontalIterator(); + + /** + * Basic test for formula dependency tracking. + */ + void testFormulaDepTracking(); + + /** + * Another test for formula dependency tracking, inspired by fdo#56278. + */ + void testFormulaDepTracking2(); + + /** + * More direct test for cell broadcaster management, used to track formula + * dependencies. + */ + void testCellBroadcaster(); + + void testFuncParam(); + void testNamedRange(); + void testCSV(); + void testMatrix(); + void testEnterMixedMatrix(); + + /** + * Basic test for pivot tables. + */ + void testPivotTable(); + + /** + * Test against unwanted automatic format detection on field names and + * field members in pivot tables. + */ + void testPivotTableLabels(); + + /** + * Make sure that we set cells displaying date values numeric cells, + * rather than text cells. Grouping by date or number functionality + * depends on this. + */ + void testPivotTableDateLabels(); + + /** + * Test for pivot table's filtering functionality by page fields. + */ + void testPivotTableFilters(); + + /** + * Test for pivot table's named source range. + */ + void testPivotTableNamedSource(); + + /** + * Test for pivot table cache. Each dimension in the pivot cache stores + * only unique values that are sorted in ascending order. + */ + void testPivotTableCache(); + + /** + * Test for pivot table containing data fields that reference the same + * source field but different functions. + */ + void testPivotTableDuplicateDataFields(); + + void testPivotTableNormalGrouping(); + void testPivotTableNumberGrouping(); + void testPivotTableDateGrouping(); + void testPivotTableEmptyRows(); + void testPivotTableTextNumber(); + + /** + * Test for checking that pivot table treats strings in a case insensitive + * manner. + */ + void testPivotTableCaseInsensitiveStrings(); + + /** + * Test for pivot table's handling of double-precision numbers that are + * very close together. + */ + void testPivotTableNumStability(); + + /** + * Test for pivot table that include field with various non-default field + * refrences. + */ + void testPivotTableFieldReference(); + + /** + * Test pivot table functionality performed via ScDBDocFunc. + */ + void testPivotTableDocFunc(); + + void testSheetCopy(); + void testSheetMove(); + void testExternalRef(); + void testExternalRefFunctions(); + void testDataArea(); + void testAutofilter(); + void testCopyPaste(); + void testMergedCells(); + void testUpdateReference(); + void testSearchCells(); + void testSharedFormulas(); + void testFormulaPosition(); + + /** + * Make sure the sheet streams are invalidated properly. + */ + void testStreamValid(); + + /** + * Test built-in cell functions to make sure their categories and order + * are correct. + */ + void testFunctionLists(); + + void testGraphicsInGroup(); + void testGraphicsOnSheetMove(); + + void testPostIts(); + + /** + * Test toggling relative/absolute flag of cell and cell range references. + * This corresponds with hitting Shift-F4 while the cursor is on a formula + * cell. + */ + void testToggleRefFlag(); + + /** + * Test to make sure correct precedent / dependent cells are obtained when + * preparing to jump to them. + */ + void testJumpToPrecedentsDependents(); + + void testSetBackgroundColor(); + void testRenameTable(); + + void testAutoFill(); + void testCopyPasteFormulas(); + void testCopyPasteFormulasExternalDoc(); + + void testFindAreaPosVertical(); + void testFindAreaPosColRight(); + void testSort(); + void testSortWithFormulaRefs(); + void testShiftCells(); + void testDeleteRow(); + void testDeleteCol(); + void testAnchoredRotatedShape(); + void testCellTextWidth(); + + /** + * Test formula & formula grouping + */ + void testFormulaGrouping(); + void testCondFormatINSDEL(); + + CPPUNIT_TEST_SUITE(Test); +#if CALC_TEST_PERF + CPPUNIT_TEST(testPerf); +#endif + CPPUNIT_TEST(testCollator); + CPPUNIT_TEST(testRangeList); + CPPUNIT_TEST(testInput); + CPPUNIT_TEST(testFormulaHashAndTag); + CPPUNIT_TEST(testFuncSUM); + CPPUNIT_TEST(testFuncPRODUCT); + CPPUNIT_TEST(testFuncN); + CPPUNIT_TEST(testFuncCOUNTIF); + CPPUNIT_TEST(testFuncNUMBERVALUE); + CPPUNIT_TEST(testFuncVLOOKUP); + CPPUNIT_TEST(testFuncMATCH); + CPPUNIT_TEST(testFuncCELL); + CPPUNIT_TEST(testFuncDATEDIF); + CPPUNIT_TEST(testFuncINDIRECT); + CPPUNIT_TEST(testFuncIFERROR); + CPPUNIT_TEST(testCopyToDocument); + CPPUNIT_TEST(testSheetsFunc); + CPPUNIT_TEST(testVolatileFunc); + CPPUNIT_TEST(testHorizontalIterator); + CPPUNIT_TEST(testFormulaDepTracking); + CPPUNIT_TEST(testFormulaDepTracking2); + CPPUNIT_TEST(testCellBroadcaster); + CPPUNIT_TEST(testFuncParam); + CPPUNIT_TEST(testNamedRange); + CPPUNIT_TEST(testCSV); + CPPUNIT_TEST(testMatrix); + CPPUNIT_TEST(testEnterMixedMatrix); + CPPUNIT_TEST(testPivotTable); + CPPUNIT_TEST(testPivotTableLabels); + CPPUNIT_TEST(testPivotTableDateLabels); + CPPUNIT_TEST(testPivotTableFilters); + CPPUNIT_TEST(testPivotTableNamedSource); + CPPUNIT_TEST(testPivotTableCache); + CPPUNIT_TEST(testPivotTableDuplicateDataFields); + CPPUNIT_TEST(testPivotTableNormalGrouping); + CPPUNIT_TEST(testPivotTableNumberGrouping); + CPPUNIT_TEST(testPivotTableDateGrouping); + CPPUNIT_TEST(testPivotTableEmptyRows); + CPPUNIT_TEST(testPivotTableTextNumber); + CPPUNIT_TEST(testPivotTableCaseInsensitiveStrings); + CPPUNIT_TEST(testPivotTableNumStability); + CPPUNIT_TEST(testPivotTableFieldReference); + CPPUNIT_TEST(testPivotTableDocFunc); + CPPUNIT_TEST(testSheetCopy); + CPPUNIT_TEST(testSheetMove); + CPPUNIT_TEST(testExternalRef); + CPPUNIT_TEST(testExternalRefFunctions); + CPPUNIT_TEST(testDataArea); + CPPUNIT_TEST(testGraphicsInGroup); + CPPUNIT_TEST(testGraphicsOnSheetMove); + CPPUNIT_TEST(testPostIts); + CPPUNIT_TEST(testStreamValid); + CPPUNIT_TEST(testFunctionLists); + CPPUNIT_TEST(testToggleRefFlag); + CPPUNIT_TEST(testAutofilter); + CPPUNIT_TEST(testCopyPaste); + CPPUNIT_TEST(testMergedCells); + CPPUNIT_TEST(testUpdateReference); + CPPUNIT_TEST(testSearchCells); + CPPUNIT_TEST(testSharedFormulas); + CPPUNIT_TEST(testFormulaPosition); + CPPUNIT_TEST(testJumpToPrecedentsDependents); + CPPUNIT_TEST(testSetBackgroundColor); + CPPUNIT_TEST(testRenameTable); + CPPUNIT_TEST(testAutoFill); + CPPUNIT_TEST(testCopyPasteFormulas); + CPPUNIT_TEST(testCopyPasteFormulasExternalDoc); + CPPUNIT_TEST(testFindAreaPosVertical); + CPPUNIT_TEST(testFindAreaPosColRight); + CPPUNIT_TEST(testSort); + CPPUNIT_TEST(testSortWithFormulaRefs); + CPPUNIT_TEST(testShiftCells); + CPPUNIT_TEST(testDeleteRow); + CPPUNIT_TEST(testDeleteCol); + CPPUNIT_TEST(testAnchoredRotatedShape); + CPPUNIT_TEST(testCellTextWidth); + CPPUNIT_TEST(testFormulaGrouping); + CPPUNIT_TEST(testCondFormatINSDEL); + CPPUNIT_TEST_SUITE_END(); + +private: + ScDocument *m_pDoc; + ScDocShellRef m_xDocShRef; +}; + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx new file mode 100644 index 000000000000..3025b5204f28 --- /dev/null +++ b/sc/qa/unit/ucalc_sharedformula.cxx @@ -0,0 +1,227 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "ucalc.hxx" +#include "editutil.hxx" + +void Test::testSharedFormulas() +{ + m_pDoc->InsertTab(0, "Test"); + + ScAddress aPos(1, 9, 0); // B10 + m_pDoc->SetString(aPos, "=A10*2"); // Insert into B10. + const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("Expected to be a non-shared cell.", pFC && !pFC->IsShared()); + + aPos.SetRow(10); // B11 + m_pDoc->SetString(aPos, "=A11*2"); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(9), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + aPos.SetRow(8); // B9 + m_pDoc->SetString(aPos, "=A9*2"); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength()); + + aPos.SetRow(12); // B13 + m_pDoc->SetString(aPos, "=A13*2"); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This formula cell shouldn't be shared yet.", pFC && !pFC->IsShared()); + + // Insert a formula to B12, and B9:B13 should be shared. + aPos.SetRow(11); // B12 + m_pDoc->SetString(aPos, "=A12*2"); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(5), pFC->GetSharedLength()); + + // Insert formulas to B15:B16. + aPos.SetRow(14); // B15 + m_pDoc->SetString(aPos, "=A15*2"); + aPos.SetRow(15); // B16 + m_pDoc->SetString(aPos, "=A16*2"); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(14), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + // Insert a formula to B14, and B9:B16 should be shared. + aPos.SetRow(13); // B14 + m_pDoc->SetString(aPos, "=A14*2"); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedLength()); + + // Insert an incompatible formula to B12, to split the shared range to B9:B11 and B13:B16. + aPos.SetRow(11); // B12 + m_pDoc->SetString(aPos, "=$A$1*4"); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell shouldn't be shared.", pFC && !pFC->IsShared()); + + aPos.SetRow(8); // B9 + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength()); + + aPos.SetRow(12); // B13 + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(12), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength()); + + // Extend B13:B16 to B13:B20. + aPos.SetRow(16); // B17 + m_pDoc->SetString(aPos, "=A17*2"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A18*2"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A19*2"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A20*2"); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell is expected to be a shared formula cell.", pFC && pFC->IsShared()); + // B13:B20 shuld be shared. + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(12), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedLength()); + + // Empty B19. This should split it into B13:B18, and B20 non-shared. + aPos.SetRow(18); + m_pDoc->SetEmptyCell(aPos); + CPPUNIT_ASSERT_MESSAGE("This cell should have been emptied.", m_pDoc->GetCellType(aPos) == CELLTYPE_NONE); + aPos.SetRow(12); // B13 + pFC = m_pDoc->GetFormulaCell(aPos); + // B13:B18 should be shared. + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(12), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(6), pFC->GetSharedLength()); + // B20 shold be non-shared. + aPos.SetRow(19); // B20 + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("B20 should be a formula cell.", pFC); + CPPUNIT_ASSERT_MESSAGE("This cell should be non-shared.", !pFC->IsShared()); + + // Empty B14, to make B13 non-shared and B15:B18 shared. + aPos.SetRow(13); // B14 + m_pDoc->SetEmptyCell(aPos); + aPos.SetRow(12); // B13 + pFC = m_pDoc->GetFormulaCell(aPos); + // B13 should be non-shared. + CPPUNIT_ASSERT_MESSAGE("B13 should be a formula cell.", pFC); + CPPUNIT_ASSERT_MESSAGE("This cell should be non-shared.", !pFC->IsShared()); + // B15:B18 should be shared. + aPos.SetRow(14); // B15 + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(14), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength()); + + // Set numeric value to B15, to make B16:B18 shared. + aPos.SetRow(14); + m_pDoc->SetValue(aPos, 1.2); + aPos.SetRow(15); + pFC = m_pDoc->GetFormulaCell(aPos); + // B16:B18 should be shared. + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(15), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength()); + + // Set string value to B16 to make B17:B18 shared. + aPos.SetRow(15); + ScCellValue aCell("Test"); + CPPUNIT_ASSERT_MESSAGE("This should be a string value.", aCell.meType == CELLTYPE_STRING); + aCell.commit(*m_pDoc, aPos); + CPPUNIT_ASSERT_EQUAL(*aCell.mpString, m_pDoc->GetString(aPos)); + aPos.SetRow(16); + pFC = m_pDoc->GetFormulaCell(aPos); + // B17:B18 should be shared. + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(16), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + // Set edit text to B17. Now B18 should be non-shared. + ScFieldEditEngine& rEditEngine = m_pDoc->GetEditEngine(); + rEditEngine.SetText("Edit Text"); + aPos.SetRow(16); + m_pDoc->SetEditText(aPos, rEditEngine.CreateTextObject()); + CPPUNIT_ASSERT_EQUAL(CELLTYPE_EDIT, m_pDoc->GetCellType(aPos)); + aPos.SetRow(17); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("B18 should be a formula cell.", pFC); + CPPUNIT_ASSERT_MESSAGE("B18 should be non-shared.", !pFC->IsShared()); + + // Set up a new group for shared formulas in B2:B10. + clearRange(m_pDoc, ScRange(0,0,0,2,100,0)); + + aPos.SetRow(1); + m_pDoc->SetString(aPos, "=A2*10"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A3*10"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A4*10"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A5*10"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A6*10"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A7*10"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A8*10"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A9*10"); + aPos.IncRow(); + m_pDoc->SetString(aPos, "=A10*10"); + + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("B10 should be a formula cell.", pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(9), pFC->GetSharedLength()); + + // Delete A4:B8. This should splite the grouping to B2:B3 and B9:B10. + clearRange(m_pDoc, ScRange(0,3,0,1,7,0)); + aPos.SetRow(1); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("B2 should be a formula cell.", pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + aPos.SetRow(8); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("B9 should be a formula cell.", pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(8), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + // Delete rows 4:8 and shift row 9 and below up to row 4. This should + // re-merge the two into a group of B2:B5. + m_pDoc->DeleteRow(ScRange(0,3,0,MAXCOL,7,0)); + aPos.SetRow(1); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("B2 should be a formula cell.", pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength()); + + // Insert 2 rows at row 4, to split it into B2:B3 and B6:B7. + m_pDoc->InsertRow(ScRange(0,3,0,MAXCOL,4,0)); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("B2 should be a formula cell.", pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + aPos.SetRow(5); + pFC = m_pDoc->GetFormulaCell(aPos); + CPPUNIT_ASSERT_MESSAGE("B6 should be a formula cell.", pFC); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(5), pFC->GetSharedTopRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength()); + + m_pDoc->DeleteTab(0); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |