new trunk (base for 1.5)

windows build only
This commit is contained in:
Aleksandar Fabijanic
2012-04-23 01:14:34 +00:00
parent f9b60296f7
commit d75e68c027
3760 changed files with 1058456 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
//
// ActiveTest.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ActiveTest.cpp#1 $
//
#include <afxwin.h>
#include "ActiveTest.h"
namespace CppUnit {
// Spawn a thread to a test
void ActiveTest::run(TestResult* result)
{
CWinThread* thread;
setTestResult(result);
_runCompleted.ResetEvent();
thread = AfxBeginThread(threadFunction, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
DuplicateHandle(GetCurrentProcess(), thread->m_hThread, GetCurrentProcess(), &_threadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
thread->ResumeThread();
}
// Simple execution thread. Assuming that an ActiveTest instance
// only creates one of these at a time.
UINT ActiveTest::threadFunction(LPVOID thisInstance)
{
ActiveTest* test = (ActiveTest*) thisInstance;
test->run();
test->_runCompleted.SetEvent();
return 0;
}
} // namespace CppUnit

View File

@@ -0,0 +1,89 @@
//
// ActiveTest.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ActiveTest.h#1 $
//
#ifndef ActiveTest_INCLUDED
#define ActiveTest_INCLUDED
#include "CppUnit/CppUnit.h"
#include "CppUnit/TestDecorator.h"
#include <afxmt.h>
namespace CppUnit {
/* A Microsoft-specific active test
*
* An active test manages its own
* thread of execution. This one
* is very simple and only sufficient
* for the limited use we put it through
* in the TestRunner. It spawns a thread
* on run (TestResult *) and signals
* completion of the test.
*
* We assume that only one thread
* will be active at once for each
* instance.
*
*/
class ActiveTest: public TestDecorator
{
public:
ActiveTest(Test* test);
~ActiveTest();
void run(TestResult* result);
protected:
HANDLE _threadHandle;
CEvent _runCompleted;
TestResult* _currentTestResult;
void run ();
void setTestResult(TestResult* result);
static UINT threadFunction(LPVOID thisInstance);
};
// Construct the active test
inline ActiveTest::ActiveTest(Test *test): TestDecorator(test)
{
_currentTestResult = NULL;
_threadHandle = INVALID_HANDLE_VALUE;
}
// Pend until the test has completed
inline ActiveTest::~ActiveTest()
{
CSingleLock(&_runCompleted, TRUE);
CloseHandle(_threadHandle);
}
// Set the test result that we are to run
inline void ActiveTest::setTestResult(TestResult* result)
{
_currentTestResult = result;
}
// Run our test result
inline void ActiveTest::run()
{
TestDecorator::run(_currentTestResult);
}
} // namespace CppUnit
#endif // ActiveTest_INCLUDED

View File

@@ -0,0 +1,50 @@
//
// DLLMain.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/DLLMain.cpp#1 $
//
#include <afxwin.h>
#include <afxdllx.h>
static AFX_EXTENSION_MODULE TestRunnerDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("WinTestRunner.DLL Initializing\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(TestRunnerDLL, hInstance))
return 0;
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(TestRunnerDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("WinTestRunner.DLL Terminating\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(TestRunnerDLL);
}
return 1; // ok
}

View File

@@ -0,0 +1,52 @@
//
// GUITestResult.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/GUITestResult.cpp#1 $
//
#include "TestRunnerDlg.h"
#include "GUITestResult.h"
namespace CppUnit {
void GUITestResult::addError(Test *test, CppUnitException *e)
{
ExclusiveZone zone(_syncObject);
TestResult::addError(test, e);
_runner->addError(this, test, e);
}
void GUITestResult::addFailure(Test *test, CppUnitException *e)
{
ExclusiveZone zone(_syncObject);
TestResult::addFailure(test, e);
_runner->addFailure(this, test, e);
}
void GUITestResult::startTest(Test *test)
{
ExclusiveZone zone(_syncObject);
TestResult::startTest(test);
_runner->startTest(test);
}
void GUITestResult::endTest(Test *test)
{
ExclusiveZone zone(_syncObject);
TestResult::endTest(test);
_runner->endTest(this, test);
}
} // namespace CppUnit

View File

@@ -0,0 +1,83 @@
//
// GUITestResult.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/GUITestResult.h#1 $
//
#ifndef GuiTestResult_INCLUDED
#define GuiTestResult_INCLUDED
#include "CppUnit/CppUnit.h"
#include "CppUnit/TestResult.h"
#include <afxmt.h>
namespace CppUnit {
class TestRunnerDlg;
class GUITestResult: public TestResult
{
public:
GUITestResult(TestRunnerDlg* runner);
~GUITestResult();
void addError(Test* test, CppUnitException* e);
void addFailure(Test* test, CppUnitException* e);
void startTest(Test* test);
void endTest(Test* test);
void stop();
protected:
class LightweightSynchronizationObject: public TestResult::SynchronizationObject
{
public:
void lock()
{
_syncObject.Lock();
}
void unlock()
{
_syncObject.Unlock();
}
private:
CCriticalSection _syncObject;
};
private:
TestRunnerDlg *_runner;
};
// Construct with lightweight synchronization
inline GUITestResult::GUITestResult(TestRunnerDlg* runner): _runner(runner)
{
setSynchronizationObject(new LightweightSynchronizationObject());
}
// Destructor
inline GUITestResult::~GUITestResult()
{
}
// Override without protection to prevent deadlock
inline void GUITestResult::stop()
{
_stop = true;
}
} // namespace CppUnit
#endif // GuiTestResult_INCLUDED

View File

@@ -0,0 +1,140 @@
//
// ProgressBar.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ProgressBar.cpp#1 $
//
#include "ProgressBar.h"
namespace CppUnit {
// Paint the progress bar in response to a paint message
void ProgressBar::paint(CDC& dc)
{
paintBackground (dc);
paintStatus (dc);
}
// Paint the background of the progress bar region
void ProgressBar::paintBackground (CDC& dc)
{
CBrush brshBackground;
CPen penGray (PS_SOLID, 1, RGB (128, 128, 128));
CPen penWhite (PS_SOLID, 1, RGB (255, 255, 255));
VERIFY (brshBackground.CreateSolidBrush (::GetSysColor (COLOR_BTNFACE)));
dc.FillRect (_bounds, &brshBackground);
CPen *pOldPen;
pOldPen = dc.SelectObject (&penGray);
{
dc.MoveTo (_bounds.left, _bounds.top);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top);
dc.MoveTo (_bounds.left, _bounds.top);
dc.LineTo (_bounds.left, _bounds.top + _bounds.Height () -1);
}
dc.SelectObject (&penWhite);
{
dc.MoveTo (_bounds.left + _bounds.Width () -1, _bounds.top);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top + _bounds.Height () -1);
dc.MoveTo (_bounds.left, _bounds.top + _bounds.Height () -1);
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top + _bounds.Height () -1);
}
dc.SelectObject (pOldPen);
}
// Paint the actual status of the progress bar
void ProgressBar::paintStatus (CDC& dc)
{
if (_progress <= 0)
return;
CBrush brshStatus;
CRect rect (_bounds.left, _bounds.top,
_bounds.left + _progressX, _bounds.bottom);
COLORREF statusColor = getStatusColor ();
VERIFY (brshStatus.CreateSolidBrush (statusColor));
rect.DeflateRect (1, 1);
dc.FillRect (rect, &brshStatus);
}
// Paint the current step
void ProgressBar::paintStep (int startX, int endX)
{
// kludge: painting the whole region on each step
_baseWindow->RedrawWindow (_bounds);
_baseWindow->UpdateWindow ();
}
// Setup the progress bar for execution over a total number of steps
void ProgressBar::start (int total)
{
_total = total;
reset ();
}
// Take one step, indicating whether it was a successful step
void ProgressBar::step (bool successful)
{
_progress++;
int x = _progressX;
_progressX = scale (_progress);
if (!_error && !successful)
{
_error = true;
x = 1;
}
paintStep (x, _progressX);
}
// Map from steps to display units
int ProgressBar::scale (int value)
{
if (_total > 0)
return max (1, value * (_bounds.Width () - 1) / _total);
return value;
}
// Reset the progress bar
void ProgressBar::reset ()
{
_progressX = 1;
_progress = 0;
_error = false;
_baseWindow->RedrawWindow (_bounds);
_baseWindow->UpdateWindow ();
}
} // namespace CppUnit

View File

@@ -0,0 +1,74 @@
//
// ProgressBar.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ProgressBar.h#1 $
//
#ifndef ProgressBar_INCLUDED
#define ProgressBar_INCLUDED
#include "CppUnit/CppUnit.h"
#include <afxwin.h>
namespace CppUnit {
/* A Simple ProgressBar for test execution display
*/
class ProgressBar
{
public:
ProgressBar(CWnd* baseWindow, CRect& bounds);
void step(bool successful);
void paint(CDC& dc);
int scale(int value);
void reset();
void start(int total);
protected:
void paintBackground(CDC& dc);
void paintStatus(CDC& dc);
COLORREF getStatusColor();
void paintStep(int startX, int endX);
CWnd* _baseWindow;
CRect _bounds;
bool _error;
int _total;
int _progress;
int _progressX;
};
// Construct a ProgressBar
inline ProgressBar::ProgressBar(CWnd* baseWindow, CRect& bounds):
_baseWindow(baseWindow),
_bounds(bounds),
_error(false),
_total(0),
_progress(0),
_progressX(0)
{
WINDOWINFO wi;
wi.cbSize = sizeof(WINDOWINFO);
baseWindow->GetWindowInfo(&wi);
_bounds.OffsetRect(-wi.rcClient.left, -wi.rcClient.top);
}
// Get the current color
inline COLORREF ProgressBar::getStatusColor()
{
return _error ? RGB(255, 0, 0) : RGB(0, 255, 0);
}
} // namespace CppUnit
#endif // ProgressBar_INCLUDED

View File

@@ -0,0 +1,106 @@
#ifndef SYNCHRONIZEDTESTRESULTDECORATOR_H
#define SYNCHRONIZEDTESTRESULTDECORATOR_H
#include <afxmt.h>
#include "TestResultDecorator.h"
class SynchronizedTestResult : public TestResultDecorator
{
public:
SynchronizedTestResult (TestResult *result);
~SynchronizedTestResult ();
bool shouldStop ();
void addError (Test *test, CppUnitException *e);
void addFailure (Test *test, CppUnitException *e);
void startTest (Test *test);
void endTest (Test *test);
int runTests ();
int testErrors ();
int testFailures ();
bool wasSuccessful ();
void stop ();
vector<TestFailure *>& errors ();
vector<TestFailure *>& failures ();
private:
CCriticalSection m_criticalSection;
};
// Constructor
inline SynchronizedTestResult::SynchronizedTestResult (TestResult *result)
: TestResultDecorator (result) {}
// Destructor
inline SynchronizedTestResult::~SynchronizedTestResult ()
{}
// Returns whether the test should stop
inline bool SynchronizedTestResult::shouldStop ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->shouldStop (); }
// Adds an error to the list of errors. The passed in exception
// caused the error
inline void SynchronizedTestResult::addError (Test *test, CppUnitException *e)
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->addError (test, e); }
// Adds a failure to the list of failures. The passed in exception
// caused the failure.
inline void SynchronizedTestResult::addFailure (Test *test, CppUnitException *e)
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->addFailure (test, e); }
// Informs the result that a test will be started.
inline void SynchronizedTestResult::startTest (Test *test)
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->startTest (test); }
// Informs the result that a test was completed.
inline void SynchronizedTestResult::endTest (Test *test)
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->endTest (test); }
// Gets the number of run tests.
inline int SynchronizedTestResult::runTests ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->runTests (); }
// Gets the number of detected errors.
inline int SynchronizedTestResult::testErrors ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->testErrors (); }
// Gets the number of detected failures.
inline int SynchronizedTestResult::testFailures ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->testFailures (); }
// Returns whether the entire test was successful or not.
inline bool SynchronizedTestResult::wasSuccessful ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->wasSuccessful (); }
// Marks that the test run should stop.
inline void SynchronizedTestResult::stop ()
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->stop (); }
// Returns a vector of the errors.
inline vector<TestFailure *>& SynchronizedTestResult::errors ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->errors (); }
// Returns a vector of the failures.
inline vector<TestFailure *>& SynchronizedTestResult::failures ()
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->failures (); }
#endif

View File

@@ -0,0 +1,102 @@
#ifndef CPP_UNIT_TESTRESULTDECORATOR_H
#define CPP_UNIT_TESTRESULTDECORATOR_H
#include "TestResult.h"
class TestResultDecorator
{
public:
TestResultDecorator (TestResult *result);
virtual ~TestResultDecorator ();
virtual bool shouldStop ();
virtual void addError (Test *test, CppUnitException *e);
virtual void addFailure (Test *test, CppUnitException *e);
virtual void startTest (Test *test);
virtual void endTest (Test *test);
virtual int runTests ();
virtual int testErrors ();
virtual int testFailures ();
virtual bool wasSuccessful ();
virtual void stop ();
vector<TestFailure *>& errors ();
vector<TestFailure *>& failures ();
protected:
TestResult *m_result;
};
inline TestResultDecorator::TestResultDecorator (TestResult *result)
: m_result (result) {}
inline TestResultDecorator::~TestResultDecorator ()
{}
// Returns whether the test should stop
inline bool TestResultDecorator::shouldStop ()
{ return m_result->shouldStop (); }
// Adds an error to the list of errors. The passed in exception
// caused the error
inline void TestResultDecorator::addError (Test *test, CppUnitException *e)
{ m_result->addError (test, e); }
// Adds a failure to the list of failures. The passed in exception
// caused the failure.
inline void TestResultDecorator::addFailure (Test *test, CppUnitException *e)
{ m_result->addFailure (test, e); }
// Informs the result that a test will be started.
inline void TestResultDecorator::startTest (Test *test)
{ m_result->startTest (test); }
// Informs the result that a test was completed.
inline void TestResultDecorator::endTest (Test *test)
{ m_result->endTest (test); }
// Gets the number of run tests.
inline int TestResultDecorator::runTests ()
{ return m_result->runTests (); }
// Gets the number of detected errors.
inline int TestResultDecorator::testErrors ()
{ return m_result->testErrors (); }
// Gets the number of detected failures.
inline int TestResultDecorator::testFailures ()
{ return m_result->testFailures (); }
// Returns whether the entire test was successful or not.
inline bool TestResultDecorator::wasSuccessful ()
{ return m_result->wasSuccessful (); }
// Marks that the test run should stop.
inline void TestResultDecorator::stop ()
{ m_result->stop (); }
// Returns a vector of the errors.
inline vector<TestFailure *>& TestResultDecorator::errors ()
{ return m_result->errors (); }
// Returns a vector of the failures.
inline vector<TestFailure *>& TestResultDecorator::failures ()
{ return m_result->failures (); }
#endif

View File

@@ -0,0 +1,439 @@
//
// TestRunnerDlg.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/TestRunnerDlg.cpp#1 $
//
#include <afxwin.h>
#include <afxext.h>
#include <afxcmn.h>
#include <mmsystem.h>
#include "TestRunnerDlg.h"
#include "ActiveTest.h"
#include "GUITestResult.h"
#include "ProgressBar.h"
#include "CppUnit/TestSuite.h"
#include "TestRunnerDlg.h"
namespace CppUnit {
TestRunnerDlg::TestRunnerDlg(CWnd* pParent): CDialog(TestRunnerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(TestRunnerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
_testsProgress = 0;
_selectedTest = 0;
_currentTest = 0;
}
void TestRunnerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TestRunnerDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(TestRunnerDlg, CDialog)
//{{AFX_MSG_MAP(TestRunnerDlg)
ON_BN_CLICKED(ID_RUN, OnRun)
ON_BN_CLICKED(ID_STOP, OnStop)
ON_CBN_SELCHANGE(IDC_COMBO_TEST, OnSelchangeComboTest)
ON_BN_CLICKED(IDC_CHK_AUTORUN, OnBnClickedAutorun)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL TestRunnerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
CComboBox *comboBox = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
ASSERT (listCtrl);
ASSERT (comboBox);
CString title;
GetWindowText(title);
#if defined(_DEBUG)
title.Append(" [debug]");
#else
title.Append(" [release]");
#endif
SetWindowText(title);
listCtrl->InsertColumn (0,"Type", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("Type"), 1);
listCtrl->InsertColumn (1,"Name", LVCFMT_LEFT, 16 * listCtrl->GetStringWidth ("X"), 2);
listCtrl->InsertColumn (2,"Failed Condition", LVCFMT_LEFT, 24 * listCtrl->GetStringWidth ("M"), 3);
listCtrl->InsertColumn (3,"Line", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("0000"), 4);
listCtrl->InsertColumn (4,"File Name", LVCFMT_LEFT, 36 * listCtrl->GetStringWidth ("M"), 5);
int numberOfCases = 0;
CWinApp* pApp = AfxGetApp();
CString lastTestCS = pApp->GetProfileString("Tests", "lastTest");
std::string lastTest((LPCSTR) lastTestCS);
int sel = -1;
for (std::vector<TestInfo>::iterator it = _tests.begin (); it != _tests.end (); ++it)
{
std::string cbName(it->level*4, ' ');
cbName.append(it->pTest->toString());
comboBox->AddString (cbName.c_str ());
if (sel < 0)
{
if (lastTest.empty() || lastTest == it->pTest->toString())
{
_selectedTest = it->pTest;
sel = numberOfCases;
}
}
numberOfCases++;
}
if (numberOfCases > 0)
{
if (sel < 0)
{
_selectedTest = _tests[0].pTest;
sel = 0;
}
comboBox->SetCurSel (sel);
}
else
{
beRunDisabled ();
}
CWnd *pProgress = GetDlgItem(IDC_PROGRESS);
CRect rect;
pProgress->GetWindowRect(&rect);
_testsProgress = new ProgressBar (this, rect);
CButton* autoRunBtn = (CButton*) GetDlgItem(IDC_CHK_AUTORUN);
autoRunBtn->SetCheck(pApp->GetProfileInt("Tests", "autoRun", BST_UNCHECKED));
reset ();
if (autoRunBtn->GetCheck() == BST_CHECKED)
{
OnRun();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
TestRunnerDlg::~TestRunnerDlg ()
{
freeState ();
delete _testsProgress;
}
void TestRunnerDlg::OnRun()
{
if (_selectedTest == 0)
return;
freeState ();
reset ();
beRunning ();
int numberOfTests = _selectedTest->countTestCases ();
_testsProgress->start (numberOfTests);
_result = new GUITestResult ((TestRunnerDlg *)this);
_activeTest = new ActiveTest (_selectedTest);
_testStartTime = timeGetTime ();
_activeTest->run (_result);
_testEndTime = timeGetTime ();
}
void TestRunnerDlg::addListEntry(const std::string& type, TestResult *result, Test *test, CppUnitException *e)
{
char stage [80];
LV_ITEM lvi;
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
int currentEntry = result->testErrors () + result->testFailures () -1;
sprintf (stage, "%s", type.c_str ());
lvi.mask = LVIF_TEXT;
lvi.iItem = currentEntry;
lvi.iSubItem = 0;
lvi.pszText = stage;
lvi.iImage = 0;
lvi.stateMask = 0;
lvi.state = 0;
listCtrl->InsertItem (&lvi);
// Set class string
listCtrl->SetItemText (currentEntry, 1, test->toString ().c_str ());
// Set the asserted text
listCtrl->SetItemText(currentEntry, 2, e->what ());
// Set the line number
if (e->lineNumber () == CppUnitException::CPPUNIT_UNKNOWNLINENUMBER)
sprintf (stage, "<unknown>");
else
sprintf (stage, "%ld", e->lineNumber ());
listCtrl->SetItemText(currentEntry, 3, stage);
// Set the file name
listCtrl->SetItemText(currentEntry, 4, e->fileName ().c_str ());
listCtrl->RedrawItems (currentEntry, currentEntry);
listCtrl->UpdateWindow ();
}
void TestRunnerDlg::addError (TestResult *result, Test *test, CppUnitException *e)
{
addListEntry ("Error", result, test, e);
_errors++;
_currentTest = 0;
updateCountsDisplay ();
}
void TestRunnerDlg::addFailure (TestResult *result, Test *test, CppUnitException *e)
{
addListEntry ("Failure", result, test, e);
_failures++;
_currentTest = 0;
updateCountsDisplay ();
}
void TestRunnerDlg::startTest(Test* test)
{
_currentTest = test;
updateCountsDisplay();
}
void TestRunnerDlg::endTest (TestResult *result, Test *test)
{
if (_selectedTest == 0)
return;
_currentTest = 0;
_testsRun++;
updateCountsDisplay ();
_testsProgress->step (_failures == 0 && _errors == 0);
_testEndTime = timeGetTime ();
updateCountsDisplay ();
if (_testsRun >= _selectedTest->countTestCases ())
beIdle ();
}
void TestRunnerDlg::beRunning ()
{
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
runButton->EnableWindow (FALSE);
closeButton->EnableWindow (FALSE);
}
void TestRunnerDlg::beIdle ()
{
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
runButton->EnableWindow (TRUE);
closeButton->EnableWindow (TRUE);
}
void TestRunnerDlg::beRunDisabled ()
{
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
CButton *stopButton = (CButton *)GetDlgItem (ID_STOP);
runButton->EnableWindow (FALSE);
stopButton->EnableWindow (FALSE);
closeButton->EnableWindow (TRUE);
}
void TestRunnerDlg::freeState ()
{
delete _activeTest;
delete _result;
}
void TestRunnerDlg::reset ()
{
_testsRun = 0;
_errors = 0;
_failures = 0;
_testEndTime = _testStartTime;
updateCountsDisplay ();
_activeTest = 0;
_result = 0;
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
listCtrl->DeleteAllItems ();
_testsProgress->reset ();
}
void TestRunnerDlg::updateCountsDisplay ()
{
CStatic *statTestsRun = (CStatic *)GetDlgItem (IDC_STATIC_RUNS);
CStatic *statErrors = (CStatic *)GetDlgItem (IDC_STATIC_ERRORS);
CStatic *statFailures = (CStatic *)GetDlgItem (IDC_STATIC_FAILURES);
CEdit *editTime = (CEdit *)GetDlgItem (IDC_EDIT_TIME);
CString argumentString;
argumentString.Format ("%d", _testsRun);
statTestsRun ->SetWindowText (argumentString);
argumentString.Format ("%d", _errors);
statErrors ->SetWindowText (argumentString);
argumentString.Format ("%d", _failures);
statFailures ->SetWindowText (argumentString);
if (_currentTest)
argumentString.Format ("Execution Time: %3.3lf seconds, Current Test: %s", (_testEndTime - _testStartTime) / 1000.0, _currentTest->toString().c_str());
else
argumentString.Format ("Execution Time: %3.3lf seconds", (_testEndTime - _testStartTime) / 1000.0);
editTime ->SetWindowText (argumentString);
}
void TestRunnerDlg::OnStop()
{
if (_result)
_result->stop ();
beIdle ();
}
void TestRunnerDlg::OnOK()
{
if (_result)
_result->stop ();
CDialog::OnOK ();
}
void TestRunnerDlg::OnSelchangeComboTest()
{
CComboBox *testsSelection = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
int currentSelection = testsSelection->GetCurSel ();
if (currentSelection >= 0 && currentSelection < _tests.size ())
{
_selectedTest = (_tests.begin () + currentSelection)->pTest;
beIdle ();
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileString("Tests", "lastTest", _selectedTest->toString().c_str());
}
else
{
_selectedTest = 0;
beRunDisabled ();
}
freeState ();
reset ();
}
void TestRunnerDlg::OnBnClickedAutorun()
{
CButton *autoRunBtn = (CButton *)GetDlgItem (IDC_CHK_AUTORUN);
CWinApp* pApp = AfxGetApp();
pApp->WriteProfileInt("Tests", "autoRun", autoRunBtn->GetCheck());
}
void TestRunnerDlg::OnPaint()
{
CPaintDC dc (this);
_testsProgress->paint (dc);
}
void TestRunnerDlg::setTests(const std::vector<Test*>& tests)
{
_tests.clear();
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
{
addTest(*it, 0);
}
}
void TestRunnerDlg::addTest(Test* pTest, int level)
{
TestInfo ti;
ti.pTest = pTest;
ti.level = level;
_tests.push_back(ti);
TestSuite* pSuite = dynamic_cast<TestSuite*>(pTest);
if (pSuite)
{
const std::vector<Test*>& tests = pSuite->tests();
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
{
addTest(*it, level + 1);
}
}
}
} // namespace CppUnit

View File

@@ -0,0 +1,94 @@
//
// TestRunnerDlg.h
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/TestRunnerDlg.h#1 $
//
#ifndef TestRunnerDlg_INCLUDED
#define TestRunnerDlg_INCLUDED
#include "CppUnit/CppUnit.h"
#include "CppUnit/CppUnitException.h"
#include "ActiveTest.h"
#include <vector>
#include "../res/Resource.h"
#include <afxwin.h>
#include "afxwin.h"
namespace CppUnit {
class ProgressBar;
class TestRunnerDlg: public CDialog
{
public:
TestRunnerDlg(CWnd* pParent = NULL);
~TestRunnerDlg();
void setTests(const std::vector<Test*>& tests);
void addError(TestResult* result, Test* test, CppUnitException* e);
void addFailure(TestResult* result, Test* test, CppUnitException* e);
void startTest(Test* test);
void endTest(TestResult* result, Test* test);
//{{AFX_DATA(TestRunnerDlg)
enum { IDD = IDD_DIALOG_TESTRUNNER };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
//{{AFX_VIRTUAL(TestRunnerDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
protected:
//{{AFX_MSG(TestRunnerDlg)
virtual BOOL OnInitDialog();
afx_msg void OnRun();
afx_msg void OnStop();
virtual void OnOK();
afx_msg void OnSelchangeComboTest();
afx_msg void OnBnClickedAutorun();
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
void addListEntry(const std::string& type, TestResult* result, Test* test, CppUnitException* e);
void beIdle();
void beRunning();
void beRunDisabled();
void reset();
void freeState();
void updateCountsDisplay();
void addTest(Test* pTest, int level);
struct TestInfo
{
Test* pTest;
int level;
};
std::vector<TestInfo> _tests;
ProgressBar* _testsProgress;
Test* _selectedTest;
ActiveTest* _activeTest;
TestResult* _result;
int _testsRun;
int _errors;
int _failures;
DWORD _testStartTime;
DWORD _testEndTime;
Test* _currentTest;
};
} // namespace CppUnit
#endif // TestRunnerDlg_INCLUDED

View File

@@ -0,0 +1,96 @@
//
// WinTestRunner.cpp
//
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/WinTestRunner.cpp#1 $
//
#include "WinTestRunner/WinTestRunner.h"
#include "TestRunnerDlg.h"
#include "CppUnit/TestRunner.h"
#include <fstream>
namespace CppUnit {
WinTestRunner::WinTestRunner()
{
}
WinTestRunner::~WinTestRunner()
{
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
delete *it;
}
void WinTestRunner::run()
{
// Note: The following code is some evil hack to
// add batch capability to the MFC based WinTestRunner.
std::string cmdLine(AfxGetApp()->m_lpCmdLine);
if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B'))
{
// We're running in batch mode.
std::string outPath;
if (cmdLine.size() > 4 && cmdLine[2] == ':')
outPath = cmdLine.substr(3);
else
outPath = "CON";
std::ofstream ostr(outPath.c_str());
if (ostr.good())
{
TestRunner runner(ostr);
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
runner.addTest((*it)->toString(), *it);
_tests.clear();
std::vector<std::string> args;
args.push_back("WinTestRunner");
args.push_back("-all");
bool success = runner.run(args);
ExitProcess(success ? 0 : 1);
}
else ExitProcess(2);
}
else
{
// We're running in interactive mode.
TestRunnerDlg dlg;
dlg.setTests(_tests);
dlg.DoModal();
}
}
void WinTestRunner::addTest(Test* pTest)
{
_tests.push_back(pTest);
}
BEGIN_MESSAGE_MAP(WinTestRunnerApp, CWinApp)
END_MESSAGE_MAP()
BOOL WinTestRunnerApp::InitInstance()
{
AllocConsole();
SetConsoleTitle("CppUnit WinTestRunner Console");
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
freopen("CONIN$", "r", stdin);
TestMain();
FreeConsole();
return FALSE;
}
void WinTestRunnerApp::TestMain()
{
}
} // namespace CppUnit