e49c6c78a6788ebf54e0d488087b686a48db322d
[swift-upb.git] / tests / connecttest.cpp
1 /*
2  *  connecttest.cpp
3  *  serp++
4  *
5  *  Created by Victor Grishchenko on 3/19/09.
6  *  Copyright 2009 Delft University of Technology. All rights reserved.
7  *
8  */
9
10 #include <gtest/gtest.h>
11 //#include <glog/logging.h>
12 #include "swift.h"
13 #include <time.h>
14
15
16 using namespace swift;
17
18
19 TEST(SWIFT,CwndTest) {
20
21     srand ( time(NULL) );
22
23     unlink("doc/sofi-copy.jpg");
24     struct stat st;
25         ASSERT_EQ(0,stat("doc/sofi.jpg", &st));
26     int size = st.st_size;//, sizek = (st.st_size>>10) + (st.st_size%1024?1:0) ;
27     Channel::SELF_CONN_OK = true;
28
29     int sock1 = swift::Listen(7001);
30         ASSERT_TRUE(sock1>=0);
31
32         int file = swift::Open("doc/sofi.jpg");
33     FileTransfer* fileobj = FileTransfer::file(file);
34     //FileTransfer::instance++;
35
36     swift::SetTracker(Address("127.0.0.1",7001));
37
38         int copy = swift::Open("doc/sofi-copy.jpg",fileobj->root_hash());
39
40         swift::Loop(TINT_SEC);
41
42     int count = 0;
43     while (swift::SeqComplete(copy)!=size && count++<600)
44         swift::Loop(TINT_SEC);
45     ASSERT_EQ(size,swift::SeqComplete(copy));
46
47         swift::Close(file);
48         swift::Close(copy);
49
50         swift::Shutdown(sock1);
51
52 }
53
54
55 int main (int argc, char** argv) {
56
57         swift::LibraryInit();
58         testing::InitGoogleTest(&argc, argv);
59         int ret = RUN_ALL_TESTS();
60         return ret;
61
62 }