 |
 |
|
Rajinder Yadav - Windows C++ Development Tools & Resources :Design, Code, Test, Deploy |
// Source: UnitTestAssembly.h
// Author: Rajinder Yadav
// Date: June 30, 2004
//
// Copyright (c) Rajinder Yadav 2004, 2007
//
// web: http://devmentor.org
// email: rajinder@devmentor.org
//
#ifndef _UnitTestAssembly_
#define _UnitTestAssembly_
// warning C4251: 'UnitTestAssembly::subject' : class 'std::vector<_Ty>'
// needs to have dll-interface to be used by clients of class 'UnitTestAssembly'
#pragma warning(disable:4251)
// forward declrations
struct IUnitTestRunner;
struct IUnitTestObserver;
// UnitTestAssembly is responsible for running all test cases
// by acting as a container and notifier of test results to
// attached observers
//
class UTCORE_API UnitTestAssembly
{
static UnitTestAssembly* sm_UnitTestAssembly;
std::vector<IUnitTestRunner*> subject; // registered test case class
UnitTestAssembly();
~UnitTestAssembly();
public:
//------------------------------
// static class factory methods
//------------------------------
static UnitTestAssembly& GetInstance()
{
if( UnitTestAssembly::sm_UnitTestAssembly == 0 )
{
UnitTestAssembly::sm_UnitTestAssembly = new UnitTestAssembly;
}
return *UnitTestAssembly::sm_UnitTestAssembly;
}
static void ReleaseInstance()
{
delete UnitTestAssembly::sm_UnitTestAssembly;
UnitTestAssembly::sm_UnitTestAssembly = 0;
}
void Reset();
int GetTestList( std::vector<IUnitTestRunner*>& subjectList );
// register observers with each contained subjects in assembly
void RegisterObserver(IUnitTestObserver& observer);
// register subject into assembly
void RegisterTest( IUnitTestRunner& subject );
void RemoveTest( IUnitTestRunner& subject );
inline void ResetTestList() {
this->subject.clear();
}
void Run();
};
//------------------------------------------------
// helper class, encapsulates factory operations
//------------------------------------------------
class UTCORE_API UnitTestManager
{
public:
static void Start()
{
// create test harness and begin the unit test
UnitTestAssembly::GetInstance().Run();
// free singleton unit test framework
UnitTestAssembly::ReleaseInstance();
}
};
#endif // _UnitTestAssembly_
Back
Copyright © 2007 Rajinder Yadav, All rights reserved