catch_common.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Created by Phil on 29/10/2010.
  3. * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
  9. #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
  10. #include "catch_compiler_capabilities.h"
  11. #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
  12. #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
  13. #ifdef CATCH_CONFIG_COUNTER
  14. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
  15. #else
  16. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
  17. #endif
  18. #include <iosfwd>
  19. #include <string>
  20. #include <cstdint>
  21. // We need a dummy global operator<< so we can bring it into Catch namespace later
  22. struct Catch_global_namespace_dummy {};
  23. std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
  24. namespace Catch {
  25. struct CaseSensitive { enum Choice {
  26. Yes,
  27. No
  28. }; };
  29. class NonCopyable {
  30. NonCopyable( NonCopyable const& ) = delete;
  31. NonCopyable( NonCopyable && ) = delete;
  32. NonCopyable& operator = ( NonCopyable const& ) = delete;
  33. NonCopyable& operator = ( NonCopyable && ) = delete;
  34. protected:
  35. NonCopyable();
  36. virtual ~NonCopyable();
  37. };
  38. struct SourceLineInfo {
  39. SourceLineInfo() = delete;
  40. SourceLineInfo( char const* _file, std::size_t _line ) noexcept
  41. : file( _file ),
  42. line( _line )
  43. {}
  44. SourceLineInfo( SourceLineInfo const& other ) = default;
  45. SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
  46. SourceLineInfo( SourceLineInfo&& ) noexcept = default;
  47. SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default;
  48. bool empty() const noexcept { return file[0] == '\0'; }
  49. bool operator == ( SourceLineInfo const& other ) const noexcept;
  50. bool operator < ( SourceLineInfo const& other ) const noexcept;
  51. char const* file;
  52. std::size_t line;
  53. };
  54. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
  55. // Bring in operator<< from global namespace into Catch namespace
  56. // This is necessary because the overload of operator<< above makes
  57. // lookup stop at namespace Catch
  58. using ::operator<<;
  59. // Use this in variadic streaming macros to allow
  60. // >> +StreamEndStop
  61. // as well as
  62. // >> stuff +StreamEndStop
  63. struct StreamEndStop {
  64. std::string operator+() const;
  65. };
  66. template<typename T>
  67. T const& operator + ( T const& value, StreamEndStop ) {
  68. return value;
  69. }
  70. }
  71. #define CATCH_INTERNAL_LINEINFO \
  72. ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
  73. #endif // TWOBLUECUBES_CATCH_COMMON_H_INCLUDED