stringbuf_virtuals.cc [plain text]
#include <sstream>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
bool test = true;
char buf[512];
const char* strlit = "how to tell a story and other essays: mark twain";
const size_t strlitsize = std::strlen(strlit);
stringbuf sbuf(ios_base::out);
sbuf.pubsetbuf(buf, strlitsize);
sbuf.sputn(strlit, strlitsize);
VERIFY( std::strncmp(strlit, buf, strlitsize) != 0 );
}
void test02(std::stringbuf& in, bool pass)
{
using namespace std;
typedef streambuf::pos_type pos_type;
typedef streambuf::off_type off_type;
pos_type bad = pos_type(off_type(-1));
pos_type p = 0;
p = in.pubseekoff(0, ios_base::beg, ios_base::in);
if (pass)
VERIFY( p != bad );
p = in.pubseekoff(0, ios_base::beg, ios_base::out);
VERIFY( p == bad );
p = in.pubseekoff(0, ios_base::beg);
VERIFY( p == bad );
p = in.pubseekpos(0, ios_base::in);
if (pass)
VERIFY( p != bad );
p = in.pubseekpos(0, ios_base::out);
VERIFY( p == bad );
p = in.pubseekpos(0);
VERIFY( p == bad );
}
void test08()
{
using std::locale;
bool test = true;
locale loc;
std::stringbuf ob;
VERIFY( ob.getloc() == loc );
locale::global(locale("en_US"));
VERIFY( ob.getloc() == loc );
locale loc_de ("de_DE");
locale ret = ob.pubimbue(loc_de);
VERIFY( ob.getloc() == loc_de );
VERIFY( ret == loc );
locale::global(loc);
VERIFY( ob.getloc() == loc_de );
}
int main()
{
using namespace std;
test01();
stringbuf in1("Hedy Lamarr", ios_base::in);
stringbuf in2(ios_base::in);
stringbuf in3("", ios_base::in);
test02(in1, true);
test02(in2, false);
test02(in3, false);
test08();
return 0;
}