mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
method for retrieve a test from its details
This commit is contained in:
parent
f6f07775af
commit
a1510a13a0
2 changed files with 53 additions and 0 deletions
|
|
@ -1,5 +1,9 @@
|
|||
#include "ParameterizedTest.h"
|
||||
|
||||
#include "TestList.h"
|
||||
#include "CurrentTest.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace UnitTest;
|
||||
|
||||
|
||||
|
|
@ -11,3 +15,39 @@ ParameterizedTest::ParameterizedTest()
|
|||
ParameterizedTest::~ParameterizedTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Details2Test & ParameterizedTest::getFastSearchMap()
|
||||
{
|
||||
static Details2Test storedMap;
|
||||
return storedMap;
|
||||
}
|
||||
|
||||
|
||||
Test* const ParameterizedTest::retrieveCurrentTest()
|
||||
{
|
||||
return retrieveTest(CurrentTest::Details());
|
||||
}
|
||||
|
||||
|
||||
Test* const ParameterizedTest::retrieveTest(TestDetails const * const details)
|
||||
{
|
||||
//TODO This workaround is too far complicated, why not simply add pointer to current test in class CurrentTest ?
|
||||
Details2Test::iterator it = getFastSearchMap().find(details);
|
||||
|
||||
if (it != getFastSearchMap().end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
for(Test* iTest = Test::GetTestList().GetHead() ; iTest!= nullptr ; iTest=iTest->m_nextTest)
|
||||
{
|
||||
if (&iTest->m_details == details)
|
||||
{
|
||||
getFastSearchMap()[details] = iTest;
|
||||
return iTest;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,26 @@
|
|||
#ifndef UNITTEST_PARAMETERIZEDTEST_H
|
||||
#define UNITTEST_PARAMETERIZEDTEST_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "Test.h"
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
typedef map<TestDetails const * const, Test*> Details2Test;
|
||||
|
||||
class ParameterizedTest
|
||||
{
|
||||
public:
|
||||
ParameterizedTest();
|
||||
virtual ~ParameterizedTest();
|
||||
|
||||
private:
|
||||
static Details2Test & getFastSearchMap();
|
||||
static Test* const retrieveCurrentTest();
|
||||
static Test* const retrieveTest(TestDetails const * const details);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue