tdisc.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"
#if __STD_C
#else
Sfio_t* f;
size_t n;
#endif
{
size_t i;
char* s = (char*)buf;
if(sfgetc(f) >= 0)
terror("Stream should be locked");
return n;
for(i = 0; i < n; ++i)
if(s[i] >= 'a' && s[i] <= 'z')
s[i] = (s[i]-'a') + 'A';
return n;
}
#if __STD_C
#else
Sfio_t* f;
size_t n;
#endif
{
size_t i;
char* s = (char*)buf;
if(sfputc(f,0) >= 0)
terror("Stream should be locked2");
for(i = 0; i < n; ++i)
if(s[i] >= 'a' && s[i] <= 'z')
s[i] = (s[i]-'a') + 'A';
}
#if __STD_C
#else
Sfio_t* f;
size_t n;
#endif
{
size_t i;
char* s = (char*)buf;
if(sfgetc(f) >= 0)
terror("Stream should be locked");
return n;
for(i = 0; i < n; ++i)
if(s[i] >= 'A' && s[i] <= 'Z')
s[i] = (s[i]-'A') + 'a';
return n;
}
#if __STD_C
#else
Sfio_t* f;
size_t n;
#endif
{
static int called = 0;
if(!called)
{ called = 1;
return 6;
}
else
{ terror("Discipline is called twice");
return -1;
}
}
#if __STD_C
#else
Sfio_t* f;
size_t n;
#endif
{
Enext += n;
return n;
}
tmain()
{
char *l, *u, *s;
int n, r, fd[2];
int flags;
terror("Flags changed after discipline setting");
l = low;
strcpy(l, "abcdefghijklmnopqrstuvwxyz");
u = up;
strcpy(u, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
n = strlen(l);
terror("Creating temp file");
if((r = sfwrite(f,l,n)) != n)
terror("Writing data %d",r);
sfsync(f);
if(!(s = sfreserve(f,n,0)) )
terror("Reading string1");
if(strncmp(s,u,n) != 0)
{ s[n-1] = 0;
terror("Input1=%s, Expect=%s",s,u);
}
if(!(s = sfreserve(f,n,0)) )
terror("Reading string2");
if(strncmp(s,l,n) != 0)
{ s[n-1] = 0;
terror("Input2=%s, Expect=%s",s,l);
}
sfclose(f);
terror("Opening file");
terror("Writing data");
terror("Seeking");
terror("sfgetr");
terror("Bad data");
sfclose(f);
/* read-once discipline */
terror("Opening file");
terror("Sfreserve failed1");
if(sfvalue(f) != 6)
terror("Wrong reserved length1");
sfread(f,s,3);
terror("String open failed");
terror("Sfreserve failed2");
if(sfvalue(f) != 6)
terror("Wrong reserved length2");
sfread(f,s,6);
terror("sfreserve failed 3");
if(sfvalue(f) != 3)
terror("Wrong reserved length3");
sfclose(f);
terror("Opening file to write");
terror("Bad sfwrite");
terror("Bad sfwr");
terror("Bad call of sfwr");
sfclose(f);
/* test for setting discipline on an unseekable device */
terror("Bad pipe call");
terror("Can't create stream to read");
terror("Can't write to pipe");
terror("Can't reserve for data");
if(s[0] != '1' || s[1] != '2' || s[2] != '3' || s[3] != '4')
terror("Bad reserved data");
terror("Bad reopening of stream");
terror("Can't insert new discipline");
terror("Read wrong data size");
terror("Bad read data");
texit(0);
}