#include <new>
#include <string>
#include <vector>
#include <stdexcept>
#include <testsuite_hooks.h>
void test01(void)
{
bool test = true;
typedef std::string::size_type csize_type;
typedef std::string::iterator citerator;
csize_type npos = std::string::npos;
csize_type csz01, csz02;
const char str_lit01[] = "rodeo beach, marin";
const std::string str01(str_lit01);
const std::string str02("baker beach, san francisco");
csz01 = str01.size();
try {
std::string str03(str01, csz01 + 1);
VERIFY( false );
}
catch(std::out_of_range& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
try {
std::string str03(str01, csz01);
VERIFY( str03.size() == 0 );
VERIFY( str03.size() <= str03.capacity() );
}
catch(...) {
VERIFY( false );
}
csz01 = str01.max_size();
try {
std::string str03(str_lit01, csz01 + 1);
VERIFY( true );
}
catch(std::length_error& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
try {
std::string str04(str_lit01, npos);
VERIFY( true );
}
catch(std::length_error& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
try {
std::string str03(csz01 - 1, 'A');
VERIFY( str03.size() == csz01 - 1 );
VERIFY( str03.size() <= str03.capacity() );
}
catch(std::bad_alloc& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
std::string str04(str_lit01);
VERIFY( str01 == str04 );
csz01 = str01.max_size();
try {
std::string str03(csz01 + 1, 'z');
VERIFY( false );
}
catch(std::length_error& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
try {
std::string str04(npos, 'b'); VERIFY( false );
}
catch(std::length_error& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
try {
std::string str03(csz01 - 1, 'z');
VERIFY( str03.size() != 0 );
VERIFY( str03.size() <= str03.capacity() );
}
catch(std::bad_alloc& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
std::string str06(str01.begin(), str01.end());
VERIFY( str06 == str01 );
}
void test02()
{
bool test = true;
std::string s(10,0);
VERIFY( s.size() == 10 );
}
void test03()
{
bool test = true;
const char* with_nulls = "This contains \0 a zero byte.";
std::string s1 (with_nulls, 28);
VERIFY( s1.size() == 28 );
std::string s2 (s1);
VERIFY( s2.size() == 28 );
const char* bogus = 0;
try
{
std::string str1(bogus);
VERIFY( false );
}
catch(std::exception& fail)
{
VERIFY( true );
}
try
{
std::string str2(bogus, 5);
VERIFY( false );
}
catch(std::exception& fail)
{
VERIFY( true );
}
}
void test04()
{
bool test = true;
std::string str01("portofino");
std::string::reverse_iterator i1 = str01.rbegin();
std::string::reverse_iterator i2 = str01.rend();
std::string str02(i1, i2);
VERIFY( str02 == "onifotrop" );
}
void test05()
{
bool test = true;
std::vector<char> empty;
std::string empty2(empty.begin(), empty.end());
char const * s = NULL;
std::string zero_length_built_with_NULL(s,0);
}
int main()
{
__gnu_cxx_test::set_memory_limits();
test01();
test02();
test03();
test04();
test05();
return 0;
}