diff --git a/src/modules/files/sendfiletest.pike b/src/modules/files/sendfiletest.pike index dd30d2173d8063f6b874485accf5f8bc9296228d..50acaec2499706332cb458915cdaa29a558b6b44 100644 --- a/src/modules/files/sendfiletest.pike +++ b/src/modules/files/sendfiletest.pike @@ -1,6 +1,6 @@ #!/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; }