New unit_test framework:

* Header-only!
* No external dependencies or other beast modules
* Compilation options allow for:
  - Stand-alone application to run a single test suite
  - Stand-alone application to run a set of test suites
  - Global suite of tests inline with the host application
  - Disable test suite generation completely
* Existing tests reworked to use the new classes
This commit is contained in:
Vinnie Falco
2014-03-20 17:25:39 -07:00
parent 0bb6171a85
commit f63cf33118
114 changed files with 3259 additions and 4312 deletions

View File

@@ -21,7 +21,5 @@
#include "../../BeastConfig.h"
#endif
#include "impl/aged_associative_container.cpp"
#include "tests/aged_associative_container.test.cpp"
#include "tests/buffer_view.test.cpp"

View File

@@ -22,6 +22,7 @@
#include "../Config.h"
#include <array>
#include "../cxx14/algorithm.h" // <algorithm>
#include <cstddef>
#include <iterator>

View File

@@ -23,9 +23,6 @@
#include "aged_container_iterator.h"
#include "aged_associative_container.h"
#include "../../cxx14/algorithm.h"
#include "../../cxx14/type_traits.h"
#include "../aged_container.h"
#include "../../chrono/abstract_clock.h"
@@ -34,10 +31,12 @@
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/set.hpp>
#include "../../cxx14/algorithm.h" // <algorithm>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <memory>
#include "../../cxx14/type_traits.h" // <type_traits>
#include <utility>
namespace beast {

View File

@@ -31,12 +31,12 @@
#include <boost/intrusive/list.hpp>
#include <boost/intrusive/unordered_set.hpp>
#include "../../cxx14/algorithm.h"
#include "../../cxx14/type_traits.h"
#include "../../cxx14/algorithm.h" // <algorithm>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <memory>
#include "../../cxx14/type_traits.h" // <type_traits>
#include <utility>
/*

View File

@@ -17,8 +17,9 @@
*/
//==============================================================================
#include "../../../modules/beast_core/beast_core.h" // for UnitTest
#include "../../chrono/manual_clock.h"
#include "../../unit_test/suite.h"
#include "../aged_set.h"
#include "../aged_map.h"
#include "../aged_multiset.h"
@@ -28,6 +29,9 @@
#include "../aged_unordered_multiset.h"
#include "../aged_unordered_multimap.h"
#include <vector>
#include <list>
#ifndef BEAST_AGED_UNORDERED_NO_ALLOC_DEFAULTCTOR
# ifdef _MSC_VER
# define BEAST_AGED_UNORDERED_NO_ALLOC_DEFAULTCTOR 0
@@ -46,7 +50,7 @@
namespace beast {
class aged_associative_container_TestsBase : public UnitTest
class aged_associative_container_test_base : public unit_test::suite
{
public:
template <class T>
@@ -392,56 +396,6 @@ public:
//--------------------------------------------------------------------------
// Compile time checks
//
void checkAliases ()
{
typedef std::string Key;
typedef int T;
static_assert (std::is_same <
aged_set <Key>,
detail::aged_ordered_container <false, false, Key, void>>::value,
"bad alias: aged_set");
static_assert (std::is_same <
aged_multiset <Key>,
detail::aged_ordered_container <true, false, Key, void>>::value,
"bad alias: aged_multiset");
static_assert (std::is_same <
aged_map <Key, T>,
detail::aged_ordered_container <false, true, Key, T>>::value,
"bad alias: aged_map");
static_assert (std::is_same <
aged_multimap <Key, T>,
detail::aged_ordered_container <true, true, Key, T>>::value,
"bad alias: aged_multimap");
static_assert (std::is_same <
aged_unordered_set <Key>,
detail::aged_unordered_container <false, false, Key, void>>::value,
"bad alias: aged_unordered_set");
static_assert (std::is_same <
aged_unordered_multiset <Key>,
detail::aged_unordered_container <true, false, Key, void>>::value,
"bad alias: aged_unordered_multiset");
static_assert (std::is_same <
aged_unordered_map <Key, T>,
detail::aged_unordered_container <false, true, Key, T>>::value,
"bad alias: aged_unordered_map");
static_assert (std::is_same <
aged_unordered_multimap <Key, T>,
detail::aged_unordered_container <true, true, Key, T>>::value,
"bad alias: aged_unordered_multimap");
}
//--------------------------------------------------------------------------
template <
class Container,
class Values
@@ -603,11 +557,6 @@ public:
template <bool IsUnordered>
void testMaybeUnordered();
aged_associative_container_TestsBase () : UnitTest (
"aged_associative_container", "beast")
{
}
};
//------------------------------------------------------------------------------
@@ -620,7 +569,7 @@ template <
>
typename std::enable_if <
Container::is_map::value && ! Container::is_multi::value>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkMapContents (Container& c, Values const& v)
{
if (v.empty())
@@ -651,7 +600,7 @@ template <
>
typename std::enable_if <
std::remove_reference <C>::type::is_unordered::value>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkUnorderedContentsRefRef (C&& c, Values const& v)
{
typedef typename std::remove_reference <C>::type Cont;
@@ -685,7 +634,7 @@ checkUnorderedContentsRefRef (C&& c, Values const& v)
template <class C, class Values>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkContentsRefRef (C&& c, Values const& v)
{
typedef typename std::remove_reference <C>::type Cont;
@@ -715,7 +664,7 @@ checkContentsRefRef (C&& c, Values const& v)
template <class Cont, class Values>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkContents (Cont& c, Values const& v)
{
checkContentsRefRef (c, v);
@@ -725,7 +674,7 @@ checkContents (Cont& c, Values const& v)
template <class Cont>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkContents (Cont& c)
{
typedef TestTraits <
@@ -746,7 +695,7 @@ checkContents (Cont& c)
// ordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <! IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testConstructEmpty ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -760,7 +709,8 @@ testConstructEmpty ()
typedef typename Traits::MyAlloc MyAlloc;
typename Traits::Clock clock;
beginTestCase (Traits::name() + " empty");
//testcase (Traits::name() + " empty");
testcase ("empty");
{
typename Traits::template Cont <Comp, Alloc> c (
@@ -790,7 +740,7 @@ testConstructEmpty ()
// unordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testConstructEmpty ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -806,8 +756,8 @@ testConstructEmpty ()
typedef typename Traits::MyAlloc MyAlloc;
typename Traits::Clock clock;
beginTestCase (Traits::name() + " empty");
//testcase (Traits::name() + " empty");
testcase ("empty");
{
typename Traits::template Cont <Hash, Equal, Alloc> c (
clock);
@@ -860,7 +810,7 @@ testConstructEmpty ()
// ordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <! IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testConstructRange ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -875,7 +825,8 @@ testConstructRange ()
typename Traits::Clock clock;
auto const v (Traits::values());
beginTestCase (Traits::name() + " range");
//testcase (Traits::name() + " range");
testcase ("range");
{
typename Traits::template Cont <Comp, Alloc> c (
@@ -922,7 +873,7 @@ testConstructRange ()
// unordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testConstructRange ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -939,7 +890,8 @@ testConstructRange ()
typename Traits::Clock clock;
auto const v (Traits::values());
beginTestCase (Traits::name() + " range");
//testcase (Traits::name() + " range");
testcase ("range");
{
typename Traits::template Cont <Hash, Equal, Alloc> c (
@@ -1001,7 +953,7 @@ testConstructRange ()
// ordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <! IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testConstructInitList ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -1015,7 +967,8 @@ testConstructInitList ()
typedef typename Traits::MyAlloc MyAlloc;
typename Traits::Clock clock;
beginTestCase (Traits::name() + " init-list");
//testcase (Traits::name() + " init-list");
testcase ("init-list");
// VFALCO TODO
@@ -1025,7 +978,7 @@ testConstructInitList ()
// unordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testConstructInitList ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -1041,7 +994,9 @@ testConstructInitList ()
typedef typename Traits::MyAlloc MyAlloc;
typename Traits::Clock clock;
beginTestCase (Traits::name() + " init-list");
//testcase (Traits::name() + " init-list");
testcase ("init-list");
// VFALCO TODO
pass();
}
@@ -1054,7 +1009,7 @@ testConstructInitList ()
template <bool IsUnordered, bool IsMulti, bool IsMap>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testCopyMove ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -1063,7 +1018,8 @@ testCopyMove ()
typename Traits::Clock clock;
auto const v (Traits::values());
beginTestCase (Traits::name() + " copy/move");
//testcase (Traits::name() + " copy/move");
testcase ("copy/move");
// copy
@@ -1136,7 +1092,7 @@ testCopyMove ()
template <class Container, class Values>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkInsertCopy (Container& c, Values const& v)
{
for (auto const& e : v)
@@ -1146,7 +1102,7 @@ checkInsertCopy (Container& c, Values const& v)
template <class Container, class Values>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkInsertMove (Container& c, Values const& v)
{
Values v2 (v);
@@ -1157,7 +1113,7 @@ checkInsertMove (Container& c, Values const& v)
template <class Container, class Values>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkInsertHintCopy (Container& c, Values const& v)
{
for (auto const& e : v)
@@ -1167,7 +1123,7 @@ checkInsertHintCopy (Container& c, Values const& v)
template <class Container, class Values>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkInsertHintMove (Container& c, Values const& v)
{
Values v2 (v);
@@ -1178,7 +1134,7 @@ checkInsertHintMove (Container& c, Values const& v)
template <class Container, class Values>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkEmplace (Container& c, Values const& v)
{
for (auto const& e : v)
@@ -1188,7 +1144,7 @@ checkEmplace (Container& c, Values const& v)
template <class Container, class Values>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
checkEmplaceHint (Container& c, Values const& v)
{
for (auto const& e : v)
@@ -1198,7 +1154,7 @@ checkEmplaceHint (Container& c, Values const& v)
template <bool IsUnordered, bool IsMulti, bool IsMap>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testModifiers()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -1206,7 +1162,8 @@ testModifiers()
auto const v (Traits::values());
auto const l (make_list (v));
beginTestCase (Traits::name() + " modify");
//testcase (Traits::name() + " modify");
testcase ("modify");
{
typename Traits::template Cont <> c (clock);
@@ -1257,7 +1214,7 @@ testModifiers()
template <bool IsUnordered, bool IsMulti, bool IsMap>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testChronological ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -1265,7 +1222,8 @@ testChronological ()
typename Traits::Clock clock;
auto const v (Traits::values());
beginTestCase (Traits::name() + " chronological");
//testcase (Traits::name() + " chronological");
testcase ("chronological");
typename Traits::template Cont <> c (
v.begin(), v.end(), clock);
@@ -1297,14 +1255,15 @@ testChronological ()
// map, unordered_map
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <IsMap && ! IsMulti>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testArrayCreate()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
typename Traits::Clock clock;
auto v (Traits::values());
beginTestCase (Traits::name() + " array create");
//testcase (Traits::name() + " array create");
testcase ("array create");
{
// Copy construct key
@@ -1332,7 +1291,7 @@ testArrayCreate()
// ordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <! IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testCompare ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -1340,7 +1299,8 @@ testCompare ()
typename Traits::Clock clock;
auto const v (Traits::values());
beginTestCase (Traits::name() + " array create");
//testcase (Traits::name() + " array create");
testcase ("array create");
typename Traits::template Cont <> c1 (
v.begin(), v.end(), clock);
@@ -1366,13 +1326,14 @@ testCompare ()
// ordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <! IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testObservers()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
typename Traits::Clock clock;
beginTestCase (Traits::name() + " observers");
//testcase (Traits::name() + " observers");
testcase ("observers");
typename Traits::template Cont <> c (clock);
c.key_comp();
@@ -1384,13 +1345,14 @@ testObservers()
// unordered
template <bool IsUnordered, bool IsMulti, bool IsMap>
typename std::enable_if <IsUnordered>::type
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testObservers()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
typename Traits::Clock clock;
beginTestCase (Traits::name() + " observers");
//testcase (Traits::name() + " observers");
testcase ("observers");
typename Traits::template Cont <> c (clock);
c.hash_function();
@@ -1407,7 +1369,7 @@ testObservers()
template <bool IsUnordered, bool IsMulti, bool IsMap>
void
aged_associative_container_TestsBase::
aged_associative_container_test_base::
testMaybeUnorderedMultiMap ()
{
typedef TestTraits <IsUnordered, IsMulti, IsMap> Traits;
@@ -1423,38 +1385,133 @@ testMaybeUnorderedMultiMap ()
testObservers <IsUnordered, IsMulti, IsMap> ();
}
template <bool IsUnordered, bool IsMulti>
void
aged_associative_container_TestsBase::
testMaybeUnorderedMulti()
{
testMaybeUnorderedMultiMap <IsUnordered, IsMulti, false> ();
testMaybeUnorderedMultiMap <IsUnordered, IsMulti, true> ();
}
template <bool IsUnordered>
void
aged_associative_container_TestsBase::
testMaybeUnordered()
{
testMaybeUnorderedMulti <IsUnordered, false> ();
testMaybeUnorderedMulti <IsUnordered, true> ();
}
//------------------------------------------------------------------------------
class aged_associative_container_Tests :
public aged_associative_container_TestsBase
class aged_set_test : public aged_associative_container_test_base
{
public:
void runTest ()
// Compile time checks
typedef std::string Key;
typedef int T;
static_assert (std::is_same <
aged_set <Key>,
detail::aged_ordered_container <false, false, Key, void>>::value,
"bad alias: aged_set");
static_assert (std::is_same <
aged_multiset <Key>,
detail::aged_ordered_container <true, false, Key, void>>::value,
"bad alias: aged_multiset");
static_assert (std::is_same <
aged_map <Key, T>,
detail::aged_ordered_container <false, true, Key, T>>::value,
"bad alias: aged_map");
static_assert (std::is_same <
aged_multimap <Key, T>,
detail::aged_ordered_container <true, true, Key, T>>::value,
"bad alias: aged_multimap");
static_assert (std::is_same <
aged_unordered_set <Key>,
detail::aged_unordered_container <false, false, Key, void>>::value,
"bad alias: aged_unordered_set");
static_assert (std::is_same <
aged_unordered_multiset <Key>,
detail::aged_unordered_container <true, false, Key, void>>::value,
"bad alias: aged_unordered_multiset");
static_assert (std::is_same <
aged_unordered_map <Key, T>,
detail::aged_unordered_container <false, true, Key, T>>::value,
"bad alias: aged_unordered_map");
static_assert (std::is_same <
aged_unordered_multimap <Key, T>,
detail::aged_unordered_container <true, true, Key, T>>::value,
"bad alias: aged_unordered_multimap");
void run ()
{
checkAliases ();
testMaybeUnordered <false> ();
testMaybeUnordered <true> ();
testMaybeUnorderedMultiMap <false, false, false>();
}
};
static aged_associative_container_Tests aged_associative_container_tests;
class aged_map_test : public aged_associative_container_test_base
{
public:
void run ()
{
testMaybeUnorderedMultiMap <false, false, true>();
}
};
class aged_multiset_test : public aged_associative_container_test_base
{
public:
void run ()
{
testMaybeUnorderedMultiMap <false, true, false>();
}
};
class aged_multimap_test : public aged_associative_container_test_base
{
public:
void run ()
{
testMaybeUnorderedMultiMap <false, true, true>();
}
};
class aged_unordered_set_test : public aged_associative_container_test_base
{
public:
void run ()
{
testMaybeUnorderedMultiMap <true, false, false>();
}
};
class aged_unordered_map_test : public aged_associative_container_test_base
{
public:
void run ()
{
testMaybeUnorderedMultiMap <true, false, true>();
}
};
class aged_unordered_multiset_test : public aged_associative_container_test_base
{
public:
void run ()
{
testMaybeUnorderedMultiMap <true, true, false>();
}
};
class aged_unordered_multimap_test : public aged_associative_container_test_base
{
public:
void run ()
{
testMaybeUnorderedMultiMap <true, true, true>();
}
};
BEAST_DEFINE_TESTSUITE(aged_set,container,beast);
BEAST_DEFINE_TESTSUITE(aged_map,container,beast);
BEAST_DEFINE_TESTSUITE(aged_multiset,container,beast);
BEAST_DEFINE_TESTSUITE(aged_multimap,container,beast);
BEAST_DEFINE_TESTSUITE(aged_unordered_set,container,beast);
BEAST_DEFINE_TESTSUITE(aged_unordered_map,container,beast);
BEAST_DEFINE_TESTSUITE(aged_unordered_multiset,container,beast);
BEAST_DEFINE_TESTSUITE(aged_unordered_multimap,container,beast);
}

View File

@@ -17,14 +17,15 @@
*/
//==============================================================================
#include "../../../modules/beast_core/beast_core.h" // for UnitTest
#include "../../unit_test/suite.h"
#include "../buffer_view.h"
#include "../../cxx14/algorithm.h" // <algorithm>
namespace beast {
class buffer_view_Tests : public UnitTest
class buffer_view_test : public unit_test::suite
{
public:
// Returns `true` if the iterator distance matches the size
@@ -153,7 +154,7 @@ public:
// Test empty containers
void testEmpty()
{
beginTestCase ("empty");
testcase ("empty");
buffer_view <char> v1;
checkEmpty (v1);
@@ -239,11 +240,11 @@ public:
void testConstruct()
{
beginTestCase ("std::vector <char>");
testcase ("std::vector <char>");
testConstruct (
std::vector <char> ({'h', 'e', 'l', 'l', 'o'}));
beginTestCase ("std::string <char>");
testcase ("std::string <char>");
testConstruct (
std::basic_string <char> ("hello"));
}
@@ -252,7 +253,7 @@ public:
void testCoerce()
{
beginTestCase ("coerce");
testcase ("coerce");
std::string const s ("hello");
const_buffer_view <unsigned char> v (s);
@@ -264,7 +265,7 @@ public:
void testAssign()
{
beginTestCase ("testAssign");
testcase ("testAssign");
std::vector <int> v1({1, 2, 3});
buffer_view<int> r1(v1);
std::vector <int> v2({4, 5, 6, 7});
@@ -305,19 +306,15 @@ public:
static_assert (std::is_nothrow_move_assignable <
buffer_view <int>>::value, "");
void runTest()
void run()
{
testEmpty();
testConstruct();
testCoerce();
testAssign();
}
buffer_view_Tests() : UnitTest ("buffer_view", "beast")
{
}
};
static buffer_view_Tests buffer_view_tests;
BEAST_DEFINE_TESTSUITE(buffer_view,container,beast);
}