add .gitignore
[swift-upb.git] / tests / rwtest.cpp
1 /*
2  *  readwrite.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 "p2tp.h"
12
13 TEST(P2TP, ConnectTest) {
14         P2File("");
15         p2tp_init(7001);
16         
17         int tf = p2tp_open("test_file",NULL);
18         int tb = p2tp_open("test_file_copy",p2tp_file_info(tf)->hash_data);
19         struct sockaddr_in addr;
20         addr.sin_family = AF_INET;
21         addr.sin_port = htons(7001);
22         addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
23         p2tp_add_peer(tb,addr,0); // TRICK: will open a channel to the first file
24         p2tp_loop(P2TP::now()+TINT1SEC/10);
25
26         while (count=copy.read(bytes)) {
27                 read(orig,bytes2,count);
28                 ASSERT_EQ ( 0, memcmp(bytes,bytes2,count) );
29         }
30         
31         p2tp_close(tb);
32         p2tp_close(tf);
33         
34 }
35
36 int main (int argc, char** argv) {
37         P2TP::init();
38         
39         testing::InitGoogleTest(&argc, argv);
40         return RUN_ALL_TESTS();
41         
42 }