forked from boostorg/container
Introducing allocator_traits and pointer_traits changes into several libraries.
[SVN r76107]
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "check_equal_containers.hpp"
|
||||
#include "expand_bwd_test_allocator.hpp"
|
||||
#include "expand_bwd_test_template.hpp"
|
||||
#include "propagate_allocator_test.hpp"
|
||||
|
||||
using namespace boost::container;
|
||||
|
||||
@@ -32,13 +33,23 @@ typedef test::dummy_test_allocator<wchar_t> DummyWCharAllocator;
|
||||
typedef basic_string<wchar_t, std::char_traits<wchar_t>, DummyWCharAllocator> DummyWString;
|
||||
typedef test::dummy_test_allocator<DummyWString> DummyWStringAllocator;
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
//Explicit instantiations of container::basic_string
|
||||
template class basic_string<char, std::char_traits<char>, DummyCharAllocator>;
|
||||
template class basic_string<char, std::char_traits<char>, DummyCharAllocator>;
|
||||
template class basic_string<wchar_t, std::char_traits<wchar_t>, DummyWCharAllocator>;
|
||||
template class basic_string<char, std::char_traits<char>, test::simple_allocator<char> >;
|
||||
template class basic_string<wchar_t, std::char_traits<wchar_t>, test::simple_allocator<wchar_t> >;
|
||||
template class basic_string<char, std::char_traits<char>, std::allocator<char> >;
|
||||
template class basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >;
|
||||
|
||||
//Explicit instantiation of container::vectors of container::strings
|
||||
template class vector<DummyString, DummyStringAllocator>;
|
||||
template class vector<DummyWString, DummyWStringAllocator>;
|
||||
|
||||
}}
|
||||
|
||||
struct StringEqual
|
||||
{
|
||||
template<class Str1, class Str2>
|
||||
@@ -60,10 +71,64 @@ bool CheckEqualStringVector(StrVector1 *strvect1, StrVector2 *strvect2)
|
||||
strvect2->begin(), comp);
|
||||
}
|
||||
|
||||
template<class CharType>
|
||||
struct string_literals;
|
||||
|
||||
template<>
|
||||
struct string_literals<char>
|
||||
{
|
||||
static const char *String()
|
||||
{ return "String"; }
|
||||
static const char *Prefix()
|
||||
{ return "Prefix"; }
|
||||
static const char *Suffix()
|
||||
{ return "Suffix"; }
|
||||
static const char *LongString()
|
||||
{ return "LongLongLongLongLongLongLongLongLongLongLongLongLongString"; }
|
||||
|
||||
static void sprintf_number(char *buf, int number)
|
||||
{
|
||||
std::sprintf(buf, "%i", number);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct string_literals<wchar_t>
|
||||
{
|
||||
static const wchar_t *String()
|
||||
{ return L"String"; }
|
||||
static const wchar_t *Prefix()
|
||||
{ return L"Prefix"; }
|
||||
static const wchar_t *Suffix()
|
||||
{ return L"Suffix"; }
|
||||
static const wchar_t *LongString()
|
||||
{ return L"LongLongLongLongLongLongLongLongLongLongLongLongLongString"; }
|
||||
|
||||
static void sprintf_number(wchar_t *buffer, unsigned int number)
|
||||
{
|
||||
//For compilers without wsprintf, print it backwards
|
||||
const wchar_t *digits = L"0123456789";
|
||||
wchar_t *buf = buffer;
|
||||
|
||||
while(1){
|
||||
int rem = number % 10;
|
||||
number = number / 10;
|
||||
|
||||
*buf = digits[rem];
|
||||
++buf;
|
||||
if(!number){
|
||||
*buf = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template<class CharType>
|
||||
int string_test()
|
||||
{
|
||||
typedef std::string StdString;
|
||||
typedef std::basic_string<CharType> StdString;
|
||||
typedef vector<StdString> StdStringVector;
|
||||
typedef basic_string<CharType> BoostString;
|
||||
typedef vector<BoostString> BoostStringVector;
|
||||
@@ -81,9 +146,9 @@ int string_test()
|
||||
|
||||
//First, push back
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
auxBoostString = "String";
|
||||
auxStdString = "String";
|
||||
std::sprintf(buffer, "%i", i);
|
||||
auxBoostString = string_literals<CharType>::String();
|
||||
auxStdString = string_literals<CharType>::String();
|
||||
string_literals<CharType>::sprintf_number(buffer, i);
|
||||
auxBoostString += buffer;
|
||||
auxStdString += buffer;
|
||||
boostStringVect->push_back(auxBoostString);
|
||||
@@ -96,9 +161,9 @@ int string_test()
|
||||
|
||||
//Now push back moving
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
auxBoostString = "String";
|
||||
auxStdString = "String";
|
||||
std::sprintf(buffer, "%i", i);
|
||||
auxBoostString = string_literals<CharType>::String();
|
||||
auxStdString = string_literals<CharType>::String();
|
||||
string_literals<CharType>::sprintf_number(buffer, i);
|
||||
auxBoostString += buffer;
|
||||
auxStdString += buffer;
|
||||
boostStringVect->push_back(boost::move(auxBoostString));
|
||||
@@ -111,9 +176,9 @@ int string_test()
|
||||
|
||||
//push front
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
auxBoostString = "String";
|
||||
auxStdString = "String";
|
||||
std::sprintf(buffer, "%i", i);
|
||||
auxBoostString = string_literals<CharType>::String();
|
||||
auxStdString = string_literals<CharType>::String();
|
||||
string_literals<CharType>::sprintf_number(buffer, i);
|
||||
auxBoostString += buffer;
|
||||
auxStdString += buffer;
|
||||
boostStringVect->insert(boostStringVect->begin(), auxBoostString);
|
||||
@@ -126,9 +191,9 @@ int string_test()
|
||||
|
||||
//Now push front moving
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
auxBoostString = "String";
|
||||
auxStdString = "String";
|
||||
std::sprintf(buffer, "%i", i);
|
||||
auxBoostString = string_literals<CharType>::String();
|
||||
auxStdString = string_literals<CharType>::String();
|
||||
string_literals<CharType>::sprintf_number(buffer, i);
|
||||
auxBoostString += buffer;
|
||||
auxStdString += buffer;
|
||||
boostStringVect->insert(boostStringVect->begin(), boost::move(auxBoostString));
|
||||
@@ -142,8 +207,8 @@ int string_test()
|
||||
//Now test long and short representation swapping
|
||||
|
||||
//Short first
|
||||
auxBoostString = "String";
|
||||
auxStdString = "String";
|
||||
auxBoostString = string_literals<CharType>::String();
|
||||
auxStdString = string_literals<CharType>::String();
|
||||
BoostString boost_swapper;
|
||||
StdString std_swapper;
|
||||
boost_swapper.swap(auxBoostString);
|
||||
@@ -177,8 +242,8 @@ int string_test()
|
||||
return 1;
|
||||
|
||||
//Long string
|
||||
auxBoostString = "LongLongLongLongLongLongLongLongLongLongLongLongLongString";
|
||||
auxStdString = "LongLongLongLongLongLongLongLongLongLongLongLongLongString";
|
||||
auxBoostString = string_literals<CharType>::LongString();
|
||||
auxStdString = string_literals<CharType>::LongString();
|
||||
boost_swapper = BoostString();
|
||||
std_swapper = StdString();
|
||||
boost_swapper.swap(auxBoostString);
|
||||
@@ -208,9 +273,9 @@ int string_test()
|
||||
std::sort(stdStringVect->begin(), stdStringVect->end());
|
||||
if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;
|
||||
|
||||
const CharType prefix [] = "Prefix";
|
||||
const int prefix_size = sizeof(prefix)/sizeof(prefix[0])-1;
|
||||
const CharType sufix [] = "Suffix";
|
||||
const CharType *prefix = string_literals<CharType>::Prefix();
|
||||
const int prefix_size = std::char_traits<CharType>::length(prefix);
|
||||
const CharType *sufix = string_literals<CharType>::Suffix();
|
||||
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
(*boostStringVect)[i].append(sufix);
|
||||
@@ -247,10 +312,10 @@ int string_test()
|
||||
for(int i = 0; i < MaxSize; ++i){
|
||||
(*boostStringVect)[i].replace((*boostStringVect)[i].begin(),
|
||||
(*boostStringVect)[i].end(),
|
||||
"String");
|
||||
string_literals<CharType>::String());
|
||||
(*stdStringVect)[i].replace((*stdStringVect)[i].begin(),
|
||||
(*stdStringVect)[i].end(),
|
||||
"String");
|
||||
string_literals<CharType>::String());
|
||||
}
|
||||
|
||||
if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;
|
||||
@@ -261,6 +326,80 @@ int string_test()
|
||||
stdStringVect->end());
|
||||
if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;
|
||||
|
||||
//Check addition
|
||||
{
|
||||
typedef std::basic_string<CharType> StdString;
|
||||
typedef basic_string<CharType> BoostString;
|
||||
|
||||
BoostString bs2 = string_literals<CharType>::String();
|
||||
StdString ss2 = string_literals<CharType>::String();
|
||||
BoostString bs3 = string_literals<CharType>::Suffix();
|
||||
StdString ss3 = string_literals<CharType>::Suffix();
|
||||
BoostString bs4 = bs2 + bs3;
|
||||
StdString ss4 = ss2 + ss3;
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
bs4 = bs2 + BoostString();
|
||||
ss4 = ss2 + StdString();
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
bs4 = BoostString() + bs2;
|
||||
ss4 = StdString() + ss2;
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
bs4 = BoostString() + boost::move(bs2);
|
||||
ss4 = StdString() + boost::move(ss2);
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
bs2 = string_literals<CharType>::String();
|
||||
ss2 = string_literals<CharType>::String();
|
||||
bs4 = boost::move(bs2) + BoostString();
|
||||
ss4 = boost::move(ss2) + StdString();
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
bs2 = string_literals<CharType>::String();
|
||||
ss2 = string_literals<CharType>::String();
|
||||
bs4 = string_literals<CharType>::Prefix() + boost::move(bs2);
|
||||
ss4 = string_literals<CharType>::Prefix() + boost::move(ss2);
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
bs2 = string_literals<CharType>::String();
|
||||
ss2 = string_literals<CharType>::String();
|
||||
bs4 = boost::move(bs2) + string_literals<CharType>::Suffix();
|
||||
ss4 = boost::move(ss2) + string_literals<CharType>::Suffix();
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
bs2 = string_literals<CharType>::String();
|
||||
ss2 = string_literals<CharType>::String();
|
||||
bs4 = string_literals<CharType>::Prefix() + bs2;
|
||||
ss4 = string_literals<CharType>::Prefix() + ss2;
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
bs2 = string_literals<CharType>::String();
|
||||
ss2 = string_literals<CharType>::String();
|
||||
bs4 = bs2 + string_literals<CharType>::Suffix();
|
||||
ss4 = ss2 + string_literals<CharType>::Suffix();
|
||||
if(!StringEqual()(bs4, ss4)){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
//When done, delete vector
|
||||
delete boostStringVect;
|
||||
delete stdStringVect;
|
||||
@@ -278,15 +417,51 @@ bool test_expand_bwd()
|
||||
return test::test_all_expand_bwd<string_type>();
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
class string_propagate_test_wrapper
|
||||
: public basic_string<T, std::char_traits<T>, A>
|
||||
{
|
||||
BOOST_COPYABLE_AND_MOVABLE(string_propagate_test_wrapper)
|
||||
typedef basic_string<T, std::char_traits<T>, A> Base;
|
||||
public:
|
||||
string_propagate_test_wrapper()
|
||||
: Base()
|
||||
{}
|
||||
|
||||
string_propagate_test_wrapper(const string_propagate_test_wrapper &x)
|
||||
: Base(x)
|
||||
{}
|
||||
|
||||
string_propagate_test_wrapper(BOOST_RV_REF(string_propagate_test_wrapper) x)
|
||||
: Base(boost::move(static_cast<Base&>(x)))
|
||||
{}
|
||||
|
||||
string_propagate_test_wrapper &operator=(BOOST_COPY_ASSIGN_REF(string_propagate_test_wrapper) x)
|
||||
{ this->Base::operator=(x); return *this; }
|
||||
|
||||
string_propagate_test_wrapper &operator=(BOOST_RV_REF(string_propagate_test_wrapper) x)
|
||||
{ this->Base::operator=(boost::move(static_cast<Base&>(x))); return *this; }
|
||||
|
||||
void swap(string_propagate_test_wrapper &x)
|
||||
{ this->Base::swap(x); }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
if(string_test<char>()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(string_test<wchar_t>()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!test_expand_bwd())
|
||||
return 1;
|
||||
|
||||
if(!boost::container::test::test_propagate_allocator<string_propagate_test_wrapper>())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user