2 * This file is part of TouristP2PImpl
4 * Copyright (C) 2007,2008 NUST Institute of Information Technology
5 * Author: Faisal Khan <faisal.khan at [niit.edu.pk | cern.ch ]>
7 * TouristP2PImpl is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * TouristP2PImpl is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with TouristP2PImpl; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "TestPeerHandshake.h"
22 #include "Tourist/App/Application.h"
23 #include "CppUnit/TestCaller.h"
24 #include "CppUnit/TestSuite.h"
25 #include "Poco/Thread.h"
27 using Tourist::App::Application
;
30 using namespace Tourist::App
;
32 TestPeerHandshake::TestPeerHandshake(const std::string
& name
): CppUnit::TestCase(name
)
36 TestPeerHandshake::~TestPeerHandshake()
40 void TestPeerHandshake::setUp()
44 void TestPeerHandshake::tearDown()
48 void TestPeerHandshake::testHandshake()
50 //create Application-1, configure the transport
51 //create Application-2, configure transport with different port
53 config_1
.setTCPEnable(true);
54 config_1
.setTCPPort(5000);
55 Application
app1(config_1
);
58 config_2
.setTCPEnable(true);
59 config_2
.setTCPPort(5010);
60 Application
app2(config_2
);
62 assert (app1
.init() == 0);
63 assert (app2
.init() == 0);
70 //connect to remote-node of application-1 with application-2
71 RemoteNode
*rn
= NULL
;
72 vector
<TransportInfo
> transportInfo
;
73 transportInfo
= app1
.getEnabledTransports();
75 assert (transportInfo
.size() != 0);
77 //TODO: test it for all the transports.
78 TransportInfo tInfo
= transportInfo
.at(0);
79 int status
= app2
.connectionTo(tInfo
.host
, tInfo
.port
, tInfo
.type
, &rn
, 10);
83 assert (rn
-> getHost() == tInfo
.host
);
84 assert (rn
-> getPort() == tInfo
.port
);
85 assert (rn
-> getProtocol() == tInfo
.type
);
86 assert (rn
-> getPipe() != NULL
);
91 //wait for all the threads to finish
95 //match remtoe node information with that one of Application-1
99 CppUnit::Test
* TestPeerHandshake::suite()
101 CppUnit::TestSuite
* pSuite
= new CppUnit::TestSuite("TestPeerHandshake");
102 CppUnit_addTest(pSuite
, TestPeerHandshake
, testHandshake
);