X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=blobdiff_plain;f=src%2Flibswift_udp%2Ftests%2Fconnecttest.cpp;fp=src%2Flibswift_udp%2Ftests%2Fconnecttest.cpp;h=69106605a48a7fcf4de9535ee954a37d44ae3d2d;hb=46f3ca346fe499ba3e8f595fc5c2aa2b3e3c4d5f;hp=0000000000000000000000000000000000000000;hpb=d8da6fc1273a2acee935a15761b77a73424faef5;p=swifty.git diff --git a/src/libswift_udp/tests/connecttest.cpp b/src/libswift_udp/tests/connecttest.cpp new file mode 100644 index 0000000..6910660 --- /dev/null +++ b/src/libswift_udp/tests/connecttest.cpp @@ -0,0 +1,81 @@ +/* + * connecttest.cpp + * serp++ + * + * Created by Victor Grishchenko on 3/19/09. + * Copyright 2009-2012 TECHNISCHE UNIVERSITEIT DELFT. All rights reserved. + * + */ +#include +#include +#include +#include "swift.h" + + +using namespace swift; + +struct event evcompl; +int size, copy; + +void IsCompleteCallback(int fd, short event, void *arg) { + if (swift::SeqComplete(copy)!=size) + evtimer_add(&evcompl, tint2tv(TINT_SEC)); + else + event_base_loopexit(Channel::evbase, NULL); +} + +TEST(Connection,CwndTest) { + + Channel::evbase = event_base_new(); + + srand ( time(NULL) ); + + unlink("test_file0-copy.dat"); +#ifdef WIN32 + struct _stat st; +#else + struct stat st; +#endif + ASSERT_EQ(0,stat("test_file0.dat", &st)); + size = st.st_size;//, sizek = (st.st_size>>10) + (st.st_size%1024?1:0) ; + Channel::SELF_CONN_OK = true; + + int sock1 = swift::Listen(7001); + ASSERT_TRUE(sock1>=0); + + int file = swift::Open("test_file0.dat"); + FileTransfer* fileobj = FileTransfer::file(file); + //FileTransfer::instance++; + + swift::SetTracker(Address("127.0.0.1",7001)); + + copy = swift::Open("test_file0-copy.dat",fileobj->root_hash()); + + evtimer_assign(&evcompl, Channel::evbase, IsCompleteCallback, NULL); + evtimer_add(&evcompl, tint2tv(TINT_SEC)); + + //swift::Loop(TINT_SEC); + event_base_dispatch(Channel::evbase); + + //int count = 0; + //while (swift::SeqComplete(copy)!=size && count++<600) + // swift::Loop(TINT_SEC); + ASSERT_EQ(size,swift::SeqComplete(copy)); + + swift::Close(file); + swift::Close(copy); + + swift::Shutdown(sock1); + +} + + +int main (int argc, char** argv) { + + swift::LibraryInit(); + testing::InitGoogleTest(&argc, argv); + Channel::debug_file = stdout; + int ret = RUN_ALL_TESTS(); + return ret; + +}