summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2011-03-19 15:14:50 +0000
committerArthur de Jong <arthur@arthurdejong.org>2011-03-19 15:14:50 +0000
commit58679f802ca6cdda16cf772e566782b1853213a0 (patch)
tree1caeafee94d2e3a3ccacdd4060b4e755493bf94f
parentf4930b502a6ea404b0ab1d316584cf1d267e886b (diff)
more tests and general test improvements
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1401 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--Makefile.am2
-rw-r--r--tests/test_expr.c7
-rw-r--r--[-rwxr-xr-x]tests/test_pamcmds.expect0
-rw-r--r--tests/test_tio.c64
4 files changed, 72 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 3711939..261fb32 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -114,7 +114,7 @@ rats.html:
splint.txt:
-env LARCH_PATH=/usr/share/splint/lib/ \
LCLIMPORTDIR=/usr/share/splint/imports/ \
- splint -checks \
+ splint -checks -mustfreefresh \
-warnposix +showsummary +showalluses +hints -namechecks \
-globstate -predboolint -mustfreeonly -temptrans -kepttrans \
-I. -I$(srcdir) -I$(top_builddir) $(DEFS) -D_REENTRANT -DDEBUG \
diff --git a/tests/test_expr.c b/tests/test_expr.c
index 2032296..3ee9773 100644
--- a/tests/test_expr.c
+++ b/tests/test_expr.c
@@ -59,8 +59,12 @@ static void test_expr_parse(void)
char buffer[1024];
assert(expr_parse("$test1",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
assertstreq(buffer,"foobar");
+ assert(expr_parse("\\$test1",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
+ assertstreq(buffer,"$test1");
assert(expr_parse("$empty",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
assertstreq(buffer,"");
+ assert(expr_parse("$foo1$empty-$foo2",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
+ assertstreq(buffer,"foobar-foobar");
assert(expr_parse("${test1}\\$",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
assertstreq(buffer,"foobar$");
assert(expr_parse("${test1:-default}",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
@@ -83,6 +87,9 @@ static void test_expr_parse(void)
assertstreq(buffer,"afoobarbfoobarec");
assert(expr_parse("a${test1}b${test2:+${empty:-d$test4}e}c",buffer,sizeof(buffer),expanderfn,NULL)!=NULL);
assertstreq(buffer,"afoobarbdfoobarec");
+ /* these are errors */
+ assert(expr_parse("$&",buffer,sizeof(buffer),expanderfn,NULL)==NULL);
+ assert(expr_parse("${a",buffer,sizeof(buffer),expanderfn,NULL)==NULL);
}
static void test_buffer_overflow(void)
diff --git a/tests/test_pamcmds.expect b/tests/test_pamcmds.expect
index bc80b86..bc80b86 100755..100644
--- a/tests/test_pamcmds.expect
+++ b/tests/test_pamcmds.expect
diff --git a/tests/test_tio.c b/tests/test_tio.c
index 212bdec..cad5ea5 100644
--- a/tests/test_tio.c
+++ b/tests/test_tio.c
@@ -275,6 +275,67 @@ static void test_reset(void)
assertok(pthread_join(wthread,NULL)==0);
}
+/* this test starts a reader and writer and does not write for a while */
+static void test_timeout_reader(void)
+{
+ int sp[2];
+ TFILE *rfp;
+ FILE *wfp;
+ struct timeval timeout;
+ uint8_t buf[20];
+ time_t start,end;
+ /* set up the socket pair */
+ assertok(socketpair(AF_UNIX,SOCK_STREAM,0,sp)==0);
+ /* open the writer */
+ assertok((wfp=fdopen(sp[0],"wb"))!=NULL);
+ /* open the reader */
+ timeout.tv_sec=1;
+ timeout.tv_usec=100000;
+ assertok((rfp=tio_fdopen(sp[1],&timeout,&timeout,2*1024,4*1024,2*1024,4*1024))!=NULL);
+ /* perform a read */
+ start=time(NULL);
+ assertok(tio_read(rfp,buf,sizeof(buf))!=0);
+ end=time(NULL);
+ assert(end>start);
+ /* close the files */
+ assertok(tio_close(rfp)==0);
+ assertok(fclose(wfp)==0);
+}
+
+/* this test starts a writer and an idle reader */
+static void test_timeout_writer(void)
+{
+ int sp[2];
+ FILE *rfp;
+ TFILE *wfp;
+ int i;
+ struct timeval timeout;
+ uint8_t buf[20];
+ time_t start,end;
+ /* set up the socket pair */
+ assertok(socketpair(AF_UNIX,SOCK_STREAM,0,sp)==0);
+ /* open the reader */
+ assertok((rfp=fdopen(sp[0],"rb"))!=NULL);
+ /* open the writer */
+ timeout.tv_sec=1;
+ timeout.tv_usec=100000;
+ assertok((wfp=tio_fdopen(sp[1],&timeout,&timeout,2*1024,4*1024,2*20,4*20+1))!=NULL);
+ /* perform a few write (these should be OK because they fill the buffer) */
+ assertok(tio_write(wfp,buf,sizeof(buf))==0);
+ assertok(tio_write(wfp,buf,sizeof(buf))==0);
+ assertok(tio_write(wfp,buf,sizeof(buf))==0);
+ assertok(tio_write(wfp,buf,sizeof(buf))==0);
+ /* one of these should fail but it depends on OS buffers */
+ start=time(NULL);
+ for (i=0;(i<10000)&&(tio_write(wfp,buf,sizeof(buf))==0);i++);
+ assert(i<10000);
+ end=time(NULL);
+ assert(end>start);
+ /* close the files */
+ assertok(tio_close(wfp)!=0); /* fails because of bufferred data */
+ assertok(fclose(rfp)==0);
+}
+
/* the main program... */
int main(int UNUSED(argc),char UNUSED(*argv[]))
{
@@ -290,5 +351,8 @@ int main(int UNUSED(argc),char UNUSED(*argv[]))
/* test_blocks(10,9,10,10); */
/* set tio_mark() and tio_reset() functions */
test_reset();
+ /* test timeout functionality */
+ test_timeout_reader();
+ test_timeout_writer();
return 0;
}