mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
rename functionality to "ignoreIndex"
This commit is contained in:
parent
24bf591900
commit
423c03b570
5 changed files with 43 additions and 43 deletions
|
|
@ -74,7 +74,7 @@ void ParameterizedManager::beginExecute(TestDetails const * const details)
|
|||
}
|
||||
_currentTest = retrieveTest(details);
|
||||
_nextTestBackup = _currentTest->m_next;
|
||||
_excludedIndexes.clear();
|
||||
_ignoredIndexes.clear();
|
||||
_iterationDone = false;
|
||||
}
|
||||
|
||||
|
|
@ -112,13 +112,13 @@ void ParameterizedManager::endExecute(TestDetails const * const details)
|
|||
|
||||
void ParameterizedManager::updateParameter(ParameterizedTestAbstract* const parameterized)
|
||||
{
|
||||
const vector<size_t> & excludedIndexes = _excludedIndexes[parameterized];
|
||||
const vector<size_t> & ignoredIndexes = _ignoredIndexes[parameterized];
|
||||
bool repeat = true;
|
||||
while (repeat)
|
||||
{
|
||||
iterate(parameterized);
|
||||
|
||||
repeat = (find(excludedIndexes.begin(), excludedIndexes.end(), parameterized->_iteration) != excludedIndexes.end());
|
||||
repeat = (find(ignoredIndexes.begin(), ignoredIndexes.end(), parameterized->_iteration) != ignoredIndexes.end());
|
||||
if (repeat)
|
||||
{
|
||||
_iterationDone = false;
|
||||
|
|
@ -162,31 +162,31 @@ ParameterizedManager::RegisterThen ParameterizedManager::registerParameter(Param
|
|||
}
|
||||
|
||||
|
||||
void ParameterizedManager::excludeIndex(ParameterizedTestAbstract* const parameterized, size_t index)
|
||||
void ParameterizedManager::ignoreIndex(ParameterizedTestAbstract* const parameterized, size_t index)
|
||||
{
|
||||
if (_iterationDone)
|
||||
{
|
||||
throw runtime_error("can not exclude indexes after iteration began");
|
||||
throw runtime_error("can not ignore indexes after iteration began");
|
||||
}
|
||||
|
||||
vector<size_t> & excludedIndexes = _excludedIndexes[parameterized];
|
||||
vector<size_t> & ignoredIndexes = _ignoredIndexes[parameterized];
|
||||
|
||||
if (index >= parameterized->parametersCount())
|
||||
{
|
||||
throw out_of_range("excluded index is out of range");
|
||||
throw out_of_range("ignore index is out of range");
|
||||
}
|
||||
|
||||
if (find(excludedIndexes.begin(), excludedIndexes.end(), index) != excludedIndexes.end())
|
||||
if (find(ignoredIndexes.begin(), ignoredIndexes.end(), index) != ignoredIndexes.end())
|
||||
{
|
||||
return; // already inserted
|
||||
}
|
||||
|
||||
if (excludedIndexes.size() + 1 == parameterized->parametersCount())
|
||||
if (ignoredIndexes.size() + 1 == parameterized->parametersCount())
|
||||
{
|
||||
throw runtime_error("all parameters have been excluded, can not proceed");
|
||||
throw runtime_error("all parameters have been ignored, can not proceed");
|
||||
}
|
||||
|
||||
excludedIndexes.push_back(index);
|
||||
ignoredIndexes.push_back(index);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace UnitTest
|
|||
void beginExecute(TestDetails const * const details);
|
||||
void endExecute(TestDetails const * const details);
|
||||
void updateParameter(ParameterizedTestAbstract* const parameterized);
|
||||
void excludeIndex(ParameterizedTestAbstract* const parameterized, size_t index);
|
||||
void ignoreIndex(ParameterizedTestAbstract* const parameterized, size_t index);
|
||||
const vector<ParameterizedTestAbstract*> & getStack(TestDetails const * const details) const;
|
||||
|
||||
private:
|
||||
|
|
@ -40,7 +40,7 @@ namespace UnitTest
|
|||
TestListNode* _currentTest;
|
||||
TestListNode* _nextTestBackup;
|
||||
vector<ParameterizedTestAbstract*> _stack;
|
||||
unordered_map<ParameterizedTestAbstract*, vector<size_t>> _excludedIndexes;
|
||||
unordered_map<ParameterizedTestAbstract*, vector<size_t>> _ignoredIndexes;
|
||||
volatile bool _iterationDone;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ void ParameterizedTestAbstract::onNewIteration(bool first)
|
|||
}
|
||||
|
||||
|
||||
ParameterizedTestAbstract & ParameterizedTestAbstract::excludeIndex(size_t index)
|
||||
ParameterizedTestAbstract & ParameterizedTestAbstract::ignoreIndex(size_t index)
|
||||
{
|
||||
ParameterizedManager::getInstance().excludeIndex(this, index);
|
||||
ParameterizedManager::getInstance().ignoreIndex(this, index);
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace UnitTest
|
|||
size_t getIteration();
|
||||
const string & getName() const { return _name; }
|
||||
string getNameCurrent() const;
|
||||
ParameterizedTestAbstract & excludeIndex(size_t index);
|
||||
ParameterizedTestAbstract & ignoreIndex(size_t index);
|
||||
|
||||
protected:
|
||||
void updateIteration();
|
||||
|
|
@ -62,9 +62,9 @@ namespace UnitTest
|
|||
return _parameters;
|
||||
}
|
||||
|
||||
ParameterizedTest<T_Parameter> & excludeIndex(size_t index)
|
||||
ParameterizedTest<T_Parameter> & ignoreIndex(size_t index)
|
||||
{
|
||||
ParameterizedTestAbstract::excludeIndex(index);
|
||||
ParameterizedTestAbstract::ignoreIndex(index);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -195,66 +195,66 @@ SUITE(ParameterizedTestSimple)
|
|||
|
||||
//////////
|
||||
|
||||
TEST(ExcludeIndex_OutOfRange_ThrowsException)
|
||||
TEST(IgnoreIndex_OutOfRange_ThrowsException)
|
||||
{
|
||||
size_t out = vowel.parameters().size();
|
||||
CHECK_THROW(vowel.excludeIndex(out), out_of_range);
|
||||
CHECK_THROW(vowel.ignoreIndex(out), out_of_range);
|
||||
}
|
||||
|
||||
TEST(ExcludeIndex_ExcludeAll_ThrowsException)
|
||||
TEST(IgnoreIndex_IgnoreAll_ThrowsException)
|
||||
{
|
||||
size_t last = vowel.parameters().size() - 1;
|
||||
for (size_t i = 0; i < last; i++)
|
||||
{
|
||||
vowel.excludeIndex(i);
|
||||
vowel.ignoreIndex(i);
|
||||
}
|
||||
|
||||
CHECK_THROW(vowel.excludeIndex(last), runtime_error);
|
||||
CHECK_THROW(vowel.ignoreIndex(last), runtime_error);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
string excludeSomeVowels;
|
||||
TEST(ExcludeIndex_ExcludeSome)
|
||||
string ignoreSomeVowels;
|
||||
TEST(IgnoreIndex_IgnoreSome)
|
||||
{
|
||||
vowel
|
||||
.excludeIndex(1) // "E"
|
||||
.excludeIndex(4); // "U"
|
||||
.ignoreIndex(1) // "E"
|
||||
.ignoreIndex(4); // "U"
|
||||
|
||||
excludeSomeVowels += vowel();
|
||||
ignoreSomeVowels += vowel();
|
||||
}
|
||||
|
||||
TEST(ExcludeIndex_ExcludeSome_Verify)
|
||||
TEST(IgnoreIndex_IgnoreSome_Verify)
|
||||
{
|
||||
CHECK_EQUAL("AIOY", excludeSomeVowels);
|
||||
CHECK_EQUAL("AIOY", ignoreSomeVowels);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
string excludeWithNested;
|
||||
TEST(ExcludeIndex_ExcludeWithNested)
|
||||
string ignoreWithNested;
|
||||
TEST(IgnoreIndex_IgnoreWithNested)
|
||||
{
|
||||
vowel
|
||||
.excludeIndex(0) // "A"
|
||||
.excludeIndex(2) // "I"
|
||||
.excludeIndex(3) // "O"
|
||||
.excludeIndex(4); // "U"
|
||||
.ignoreIndex(0) // "A"
|
||||
.ignoreIndex(2) // "I"
|
||||
.ignoreIndex(3) // "O"
|
||||
.ignoreIndex(4); // "U"
|
||||
|
||||
excludeWithNested += vowel();
|
||||
excludeWithNested += oneTwo();
|
||||
ignoreWithNested += vowel();
|
||||
ignoreWithNested += oneTwo();
|
||||
}
|
||||
|
||||
TEST(ExcludeIndex_ExcludeWithNested_Verify)
|
||||
TEST(IgnoreIndex_IgnoreWithNested_Verify)
|
||||
{
|
||||
CHECK_EQUAL("E1E2Y1Y2", excludeWithNested);
|
||||
CHECK_EQUAL("E1E2Y1Y2", ignoreWithNested);
|
||||
}
|
||||
|
||||
//////////
|
||||
|
||||
TEST(ExcludeIndex_ExcludeAfterIterationBegan_ThrowsException)
|
||||
TEST(IgnoreIndex_IgnoreAfterIterationBegan_ThrowsException)
|
||||
{
|
||||
vowel.excludeIndex(0);
|
||||
vowel.ignoreIndex(0);
|
||||
vowel();
|
||||
CHECK_THROW(vowel.excludeIndex(1), runtime_error);
|
||||
CHECK_THROW(vowel.ignoreIndex(1), runtime_error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue