From a6855f7eab47512d866914fae9f714a60d184585 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 11 May 2012 08:03:05 +0100 Subject: [PATCH] Move expression classes into own file --- include/internal/catch_capture.hpp | 193 +--------------- include/internal/catch_expression.hpp | 208 ++++++++++++++++++ .../CatchSelfTest.xcodeproj/project.pbxproj | 2 + 3 files changed, 212 insertions(+), 191 deletions(-) create mode 100644 include/internal/catch_expression.hpp diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index 91bfa6bd..14426d01 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -8,6 +8,7 @@ #ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED +#include "catch_expression.hpp" #include "catch_resultinfo_builder.hpp" #include "catch_tostring.hpp" #include "catch_resultinfo.hpp" @@ -24,197 +25,7 @@ namespace Catch struct TestFailureException{}; struct DummyExceptionType_DontUse{}; - -template -class Expression -{ - void operator = ( const Expression& ); - -public: - /////////////////////////////////////////////////////////////////////////// - Expression - ( - ResultInfoBuilder& result, - T lhs - ) - : m_result( result ), - m_lhs( lhs ) - { - } - - /////////////////////////////////////////////////////////////////////////// - template - ResultInfoBuilder& operator == - ( - const RhsT& rhs - ) - { - return m_result.captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - template - ResultInfoBuilder& operator != - ( - const RhsT& rhs - ) - { - return m_result.captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - template - ResultInfoBuilder& operator < - ( - const RhsT& rhs - ) - { - return m_result.captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - template - ResultInfoBuilder& operator > - ( - const RhsT& rhs - ) - { - return m_result.captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - template - ResultInfoBuilder& operator <= - ( - const RhsT& rhs - ) - { - return m_result.captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - template - ResultInfoBuilder& operator >= - ( - const RhsT& rhs - ) - { - return m_result.captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - ResultInfoBuilder& operator == - ( - bool rhs - ) - { - return m_result.captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - ResultInfoBuilder& operator != - ( - bool rhs - ) - { - return m_result.captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - operator ResultInfoBuilder& - () - { - return m_result.captureBoolExpression( m_lhs ); - } - - /////////////////////////////////////////////////////////////////////////// - template - STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + - ( - const RhsT& - ); - - /////////////////////////////////////////////////////////////////////////// - template - STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - - ( - const RhsT& - ); - -private: - ResultInfoBuilder& m_result; - T m_lhs; -}; - -template -class PtrExpression -{ -public: - - /////////////////////////////////////////////////////////////////////////// - PtrExpression - ( - ResultInfoBuilder& result, - const LhsT* lhs - ) - : m_result( &result ), - m_lhs( lhs ) - {} - - /////////////////////////////////////////////////////////////////////////// - template - ResultInfoBuilder& operator == - ( - const RhsT* rhs - ) - { - return m_result->captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - // This catches NULL - ResultInfoBuilder& operator == - ( - LhsT* rhs - ) - { - return m_result->captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - template - ResultInfoBuilder& operator != - ( - const RhsT* rhs - ) - { - return m_result->captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - // This catches NULL - ResultInfoBuilder& operator != - ( - LhsT* rhs - ) - { - return m_result->captureExpression( m_lhs, rhs ); - } - - /////////////////////////////////////////////////////////////////////////// - operator ResultInfoBuilder& - () - { - return m_result->captureBoolExpression( m_lhs ); - } - - -private: - ResultInfoBuilder* m_result; - const LhsT* m_lhs; -}; - - + class ResultBuilder { public: diff --git a/include/internal/catch_expression.hpp b/include/internal/catch_expression.hpp new file mode 100644 index 00000000..d1502195 --- /dev/null +++ b/include/internal/catch_expression.hpp @@ -0,0 +1,208 @@ +/* + * Created by Phil on 11/5/2012. + * Copyright 2012 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED + +#include "catch_resultinfo_builder.hpp" +#include "catch_evaluate.hpp" + +namespace Catch +{ + +template +class Expression +{ + void operator = ( const Expression& ); + +public: + /////////////////////////////////////////////////////////////////////////// + Expression + ( + ResultInfoBuilder& result, + T lhs + ) + : m_result( result ), + m_lhs( lhs ) + { + } + + /////////////////////////////////////////////////////////////////////////// + template + ResultInfoBuilder& operator == + ( + const RhsT& rhs + ) + { + return m_result.captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + template + ResultInfoBuilder& operator != + ( + const RhsT& rhs + ) + { + return m_result.captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + template + ResultInfoBuilder& operator < + ( + const RhsT& rhs + ) + { + return m_result.captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + template + ResultInfoBuilder& operator > + ( + const RhsT& rhs + ) + { + return m_result.captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + template + ResultInfoBuilder& operator <= + ( + const RhsT& rhs + ) + { + return m_result.captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + template + ResultInfoBuilder& operator >= + ( + const RhsT& rhs + ) + { + return m_result.captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + ResultInfoBuilder& operator == + ( + bool rhs + ) + { + return m_result.captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + ResultInfoBuilder& operator != + ( + bool rhs + ) + { + return m_result.captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + operator ResultInfoBuilder& + () + { + return m_result.captureBoolExpression( m_lhs ); + } + + /////////////////////////////////////////////////////////////////////////// + template + STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + + ( + const RhsT& + ); + + /////////////////////////////////////////////////////////////////////////// + template + STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - + ( + const RhsT& + ); + +private: + ResultInfoBuilder& m_result; + T m_lhs; +}; + +template +class PtrExpression +{ +public: + + /////////////////////////////////////////////////////////////////////////// + PtrExpression + ( + ResultInfoBuilder& result, + const LhsT* lhs + ) + : m_result( &result ), + m_lhs( lhs ) + {} + + /////////////////////////////////////////////////////////////////////////// + template + ResultInfoBuilder& operator == + ( + const RhsT* rhs + ) + { + return m_result->captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + // This catches NULL + ResultInfoBuilder& operator == + ( + LhsT* rhs + ) + { + return m_result->captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + template + ResultInfoBuilder& operator != + ( + const RhsT* rhs + ) + { + return m_result->captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + // This catches NULL + ResultInfoBuilder& operator != + ( + LhsT* rhs + ) + { + return m_result->captureExpression( m_lhs, rhs ); + } + + /////////////////////////////////////////////////////////////////////////// + operator ResultInfoBuilder& + () + { + return m_result->captureBoolExpression( m_lhs ); + } + + +private: + ResultInfoBuilder* m_result; + const LhsT* m_lhs; +}; + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index 0ae06273..db8a0a84 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -92,6 +92,7 @@ 4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_ptr.hpp; sourceTree = ""; }; 4AB77CB71553B72B00857BF0 /* catch_section_info.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_section_info.hpp; sourceTree = ""; }; 4AB77CB81553BB3800857BF0 /* catch_running_test.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_running_test.hpp; sourceTree = ""; }; + 4AC91CCE155CF02800DC5117 /* catch_expression.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_expression.hpp; sourceTree = ""; }; 4AE1840A14EE4F230066340D /* catch_self_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_self_test.cpp; path = ../../../SelfTest/catch_self_test.cpp; sourceTree = ""; }; /* End PBXFileReference section */ @@ -214,6 +215,7 @@ 4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */, 4A6D0C46149B3E3D00DB3EAA /* catch_approx.hpp */, 4A6D0C47149B3E3D00DB3EAA /* catch_capture.hpp */, + 4AC91CCE155CF02800DC5117 /* catch_expression.hpp */, ); name = Assertions; sourceTree = "";