#include <fstream>
#include <testsuite_hooks.h>
#include <testsuite_io.h>
const char name_01[] = "seekoff-2io.tst";
void test05()
{
using namespace std;
using namespace __gnu_test;
typedef filebuf::int_type int_type;
typedef filebuf::pos_type pos_type;
typedef filebuf::off_type off_type;
bool test __attribute__((unused)) = true;
streamsize strmsz_1, strmsz_2;
int_type c1;
int_type c2;
int_type c3;
pos_type pt_1(off_type(-1));
pos_type pt_2(off_type(0));
off_type off_1 = 0;
off_type off_2 = 0;
{
constraint_filebuf fb;
fb.pubsetbuf(0, 0);
fb.open(name_01, ios_base::out | ios_base::in);
VERIFY( fb.unbuffered() );
strmsz_1 = fb.in_avail();
pt_1 = fb.pubseekoff(2, ios_base::beg);
strmsz_2 = fb.in_avail();
off_1 = off_type(pt_1);
VERIFY( off_1 > 0 );
c1 = fb.snextc(); VERIFY( c1 == '9' );
fb.pubseekoff(3, ios_base::beg);
c2 = fb.sputc('\n'); fb.pubseekoff(4, ios_base::beg);
c3 = fb.sgetc();
VERIFY( c2 != c3 );
VERIFY( c3 == '9' );
fb.pubsync();
c1 = fb.sgetc();
VERIFY( c1 == c3 );
pt_2 = fb.pubseekoff(2, ios_base::cur);
off_2 = off_type(pt_2);
VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
c1 = fb.snextc(); VERIFY( c1 == '1' );
fb.pubseekoff(0, ios_base::cur);
c2 = fb.sputc('x'); c3 = fb.sputc('\n');
fb.pubseekoff(0, ios_base::cur);
c1 = fb.sgetc();
fb.pubsync();
c3 = fb.sgetc();
VERIFY( c1 == c3 );
pt_2 = fb.pubseekoff(0, ios_base::end);
off_1 = off_type(pt_2);
VERIFY( off_1 > off_2 ); c3 = fb.sputc('\n');
strmsz_1 = fb.sputn("because because because. . .", 28);
VERIFY( strmsz_1 == 28 );
fb.pubseekoff(-1, ios_base::end);
fb.sgetc();
c1 = fb.sungetc();
c1 = fb.sgetc();
fb.pubsync();
c3 = fb.sgetc();
VERIFY( c1 == c3 );
VERIFY( fb.unbuffered() );
}
}
int main()
{
test05();
return 0;
}