aboutsummaryrefslogtreecommitdiff
path: root/unittest/Catch/projects/SelfTest/ToStringWhich.cpp
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:53:56 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:53:56 +0100
commite9fc58cb304323f07aba736fc523903481404cff (patch)
tree59db450412ca101aa9601b3f2174436898f955c1 /unittest/Catch/projects/SelfTest/ToStringWhich.cpp
parent8150ee4edc7e32d5c27cd3e0f68c630d90865638 (diff)
parent48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391 (diff)
downloadlibnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.gz
libnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.bz2
Merge commit '48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391' as 'unittest/Catch'
Diffstat (limited to 'unittest/Catch/projects/SelfTest/ToStringWhich.cpp')
-rw-r--r--unittest/Catch/projects/SelfTest/ToStringWhich.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/unittest/Catch/projects/SelfTest/ToStringWhich.cpp b/unittest/Catch/projects/SelfTest/ToStringWhich.cpp
new file mode 100644
index 0000000..1d4aa89
--- /dev/null
+++ b/unittest/Catch/projects/SelfTest/ToStringWhich.cpp
@@ -0,0 +1,68 @@
+#include "catch.hpp"
+/*
+ Demonstrate which version of toString/StringMaker is being used
+ for various types
+*/
+
+
+struct has_toString { };
+struct has_maker {};
+struct has_maker_and_toString {};
+
+namespace Catch {
+ inline std::string toString( const has_toString& ) {
+ return "toString( has_toString )";
+ }
+ inline std::string toString( const has_maker_and_toString& ) {
+ return "toString( has_maker_and_toString )";
+ }
+ template<>
+ struct StringMaker<has_maker> {
+ static std::string convert( const has_maker& ) {
+ return "StringMaker<has_maker>";
+ }
+ };
+ template<>
+ struct StringMaker<has_maker_and_toString> {
+ static std::string convert( const has_maker_and_toString& ) {
+ return "StringMaker<has_maker_and_toString>";
+ }
+ };
+}
+
+// Call the overload
+TEST_CASE( "toString( has_toString )", "[toString]" ) {
+ has_toString item;
+ REQUIRE( Catch::toString( item ) == "toString( has_toString )" );
+}
+
+// Call the overload
+TEST_CASE( "toString( has_maker )", "[toString]" ) {
+ has_maker item;
+ REQUIRE( Catch::toString( item ) == "StringMaker<has_maker>" );
+}
+
+// Call the overload
+TEST_CASE( "toString( has_maker_and_toString )", "[toString]" ) {
+ has_maker_and_toString item;
+ REQUIRE( Catch::toString( item ) == "toString( has_maker_and_toString )" );
+}
+
+// Vectors...
+TEST_CASE( "toString( vectors<has_toString )", "[toString]" ) {
+ std::vector<has_toString> v(1);
+ // This invokes template<T> toString which actually gives us '{ ? }'
+ REQUIRE( Catch::toString( v ) == "{ {?} }" );
+}
+
+TEST_CASE( "toString( vectors<has_maker )", "[toString]" ) {
+ std::vector<has_maker> v(1);
+ REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker> }" );
+}
+
+
+TEST_CASE( "toString( vectors<has_maker_and_toString )", "[toString]" ) {
+ std::vector<has_maker_and_toString> v(1);
+ // Note: This invokes the template<T> toString -> StringMaker
+ REQUIRE( Catch::toString( v ) == "{ StringMaker<has_maker_and_toString> }" );
+}