From 024fde50cc416a089bd1240cd993716557f14bae Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Tue, 1 Jan 2008 20:53:44 +0000 Subject: add limited implementation of tio_mark() and tio_reset() functions to do limited seeks in the read stream, clean up header file comments and write tests for new code git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@547 ef36b2f9-881f-0410-afb5-c4e39611909c --- tests/test_tio.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 5 deletions(-) (limited to 'tests/test_tio.c') diff --git a/tests/test_tio.c b/tests/test_tio.c index 5e8758b..f3bc8f8 100644 --- a/tests/test_tio.c +++ b/tests/test_tio.c @@ -2,7 +2,7 @@ test_tio.c - simple test for the tio module This file is part of the nss-ldapd library. - Copyright (C) 2007 Arthur de Jong + Copyright (C) 2007, 2008 Arthur de Jong This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -55,7 +55,7 @@ static void *help_tiowriter(void *arg) timeout.tv_sec=hargs->timeout; timeout.tv_usec=0; /* open the file */ - fp = tio_fdopen(hargs->fd,&timeout,&timeout); + fp=tio_fdopen(hargs->fd,&timeout,&timeout); assert(fp!=NULL); /* write the blocks */ i=0; @@ -87,7 +87,7 @@ static void *help_tioreader(void *arg) timeout.tv_sec=hargs->timeout; timeout.tv_usec=0; /* open the file */ - fp = tio_fdopen(hargs->fd,&timeout,&timeout); + fp=tio_fdopen(hargs->fd,&timeout,&timeout); assert(fp!=NULL); /* read the blocks */ i=0; @@ -115,7 +115,7 @@ static void *help_normwriter(void *arg) buf=(uint8_t *)malloc(hargs->blocksize); assert(buf!=NULL); /* open the file */ - fp = fdopen(hargs->fd,"wb"); + fp=fdopen(hargs->fd,"wb"); assert(fp!=NULL); /* write the blocks */ i=0; @@ -139,7 +139,7 @@ static void *help_normreader(void *arg) size_t i,j,k; struct helper_args *hargs=(struct helper_args *)arg; /* open the file */ - fp = fdopen(hargs->fd,"rb"); + fp=fdopen(hargs->fd,"rb"); assert(fp!=NULL); /* read the blocks */ i=0; @@ -189,6 +189,73 @@ static int test_blocks(size_t wbs, size_t wbl, size_t rbs, size_t rbl) return 0; } +static void test_reset(void) +{ + int sp[2]; + pthread_t wthread; + struct helper_args wargs; + TFILE *fp; + struct timeval timeout; + size_t i,j,k,save; + uint8_t buf[10]; + /* set up the socket pair */ + assert(socketpair(AF_UNIX,SOCK_STREAM,0,sp)==0); + /* start the writer thread */ + wargs.fd=sp[0]; + wargs.blocksize=4*1024; /* the current TIO_BUFFERSIZE */ + wargs.blocks=5; + wargs.timeout=2; + assert(pthread_create(&wthread,NULL,help_tiowriter,&wargs)==0); + /* set up read handle */ + timeout.tv_sec=2; + timeout.tv_usec=0; + fp=tio_fdopen(sp[1],&timeout,&timeout); + assert(fp!=NULL); + /* perform 20 reads */ + i=0; + for (k=0;k<20;k++) + { + assert(tio_read(fp,buf,sizeof(buf))==0); + /* check the buffer */ + for (j=0;j