diff options
Diffstat (limited to 'vendor/bandit/bandit/assertion_frameworks/snowhouse/example/stringize_tests.cpp')
-rw-r--r-- | vendor/bandit/bandit/assertion_frameworks/snowhouse/example/stringize_tests.cpp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/stringize_tests.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/stringize_tests.cpp new file mode 100644 index 00000000..a0971274 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/stringize_tests.cpp @@ -0,0 +1,111 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +namespace +{ + // No overload for operator<<(std::ostream&) or specialization of igloo::Stringizer + struct WithoutStreamOperator + { + WithoutStreamOperator(int id) + : m_id(id) + { + } + + bool operator==(const WithoutStreamOperator& rhs) const + { + return m_id == rhs.m_id; + } + + int m_id; + }; + + // Has operator<<(std::ostream&) + struct WithStreamOperator : public WithoutStreamOperator + { + WithStreamOperator(int id) + : WithoutStreamOperator(id) + { + } + }; + + std::ostream& operator<<(std::ostream& stream, const WithStreamOperator& a) + { + stream << a.m_id; + return stream; + } + + // Has no operator<<(std::ostream&), but a specialization of igloo::Stringizer + struct WithoutStreamOperatorButWithStringizer : public WithoutStreamOperator + { + WithoutStreamOperatorButWithStringizer(int id) + : WithoutStreamOperator(id) + { + } + }; +} + +namespace snowhouse { + + template<> + struct Stringizer< WithoutStreamOperatorButWithStringizer > + { + static std::string ToString(const WithoutStreamOperatorButWithStringizer& value) + { + return snowhouse::Stringize(value.m_id); + } + }; +} + +void StringizeTests() +{ + std::cout << "================================================" << std::endl; + std::cout << " StringizeTests" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleTypesWithStreamOperators" << std::endl; + { + WithStreamOperator a(12); + WithStreamOperator b(13); + AssertTestFails(Assert::That(a, Is().EqualTo(b)), "Expected: equal to 13\nActual: 12"); + } + + std::cout << "ShouldHandleTypesWithoutStreamOperators" << std::endl; + { + WithoutStreamOperator a(12); + WithoutStreamOperator b(13); + AssertTestFails(Assert::That(a, Is().EqualTo(b)), "Expected: equal to [unsupported type]\nActual: [unsupported type]"); + } + + std::cout << "ShouldHandleTypesWithTraits" << std::endl; + { + WithoutStreamOperatorButWithStringizer a(12); + WithoutStreamOperatorButWithStringizer b(13); + AssertTestFails(Assert::That(a, Is().EqualTo(b)), "Expected: equal to 13\nActual: 12"); + } + + std::cout << "================================================" << std::endl; + std::cout << " StringizeTestsExpressionTemplates" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleTypesWithStreamOperators" << std::endl; + { + WithStreamOperator a(12); + WithStreamOperator b(13); + AssertTestFails(Assert::That(a, Equals(b)), "Expected: equal to 13\nActual: 12"); + } + + std::cout << "ShouldHandleTypesWithoutStreamOperators" << std::endl; + { + WithoutStreamOperator a(12); + WithoutStreamOperator b(13); + AssertTestFails(Assert::That(a, Equals(b)), "Expected: equal to [unsupported type]\nActual: [unsupported type]"); + } + + std::cout << "ShouldHandleTypesWithTraits" << std::endl; + { + WithoutStreamOperatorButWithStringizer a(12); + WithoutStreamOperatorButWithStringizer b(13); + AssertTestFails(Assert::That(a, Is().EqualTo(b)), "Expected: equal to 13\nActual: 12"); + } +} |