CppunitTest_sc_uicalc: simplify code a bit

Change-Id: I65f32c3f308f7ac9a416026efaf0648ff6457ddc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134272
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Xisco Fauli 2022-05-13 11:43:08 +02:00
parent 02367bacaf
commit c63b865018

View File

@ -52,9 +52,8 @@ public:
ScModelObj* saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent,
const OUString& rFilter);
void goToCell(const OUString& rCell);
void insertString(ScModelObj& rModelObj, const std::string& rStr);
void insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, const std::string& rStr,
bool bUseReturn = true);
void typeString(ScModelObj& rModelObj, const std::string& rStr);
void insertStringToCell(ScModelObj& rModelObj, const OUString& rCell, const std::string& rStr);
void insertArrayToCell(ScModelObj& rModelObj, const OUString& rCell, const std::string& rStr);
void insertNewSheet(ScDocument& rDoc);
@ -109,7 +108,7 @@ void ScUiCalcTest::goToCell(const OUString& rCell)
dispatchCommand(mxComponent, ".uno:GoToCell", aArgs);
}
void ScUiCalcTest::insertString(ScModelObj& rModelObj, const std::string& rStr)
void ScUiCalcTest::typeString(ScModelObj& rModelObj, const std::string& rStr)
{
for (const char c : rStr)
{
@ -120,24 +119,23 @@ void ScUiCalcTest::insertString(ScModelObj& rModelObj, const std::string& rStr)
}
void ScUiCalcTest::insertStringToCell(ScModelObj& rModelObj, const OUString& rCell,
const std::string& rStr, bool bUseReturn)
const std::string& rStr)
{
goToCell(rCell);
insertString(rModelObj, rStr);
typeString(rModelObj, rStr);
if (bUseReturn)
{
rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
}
rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
}
void ScUiCalcTest::insertArrayToCell(ScModelObj& rModelObj, const OUString& rCell,
const std::string& rStr)
{
insertStringToCell(rModelObj, rCell, rStr, false);
goToCell(rCell);
typeString(rModelObj, rStr);
rModelObj.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | KEY_SHIFT | awt::Key::RETURN);
rModelObj.postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | KEY_SHIFT | awt::Key::RETURN);
@ -728,14 +726,16 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf56036)
ScDocument* pDoc = pModelObj->GetDocument();
CPPUNIT_ASSERT(pDoc);
insertStringToCell(*pModelObj, "A1", "=SUM( 1 + 2 ", /*bUseReturn*/ false);
goToCell("A1");
typeString(*pModelObj, "=SUM( 1 + 2 ");
// Insert Newline
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | awt::Key::RETURN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_MOD1 | awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
insertString(*pModelObj, "+ 3)");
typeString(*pModelObj, "+ 3)");
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
@ -755,7 +755,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119162)
ScDocument* pDoc = pModelObj->GetDocument();
CPPUNIT_ASSERT(pDoc);
insertStringToCell(*pModelObj, "A1", "Test", /*bUseReturn*/ false);
goToCell("A1");
typeString(*pModelObj, "Test");
// Insert Newline
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_MOD1 | awt::Key::RETURN);
@ -915,7 +917,9 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf138432)
dispatchCommand(mxComponent, ".uno:Copy", {});
Scheduler::ProcessEventsToIdle();
insertStringToCell(*pModelObj, "A2", "=", /*bUseReturn*/ false);
goToCell("A2");
typeString(*pModelObj, "=");
dispatchCommand(mxComponent, ".uno:Paste", {});
Scheduler::ProcessEventsToIdle();
@ -1930,7 +1934,7 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119793)
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1381), xShape->getPosition().Y);
// Type into the shape
insertString(*pModelObj, "x");
typeString(*pModelObj, "x");
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_ESCAPE);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_ESCAPE);
Scheduler::ProcessEventsToIdle();