diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-05-26 12:05:06 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2019-02-14 22:33:13 +0800 |
commit | 1caa3a0c66f009fe1a386d7559dc25054dad42a3 (patch) | |
tree | 6b778a26c9603cc7e753b485a986dc17374994e3 /examples/cppunittest/MessageTest.cpp | |
parent | 3788fccdd12ea1e3240d79e85d9146f6c264c6ec (diff) | |
download | cppunit-1caa3a0c66f009fe1a386d7559dc25054dad42a3.tar.gz |
custom tostring formatter to CPPUNIT_ASSERT_MESSAGE
Provide an extension trait message_to_string that allows client code
to call ASSERT_MESSAGE with their own string types.
Also provide a default extension trait that accepts std::ostream
messages.
Change-Id: I516f97063c34d86bc91c40e0ec147d5393e7b6ea
Diffstat (limited to 'examples/cppunittest/MessageTest.cpp')
-rw-r--r-- | examples/cppunittest/MessageTest.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/cppunittest/MessageTest.cpp b/examples/cppunittest/MessageTest.cpp index c59544d..c0674b8 100644 --- a/examples/cppunittest/MessageTest.cpp +++ b/examples/cppunittest/MessageTest.cpp @@ -232,3 +232,30 @@ MessageTest::testNotEqual() CPPUNIT_ASSERT( message1 != message2 ); CPPUNIT_ASSERT( !(message1 != message1) ); } + + +struct Foo +{ + std::string s; +}; +CPPUNIT_NS_BEGIN +static std::string message_to_string(const Foo& m) +{ + return m.s; +} +CPPUNIT_NS_END + +void +MessageTest::testCustomMessageType() +{ + Foo foo { "xxxx" }; + CPPUNIT_ASSERT_MESSAGE( foo, true ); +} + +void +MessageTest::testOStreamMessage() +{ + std::ostringstream ost; + ost << "xxx" << "yyy"; + CPPUNIT_ASSERT_MESSAGE( ost, true ); +} |