examples/simple/ExampleTestCase.cpp | 15 +++++++++++++++ include/cppunit/extensions/HelperMacros.h | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+)
New commits: commit 48145587c4c2dc4f1e07d83073e136336c81ce79 Author: Miklos Vajna <vmik...@collabora.co.uk> AuthorDate: Fri Oct 12 21:34:07 2018 +0200 Commit: Markus Mohrhard <markus.mohrh...@googlemail.com> CommitDate: Fri Nov 2 06:03:13 2018 +0100 extensions: add CPPUNIT_TEST_FIXTURE() This is similar to googletest's TEST_F() macro, allows to avoid spelling out the test name in a suite only once, not 3 times. Change-Id: I90804d271d046d8158678617d8db75ed6ca7c420 Reviewed-on: https://gerrit.libreoffice.org/61732 Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrh...@googlemail.com> diff --git a/examples/simple/ExampleTestCase.cpp b/examples/simple/ExampleTestCase.cpp index c45109f..823a8df 100644 --- a/examples/simple/ExampleTestCase.cpp +++ b/examples/simple/ExampleTestCase.cpp @@ -45,3 +45,18 @@ void ExampleTestCase::testEquals() CPPUNIT_ASSERT_EQUAL( 12, 13 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 12.0, 11.99, 0.5 ); } + +class FixtureTest : public CPPUNIT_NS::TestFixture +{ +}; + +CPPUNIT_TEST_FIXTURE(FixtureTest, testEquals) +{ + CPPUNIT_ASSERT_EQUAL( 12, 12 ); +} + +CPPUNIT_TEST_FIXTURE(FixtureTest, testAdd) +{ + double result = 2.0 + 2.0; + CPPUNIT_ASSERT( result == 4.0 ); +} diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h index 4c30319..34be2ca 100644 --- a/include/cppunit/extensions/HelperMacros.h +++ b/include/cppunit/extensions/HelperMacros.h @@ -240,6 +240,29 @@ public: \ private: /* dummy typedef so that the macro can still end with ';'*/ \ typedef int CppUnitDummyTypedefForSemiColonEnding__ +/*! \brief Define test suite with a single test. + * + * This macro declares a new test suite with a single test and a single parent + * class. Use CPPUNIT_TEST_SUITE(), CPPUNIT_TEST() and + * CPPUNIT_TEST_SUITE_END() instead if you wish to include more tests in the + * suite. The benefit of using this macro is that you don't have to declare, + * register and define your test name manually, so you don't repeat yourself. + * + * \param TestClass Base class. This type \b MUST be derived from TestFixture. + * \param TestName Name of the test. + * \see CPPUNIT_TEST_SUITE, CPPUNIT_TEST, CPPUNIT_TEST_SUITE_END + */ +#define CPPUNIT_TEST_FIXTURE(TestClass, TestName) \ + class TestName : public TestClass \ + { \ + public: \ + void TestBody(); \ + CPPUNIT_TEST_SUITE(TestName); \ + CPPUNIT_TEST(TestBody); \ + CPPUNIT_TEST_SUITE_END(); \ + }; \ + CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \ + void TestName::TestBody() /*! \brief Add a test to the suite (for custom test macro). * _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits