Refactor.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@991 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
272dc6a91b
commit
0e615e0932
1 changed files with 858 additions and 840 deletions
|
@ -36,21 +36,69 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
AllocatorStringStorage<char, std::allocator<char> >
|
||||
> my_string;
|
||||
|
||||
template class flex_string<
|
||||
namespace StringsToTest
|
||||
{
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
SimpleStringStorage<char, std::allocator<char> >
|
||||
> my_string_SimpleStorage;
|
||||
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
AllocatorStringStorage<char, std::allocator<char> >
|
||||
>;
|
||||
> my_string_AllocatorStorage;
|
||||
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
mallocator<char>,
|
||||
AllocatorStringStorage<char, mallocator<char> >
|
||||
> my_string_MallocatorStorage;
|
||||
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
VectorStringStorage<char, std::allocator<char> >
|
||||
> my_string_VectorStorage;
|
||||
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
SmallStringOpt<SimpleStringStorage<char, std::allocator<char> >, 31>
|
||||
> my_string_SmallStringSimple;
|
||||
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
SmallStringOpt<VectorStringStorage<char, std::allocator<char> >, 23>
|
||||
> my_string_SmallStringVector;
|
||||
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
CowStringOpt<SimpleStringStorage<char, std::allocator<char> > >
|
||||
> my_string_CowSimple;
|
||||
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
CowStringOpt<AllocatorStringStorage<char, std::allocator<char> > >
|
||||
> my_string_CowAllocator;
|
||||
}
|
||||
|
||||
|
||||
template <class Integral1, class Integral2>
|
||||
Integral2 random(Integral1 low, Integral2 up)
|
||||
|
@ -98,14 +146,13 @@ std::list<char> RandomList(unsigned int maxSize)
|
|||
int currentTest = 0;
|
||||
|
||||
template <class String>
|
||||
String Test(String, unsigned int count, bool avoidAliasing)
|
||||
String Test(bool avoidAliasing)
|
||||
{
|
||||
typedef typename String::size_type size_type;
|
||||
const size_type maxString = 1000;
|
||||
|
||||
String test;
|
||||
while (count--)
|
||||
{
|
||||
|
||||
test = RandomString(&test, maxString);
|
||||
|
||||
static unsigned int functionSelector = 0;
|
||||
|
@ -861,7 +908,7 @@ String Test(String, unsigned int count, bool avoidAliasing)
|
|||
assert(((functionSelector + 1) % 96) == 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
@ -893,95 +940,55 @@ void Compare()
|
|||
unsigned long t = rand(); //time(0);
|
||||
|
||||
srand(t);
|
||||
const std::string reference = Test(std::string(), 1, true);
|
||||
const std::string reference = Test<std::string>(true);
|
||||
|
||||
using namespace StringsToTest;
|
||||
|
||||
{
|
||||
srand(t);
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
SimpleStringStorage<char, std::allocator<char> >
|
||||
> my_string;
|
||||
const my_string tested = Test(my_string(), 1, false);
|
||||
const my_string_SimpleStorage tested = Test<my_string_SimpleStorage>(false);
|
||||
checkResults(reference, tested);
|
||||
}
|
||||
|
||||
{
|
||||
srand(t);
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
AllocatorStringStorage<char, std::allocator<char> >
|
||||
> my_string;
|
||||
const my_string tested = Test(my_string(), 1, false);
|
||||
const my_string_AllocatorStorage tested = Test<my_string_AllocatorStorage>(false);
|
||||
checkResults(reference, tested);
|
||||
}
|
||||
|
||||
{
|
||||
srand(t);
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
mallocator<char>,
|
||||
AllocatorStringStorage<char, mallocator<char> >
|
||||
> my_string;
|
||||
const my_string tested = Test(my_string(), 1, false);
|
||||
const my_string_MallocatorStorage tested = Test<my_string_MallocatorStorage>(false);
|
||||
checkResults(reference, tested);
|
||||
}
|
||||
|
||||
{
|
||||
srand(t);
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
VectorStringStorage<char, std::allocator<char> >
|
||||
> my_string;
|
||||
const my_string tested = Test(my_string(), 1, false);
|
||||
const my_string_VectorStorage tested = Test<my_string_VectorStorage>(false);
|
||||
checkResults(reference, tested);
|
||||
}
|
||||
|
||||
{
|
||||
srand(t);
|
||||
typedef VectorStringStorage<char, std::allocator<char> >
|
||||
Storage;
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
SmallStringOpt<Storage, 23>
|
||||
> my_string;
|
||||
static my_string sample;
|
||||
const my_string tested(Test(sample, 1, false));
|
||||
const my_string_SmallStringSimple tested(Test<my_string_SmallStringSimple>(false));
|
||||
checkResults(reference, tested);
|
||||
}
|
||||
|
||||
{
|
||||
srand(t);
|
||||
typedef SimpleStringStorage<char, std::allocator<char> >
|
||||
Storage;
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
CowStringOpt<Storage>
|
||||
> my_string;
|
||||
static my_string sample;
|
||||
const my_string tested(Test(sample, 1, false));
|
||||
const my_string_SmallStringVector tested(Test<my_string_SmallStringVector>(false));
|
||||
checkResults(reference, tested);
|
||||
}
|
||||
|
||||
{
|
||||
srand(t);
|
||||
typedef AllocatorStringStorage<char, std::allocator<char> >
|
||||
Storage;
|
||||
typedef flex_string<
|
||||
char,
|
||||
std::char_traits<char>,
|
||||
std::allocator<char>,
|
||||
CowStringOpt<Storage>
|
||||
> my_string;
|
||||
static my_string sample;
|
||||
const my_string tested(Test(sample, 1, false));
|
||||
const my_string_CowSimple tested(Test<my_string_CowSimple>(false));
|
||||
checkResults(reference, tested);
|
||||
}
|
||||
|
||||
{
|
||||
srand(t);
|
||||
const my_string_CowAllocator tested(Test<my_string_CowAllocator>(false));
|
||||
checkResults(reference, tested);
|
||||
}
|
||||
/*
|
||||
|
@ -995,8 +1002,7 @@ void Compare()
|
|||
std::allocator<unicode::UTF16Char>,
|
||||
UTF16Encoding<Storage>
|
||||
> my_string;
|
||||
static my_string sample;
|
||||
const my_string tested(Test(sample, 1, false));
|
||||
const my_string tested(Test<my_string>(false));
|
||||
assert(tested.size() == reference.size());
|
||||
//assert(std::string(tested.data(), tested.size()) == reference);
|
||||
}
|
||||
|
@ -1005,28 +1011,28 @@ void Compare()
|
|||
}
|
||||
|
||||
/// This function tests out a bug found by Jean-Francois Bastien in the find function.
|
||||
void TestBug2536490( void )
|
||||
template<class StringType>
|
||||
void TestBug2536490()
|
||||
{
|
||||
|
||||
my_string bug;
|
||||
std::cout << "Index of '6' in \"" << bug.c_str() << "\": " << bug.find('6') << std::endl;
|
||||
StringType bug;
|
||||
assert(StringType::npos == bug.find('6'));
|
||||
bug = "12345";
|
||||
std::cout << "Index of '6' in \"" << bug.c_str() << "\": " << bug.find('6') << std::endl;
|
||||
assert(StringType::npos == bug.find('6'));
|
||||
bug = "123456";
|
||||
std::cout << "Index of '6' in \"" << bug.c_str() << "\": " << bug.find('6') << std::endl;
|
||||
assert(5 == bug.find('6'));
|
||||
bug = "12345";
|
||||
std::cout << "Index of '6' in \"" << bug.c_str() << "\": " << bug.find('6') << std::endl;
|
||||
assert(StringType::npos == bug.find('6'));
|
||||
|
||||
bug = "12345";
|
||||
std::cout << "Index of '123' in \"" << bug.c_str() << "\": " << bug.find("123") << std::endl;
|
||||
assert(0 == bug.find("123"));
|
||||
bug = "12345";
|
||||
std::cout << "Index of '12345' in \"" << bug.c_str() << "\": " << bug.find("12345") << std::endl;
|
||||
assert(0 == bug.find("12345"));
|
||||
bug = "12345";
|
||||
std::cout << "Index of '345' in \"" << bug.c_str() << "\": " << bug.find("345") << std::endl;
|
||||
assert(2 == bug.find("345"));
|
||||
bug = "123456";
|
||||
std::cout << "Index of '456' in \"" << bug.c_str() << "\": " << bug.find("456") << std::endl;
|
||||
assert(3 == bug.find("456"));
|
||||
bug = "12345";
|
||||
std::cout << "Index of '456' in \"" << bug.c_str() << "\": " << bug.find("456") << std::endl;
|
||||
assert(StringType::npos == bug.find("456"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1059,8 +1065,20 @@ int main()
|
|||
*/
|
||||
int main()
|
||||
{
|
||||
TestBug2536490();
|
||||
using namespace StringsToTest;
|
||||
|
||||
TestBug2536490<std::string>();
|
||||
TestBug2536490<my_string_SimpleStorage>();
|
||||
TestBug2536490<my_string_AllocatorStorage>();
|
||||
TestBug2536490<my_string_MallocatorStorage>();
|
||||
TestBug2536490<my_string_VectorStorage>();
|
||||
TestBug2536490<my_string_SmallStringSimple>();
|
||||
TestBug2536490<my_string_SmallStringVector>();
|
||||
TestBug2536490<my_string_CowSimple>();
|
||||
TestBug2536490<my_string_CowAllocator>();
|
||||
|
||||
srand(unsigned(time(0)));
|
||||
Compare();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue