/***********************************************************************
* *
* 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()
{
char* s;
int i, n;
terror("Can't open file");
terror("Writing");
terror("Seeking");
if((n = (int)sfsize(f)) != 1000)
terror("Wrong size %d", n);
terror("Can't open stream");
terror("Seeking2");
terror("Wrong size2 %d", n);
if((n = (int)sfsize(f)) != 1000)
terror("Wrong size3 %d", n);
sfputc(f,'a');
if((n = (int)sfsize(f)) != 2000)
terror("Wrong size4 %d", n);
terror("Can't open string stream");
if(sfsize(f) != 10)
terror("String size is wrong1");
if(sfsize(f) != 10)
terror("String size is wrong2");
sfputc(f,'a');
if(sfsize(f) != 20)
terror("String size is wrong3");
if(sfsize(f) != 20)
terror("String size is wrong4");
terror("String size is wrong5");
sfread(f,s,5);
if(sfsize(f) != 20)
terror("String size is wrong6");
if(sfsize(f) != 25)
terror("String size is wrong7");
terror("Can't open string stream2");
terror("SF_MALLOC should not have been set");
if(sfsize(f) != 10)
terror("String size is wrong8");
terror("Write wrong amount %d", n);
if(sfsize(f) != 10)
terror("String size is wrong9");
terror("Reopening file1");
for(i = 0; i < 10000; ++i)
terror("sfputc failed");
terror("Reopening file2");
if(sfsize(f) != 10000)
terror("Bad size of file1");
for(i = 0; i < 20; ++i)
if(!sfreserve(f,100,0))
terror("Reserve failed");
s = buf+1024;
for(i = 0; i < 20; ++i)
s[i] = '0' + i%10;
terror("Write failed");
if(sfsize(f) != 10010)
terror("Bad size of file2");
for(i = 0; i < 10; ++i)
{ if(!(s = sfreserve(f,1001,0)) )
terror("Reserve failed2");
if(s[0] != '0'+i)
terror("Bad data1");
}
for(n = 0; n < 1001; ++n)
if(s[n] != ((n+i-1)%10 + '0') )
terror("Bad data");
/* test to see if a string stream extends ok during writes */
s = malloc(5);
if(!f)
terror("Can't create string stream");
terror("Bad write to string stream");
terror("Bad write to string stream2");
if(sfputc(f,0) != 0)
terror("sfputc failed");
terror("sfseek failed");
terror("sfread gets wrong amount of data %d", n);
terror("Get wrong data");
texit(0);
}