improve test program (gcc fails test 22 and 41)
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@418 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
f00a0e6e47
commit
c9fa59ada0
1 changed files with 37 additions and 18 deletions
|
@ -92,6 +92,8 @@ std::list<char> RandomList(unsigned int maxSize)
|
||||||
return lst;
|
return lst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int currentTest = 0;
|
||||||
|
|
||||||
template <class String>
|
template <class String>
|
||||||
String Test(String, unsigned int count, bool avoidAliasing)
|
String Test(String, unsigned int count, bool avoidAliasing)
|
||||||
{
|
{
|
||||||
|
@ -104,7 +106,10 @@ String Test(String, unsigned int count, bool avoidAliasing)
|
||||||
test = RandomString(&test, maxString);
|
test = RandomString(&test, maxString);
|
||||||
|
|
||||||
static unsigned int functionSelector = 0;
|
static unsigned int functionSelector = 0;
|
||||||
switch (++functionSelector % 90)
|
++functionSelector;
|
||||||
|
currentTest = functionSelector % 90;
|
||||||
|
//std::cout << currentTest <<"\n";
|
||||||
|
switch (currentTest)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
// test default constructor 21.3.1
|
// test default constructor 21.3.1
|
||||||
|
@ -222,8 +227,11 @@ String Test(String, unsigned int count, bool avoidAliasing)
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
// exercise element access 21.3.4
|
// exercise element access 21.3.4
|
||||||
test[random(0, test.size() - 1)];
|
if(!test.empty())
|
||||||
test.at(random(0, test.size() - 1));
|
{
|
||||||
|
test[random(0, test.size() - 1)];
|
||||||
|
test.at(random(0, test.size() - 1));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
// 21.3.5 modifiers
|
// 21.3.5 modifiers
|
||||||
|
@ -373,7 +381,8 @@ String Test(String, unsigned int count, bool avoidAliasing)
|
||||||
break;
|
break;
|
||||||
case 42:
|
case 42:
|
||||||
// 21.3.5 modifiers
|
// 21.3.5 modifiers
|
||||||
test.erase(test.begin() + random(0, test.size()));
|
if(!test.empty())
|
||||||
|
test.erase(test.begin() + random(0, test.size()));
|
||||||
break;
|
break;
|
||||||
case 43:
|
case 43:
|
||||||
// 21.3.5 modifiers
|
// 21.3.5 modifiers
|
||||||
|
@ -853,6 +862,23 @@ String Test(String, unsigned int count, bool avoidAliasing)
|
||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void checkResults(const std::string& reference, const T& tested)
|
||||||
|
{
|
||||||
|
if( (tested.size() != reference.size())||
|
||||||
|
(std::string(tested.data(), tested.size()) != reference) )
|
||||||
|
{
|
||||||
|
std::cout << "\nTest " << currentTest << " failed: \n";
|
||||||
|
std::cout << "reference.size() = " << reference.size() << "\n";
|
||||||
|
std::cout << "tested.size() = " << tested.size() << "\n";
|
||||||
|
std::cout << "reference data = " << reference << "\n";
|
||||||
|
std::cout << "tested data = " << tested << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
//assert(tested.size() == reference.size());
|
||||||
|
//assert(std::string(tested.data(), tested.size()) == reference);
|
||||||
|
}
|
||||||
|
|
||||||
void Compare()
|
void Compare()
|
||||||
{
|
{
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
|
@ -875,8 +901,7 @@ void Compare()
|
||||||
SimpleStringStorage<char, std::allocator<char> >
|
SimpleStringStorage<char, std::allocator<char> >
|
||||||
> my_string;
|
> my_string;
|
||||||
const my_string tested = Test(my_string(), 1, false);
|
const my_string tested = Test(my_string(), 1, false);
|
||||||
assert(tested.size() == reference.size());
|
checkResults(reference, tested);
|
||||||
assert(std::string(tested.data(), tested.size()) == reference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -888,8 +913,7 @@ void Compare()
|
||||||
AllocatorStringStorage<char, std::allocator<char> >
|
AllocatorStringStorage<char, std::allocator<char> >
|
||||||
> my_string;
|
> my_string;
|
||||||
const my_string tested = Test(my_string(), 1, false);
|
const my_string tested = Test(my_string(), 1, false);
|
||||||
assert(tested.size() == reference.size());
|
checkResults(reference, tested);
|
||||||
assert(std::string(tested.data(), tested.size()) == reference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -901,8 +925,7 @@ void Compare()
|
||||||
AllocatorStringStorage<char, mallocator<char> >
|
AllocatorStringStorage<char, mallocator<char> >
|
||||||
> my_string;
|
> my_string;
|
||||||
const my_string tested = Test(my_string(), 1, false);
|
const my_string tested = Test(my_string(), 1, false);
|
||||||
assert(tested.size() == reference.size());
|
checkResults(reference, tested);
|
||||||
assert(std::string(tested.data(), tested.size()) == reference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -914,8 +937,7 @@ void Compare()
|
||||||
VectorStringStorage<char, std::allocator<char> >
|
VectorStringStorage<char, std::allocator<char> >
|
||||||
> my_string;
|
> my_string;
|
||||||
const my_string tested = Test(my_string(), 1, false);
|
const my_string tested = Test(my_string(), 1, false);
|
||||||
assert(tested.size() == reference.size());
|
checkResults(reference, tested);
|
||||||
assert(std::string(tested.data(), tested.size()) == reference);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
srand(t);
|
srand(t);
|
||||||
|
@ -929,8 +951,7 @@ void Compare()
|
||||||
> my_string;
|
> my_string;
|
||||||
static my_string sample;
|
static my_string sample;
|
||||||
const my_string tested(Test(sample, 1, false));
|
const my_string tested(Test(sample, 1, false));
|
||||||
assert(tested.size() == reference.size());
|
checkResults(reference, tested);
|
||||||
assert(std::string(tested.data(), tested.size()) == reference);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
srand(t);
|
srand(t);
|
||||||
|
@ -944,8 +965,7 @@ void Compare()
|
||||||
> my_string;
|
> my_string;
|
||||||
static my_string sample;
|
static my_string sample;
|
||||||
const my_string tested(Test(sample, 1, false));
|
const my_string tested(Test(sample, 1, false));
|
||||||
assert(tested.size() == reference.size());
|
checkResults(reference, tested);
|
||||||
assert(std::string(tested.data(), tested.size()) == reference);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
srand(t);
|
srand(t);
|
||||||
|
@ -959,8 +979,7 @@ void Compare()
|
||||||
> my_string;
|
> my_string;
|
||||||
static my_string sample;
|
static my_string sample;
|
||||||
const my_string tested(Test(sample, 1, false));
|
const my_string tested(Test(sample, 1, false));
|
||||||
assert(tested.size() == reference.size());
|
checkResults(reference, tested);
|
||||||
assert(std::string(tested.data(), tested.size()) == reference);
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
{ // SimpleStringStorage with UTF16 Encoding
|
{ // SimpleStringStorage with UTF16 Encoding
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue