summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cppunit/Message.h6
-rw-r--r--include/cppunit/SourceLine.h5
-rw-r--r--src/cppunit/Message.cpp21
-rw-r--r--src/cppunit/SourceLine.cpp25
4 files changed, 53 insertions, 4 deletions
diff --git a/include/cppunit/Message.h b/include/cppunit/Message.h
index 9b12431..1ae51cc 100644
--- a/include/cppunit/Message.h
+++ b/include/cppunit/Message.h
@@ -40,6 +40,9 @@ class CPPUNIT_API Message
public:
Message();
+ // Ensure thread-safe copy by detaching the string.
+ Message( const Message &other );
+
explicit Message( const std::string &shortDescription );
Message( const std::string &shortDescription,
@@ -54,6 +57,8 @@ public:
const std::string &detail2,
const std::string &detail3 );
+ Message &operator =( const Message &other );
+
/*! \brief Returns the short description.
* \return Short description.
*/
@@ -127,7 +132,6 @@ public:
*/
bool operator ==( const Message &other ) const;
-
/*! \brief Tests if a message is different from another one.
* \param other Message this message is compared to.
* \return \c true if the two message are not identical, \c false otherwise.
diff --git a/include/cppunit/SourceLine.h b/include/cppunit/SourceLine.h
index 71eeaed..f7a85df 100644
--- a/include/cppunit/SourceLine.h
+++ b/include/cppunit/SourceLine.h
@@ -32,9 +32,14 @@ class CPPUNIT_API SourceLine
public:
SourceLine();
+ // Ensure thread-safe copy by detaching the string buffer.
+ SourceLine( const SourceLine &other );
+
SourceLine( const std::string &fileName,
int lineNumber );
+ SourceLine &operator =( const SourceLine &other );
+
/// Destructor.
virtual ~SourceLine();
diff --git a/src/cppunit/Message.cpp b/src/cppunit/Message.cpp
index 85f235e..9d6a0e9 100644
--- a/src/cppunit/Message.cpp
+++ b/src/cppunit/Message.cpp
@@ -9,6 +9,11 @@ Message::Message()
{
}
+Message::Message( const Message &other )
+{
+ *this = other;
+}
+
Message::Message( const std::string &shortDescription )
: m_shortDescription( shortDescription )
@@ -42,6 +47,22 @@ Message::Message( const std::string &shortDescription,
addDetail( detail1, detail2, detail3 );
}
+Message &
+Message::operator =( const Message &other )
+{
+ if ( this != &other )
+ {
+ m_shortDescription = other.m_shortDescription.c_str();
+ m_details.clear();
+ Details::const_iterator it = other.m_details.begin();
+ Details::const_iterator itEnd = other.m_details.end();
+ while ( it != itEnd )
+ m_details.push_back( (*it++).c_str() );
+ }
+
+ return *this;
+}
+
const std::string &
Message::shortDescription() const
diff --git a/src/cppunit/SourceLine.cpp b/src/cppunit/SourceLine.cpp
index bd70709..dfadae3 100644
--- a/src/cppunit/SourceLine.cpp
+++ b/src/cppunit/SourceLine.cpp
@@ -10,11 +10,30 @@ SourceLine::SourceLine() :
}
+SourceLine::SourceLine( const SourceLine &other )
+ : m_fileName( other.m_fileName.c_str() )
+ , m_lineNumber( other.m_lineNumber )
+{
+}
+
+
SourceLine::SourceLine( const std::string &fileName,
- int lineNumber ) :
- m_fileName( fileName ),
- m_lineNumber( lineNumber )
+ int lineNumber )
+ : m_fileName( fileName.c_str() )
+ , m_lineNumber( lineNumber )
+{
+}
+
+
+SourceLine &
+SourceLine::operator =( const SourceLine &other )
{
+ if ( this != &other )
+ {
+ m_fileName = other.m_fileName.c_str();
+ m_lineNumber = other.m_lineNumber;
+ }
+ return *this;
}