// (C) 2015 Simon Warta (Kullo GmbH) // Botan is released under the Simplified BSD License (see license.txt) #ifndef BOTAN_CATCHY_TESTS_H__ #define BOTAN_CATCHY_TESTS_H__ #include "catch.hpp" #include // BEGIN CATCH STD::VECTOR IMPLEMENTATION // This is basically https://github.com/philsquared/Catch/pull/466 #include #include namespace Catch { namespace Matchers { namespace Impl { namespace Generic { template struct Not : public MatcherImpl, ExpressionT> { Not( Matcher const& matcher ) : m_matcher(matcher.clone()) {} Not( Not const& other ) : m_matcher( other.m_matcher ) {} virtual bool match( ExpressionT const& expr ) const { return !m_matcher->match( expr ); } virtual std::string toString() const { return "not " + m_matcher->toString(); } Ptr> m_matcher; }; } // namespace Generic namespace StdVector { template struct Equals : MatcherImpl, std::vector > { Equals( std::vector const& vec ) : m_vector( vec ){} Equals( Equals const& other ) : m_vector( other.m_vector ){} virtual ~Equals() {} virtual bool match( std::vector const& expr ) const { return m_vector == expr; } virtual std::string toString() const { return "equals: std::vector of length " + Catch::toString(m_vector.size()); } std::vector m_vector; }; } // namespace StdVector namespace Boolean { struct Equals : MatcherImpl { Equals( const bool expected ) : m_expected( expected ){} Equals( Equals const& other ) : m_expected( other.m_expected ){} virtual ~Equals() override {} virtual bool match( bool const& expr ) const { return m_expected == expr; } virtual std::string toString() const { return "== " + Catch::toString(m_expected); } bool m_expected; }; } // Boolean namespace Integer { template struct Equals : MatcherImpl, T> { Equals( const T expected ) : m_expected( expected ){} Equals( Equals const& other ) : m_expected( other.m_expected ){} virtual ~Equals() override {} virtual bool match( T const& expr ) const { return m_expected == expr; } virtual std::string toString() const { return "== " + Catch::toString(m_expected); } T m_expected; }; } // namespace Integer } // namespace Impl // The following functions create the actual matcher objects. // This allows the types to be inferred template inline Impl::Generic::Not Not( Impl::Matcher const& m ) { return Impl::Generic::Not( m ); } template inline Impl::StdVector::Equals Equals( std::vector const& vec ) { return Impl::StdVector::Equals( vec ); } template ::is_integer, T>::type> inline Impl::Integer::Equals Equals( T expected ) { return Impl::Integer::Equals( expected ); } inline Impl::Boolean::Equals Equals( bool expected ) { return Impl::Boolean::Equals( expected ); } } // namespace Matchers } // namespace Catch // END CATCH STD::VECTOR IMPLEMENTATION #endif // BOTAN_CATCHY_TESTS_H__