tstring.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* 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"
/* test to make sure sfputr() does not cause too many buffer reallocation */
static int Putrextend = 0;
{
Putrextend += 1;
return 0;
}
tmain()
{
Sfio_t *f;
int n;
char buf[8192];
terror("Can't open string stream");
terror("Can't insert putr discipline");
for(n = 0; n < sizeof(Putrbuf)-1; ++n)
terror("Wrong sfputr return size=%d", n);
if(Putrextend != 1)
terror("Can't read output string");
terror("Wrong data");
sfclose(f);
os = "123\n456\n789\n";
terror("Opening string");
while((s = sfgetr(f,'\n',0)) )
{
if(s != os)
terror("Did not get string");
}
terror("Did not match everything");
terror("Stream should have exhausted");
if(!(f = sfopen(f,(char*)0,"s+")))
terror("Opening string for r/w");
for(n = 0; n < 26; ++n)
terror("Output");
if(sfgetc(f) >= 0)
terror("Read a non-existent byte");
if(!(s = sfreserve(f,26,0)) )
terror("Didnot get the right amount of data");
for(n = 0; n < 26; ++n)
terror("Output2");
if(!(s = sfreserve(f,50,0)) )
terror("Didnot get the right amount of data2");
if(!(f = sfopen(f,(char*)0,"s+")))
terror("Opening string for r/w");
sfwrite(f,s,0) != 0)
terror("Buffer size should be positive");
sfwrite(f,s,0) != 0)
terror("Bad buffer size");
if(!(f = sfopen(f,(char*)0,"s+")))
terror("Opening string for r/w");
terror("Can't write large buffer");
terror("Opening string for r/w");
for(n = 0; n < 16*1024; ++n)
{
if((n%1024) == 0)
sfputc(f,'a');
}
sfputc(f,'a');
}
sfwrite(f,s,0) != 0)
terror("Wrong buffer size");
while(n-- > 0)
if(*s++ != 'a')
terror("Wrong data");
terror("Opening r/w string");
for(n = 0; n < 10; n++)
sfputc(f,'a'+n);
sfputc(f,'\n');
for(n = 0; n <= 11 ; ++n)
if(sfgetc(f) != 'a'+n)
break;
if(n != 10)
terror("Get too many");
if(sfgetc(f) >= 0)
terror("Reading non-existent data");
if(!sfeof(f))
terror("Didn't get eof");
texit(0);
}