SourceLine.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef CPPUNIT_SOURCELINE_H
  2. #define CPPUNIT_SOURCELINE_H
  3. #include <cppunit/Portability.h>
  4. #include <string>
  5. /*! \brief Constructs a SourceLine object initialized with the location where the macro is expanded.
  6. * \ingroup CreatingNewAssertions
  7. * \relates CppUnit::SourceLine
  8. * Used to write your own assertion macros.
  9. * \see Asserter for example of usage.
  10. */
  11. #define CPPUNIT_SOURCELINE() CPPUNIT_NS::SourceLine( __FILE__, __LINE__ )
  12. CPPUNIT_NS_BEGIN
  13. /*! \brief Represents a source line location.
  14. * \ingroup CreatingNewAssertions
  15. * \ingroup BrowsingCollectedTestResult
  16. *
  17. * Used to capture the failure location in assertion.
  18. *
  19. * Use the CPPUNIT_SOURCELINE() macro to construct that object. Typically used when
  20. * writing an assertion macro in association with Asserter.
  21. *
  22. * \see Asserter.
  23. */
  24. class CPPUNIT_API SourceLine
  25. {
  26. public:
  27. SourceLine();
  28. // Ensure thread-safe copy by detaching the string buffer.
  29. SourceLine( const SourceLine &other );
  30. SourceLine( const std::string &fileName,
  31. int lineNumber );
  32. SourceLine &operator =( const SourceLine &other );
  33. /// Destructor.
  34. virtual ~SourceLine();
  35. bool isValid() const;
  36. int lineNumber() const;
  37. std::string fileName() const;
  38. bool operator ==( const SourceLine &other ) const;
  39. bool operator !=( const SourceLine &other ) const;
  40. private:
  41. std::string m_fileName;
  42. int m_lineNumber;
  43. };
  44. CPPUNIT_NS_END
  45. #endif // CPPUNIT_SOURCELINE_H