5 * Created by Victor Grishchenko on 3/19/09.
6 * Copyright 2009-2012 TECHNISCHE UNIVERSITEIT DELFT. All rights reserved.
11 #include <gtest/gtest.h>
15 using namespace swift;
20 void IsCompleteCallback(int fd, short event, void *arg) {
21 if (swift::SeqComplete(copy)!=size)
22 evtimer_add(&evcompl, tint2tv(TINT_SEC));
24 event_base_loopexit(Channel::evbase, NULL);
27 TEST(Connection,CwndTest) {
29 Channel::evbase = event_base_new();
33 unlink("test_file0-copy.dat");
39 ASSERT_EQ(0,stat("test_file0.dat", &st));
40 size = st.st_size;//, sizek = (st.st_size>>10) + (st.st_size%1024?1:0) ;
41 Channel::SELF_CONN_OK = true;
43 int sock1 = swift::Listen(7001);
44 ASSERT_TRUE(sock1>=0);
46 int file = swift::Open("test_file0.dat");
47 FileTransfer* fileobj = FileTransfer::file(file);
48 //FileTransfer::instance++;
50 swift::SetTracker(Address("127.0.0.1",7001));
52 copy = swift::Open("test_file0-copy.dat",fileobj->root_hash());
54 evtimer_assign(&evcompl, Channel::evbase, IsCompleteCallback, NULL);
55 evtimer_add(&evcompl, tint2tv(TINT_SEC));
57 //swift::Loop(TINT_SEC);
58 event_base_dispatch(Channel::evbase);
61 //while (swift::SeqComplete(copy)!=size && count++<600)
62 // swift::Loop(TINT_SEC);
63 ASSERT_EQ(size,swift::SeqComplete(copy));
68 swift::Shutdown(sock1);
73 int main (int argc, char** argv) {
76 testing::InitGoogleTest(&argc, argv);
77 Channel::debug_file = stdout;
78 int ret = RUN_ALL_TESTS();