|
From: <ric...@us...> - 2009-01-26 02:21:13
|
Revision: 949
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=949&view=rev
Author: rich_sposato
Date: 2009-01-26 02:04:40 +0000 (Mon, 26 Jan 2009)
Log Message:
-----------
Added fix for bug.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-01-26 01:55:50 UTC (rev 948)
+++ trunk/test/flex_string/main.cpp 2009-01-26 02:04:40 UTC (rev 949)
@@ -1003,6 +1003,32 @@
*/
}
}
+
+/// This function tests out a bug found by Jean-Francois Bastien in the find function.
+void TestBug2536490( void )
+{
+
+ my_string bug;
+ std::cout << "Index of '6' in \"" << bug.c_str() << "\": " << bug.find('6') << std::endl;
+ bug = "12345";
+ std::cout << "Index of '6' in \"" << bug.c_str() << "\": " << bug.find('6') << std::endl;
+ bug = "123456";
+ std::cout << "Index of '6' in \"" << bug.c_str() << "\": " << bug.find('6') << std::endl;
+ bug = "12345";
+ std::cout << "Index of '6' in \"" << bug.c_str() << "\": " << bug.find('6') << std::endl;
+
+ bug = "12345";
+ std::cout << "Index of '123' in \"" << bug.c_str() << "\": " << bug.find("123") << std::endl;
+ bug = "12345";
+ std::cout << "Index of '12345' in \"" << bug.c_str() << "\": " << bug.find("12345") << std::endl;
+ bug = "12345";
+ std::cout << "Index of '345' in \"" << bug.c_str() << "\": " << bug.find("345") << std::endl;
+ bug = "123456";
+ std::cout << "Index of '456' in \"" << bug.c_str() << "\": " << bug.find("456") << std::endl;
+ bug = "12345";
+ std::cout << "Index of '456' in \"" << bug.c_str() << "\": " << bug.find("456") << std::endl;
+}
+
/*
#include <string>
#include <limits>
@@ -1033,6 +1059,7 @@
*/
int main()
{
+ TestBug2536490();
srand(unsigned(time(0)));
Compare();
return 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-02 16:02:53
|
Revision: 990
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=990&view=rev
Author: jfbastien
Date: 2009-03-02 16:02:51 +0000 (Mon, 02 Mar 2009)
Log Message:
-----------
Fix function selector, some tests weren't being run.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-02 14:54:16 UTC (rev 989)
+++ trunk/test/flex_string/main.cpp 2009-03-02 16:02:51 UTC (rev 990)
@@ -36,7 +36,7 @@
#include <cstdio>
#include <cstring>
#include <ctime>
-using namespace std;
+using namespace std;
typedef flex_string<
char,
@@ -87,7 +87,7 @@
std::list<char> RandomList(unsigned int maxSize)
{
std::list<char> lst(random(0u, maxSize));
- std::list<char>::iterator i = lst.begin();
+ std::list<char>::iterator i = lst.begin();
for (; i != lst.end(); ++i)
{
*i = random('a', 'z');
@@ -110,7 +110,7 @@
static unsigned int functionSelector = 0;
++functionSelector;
- currentTest = functionSelector % 90;
+ currentTest = functionSelector % 95;
//std::cout << currentTest <<"\n";
switch (currentTest)
{
@@ -128,7 +128,7 @@
break;
case 2:
// test constructor 21.3.1
- {
+ {
const size_type
pos = random(0, test.size()),
n = random(0, test.size() - pos);
@@ -138,7 +138,7 @@
break;
case 3:
// test constructor 21.3.1
- {
+ {
const size_type pos = random(0, test.size());
String s(test.c_str() + pos);
test = s;
@@ -342,8 +342,8 @@
// 21.3.5 modifiers
{
String str = RandomString(&test, maxString);
- test.insert(random(0, test.size()),
- str, random(0, str.size()),
+ test.insert(random(0, test.size()),
+ str, random(0, str.size()),
random(0, maxString));
}
break;
@@ -351,34 +351,34 @@
// 21.3.5 modifiers
{
String str = RandomString(&test, maxString);
- test.insert(random(0, test.size()),
+ 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()),
+ test.insert(random(0, test.size()),
RandomString(&test, maxString).c_str());
break;
case 38:
// 21.3.5 modifiers
- test.insert(random(0, test.size()),
+ 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()),
+ 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()),
+ test.insert(test.begin() + random(0, test.size()),
lst.begin(), lst.end());
}
break;
- case 41:
+ case 41:
// 21.3.5 modifiers
test.erase(random(0, test.size()), random(0, maxString));
break;
@@ -400,7 +400,7 @@
const typename String::size_type pos = random(0, test.size());
if (avoidAliasing)
{
- test.replace(pos, random(0, test.size() - pos),
+ test.replace(pos, random(0, test.size() - pos),
String(test));
}
else
@@ -413,25 +413,25 @@
// 21.3.5 modifiers
{
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, pos + random(0, test.size() - pos),
+ test.replace(pos, pos + random(0, test.size() - pos),
RandomString(&test, maxString));
}
break;
case 46:
// 21.3.5 modifiers
{
- const size_type
+ 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),
+ 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.replace(pos1, pos1 + random(0, test.size() - pos1),
test, pos2, pos2 + random(0, test.size() - pos2));
}
}
@@ -442,7 +442,7 @@
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),
+ test.replace(pos1, pos1 + random(0, test.size() - pos1),
str, pos2, pos2 + random(0, str.size() - pos2));
}
break;
@@ -452,12 +452,12 @@
const size_type pos = random(0, test.size());
if (avoidAliasing)
{
- test.replace(pos, random(0, test.size() - pos),
+ test.replace(pos, random(0, test.size() - pos),
String(test).c_str(), test.size());
}
else
{
- test.replace(pos, random(0, test.size() - pos),
+ test.replace(pos, random(0, test.size() - pos),
test.c_str(), test.size());
}
}
@@ -467,7 +467,7 @@
{
const size_type pos = random(0, test.size());
String str = RandomString(&test, maxString);
- test.replace(pos, pos + random(0, test.size() - pos),
+ test.replace(pos, pos + random(0, test.size() - pos),
str.c_str(), str.size());
}
break;
@@ -476,7 +476,7 @@
{
const size_type pos = random(0, test.size());
String str = RandomString(&test, maxString);
- test.replace(pos, pos + random(0, test.size() - pos),
+ test.replace(pos, pos + random(0, test.size() - pos),
str.c_str());
}
break;
@@ -484,7 +484,7 @@
// 21.3.5 modifiers
{
const size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
+ test.replace(pos, random(0, test.size() - pos),
random(0, maxString), random('a', 'z'));
}
break;
@@ -495,15 +495,15 @@
if (avoidAliasing)
{
test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
+ 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.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
test);
}
}
@@ -515,17 +515,17 @@
if (avoidAliasing)
{
test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test).c_str(),
+ 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.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ test.c_str(),
test.size() - random(0, test.size()));
}
}
@@ -533,15 +533,15 @@
case 54:
// 21.3.5 modifiers
{
- const size_type
+ 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,
+ b + pos,
+ b + pos + n,
s);
}
break;
@@ -550,19 +550,19 @@
{
const size_type pos = random(0, test.size());
test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
+ 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>
+ std::vector<typename String::value_type>
vec(random(0, maxString));
test.copy(
- &vec[0],
- vec.size(),
+ &vec[0],
+ vec.size(),
random(0, test.size()));
}
break;
@@ -575,14 +575,14 @@
// exercise c_str() and data()
assert(test.c_str() == test.data());
// exercise get_allocator()
- assert(test.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()),
random(0, test.size()));
Num2String(test, test.find(str, random(0, test.size())));
}
@@ -591,9 +591,9 @@
// 21.3.6 string operations
{
String str = test.substr(
- random(0, test.size()),
+ random(0, test.size()),
random(0, test.size()));
- Num2String(test, test.find(str.c_str(),
+ Num2String(test, test.find(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
@@ -602,23 +602,23 @@
// 21.3.6 string operations
{
String str = test.substr(
- random(0, test.size()),
+ random(0, test.size()),
random(0, test.size()));
- Num2String(test, test.find(str.c_str(),
+ 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('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()),
random(0, test.size()));
Num2String(test, test.rfind(str, random(0, test.size())));
}
@@ -627,9 +627,9 @@
// 21.3.6 string operations
{
String str = test.substr(
- random(0, test.size()),
+ random(0, test.size()),
random(0, test.size()));
- Num2String(test, test.rfind(str.c_str(),
+ Num2String(test, test.rfind(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
@@ -638,23 +638,23 @@
// 21.3.6 string operations
{
String str = test.substr(
- random(0, test.size()),
+ random(0, test.size()),
random(0, test.size()));
- Num2String(test, test.rfind(str.c_str(),
+ 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('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,
+ Num2String(test, test.find_first_of(str,
random(0, test.size())));
}
break;
@@ -662,7 +662,7 @@
// 21.3.6 string operations
{
String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_of(str.c_str(),
+ Num2String(test, test.find_first_of(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
@@ -671,21 +671,21 @@
// 21.3.6 string operations
{
String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_of(str.c_str(),
+ 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('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,
+ Num2String(test, test.find_last_of(str,
random(0, test.size())));
}
break;
@@ -693,7 +693,7 @@
// 21.3.6 string operations
{
String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_of(str.c_str(),
+ Num2String(test, test.find_last_of(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
@@ -702,21 +702,21 @@
// 21.3.6 string operations
{
String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_of(str.c_str(),
+ 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('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,
+ Num2String(test, test.find_first_not_of(str,
random(0, test.size())));
}
break;
@@ -724,7 +724,7 @@
// 21.3.6 string operations
{
String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_not_of(str.c_str(),
+ Num2String(test, test.find_first_not_of(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
@@ -733,21 +733,21 @@
// 21.3.6 string operations
{
String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_not_of(str.c_str(),
+ 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('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,
+ Num2String(test, test.find_last_not_of(str,
random(0, test.size())));
}
break;
@@ -755,7 +755,7 @@
// 21.3.6 string operations
{
String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_not_of(str.c_str(),
+ Num2String(test, test.find_last_not_of(str.c_str(),
random(0, test.size()),
random(0, str.size())));
}
@@ -764,14 +764,14 @@
// 21.3.6 string operations
{
String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_not_of(str.c_str(),
+ 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('a', 'z'),
random(0, test.size())));
break;
case 83:
@@ -789,8 +789,8 @@
case 85:
{
int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
+ random(0, test.size()),
+ random(0, test.size()),
RandomString(&test, maxString));
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
@@ -801,10 +801,10 @@
{
String str = RandomString(&test, maxString);
int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
+ random(0, test.size()),
+ random(0, test.size()),
str,
- random(0, str.size()),
+ random(0, str.size()),
random(0, str.size()));
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
@@ -824,8 +824,8 @@
{
String str = RandomString(&test, maxString);
int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
+ random(0, test.size()),
+ random(0, test.size()),
str.c_str(),
random(0, str.size()));
if (tristate > 0) tristate = 1;
@@ -834,27 +834,27 @@
}
break;
case 89:
- test = RandomString(&test, maxString) +
+ test = RandomString(&test, maxString) +
RandomString(&test, maxString);
break;
case 90:
- test = RandomString(&test, maxString).c_str() +
+ test = RandomString(&test, maxString).c_str() +
RandomString(&test, maxString);
break;
case 91:
- test = typename String::value_type(random('a', 'z')) +
+ test = typename String::value_type(random('a', 'z')) +
RandomString(&test, maxString);
break;
case 92:
- test = RandomString(&test, maxString) +
+ test = RandomString(&test, maxString) +
RandomString(&test, maxString).c_str();
break;
case 93:
- test = RandomString(&test, maxString) +
+ test = RandomString(&test, maxString) +
RandomString(&test, maxString).c_str();
break;
case 94:
- test = RandomString(&test, maxString) +
+ test = RandomString(&test, maxString) +
typename String::value_type(random('a', 'z'));
break;
default:
@@ -889,7 +889,7 @@
for (;;)
{
cout << ++count << '\r';
-
+
unsigned long t = rand(); //time(0);
srand(t);
@@ -1050,9 +1050,9 @@
std_string_t s2(L"A std string");
assert(std::numeric_limits<char_type>::is_specialized);
-
- assert(std::numeric_limits<std_string_t::iterator::value_type>::is_specialized);
- s1.replace<std_string_t::iterator>(s1.begin(), s1.begin(),
+
+ assert(std::numeric_limits<std_string_t::iterator::value_type>::is_specialized);
+ s1.replace<std_string_t::iterator>(s1.begin(), s1.begin(),
s2.begin(),s2.end());
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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)
+ ...
[truncated message content] |
|
From: <jfb...@us...> - 2009-03-03 22:14:59
|
Revision: 994
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=994&view=rev
Author: jfbastien
Date: 2009-03-03 22:14:49 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
Refactor some more. Add tests.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-03 16:29:14 UTC (rev 993)
+++ trunk/test/flex_string/main.cpp 2009-03-03 22:14:49 UTC (rev 994)
@@ -32,14 +32,16 @@
#include <loki/flex/flex_string.h>
-#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
+#include <iostream>
+#include <typeinfo>
+#include <sstream>
+#include <utility>
+#include <vector>
-using namespace std;
-
namespace StringsToTest
{
typedef flex_string<
@@ -100,985 +102,1522 @@
}
-template <class Integral1, class Integral2>
+template<class Integral1, class Integral2>
Integral2 random(Integral1 low, Integral2 up)
{
- Integral2 low2(low);
- assert(up >= low2);
- if (low2 == up) return low;
- Integral2 x = Integral2(low2 + (rand() * (up - low2)) / RAND_MAX);
- assert(x >= low2 && x <= up);
- return x;
+ Integral2 low2(low);
+ assert(up >= low2);
+ if (low2 == up) return low;
+ Integral2 x = Integral2(low2 + (rand() * (up - low2)) / RAND_MAX);
+ assert(x >= low2 && x <= up);
+ return x;
}
-template <class String>
-String RandomString(const String* /* model */, unsigned int maxSize)
+template<class String>
+String RandomString(size_t maxSize)
{
- String result(random(0, maxSize), '\0');
- size_t i = 0;
- for (; i != result.size(); ++i)
- {
- result[i] = random('a', 'z');
- }
- return result;
+ String result(random(0, maxSize), '\0');
+ size_t i = 0;
+ for (; i != result.size(); ++i)
+ {
+ result[i] = random('a', 'z');
+ }
+ return result;
}
-template <class String, class Integral>
-void Num2String(String& str, Integral )
+template<class String, class Integral>
+String Num2String(Integral value)
{
- str.resize(10, '\0');
-// ultoa((unsigned long)n, &str[0], 10);
- sprintf(&str[0], "%ul", 10);
- str.resize(strlen(str.c_str()));
+ typedef typename String::value_type CharType;
+ std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
+ stream << value;
+ return stream.str().c_str();
}
-std::list<char> RandomList(unsigned int maxSize)
+template<class String>
+std::list<typename String::value_type> RandomList(typename String::size_type maxSize)
{
- std::list<char> lst(random(0u, maxSize));
- std::list<char>::iterator i = lst.begin();
- for (; i != lst.end(); ++i)
+ std::list<typename String::value_type> lst(random(0, maxSize));
+ std::list<typename String::value_type>::iterator i = lst.begin();
+ for (; i != lst.end(); ++i)
+ {
+ *i = random('a', 'z');
+ }
+ return lst;
+}
+
+namespace Tests
+{
+ template<class String>
+ struct MaxString
+ {
+ static const typename String::size_type value = 1050;
+ };
+
+
+ template<class String>
+ String default_constructor(String &)
+ {
+ // 21.3.1
+ return String();
+ }
+
+ template<class String>
+ String copy_constructor(String & test)
+ {
+ // 21.3.1
+ String s(test);
+ return s;
+ }
+
+ template<class String>
+ String copy_constructor_with_size_and_range(String & test)
+ {
+ // 21.3.1
+ const typename String::size_type pos = random(0, test.size());
+ String s(test, pos, random(0, test.size() - pos));
+ return s;
+ }
+
+ template<class String>
+ String constructor_with_cstr_and_size(String & test)
+ {
+ // 21.3.1
+ const typename String::size_type
+ pos = random(0, test.size()),
+ n = random(0, test.size() - pos);
+ String s(test.c_str() + pos, n);
+ return s;
+ }
+
+ template<class String>
+ String constructor_with_cstr(String & test)
+ {
+ // 21.3.1
+ const typename String::size_type pos = random(0, test.size());
+ String s(test.c_str() + pos);
+ return s;
+ }
+
+ template<class String>
+ String assignment(String & test)
+ {
+ // 21.3.1
+ String s(random(0, 1000), '\0');
+ typename String::size_type i = 0;
+ for (; i != s.size(); ++i)
{
- *i = random('a', 'z');
+ s[i] = random('a', 'z');
}
- return lst;
-}
+ test = s;
+ return test;
+ }
-int currentTest = 0;
+ template<class String>
+ String assignment_with_cstr(String & test)
+ {
+ // 21.3.1
+ String s(random(0, 1000), '\0');
+ typename String::size_type i = 0;
+ for (; i != s.size(); ++i)
+ {
+ s[i] = random('a', 'z');
+ }
+ test = s.c_str();
+ return test;
+ }
-template <class String>
-String Test(bool avoidAliasing)
-{
- typedef typename String::size_type size_type;
- const size_type maxString = 1000;
+ template<class String>
+ String assignment_aliased(String & test)
+ {
+ // 21.3.1
+ const size_t pos = random(0, test.size());
+ test = test.c_str() + pos;
+ return test;
+ }
- String test;
+ template<class String>
+ String assignment_non_aliased(String & test)
+ {
+ // 21.3.1
+ const size_t pos = random(0, test.size());
+ test = String(test.c_str() + pos);
+ return test;
+ }
- test = RandomString(&test, maxString);
+ template<class String>
+ String assignment_from_char(String & test)
+ {
+ // 21.3.1
+ test = random('a', 'z');
+ return test;
+ }
- 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;
- }
+ template<class String>
+ String iterators_call(String & test)
+ {
+ // 21.3.2
+ String result;
+ result ...
[truncated message content] |
|
From: <jfb...@us...> - 2009-03-04 16:04:48
|
Revision: 996
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=996&view=rev
Author: jfbastien
Date: 2009-03-04 16:04:41 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
There were test failures in release (MSVC 9 with Multi-threaded DLL runtime library) because random and RandomString were called directly as arguments to functions. When this happened more than once in the same function there would sometimes be different results because the order of evaluation of function arguments isn't guaranteed.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-04 07:13:07 UTC (rev 995)
+++ trunk/test/flex_string/main.cpp 2009-03-04 16:04:41 UTC (rev 996)
@@ -116,7 +116,8 @@
template<class String>
String RandomString(size_t maxSize)
{
- String result(random(0, maxSize), '\0');
+ const typename String::size_type size = random(0, maxSize);
+ String result(size, '\0');
size_t i = 0;
for (; i != result.size(); ++i)
{
@@ -137,7 +138,8 @@
template<class String>
std::list<typename String::value_type> RandomList(typename String::size_type maxSize)
{
- std::list<typename String::value_type> lst(random(0, maxSize));
+ const typename String::size_type size = random(0, maxSize);
+ std::list<typename String::value_type> lst(size);
std::list<typename String::value_type>::iterator i = lst.begin();
for (; i != lst.end(); ++i)
{
@@ -175,7 +177,8 @@
{
// 21.3.1
const typename String::size_type pos = random(0, test.size());
- String s(test, pos, random(0, test.size() - pos));
+ const typename String::size_type length = random(0, test.size() - pos);
+ String s(test, pos, length);
return s;
}
@@ -183,9 +186,8 @@
String constructor_with_cstr_and_size(String & test)
{
// 21.3.1
- const typename String::size_type
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
+ const typename String::size_type pos = random(0, test.size());
+ const typename String::size_type n = random(0, test.size() - pos);
String s(test.c_str() + pos, n);
return s;
}
@@ -203,7 +205,8 @@
String assignment(String & test)
{
// 21.3.1
- String s(random(0, 1000), '\0');
+ const typename String::size_type size = random(0, 1000);
+ String s(size, '\0');
typename String::size_type i = 0;
for (; i != s.size(); ++i)
{
@@ -217,7 +220,8 @@
String assignment_with_cstr(String & test)
{
// 21.3.1
- String s(random(0, 1000), '\0');
+ const typename String::size_type size = random(0, 1000);
+ String s(size, '\0');
typename String::size_type i = 0;
for (; i != s.size(); ++i)
{
@@ -310,21 +314,25 @@
template<class String>
String resize(String & test)
{
- test.resize(random(0, test.size()), random('a', 'z'));
+ const typename String::size_type newSize = random(0, test.size());
+ const typename String::value_type value = random('a', 'z');
+ test.resize(newSize, value);
return test;
}
template<class String>
String resize_with_1_argument(String & test)
{
- test.resize(random(0, test.size()));
+ const typename String::size_type newSize = random(0, test.size());
+ test.resize(newSize);
return test;
}
template<class String>
String reserve(String & test)
{
- test.reserve(random(0, 1000));
+ const typename String::size_type reserveSize = random(0, 1000);
+ test.reserve(reserveSize);
return test;
}
@@ -359,8 +367,10 @@
// 21.3.4
if(!test.empty())
{
- test[random(0, test.size() - 1)];
- test.at(random(0, test.size() - 1));
+ const typename String::size_type index1 = random(0, test.size() - 1);
+ test += test[index1];
+ const typename String::size_type index2 = random(0, test.size() - 1);
+ test += test.at(index2);
}
return test;
}
@@ -368,7 +378,8 @@
template<class String>
String operator_plus_equal(String & test)
{
- test += RandomString<String>(MaxString<String>::value);
+ String str(RandomString<String>(MaxString<String>::value));
+ test += str;
return test;
}
@@ -383,7 +394,8 @@
String operator_plus_equal_with_cstr(String & test)
{
// 21.3.5
- test += RandomString<String>(MaxString<String>::value).c_str();
+ String str(RandomString<String>(MaxString<String>::value));
+ test += str.c_str();
return test;
}
@@ -391,7 +403,8 @@
String operator_plus_equal_no_aliasing(String & test)
{
// 21.3.5
- test += String(test.c_str() + random(0, test.size()));
+ const typename String::size_type offset = random(0, test.size());
+ test += String(test.c_str() + offset);
return test;
}
@@ -399,7 +412,8 @@
String operator_plus_equal_aliasing_cstr(String & test)
{
// 21.3.5
- test += test.c_str() + random(0, test.size());
+ const typename String::size_type offset = random(0, test.size());
+ test += test.c_str() + offset;
return test;
}
@@ -415,7 +429,8 @@
String append_string(String & test)
{
// 21.3.5
- test.append(RandomString<String>(MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ test.append(str);
return test;
}
@@ -424,7 +439,9 @@
{
// 21.3.5
String s(RandomString<String>(MaxString<String>::value));
- test.append(s, random(0, s.size()), random(0, MaxString<String>::value));
+ const typename String::size_type start = random(0, s.size());
+ const typename String::size_type range = random(0, MaxString<String>::value);
+ test.append(s, start, range);
return test;
}
@@ -432,8 +449,9 @@
String append_cstr_size(String & test)
{
// 21.3.5
- String s = RandomString<String>(MaxString<String>::value);
- test.append(s.c_str(), random(0, s.size()));
+ String s(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type size = random(0, s.size());
+ test.append(s.c_str(), size);
return test;
}
@@ -441,15 +459,25 @@
String append_cstr(String & test)
{
// 21.3.5
- test.append(RandomString<String>(MaxString<String>::value).c_str());
+ String str(RandomString<String>(MaxString<String>::value));
+ test.append(str.c_str());
return test;
}
template<class String>
+ String append_count_char(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type count = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.append(count, value);
+ return test;
+ }
+
+ template<class String>
String append_iterators(String & test)
{
// 21.3.5
- test.append(random(0, MaxString<String>::value), random('a', 'z'));
std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
test.append(lst.begin(), lst.end());
return test;
@@ -459,7 +487,8 @@
String push_back_char(String & test)
{
// 21.3.5
- test.push_back(random('a', 'z'));
+ const typename String::value_type value = random('a', 'z');
+ test.push_back(value);
return test;
}
@@ -467,7 +496,8 @@
String assign_string(String & test)
{
// 21.3.5
- test.assign(RandomString<String>(MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ test.assign(str);
return test;
}
@@ -475,8 +505,10 @@
String assign_string_start_size(String & test)
{
// 21.3.5
- String str = RandomString<String>(MaxString<String>::value);
- test.assign(str, random(0, str.size()), random(0, MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type start = random(0, str.size());
+ const typename String::size_type size = random(0, MaxString<String>::value);
+ test.assign(str, start, size);
return test;
}
@@ -484,8 +516,9 @@
String assign_cstr_size(String & test)
{
// 21.3.5
- String str = RandomString<String>(MaxString<String>::value);
- test.assign(str.c_str(), random(0, str.size()));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type size = random(0, str.size());
+ test.assign(str.c_str(), size);
return test;
}
@@ -493,7 +526,8 @@
String assign_cstr(String & test)
{
// 21.3.5
- test.assign(RandomString<String>(MaxString<String>::value).c_str());
+ String str(RandomString<String>(MaxString<String>::value));
+ test.assign(str.c_str());
return test;
}
@@ -501,7 +535,9 @@
String assign_number_char(String & test)
{
// 21.3.5
- test.assign(random(0, MaxString<String>::value), random('a', 'z'));
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.assign(number, value);
return test;
}
@@ -518,7 +554,9 @@
String insert_position_string(String & test)
{
// 21.3.5
- test.insert(random(0, test.size()), RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, test.size());
+ String str(RandomString<String>(MaxString<String>::value));
+ test.insert(position, str);
return test;
}
@@ -526,10 +564,11 @@
String insert_position_string_start_end(String & test)
{
// 21.3.5
- String str = RandomString<String>(MaxString<String>::value);
- test.insert(random(0, test.size()),
- str, random(0, str.size()),
- random(0, MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, test.size());
+ const typename String::size_type start = random(0, str.size());
+ const typename String::size_type end = random(0, MaxString<String>::value);
+ test.insert(position, str, start, end);
return test;
}
@@ -537,9 +576,10 @@
String insert_position_cstr_size(String & test)
{
// 21.3.5
- String str = RandomString<String>(MaxString<String>::value);
- test.insert(random(0, test.size()),
- str.c_str(), random(0, str.size()));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, test.size());
+ const typename String::size_type size = random(0, str.size());
+ test.insert(position, str.c_str(), size);
return test;
}
@@ -547,8 +587,9 @@
String insert_position_cstr(String & test)
{
// 21.3.5
- test.insert(random(0, test.size()),
- RandomString<String>(MaxString<String>::value).c_str());
+ const typename String::size_type position = random(0, test.size());
+ String str(RandomString<String>(MaxString<String>::value));
+ test.insert(position, str.c_str());
return test;
}
@@ -556,8 +597,10 @@
String insert_position_number_char(String & test)
{
// 21.3.5
- test.insert(random(0, test.size()),
- random(0, MaxString<String>::value), random('a', 'z'));
+ const typename String::size_type position = random(0, test.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.insert(position, number, value);
return test;
}
@@ -565,8 +608,9 @@
String insert_iterator_char(String & test)
{
// 21.3.5
- test.insert(test.begin() + random(0, test.size()),
- random('a', 'z'));
+ const typename String::size_type offset = random(0, test.size());
+ const typename String::value_type value = random('a', 'z');
+ test.insert(test.begin() + offset, value);
return test;
}
@@ -575,8 +619,8 @@
{
// 21.3.5
std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
- test.insert(test.begin() + random(0, test.size()),
- lst.begin(), lst.end());
+ const typename String::size_type offset = random(0, test.size());
+ test.insert(test.begin() + offset, lst.begin(), lst.end());
return test;
}
@@ -584,7 +628,9 @@
String erase_position_position(String & test)
{
// 21.3.5
- test.erase(random(0, test.size()), random(0, MaxString<String>::value));
+ const typename String::size_type start = random(0, test.size());
+ const typename String::size_type end = random(0, MaxString<String>::value);
+ test.erase(start, end);
return test;
}
@@ -593,7 +639,10 @@
{
// 21.3.5
if(!test.empty())
- test.erase(test.begin() + random(0, test.size()));
+ {
+ const typename String::size_type offset = random(0, test.size());
+ test.erase(test.begin() + offset);
+ }
return test;
}
@@ -601,8 +650,10 @@
String erase_iterator_iterator(String & test)
{
// 21.3.5
- const typename String::iterator i = test.begin() + random(0, test.size());
- test.erase(i, i + random(0, size_t(test.end() - i)));
+ const typename String::size_type offset = random(0, test.size());
+ const typename String::iterator i = test.begin() + offset;
+ const typename String::size_type endOffset = random(0, test.end() - i);
+ test.erase(i, i + endOffset);
return test;
}
@@ -611,7 +662,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos), String(test));
+ const typename String::size_type end = random(0, test.size() - pos);
+ test.replace(pos, end, String(test));
return test;
}
@@ -620,7 +672,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos), test);
+ const typename String::size_type end = random(0, test.size() - pos);
+ test.replace(pos, end, test);
return test;
}
@@ -629,8 +682,9 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, pos + random(0, test.size() - pos),
- RandomString<String>(MaxString<String>::value));
+ const typename String::size_type end = random(0, test.size() - pos);
+ String str(RandomString<String>(MaxString<String>::value));
+ test.replace(pos, pos + end, str);
return test;
}
@@ -638,12 +692,11 @@
String replace_start_end_selfcopy_start_end(String & test)
{
// 21.3.5
- const typename String::size_type
- pos1 = random(0, test.size()),
- pos2 = random(0, test.size());
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- String(test),
- pos2, pos2 + random(0, test.size() - pos2));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ const typename String::size_type offset1 = random(0, test.size() - pos1);
+ const typename String::size_type offset2 = random(0, test.size() - pos2);
+ test.replace(pos1, pos1 + offset1, String(test), pos2, pos2 + offset2);
return test;
}
@@ -651,11 +704,11 @@
String replace_start_end_self_start_end(String & test)
{
// 21.3.5
- const typename String::size_type
- pos1 = random(0, test.size()),
- pos2 = random(0, test.size());
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- test, pos2, pos2 + random(0, test.size() - pos2));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ const typename String::size_type offset1 = random(0, test.size() - pos1);
+ const typename String::size_type offset2 = random(0, test.size() - pos2);
+ test.replace(pos1, pos1 + offset1, test, pos2, pos2 + offset2);
return test;
}
@@ -663,11 +716,12 @@
String replace_start_end_string_start_end(String & test)
{
// 21.3.5
+ String str(RandomString<String>(MaxString<String>::value));
const typename String::size_type pos1 = random(0, test.size());
- String str = RandomString<String>(MaxString<String>::value);
const typename String::size_type pos2 = random(0, str.size());
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- str, pos2, pos2 + random(0, str.size() - pos2));
+ const typename String::size_type offset1 = random(0, test.size() - pos1);
+ const typename String::size_type offset2 = random(0, str.size() - pos2);
+ test.replace(pos1, pos1 + offset1, str, pos2, pos2 + offset2);
return test;
}
@@ -676,8 +730,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
- String(test).c_str(), test.size());
+ const typename String::size_type pos2 = random(0, test.size() - pos);
+ test.replace(pos, pos2, String(test).c_str(), test.size());
return test;
}
@@ -686,8 +740,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
- test.c_str(), test.size());
+ const typename String::size_type pos2 = random(0, test.size() - pos);
+ test.replace(pos, pos2, test.c_str(), test.size());
return test;
}
@@ -695,10 +749,10 @@
String replace_start_end_stringcstr_size(String & test)
{
// 21.3.5
+ String str(RandomString<String>(MaxString<String>::value));
const typename String::size_type pos = random(0, test.size());
- String str = RandomString<String>(MaxString<String>::value);
- test.replace(pos, pos + random(0, test.size() - pos),
- str.c_str(), str.size());
+ const typename String::size_type offset = random(0, test.size() - pos);
+ test.replace(pos, pos + offset, str.c_str(), str.size());
return test;
}
@@ -706,10 +760,10 @@
String replace_start_end_stringcstr(String & test)
{
// 21.3.5
+ String str(RandomString<String>(MaxString<String>::value));
const typename String::size_type pos = random(0, test.size());
- String str = RandomString<String>(MaxString<String>::value);
- test.replace(pos, pos + random(0, test.size() - pos),
- str.c_str());
+ const typename String::size_type offset = random(0, test.size() - pos);
+ test.replace(pos, pos + offset, str.c_str());
return test;
}
@@ -717,9 +771,11 @@
String replace_start_end_number_char(String & test)
{
// 21.3.5
- const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
- random(0, MaxString<String>::value), random('a', 'z'));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size() - pos1);
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.replace(pos1, pos2, number, value);
return test;
}
@@ -728,10 +784,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test));
+ const typename String::size_type offset = random(0, test.size() - pos);
+ test.replace(test.begin() + pos, test.begin() + pos + offset, String(test));
return test;
}
@@ -740,10 +794,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- test);
+ const typename String::size_type offset = random(0, test.size() - pos);
+ test.replace(test.begin() + pos, test.begin() + pos + offset, test);
return test;
}
@@ -752,11 +804,9 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test).c_str(),
- test.size() - random(0, test.size()));
+ const typename String::size_type offset = random(0, test.size() - pos);
+ const typename String::size_type size = random(0, test.size());
+ test.replace(test.begin() + pos, test.begin() + pos + offset, String(test).c_str(), test.size() - size);
return test;
}
@@ -765,11 +815,9 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- test.c_str(),
- test.size() - random(0, test.size()));
+ const typename String::size_type offset = random(0, test.size() - pos);
+ const typename String::size_type size = random(0, test.size());
+ test.replace(test.begin() + pos, test.begin() + pos + offset, test.c_str(), test.size() - size);
return test;
}
@@ -777,16 +825,12 @@
String replace_iterator_iterator_stringcstr(String & test)
{
// 21.3.5
- const typename String::size_type
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
+ const typename String::size_type pos = random(0, test.size());
+ const typename String::size_type n = random(0, test.size() - pos);
typename String::iterator b = test.begin();
- const String str = RandomString<String>(MaxString<String>::value);
+ const String str(RandomString<String>(MaxString<String>::value));
const typename String::value_type* s = str.c_str();
- test.replace(
- b + pos,
- b + pos + n,
- s);
+ test.replace(b + pos, b + pos + n, s);
return test;
}
@@ -795,10 +839,10 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- random(0, MaxString<String>::value), random('a', 'z'));
+ const typename String::size_type pos2 = random(0, test.size() - pos);
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.replace(test.begin() + pos, test.begin() + pos + pos2, number, value);
return test;
}
@@ -806,12 +850,9 @@
String copy_pointer_size_position(String & test)
{
// 21.3.5
- std::vector<typename String::value_type>
- vec(random(1, MaxString<String>::value));
- test.copy(
- &vec[0],
- vec.size(),
- random(0, test.size()));
+ std::vector<typename String::value_type> vec(random(1, MaxString<String>::value));
+ const typename String::size_type pos = random(0, test.size());
+ test.copy(&vec[0], vec.size(), pos);
return test;
}
@@ -819,8 +860,9 @@
String member_swap(String & test)
{
// 21.3.5
- RandomString<String>(MaxString<String>::value).swap(test);
- return test;
+ String s(RandomString<String>(MaxString<String>::value));
+ s.swap(test);
+ return test + " -- " + s;
}
template<class String>
@@ -828,17 +870,42 @@
{
// 21.3.5
String s(RandomString<String>(MaxString<String>::value));
- s.swap(test);
- return s;
+ test.swap(s);
+ return test + " -- " + s;
}
template<class String>
+ String member_self_swap(String & test)
+ {
+ // 21.3.5
+ test.swap(test);
+ return test;
+ }
+
+ template<class String>
+ String member_selfcopy_swap(String & test)
+ {
+ // 21.3.5
+ String(test).swap(test);
+ return test;
+ }
+
+ template<class String>
+ String member_selfcopy_swap2(String & test)
+ {
+ // 21.3.5
+ String s(test);
+ test.swap(s);
+ return test + " -- " + s;
+ }
+
+ template<class String>
String swap(String & test)
{
using std::swap;
String s(RandomString<String>(MaxString<String>::value));
swap(test, s);
- return test;
+ return test + " -- " + s;
}
template<class String>
@@ -846,18 +913,44 @@
{
using std::swap;
String s(RandomString<String>(MaxString<String>::value));
+ swap(s, test);
+ return test + " -- " + s;
+ }
+
+ template<class String>
+ String swap_self(String & test)
+ {
+ using std::swap;
+ swap(test, test);
+ return test;
+ }
+
+ template<class String>
+ String swap_selfcopy(String & test)
+ {
+ using std::swap;
+ String s(test);
swap(test, s);
- return s;
+ return test + " -- " + s;
}
template<class String>
+ String swap_selfcopy2(String & test)
+ {
+ using std::swap;
+ String s(test);
+ swap(s, test);
+ return test + " -- " + s;
+ }
+
+ template<class String>
String cstr_data_getallocator(String & test)
{
// 21.3.6
String result;
+ String str(RandomString<String>(MaxString<String>::value));
result += Num2String<String>(test.c_str() == test.data()) + " -- ";
- result += Num2String<String>(test.get_allocator() ==
- RandomString<String>(MaxString<String>::value).get_allocator()) + " -- ";
+ result += Num2String<String>(test.get_allocator() == str.get_allocator()) + " -- ";
return result;
}
@@ -865,10 +958,11 @@
String find_string_index(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.find(str, random(0, test.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find(str, index));
return test;
}
@@ -876,12 +970,12 @@
String find_stringcstr_index_length(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.find(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, str.size());
+ test = Num2String<String>(test.find(str.c_str(), index, length));
return test;
}
@@ -889,11 +983,11 @@
String find_stringcstr_index(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.find(str.c_str(),
- random(0, test.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find(str.c_str(), index));
return test;
}
@@ -901,9 +995,9 @@
String find_char_index(String & test)
{
// 21.3.6
- test = Num2String<String>(test.find(
- random('a', 'z'),
- random(0, test.size())));
+ const typename String::value_type value = random('a', 'z');
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find(value, index));
return test;
}
@@ -993,10 +1087,11 @@
String rfind_string_index(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.rfind(str, random(0, test.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.rfind(str, index));
return test;
}
@@ -1004,12 +1099,12 @@
String rfind_stringcstr_index_length(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.rfind(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, str.size());
+ test = Num2String<String>(test.rfind(str.c_str(), index, length));
return test;
}
@@ -1017,11 +1112,11 @@
String rfind_stringcstr_index(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.rfind(str.c_str(),
- random(0, test.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.rfind(str.c_str(), index));
return test;
}
@@ -1029,9 +1124,9 @@
String rfind_char_index(String & test)
{
// 21.3.6
- test = Num2String<String>(test.rfind(
- random('a', 'z'),
- random(0, test.size())));
+ const typename String::value_type value = random('a', 'z');
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.rfind(value, index));
return test;
}
@@ -1039,9 +1134,9 @@
String find_first_of_string_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_first_of(str,
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ ...
[truncated message content] |
|
From: <jfb...@us...> - 2009-03-05 16:14:07
|
Revision: 998
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=998&view=rev
Author: jfbastien
Date: 2009-03-05 16:13:57 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
Use MaxString<String>::value instead of 1000.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-05 12:21:52 UTC (rev 997)
+++ trunk/test/flex_string/main.cpp 2009-03-05 16:13:57 UTC (rev 998)
@@ -205,7 +205,7 @@
String assignment(String & test)
{
// 21.3.1
- const typename String::size_type size = random(0, 1000);
+ const typename String::size_type size = random(0, MaxString<String>::value);
String s(size, '\0');
typename String::size_type i = 0;
for (; i != s.size(); ++i)
@@ -220,7 +220,7 @@
String assignment_with_cstr(String & test)
{
// 21.3.1
- const typename String::size_type size = random(0, 1000);
+ const typename String::size_type size = random(0, MaxString<String>::value);
String s(size, '\0');
typename String::size_type i = 0;
for (; i != s.size(); ++i)
@@ -331,7 +331,7 @@
template<class String>
String reserve(String & test)
{
- const typename String::size_type reserveSize = random(0, 1000);
+ const typename String::size_type reserveSize = random(0, MaxString<String>::value);
test.reserve(reserveSize);
return test;
}
@@ -1718,7 +1718,7 @@
int main()
{
- const time_t initialSeed(1236182091 /*time(0)*/);
+ const time_t initialSeed(time(0));
srand(unsigned(initialSeed));
std::cout << "initial seed = " << initialSeed << "\n\n";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-05 21:09:24
|
Revision: 999
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=999&view=rev
Author: jfbastien
Date: 2009-03-05 21:09:20 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
Add a small string optimization test with a buffer of 126.
Cache size() outside the loop for RandomString.
Modify Num2String so that npos is properly taken into account.
Add Tristate2String.
Modify seedForThisIteration so that its value is count + rand() instead of just rand(): using just rand meant that a lot of the initial seeds repeated because the pseudo-randomness of rand isn't good. Adding count should somewhat reduce the repetitions.
I'd consider using another random number generator, rand() is slow and has a bad distribution.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-05 16:13:57 UTC (rev 998)
+++ trunk/test/flex_string/main.cpp 2009-03-05 21:09:20 UTC (rev 999)
@@ -83,6 +83,13 @@
char,
std::char_traits<char>,
std::allocator<char>,
+ SmallStringOpt<SimpleStringStorage<char, std::allocator<char> >, 126>
+ > my_string_SmallStringSimpleBigBuffer;
+
+ typedef flex_string<
+ char,
+ std::char_traits<char>,
+ std::allocator<char>,
SmallStringOpt<VectorStringStorage<char, std::allocator<char> >, 23>
> my_string_SmallStringVector;
@@ -119,13 +126,20 @@
const typename String::size_type size = random(0, maxSize);
String result(size, '\0');
size_t i = 0;
- for (; i != result.size(); ++i)
+ for (; i != size; ++i)
{
result[i] = random('a', 'z');
}
return result;
}
+// Specialize this method for different String types.
+template<class String>
+String Npos()
+{
+ return "{npos}";
+}
+
template<class String, class Integral>
String Num2String(Integral value)
{
@@ -136,6 +150,37 @@
}
template<class String>
+String Num2String(typename String::size_type value)
+{
+ if(String::npos != value)
+ {
+ typedef typename String::value_type CharType;
+ std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
+ stream << value;
+ return stream.str().c_str();
+ }
+ else
+ {
+ // Not all strings will have the same value for npos.
+ // Since methods like find return npos on failure we want to represent npos in an implementation-independent manner.
+ return Npos<String>();
+ }
+}
+
+// Some comparison functions return 0 or a value greater/smaller than zero.
+// This function makes the greater/smaller than zero specification implementation-independent.
+template<class String>
+String Tristate2String(int tristate)
+{
+ if(0 == tristate)
+ return Num2String<String>(0);
+ else if(0 < tristate)
+ return Num2String<String>(1);
+ else
+ return Num2String<String>(2);
+}
+
+template<class String>
std::list<typename String::value_type> RandomList(typename String::size_type maxSize)
{
const typename String::size_type size = random(0, maxSize);
@@ -1308,10 +1353,7 @@
String compare_selfcopy(String & test)
{
int tristate = test.compare(String(test));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1319,10 +1361,7 @@
{
String str(RandomString<String>(MaxString<String>::value));
int tristate = test.compare(str);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1331,10 +1370,7 @@
const typename String::size_type index = random(0, test.size());
const typename String::size_type length = random(0, test.size());
int tristate = test.compare(index, length, String(test));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1344,10 +1380,7 @@
const typename String::size_type length = random(0, test.size());
String str(RandomString<String>(MaxString<String>::value));
int tristate = test.compare(index, length, str);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1359,10 +1392,7 @@
const typename String::size_type index2 = random(0, str.size());
const typename String::size_type length2 = random(0, str.size());
int tristate = test.compare(index, length, str, index2, length2);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1374,10 +1404,7 @@
const typename String::size_type index2 = random(0, str.size());
const typename String::size_type length2 = random(0, str.size());
int tristate = test.compare(index, length, str, index2, length2);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1385,10 +1412,7 @@
{
String str(RandomString<String>(MaxString<String>::value));
int tristate = test.compare(str.c_str());
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1399,10 +1423,7 @@
const typename String::size_type length = random(0, test.size());
const typename String::size_type index2 = random(0, str.size());
int tristate = test.compare(index, length, str.c_str(), index2);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1647,21 +1668,22 @@
size_t count = 0;
using namespace StringsToTest;
- TestFunctions<std::string> testFunctions_std;
- TestFunctions<my_string_SimpleStorage> testFunctions_SimpleStorage;
- TestFunctions<my_string_AllocatorStorage> testFunctions_AllocatorStorage;
- TestFunctions<my_string_MallocatorStorage> testFunctions_MallocatorStorage;
- TestFunctions<my_string_VectorStorage> testFunctions_VectorStorage;
- TestFunctions<my_string_SmallStringSimple> testFunctions_SmallStringSimple;
- TestFunctions<my_string_SmallStringVector> testFunctions_SmallStringVector;
- TestFunctions<my_string_CowSimple> testFunctions_CowSimple;
- TestFunctions<my_string_CowAllocator> testFunctions_CowAllocator;
+ TestFunctions<std::string> testFunctions_std;
+ TestFunctions<my_string_SimpleStorage> testFunctions_SimpleStorage;
+ TestFunctions<my_string_AllocatorStorage> testFunctions_AllocatorStorage;
+ TestFunctions<my_string_MallocatorStorage> testFunctions_MallocatorStorage;
+ TestFunctions<my_string_VectorStorage> testFunctions_VectorStorage;
+ TestFunctions<my_string_SmallStringSimple> testFunctions_SmallStringSimple;
+ TestFunctions<my_string_SmallStringSimpleBigBuffer> testFunctions_smallStringSimpleBigBuffer;
+ TestFunctions<my_string_SmallStringVector> testFunctions_SmallStringVector;
+ TestFunctions<my_string_CowSimple> testFunctions_CowSimple;
+ TestFunctions<my_string_CowAllocator> testFunctions_CowAllocator;
for (;;)
{
std::cout << ++count << '\r';
- const unsigned int seedForThisIteration = rand();
+ const unsigned int seedForThisIteration = count + rand();
srand(seedForThisIteration);
const std::string reference(Test<std::string>(count, testFunctions_std));
@@ -1698,6 +1720,12 @@
{
srand(seedForThisIteration);
+ const my_string_SmallStringSimpleBigBuffer tested(Test<my_string_SmallStringSimpleBigBuffer>(count, testFunctions_smallStringSimpleBigBuffer));
+ checkResults(reference, tested, testFunctions_smallStringSimpleBigBuffer, seedForThisIteration, count);
+ }
+
+ {
+ srand(seedForThisIteration);
const my_string_SmallStringVector tested(Test<my_string_SmallStringVector>(count, testFunctions_SmallStringVector));
checkResults(reference, tested, testFunctions_SmallStringVector, seedForThisIteration, count);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-10 18:36:55
|
Revision: 1002
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1002&view=rev
Author: jfbastien
Date: 2009-03-10 18:36:42 +0000 (Tue, 10 Mar 2009)
Log Message:
-----------
Refactor some more, and add a bunch of tests. These new tests led me to find bug #2679853.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-05 22:04:56 UTC (rev 1001)
+++ trunk/test/flex_string/main.cpp 2009-03-10 18:36:42 UTC (rev 1002)
@@ -133,19 +133,73 @@
return result;
}
-// Specialize this method for different String types.
+// Specialize these method for different String types.
template<class String>
-String Npos()
+typename String::value_type NullTerminator()
{
+ return '\0';
+}
+
+template<class String>
+String LengthErrorExceptionString()
+{
+ return "length_error exception thrown";
+}
+
+template<class String>
+String OutOfRangeExceptionString()
+{
+ return "out_of_range exception thrown";
+}
+
+template<class String>
+String UnknownExceptionString()
+{
+ return "Unknown exception thrown";
+}
+
+template<class String>
+String NposString()
+{
return "{npos}";
}
+template<class String>
+String OpenCurlyString()
+{
+ return "{";
+}
+
+template<class String>
+String CloseCurlyString()
+{
+ return "}";
+}
+
+template<class String>
+String SeparatorString()
+{
+ return "--";
+}
+
+template<class String>
+String TrueString()
+{
+ return "{true}";
+}
+
+template<class String>
+String FalseString()
+{
+ return "{false}";
+}
+
template<class String, class Integral>
String Num2String(Integral value)
{
typedef typename String::value_type CharType;
std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
- stream << value;
+ stream << OpenCurlyString<String>() << value << CloseCurlyString<String>();
return stream.str().c_str();
}
@@ -156,17 +210,23 @@
{
typedef typename String::value_type CharType;
std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
- stream << value;
+ stream << OpenCurlyString<String>() << value << CloseCurlyString<String>();
return stream.str().c_str();
}
else
{
// Not all strings will have the same value for npos.
// Since methods like find return npos on failure we want to represent npos in an implementation-independent manner.
- return Npos<String>();
+ return NposString<String>();
}
}
+template<class String>
+String Num2String(bool value)
+{
+ return value ? TrueString<String>() : FalseString<String>();
+}
+
// Some comparison functions return 0 or a value greater/smaller than zero.
// This function makes the greater/smaller than zero specification implementation-independent.
template<class String>
@@ -184,13 +244,13 @@
std::list<typename String::value_type> RandomList(typename String::size_type maxSize)
{
const typename String::size_type size = random(0, maxSize);
- std::list<typename String::value_type> lst(size);
- std::list<typename String::value_type>::iterator i = lst.begin();
- for (; i != lst.end(); ++i)
+ std::list<typename String::value_type> list(size);
+ std::list<typename String::value_type>::iterator i = list.begin();
+ for (; i != list.end(); ++i)
{
*i = random('a', 'z');
}
- return lst;
+ return list;
}
namespace Tests
@@ -201,1274 +261,2424 @@
static const typename String::size_type value = 1050;
};
+ template<class String>
+ String operator_plus_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = random1 + random2;
+ return result;
+ }
template<class String>
- String default_constructor(String &)
+ String operator_plus_cstr_string()
{
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = random1.c_str() + random2;
+ return result;
+ }
+
+ template<class String>
+ String operator_plus_char_string()
+ {
+ // 21.3
+ const typename String::value_type value = random('a', 'z');
+ String random1(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = value + random1;
+ return result;
+ }
+
+ template<class String>
+ String operator_plus_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = random1 + random2.c_str();
+ return result;
+ }
+
+ template<class String>
+ String operator_plus_string_char()
+ {
+ // 21.3
+ const typename String::value_type value = random('a', 'z');
+ String random1(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = random1 + value;
+ return result;
+ }
+
+ template<class String>
+ String operator_equal_equal_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 == random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_equal_equal_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() == random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_equal_equal_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 == random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_not_equal_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 != random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_not_equal_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() != random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_not_equal_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 != random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 < random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() < random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 < random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 > random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() > random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 > random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_equal_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 <= random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_equal_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() <= random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_equal_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 <= random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_equal_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 >= random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_equal_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() >= random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_equal_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 >= random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String swap_string_string()
+ {
+ using std::swap;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ swap(random1, random2);
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String swap_string_string__self()
+ {
+ using std::swap;
+ String random1(RandomString<String>(MaxString<String>::value));
+ swap(random1, random1);
+ return random1;
+ }
+
+ template<class String>
+ String swap_string_string__selfcopy()
+ {
+ using std::swap;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ swap(random1, copy);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String swap_string_string__selfcopy2()
+ {
+ using std::swap;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ swap(copy, random1);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ // TODO: operator>>(istream, string)
+ // TODO: operator<<(ostream, string)
+ // TODO: getline(istream, string, char delimiter)
+ // TODO: getline(istream, string)
+
+ template<class String>
+ String constructor()
+ {
// 21.3.1
return String();
}
template<class String>
- String copy_constructor(String & test)
+ String constructor_string()
{
// 21.3.1
- String s(test);
- return s;
+ String random1(RandomString<String>(MaxString<String>::value));
+ return random1;
}
template<class String>
- String copy_constructor_with_size_and_range(String & test)
+ String constructor_string_position_number()
{
// 21.3.1
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type length = random(0, test.size() - pos);
- String s(test, pos, length);
- return s;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, random1.size() - position);
+ String result(random1, position, number);
+ return result;
}
template<class String>
- String constructor_with_cstr_and_size(String & test)
+ String constructor_string_position_number__bigNumber()
{
// 21.3.1
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type n = random(0, test.size() - pos);
- String s(test.c_str() + pos, n);
- return s;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, String::npos);
+ String result(random1, position, number);
+ return result;
}
template<class String>
- String constructor_with_cstr(String & test)
+ String constructor_cstr_number()
{
// 21.3.1
- const typename String::size_type pos = random(0, test.size());
- String s(test.c_str() + pos);
- return s;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, random1.size());
+ String result(random1.c_str(), number);
+ return result;
}
template<class String>
- String assignment(String & test)
+ String constructor_number_char()
{
// 21.3.1
- const typename String::size_type size = random(0, MaxString<String>::value);
- String s(size, '\0');
- typename String::size_type i = 0;
- for (; i != s.size(); ++i)
- {
- s[i] = random('a', 'z');
- }
- test = s;
- return test;
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::size_type value = random('a', 'z');
+ String result(number, value);
+ return result;
}
template<class String>
- String assignment_with_cstr(String & test)
+ String constructor_iterator_iterator()
{
+ // 21.3.5
+ std::list<typename String::value_type> list(RandomList<String>(MaxString<String>::value));
+ String result(list.begin(), list.end());
+ return result;
+ }
+
+ // TODO: destructor
+
+ template<class String>
+ String operator_equal_string()
+ {
// 21.3.1
- const typename String::size_type size = random(0, MaxString<String>::value);
- String s(size, '\0');
- typename String::size_type i = 0;
- for (; i != s.size(); ++i)
- {
- s[i] = random('a', 'z');
- }
- test = s.c_str();
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1 = random2;
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String assignment_aliased(String & test)
+ String operator_equal_string__self()
{
// 21.3.1
- const size_t pos = random(0, test.size());
- test = test.c_str() + pos;
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1 = random1;
+ return random1;
}
template<class String>
- String assignment_non_aliased(String & test)
+ String operator_equal_string__selfCopy()
{
// 21.3.1
- const size_t pos = random(0, test.size());
- test = String(test.c_str() + pos);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(random1);
+ random1 = random2;
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String assignment_from_char(String & test)
+ String operator_equal_cstr()
{
// 21.3.1
- test = random('a', 'z');
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1 = random2.c_str();
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String iterators_call(String & test)
+ String operator_equal_cstr__self()
{
+ // 21.3.1
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1 = random1.c_str();
+ return random1;
+ }
+
+ template<class String>
+ String operator_equal_cstr__selfCopy()
+ {
+ // 21.3.1
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(random1);
+ random1 = random2.c_str();
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String iterators()
+ {
// 21.3.2
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String random2(RandomString<String>(MaxString<String>::value));
String result;
- result += Num2String<String>(test.end() - test.begin()) + " -- ";
- result += Num2String<String>(test.rend() - test.rbegin()) + " -- ";
+ result += Num2String<String>(random1.end() - random1.begin())
+ + Num2String<String>(random1.rend() - random1.rbegin())
+ + Num2String<String>(random2.end() - random2.begin())
+ + Num2String<String>(random2.rend() - random2.rbegin())
+ + Num2String<String>(random1.end() == random1.begin())
+ + Num2String<String>(random1.rend() == random1.rbegin())
+ + Num2String<String>(random2.end() == random2.begin())
+ + Num2String<String>(random2.rend() == random2.rbegin())
+ + Num2String<String>(random1.end() != random1.begin())
+ + Num2String<String>(random1.rend() != random1.rbegin())
+ + Num2String<String>(random2.end() != random2.begin())
+ + Num2String<String>(random2.rend() != random2.rbegin());
return result;
}
template<class String>
- String iterators_equality(String & test)
+ String capacity()
{
- // 21.3.2
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
String result;
- result += Num2String<String>(test.size()) + " -- ";
- if(0 != test.size())
+ result += Num2String<String>(random1.size())
+ + Num2String<String>(random1.length())
+ + Num2String<String>(random1.size() == random1.length())
+ + Num2String<String>(random1.capacity() >= random1.size())
+ + Num2String<String>(random1.max_size() >= random1.size())
+ + Num2String<String>(random1.max_size() >= random1.capacity());
+ return result;
+ }
+
+ template<class String>
+ String resize_number_char()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ random1.resize(number, value);
+ return random1;
+ }
+
+ template<class String>
+ String resize_number()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.resize(number);
+ return random1;
+ }
+
+ template<class String>
+ String reserve_number()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.reserve(number);
+ random1 += Num2String<String>(random1.capacity() >= number);
+ return random1;
+ }
+
+ template<class String>
+ String clear()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.clear();
+ return random1;
+ }
+
+ template<class String>
+ String empty()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ return Num2String<String>(random1.empty());
+ }
+
+ template<class String>
+ String element_access()
+ {
+ // 21.3.4
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ if(!random1.empty())
{
- result += Num2String<String>(test.begin() != test.end()) + " -- ";
- result += Num2String<String>(test.rbegin() != test.rend()) + " -- ";
+ {
+ const typename String::size_type index = random(0, random1.size() - 1);
+ result += random1[index] + SeparatorString<String>();
+ }
+ {
+ const typename String::size_type index = random(0, random1.size() - 1);
+ result += random1.at(index) + SeparatorString<String>();
+ }
}
- else
+ if(!random2.empty())
{
- result += Num2String<String>(test.begin() == test.end()) + " -- ";
- result += Num2String<String>(test.rbegin() == test.rend()) + " -- ";
+ {
+ const typename String::size_type index = random(0, random2.size() - 1);
+ result += random2[index] + SeparatorString<String>();
+ }
+ {
+ const typename String::size_type index = random(0, random2.size() - 1);
+ result += random2.at(index) + SeparatorString<String>();
+ }
}
return result;
}
template<class String>
- String capacity(String & test)
+ String operator_plus_equal_string()
{
- // 21.3.2
- String result;
- result += Num2String<String>(test.size()) + " -- ";
- result += Num2String<String>(test.length()) + " -- ";
- test.max_size();
- test.capacity();
- result += test;
- return result;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1 += random2;
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String capacity_values(String & test)
+ String operator_plus_equal_string__self()
{
- // 21.3.2
- String result;
- result += Num2String<String>(test.size() == test.length()) + " -- ";
- result += Num2String<String>(test.capacity() >= test.size()) + " -- ";
- result += Num2String<String>(test.max_size() >= test.size()) + " -- ";
- result += Num2String<String>(test.max_size() >= test.capacity()) + " -- ";
- return result;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1 += random1;
+ return random1;
}
template<class String>
- String resize(String & test)
+ String operator_plus_equal_string__selfcopy()
{
- const typename String::size_type newSize = random(0, test.size());
- const typename String::value_type value = random('a', 'z');
- test.resize(newSize, value);
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1 += copy;
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String resize_with_1_argument(String & test)
+ String operator_plus_equal_cstr()
{
- const typename String::size_type newSize = random(0, test.size());
- test.resize(newSize);
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1 += random2.c_str();
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String reserve(String & test)
+ String operator_plus_equal_cstr__self()
{
- const typename String::size_type reserveSize = random(0, MaxString<String>::value);
- test.reserve(reserveSize);
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1 += random1.c_str();
+ return random1;
}
template<class String>
- String clear(String & test)
+ String operator_plus_equal_cstr__selfcopy()
{
- test.clear();
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1 += copy.c_str();
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String empty1(String & test)
+ String operator_plus_equal_char()
{
- if (test.empty()) test = "empty";
- else test = "not empty";
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::value_type value = random('a', 'z');
+ random1 += value;
+ return random1;
}
template<class String>
- String empty2(String & test)
+ String append_string()
{
- const char* kEmptyString = "empty";
- const char* kNonEmptyString = "not empty";
- if (test.empty()) test = String(kEmptyString, kEmptyString + strlen(kEmptyString));
- else test = String(kNonEmptyString, kNonEmptyString + strlen(kNonEmptyString));
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1.append(random2);
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String element_access(String & test)
+ String append_string__self()
{
- // 21.3.4
- if(!test.empty())
- {
- const typename String::size_type index1 = random(0, test.size() - 1);
- test += test[index1];
- const typename String::size_type index2 = random(0, test.size() - 1);
- test += test.at(index2);
- }
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.append(random1);
+ return random1;
}
template<class String>
- String operator_plus_equal(String & test)
+ String append_string__selfcopy()
{
- String str(RandomString<String>(MaxString<String>::value));
- test += str;
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1.append(copy);
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String operator_plus_equal_aliasing(String & test)
+ String append_string_position_number()
{
- test += test;
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random2.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.append(random2, position, number);
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String operator_plus_equal_with_cstr(String & test)
+ String append_string_position_number__self()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- test += str.c_str();
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.append(random1, position, number);
+ return random1;
}
template<class String>
- String operator_plus_equal_no_aliasing(String & test)
+ String append_string_position_number__selfcopy()
{
// 21.3.5
- const typename String::size_type offset = random(0, test.size());
- test += String(test.c_str() + offset);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.append(copy, position, number);
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String operator_plus_equal_aliasing_cstr(String & test)
+ String append_cstr_number()
{
// 21.3.5
- const typename String::size_type offset = random(0, test.size());
- test += test.c_str() + offset;
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, random2.size());
+ random1.append(random2.c_str(), number);
+ return random1;
}
template<class String>
- String operator_plus_equal_char(String & test)
+ String append_cstr_number__self()
{
// 21.3.5
- test += random('a', 'z');
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, random1.size());
+ random1.append(random1.c_str(), number);
+ return random1;
}
template<class String>
- String append_string(String & test)
+ String append_cstr_number__selfcopy()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- test.append(str);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type number = random(0, random1.size());
+ random...
[truncated message content] |
|
From: <jfb...@us...> - 2009-03-10 19:56:19
|
Revision: 1003
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1003&view=rev
Author: jfbastien
Date: 2009-03-10 19:55:59 +0000 (Tue, 10 Mar 2009)
Log Message:
-----------
Simplify Num2String.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-10 18:36:42 UTC (rev 1002)
+++ trunk/test/flex_string/main.cpp 2009-03-10 19:55:59 UTC (rev 1003)
@@ -208,10 +208,7 @@
{
if(String::npos != value)
{
- typedef typename String::value_type CharType;
- std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
- stream << OpenCurlyString<String>() << value << CloseCurlyString<String>();
- return stream.str().c_str();
+ return Num2String<String, typename String::size_type>(value);
}
else
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-13 15:18:20
|
Revision: 1010
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1010&view=rev
Author: jfbastien
Date: 2009-03-13 15:17:59 +0000 (Fri, 13 Mar 2009)
Log Message:
-----------
Copy/paste mistake.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-13 13:54:51 UTC (rev 1009)
+++ trunk/test/flex_string/main.cpp 2009-03-13 15:17:59 UTC (rev 1010)
@@ -608,7 +608,7 @@
{
// 21.3.1
const typename String::size_type number = random(0, MaxString<String>::value);
- const typename String::size_type value = random('a', 'z');
+ const typename String::value_type value = random('a', 'z');
String result(number, value);
return result;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|