[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:

I completed my first conversion and thought it might be useful to write 
about my experience. The conversion commit is here:

I started by temporarily undoing the fix for the bug so the crash would 
reappear and the test would fail: 

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/
rm -rf /tmp/libreoffice/4
python "$SRCDIR"/uitest/test_main.py --debug 

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 

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


More information about the Libreoffice-qa mailing list