yet another random test helper
This commit is contained in:
parent
ceb4d4b5ea
commit
006392f6ea
4 changed files with 53 additions and 2 deletions
|
|
@ -41,5 +41,21 @@ namespace test{
|
|||
}
|
||||
|
||||
|
||||
/** @todo probably this can be done in a more clever way. Anyone...?
|
||||
*/
|
||||
string
|
||||
randStr (size_t len)
|
||||
{
|
||||
static const string alpha ("aaaabbccddeeeeffgghiiiijjkkllmmnnooooppqqrrssttuuuuvvwwxxyyyyzz0123456789");
|
||||
static const size_t MAXAL (alpha.size());
|
||||
|
||||
string garbage(len,'\0');
|
||||
size_t p = len;
|
||||
while (p)
|
||||
garbage[--p] = alpha[rand() % MAXAL];
|
||||
return garbage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}} // namespace lib::test
|
||||
|
|
|
|||
|
|
@ -110,6 +110,11 @@ namespace test{
|
|||
return Time (500 * (rand() % 2), (rand() % 600));
|
||||
}
|
||||
|
||||
/** create garbage string of given length
|
||||
* @return string containing arbitrary lower case letters and numbers
|
||||
*/
|
||||
string randStr (size_t len);
|
||||
|
||||
|
||||
}} // namespace lib::test
|
||||
|
||||
|
|
|
|||
|
|
@ -489,6 +489,7 @@ END
|
|||
|
||||
|
||||
TEST "Test support functions" TestHelper_test <<END
|
||||
out: [a-z0-9]{80}$
|
||||
out: Displaying types and sizes....
|
||||
out: sizeof..theUniverse.+ = 42
|
||||
out: sizeof..just a char.+ = 1
|
||||
|
|
|
|||
|
|
@ -24,15 +24,25 @@
|
|||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <tr1/functional>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using util::for_each;
|
||||
using lumiera::Error;
|
||||
using lumiera::LUMIERA_ERROR_EXCEPTION;
|
||||
using lumiera::error::LUMIERA_ERROR_ASSERTION;
|
||||
|
||||
using boost::algorithm::is_lower;
|
||||
using boost::algorithm::is_digit;
|
||||
using std::tr1::function;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
|
@ -61,6 +71,7 @@ namespace test{
|
|||
void
|
||||
run (Arg)
|
||||
{
|
||||
checkGarbageStr();
|
||||
checkTypeDisplay();
|
||||
checkThrowChecker();
|
||||
}
|
||||
|
|
@ -99,6 +110,24 @@ namespace test{
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
checkGarbageStr()
|
||||
{
|
||||
string garN = randStr(0);
|
||||
ASSERT (0 == garN.size());
|
||||
|
||||
typedef function<bool(string::value_type)> ChPredicate;
|
||||
ChPredicate is_OK (is_lower() || is_digit());
|
||||
|
||||
string garM = randStr(1000000);
|
||||
for_each (garM, is_OK);
|
||||
|
||||
cout << randStr(80) << endl;
|
||||
}
|
||||
|
||||
|
||||
/** @test check the VERIFY_ERROR macro,
|
||||
* which ensures a given error is raised.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue