diff options
author | Michael Zucci <zucchi@src.gnome.org> | 2000-12-05 20:07:01 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-12-05 20:07:01 +0800 |
commit | e57a50f5329105e8b5e6bf4497c2e09079012a0d (patch) | |
tree | 4558f818b1e48eb2a099b653d8d00d60df7e719f /camel | |
parent | 58b924bf6e9c9d9072744041c3f1adaa9ddbedf4 (diff) | |
download | gsoc2013-evolution-e57a50f5329105e8b5e6bf4497c2e09079012a0d.tar.gz gsoc2013-evolution-e57a50f5329105e8b5e6bf4497c2e09079012a0d.tar.zst gsoc2013-evolution-e57a50f5329105e8b5e6bf4497c2e09079012a0d.zip |
Stream testing stuff.
svn path=/trunk/; revision=6792
Diffstat (limited to 'camel')
-rw-r--r-- | camel/tests/lib/streams.c | 242 | ||||
-rw-r--r-- | camel/tests/lib/streams.h | 12 | ||||
-rw-r--r-- | camel/tests/stream/README | 4 |
3 files changed, 258 insertions, 0 deletions
diff --git a/camel/tests/lib/streams.c b/camel/tests/lib/streams.c new file mode 100644 index 0000000000..b4b5e94f59 --- /dev/null +++ b/camel/tests/lib/streams.c @@ -0,0 +1,242 @@ +/* + stream tests + + todo: do we need a seek test that seeks beyond the eos, writes, + then reads and checks for 0's in the space? +*/ + +#include "camel/camel-stream.h" +#include "camel/camel-seekable-stream.h" +#include "camel/camel-seekable-substream.h" + +#include "streams.h" + +#include "camel-test.h" + +static char teststring[] = "\xaa\x55\xc0\x0c\xff\x00"; +static char testbuf[10240]; + +/* pass in an empty read/write stream */ +void +test_stream_seekable_writepart(CamelSeekableStream *s) +{ + off_t end; + int i; + + push("seekable stream test, writing "); + + check(camel_seekable_stream_tell(s) == 0); + check(camel_seekable_stream_seek(s, 0, CAMEL_STREAM_SET) == 0); + check(camel_seekable_stream_tell(s) == 0); + + check(camel_stream_write(CAMEL_STREAM(s), "", 0) == 0); + check(camel_seekable_stream_tell(s) == 0); + check(camel_stream_write(CAMEL_STREAM(s), "\n", 1) == 1); + check(camel_seekable_stream_tell(s) == 1); + + for (i=0;i<10240;i++) { + check(camel_stream_write(CAMEL_STREAM(s), teststring, sizeof(teststring)) == sizeof(teststring)); + check(camel_seekable_stream_tell(s) == 1 + (i+1)*sizeof(teststring)); + } + end = 10240*sizeof(teststring)+1; + + check_msg(camel_seekable_stream_seek(s, 0, CAMEL_STREAM_END) == end, "seek =%d end = %d", + camel_seekable_stream_seek(s, 0, CAMEL_STREAM_END), end); + + check(camel_seekable_stream_seek(s, 0, CAMEL_STREAM_END) == end); + check(camel_seekable_stream_tell(s) == end); + /* need to read 0 first to set eos */ + check(camel_stream_read(CAMEL_STREAM(s), testbuf, 10240) == 0); + check(camel_stream_eos(CAMEL_STREAM(s))); + + pull(); +} + +void +test_stream_seekable_readpart(CamelSeekableStream *s) +{ + off_t off, new, end; + int i, j; + + push("seekable stream test, re-reading"); + + end = 10240*sizeof(teststring)+1; + + check(camel_seekable_stream_seek(s, 0, CAMEL_STREAM_SET) == 0); + check(camel_seekable_stream_tell(s) == 0); + check(!camel_stream_eos(CAMEL_STREAM(s))); + + off = 0; + for (i=0;i<1024;i++) { + + new = i*3; + + /* exercise all seek methods */ + switch(i % 3) { + case 0: + check(camel_seekable_stream_seek(s, new, CAMEL_STREAM_SET) == new); + break; + case 1: + check(camel_seekable_stream_seek(s, new-off, CAMEL_STREAM_CUR) == new); + break; + case 2: + check(camel_seekable_stream_seek(s, new-end, CAMEL_STREAM_END) == new); + break; + } + check(camel_seekable_stream_tell(s) == new); + + check(camel_stream_read(CAMEL_STREAM(s), testbuf, i*3) == i*3); + for (j=0;j<i*3;j++) { + int k = new + j; + + if (k==0) { + check(testbuf[j] == '\n'); + } else { + check(testbuf[j] == teststring[(k-1) % sizeof(teststring)]); + } + } + off = new+i*3; + } + + /* verify end-of-file behaviour */ + check(camel_seekable_stream_seek(s, -1, CAMEL_STREAM_END) == end-1); + check(camel_seekable_stream_tell(s) == end-1); + + check(camel_stream_read(CAMEL_STREAM(s), testbuf, 10240) == 1); + check(testbuf[0] == teststring[sizeof(teststring)-1]); + + check(camel_stream_read(CAMEL_STREAM(s), testbuf, 10240) == 0); + check(camel_seekable_stream_seek(s, 0, CAMEL_STREAM_CUR) == end); + check(camel_seekable_stream_tell(s) == end); + check(camel_stream_eos(CAMEL_STREAM(s))); + + pull(); +} + +/* + 0 = write to the substream + 1 = write to the parent stream at the right spot +*/ +void +test_seekable_substream_writepart(CamelStream *s, int type) +{ + CamelSeekableStream *ss = (CamelSeekableStream *)s; + CamelSeekableSubstream *sus = (CamelSeekableSubstream *)s; + CamelSeekableStream *sp = sus->parent_stream; + int i, len; + off_t end; + + push("writing substream, type %d", type); + + if (type == 1) { + check(camel_seekable_stream_seek(sp, ss->bound_start, CAMEL_STREAM_SET) == ss->bound_start); + s = (CamelStream *)sp; + } else { + check(camel_seekable_stream_tell(ss) == ss->bound_start); + check(camel_seekable_stream_seek(ss, 0, CAMEL_STREAM_SET) == ss->bound_start); + } + + check(camel_seekable_stream_tell(CAMEL_SEEKABLE_STREAM(s)) == ss->bound_start); + + check(camel_stream_write(s, "", 0) == 0); + check(camel_seekable_stream_tell(CAMEL_SEEKABLE_STREAM(s)) == ss->bound_start); + + /* fill up the bounds with writes */ + if (ss->bound_end != CAMEL_STREAM_UNBOUND) { + for (i=0;i<(ss->bound_end-ss->bound_start)/sizeof(teststring);i++) { + check(camel_stream_write(s, teststring, sizeof(teststring)) == sizeof(teststring)); + check(camel_seekable_stream_tell(CAMEL_SEEKABLE_STREAM(s)) == ss->bound_start + (i+1)*sizeof(teststring)); + } + len = (ss->bound_end-ss->bound_start) % sizeof(teststring); + check(camel_stream_write(s, teststring, len) == len); + check(camel_seekable_stream_tell(CAMEL_SEEKABLE_STREAM(s)) == ss->bound_end); + if (type == 0) { + check(camel_stream_write(s, teststring, sizeof(teststring)) == 0); + check(camel_stream_eos(s)); + check(camel_seekable_stream_tell(CAMEL_SEEKABLE_STREAM(s)) == ss->bound_end); + } + } else { + /* just 10K */ + for (i=0;i<10240;i++) { + check(camel_stream_write(CAMEL_STREAM(s), teststring, sizeof(teststring)) == sizeof(teststring)); + check(camel_seekable_stream_tell(CAMEL_SEEKABLE_STREAM(s)) == ss->bound_start + (i+1)*sizeof(teststring)); + } + + /* we can't really verify any end length here */ + } + + pull(); +} + +void +test_seekable_substream_readpart(CamelStream *s) +{ + CamelSeekableStream *ss = (CamelSeekableStream *)s; + CamelSeekableSubstream *sus = (CamelSeekableSubstream *)s; + CamelSeekableStream *sp = sus->parent_stream; + int i, len; + off_t end; + + push("reading substream"); + + check(camel_seekable_stream_seek(ss, 0, CAMEL_STREAM_SET) == ss->bound_start); + check(camel_seekable_stream_tell(ss) == ss->bound_start); + + check(camel_seekable_stream_seek(sp, ss->bound_start, CAMEL_STREAM_SET) == ss->bound_start); + check(camel_seekable_stream_tell(sp) == ss->bound_start); + + /* check writes, cross check with parent stream */ + if (ss->bound_end != CAMEL_STREAM_UNBOUND) { + for (i=0;i<(ss->bound_end-ss->bound_start)/sizeof(teststring);i++) { + check(camel_stream_read(s, testbuf, sizeof(teststring)) == sizeof(teststring)); + check(memcmp(testbuf, teststring, sizeof(teststring)) == 0); + check(camel_seekable_stream_tell(ss) == ss->bound_start + (i+1)*sizeof(teststring)); + + /* yeah great, the substreams affect the seek ... */ + check(camel_seekable_stream_seek(sp, ss->bound_start + (i)*sizeof(teststring), CAMEL_STREAM_SET) == ss->bound_start + i*sizeof(teststring)); + check(camel_stream_read(CAMEL_STREAM(sp), testbuf, sizeof(teststring)) == sizeof(teststring)); + check(memcmp(testbuf, teststring, sizeof(teststring)) == 0); + check(camel_seekable_stream_tell(sp) == ss->bound_start + (i+1)*sizeof(teststring)); + } + len = (ss->bound_end-ss->bound_start) % sizeof(teststring); + check(camel_stream_read(s, testbuf, len) == len); + check(memcmp(testbuf, teststring, len) == 0); + + check(camel_seekable_stream_seek(sp, ss->bound_end - len, CAMEL_STREAM_SET) == ss->bound_end - len); + check(camel_stream_read(CAMEL_STREAM(sp), testbuf, len) == len); + check(memcmp(testbuf, teststring, len) == 0); + + check(camel_stream_eos(s)); + check(camel_seekable_stream_tell(ss) == ss->bound_end); + check(camel_seekable_stream_tell(sp) == ss->bound_end); + check(camel_stream_read(s, testbuf, 1024) == 0); + check(camel_seekable_stream_tell(ss) == ss->bound_end); + check(camel_seekable_stream_tell(sp) == ss->bound_end); + check(camel_stream_eos(s)); + } else { + /* just 10K */ + for (i=0;i<10240;i++) { + check(camel_stream_read(s, testbuf, sizeof(teststring)) == sizeof(teststring)); + check(memcmp(testbuf, teststring, sizeof(teststring)) == 0); + check(camel_seekable_stream_tell(ss) == ss->bound_start + (i+1)*sizeof(teststring)); + + check(camel_seekable_stream_seek(sp, ss->bound_start + (i)*sizeof(teststring), CAMEL_STREAM_SET) == ss->bound_start + i*sizeof(teststring)); + check(camel_stream_read(CAMEL_STREAM(sp), testbuf, sizeof(teststring)) == sizeof(teststring)); + check(memcmp(testbuf, teststring, sizeof(teststring)) == 0); + check(camel_seekable_stream_tell(sp) == ss->bound_start + (i+1)*sizeof(teststring)); + } + + /* unbound - we dont know the real length */ +#if 0 + end = 10240*sizeof(teststring)+ss->bound_start; + + check(camel_seekable_stream_seek(ss, 0, CAMEL_STREAM_END) == end); + check(camel_seekable_stream_tell(ss) == end); + /* need to read 0 first to set eos */ + check(camel_stream_read(s, testbuf, 10240) == 0); + check(camel_stream_eos(s)); +#endif + } + + pull(); +} diff --git a/camel/tests/lib/streams.h b/camel/tests/lib/streams.h new file mode 100644 index 0000000000..df52e283d0 --- /dev/null +++ b/camel/tests/lib/streams.h @@ -0,0 +1,12 @@ + +#include "camel/camel-seekable-stream.h" + +/* call one, then the other on the same stream content */ +void test_stream_seekable_writepart(CamelSeekableStream *s); +void test_stream_seekable_readpart(CamelSeekableStream *s); + +/* same, for substreams, multiple ways of writing */ +#define SEEKABLE_SUBSTREAM_WAYS (2) + +void test_seekable_substream_writepart(CamelStream *s, int type); +void test_seekable_substream_readpart(CamelStream *s); diff --git a/camel/tests/stream/README b/camel/tests/stream/README new file mode 100644 index 0000000000..8ca6a9602d --- /dev/null +++ b/camel/tests/stream/README @@ -0,0 +1,4 @@ + +test1 camelstreamfs, creating, read/write, eos, refcounting +test2 camelstreammem, creating, read/write, eos, refcounting +test3 camelseekablesubstream |