/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1999-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#include "sftest.h"
tmain()
{
int i, n, k;
Sfoff_t o;
Sfio_t* f;
terror("Opening file to write");
terror("Writing data");
terror("Opening file to read");
if(!(s = (char*)sfreserve(f,10,0)) )
terror("sfreserve failed");
terror("Did not get correct data");
if((s = (char*)sfreserve(f,10,0)) )
terror("sfreserve should not have succeeded");
if(sfvalue(f) != 8)
terror("sfreserve should have left the right unread record length");
if(!(s = (char*)sfreserve(f,4,0)) )
terror("sfreserve should return 4 bytes");
terror("Got wrong data");
if((s = (char*)sfreserve(f,10,0)) )
terror("sfreserve should not have succeeded2");
if(sfvalue(f) != 4)
terror("sfreserve should have left 4 bytes length");
terror("sfreserve should have returned last unread record");
terror("Record has wrong data");
sfclose(f);
terror("Wrong buffer");
terror("Write failed");
terror("Wrong reserved pointer");
terror("Opening file");
terror("Could not lock stdout");
terror("stdout wasn't locked");
terror("stdout can't be unlocked");
for(i = 0; i < sizeof(buf); ++i)
n = 0;
for(i = 0; i < 33; ++i)
terror("Can't reserve write buffer");
terror("Writing to file");
else n += sizeof(buf);
}
terror("Opening file2");
terror("Wrong size for file");
i = 0;
for(;;)
break;
else i += 16*sizeof(buf);
}
if(i != n)
terror("Did not read data");
terror("sfseek failed0");
i = 0;
for(;;)
break;
else i += 16*sizeof(buf);
}
if(i != n)
terror("Did not read data2");
terror("Can't open to write");
for(i = 0; i < 32; ++i)
{ for(k = 0; k < sizeof(bigbuf); ++k)
}
terror("Opening to read");
terror("sfreserve failed");
for(i = 0; i < 16; ++i)
{ for(k = 0; k < sizeof(bigbuf); ++k)
if(*s++ != ('0' + (k+i)%10))
terror("Wrong data i=%d k=%d",i,k);
}
terror("sfread failed");
s = bigbuf;
for(i = 1; i < 2; ++i)
{ for(k = 0; k < sizeof(bigbuf); ++k)
if(*s++ != ('0' + (k+i)%10))
terror("Wrong data2 i=%d k=%d",i,k);
}
terror("sfreserve failed2");
}
#ifdef MAP_TYPE
terror("Reserve pointer changed?");
#endif
for(i = 2; i < 17; ++i)
{ for(k = 0; k < sizeof(bigbuf); ++k)
if(*s++ != ('0' + (k+i)%10))
terror("Wrong data3 i=%d k=%d",i,k);
}
terror("Opening for write");
for(i = 0; i < 100; ++i)
bigbuf[i] = 'a';
for(i = 0; i < 101; ++i)
terror("Bad write to file");
terror("Opening for read");
for(i = 0; i < 10; ++i)
terror("Can't reserve from file");
for(i = 0; i < 5; ++i)
terror("Bad write to file2");
n = 5000;
n += 500;
terror("Wrong reserve size from file");
tcleanup();
terror("Can't make pipe");
terror("Can't write to pipe");
terror("Can't creat pipe stream");
strcmp(s,"abcdefghijklmnopqrstuvwxyz") != 0)
terror("Get wrong string");
terror("There should not be enough data for this");
terror("Fail to reserve remainder of stream");
terror("Reserved data was corrupted");
for(i = 0; i < 18; i += 6)
{
if(!(f = sftmp(i)) )
terror("Can't open tempfile");
for(k = 0; k < 10; ++k)
if(!sfreserve(f,0,-1) )
terror("No write buffer?");
terror("No file created");
if(sfgetc(f) != '0')
terror("Getting the 0");
terror("Read reserved failed");
if(sfgetc(f) != '1')
terror("Getting the 1");
sfclose(f);
}
if(!(f = sftmp(0)) )
terror("Can't open file");
for(i = 0; i < sizeof(bigbuf); ++i)
terror("Writing to file");
terror("sfreserve failed at bottom1");
if(sfvalue(f) != 100)
terror("Wrong data at bottom");
sfread(f,s,95);
terror("sfreserve failed at bottom2");
if(sfvalue(f) != 100)
terror("Wrong data at bottom2");
sfread(f,s,5);
for(i = 1; i < 10; ++i)
terror("sfreserve failed at bottom loop");
if(sfvalue(f) != 100)
terror("Wrong data at bottom loop");
sfread(f,s,100);
}
for(i = 0; i < 16; ++i)
terror("sfreserve failed 11");
if((n = sfvalue(f)) < 4096)
terror("sfvalue is wrong");
terror("sfread failed");
terror("sfreserve failed 12");
if(sfvalue(f) < 16 )
terror("hmm");
terror("can't open a read string stream");
terror("can't lock an empty string stream");
if(sfread(f,s,0) != 0)
terror("can't unlock");
if((s = sfreserve(f, 0, 0)) )
terror("reserve successful on an empty stream");
terror("can't open a write string stream");
terror("can't lock an empty string stream");
if(sfwrite(f,s,0) != 0)
terror("can't unlock");
if((s = sfreserve(f, 0, 0)) )
terror("reserve successful on an empty stream");
texit(0);
}