 |
 |
|
Rajinder Yadav - Windows C++ Development Tools & Resources :Design, Code, Test, Deploy |
// Source: UnitTestAssembly.cpp
// Author: Rajinder Yadav
// Date: June 30, 2004
//
// Copyright (c) Rajinder Yadav 2004, 2007
//
// web: http://devmentor.org
// email: rajinder@devmentor.org
//
#include "stdafx.h"
#include "IUnitTestRunner.h"
#include "UnitTestRunner.h"
#include "UnitTestAssembly.h"
// initialize class static member
UnitTestAssembly* UnitTestAssembly::sm_UnitTestAssembly = 0;
UnitTestAssembly::UnitTestAssembly()
{
this->subject.clear();
}
// class dtor
UnitTestAssembly::~UnitTestAssembly()
{
}
void UnitTestAssembly::RegisterTest(IUnitTestRunner& subject)
{
this->subject.push_back(&subject);
}
void UnitTestAssembly::Run()
{
std::vector<IUnitTestRunner*>::iterator it = this->subject.begin();
while( it != this->subject.end() )
{
IUnitTestRunner* IFace = static_cast<IUnitTestRunner*>(*it);
IFace->RunTest();
++it;
}
}
void UnitTestAssembly::RegisterObserver( IUnitTestObserver& observer )
{
// before observer can be added, subjects must belong to the assembly!
// since it it the job of each sucject to notify each observer
// of the unit test result
_ASSERT( ! this->subject.empty() );
std::vector<IUnitTestRunner*>::iterator it = this->subject.begin();
while( it != this->subject.end() )
{
try {
UnitTestRunner* IObj = dynamic_cast<UnitTestRunner*>(*it);
IObj->AddObserver( observer );
++it;
}
catch ( std::bad_cast e ) {
_ASSERT( 0 );
}
}
}
int UnitTestAssembly::GetTestList( std::vector<IUnitTestRunner*>& subjectList )
{
const int nSize = (int)this->subject.size();
for( int i=0; i < nSize; ++i ) {
subjectList.push_back( this->subject[i] );
}
return nSize;
}
void UnitTestAssembly::RemoveTest( IUnitTestRunner& subject )
{
_ASSERT( ! this->subject.empty() );
std::vector<IUnitTestRunner*>::iterator it =
std::remove( this->subject.begin(), this->subject.end(), &subject );
if( it != this->subject.end() ) {
this->subject.erase( it );
}
}
void UnitTestAssembly::Reset()
{
try {
const int nSize = (int)this->subject.size();
for( int i=0; i < nSize; ++i ) {
dynamic_cast<UnitTestRunner*>(this->subject[i])->Reset();
}
}
catch( std::bad_cast e ) {
_ASSERT( 0 );
}
}
Back
Copyright © 2007 Rajinder Yadav, All rights reserved