Normalize files containing unit test code:

Source files are split to place all unit test code into translation
units ending in .test.cpp with no other business logic in the same file,
and in directories named "test".

A new target is added to the SConstruct, invoked by:
    scons count
This prints the total number of source code lines occupied by unit tests,
in rippled specific code and excluding library subtrees.
This commit is contained in:
Vinnie Falco
2014-12-23 12:28:19 -08:00
parent 9eb7c8344f
commit 9a3214d46e
65 changed files with 2396 additions and 2788 deletions

View File

@@ -236,7 +236,7 @@ void RangeSet::simplify ()
void RangeSet::checkInternalConsistency () const noexcept
{
#if BEAST_DEBUG
#ifndef NDEBUG
if (mRanges.size () > 1)
{
const_iterator const last = std::prev (mRanges.end ());
@@ -244,92 +244,17 @@ void RangeSet::checkInternalConsistency () const noexcept
for (const_iterator cur = mRanges.begin (); cur != last; ++cur)
{
const_iterator const next = std::next (cur);
bassert (cur->first <= cur->second);
bassert (next->first <= next->second);
bassert (cur->second + 1 < next->first);
assert (cur->first <= cur->second);
assert (next->first <= next->second);
assert (cur->second + 1 < next->first);
}
}
else if (mRanges.size () == 1)
{
const_iterator const iter = mRanges.begin ();
bassert (iter->first <= iter->second);
assert (iter->first <= iter->second);
}
#endif
}
//------------------------------------------------------------------------------
class RangeSet_test : public beast::unit_test::suite
{
public:
RangeSet createPredefinedSet ()
{
RangeSet set;
// Set will include:
// [ 0, 5]
// [10,15]
// [20,25]
// etc...
for (int i = 0; i < 10; ++i)
set.setRange (10 * i, 10 * i + 5);
return set;
}
void testMembership ()
{
testcase ("membership");
RangeSet r1, r2;
r1.setRange (1, 10);
r1.clearValue (5);
r1.setRange (11, 20);
r2.setRange (1, 4);
r2.setRange (6, 10);
r2.setRange (10, 20);
expect (!r1.hasValue (5));
expect (r2.hasValue (9));
}
void testPrevMissing ()
{
testcase ("prevMissing");
RangeSet const set = createPredefinedSet ();
for (int i = 0; i < 100; ++i)
{
int const oneBelowRange = (10*(i/10))-1;
int const expectedPrevMissing =
((i % 10) > 6) ? (i-1) : oneBelowRange;
expect (set.prevMissing (i) == expectedPrevMissing);
}
}
void run ()
{
testMembership ();
testPrevMissing ();
// TODO: Traverse functions must be tested
}
};
BEAST_DEFINE_TESTSUITE(RangeSet,ripple_basics,ripple);
} // ripple