From 84ccbcc400de33d19461a816212e9fb8383bda3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Fri, 6 Oct 2000 23:18:10 +0200 Subject: [PATCH] Improved testsuite for Stdio.sendfile(). Rev: src/modules/files/sendfiletest.pike:1.3 --- src/modules/files/sendfiletest.pike | 154 +++++++++++++++++++++++----- 1 file changed, 130 insertions(+), 24 deletions(-) diff --git a/src/modules/files/sendfiletest.pike b/src/modules/files/sendfiletest.pike index c5d9628c42..dd30d2173d 100644 --- a/src/modules/files/sendfiletest.pike +++ b/src/modules/files/sendfiletest.pike @@ -1,37 +1,143 @@ #!/usr/local/bin/pike -/* $Id: sendfiletest.pike,v 1.2 1999/10/14 21:23:33 grubba Exp $ */ +/* $Id: sendfiletest.pike,v 1.3 2000/10/06 21:18:10 grubba Exp $ */ -void done(int sent) +constant TEST_SIZE = 16384; + +string testdata = Crypto.randomness.reasonably_random()->read(TEST_SIZE); + +int testno; + +/* + * Some helper functions. + */ + +object(Stdio.File) From(string f) +{ + object(Stdio.File) from = Stdio.File(); + + if (!from->open(f, "r")) { + werror("Failed to open %O for reading.\n", f); + exit(1); + } + return from; +} + +object(Stdio.File) To(string f) { - rm("conftest.Makefile"); - exit(0); + object(Stdio.File) to = Stdio.File(); + + if (!to->open(f, "cwt")) { + werror("Failed to open %O for writing.\n", f); + exit(1); + } + return to; } -int main(int argc, array(string) argv) +/* + * The driver function. + */ + +void next() +{ + testno++; + + function test; + if (!(test = this_object()["test"+testno])) exit(0); + mixed err; + if (err = catch { + werror("Sendfile test: %d\n", testno); + test(); + }) { + catch { + werror("Test %d failed!\n" + "%s\n", + testno, + describe_backtrace(err)); + }; + exit(1); + } +} + +void done(int sent, int expected) +{ + if (sent != expected) { + werror(sprintf("Test %d failed: %d != %d\n", testno, sent, expected)); + exit(1); + } + next(); +} + +/* + * The actual tests. + */ + +void test1() +{ + /* First try sending out testdata to a plain file. */ + + if (!Stdio.sendfile(testdata/1024, 0, 0, -1, 0, + To("conftest.src"), done, TEST_SIZE)) { + werror("Stdio,sendfile() failed!\n"); + exit(1); + } +} + +void test2() +{ + /* Then try copying it to another file. */ + + if (!Stdio.sendfile(0, From("conftest.src"), 0, -1, 0, + To("conftest.dst"), done, TEST_SIZE)) { + werror("Stdio.sendfile() failed!\n"); + exit(1); + } +} + +void test3() { - object from = Stdio.File(); - object to = Stdio.File(); + /* Check that the testdata still is correct. */ + + if (From("conftest.dst")->read() != testdata) { + werror("Data corruption!\n"); + exit(1); + } - if (!from->open("Makefile", "r")) { - werror("Failed to open \"Makefile\" for reading!\n"); + /* Try with a headers + file + trailers combo. */ + + if (!Stdio.sendfile(testdata/4096, From("conftest.src"), 0, -1, + testdata/512, To("conftest.dst"), done, TEST_SIZE*3)) { + werror("Stdio.sendfile() failed!\n"); exit(1); } - if (!to->open("conftest.Makefile", "cwt")) { - werror("Failed to open \"conftest.Makefile\" for writing!\n"); +} + +void test4() +{ + /* Check that the testdata still is correct. */ + + if (From("conftest.dst")->read() != testdata*3) { + werror("Data corruption!\n"); exit(1); } - mixed err = catch { - if (!Stdio.sendfile(0, from, 0, -1, 0, to, done)) { - werror("Stdio,sendfile() failed!\n"); - exit(1); - } - return(-1); - }; - catch { - werror("Stdio.sendfile() failed!\n" - "%s\n", - describe_backtrace(err)); - }; - exit(1); + + next(); +} + +void test5() +{ + /* Clean up. */ + rm("conftest.src"); + rm("conftest.dst"); + next(); +} + +/* + * Start the backend. + */ + +int main(int argc, array(string) argv) +{ + call_out(next, 0); + return -1; } -- GitLab