Skip to content
Snippets Groups Projects
Commit 84ccbcc4 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Improved testsuite for Stdio.sendfile().

Rev: src/modules/files/sendfiletest.pike:1.3
parent 43f9db63
Branches
Tags
No related merge requests found
#!/usr/local/bin/pike #!/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;
{
rm("conftest.Makefile");
exit(0);
}
int main(int argc, array(string) argv) string testdata = Crypto.randomness.reasonably_random()->read(TEST_SIZE);
int testno;
/*
* Some helper functions.
*/
object(Stdio.File) From(string f)
{ {
object from = Stdio.File(); object(Stdio.File) from = Stdio.File();
object to = Stdio.File();
if (!from->open("Makefile", "r")) { if (!from->open(f, "r")) {
werror("Failed to open \"Makefile\" for reading!\n"); werror("Failed to open %O for reading.\n", f);
exit(1); exit(1);
} }
if (!to->open("conftest.Makefile", "cwt")) { return from;
werror("Failed to open \"conftest.Makefile\" for writing!\n");
exit(1);
} }
mixed err = catch {
if (!Stdio.sendfile(0, from, 0, -1, 0, to, done)) { object(Stdio.File) To(string f)
werror("Stdio,sendfile() failed!\n"); {
object(Stdio.File) to = Stdio.File();
if (!to->open(f, "cwt")) {
werror("Failed to open %O for writing.\n", f);
exit(1); exit(1);
} }
return(-1); return to;
}; }
/*
* 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 { catch {
werror("Stdio.sendfile() failed!\n" werror("Test %d failed!\n"
"%s\n", "%s\n",
testno,
describe_backtrace(err)); describe_backtrace(err));
}; };
exit(1); 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()
{
/* Check that the testdata still is correct. */
if (From("conftest.dst")->read() != testdata) {
werror("Data corruption!\n");
exit(1);
}
/* 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);
}
}
void test4()
{
/* Check that the testdata still is correct. */
if (From("conftest.dst")->read() != testdata*3) {
werror("Data corruption!\n");
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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment