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

Improved test of Stdio.sendfile().

Rev: src/modules/files/sendfiletest.pike:1.4
parent 84ccbcc4
No related branches found
No related tags found
No related merge requests found
#!/usr/local/bin/pike
/* $Id: sendfiletest.pike,v 1.3 2000/10/06 21:18:10 grubba Exp $ */
/* $Id: sendfiletest.pike,v 1.4 2000/10/07 11:34:28 grubba Exp $ */
constant TEST_SIZE = 16384;
......@@ -8,6 +8,9 @@ string testdata = Crypto.randomness.reasonably_random()->read(TEST_SIZE);
int testno;
object(Stdio.Port) loopback = Stdio.Port();
int loopbackport;
/*
* Some helper functions.
*/
......@@ -34,6 +37,20 @@ object(Stdio.File) To(string f)
return to;
}
array(object(Stdio.File)) SocketPair()
{
object(Stdio.File) sock1, sock2;
sock1 = Stdio.File();
sock1->connect("127.0.0.1", loopbackport);
sock2 = loopback->accept();
if(!sock2)
{
werror("Accept returned 0\n");
exit(1);
}
return ({ sock1, sock2 });
}
/*
* The driver function.
*/
......@@ -121,10 +138,43 @@ void test4()
exit(1);
}
/* Try a loopback test. */
array(object) pair = SocketPair();
if (!Stdio.sendfile(testdata/4096, From("conftest.src"), 0, -1,
testdata/512, pair[0], done, TEST_SIZE*3)) {
werror("Stdio.sendfile() failed!\n");
exit(1);
}
if (!Stdio.sendfile(testdata/4096, pair[1], 0, -1,
testdata/512, To("conftest.dst"), done, TEST_SIZE*5)) {
werror("Stdio.sendfile() failed!\n");
exit(1);
}
next();
}
void test5()
{
/* Dummy (test 4 will call done twice). */
}
void test6()
{
/* Check that the testdata still is correct. */
if (From("conftest.dst")->read() != testdata*5) {
werror("Data corruption!\n");
exit(1);
}
next();
}
void test7()
{
/* Clean up. */
rm("conftest.src");
......@@ -138,6 +188,8 @@ void test5()
int main(int argc, array(string) argv)
{
loopback->bind(0);
loopbackport = (int)((loopback->query_address()/" ")[1]);
call_out(next, 0);
return -1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment