[Libreoffice-qa] Converting a Python UI test into a cppunit test
Ilmari Lauhakangas
ilmari.lauhakangas at libreoffice.org
Thu Jul 16 16:55:21 UTC 2020
We have a list of Python UI tests that should be reimplemented as
cppunit tests:
https://wiki.documentfoundation.org/UiTestsToCppUnittests
I completed my first conversion and thought it might be useful to write
about my experience. The conversion commit is here:
https://git.libreoffice.org/core/commit/72186f02c118e9f5602e15c2bac9b3ac19987f93
I started by temporarily undoing the fix for the bug so the crash would
reappear and the test would fail:
https://git.libreoffice.org/core/commit/9ec2c77046901fdacca77753052b54c81e6bc82c
sw/source/core/text/txtfrm.cxx:
assert(nLen != TextFrameIndex(COMPLETE_STRING));
if (rFrame.IsFollow() && nPos < rFrame.GetOffset())
{
rFrame.ManipOfst( std::max(TextFrameIndex(0),
op(rFrame.GetOffset(), nLen)) );
}
I created execute.sh for running the Python UI test:
export PYTHONPATH=/home/tonttu/libreoffice/instdir/program/
export
URE_BOOTSTRAP=file:///home/tonttu/libreoffice/instdir/program/fundamentalrc
export SAL_USE_VCLPLUGIN=gen
rm -rf /tmp/libreoffice/4
SRCDIR="${SRCDIR:-$(pwd)}"
python "$SRCDIR"/uitest/test_main.py --debug
--soffice=path:"$SRCDIR"/instdir/program/soffice
--userdir=file:///tmp/libreoffice/4
--file="$SRCDIR"/sw/qa/uitest/writer_tests7/tdf127652.py
I ran execute.sh while in the core directory and confirmed that the UI
test failed.
I copied the test document from sw/qa/uitest/writer_tests7/data to
sw/qa/extras/uiwriter/data3
I started creating the cppunit test in sw/qa/extras/uiwriter/uiwriter3.cxx
Command for running the cppunit test:
CPPUNIT_TEST_NAME="testTdf127652" make CppunitTest_sw_uiwriter
I had no idea how to convert the Python methods for moving the cursor,
deleting and checking the current page. For figuring things out, I had
to do web searches against https://docs.libreoffice.org/ and to grep the
code in sw as well as the existing Writer cppunit tests found in sw/qa
For example, hoping for the best I tried grepping 'current page' in sw/,
found useful stuff and continued in a similar manner.
For searching I used ripgrep, but you can use whatever you feel
comfortable with (like git grep).
Examples with ripgrep, ran in the core directory:
rg --pretty 'DelRight' sw/qa --glob '*.cxx' | less -RK
rg --pretty --ignore-case 'jumpto' sw/qa --glob '*.cxx' | less -RK
Clang-format was not happy with the old skool indentation, so it was
fixed with:
clang-format -i sw/qa/extras/uiwriter/uiwriter3.cxx
Ilmari
More information about the Libreoffice-qa
mailing list