sc/qa/uitest/calc_tests/autosum.py | 214 ------------------------------------- sc/qa/unit/uicalc/data/autosum.ods |binary sc/qa/unit/uicalc/uicalc.cxx | 179 +++++++++++++++++++++++++++++- 3 files changed, 170 insertions(+), 223 deletions(-)
New commits: commit c82fa434dab8744c548db166cd24ee82e8759e1f Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu Jan 12 23:07:53 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Jan 12 23:33:45 2023 +0000 sc: move different UItests to CppUnittest it seems Jenkins fails sometimes with this test https://ci.libreoffice.org/job/gerrit_linux_clang_dbgutil/131248/ this commit might help TODO: convert the remaining test Change-Id: Ib3fb48e2e457a9168fa16c8f9f2ac9f98beabcf3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145422 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/uitest/calc_tests/autosum.py b/sc/qa/uitest/calc_tests/autosum.py index cc67bae05d80..db3334c36725 100644 --- a/sc/qa/uitest/calc_tests/autosum.py +++ b/sc/qa/uitest/calc_tests/autosum.py @@ -15,132 +15,6 @@ from libreoffice.uno.propertyvalue import mkPropertyValues class calcAutosum(UITestCase): - def test_autosum_test1(self): - #Sum on range and Sum on Sum's - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - #Place the cell cursor on the gray cells located under Point 1. - #(Multiselection is not possible at this place) and press the Sum Icon in the formula bar. - #Now hit the enter key and the result should be shown. Do so for each gray cell in this part of the document. - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "B10"})) - self.xUITest.executeCommand(".uno:AutoSum") - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "B13"})) - self.xUITest.executeCommand(".uno:AutoSum") - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "B14"})) - self.xUITest.executeCommand(".uno:AutoSum") - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 9).getValue(), 2) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 9).getFormula(), "=SUM(B8:B9)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 12).getValue(), 2) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 12).getFormula(), "=SUM(B11:B12)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 13).getValue(), 4) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 13).getFormula(), "=SUM(B13:B13;B10:B10)") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "F8:F14"})) - self.xUITest.executeCommand(".uno:AutoSum") - self.assertEqual(get_cell_by_position(calc_doc, 0, 5, 13).getValue(), 4) - self.assertEqual(get_cell_by_position(calc_doc, 0, 5, 13).getFormula(), "=SUM(F13:F13;F10:F10)") - - def test_autosum_test2(self): - #Sum on Row and Column - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E25"})) - self.xUITest.executeCommand(".uno:AutoSum") - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E26"})) - self.xUITest.executeCommand(".uno:AutoSum") - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E27"})) - self.xUITest.executeCommand(".uno:AutoSum") - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E28"})) - self.xUITest.executeCommand(".uno:AutoSum") - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E29"})) - self.xUITest.executeCommand(".uno:AutoSum") - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E30"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 24).getValue(), 3) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 24).getFormula(), "=SUM(E22:E24)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 25).getValue(), 3) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 25).getFormula(), "=SUM(B26:D26)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 26).getValue(), 3) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 26).getFormula(), "=SUM(B27:D27)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 27).getValue(), 3) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 27).getFormula(), "=SUM(B28:D28)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 28).getValue(), 9) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 28).getFormula(), "=SUM(E26:E28)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 29).getValue(), 12) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 29).getFormula(), "=SUM(E29:E29;E25:E25)") - - def test_autosum_test3(self): - #Subtotals on Autosum - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C49"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 48).getValue(), 20) - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 48).getFormula(), "=SUBTOTAL(9;C38:C48)") - - def test_autosum_test4(self): - #Autosum on column with selected empty cell for result - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B59:B64"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 63).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 63).getFormula(), "=SUM(B59:B63)") - - def test_autosum_test5(self): - #5.Autosum on rows with selected empty cell for result - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B76:E80"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 75).getValue(), 30) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 75).getFormula(), "=SUM(B76:D76)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 76).getValue(), 60) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 76).getFormula(), "=SUM(B77:D77)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 77).getValue(), 90) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 77).getFormula(), "=SUM(B78:D78)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 78).getValue(), 120) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 78).getFormula(), "=SUM(B79:D79)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 79).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 79).getFormula(), "=SUM(B80:D80)") - - def test_autosum_test6(self): - #6.Subtotal on column with selected empty cell for result - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "C92:C101"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 100).getValue(), 19) - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 100).getFormula(), "=SUBTOTAL(9;C92:C100)") - - def test_autosum_test7(self): - #7.Autosum on column without selected empty cell for result - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B109:B113"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 113).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 113).getFormula(), "=SUM(B109:B113)") - def test_autosum_test8(self): #8.Autosum on rows without selected empty cell for result with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: @@ -159,92 +33,4 @@ class calcAutosum(UITestCase): self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 129).getValue(), 150) self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 129).getFormula(), "=SUM(B130:D130)") - def test_autosum_test9(self): - #9.Subtotal on column without selected empty cell for result - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "C142:C149"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 150).getValue(), 19) - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 150).getFormula(), "=SUBTOTAL(9;C142:C149)") - - def test_autosum_test10(self): - #10.Autosum on multiselected columns without selected empty cell for result - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B160:D164"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 164).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 164).getFormula(), "=SUM(B160:B164)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 164).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 164).getFormula(), "=SUM(C160:C164)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 3, 164).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 3, 164).getFormula(), "=SUM(D160:D164)") - - def test_autosum_test11(self): - #11.Autosum on columns with formula results without selected empty cell for result - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B173:D177"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(round(get_cell_by_position(calc_doc, 0, 1, 177).getValue(),2), 2.55) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 177).getFormula(), "=SUM(B173:B177)") - self.assertEqual(round(get_cell_by_position(calc_doc, 0, 2, 177).getValue(),2), -4.91) - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 177).getFormula(), "=SUM(C173:C177)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 3, 177).getValue(), 5500) - self.assertEqual(get_cell_by_position(calc_doc, 0, 3, 177).getFormula(), "=SUM(D173:D177)") - - def test_autosum_test12(self): - #12.Autosum on column with filled cell under selected area - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B186:D190"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 191).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 191).getFormula(), "=SUM(B186:B190)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 191).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 191).getFormula(), "=SUM(C186:C190)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 3, 191).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 3, 191).getFormula(), "=SUM(D186:D190)") - - def test_autosum_test13(self): - #13.Autosum on column and rows with empty cells selected for row and column - with self.ui_test.load_file(get_url_for_data_file("autosum.ods")) as calc_doc: - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B203:E208"})) - self.xUITest.executeCommand(".uno:AutoSum") - - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 207).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 207).getFormula(), "=SUM(B203:B207)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 207).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 207).getFormula(), "=SUM(C203:C207)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 3, 207).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 3, 207).getFormula(), "=SUM(D203:D207)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 207).getValue(), 450) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 207).getFormula(), "=SUM(B208:D208)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 202).getValue(), 30) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 202).getFormula(), "=SUM(B203:D203)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 203).getValue(), 60) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 203).getFormula(), "=SUM(B204:D204)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 204).getValue(), 90) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 204).getFormula(), "=SUM(B205:D205)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 205).getValue(), 120) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 205).getFormula(), "=SUM(B206:D206)") - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 206).getValue(), 150) - self.assertEqual(get_cell_by_position(calc_doc, 0, 4, 206).getFormula(), "=SUM(B207:D207)") - # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/unit/uicalc/data/autosum.ods b/sc/qa/unit/uicalc/data/autosum.ods new file mode 100644 index 000000000000..05fa934b75b2 Binary files /dev/null and b/sc/qa/unit/uicalc/data/autosum.ods differ diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index 767bc23e740b..30c42f98beaa 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -46,6 +46,7 @@ public: void insertStringToCell(const OUString& rCell, const std::u16string_view& rStr); void insertArrayToCell(const OUString& rCell, const std::u16string_view& rStr); void insertNewSheet(ScDocument& rDoc); + void executeAutoSum(); }; ScUiCalcTest::ScUiCalcTest() @@ -131,6 +132,17 @@ void ScUiCalcTest::insertNewSheet(ScDocument& rDoc) CPPUNIT_ASSERT_EQUAL(static_cast<SCTAB>(nTabs + 1), rDoc.GetTableCount()); } +void ScUiCalcTest::executeAutoSum() +{ + dispatchCommand(mxComponent, ".uno:AutoSum", {}); + + // Use RETURN key to exit autosum edit view + ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent); + pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); + pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); + Scheduler::ProcessEventsToIdle(); +} + CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf142854_GridVisibilityImportXlsxInHeadlessMode) { // Tests are running in Headless mode @@ -2483,7 +2495,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf71339) goToCell("A1:A3"); - dispatchCommand(mxComponent, ".uno:AutoSum", {}); + executeAutoSum(); CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(ScAddress(0, 3, 0))); @@ -2506,13 +2518,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf116421) goToCell("A4"); - dispatchCommand(mxComponent, ".uno:AutoSum", {}); - - // Use RETURN key to exit autosum edit view - ScModelObj* pModelObj = comphelper::getFromUnoTunnel<ScModelObj>(mxComponent); - pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN); - pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); - Scheduler::ProcessEventsToIdle(); + executeAutoSum(); // Without the fix in place, this test would have failed with // - Expected: 3 @@ -2687,7 +2693,8 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf116215) insertStringToCell("B1", u"1"); insertStringToCell("B2", u"1"); goToCell("A1:C3"); - dispatchCommand(mxComponent, ".uno:AutoSum", {}); + + executeAutoSum(); CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(ScAddress(0, 2, 0))); OUString aFormula = pDoc->GetFormula(0, 2, 0); @@ -2987,6 +2994,160 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testUnallocatedColumnsAttributes) CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight()); } +CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testAutoSum) +{ + createScDoc("autosum.ods"); + ScDocument* pDoc = getScDoc(); + + //Sum on range and Sum on Sum's + goToCell("B10"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(ScAddress(1, 9, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B8:B9)"), pDoc->GetFormula(1, 9, 0)); + + goToCell("B13"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(ScAddress(1, 12, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B11:B12)"), pDoc->GetFormula(1, 12, 0)); + + goToCell("B14"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(4.0, pDoc->GetValue(ScAddress(1, 13, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B13:B13,B10:B10)"), pDoc->GetFormula(1, 13, 0)); + + goToCell("F8:F14"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(4.0, pDoc->GetValue(ScAddress(5, 13, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(F13:F13,F10:F10)"), pDoc->GetFormula(5, 13, 0)); + + //Sum on Row and Column + goToCell("E25"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(4, 24, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(E22:E24)"), pDoc->GetFormula(4, 24, 0)); + + goToCell("E26"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(4, 25, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B26:D26)"), pDoc->GetFormula(4, 25, 0)); + + goToCell("E27"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(4, 26, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B27:D27)"), pDoc->GetFormula(4, 26, 0)); + + goToCell("E28"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(3.0, pDoc->GetValue(ScAddress(4, 27, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B28:D28)"), pDoc->GetFormula(4, 27, 0)); + + goToCell("E29"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(9.0, pDoc->GetValue(ScAddress(4, 28, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(E26:E28)"), pDoc->GetFormula(4, 28, 0)); + + goToCell("E30"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(12.0, pDoc->GetValue(ScAddress(4, 29, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(E29:E29,E25:E25)"), pDoc->GetFormula(4, 29, 0)); + + //Subtotals on Autosum + goToCell("C49"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(20.0, pDoc->GetValue(ScAddress(2, 48, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUBTOTAL(9,C38:C48)"), pDoc->GetFormula(2, 48, 0)); + + //Autosum on column with selected empty cell for result + goToCell("B59:B64"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(1, 63, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B59:B63)"), pDoc->GetFormula(1, 63, 0)); + + //Autosum on rows with selected empty cell for result + goToCell("B76:E80"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(30.0, pDoc->GetValue(ScAddress(4, 75, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B76:D76)"), pDoc->GetFormula(4, 75, 0)); + CPPUNIT_ASSERT_EQUAL(60.0, pDoc->GetValue(ScAddress(4, 76, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B77:D77)"), pDoc->GetFormula(4, 76, 0)); + CPPUNIT_ASSERT_EQUAL(90.0, pDoc->GetValue(ScAddress(4, 77, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B78:D78)"), pDoc->GetFormula(4, 77, 0)); + CPPUNIT_ASSERT_EQUAL(120.0, pDoc->GetValue(ScAddress(4, 78, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B79:D79)"), pDoc->GetFormula(4, 78, 0)); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(4, 79, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B80:D80)"), pDoc->GetFormula(4, 79, 0)); + + //Subtotal on column with selected empty cell for result + goToCell("C92:C101"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(19.0, pDoc->GetValue(ScAddress(2, 100, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUBTOTAL(9,C92:C100)"), pDoc->GetFormula(2, 100, 0)); + + //Autosum on column without selected empty cell for result + goToCell("B109:B113"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(1, 113, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B109:B113)"), pDoc->GetFormula(1, 113, 0)); + + //Subtotal on column without selected empty cell for result + goToCell("C142:C149"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(19.0, pDoc->GetValue(ScAddress(2, 150, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUBTOTAL(9,C142:C149)"), pDoc->GetFormula(2, 150, 0)); + + //Autosum on multiselected columns without selected empty cell for result + goToCell("B160:D164"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(1, 164, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B160:B164)"), pDoc->GetFormula(1, 164, 0)); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(2, 164, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C160:C164)"), pDoc->GetFormula(2, 164, 0)); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(3, 164, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(D160:D164)"), pDoc->GetFormula(3, 164, 0)); + + //Autosum on columns with formula results without selected empty cell for result + goToCell("B173:D177"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(2.54, std::floor(pDoc->GetValue(ScAddress(1, 177, 0)) * 100.0) / 100.0); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B173:B177)"), pDoc->GetFormula(1, 177, 0)); + CPPUNIT_ASSERT_EQUAL(-4.91, std::floor(pDoc->GetValue(ScAddress(2, 177, 0)) * 100.0) / 100.0); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C173:C177)"), pDoc->GetFormula(2, 177, 0)); + CPPUNIT_ASSERT_EQUAL(5500.0, pDoc->GetValue(ScAddress(3, 177, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(D173:D177)"), pDoc->GetFormula(3, 177, 0)); + + //Autosum on column with filled cell under selected area + goToCell("B186:D190"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(1, 191, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B186:B190)"), pDoc->GetFormula(1, 191, 0)); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(2, 191, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C186:C190)"), pDoc->GetFormula(2, 191, 0)); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(3, 191, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(D186:D190)"), pDoc->GetFormula(3, 191, 0)); + + //Autosum on column and rows with empty cells selected for row and column + goToCell("B203:E208"); + executeAutoSum(); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(1, 207, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B203:B207)"), pDoc->GetFormula(1, 207, 0)); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(2, 207, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C203:C207)"), pDoc->GetFormula(2, 207, 0)); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(3, 207, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(D203:D207)"), pDoc->GetFormula(3, 207, 0)); + CPPUNIT_ASSERT_EQUAL(450.0, pDoc->GetValue(ScAddress(4, 207, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B208:D208)"), pDoc->GetFormula(4, 207, 0)); + CPPUNIT_ASSERT_EQUAL(30.0, pDoc->GetValue(ScAddress(4, 202, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B203:D203)"), pDoc->GetFormula(4, 202, 0)); + CPPUNIT_ASSERT_EQUAL(60.0, pDoc->GetValue(ScAddress(4, 203, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B204:D204)"), pDoc->GetFormula(4, 203, 0)); + CPPUNIT_ASSERT_EQUAL(90.0, pDoc->GetValue(ScAddress(4, 204, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B205:D205)"), pDoc->GetFormula(4, 204, 0)); + CPPUNIT_ASSERT_EQUAL(120.0, pDoc->GetValue(ScAddress(4, 205, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B206:D206)"), pDoc->GetFormula(4, 205, 0)); + CPPUNIT_ASSERT_EQUAL(150.0, pDoc->GetValue(ScAddress(4, 206, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("=SUM(B207:D207)"), pDoc->GetFormula(4, 206, 0)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */