1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
//===- UnitTest.cpp -------------------------------------------------------===//
//
// The SkyPat Team
//
// This file is distributed under the New BSD License.
// See LICENSE for details.
//
//===----------------------------------------------------------------------===//
#include <skypat/skypat.h>
using namespace skypat;
//===----------------------------------------------------------------------===//
// Details of UnitTest
//===----------------------------------------------------------------------===//
testing::UnitTest::UnitTest()
: m_pCurrentInfo(NULL), m_NumOfTests(0), m_NumOfFails(0) {
}
testing::UnitTest::~UnitTest()
{
CaseMap::iterator iCase, iEnd = m_CaseMap.end();
for (iCase = m_CaseMap.begin(); iCase != iEnd; ++iCase) {
delete iCase->second;
}
}
/// addRunCase - add the test case to run
/// @return true if the case exists (be stored at static-time).
bool testing::UnitTest::addRunCase(const std::string& pCaseName)
{
CaseMap::iterator iCase = m_CaseMap.find(pCaseName);
if (m_CaseMap.end() == iCase)
return false;
m_RunCases.push_back(iCase->second);
return true;
}
/// addAllRunCase - add all test cases to run
void testing::UnitTest::addAllRunCases()
{
CaseMap::iterator iCase, iEnd = m_CaseMap.end();
for (iCase = m_CaseMap.begin(); iCase != iEnd; ++iCase) {
m_RunCases.push_back(iCase->second);
}
}
testing::TestInfo*
testing::UnitTest::addTestInfo(const std::string& pCaseName,
const std::string& pTestName,
testing::TestFactoryBase& pFactory)
{
CaseMap::iterator iCase = m_CaseMap.find(pCaseName);
TestCase* test_case;
if (iCase != m_CaseMap.end())
test_case = iCase->second;
else {
test_case = new TestCase(pCaseName);
m_CaseMap.insert(make_pair(pCaseName, test_case));
}
testing::TestInfo* info = test_case->addTestInfo(pTestName, pFactory);
++m_NumOfTests;
return info;
}
void testing::UnitTest::addTestPartResult(const TestPartResult& pPartResult)
{
m_pCurrentInfo->addTestPartResult(pPartResult);
m_Repeater.OnTestPartResult(pPartResult);
if (testing::TestPartResult::kSuccess != pPartResult.type())
++m_NumOfFails;
}
testing::PerfPartResult*
testing::UnitTest::addPerfPartResult(const char* pFile, int pLine)
{
/* XXX: */
m_Repeater.OnPerfPartResult(testing::PerfPartResult(pFile, pLine));
return m_pCurrentInfo->addPerfPartResult(pFile, pLine);
}
void testing::UnitTest::RunAll()
{
m_Repeater.OnTestProgramStart(*this);
RunCases::iterator iCase, iEnd = m_RunCases.end();
for (iCase = m_RunCases.begin(); iCase != iEnd; ++iCase) {
TestCase* test_case = *iCase;
m_Repeater.OnTestCaseStart(*test_case);
TestCase::iterator it = test_case->begin();
TestCase::iterator iEnd = test_case->end();
while (it != iEnd) {
m_pCurrentInfo = *it;
(*it)->run();
++it;
}
m_Repeater.OnTestCaseEnd(*test_case);
}
m_Repeater.OnTestProgramEnd(*this);
}
|