Update of /cvsroot/cppunit/cppunit2/src/cpput
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13378/src/cpput
Modified Files:
cpput.vcproj
Added Files:
testinfo.cpp
Log Message:
* started implementing assertion support for both checking and aborting assertion
* TestInfo to send incremental update on the test result to the test driver (logging...)
--- NEW FILE: testinfo.cpp ---
#include <cpput/testinfo.h>
namespace {
struct CompactLocation
{
CompactLocation( const char *file = 0,
const char *function = 0,
unsigned int line =0 )
: file_( file )
, function_( function )
, line_( line )
{
}
const char *file_;
const char *function_;
unsigned int line_;
};
}
namespace CppUT {
class TestInfoData
{
public:
TestInfoData()
: assertionType_( abortingAssertion )
{
}
TestResultUpdaterPtr updater_;
OpenTest::Properties result_;
OpenTest::Properties assertion_;
AssertionType assertionType_;
CompactLocation assertionLocation_;
};
namespace TestInfo {
static TestInfoDataPtr staticData( new TestInfoData() );
static const TestInfoDataPtr &dataPtr()
{
return staticData;
}
static TestInfoData &data()
{
return *dataPtr();
}
static void setData( const TestInfoDataPtr &data )
{
staticData = data;
}
void setTestResultUpdater( const TestResultUpdaterPtr &updater )
{
data().updater_ = updater;
}
void startNewTest()
{
data().result_.clear();
}
OpenTest::PropertiesAccessor result()
{
return data().result_.accessor();
}
void newAssertion()
{
data().assertion_.clear();
data().assertionType_ = abortingAssertion;
data().assertionLocation_ = CompactLocation();
}
void setAssertionType( AssertionType type )
{
data().assertionType_ = type;
}
AssertionType assertionType()
{
return data().assertionType_;
}
void setAssertionLocation( const char *fileName,
unsigned int lineNumber,
const char *functionName )
{
data().assertionLocation_ = CompactLocation( fileName, functionName, lineNumber );
}
OpenTest::Properties ¤tAssertion()
{
return data().assertion_;
}
/// Realize the current assertion.
/// Add data about the current assertion to the test result.
/// @exception AbortingAssertionException If assertionType was set to
/// abortingAssertion.
void realizeAssertion()
{
OpenTest::Properties assertion = data().assertion_;
if ( data().assertionLocation_.file_ )
{
assertion["location"]["file"] = data().assertionLocation_.file_;
assertion["location"]["line"] = data().assertionLocation_.line_;
}
if ( data().assertionLocation_.function_ )
assertion["location"]["function"] = data().assertionLocation_.function_;
appendToResult( "assertions", assertion );
if ( data().assertionType_ == abortingAssertion )
throw AbortingAssertionException( "" );
}
void mergeInResult( const std::string &path,
const OpenTest::Value &value )
{
data().result_[path] = value;
if ( data().updater_ )
data().updater_->mergeInResult( path, value );
}
void appendToResult( const std::string &path,
const OpenTest::Value &value )
{
data().result_[path].append( value );
if ( data().updater_ )
data().updater_->appendToResult( path, value );
}
TestInfoDataPtr saveAndResetContext()
{
TestInfoDataPtr oldData = dataPtr();
setData( TestInfoDataPtr( new TestInfoData() ) );
return oldData;
}
void restoreContext( const TestInfoDataPtr &oldContext )
{
setData( oldContext );
}
} // namespace TestInfo
} // namespace CppUT
Index: cpput.vcproj
===================================================================
RCS file: /cvsroot/cppunit/cppunit2/src/cpput/cpput.vcproj,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** cpput.vcproj 17 Nov 2004 21:47:10 -0000 1.19
--- cpput.vcproj 18 Nov 2004 09:20:33 -0000 1.20
***************
*** 389,392 ****
--- 389,398 ----
</File>
<File
+ RelativePath=".\testinfo.cpp">
+ </File>
+ <File
+ RelativePath="..\..\include\cpput\testinfo.h">
+ </File>
+ <File
RelativePath="..\..\include\cpput\testlistener.h">
</File>
|