|
From: <jfb...@us...> - 2009-03-02 19:43:54
|
Revision: 991
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=991&view=rev
Author: jfbastien
Date: 2009-03-02 19:43:49 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
Refactor.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-02 16:02:51 UTC (rev 990)
+++ trunk/test/flex_string/main.cpp 2009-03-02 19:43:49 UTC (rev 991)
@@ -36,22 +36,70 @@
#include <cstdio>
#include <cstring>
#include <ctime>
+
using namespace std;
-typedef flex_string<
+
+namespace StringsToTest
+{
+ typedef flex_string<
char,
std::char_traits<char>,
std::allocator<char>,
- AllocatorStringStorage<char, std::allocator<char> >
-> my_string;
+ SimpleStringStorage<char, std::allocator<char> >
+ > my_string_SimpleStorage;
-template class flex_string<
+ 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,770 +146,769 @@
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;
- ++functionSelector;
- currentTest = functionSelector % 95;
- //std::cout << currentTest <<"\n";
- switch (currentTest)
- {
- case 0:
- // test default constructor 21.3.1
- return String();
- break;
- case 1:
- // test copy constructor 21.3.1
- {
- const size_type pos = random(0, test.size());
- String s(test, pos, random(0, static_cast<typename String::size_type>(test.size() - pos)));
- test = s;
- }
- break;
- case 2:
- // test constructor 21.3.1
- {
- const size_type
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
- String s(test.c_str() + pos, n);
- test = s;
- }
- break;
- case 3:
- // test constructor 21.3.1
- {
- const size_type pos = random(0, test.size());
- String s(test.c_str() + pos);
- test = s;
- }
- break;
- case 4:
- // test assignment 21.3.1
- {
- String s(random(0, 1000), '\0');
- size_type i = 0;
- for (; i != s.size(); ++i)
- {
- s[i] = random('a', 'z');
- }
- test = s;
- }
- break;
- case 5:
- // test assignment 21.3.1
- {
- String s(random(0, 1000), '\0');
- size_type i = 0;
- for (; i != s.size(); ++i)
- {
- s[i] = random('a', 'z');
- }
- test = s.c_str();
- }
- break;
- case 6:
- // test aliased assignment 21.3.1
- {
- const size_t pos = random(0, test.size());
- if (avoidAliasing)
- {
- test = String(test.c_str() + pos);
- }
- else
- {
- test = test.c_str() + pos;
- }
- }
- break;
- case 7:
- // test assignment 21.3.1
- test = random('a', 'z');
- break;
- case 8:
- // exercise iterators 21.3.2
- test.begin();
- test.end();
- test.rbegin();
- test.rend();
- break;
- case 9:
- // exercise capacity 21.3.3
- test.size();
- test.length();
- test.max_size();
- test.capacity();
- break;
- case 10:
- // test resize
- test.resize(random(0, test.size()), random('a', 'z'));
- break;
- case 11:
- // test resize with 1 arg
- test.resize(random(0, test.size()));
- break;
- case 12:
- // test reserve
- test.reserve(random(0, 1000));
- break;
- case 13:
- // test clear
- test.clear(); // skip because std::string doesn't support it
- break;
- case 14:
- // exercise empty
- {
- const char* kEmptyString = "empty";
- const char* kNonEmptyString = "not empty";
- if (test.empty()) test = "empty";
- else test = "not empty";
- // the above assignments don't work yet; use iterator assign
- if (test.empty()) test = String(kEmptyString, kEmptyString + strlen(kEmptyString));
- else test = String(kNonEmptyString, kNonEmptyString + strlen(kNonEmptyString));
- }
- break;
- case 15:
- // exercise element access 21.3.4
- if(!test.empty())
- {
- test[random(0, test.size() - 1)];
- test.at(random(0, test.size() - 1));
- }
- break;
- case 16:
- // 21.3.5 modifiers
- test += RandomString(&test, maxString);
- break;
- case 17:
- // aliasing modifiers
- test += test;
- break;
- case 18:
- // 21.3.5 modifiers
- test += RandomString(&test, maxString).c_str();
- break;
- case 19:
- // aliasing modifiers
- if (avoidAliasing)
- {
- test += String(test.c_str() + random(0, test.size()));
- }
- else
- {
- test += test.c_str() + random(0, test.size());
- }
- break;
- case 20:
- // 21.3.5 modifiers
- test += random('a', 'z');
- break;
- case 21:
- // 21.3.5 modifiers
- test.append(RandomString(&test, maxString));
- break;
- case 22:
- // 21.3.5 modifiers
- {
- String s(RandomString(&test, maxString));
- test.append(s, random(0, s.size()), random(0, maxString));
- }
- break;
- case 23:
- // 21.3.5 modifiers
- {
- String s = RandomString(&test, maxString);
- test.append(s.c_str(), random(0, s.size()));
- }
- break;
- case 24:
- // 21.3.5 modifiers
- test.append(RandomString(&test, maxString).c_str());
- break;
- case 25:
- // 21.3.5 modifiers
- test.append(random(0, maxString), random('a', 'z'));
- break;
- case 26:
- {
- std::list<char> lst(RandomList(maxString));
- test.append(lst.begin(), lst.end());
- }
- break;
- case 27:
- // 21.3.5 modifiers
- // skip push_back, Dinkumware doesn't support it
- test.push_back(random('a', 'z'));
- break;
- case 28:
- // 21.3.5 modifiers
- test.assign(RandomString(&test, maxString));
- break;
- case 29:
- // 21.3.5 modifiers
- {
- String str = RandomString(&test, maxString);
- test.assign(str, random(0, str.size()), random(0, maxString));
- }
- break;
- case 30:
- // 21.3.5 modifiers
- {
- String str = RandomString(&test, maxString);
- test.assign(str.c_str(), random(0, str.size()));
- }
- break;
- case 31:
- // 21.3.5 modifiers
- test.assign(RandomString(&test, maxString).c_str());
- break;
- case 32:
- // 21.3.5 modifiers
- test.assign(random(0, maxString), random('a', 'z'));
- break;
- case 33:
- // 21.3.5 modifiers
- {
- // skip, Dinkumware doesn't support it
- std::list<char> lst(RandomList(maxString));
- test.assign(lst.begin(), lst.end());
- }
- break;
- case 34:
- // 21.3.5 modifiers
- test.insert(random(0, test.size()), RandomString(&test, maxString));
- break;
- case 35:
- // 21.3.5 modifiers
- {
- String str = RandomString(&test, maxString);
- test.insert(random(0, test.size()),
- str, random(0, str.size()),
- random(0, maxString));
- }
- break;
- case 36:
- // 21.3.5 modifiers
- {
- String str = RandomString(&test, maxString);
- test.insert(random(0, test.size()),
- str.c_str(), random(0, str.size()));
- }
- break;
- case 37:
- // 21.3.5 modifiers
- test.insert(random(0, test.size()),
- RandomString(&test, maxString).c_str());
- break;
- case 38:
- // 21.3.5 modifiers
- test.insert(random(0, test.size()),
- random(0, maxString), random('a', 'z'));
- break;
- case 39:
- // 21.3.5 modifiers
- test.insert(test.begin() + random(0, test.size()),
- random('a', 'z'));
- break;
- case 40:
- // 21.3.5 modifiers
- {
- std::list<char> lst(RandomList(maxString));
- test.insert(test.begin() + random(0, test.size()),
- lst.begin(), lst.end());
- }
- break;
- case 41:
- // 21.3.5 modifiers
- test.erase(random(0, test.size()), random(0, maxString));
- break;
- case 42:
- // 21.3.5 modifiers
- if(!test.empty())
- test.erase(test.begin() + random(0, test.size()));
- break;
- case 43:
- // 21.3.5 modifiers
- {
- const typename String::iterator i = test.begin() + random(0, test.size());
- test.erase(i, i + random(0, size_t(test.end() - i)));
- }
- break;
- case 44:
- // 21.3.5 modifiers
- {
- const typename String::size_type pos = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(pos, random(0, test.size() - pos),
- String(test));
- }
- else
- {
- test.replace(pos, random(0, test.size() - pos), test);
- }
- }
- break;
- case 45:
- // 21.3.5 modifiers
- {
- const typename String::size_type pos = random(0, test.size());
- test.replace(pos, pos + random(0, test.size() - pos),
- RandomString(&test, maxString));
- }
- break;
- case 46:
- // 21.3.5 modifiers
- {
- const size_type
- pos1 = random(0, test.size()),
- pos2 = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- String(test),
- pos2, pos2 + random(0, test.size() - pos2));
- }
- else
- {
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- test, pos2, pos2 + random(0, test.size() - pos2));
- }
- }
- break;
- case 47:
- // 21.3.5 modifiers
- {
- const size_type pos1 = random(0, test.size());
- String str = RandomString(&test, maxString);
- const size_type pos2 = random(0, str.size());
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- str, pos2, pos2 + random(0, str.size() - pos2));
- }
- break;
- case 48:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(pos, random(0, test.size() - pos),
- String(test).c_str(), test.size());
- }
- else
- {
- test.replace(pos, random(0, test.size() - pos),
- test.c_str(), test.size());
- }
- }
- break;
- case 49:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- String str = RandomString(&test, maxString);
- test.replace(pos, pos + random(0, test.size() - pos),
- str.c_str(), str.size());
- }
- break;
- case 50:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- String str = RandomString(&test, maxString);
- test.replace(pos, pos + random(0, test.size() - pos),
- str.c_str());
- }
- break;
- case 51:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
- random(0, maxString), random('a', 'z'));
- }
- break;
- case 52:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test));
- }
- else
- {
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- test);
- }
- }
- break;
- case 53:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test).c_str(),
- test.size() - random(0, test.size()));
- }
- else
- {
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- test.c_str(),
- test.size() - random(0, test.size()));
- }
- }
- break;
- case 54:
- // 21.3.5 modifiers
- {
- const size_type
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
- typename String::iterator b = test.begin();
- const String str = RandomString(&test, maxString);
- const typename String::value_type* s = str.c_str();
- test.replace(
- b + pos,
- b + pos + n,
- s);
- }
- break;
- case 55:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- random(0, maxString), random('a', 'z'));
- }
- break;
- case 56:
- // 21.3.5 modifiers
- {
- std::vector<typename String::value_type>
- vec(random(0, maxString));
- test.copy(
- &vec[0],
- vec.size(),
- random(0, test.size()));
- }
- break;
- case 57:
- // 21.3.5 modifiers
- RandomString(&test, maxString).swap(test);
- break;
- case 58:
- // 21.3.6 string operations
- // exercise c_str() and data()
- assert(test.c_str() == test.data());
- // exercise get_allocator()
- assert(test.get_allocator() ==
- RandomString(&test, maxString).get_allocator());
- break;
- case 59:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.find(str, random(0, test.size())));
- }
- break;
- case 60:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.find(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 61:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.find(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 62:
- // 21.3.6 string operations
- Num2String(test, test.find(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 63:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.rfind(str, random(0, test.size())));
- }
- break;
- case 64:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.rfind(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 65:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.rfind(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 66:
- // 21.3.6 string operations
- Num2String(test, test.rfind(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 67:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_of(str,
- random(0, test.size())));
- }
- break;
- case 68:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 69:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_of(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 70:
- // 21.3.6 string operations
- Num2String(test, test.find_first_of(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 71:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_of(str,
- random(0, test.size())));
- }
- break;
- case 72:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 73:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_of(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 74:
- // 21.3.6 string operations
- Num2String(test, test.find_last_of(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 75:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_not_of(str,
- random(0, test.size())));
- }
- break;
- case 76:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_not_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 77:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_not_of(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 78:
- // 21.3.6 string operations
- Num2String(test, test.find_first_not_of(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 79:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_not_of(str,
- random(0, test.size())));
- }
- break;
- case 80:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_not_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 81:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_not_of(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 82:
- // 21.3.6 string operations
- Num2String(test, test.find_last_not_of(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 83:
- // 21.3.6 string operations
- test = test.substr(random(0, test.size()), random(0, test.size()));
- break;
- case 84:
- {
- int tristate = test.compare(RandomString(&test, maxString));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 85:
- {
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- RandomString(&test, maxString));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 86:
- {
- String str = RandomString(&test, maxString);
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- str,
- random(0, str.size()),
- random(0, str.size()));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 87:
- {
- int tristate = test.compare(
- RandomString(&test, maxString).c_str());
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 88:
- {
- String str = RandomString(&test, maxString);
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- str.c_str(),
- random(0, str.size()));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 89:
- test = RandomString(&test, maxString) +
- RandomString(&test, maxString);
- break;
- case 90:
- test = RandomString(&test, maxString).c_str() +
- RandomString(&test, maxString);
- break;
- case 91:
- test = typename String::value_type(random('a', 'z')) +
- RandomString(&test, maxString);
- break;
- case 92:
- test = RandomString(&test, maxString) +
- RandomString(&test, maxString).c_str();
- break;
- case 93:
- test = RandomString(&test, maxString) +
- RandomString(&test, maxString).c_str();
- break;
- case 94:
- test = RandomString(&test, maxString) +
- typename String::value_type(random('a', 'z'));
- break;
- default:
- assert(((functionSelector + 1) % 96) == 0);
- break;
- }
- }
+ test = RandomString(&test, maxString);
+
+ static unsigned int functionSelector = 0;
+ ++functionSelector;
+ currentTest = functionSelector % 95;
+ //std::cout << currentTest <<"\n";
+ switch (currentTest)
+ {
+ case 0:
+ // test default constructor 21.3.1
+ return String();
+ break;
+ case 1:
+ // test copy constructor 21.3.1
+ {
+ const size_type pos = random(0, test.size());
+ String s(test, pos, random(0, static_cast<typename String::size_type>(test.size() - pos)));
+ test = s;
+ }
+ break;
+ case 2:
+ // test constructor 21.3.1
+ {
+ const size_type
+ pos = random(0, test.size()),
+ n = random(0, test.size() - pos);
+ String s(test.c_str() + pos, n);
+ test = s;
+ }
+ break;
+ case 3:
+ // test constructor 21.3.1
+ {
+ const size_type pos = random(0, test.size());
+ String s(test.c_str() + pos);
+ test = s;
+ }
+ break;
+ case 4:
+ // test assignment 21.3.1
+ {
+ String s(random(0, 1000), '\0');
+ size_type i = 0;
+ for (; i != s.size(); ++i)
+ {
+ s[i] = random('a', 'z');
+ }
+ test = s;
+ }
+ break;
+ case 5:
+ // test assignment 21.3.1
+ {
+ String s(random(0, 1000), '\0');
+ size_type i = 0;
+ for (; i != s.size(); ++i)
+ {
+ s[i] = random('a', 'z');
+ }
+ test = s.c_str();
+ }
+ break;
+ case 6:
+ // test aliased assignment 21.3.1
+ {
+ const size_t pos = random(0, test.size());
+ if (avoidAliasing)
+ {
+ test = String(test.c_str() + pos);
+ }
+ else
+ {
+ test = test.c_str() + pos;
+ }
+ }
+ break;
+ case 7:
+ // test assignment 21.3.1
+ test = random('a', 'z');
+ break;
+ case 8:
+ // exercise iterators 21.3.2
+ test.begin();
+ test.end();
+ test.rbegin();
+ test.rend();
+ break;
+ case 9:
+ // exercise capacity 21.3.3
+ test.size();
+ test.length();
+ test.max_size();
+ test.capacity();
+ break;
+ case 10:
+ // test resize
+ test.resize(random(0, test.size()), random('a', 'z'));
+ break;
+ case 11:
+ // test resize with 1 arg
+ test.resize(random(0, test.size()));
+ break;
+ case 12:
+ // test reserve
+ test.reserve(random(0, 1000));
+ break;
+ case 13:
+ // test clear
+ test.clear(); // skip because std::string doesn't support it
+ break;
+ case 14:
+ // exercise empty
+ {
+ const char* kEmptyString = "empty";
+ const char* kNonEmptyString = "not empty";
+ if (test.empty()) test = "empty";
+ else test = "not empty";
+ // the above assignments don't work yet; use iterator assign
+ if (test.empty()) test = String(kEmptyString, kEmptyString + strlen(kEmptyString));
+ else test = String(kNonEmptyString, kNonEmptyString + strlen(kNonEmptyString));
+ }
+ break;
+ case 15:
+ // exercise element access 21.3.4
+ if(!test.empty())
+ {
+ test[random(0, test.size() - 1)];
+ test.at(random(0, test.size() - 1));
+ }
+ break;
+ case 16:
+ // 21.3.5 modifiers
+ test += RandomString(&test, maxString);
+ break;
+ case 17:
+ // aliasing modifiers
+ test += test;
+ break;
+ case 18:
+ // 21.3.5 modifiers
+ test += RandomString(&test, maxString).c_str();
+ break;
+ case 19:
+ // aliasing modifiers
+ if (avoidAliasing)
+ {
+ test += String(test.c_str() + random(0, test.size()));
+ }
+ else
+ {
+ test += test.c_str() + random(0, test.size());
+ }
+ break;
+ case 20:
+ // 21.3.5 modifiers
+ test += random('a', 'z');
+ break;
+ case 21:
+ // 21.3.5 modifiers
+ test.append(RandomString(&test, maxString));
+ break;
+ case 22:
+ // 21.3.5 modifiers
+ {
+ String s(RandomString(&test, maxString));
+ test.append(s, random(0, s.size()), random(0, maxString));
+ }
+ break;
+ case 23:
+ // 21.3.5 modifiers
+ {
+ String s = RandomString(&test, maxString);
+ test.append(s.c_str(), random(0, s.size()));
+ }
+ break;
+ case 24:
+ // 21.3.5 modifiers
+ test.append(RandomString(&test, maxString).c_str());
+ break;
+ case 25:
+ // 21.3.5 modifiers
+ test.append(random(0, maxString), random('a', 'z'));
+ break;
+ case 26:
+ {
+ std::list<char> lst(RandomList(maxString));
+ test.append(lst.begin(), lst.end());
+ }
+ break;
+ case 27:
+ // 21.3.5 modifiers
+ // skip push_back, Dinkumware doesn't support it
+ test.push_back(random('a', 'z'));
+ break;
+ case 28:
+ // 21.3.5 modifiers
+ test.assign(RandomString(&test, maxString));
+ break;
+ case 29:
+ // 21.3.5 modifiers
+ {
+ String str = RandomString(&test, maxString);
+ test.assign(str, random(0, str.size()), random(0, maxString));
+ }
+ break;
+ case 30:
+ // 21.3.5 modifiers
+ {
+ String str = RandomString(&test, maxString);
+ test.assign(str.c_str(), random(0, str.size()));
+ }
+ break;
+ case 31:
+ // 21.3.5 modifiers
+ test.assign(RandomString(&test, maxString).c_str());
+ break;
+ case 32:
+ // 21.3.5 modifiers
+ test.assign(random(0, maxString), random('a', 'z'));
+ break;
+ case 33:
+ // 21.3.5 modifiers
+ {
+ // skip, Dinkumware doesn't support it
+ std::list<char> lst(RandomList(maxString));
+ test.assign(lst.begin(), lst.end());
+ }
+ break;
+ case 34:
+ // 21.3.5 modifiers
+ test.insert(random(0, test.size()), RandomString(&test, maxString));
+ break;
+ case 35:
+ // 21.3.5 modifiers
+ {
+ String str = RandomString(&test, maxString);
+ test.insert(random(0, test.size()),
+ str, random(0, str.size()),
+ random(0, maxString));
+ }
+ break;
+ case 36:
+ // 21.3.5 modifiers
+ {
+ String str = RandomString(&test, maxString);
+ test.insert(random(0, test.size()),
+ str.c_str(), random(0, str.size()));
+ }
+ break;
+ case 37:
+ // 21.3.5 modifiers
+ test.insert(random(0, test.size()),
+ RandomString(&test, maxString).c_str());
+ break;
+ case 38:
+ // 21.3.5 modifiers
+ test.insert(random(0, test.size()),
+ random(0, maxString), random('a', 'z'));
+ break;
+ case 39:
+ // 21.3.5 modifiers
+ test.insert(test.begin() + random(0, test.size()),
+ random('a', 'z'));
+ break;
+ case 40:
+ // 21.3.5 modifiers
+ {
+ std::list<char> lst(RandomList(maxString));
+ test.insert(test.begin() + random(0, test.size()),
+ lst.begin(), lst.end());
+ }
+ break;
+ case 41:
+ // 21.3.5 modifiers
+ test.erase(random(0, test.size()), random(0, maxString));
+ break;
+ case 42:
+ // 21.3.5 modifiers
+ if(!test.empty())
+ test.erase(test.begin() + random(0, test.size()));
+ break;
+ case 43:
+ // 21.3.5 modifiers
+ {
+ const typename String::iterator i = test.begin() + random(0, test.size());
+ test.erase(i, i + random(0, size_t(test.end() - i)));
+ }
+ break;
+ case 44:
+ // 21.3.5 modifiers
+ {
+ const typename String::size_type pos = random(0, test.size());
+ if (avoidAliasing)
+ {
+ test.replace(pos, random(0, test.size() - pos),
+ String(test));
+ }
+ else
+ {
+ test.replace(pos, random(0, test.size() - pos), test);
+ }
+ }
+ break;
+ case 45:
+ // 21.3.5 modifiers
+ {
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(pos, pos + random(0, test.size() - pos),
+ RandomString(&test, maxString));
+ }
+ break;
+ case 46:
+ // 21.3.5 modifiers
+ {
+ const size_type
+ pos1 = random(0, test.size()),
+ pos2 = random(0, test.size());
+ if (avoidAliasing)
+ {
+ test.replace(pos1, pos1 + random(0, test.size() - pos1),
+ String(test),
+ pos2, pos2 + random(0, test.size() - pos2));
+ }
+ else
+ {
+ test.replace(pos1, pos1 + random(0, test.size() - pos1),
+ test, pos2, pos2 + random(0, test.size() - pos2));
+ }
+ }
+ break;
+ case 47:
+ // 21.3.5 modifiers
+ {
+ const size_type pos1 = random(0, test.size());
+ String str = RandomString(&test, maxString);
+ const size_type pos2 = random(0, str.size());
+ test.replace(pos1, pos1 + random(0, test.size() - pos1),
+ str, pos2, pos2 + random(0, str.size() - pos2));
+ }
+ break;
+ case 48:
+ // 21.3.5 modifiers
+ {
+ const size_type pos = random(0, test.size());
+ if (avoidAliasing)
+ {
+ test.replace(pos, random(0, test.size() - pos),
+ String(test).c_str(), test.size());
+ }
+ else
+ {
+ test.replace(pos, random(0, test.size() - pos),
+ test.c_str(), test.size());
+ }
+ }
+ break;
+ case 49:
+ // 21.3.5 modifiers
+ {
+ const size_type pos = random(0, test.size());
+ String str = RandomString(&test, maxString);
+ test.replace(pos, pos + random(0, test.size() - pos),
+ str.c_str(), str.size());
+ }
+ break;
+ case 50:
+ // 21.3.5 modifiers
+ {
+ const size_type pos = random(0, test.size());
+ String str = RandomString(&test, maxString);
+ test.replace(pos, pos + random(0, test.size() - pos),
+ str.c_str());
+ }
+ break;
+ case 51:
+ // 21.3.5 modifiers
+ {
+ const size_type pos = random(0, test.size());
+ test.replace(pos, random(0, test.size() - pos),
+ random(0, maxString), random('a', 'z'));
+ }
+ break;
+ case 52:
+ // 21.3.5 modifiers
+ {
+ const size_type pos = random(0, test.size());
+ if (avoidAliasing)
+ {
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ String(test));
+ }
+ else
+ {
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ test);
+ }
+ }
+ break;
+ case 53:
+ // 21.3.5 modifiers
+ {
+ const size_type pos = random(0, test.size());
+ if (avoidAliasing)
+ {
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ String(test).c_str(),
+ test.size() - random(0, test.size()));
+ }
+ else
+ {
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ test.c_str(),
+ test.size() - random(0, test.size()));
+ }
+ }
+ break;
+ case 54:
+ // 21.3.5 modifiers
+ {
+ const size_type
+ pos = random(0, test.size()),
+ n = random(0, test.size() - pos);
+ typename String::iterator b = test.begin();
+ const String str = RandomString(&test, maxString);
+ const typename String::value_type* s = str.c_str();
+ test.replace(
+ b + pos,
+ b + pos + n,
+ s);
+ }
+ break;
+ case 55:
+ // 21.3.5 modifiers
+ {
+ const size_type pos = random(0, test.size());
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ random(0, maxString), random('a', 'z'));
+ }
+ break;
+ case 56:
+ // 21.3.5 modifiers
+ {
+ std::vector<typename String::value_type>
+ vec(random(0, maxString));
+ test.copy(
+ &vec[0],
+ vec.size(),
+ random(0, test.size()));
+ }
+ break;
+ case 57:
+ // 21.3.5 modifiers
+ RandomString(&test, maxString).swap(test);
+ break;
+ case 58:
+ // 21.3.6 string operations
+ // exercise c_str() and data()
+ assert(test.c_str() == test.data());
+ // exercise get_allocator()
+ assert(test.get_allocator() ==
+ RandomString(&test, maxString).get_allocator());
+ break;
+ case 59:
+ // 21.3.6 string operations
+ {
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.find(str, random(0, test.size())));
+ }
+ break;
+ case 60:
+ // 21.3.6 string operations
+ {
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.find(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ }
+ break;
+ case 61:
+ // 21.3.6 string operations
+ {
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.find(str.c_str(),
+ random(0, test.size())));
+ }
+ break;
+ case 62:
+ // 21.3.6 string operations
+ Num2String(test, test.find(
+ random('a', 'z'),
+ random(0, test.size())));
+ break;
+ case 63:
+ // 21.3.6 string operations
+ {
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.rfind(str, random(0, test.size())));
+ }
+ break;
+ case 64:
+ // 21.3.6 string operations
+ {
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.rfind(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ }
+ break;
+ case 65:
+ // 21.3.6 string operations
+ {
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ Num2String(test, test.rfind(str.c_str(),
+ random(0, test.size())));
+ }
+ break;
+ case 66:
+ // 21.3.6 string operations
+ Num2String(test, test.rfind(
+ random('a', 'z'),
+ random(0, test.size())));
+ break;
+ case 67:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_first_of(str,
+ random(0, test.size())));
+ }
+ break;
+ case 68:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_first_of(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ }
+ break;
+ case 69:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_first_of(str.c_str(),
+ random(0, test.size())));
+ }
+ break;
+ case 70:
+ // 21.3.6 string operations
+ Num2String(test, test.find_first_of(
+ random('a', 'z'),
+ random(0, test.size())));
+ break;
+ case 71:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_last_of(str,
+ random(0, test.size())));
+ }
+ break;
+ case 72:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_last_of(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ }
+ break;
+ case 73:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_last_of(str.c_str(),
+ random(0, test.size())));
+ }
+ break;
+ case 74:
+ // 21.3.6 string operations
+ Num2String(test, test.find_last_of(
+ random('a', 'z'),
+ random(0, test.size())));
+ break;
+ case 75:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_first_not_of(str,
+ random(0, test.size())));
+ }
+ break;
+ case 76:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_first_not_of(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ }
+ break;
+ case 77:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_first_not_of(str.c_str(),
+ random(0, test.size())));
+ }
+ break;
+ case 78:
+ // 21.3.6 string operations
+ Num2String(test, test.find_first_not_of(
+ random('a', 'z'),
+ random(0, test.size())));
+ break;
+ case 79:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_last_not_of(str,
+ random(0, test.size())));
+ }
+ break;
+ case 80:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_last_not_of(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ }
+ break;
+ case 81:
+ // 21.3.6 string operations
+ {
+ String str = RandomString(&test, maxString);
+ Num2String(test, test.find_last_not_of(str.c_str(),
+ random(0, test.size())));
+ }
+ break;
+ case 82:
+ // 21.3.6 string operations
+ Num2String(test, test.find_last_not_of(
+ random('a', 'z'),
+ random(0, test.size())));
+ break;
+ case 83:
+ // 21.3.6 string operations
+ test = test.substr(random(0, test.size()), random(0, test.size()));
+ break;
+ case 84:
+ {
+ int tristate = test.compare(RandomString(&test, maxString));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ Num2String(test, tristate);
+ }
+ break;
+ case 85:
+ {
+ int tristate = test.compare(
+ random(0, test.size()),
+ random(0, test.size()),
+ RandomString(&test, maxString));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ Num2String(test, tristate);
+ }
+ break;
+ case 86:
+ {
+ String str = RandomString(&test, maxString);
+ int tristate = test.compare(
+ random(0, test.size()),
+ random(0, test.size()),
+ str,
+ random(0, str.size()),
+ random(0, str.size()));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ Num2String(test, tristate);
+ }
+ break;
+ case 87:
+ {
+ int tristate = test.compare(
+ RandomString(&test, maxString).c_str());
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ Num2String(test, tristate);
+ }
+ break;
+ case 88:
+ {
+ String str = RandomString(&test, maxString);
+ int tristate = test.compare(
+ random(0, test.size()),
+ random(0, test.size()),
+ str.c_str(),
+ random(0, str.size()));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ Num2String(test, tristate);
+ }
+ break;
+ case 89:
+ test = RandomString(&test, maxString) +
+ RandomString(&test, maxString);
+ break;
+ case 90:
+ test = RandomString(&test, maxString).c_str() +
+ RandomString(&test, maxString);
+ break;
+ case 91:
+ test = typename String::value_type(random('a', 'z')) +
+ RandomString(&test, maxString);
+ break;
+ case 92:
+ test = RandomString(&test, maxString) +
+ RandomString(&test, maxString).c_str();
+ break;
+ case 93:
+ test = RandomString(&test, maxString) +
+ RandomString(&test, maxString).c_str();
+ break;
+ case 94:
+ test = RandomString(&test, maxString) +
+ typename String::value_type(random('a', 'z'));
+ break;
+ default:
+ assert(((functionSelector + 1) % 96) == 0);
+ break;
+ }
+
return test;
}
@@ -893,95 +940,55 @@
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);
+ const my_string_SmallStringSimple tested(Test<my_string_SmallStringSimple>(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_SmallStringVector tested(Test<my_string_SmallStringVector>(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_CowSimple tested(Test<my_string_CowSimple>(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_CowAllocator tested(Test<my_string_CowAllocator>(false));
checkResults(reference, tested);
}
/*
@@ -995,8 +1002,7 @@
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 @@
}
/// 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()
{
- 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;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest ...
[truncated message content] |