Renamed files with + in them to be alphanumeric and baselined to roughly r2 or http://unittestpp.googlecode.com/svn/trunk/

This commit is contained in:
Patrick Johnmeyer 2013-01-09 23:33:51 -06:00
parent a3f957c09f
commit 72c2581719
34 changed files with 308 additions and 306 deletions

View file

@ -37,7 +37,7 @@ endif
test_src = src/tests/Main.cpp \
src/tests/TestAssertHandler.cpp \
src/tests/TestChecks.cpp \
src/tests/TestUnitTest++.cpp \
src/tests/TestUnitTestPP.cpp \
src/tests/TestTest.cpp \
src/tests/TestTestResults.cpp \
src/tests/TestTestRunner.cpp \

2
README
View file

@ -7,7 +7,7 @@ the terms of the License contained in the file COPYING distributed
with this package. This license is the same as the MIT/X Consortium
license.
See src/tests/TestUnitTest++.cpp for usage.
See src/tests/TestUnitTestPP.cpp for usage.
Authors:
Noel Llopis (llopis@convexhull.com)

View file

@ -163,7 +163,7 @@
RelativePath=".\src\tests\TestTimeConstraintMacro.cpp">
</File>
<File
RelativePath=".\src\tests\TestUnitTest++.cpp">
RelativePath=".\src\tests\TestUnitTestPP.cpp">
</File>
<File
RelativePath=".\src\tests\TestXmlTestReporter.cpp">

View file

@ -243,7 +243,7 @@
>
</File>
<File
RelativePath=".\src\tests\TestUnitTest++.cpp"
RelativePath=".\src\tests\TestUnitTestPP.cpp"
>
</File>
<File

View file

@ -146,7 +146,7 @@ SOURCE=.\src\tests\TestTimeConstraintMacro.cpp
# End Source File
# Begin Source File
SOURCE=".\src\tests\TestUnitTest++.cpp"
SOURCE=".\src\tests\TestUnitTestPP.cpp"
# End Source File
# Begin Source File

View file

@ -212,7 +212,7 @@
RelativePath=".\src\TimeHelpers.h">
</File>
<File
RelativePath=".\src\UnitTest++.h">
RelativePath=".\src\unittestpp.h">
</File>
<File
RelativePath=".\src\XmlTestReporter.cpp">

View file

@ -301,7 +301,7 @@
>
</File>
<File
RelativePath=".\src\UnitTest++.h"
RelativePath=".\src\unittestpp.h"
>
</File>
<File

View file

@ -237,7 +237,7 @@ SOURCE=.\src\TimeHelpers.h
# End Source File
# Begin Source File
SOURCE=".\src\UnitTest++.h"
SOURCE=".\src\unittestpp.h"
# End Source File
# Begin Source File

View file

@ -31,14 +31,14 @@
<p>You'll probably want to keep the generated library in a shared space in source control, so you can reuse it for multiple test projects. A redistributable package of UnitTest++ would consist of the generated library file, and all of the header files in <code>UnitTest++/src/</code> and its per-platform subfolders. The <code>tests</code> directory only contains the unit tests for the library, and need not be included.</p>
<h2>Using UnitTest++</h2>
<p>The source code for UnitTest++ comes with a full test suite written <em>using</em> UnitTest++. This is a great place to learn techniques for testing. There is one sample .cpp file: <code>UnitTest++/src/tests/TestUnitTest++.cpp</code>. It covers most of UnitTest++'s features in an easy-to-grasp context, so start there if you want a quick overview of typical usage.</p>
<p>The source code for UnitTest++ comes with a full test suite written <em>using</em> UnitTest++. This is a great place to learn techniques for testing. There is one sample .cpp file: <code>UnitTest++/src/tests/TestUnitTestPP.cpp</code>. It covers most of UnitTest++'s features in an easy-to-grasp context, so start there if you want a quick overview of typical usage.</p>
<h3>Getting started</h3>
<p>Listed below is a minimal C++ program to run a failing test through UnitTest++.</p>
<pre>
// test.cpp
#include &lt;UnitTest++.h&gt;
#include &lt;unittestpp.h&gt;
TEST(FailSpectacularly)
{
@ -51,7 +51,7 @@
}
</pre>
<p><code>UnitTest++.h</code> is a facade header for UnitTest++, so including that should get you all features of the library. All classes and free functions are placed in namespace <code>UnitTest</code>, so you need to either qualify their full names (as with <code>RunAllTests()</code> in the example) or add a <code>using namespace UnitTest;</code> statement in your .cpp files. Note that any mention of UnitTest++ functions and classes in this document assume that the <code>UnitTest</code> namespace has been opened.</p>
<p><code>unittestpp.h</code> is a facade header for UnitTest++, so including that should get you all features of the library. All classes and free functions are placed in namespace <code>UnitTest</code>, so you need to either qualify their full names (as with <code>RunAllTests()</code> in the example) or add a <code>using namespace UnitTest;</code> statement in your .cpp files. Note that any mention of UnitTest++ functions and classes in this document assume that the <code>UnitTest</code> namespace has been opened.</p>
<p>Compiling and linking this program with UnitTest++'s static library into an executable, and running it, will produce the following output (details may vary):</p>

View file

@ -1,28 +1,28 @@
#include "DeferredTestReporter.h"
#include "TestDetails.h"
using namespace UnitTest;
void DeferredTestReporter::ReportTestStart(TestDetails const& details)
{
m_results.push_back(DeferredTestResult(details.suiteName, details.testName));
}
void DeferredTestReporter::ReportFailure(TestDetails const& details, char const* failure)
{
DeferredTestResult& r = m_results.back();
r.failed = true;
r.failures.push_back(DeferredTestResult::Failure(details.lineNumber, failure));
r.failureFile = details.filename;
}
void DeferredTestReporter::ReportTestFinish(TestDetails const&, float secondsElapsed)
{
DeferredTestResult& r = m_results.back();
r.timeElapsed = secondsElapsed;
}
DeferredTestReporter::DeferredTestResultList& DeferredTestReporter::GetResults()
{
return m_results;
}
#include "DeferredTestReporter.h"
#include "TestDetails.h"
using namespace UnitTest;
void DeferredTestReporter::ReportTestStart(TestDetails const& details)
{
m_results.push_back(DeferredTestResult(details.suiteName, details.testName));
}
void DeferredTestReporter::ReportFailure(TestDetails const& details, char const* failure)
{
DeferredTestResult& r = m_results.back();
r.failed = true;
r.failures.push_back(DeferredTestResult::Failure(details.lineNumber, failure));
r.failureFile = details.filename;
}
void DeferredTestReporter::ReportTestFinish(TestDetails const&, float secondsElapsed)
{
DeferredTestResult& r = m_results.back();
r.timeElapsed = secondsElapsed;
}
DeferredTestReporter::DeferredTestResultList& DeferredTestReporter::GetResults()
{
return m_results;
}

View file

@ -1,25 +1,29 @@
#include "DeferredTestResult.h"
#include "Config.h"
namespace UnitTest
{
DeferredTestResult::DeferredTestResult()
: suiteName("")
, testName("")
, failureFile("")
, timeElapsed(0.0f)
, failed(false)
{
}
DeferredTestResult::DeferredTestResult(char const* suite, char const* test)
: suiteName(suite)
, testName(test)
, failureFile("")
, timeElapsed(0.0f)
, failed(false)
{
}
}
#include "DeferredTestResult.h"
#include "Config.h"
namespace UnitTest
{
DeferredTestResult::DeferredTestResult()
: suiteName("")
, testName("")
, failureFile("")
, timeElapsed(0.0f)
, failed(false)
{
}
DeferredTestResult::DeferredTestResult(char const* suite, char const* test)
: suiteName(suite)
, testName(test)
, failureFile("")
, timeElapsed(0.0f)
, failed(false)
{
}
DeferredTestResult::~DeferredTestResult()
{
}
}

View file

@ -1,76 +1,76 @@
#include "TestRunner.h"
#include "TestResults.h"
#include "TestReporter.h"
#include "TestReporterStdout.h"
#include "TimeHelpers.h"
#include "MemoryOutStream.h"
#include <cstring>
namespace UnitTest {
int RunAllTests()
{
TestReporterStdout reporter;
TestRunner runner(reporter);
return runner.RunTestsIf(Test::GetTestList(), NULL, True(), 0);
}
TestRunner::TestRunner(TestReporter& reporter)
: m_reporter(&reporter)
, m_result(new TestResults(&reporter))
, m_timer(new Timer)
{
m_timer->Start();
}
TestRunner::~TestRunner()
{
delete m_result;
delete m_timer;
}
int TestRunner::Finish() const
{
float const secondsElapsed = m_timer->GetTimeInMs() / 1000.0f;
m_reporter->ReportSummary(m_result->GetTotalTestCount(),
m_result->GetFailedTestCount(),
m_result->GetFailureCount(),
secondsElapsed);
return m_result->GetFailureCount();
}
bool TestRunner::IsTestInSuite(const Test* const curTest, char const* suiteName) const
{
using namespace std;
return (suiteName == NULL) || !strcmp(curTest->m_details.suiteName, suiteName);
}
void TestRunner::RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const
{
CurrentTest::Results() = result;
Timer testTimer;
testTimer.Start();
result->OnTestStart(curTest->m_details);
curTest->Run();
int const testTimeInMs = testTimer.GetTimeInMs();
if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt)
{
MemoryOutStream stream;
stream << "Global time constraint failed. Expected under " << maxTestTimeInMs <<
"ms but took " << testTimeInMs << "ms.";
result->OnTestFailure(curTest->m_details, stream.GetText());
}
result->OnTestFinish(curTest->m_details, testTimeInMs/1000.0f);
}
}
#include "TestRunner.h"
#include "TestResults.h"
#include "TestReporter.h"
#include "TestReporterStdout.h"
#include "TimeHelpers.h"
#include "MemoryOutStream.h"
#include <cstring>
namespace UnitTest {
int RunAllTests()
{
TestReporterStdout reporter;
TestRunner runner(reporter);
return runner.RunTestsIf(Test::GetTestList(), NULL, True(), 0);
}
TestRunner::TestRunner(TestReporter& reporter)
: m_reporter(&reporter)
, m_result(new TestResults(&reporter))
, m_timer(new Timer)
{
m_timer->Start();
}
TestRunner::~TestRunner()
{
delete m_result;
delete m_timer;
}
int TestRunner::Finish() const
{
float const secondsElapsed = static_cast<float>(m_timer->GetTimeInMs() / 1000.0);
m_reporter->ReportSummary(m_result->GetTotalTestCount(),
m_result->GetFailedTestCount(),
m_result->GetFailureCount(),
secondsElapsed);
return m_result->GetFailureCount();
}
bool TestRunner::IsTestInSuite(const Test* const curTest, char const* suiteName) const
{
using namespace std;
return (suiteName == NULL) || !strcmp(curTest->m_details.suiteName, suiteName);
}
void TestRunner::RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const
{
CurrentTest::Results() = result;
Timer testTimer;
testTimer.Start();
result->OnTestStart(curTest->m_details);
curTest->Run();
double const testTimeInMs = testTimer.GetTimeInMs();
if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt)
{
MemoryOutStream stream;
stream << "Global time constraint failed. Expected under " << maxTestTimeInMs <<
"ms but took " << testTimeInMs << "ms.";
result->OnTestFailure(curTest->m_details, stream.GetText());
}
result->OnTestFinish(curTest->m_details, static_cast<float>(testTimeInMs/1000.0));
}
}

View file

@ -1,59 +1,59 @@
#ifndef UNITTEST_TESTRUNNER_H
#define UNITTEST_TESTRUNNER_H
#include "Test.h"
#include "TestList.h"
#include "CurrentTest.h"
namespace UnitTest {
class TestReporter;
class TestResults;
class Timer;
int RunAllTests();
struct True
{
bool operator()(const Test* const) const
{
return true;
}
};
class TestRunner
{
public:
explicit TestRunner(TestReporter& reporter);
~TestRunner();
template <class Predicate>
int RunTestsIf(TestList const& list, char const* suiteName,
const Predicate& predicate, int maxTestTimeInMs) const
{
Test* curTest = list.GetHead();
while (curTest != 0)
{
if (IsTestInSuite(curTest, suiteName) && predicate(curTest))
RunTest(m_result, curTest, maxTestTimeInMs);
curTest = curTest->next;
}
return Finish();
}
private:
TestReporter* m_reporter;
TestResults* m_result;
Timer* m_timer;
int Finish() const;
bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
};
}
#endif
#ifndef UNITTEST_TESTRUNNER_H
#define UNITTEST_TESTRUNNER_H
#include "Test.h"
#include "TestList.h"
#include "CurrentTest.h"
namespace UnitTest {
class TestReporter;
class TestResults;
class Timer;
int RunAllTests();
struct True
{
bool operator()(const Test* const) const
{
return true;
}
};
class TestRunner
{
public:
explicit TestRunner(TestReporter& reporter);
~TestRunner();
template <class Predicate>
int RunTestsIf(TestList const& list, char const* suiteName,
const Predicate& predicate, int maxTestTimeInMs) const
{
Test* curTest = list.GetHead();
while (curTest != 0)
{
if (IsTestInSuite(curTest, suiteName) && predicate(curTest))
RunTest(m_result, curTest, maxTestTimeInMs);
curTest = curTest->next;
}
return Finish();
}
private:
TestReporter* m_reporter;
TestResults* m_result;
Timer* m_timer;
int Finish() const;
bool IsTestInSuite(const Test* const curTest, char const* suiteName) const;
void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const;
};
}
#endif

View file

@ -1,14 +1,12 @@
#ifndef UNITTEST_TESTSUITE_H
#define UNITTEST_TESTSUITE_H
namespace UnitTestSuite {
inline char const* GetSuiteName ()
{
return "DefaultSuite";
}
}
#endif
#ifndef UNITTEST_TESTSUITE_H
#define UNITTEST_TESTSUITE_H
namespace UnitTestSuite
{
inline char const* GetSuiteName ()
{
return "DefaultSuite";
}
}
#endif

View file

@ -1,29 +1,29 @@
#include "TimeConstraint.h"
#include "TestResults.h"
#include "MemoryOutStream.h"
#include "CurrentTest.h"
namespace UnitTest {
TimeConstraint::TimeConstraint(int ms, TestDetails const& details)
: m_details(details)
, m_maxMs(ms)
{
m_timer.Start();
}
TimeConstraint::~TimeConstraint()
{
int const totalTimeInMs = m_timer.GetTimeInMs();
if (totalTimeInMs > m_maxMs)
{
MemoryOutStream stream;
stream << "Time constraint failed. Expected to run test under " << m_maxMs <<
"ms but took " << totalTimeInMs << "ms.";
UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText());
}
}
}
#include "TimeConstraint.h"
#include "TestResults.h"
#include "MemoryOutStream.h"
#include "CurrentTest.h"
namespace UnitTest {
TimeConstraint::TimeConstraint(int ms, TestDetails const& details)
: m_details(details)
, m_maxMs(ms)
{
m_timer.Start();
}
TimeConstraint::~TimeConstraint()
{
double const totalTimeInMs = m_timer.GetTimeInMs();
if (totalTimeInMs > m_maxMs)
{
MemoryOutStream stream;
stream << "Time constraint failed. Expected to run test under " << m_maxMs <<
"ms but took " << totalTimeInMs << "ms.";
UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText());
}
}
}

View file

@ -1,47 +1,47 @@
#include "TimeHelpers.h"
#include <windows.h>
namespace UnitTest {
Timer::Timer()
: m_threadHandle(::GetCurrentThread())
, m_startTime(0)
{
#if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR?
typedef unsigned long DWORD_PTR;
#endif
DWORD_PTR systemMask;
::GetProcessAffinityMask(GetCurrentProcess(), &m_processAffinityMask, &systemMask);
::SetThreadAffinityMask(m_threadHandle, 1);
::QueryPerformanceFrequency(reinterpret_cast< LARGE_INTEGER* >(&m_frequency));
::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask);
}
void Timer::Start()
{
m_startTime = GetTime();
}
double Timer::GetTimeInMs() const
{
__int64 const elapsedTime = GetTime() - m_startTime;
double const seconds = double(elapsedTime) / double(m_frequency);
return seconds * 1000.0;
}
__int64 Timer::GetTime() const
{
LARGE_INTEGER curTime;
::SetThreadAffinityMask(m_threadHandle, 1);
::QueryPerformanceCounter(&curTime);
::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask);
return curTime.QuadPart;
}
void TimeHelpers::SleepMs(int const ms)
{
::Sleep(ms);
}
}
#include "TimeHelpers.h"
#include <windows.h>
namespace UnitTest {
Timer::Timer()
: m_threadHandle(::GetCurrentThread())
, m_startTime(0)
{
#if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR
typedef unsigned long DWORD_PTR;
#endif
DWORD_PTR systemMask;
::GetProcessAffinityMask(GetCurrentProcess(), &m_processAffinityMask, &systemMask);
::SetThreadAffinityMask(m_threadHandle, 1);
::QueryPerformanceFrequency(reinterpret_cast< LARGE_INTEGER* >(&m_frequency));
::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask);
}
void Timer::Start()
{
m_startTime = GetTime();
}
double Timer::GetTimeInMs() const
{
__int64 const elapsedTime = GetTime() - m_startTime;
double const seconds = double(elapsedTime) / double(m_frequency);
return seconds * 1000.0;
}
__int64 Timer::GetTime() const
{
LARGE_INTEGER curTime;
::SetThreadAffinityMask(m_threadHandle, 1);
::QueryPerformanceCounter(&curTime);
::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask);
return curTime.QuadPart;
}
void TimeHelpers::SleepMs(int const ms)
{
::Sleep(ms);
}
}

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../TestReporterStdout.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../AssertException.h"
#include "../ReportAssert.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../CurrentTest.h"
#include "RecordingReporter.h"
#include "ScopedCurrentTest.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "RecordingReporter.h"
using namespace UnitTest;

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../CurrentTest.h"
#include "ScopedCurrentTest.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../DeferredTestReporter.h"
#include "../Config.h"
#include <cstring>

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../MemoryOutStream.h"
#include <cstring>

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../TestReporter.h"
#include "../TimeHelpers.h"
#include "ScopedCurrentTest.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../TestList.h"
using namespace UnitTest;

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../TestMacros.h"
#include "../TestList.h"
#include "../TestResults.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../TestResults.h"
#include "RecordingReporter.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "RecordingReporter.h"
#include "../ReportAssert.h"
#include "../TestList.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
// We're really testing if it's possible to use the same suite in two files
// to compile and link successfuly (TestTestSuite.cpp has suite with the same name)

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../TestResults.h"
#include "../TimeHelpers.h"
#include "RecordingReporter.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../TimeHelpers.h"
#include "RecordingReporter.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../ReportAssert.h"
#include "ScopedCurrentTest.h"

View file

@ -1,4 +1,4 @@
#include "../UnitTest++.h"
#include "../unittestpp.h"
#include "../XmlTestReporter.h"
#include <sstream>