Bug 122169 - Simpler cppunit tests, use CPPUNIT_TEST_FIXTURE
Summary: Simpler cppunit tests, use CPPUNIT_TEST_FIXTURE
Status: RESOLVED WONTFIX
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks:
 
Reported: 2018-12-18 10:58 UTC by Miklos Vajna
Modified: 2019-04-01 07:24 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Miklos Vajna 2018-12-18 10:58:56 UTC
<https://cgit.freedesktop.org/libreoffice/cppunit/commit/?id=48145587c4c2dc4f1e07d83073e136336c81ce79>
adds a macro in cppunit that allows not spelling out the declaration /
definition / registration of a testcase in a testsuite, but you can just
do all of this with a single line of code. If you used googletest in
other projects, this is probably familiar to you.

This is just a macro, so it's easy to "bundle" it in core.git (for both
the system and bundled cppunit case), so we can unconditionally use it
right now.  An example conversion looks like this:

https://cgit.freedesktop.org/libreoffice/core/commit/?id=caec23449a21c0eacbb593330a5b22f8c60d58e8

Hopefully it's obvious how this avoids repetition, also makes it
impossible to get the wrapping ifdefs wrong around the
declaration/definition/registration in case such a condition is
necessary.

Declaring what exact testcase you want to run is still possible by
setting CPPUNIT_TEST_NAME to "testFoo" from
CPPUNIT_TEST_FIXTURE(FooTest, testFoo).

It would be good to use this markup in our cppunit tests, if you just grep for CPPUNIT_TEST_SUITE, you'll see the places that could be converted over to CPPUNIT_TEST_FIXTURE.

One test suite conversion / commit, please.
Comment 1 Andrés Maldonado 2019-03-29 16:14:50 UTC
Hello, 

I looked at this EasyHack and made a patch at https://gerrit.libreoffice.org/#/c/69914/

But the commit that adds the CPPUNIT_TEST_FIXTURE macro (https://cgit.freedesktop.org/libreoffice/cppunit/commit/?id=48145587c4c2dc4f1e07d83073e136336c81ce79) is not yet on a released version of CppUnit, so the Jenkins build fails :/

I'll try to contact the maintainer of CppUnit to see if he can release a cppunit-1.14.1 version
Comment 2 Miklos Vajna 2019-03-29 16:33:59 UTC
You need to include unotest/bootstrapfixturebase.hxx if it's not already included, that handles the missing macro for you if it's not provided by cppunit (which is indeed the case currently, unless you have system-cppunit installed from git).
Comment 3 Miklos Vajna 2019-04-01 07:24:55 UTC
See the comments at <https://gerrit.libreoffice.org/#/c/68970/> from Markus and Eike, the new style also has some issues, so doing this conversion large-scale (in code you don't touch / maintain anyway) is not as a great idea as it sounded. Closing as won't fix.