tdf#122232: move UItest to CppunitTest

Change-Id: I6cb9019fea4b1be5af94dcc8811a4f96fc1b6d37
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90238
Tested-by: Jenkins
Reviewed-by: Xisco FaulĂ­ <xiscofauli@libreoffice.org>
diff --git a/sc/CppunitTest_sc_uicalc.mk b/sc/CppunitTest_sc_uicalc.mk
new file mode 100644
index 0000000..842b8b5
--- /dev/null
+++ b/sc/CppunitTest_sc_uicalc.mk
@@ -0,0 +1,45 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# 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/.
#

$(eval $(call gb_CppunitTest_CppunitTest,sc_uicalc))

$(eval $(call gb_CppunitTest_use_external,sc_uicalc,boost_headers))

$(eval $(call gb_CppunitTest_add_exception_objects,sc_uicalc, \
    sc/qa/unit/uicalc/uicalc \
))

$(eval $(call gb_CppunitTest_use_libraries,sc_uicalc, \
    comphelper \
    cppu \
    cppuhelper \
    sal \
    sc \
    test \
    tl \
    unotest \
    vcl \
))

$(eval $(call gb_CppunitTest_set_include,sc_uicalc,\
    -I$(SRCDIR)/sc/source/ui/inc \
    -I$(SRCDIR)/sc/inc \
    $$(INCLUDE) \
))

$(eval $(call gb_CppunitTest_use_sdk_api,sc_uicalc))

$(eval $(call gb_CppunitTest_use_ure,sc_uicalc))
$(eval $(call gb_CppunitTest_use_vcl,sc_uicalc))

$(eval $(call gb_CppunitTest_use_rdb,sc_uicalc,services))

$(eval $(call gb_CppunitTest_use_configuration,sc_uicalc))

# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index a56b9d4..8438b34 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -210,6 +210,9 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\
	CppunitTest_sc_uniquecellformatsenumeration \
	CppunitTest_sc_uniquecellformatsobj \
	CppunitTest_sc_viewpaneobj \
    $(if $(filter-out MACOSX,$(OS)), \
        CppunitTest_sc_uicalc \
    ) \
))

$(eval $(call gb_Module_add_perfcheck_targets,sc,\
diff --git a/sc/qa/uitest/calc_tests9/tdf122232.py b/sc/qa/uitest/calc_tests9/tdf122232.py
deleted file mode 100644
index 16cce02..0000000
--- a/sc/qa/uitest/calc_tests9/tdf122232.py
+++ /dev/null
@@ -1,49 +0,0 @@
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# 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/.
#
from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict
from uitest.path import get_srcdir_url
from libreoffice.calc.document import get_sheet_from_doc
from libreoffice.calc.conditional_format import get_conditional_format_from_sheet
from uitest.debug import sleep
from libreoffice.calc.document import get_cell_by_position
from libreoffice.uno.propertyvalue import mkPropertyValues
import org.libreoffice.unotest
import pathlib

def get_url_for_data_file(file_name):
    return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()

#Bug 122232 - UI: Pressing Enter in a protected sheet doesn't jump to next row in every case

class tdf122232(UITestCase):

    def test_tdf122232_press_Enter_key_jump(self):
        calc_doc = self.ui_test.load_file(get_url_for_data_file("tdf122232.ods"))
        xCalcDoc = self.xUITest.getTopFocusWindow()
        gridwin = xCalcDoc.getChild("grid_window")
        document = self.ui_test.get_component()
        #Start with from C6. Press tabulator to reach G6.
        gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C6"}))
        gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RIGHT"}))
        gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "LEFT"}))

        gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
        gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
        #Press "Enter".
        gridWinState = get_state_as_dict(gridwin)
        self.assertEqual(gridWinState["CurrentRow"], "5")
        self.assertEqual(gridWinState["CurrentColumn"], "6")
        gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
        #Cursor jumps to C29 instead of C7.
        gridWinState = get_state_as_dict(gridwin)
        self.assertEqual(gridWinState["CurrentRow"], "6")
        self.assertEqual(gridWinState["CurrentColumn"], "2")

        self.ui_test.close_doc()

# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/qa/uitest/calc_tests/data/tdf122232.ods b/sc/qa/unit/uicalc/data/tdf122232.ods
similarity index 100%
rename from sc/qa/uitest/calc_tests/data/tdf122232.ods
rename to sc/qa/unit/uicalc/data/tdf122232.ods
Binary files differ
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
new file mode 100644
index 0000000..3dfcade
--- /dev/null
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -0,0 +1,92 @@
/* -*- 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 <test/bootstrapfixture.hxx>
#include <unotest/macros_test.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <vcl/scheduler.hxx>

#include <comphelper/processfactory.hxx>
#include <com/sun/star/frame/Desktop.hpp>
#include <document.hxx>
#include <docuno.hxx>
#include <tabvwsh.hxx>

using namespace ::com::sun::star;

class ScUiCalcTest : public test::BootstrapFixture, public unotest::MacrosTest
{
public:
    virtual void setUp() override;

    virtual void tearDown() override;

    ScModelObj* createDoc(const char* pName);

private:
    uno::Reference<lang::XComponent> mxComponent;
};

void ScUiCalcTest::setUp()
{
    test::BootstrapFixture::setUp();

    mxDesktop.set(frame::Desktop::create(mxComponentContext));
}

void ScUiCalcTest::tearDown()
{
    if (mxComponent.is())
        mxComponent->dispose();

    test::BootstrapFixture::tearDown();
}

char const DATA_DIRECTORY[] = "/sc/qa/unit/uicalc/data/";

ScModelObj* ScUiCalcTest::createDoc(const char* pName)
{
    if (mxComponent.is())
        mxComponent->dispose();
    mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY)
                                      + OUString::createFromAscii(pName),
                                  "com.sun.star.sheet.SpreadsheetDocument");
    ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get());
    CPPUNIT_ASSERT(pModelObj);
    return pModelObj;
}

CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf122232)
{
    ScModelObj* pModelObj = createDoc("tdf122232.ods");
    ScDocument* pDoc = pModelObj->GetDocument();
    CPPUNIT_ASSERT(pDoc);

    //Start with from C6. Press tabulator to reach G6.
    CPPUNIT_ASSERT_EQUAL(sal_Int16(2), ScDocShell::GetViewData()->GetCurX());
    CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ScDocShell::GetViewData()->GetCurY());

    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB);
    Scheduler::ProcessEventsToIdle();

    CPPUNIT_ASSERT_EQUAL(sal_Int16(6), ScDocShell::GetViewData()->GetCurX());
    CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ScDocShell::GetViewData()->GetCurY());

    //without the fix, cursor would jump to C29 instead of C7.
    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
    Scheduler::ProcessEventsToIdle();

    CPPUNIT_ASSERT_EQUAL(sal_Int16(2), ScDocShell::GetViewData()->GetCurX());
    CPPUNIT_ASSERT_EQUAL(sal_Int32(6), ScDocShell::GetViewData()->GetCurY());
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */