#include "DHTPingMessage.h" #include "DHTNode.h" #include "DHTUtil.h" #include "BencodeVisitor.h" #include "Dictionary.h" #include "Data.h" #include "Exception.h" #include "Util.h" #include class DHTPingMessageTest:public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(DHTPingMessageTest); CPPUNIT_TEST(testGetBencodedMessage); CPPUNIT_TEST_SUITE_END(); public: void setUp() {} void tearDown() {} void testGetBencodedMessage(); }; CPPUNIT_TEST_SUITE_REGISTRATION(DHTPingMessageTest); void DHTPingMessageTest::testGetBencodedMessage() { DHTNodeHandle localNode = new DHTNode(); DHTNodeHandle remoteNode = new DHTNode(); char tid[DHT_TRANSACTION_ID_LENGTH]; DHTUtil::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH); string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]); DHTPingMessage msg(localNode, remoteNode, transactionID); string msgbody = msg.getBencodedMessage(); SharedHandle cm = new Dictionary(); cm->put("t", new Data(transactionID)); cm->put("y", new Data("q")); cm->put("q", new Data("ping")); Dictionary* a = new Dictionary(); cm->put("a", a); a->put("id", new Data(reinterpret_cast(localNode->getID()), DHT_ID_LENGTH)); BencodeVisitor v; cm->accept(&v); CPPUNIT_ASSERT_EQUAL(v.getBencodedData(), msgbody); }