#include <new>
#include <string>
#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 );
}
}
int main()
{
__set_testsuite_memlimit();
test01();
test02();
test03();
return 0;
}