aria2/test/DHTPingReplyMessageTest.cc
Tatsuhiro Tsujikawa 9202fe23c8 2008-12-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use BDE instead of Dictionary/List/Data.
	* src/DHTAbstractMessage.cc
	* src/DHTAbstractMessage.h
	* src/DHTAnnouncePeerMessage.cc
	* src/DHTAnnouncePeerMessage.h
	* src/DHTAnnouncePeerReplyMessage.cc
	* src/DHTAnnouncePeerReplyMessage.h
	* src/DHTFindNodeMessage.cc
	* src/DHTFindNodeMessage.h
	* src/DHTFindNodeReplyMessage.cc
	* src/DHTFindNodeReplyMessage.h
	* src/DHTGetPeersMessage.cc
	* src/DHTGetPeersMessage.h
	* src/DHTGetPeersReplyMessage.cc
	* src/DHTGetPeersReplyMessage.h
	* src/DHTMessageFactory.h
	* src/DHTMessageFactoryImpl.cc
	* src/DHTMessageFactoryImpl.h
	* src/DHTMessageReceiver.cc
	* src/DHTMessageTracker.cc
	* src/DHTMessageTracker.h
	* src/DHTPingMessage.cc
	* src/DHTPingMessage.h
	* src/DHTPingReplyMessage.cc
	* src/DHTPingReplyMessage.h
	* src/DHTQueryMessage.cc
	* src/DHTQueryMessage.h
	* src/DHTResponseMessage.cc
	* src/DHTResponseMessage.h
	* test/DHTAnnouncePeerMessageTest.cc
	* test/DHTAnnouncePeerReplyMessageTest.cc
	* test/DHTFindNodeMessageTest.cc
	* test/DHTFindNodeReplyMessageTest.cc
	* test/DHTGetPeersMessageTest.cc
	* test/DHTGetPeersReplyMessageTest.cc
	* test/DHTMessageFactoryImplTest.cc
	* test/DHTMessageTrackerTest.cc
	* test/DHTPingMessageTest.cc
	* test/DHTPingReplyMessageTest.cc
	* test/MockDHTMessageFactory.h
2008-12-14 05:46:45 +00:00

55 lines
1.3 KiB
C++

#include "DHTPingReplyMessage.h"
#include <cppunit/extensions/HelperMacros.h>
#include "DHTNode.h"
#include "DHTUtil.h"
#include "Exception.h"
#include "Util.h"
#include "bencode.h"
namespace aria2 {
class DHTPingReplyMessageTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DHTPingReplyMessageTest);
CPPUNIT_TEST(testGetBencodedMessage);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testGetBencodedMessage();
};
CPPUNIT_TEST_SUITE_REGISTRATION(DHTPingReplyMessageTest);
void DHTPingReplyMessageTest::testGetBencodedMessage()
{
SharedHandle<DHTNode> localNode(new DHTNode());
SharedHandle<DHTNode> remoteNode(new DHTNode());
unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
DHTUtil::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
unsigned char id[DHT_ID_LENGTH];
DHTUtil::generateRandomData(id, DHT_ID_LENGTH);
DHTPingReplyMessage msg(localNode, remoteNode, id, transactionID);
std::string msgbody = msg.getBencodedMessage();
bencode::BDE dict = bencode::BDE::dict();
dict["t"] = transactionID;
dict["y"] = bencode::BDE("r");
bencode::BDE rDict = bencode::BDE::dict();
rDict["id"] = bencode::BDE(id, DHT_ID_LENGTH);
dict["r"] = rDict;
CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);
}
} // namespace aria2