summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-10-12 21:34:07 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2018-11-02 06:03:13 +0100
commit48145587c4c2dc4f1e07d83073e136336c81ce79 (patch)
tree079de5e81b2f62edc0a770b9815c865d775f53d3
parent4f5cd3b486afb9c7be1903252b4ae3787137a454 (diff)
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.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r--examples/simple/ExampleTestCase.cpp15
-rw-r--r--include/cppunit/extensions/HelperMacros.h23
2 files changed, 38 insertions, 0 deletions
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).
*